Browse Source

Completely remade.

main
Nichole Mattera 11 years ago
parent
commit
6b7f928ce3
  1. 47
      README.md
  2. 91
      src/com/stevenmattera/MobBounty/Commands/mb.java
  3. 76
      src/com/stevenmattera/MobBounty/Commands/mbmulti.java
  4. 121
      src/com/stevenmattera/MobBounty/Commands/mbreward.java
  5. 249
      src/com/stevenmattera/MobBounty/Config.java
  6. 106
      src/com/stevenmattera/MobBounty/Listeners/DeathListener.java
  7. 56
      src/com/stevenmattera/MobBounty/Listeners/PluginListener.java
  8. 101
      src/com/stevenmattera/MobBounty/Main.java
  9. 25
      src/com/stevenmattera/MobBounty/Utils/Colors.java
  10. 60
      src/plugin.yml

47
README.md

@ -1,32 +1,37 @@
#MobBounty
A simple plugin for iConomy that pays players for killing mobs.
A simple plugin for iConomy that pays and fines players for killing mobs.
What you can players kill to earn money
Features
----------------------
* Chicken
* Cow
* Creeper
* Ghast
* Pig
* Pigman
* Sheep
* Skeleton
* Slime
* Spider
* Squid
* Zombie
Features
* Individual mob rewards/fines.
* Multi-world support allowing for different rewards/fine depending on the world.
* Multiply the rewards/fine depending on the Time, Environment, and/or world.
* Admin commands to change any setting in game.
Permissions
----------------------
* Individual mob reward amount.
* Multi-world support to allow for multipliers in different worlds.
* Commands to change anything during game.
* MobBounty.mb -- (Allows for /mb command and collect of rewards and fines.)
* MobBounty.Admin.mbg -- (Allows for /mbg command.)
* MobBounty.Admin.mbr -- (Allows for /mbr command.)
* MobBounty.Admin.mbwr -- (Allows for /mbwr command.)
* MobBounty.Admin.mbem -- (Allows for /mbem command.)
* MobBounty.Admin.mbtm -- (Allows for /mbtm command.)
* MobBounty.Admin.mbwm -- (Allows for /mbwm command.)
* MobBounty.Admin.mbs -- (Allows for /mbs command.)
* MobBounty.Admin.mbl -- (Allows for /mbl command.)
Commands
----------------------
* /mb -- (View rewards.)
* /mbmulti -- (Modify reward amount per mob.)
* /mbreward -- (Modify multiplication amount per world.)
* /mb -- (View rewards and fines.)
* /mbg -- (Modify the general settings.)
* /mbr -- (Modify the default rewards and fines of a mob.)
* /mbwr -- (Modify rewards and fines of a mob in a world.)
* /mbem -- (Modify multiplier per environment.)
* /mbtm -- (Modify multiplier per time.)
* /mbwm -- (Modify multiplier per world.)
* /mbs -- (Save the config files.)
* /mbl -- (Load the config files.)

91
src/com/stevenmattera/MobBounty/Commands/mb.java

