From 8bad0a97f410e99c9d9694af495f9c42a9ae0e54 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 8 Dec 2016 21:34:32 -0500 Subject: [PATCH] Made zombies drop $1 --- src/alisolarflare/AliPresents.java | 2 + .../components/cashmob/CashMobComponent.java | 18 ++++++++ .../components/cashmob/MobKillListener.java | 41 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/alisolarflare/components/cashmob/CashMobComponent.java create mode 100644 src/alisolarflare/components/cashmob/MobKillListener.java diff --git a/src/alisolarflare/AliPresents.java b/src/alisolarflare/AliPresents.java index 6db2501..7d0716e 100644 --- a/src/alisolarflare/AliPresents.java +++ b/src/alisolarflare/AliPresents.java @@ -8,6 +8,7 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.components.alilinks.AliLinkComponent; import alisolarflare.components.bankchest.BankChestComponent; +import alisolarflare.components.cashmob.CashMobComponent; import alisolarflare.components.creativeboundaries.CreativeBoundariesComponent; import alisolarflare.components.flaircolouring.FlairColouringComponent; import alisolarflare.components.gpowers.GPowerComponent; @@ -25,6 +26,7 @@ public class AliPresents extends JavaPlugin{ new AliLinkComponent().register(this); new BankChestComponent().register(this); + new CashMobComponent().register(this); new CreativeBoundariesComponent().register(this); new FlairColouringComponent().register(this); new GPowerComponent().register(this); diff --git a/src/alisolarflare/components/cashmob/CashMobComponent.java b/src/alisolarflare/components/cashmob/CashMobComponent.java new file mode 100644 index 0000000..dda2346 --- /dev/null +++ b/src/alisolarflare/components/cashmob/CashMobComponent.java @@ -0,0 +1,18 @@ +package alisolarflare.components.cashmob; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import com.earth2me.essentials.Essentials; + +import alisolarflare.architecture.Component; + +public class CashMobComponent extends Component{ + + @Override + public void register(JavaPlugin plugin) { + registerListener(plugin, new MobKillListener((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"))); + + } + +} diff --git a/src/alisolarflare/components/cashmob/MobKillListener.java b/src/alisolarflare/components/cashmob/MobKillListener.java new file mode 100644 index 0000000..2296a05 --- /dev/null +++ b/src/alisolarflare/components/cashmob/MobKillListener.java @@ -0,0 +1,41 @@ +package alisolarflare.components.cashmob; + +import java.math.BigDecimal; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDeathEvent; + +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; + +import net.ess3.api.MaxMoneyException; + +public class MobKillListener implements Listener { + private Essentials essentials; + + public MobKillListener(Essentials essentials) { + this.essentials = essentials; + } + + @EventHandler + public void onMobKill(EntityDeathEvent event){ + Player killer; + if ((killer = event.getEntity().getKiller()) == null){ + return; + } + User user = essentials.getUser(killer); + switch(event.getEntity().getType()){ + case ZOMBIE: + try { + user.giveMoney(BigDecimal.ONE); + } catch (MaxMoneyException e) { + return; + } + default: + return; + } + + } +}