Skip to content

Commit

Permalink
Expand Economics
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepSterr committed Jun 10, 2024
1 parent 7de820b commit 558a611
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dev_server/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Sun Jun 09 10:48:52 CEST 2024
#Tue Jun 11 01:16:00 CEST 2024
accepts-transfers=false
allow-flight=false
allow-nether=false
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/dev/beeps/plugins/Events/OnPlayerDeath.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -100,7 +102,17 @@ public void onPlayerDeath(PlayerDeathEvent event) {

plugin.log(Level.FINE, ply, "###### Economy ######");
if(!ply.hasPermission("betterkeepinventory.bypass.eco") && !config.GetOverrideForMode("ECO", ply) ) {
handleEcon(ply, event);
EntityDamageEvent dmg_event = ply.getLastDamageCause();
Player attacker = null;
if(dmg_event != null) {
if (dmg_event instanceof EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager() instanceof Player atk) {
attacker = atk;
}
}
}

handleEcon(ply, attacker);
}

if(config.getBoolean("main.grace", true)){
Expand Down Expand Up @@ -199,7 +211,7 @@ public void handleExperience(Player ply, Event evt){

}

public void handleEcon(Player ply, Event evt){
public void handleEcon(Player ply, Player attacker){

// Ensure econ is enabled
if(!plugin.config.getBoolean("eco.enabled")){
Expand Down Expand Up @@ -239,6 +251,13 @@ public void handleEcon(Player ply, Event evt){
if(r){
ply.sendMessage(ChatColor.RED + "You lost $" + amount);
}

if(attacker != null && attacker != ply && config.getBoolean("eco.pay_to_killer")) {
boolean r2 = v.giveMoney(attacker, amount);
if (r2) {
attacker.sendMessage(ChatColor.GREEN + "You received $" + amount + " for killing " + ply.getDisplayName());
}
}
}

}else{
Expand Down

0 comments on commit 558a611

Please sign in to comment.