@ -1,91 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty.Commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Player;
import com.nijiko.coelho.iConomy.iConomy;
import com.stevenmattera.MobBounty.Main;
import com.stevenmattera.MobBounty.Utils.Colors;
public class mb implements CommandExecutor {
private final Main _plugin;
// ----
// ==== Constructor Method ====
// ----
public mb(Main plugin) {
_plugin = plugin;
}
// ----
// ==== CommandExecutor Methods ====
// ----
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (_plugin.Permissions != null && _plugin.Permissions.has((Player) sender, "MobBounty.mb")) {
this.mbCommand(sender);
}
else if (_plugin.Permissions == null) {
this.mbCommand(sender);
}
else {
sender.sendMessage(Colors.Red+"You do no have access to that command.");
}
return true;
}
// ----
// ==== Private Methods ====
// ----
private void mbCommand(CommandSender sender) {
double multiplier = _plugin.getConfig().getWorldMultiplier(((Player) sender).getWorld());
if (_plugin.getConfig().getReward(CreatureType.CHICKEN) > 0)
sender.sendMessage("\u00A7f"+"Chicken"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.CHICKEN)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.COW) > 0)
sender.sendMessage("\u00A7f"+"Cow"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.COW)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.CREEPER) > 0)
sender.sendMessage("\u00A7f"+"Creeper"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.CREEPER)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.GHAST) > 0)
sender.sendMessage("\u00A7f"+"Ghast"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.GHAST)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.PIG) > 0)
sender.sendMessage("\u00A7f"+"Pig"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.PIG)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.PIG_ZOMBIE) > 0)
sender.sendMessage("\u00A7f"+"Pigman"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.PIG_ZOMBIE)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.SHEEP) > 0)
sender.sendMessage("\u00A7f"+"Sheep"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.SHEEP)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.SKELETON) > 0)
sender.sendMessage("\u00A7f"+"Skeleton"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.SKELETON)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.SLIME) > 0)
sender.sendMessage("\u00A7f"+"Slime"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.SLIME)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.SPIDER) > 0)
sender.sendMessage("\u00A7f"+"Spider"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.SPIDER)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.SQUID) > 0)
sender.sendMessage("\u00A7f"+"Squid"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.SQUID)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
if (_plugin.getConfig().getReward(CreatureType.ZOMBIE) > 0)
sender.sendMessage("\u00A7f"+"Zombie"+"\u00A72"+" - "+_plugin.getConfig().getReward(CreatureType.ZOMBIE)*multiplier+" "+iConomy.getBank().getCurrency()+"(s)");
}
}

76
src/com/stevenmattera/MobBounty/Commands/mbmulti.java

@ -1,76 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty.Commands;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.stevenmattera.MobBounty.Main;
import com.stevenmattera.MobBounty.Utils.Colors;
public class mbmulti implements CommandExecutor {
private final Main _plugin;
// ----
// ==== Constructor Methods ====
// ----
public mbmulti(Main plugin) {
_plugin = plugin;
}
// ----
// ==== CommandExecutor Methods ====
// ----
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (_plugin.Permissions != null && _plugin.Permissions.has((Player) sender, "MobBounty.mbmulti")) {
this.mbmultiCommand(sender, label, args);
}
else if (_plugin.Permissions == null && sender.isOp()) {
this.mbmultiCommand(sender, label, args);
}
else {
sender.sendMessage(Colors.Red+"You do no have access to that command.");
}
return true;
}
// ----
// ==== Private Methods ====
// ----
private void mbmultiCommand(CommandSender sender, String label, String[] args) {
if (args.length == 2) {
if (args[1].matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {
Double amount = Double.parseDouble(args[1]);
if (amount >= 0) {
World world = _plugin.getServer().getWorld(args[0]);
if (world != null) {
_plugin.getConfig().setWorldMultiplier(world.getName(), amount);
sender.sendMessage(Colors.DarkGreen+"World \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to multiply by: "+Colors.White+amount);
}
else {
sender.sendMessage(Colors.Red+"Unknown world \""+Colors.White+args[0]+Colors.Red+"\".");
}
}
else {
sender.sendMessage(Colors.Red+"Amount must be greater than or equal to 0.");
}
}
}
else {
sender.sendMessage(Colors.Red+"Usage: /"+label+" <world> <amount>");
}
}
}

121
src/com/stevenmattera/MobBounty/Commands/mbreward.java

@ -1,121 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty.Commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Player;
import com.stevenmattera.MobBounty.Main;
import com.stevenmattera.MobBounty.Utils.Colors;
public class mbreward implements CommandExecutor {
private final Main _plugin;
// ----
// ==== Constructor Methods ====
// ----
public mbreward(Main plugin) {
_plugin = plugin;
}
// ----
// ==== CommandExecutor Methods ====
// ----
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (_plugin.Permissions != null && _plugin.Permissions.has((Player) sender, "MobBounty.mbreward")) {
this.mbrewardCommand(sender, label, args);
}
else if (_plugin.Permissions == null && sender.isOp()) {
this.mbrewardCommand(sender, label, args);
}
else {
sender.sendMessage(Colors.Red+"You do no have access to that command.");
}
return true;
}
// ----
// ==== Private Methods ====
// ----
private void mbrewardCommand(CommandSender sender, String label, String[] args) {
if (args.length == 2) {
if (args[1].matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {
Double amount = Double.parseDouble(args[1]);
if (amount >= 0) {
if (args[0].equalsIgnoreCase("chicken")) {
_plugin.getConfig().setReward(CreatureType.CHICKEN, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("cow")) {
_plugin.getConfig().setReward(CreatureType.COW, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("creeper")) {
_plugin.getConfig().setReward(CreatureType.CREEPER, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("ghast")) {
_plugin.getConfig().setReward(CreatureType.GHAST, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("pig")) {
_plugin.getConfig().setReward(CreatureType.PIG, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("pigman")) {
_plugin.getConfig().setReward(CreatureType.PIG_ZOMBIE, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("sheep")) {
_plugin.getConfig().setReward(CreatureType.SHEEP, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("skeleton")) {
_plugin.getConfig().setReward(CreatureType.SKELETON, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("slime")) {
_plugin.getConfig().setReward(CreatureType.SLIME, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("spider")) {
_plugin.getConfig().setReward(CreatureType.SPIDER, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("squid")) {
_plugin.getConfig().setReward(CreatureType.SQUID, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else if (args[0].equalsIgnoreCase("zombie")) {
_plugin.getConfig().setReward(CreatureType.ZOMBIE, amount);
sender.sendMessage(Colors.DarkGreen+"Mob \""+Colors.White+args[0]+Colors.DarkGreen+"\" has been changed to amount: "+Colors.White+amount);
}
else {
sender.sendMessage(Colors.Red+"Unknown mob \""+Colors.White+args[0]+Colors.Red+"\"");
}
}
else {
sender.sendMessage(Colors.Red+"Amount must be greater than or equal to 0.");
}
}
else {
sender.sendMessage(Colors.Red+"Unknown amount \""+Colors.White+args[1]+Colors.Red+"\"");
}
}
else {
sender.sendMessage(Colors.Red+"Usage: /"+label+" <mob> <amount>");
}
}
}

249
src/com/stevenmattera/MobBounty/Config.java

@ -1,249 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.World;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Pig;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Zombie;
import org.bukkit.util.config.Configuration;
public class Config {
private static Main _plugin = null;
private File _configFile = null;
private Configuration _config = null;
private double _defaultMultiplier = 1;
private Map<String, Double> _worldMultiplier = null;
private Map<String, Double> _rewards = null;
// ----
// ==== Constructor Method ====
// ----
public Config(Main plugin) {
if (_plugin == null) _plugin = plugin;
_configFile = new File(_plugin.getDataFolder() + File.separator + "config.yml");
_worldMultiplier = new HashMap<String, Double>();
_rewards = new HashMap<String, Double>();
_config = new Configuration(_configFile);
if (!_configFile.exists()) this.createConfig();
else this.loadConfig();
}
// ----
// ==== Private Methods ====
// ----
private void createConfig() {
if (_config != null) {
List<World> worlds = _plugin.getServer().getWorlds();
Iterator<World> worldIterator = worlds.iterator();
_config.setProperty("Multipliers.Default", 1);
_defaultMultiplier = 1;
while (worldIterator.hasNext()) {
World world = worldIterator.next();
if (world.getEnvironment() == World.Environment.NETHER) {
_config.setProperty("Multipliers."+world.getName(), 2);
_worldMultiplier.put(world.getName(), new Double(2));
}
else {
_config.setProperty("Multipliers."+world.getName(), 1);
_worldMultiplier.put(world.getName(), new Double(1));
}
}
_config.setProperty("Pig", 0);
_rewards.put(CreatureType.PIG.getName(), new Double(0));
_config.setProperty("Sheep", 0);
_rewards.put(CreatureType.SHEEP.getName(), new Double(0));
_config.setProperty("Cow", 0);
_rewards.put(CreatureType.COW.getName(), new Double(0));
_config.setProperty("Chicken", 0);
_rewards.put(CreatureType.CHICKEN.getName(), new Double(0));
_config.setProperty("Squid", 0);
_rewards.put(CreatureType.SQUID.getName(), new Double(0));
_config.setProperty("Spider", 5);
_rewards.put(CreatureType.SPIDER.getName(), new Double(5));
_config.setProperty("Slime", 5);
_rewards.put(CreatureType.SLIME.getName(), new Double(5));
_config.setProperty("Zombie", 10);
_rewards.put(CreatureType.ZOMBIE.getName(), new Double(10));
_config.setProperty("Skeleton", 15);
_rewards.put(CreatureType.SKELETON.getName(), new Double(15));
_config.setProperty("Pigman", 15);
_rewards.put(CreatureType.PIG_ZOMBIE.getName(), new Double(15));
_config.setProperty("Creeper", 25);
_rewards.put(CreatureType.CREEPER.getName(), new Double(25));
_config.setProperty("Ghast", 50);
_rewards.put(CreatureType.GHAST.getName(), new Double(50));
this.saveConfig();
}
}
// ----
// ==== Public Methods ====
// ----
public void loadConfig() {
if (_config != null) {
_config.load();
List<World> worlds = _plugin.getServer().getWorlds();
Iterator<World> worldIterator = worlds.iterator();
_defaultMultiplier = _config.getDouble("Multipliers.Default", new Double(1));
while (worldIterator.hasNext()) {
World world = worldIterator.next();
_worldMultiplier.put(world.getName(), _config.getDouble("Multipliers."+world.getName(), _defaultMultiplier));
}
_rewards.put(CreatureType.PIG.getName(), new Double(_config.getDouble("Pig", 0)));
_rewards.put(CreatureType.SHEEP.getName(), new Double(_config.getDouble("Sheep", 0)));
_rewards.put(CreatureType.COW.getName(), new Double(_config.getDouble("Cow", 0)));
_rewards.put(CreatureType.CHICKEN.getName(), new Double(_config.getDouble("Chicken", 0)));
_rewards.put(CreatureType.SQUID.getName(), new Double(_config.getDouble("Squid", 0)));
_rewards.put(CreatureType.SPIDER.getName(), new Double(_config.getDouble("Spider", 5)));
_rewards.put(CreatureType.SLIME.getName(), new Double(_config.getDouble("Slime", 5)));
_rewards.put(CreatureType.ZOMBIE.getName(), new Double(_config.getDouble("Zombie", 10)));
_rewards.put(CreatureType.SKELETON.getName(), new Double(_config.getDouble("Skeleton", 15)));
_rewards.put(CreatureType.PIG_ZOMBIE.getName(), new Double(_config.getDouble("Pigman", 15)));
_rewards.put(CreatureType.CREEPER.getName(), new Double(_config.getDouble("Creeper", 25)));
_rewards.put(CreatureType.GHAST.getName(), new Double(_config.getDouble("Ghast", 50)));
}
}
public void saveConfig() {
if (_config != null) {
_config.save();
}
}
public double getWorldMultiplier(World world) {
return this.getWorldMultiplier(world.getName());
}
public double getWorldMultiplier(String worldName) {
Double multi = _worldMultiplier.get(worldName);
if (multi == null) multi = new Double(_defaultMultiplier);
return multi.doubleValue();
}
public double getReward(Entity entity) {
if (entity instanceof Pig) return getReward(CreatureType.PIG).doubleValue();
else if (entity instanceof Sheep) return getReward(CreatureType.SHEEP).doubleValue();
else if (entity instanceof Cow) return getReward(CreatureType.COW).doubleValue();
else if (entity instanceof Chicken) return getReward(CreatureType.CHICKEN).doubleValue();
else if (entity instanceof Squid) return getReward(CreatureType.SQUID).doubleValue();
else if (entity instanceof Spider) return getReward(CreatureType.SPIDER).doubleValue();
else if (entity instanceof Slime) return getReward(CreatureType.SLIME).doubleValue();
else if (entity instanceof Zombie) return getReward(CreatureType.ZOMBIE).doubleValue();
else if (entity instanceof Skeleton) return getReward(CreatureType.SKELETON).doubleValue();
else if (entity instanceof PigZombie) return getReward(CreatureType.PIG_ZOMBIE).doubleValue();
else if (entity instanceof Creeper) return getReward(CreatureType.CREEPER).doubleValue();
else if (entity instanceof Ghast) return getReward(CreatureType.GHAST).doubleValue();
return 0.0;
}
public Double getReward(CreatureType creature) {
return _rewards.get(creature.getName());
}
public void setWorldMultiplier(String worldName, Double amount) {
_worldMultiplier.put(worldName, amount);
_config.setProperty("Multipliers."+worldName, amount);
this.saveConfig();
}
public void setReward(CreatureType creature, Double amount) {
_rewards.put(creature.getName(), amount);
switch (creature) {
case PIG:
_config.setProperty("Pig", amount);
break;
case SHEEP:
_config.setProperty("Sheep", amount);
break;
case COW:
_config.setProperty("Cow", amount);
break;
case CHICKEN:
_config.setProperty("Chicken", amount);
break;
case SQUID:
_config.setProperty("Squid", amount);
break;
case SPIDER:
_config.setProperty("Spider", amount);
break;
case SLIME:
_config.setProperty("Slime", amount);
break;
case ZOMBIE:
_config.setProperty("Zombie", amount);
break;
case SKELETON:
_config.setProperty("Skeleton", amount);
break;
case PIG_ZOMBIE:
_config.setProperty("Pigman", amount);
break;
case CREEPER:
_config.setProperty("Creeper", amount);
break;
case GHAST:
_config.setProperty("Ghast", amount);
break;
}
this.saveConfig();
}
}

106
src/com/stevenmattera/MobBounty/Listeners/DeathListener.java

@ -1,106 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty.Listeners;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account;
import com.stevenmattera.MobBounty.Main;
import com.stevenmattera.MobBounty.Utils.Colors;
public class DeathListener extends EntityListener {
private final Main _plugin;
private Map<Entity, Player> _deathNote;
// ----
// ==== Constructor Method ====
// ----
public DeathListener(Main plugin) {
_plugin = plugin; //Save our Main Plugin to be used later.
_deathNote = new HashMap<Entity, Player>(); //Create our Death Note of KILLING!!!!
}
// ----
// ==== Private Methods ====
// ----
private void entityKilledByPlayer(Entity entity, Player player) {
if (_plugin.iConomy != null) { //Was iConomy hooked?
if ((_plugin.Permissions != null && _plugin.Permissions.has(player, "MobBounty.mb")) || (_plugin.Permissions == null)) {
double reward = _plugin.getConfig().getReward(entity); //Get how much the reward is based on the mob.
if (reward > 0) { //Was there a reward?
double multiplier = _plugin.getConfig().getWorldMultiplier(entity.getWorld()); //Get the multiplier for the world.
Account account = iConomy.getBank().getAccount(player.getName()); //Get the player's account.
account.add(reward*multiplier); //Give the player their reward.
player.sendRawMessage(Colors.DarkGreen+"You have been awarded "+Colors.White+(reward*multiplier)+Colors.DarkGreen+" "+iConomy.getBank().getCurrency()+"(s)");
}
}
}
}
// ----
// ==== Public Methods ====
// ----
public void onEntityDamage(EntityDamageEvent event) {
if (_plugin.iConomy != null) { //Was iConomy hooked?
if (!(event.isCancelled())) { //Was this event cancelled?
if (event.getEntity() instanceof LivingEntity && !(event.getEntity() instanceof Player)) { //Was it something other than a player that was damaged.
LivingEntity entity = (LivingEntity) event.getEntity(); //Grab our LivingEntity that was damaged.
if (entity.getHealth() - event.getDamage() <= 0) { //Was the damage fatal?
if (event instanceof EntityDamageByEntityEvent) { //Were the damage dealt by another entity?
EntityDamageByEntityEvent subevent = (EntityDamageByEntityEvent)event; //Change our event type accordingly.
if (subevent.getDamager() instanceof Player) { //Was it a player that wounded our mob?
Player damager = (Player) subevent.getDamager(); //Get our lucky player.
if (_deathNote.get(event.getEntity()) == null) //See if our mob is already in the Death Note!
_deathNote.put(event.getEntity(), damager); //Add our mob to the Death Note to be killed by our player.
}
}
else if (event instanceof EntityDamageByProjectileEvent) { //or was the damage dealt by a projectile?
EntityDamageByProjectileEvent subevent = (EntityDamageByProjectileEvent)event; //Change our event type accordingly.
if (subevent.getDamager() instanceof Player) { //Was it a player that wounded our mob?
Player damager = (Player) subevent.getDamager(); //Get our lucky player.
if (_deathNote.get(event.getEntity()) == null) //See if our mob is already in the Death Note!
_deathNote.put(event.getEntity(), damager); //Add our mob to the Death Note to be killed by our player.
}
}
}
}
}
}
}
public void onEntityDeath(EntityDeathEvent event) {
Player damager = _deathNote.get(event.getEntity()); //Grab our killer from the Death Note.
if (damager != null) { //Were we able to grab a killer?
this.entityKilledByPlayer(event.getEntity(), damager); //Lets reward our killer!
_deathNote.remove(event.getEntity()); //Remove them from the Death Note as we are done with them.
}
}
}

56
src/com/stevenmattera/MobBounty/Listeners/PluginListener.java

@ -1,56 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty.Listeners;
import org.bukkit.event.server.PluginEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.stevenmattera.MobBounty.Main;
public class PluginListener extends ServerListener {
private static Main _plugin = null;
// ----
// ==== Constructor Method ====
// ----
public PluginListener(Main plugin) {
if (_plugin == null) _plugin = plugin;
}
// ----
// ==== Public Method ====
// ----
public void onPluginEnabled(PluginEvent event) {
if (_plugin != null) {
if (_plugin.iConomy == null) {
Plugin iConomy = _plugin.getServer().getPluginManager().getPlugin("iConomy");
if (iConomy != null) {
if (iConomy.isEnabled()) {
_plugin.iConomy = (iConomy) iConomy;
_plugin.getLogger().info("[MobBounty] hooked into iConomy.");
}
}
}
if (_plugin.Permissions == null) {
Plugin Permissions = _plugin.getServer().getPluginManager().getPlugin("Permissions");
if (Permissions != null) {
if (Permissions.isEnabled()) {
_plugin.Permissions = ((Permissions) Permissions).getHandler();
_plugin.getLogger().info("[MobBounty] hooked into Permissions/GroupManager.");
}
}
}
}
}
}

101
src/com/stevenmattera/MobBounty/Main.java

@ -1,101 +0,0 @@
// MobBounty
// Version 1.01
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty;
import java.util.logging.Logger;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.stevenmattera.MobBounty.Commands.mb;
import com.stevenmattera.MobBounty.Commands.mbmulti;
import com.stevenmattera.MobBounty.Commands.mbreward;
import com.stevenmattera.MobBounty.Listeners.DeathListener;
import com.stevenmattera.MobBounty.Listeners.PluginListener;
public class Main extends JavaPlugin {
private final DeathListener _deathListener = new DeathListener(this);
private final PluginListener _pluginListener = new PluginListener(this);
private final mb _mb = new mb(this);
private final mbmulti _mbmulti = new mbmulti(this);
private final mbreward _mbreward = new mbreward(this);
private final Logger _logger = Logger.getLogger("Minecraft");
private Config _config;
public iConomy iConomy = null;
public PermissionHandler Permissions = null;
// ----
// ==== Overridden Methods ====
// ----
@Override
public void onEnable() {
_logger.info("[MobBounty] v"+this.getDescription().getVersion()+" (Helium) loaded.");
_logger.info("[MobBounty] Developed by: [Mattera, Steven (IchigoKyger)].");
_config = new Config(this);
getCommand("mb").setExecutor(_mb);
getCommand("mbmulti").setExecutor(_mbmulti);
getCommand("mbreward").setExecutor(_mbreward);
if (iConomy == null) {
Plugin iConomyPlugin = this.getServer().getPluginManager().getPlugin("iConomy");
if (iConomyPlugin != null) {
if (iConomyPlugin.isEnabled()) {
iConomy = (iConomy) iConomyPlugin;
this.getLogger().info("[MobBounty] hooked into iConomy.");
}
}
}
if (Permissions == null) {
Plugin PermissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
if (PermissionsPlugin != null) {
if (PermissionsPlugin.isEnabled()) {
Permissions = ((Permissions) PermissionsPlugin).getHandler();
this.getLogger().info("[MobBounty] hooked into Permissions/GroupManager.");
}
}
}
this.getServer().getPluginManager().registerEvent(Event.Type.ENTITY_DAMAGE, _deathListener, Priority.Monitor, this);
this.getServer().getPluginManager().registerEvent(Event.Type.ENTITY_DEATH, _deathListener, Priority.Monitor, this);
if (iConomy == null || Permissions == null)
this.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, _pluginListener, Priority.Monitor, this);
}
@Override
public void onDisable() {
_config.saveConfig();
_logger.info("[MobBounty] Plugin disabled.");
}
// ----
// ==== Public Methods ====
// ----
public Config getConfig() {
return _config;
}
public Logger getLogger() {
return _logger;
}
}

25
src/com/stevenmattera/MobBounty/Utils/Colors.java

@ -1,25 +0,0 @@
// MobBounty
// Version 1.0
//
// Created By Steven Mattera
package com.stevenmattera.MobBounty.Utils;
public class Colors {
public static String Black = "\u00A70";
public static String DarkBlue = "\u00A71";
public static String DarkGreen = "\u00A72";
public static String DarkTeal = "\u00A73";
public static String DarkRed = "\u00A74";
public static String Purple = "\u00A75";
public static String Gold = "\u00A76";
public static String Gray = "\u00A77";
public static String DarkGray = "\u00A78";
public static String Blue = "\u00A79";
public static String Green = "\u00A7A";
public static String Teal = "\u00A7B";
public static String Red = "\u00A7C";
public static String Pink = "\u00A7D";
public static String Yellow = "\u00A7E";
public static String White = "\u00A7F";
}

60
src/plugin.yml

@ -1,20 +1,54 @@
name: MobBounty
main: com.stevenmattera.MobBounty.Main
version: 1.02
website: http://stevenmattera.com
main: net.mcbat.MobBounty.Main
version: 2.00
website: http://mc-bat.net
author: Steven Mattera
description: Simple plugin for iConomy that pays players for killing mobs.
description: Simple plugin for iConomy that pays/fines players for killing mobs.
commands:
mb:
description: View rewards.
description: View rewards and fines.
usage: /<command>
mbreward:
description: Modify reward amount per mob.
alias:
- mobbounty
mbg:
description: Modify the general settings.
usage: /<command> <property> <value>
alias:
- mbgeneral
mbr:
description: Modify the default reward/fine of a mob.
usage: /<command> <mob> <amount>
aliases:
- mbr
mbmulti:
description: Modify multiplication amount per world.
alias:
- mbreward
mbwr:
description: Modify reward/fine of a mob in a world.
usage: /<command> <world> <mob> <amount>
alias:
- mbworldreward
mbem:
description: Modify multiplier per environment.
usage: /<command> <normal|nether> <amount>
alias:
- mbenvmulti
mbtm:
description: Modify multiplier per time.
usage: /<command> <day|sunset|night|sunrise> <amount>
alias:
- mbtimemulti
mbwm:
description: Modify multiplier per world.
usage: /<command> <world> <amount>
aliases:
- mbm
alias:
- mbworldmulti
mbs:
description: Save the config files.
usage: /<command>
alias:
- mbsave
mbl:
description: Load the config files.
usage: /<command>
alias:
- mbload
depend:
- iConomy
Loading…
Cancel
Save