Browse Source

4.0 Source Code

main
Nichole Mattera 10 years ago
parent
commit
cf9db47d38
  1. 9
      src/com/stevenmattera/MobLoot/Commands/MobLoot.java
  2. 36
      src/com/stevenmattera/MobLoot/ConfigManager.java
  3. 31
      src/com/stevenmattera/MobLoot/ListenerManager.java
  4. 160
      src/com/stevenmattera/MobLoot/Misc/CreatureID.java
  5. 49
      src/com/stevenmattera/MobLoot/Misc/ItemInfo.java
  6. 28
      src/com/stevenmattera/MobLoot/MobLoot.java
  7. 113
      src/net/mcbat/MobLoot/Utils/CreatureID.java
  8. 6
      src/plugin.yml

9
src/net/mcbat/MobLoot/Commands/MobLoot.java → src/com/stevenmattera/MobLoot/Commands/MobLoot.java

@ -1,6 +1,5 @@
package net.mcbat.MobLoot.Commands;
package com.stevenmattera.MobLoot.Commands;
import net.mcbat.MobLoot.Utils.CreatureID;
import org.bukkit.ChatColor;
import org.bukkit.World;
@ -8,10 +7,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.stevenmattera.MobLoot.Misc.CreatureID;
public class MobLoot {
private final net.mcbat.MobLoot.MobLoot _plugin;
private final com.stevenmattera.MobLoot.MobLoot _plugin;
public MobLoot(net.mcbat.MobLoot.MobLoot plugin) {
public MobLoot(com.stevenmattera.MobLoot.MobLoot plugin) {
_plugin = plugin;
}

36
src/net/mcbat/MobLoot/Config/ConfigManager.java → src/com/stevenmattera/MobLoot/ConfigManager.java

@ -1,4 +1,4 @@
package net.mcbat.MobLoot.Config;
package com.stevenmattera.MobLoot;
import java.io.File;
import java.util.ArrayList;
@ -7,17 +7,18 @@ import java.util.Iterator;
import java.util.List;
import org.bukkit.World;
import org.bukkit.util.config.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import com.stevenmattera.MobLoot.Misc.CreatureID;
import com.stevenmattera.MobLoot.Misc.ItemInfo;
import net.mcbat.MobLoot.MobLoot;
import net.mcbat.MobLoot.Utils.CreatureID;
import net.mcbat.MobLoot.Utils.ItemInfo;
public class ConfigManager {
private final MobLoot _plugin;
private final File _configFile;
private Configuration _config;
private FileConfiguration _config;
private final HashMap<String, HashMap<CreatureID, ArrayList<ItemInfo>>> _worldDropTable;
@ -34,8 +35,13 @@ public class ConfigManager {
List<World> worlds = _plugin.getServer().getWorlds();
Iterator<World> worldIterator = worlds.iterator();
_config = new Configuration(_configFile);
_config.load();
_config = new YamlConfiguration();
try {
_config.load(_configFile);
} catch (Exception e) {
e.printStackTrace();
}
while (worldIterator.hasNext()) {
World world = worldIterator.next();
@ -47,7 +53,11 @@ public class ConfigManager {
}
public void saveConfig() {
_config.save();
try {
_config.save(_configFile);
} catch (Exception e) {
e.printStackTrace();
}
_plugin.getMinecraftLogger().info("[MobLoot] Config saved.");
}
@ -78,7 +88,7 @@ public class ConfigManager {
dropTable.put(creature, itemDrops);
_config.setProperty(worldName+"."+creature.getName(), itemDropsData);
_config.set(worldName+"."+creature.getName(), itemDropsData);
_worldDropTable.put(worldName, dropTable);
}
@ -86,7 +96,7 @@ public class ConfigManager {
List<World> worlds = _plugin.getServer().getWorlds();
Iterator<World> worldIterator = worlds.iterator();
_config = new Configuration(_configFile);
_config = new YamlConfiguration();
while (worldIterator.hasNext()) {
World world = worldIterator.next();
@ -97,7 +107,7 @@ public class ConfigManager {
ArrayList<ItemInfo> creatureDrop = new ArrayList<ItemInfo>();
dropTable.put(creature, creatureDrop);
_config.setProperty(world.getName()+"."+creature.getName(), creatureDrop);
_config.set(world.getName()+"."+creature.getName(), creatureDrop);
}
_worldDropTable.put(world.getName(), dropTable);
@ -111,7 +121,7 @@ public class ConfigManager {
HashMap<CreatureID, ArrayList<ItemInfo>> dropTable = new HashMap<CreatureID, ArrayList<ItemInfo>>();
for (CreatureID creature : CreatureID.values()) {
ArrayList<String> creatureDropData = (ArrayList<String>) _config.getStringList(worldName+"."+creature.getName(), new ArrayList<String>());
ArrayList<String> creatureDropData = (ArrayList<String>) _config.getStringList(worldName+"."+creature.getName());
ArrayList<ItemInfo> creatureDrop = new ArrayList<ItemInfo>();
Iterator<String> creatureDropDataIterator = creatureDropData.iterator();

31
src/net/mcbat/MobLoot/Listeners/MobLootEntityListener.java → src/com/stevenmattera/MobLoot/ListenerManager.java

@ -1,42 +1,39 @@
package net.mcbat.MobLoot.Listeners;
package com.stevenmattera.MobLoot;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import net.mcbat.MobLoot.MobLoot;
import net.mcbat.MobLoot.Utils.CreatureID;
import net.mcbat.MobLoot.Utils.ItemInfo;
import org.bukkit.Bukkit;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.PluginManager;
public class MobLootEntityListener extends EntityListener {
import com.stevenmattera.MobLoot.Misc.CreatureID;
import com.stevenmattera.MobLoot.Misc.ItemInfo;
public class ListenerManager implements Listener {
private final MobLoot _plugin;
public MobLootEntityListener(MobLoot plugin) {
public ListenerManager(MobLoot plugin) {
_plugin = plugin;
}
public void registerEvents() {
PluginManager pm = _plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_DEATH, this, Priority.Normal, _plugin);
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDeath(EntityDeathEvent event) {
if (!(event.getEntity() instanceof LivingEntity) || event.getEntity() instanceof HumanEntity)
return;
@ -59,7 +56,7 @@ public class MobLootEntityListener extends EntityListener {
}
}
CreatureID creature = CreatureID.fromEntity(mob, (player != null)?player.getName():"");
CreatureID creature = CreatureID.valueOf(mob, player);
if (creature != null) {
ArrayList<ItemInfo> creatureDrop = _plugin.getConfigManager().getDrop(mob.getWorld().getName(), creature);

160
src/com/stevenmattera/MobLoot/Misc/CreatureID.java

@ -0,0 +1,160 @@
/*
* MobBounty - Version 5.0 (Neon)
* CreatureID.java - Creature Enumeration used for Identifying Creatures.
*
* Programmed by: Steven Mattera
* Special Thanks to: Bukkit Team for Identification Code from CraftEntity.java:36-102
*
*/
package com.stevenmattera.MobLoot.Misc;
import org.bukkit.entity.*;
public enum CreatureID {
ANIMALS("Animals"),
BLAZE("Blaze"),
CAVE_SPIDER("CaveSpider"),
CHICKEN("Chicken"),
COMPLEX_MOB("ComplexMob"),
COW("Cow"),
CREATURE("Creature"),
CREEPER("Creeper"),
ELECTRIFIED_CREEPER("ElectrifiedCreeper"),
ENDERDRAGON("Enderdragon"),
ENDERMAN("Enderman"),
FLYING("Flying"),
GHAST("Ghast"),
GIANT("Giant"),
LIVING_MOB("LivingMob"),
MAGMA_CUBE_TINY("MagmaCubeTiny"),
MAGMA_CUBE_SMALL("MagmaCubeSmall"),
MAGMA_CUBE_BIG("MagmaCubeBig"),
MONSTER("Monster"),
MUSHROOM_COW("MushroomCow"),
PIG("Pig"),
PIG_ZOMBIE("PigZombie"),
SHEEP("Sheep"),
SILVERFISH("Silverfish"),
SKELETON("Skeleton"),
SLIME_TINY("SlimeTiny"),
SLIME_SMALL("SlimeSmall"),
SLIME_BIG("SlimeBig"),
SNOWMAN("Snowman"),
SPIDER("Spider"),
SQUID("Squid"),
VILLAGER("Villager"),
WATER_MOB("WaterMob"),
WOLF("Wolf"),
WOLF_TAMED("TamedWolf"),
WOLF_TAMED_BY_SELF("SelfTamedWolf"),
ZOMBIE("Zombie");
private final String _name;
private CreatureID(final String name) {
_name = name;
}
public String getName() {
return _name;
}
public static CreatureID fromName(String name) {
for (CreatureID id : CreatureID.values()) {
if (id.name().equalsIgnoreCase(name)) { return id; }
}
return null;
}
public static CreatureID valueOf(Entity entity, Player player) {
// Logic from CraftEntity.java:35-102
// Order is important!
if (entity instanceof Entity) {
if (entity instanceof Creature) {
// Animals
if (entity instanceof Animals) {
if (entity instanceof Chicken) { return CreatureID.CHICKEN; }
else if (entity instanceof Cow) {
if (entity instanceof MushroomCow) { return CreatureID.MUSHROOM_COW; }
else { return CreatureID.COW; }
}
else if (entity instanceof Pig) { return CreatureID.PIG; }
else if (entity instanceof Wolf) {
Wolf wolfEntity = (Wolf) entity;
if (wolfEntity.isTamed() && wolfEntity.getOwner() instanceof Player) {
Player owner = (Player) wolfEntity.getOwner();
if (owner.getName().equalsIgnoreCase(player.getName())) { return CreatureID.WOLF_TAMED_BY_SELF; }
else { return CreatureID.WOLF_TAMED; }
}
else { return CreatureID.WOLF; }
}
else if (entity instanceof Sheep) { return CreatureID.SHEEP; }
else { return CreatureID.ANIMALS; }
}
// Monsters
else if (entity instanceof Monster) {
if (entity instanceof Zombie) {
if (entity instanceof PigZombie) { return CreatureID.PIG_ZOMBIE; }
else { return CreatureID.ZOMBIE; }
}
else if (entity instanceof Creeper) {
if (((Creeper) entity).isPowered()) { return CreatureID.ELECTRIFIED_CREEPER; }
else { return CreatureID.CREEPER; }
}
else if (entity instanceof Enderman) { return CreatureID.ENDERMAN; }
else if (entity instanceof Silverfish) { return CreatureID.SILVERFISH; }
else if (entity instanceof Giant) { return CreatureID.GIANT; }
else if (entity instanceof Skeleton) { return CreatureID.SKELETON; }
else if (entity instanceof Blaze) { return CreatureID.BLAZE; }
else if (entity instanceof Spider) {
if (entity instanceof CaveSpider) { return CreatureID.CAVE_SPIDER; }
else { return CreatureID.SPIDER; }
}
else { return CreatureID.MONSTER; }
}
// Water Animals
else if (entity instanceof WaterMob) {
if (entity instanceof Squid) { return CreatureID.SQUID; }
else { return CreatureID.WATER_MOB; }
}
else if (entity instanceof Snowman) { return CreatureID.SNOWMAN; }
else if (entity instanceof Villager) { return CreatureID.VILLAGER; }
else { return CreatureID.CREATURE; }
}
// Slimes
else if (entity instanceof Slime) {
if (entity instanceof MagmaCube) {
MagmaCube magmaCubeEntity = (MagmaCube) entity;
if (magmaCubeEntity.getSize() == 1) { return CreatureID.MAGMA_CUBE_TINY; }
else if (magmaCubeEntity.getSize() == 2) { return CreatureID.MAGMA_CUBE_SMALL; }
else if (magmaCubeEntity.getSize() > 2) { return CreatureID.MAGMA_CUBE_BIG; }
}
else {
Slime slimeCubeEntity = (Slime) entity;
if (slimeCubeEntity.getSize() == 1) { return CreatureID.SLIME_TINY; }
else if (slimeCubeEntity.getSize() == 2) { return CreatureID.SLIME_SMALL; }
else if (slimeCubeEntity.getSize() > 2) { return CreatureID.SLIME_BIG; }
}
}
// Flying
else if (entity instanceof Flying) {
if (entity instanceof Ghast) { return CreatureID.GHAST; }
else { return CreatureID.FLYING; }
}
// Dragon
else if (entity instanceof ComplexLivingEntity) {
if (entity instanceof EnderDragon) { return CreatureID.ENDERDRAGON; }
else { return CreatureID.COMPLEX_MOB; }
}
else { return CreatureID.LIVING_MOB; }
}
return null;
}
}

49
src/net/mcbat/MobLoot/Utils/ItemInfo.java → src/com/stevenmattera/MobLoot/Misc/ItemInfo.java

@ -1,4 +1,4 @@
package net.mcbat.MobLoot.Utils;
package com.stevenmattera.MobLoot.Misc;
public class ItemInfo {
public int itemID;
@ -79,9 +79,9 @@ public class ItemInfo {
}
private boolean isItem(int item) {
if (item >= 0 && item <= 115) return true;
else if (item >= 256 && item <= 372) return true;
else if (item >= 2256 && item <= 2257) return true;
if (item >= 0 && item <= 124) return true;
else if (item >= 256 && item <= 385) return true;
else if (item >= 2256 && item <= 2266) return true;
return false;
}
@ -90,38 +90,56 @@ public class ItemInfo {
if (data == 0)
return true;
// Pressure Plates and Coal/Charcoal
if (item == 70 || item == 72 || item == 263) {
if (data == 0 || data == 1) return true;
else return false;
}
if (item == 17 || item == 18 || item == 31 || item == 84 || item == 97) {
// Tall Grass, and Silverfish
if ( item == 31 || item == 97) {
if (data >= 0 && data <= 2) return true;
else return false;
}
else if (item == 43 || item == 44 || item == 53 || item == 65 || item == 67 || item == 86 || item == 91 || item == 98) {
// Wood, Leaves, Ladders, Nether Wart, Cauldron
else if (item == 17 || item == 18 || item == 65 || item == 86 || item == 91 || item == 98 || item == 115 || item == 118) {
if (data >= 0 && data <= 3) return true;
else return false;
}
else if (item == 50 || item == 75 || item == 76 || item == 92) {
// Stairs, Brewing Stand, End Portal Frame
else if (item == 53 || item == 67 || item == 108 || item == 109 || item == 114 || item == 117 || item == 120) {
if (data >= 0 && data <= 4) return true;
else return false;
}
// Double Slabs, Torches, Redstone Torches, and Cake
else if (item == 43 || item == 44 || item == 50 || item == 75 || item == 76 || item == 92) {
if (data >= 0 && data <= 5) return true;
else return false;
}
// Wheat, Trapdoor, Pumpkin, Melon, Fence Gate
else if (item == 59 || item == 96 || item == 104 || item == 105 || item == 107) {
if (data >= 0 && data <= 7) return true;
else return false;
}
else if (item == 60) {
// Farmland, Vines
else if (item == 60 || item == 106) {
if (data >= 0 && data <= 8) return true;
else return false;
}
// Rails
else if (item == 27 || item == 28 || item == 66) {
if (data >= 0 && data <= 9) return true;
else return false;
}
// Mushrooms
else if (item == 99 || item == 100) {
if (data >= 0 && data <= 10) return true;
else return false;
}
// Jukebox
else if (item == 84) {
if (data >= 0 && data <= 11) return true;
else return false;
}
else if (item == 6 || item == 8 || item == 9 || item == 11 || item == 35 || item == 51 || item == 55 || item == 63 || item == 64 || item == 71 || item == 81 || item == 83 || item == 93 || item == 94 || item == 106 || item == 351) {
if (data >= 0 && data <= 15) return true;
else return false;
@ -139,12 +157,25 @@ public class ItemInfo {
else if (data >= 8 && data <= 11) return true;
else return false;
}
// Pistons
else if (item == 29 || item == 33 || item == 34) {
if (data >= 0 && data <= 5) return true;
else if (data >= 8 && data <= 13) return true;
else return false;
}
else if ((item >= 256 && item <= 259) || (item >= 267 && item <= 279) || (item >= 283 && item <= 286) || (item >= 290 && item <= 294) || (item >= 298 && item <= 317) || item == 359) {
// Spawn Eggs
else if (item == 383) {
if (data >= 50 && data <= 63) return true;
else if (data >= 90 && data <= 99) return true;
else if (data == 120) return true;
else return false;
}
// Potions - Screw validation that.
else if (item == 373) {
return true;
}
// Items with Damage
else if ((item >= 256 && item <= 259) || item == 261 || (item >= 267 && item <= 279) || (item >= 283 && item <= 286) || (item >= 290 && item <= 294) || (item >= 298 && item <= 317) || item == 346 || item == 359) {
return true;
}

28
src/net/mcbat/MobLoot/MobLoot.java → src/com/stevenmattera/MobLoot/MobLoot.java

@ -1,9 +1,7 @@
package net.mcbat.MobLoot;
package com.stevenmattera.MobLoot;
import java.util.logging.Logger;
import net.mcbat.MobLoot.Config.ConfigManager;
import net.mcbat.MobLoot.Listeners.MobLootEntityListener;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -12,25 +10,33 @@ import org.bukkit.plugin.java.JavaPlugin;
public class MobLoot extends JavaPlugin {
private final Logger _logger = Logger.getLogger("Minecraft");
private ConfigManager _configManager;
private net.mcbat.MobLoot.Commands.MobLoot _mobLoot;
@SuppressWarnings("unused")
private ListenerManager _listenerManager;
private com.stevenmattera.MobLoot.Commands.MobLoot _mobLoot;
@Override
public void onEnable() {
_logger.info("[MobLoot] v"+this.getDescription().getVersion()+" (Carbon) enabled.");
_logger.info("[MobLoot] Developed by: [Mattera, Steven (IchigoKyger)].");
_logger.info("[MobLoot] v4.0 (Oxygen) enabled.");
_logger.info("[MobLoot] Developed by: [Mattera, Steven]");
_configManager = new ConfigManager(this);
_mobLoot = new net.mcbat.MobLoot.Commands.MobLoot(this);
(new MobLootEntityListener(this)).registerEvents();
_listenerManager = new ListenerManager(this);
_mobLoot = new com.stevenmattera.MobLoot.Commands.MobLoot(this);
}
@Override
public void onDisable() {
_configManager.saveConfig();
_logger.info("[MobLoot] v"+this.getDescription().getVersion()+" (Carbon) disabled.");
_configManager = null;
_listenerManager = null;
_mobLoot = null;
_logger.info("[MobLoot] v4.0 (Oxygen) disabled.");
}
@Override

113
src/net/mcbat/MobLoot/Utils/CreatureID.java

@ -1,113 +0,0 @@
package net.mcbat.MobLoot.Utils;
import net.minecraft.server.EntityWolf;
import org.bukkit.craftbukkit.entity.CraftWolf;
import org.bukkit.entity.Animals;
import org.bukkit.entity.CaveSpider;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Giant;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Pig;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Silverfish;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Zombie;
public enum CreatureID {
CAVE_SPIDER("CaveSpider"),
CHICKEN("Chicken"),
COW("Cow"),
CREEPER("Creeper"),
ELECTRIFIED_CREEPER("ElectrifiedCreeper"),
ENDERMAN("Enderman"),
GHAST("Ghast"),
GIANT("Giant"),
MONSTER("Monster"),
PIG("Pig"),
PIG_ZOMBIE("PigZombie"),
SHEEP("Sheep"),
SILVERFISH("Silverfish"),
SKELETON("Skeleton"),
SLIME("Slime"),
SPIDER("Spider"),
SQUID("Squid"),
WOLF("Wolf"),
WOLF_TAMED("TamedWolf"),
WOLF_TAMED_BY_SELF("SelfTamedWolf"),
ZOMBIE("Zombie");
private String _name;
private CreatureID(String name) {
_name = name;
}
public String getName() {
return _name;
}
public static CreatureID fromName(String name) {
for (CreatureID id : CreatureID.values()) {
if (id.name().equalsIgnoreCase(name))
return id;
}
return null;
}
public static CreatureID fromEntity(Entity entity, String playerName) {
// Order borrowed from CraftBukkit->CraftEntity.java (Thank You! =D)
if (entity instanceof Animals) {
if (entity instanceof Chicken) return CreatureID.CHICKEN;
else if (entity instanceof Cow) return CreatureID.COW;
else if (entity instanceof Pig) return CreatureID.PIG;
else if (entity instanceof Wolf) {
EntityWolf wolfEntity = ((CraftWolf) entity).getHandle();
if (wolfEntity.getOwnerName().equalsIgnoreCase(""))
return CreatureID.WOLF;
else if (wolfEntity.getOwnerName().equalsIgnoreCase(playerName))
return CreatureID.WOLF_TAMED_BY_SELF;
else
return CreatureID.WOLF_TAMED;
}
else if (entity instanceof Sheep) return CreatureID.SHEEP;
}
else if (entity instanceof Monster) {
if (entity instanceof Zombie) {
if (entity instanceof PigZombie) return CreatureID.PIG_ZOMBIE;
else return CreatureID.ZOMBIE;
}
else if (entity instanceof Creeper) {
if (((Creeper) entity).isPowered()) return CreatureID.ELECTRIFIED_CREEPER;
else return CreatureID.CREEPER;
}
else if (entity instanceof Enderman) return CreatureID.ENDERMAN;
else if (entity instanceof Silverfish) return CreatureID.SILVERFISH;
else if (entity instanceof Giant) return CreatureID.GIANT;
else if (entity instanceof Skeleton) return CreatureID.SKELETON;
else if (entity instanceof Spider) {
if (entity instanceof CaveSpider) return CreatureID.CAVE_SPIDER;
else return CreatureID.SPIDER;
}
else return CreatureID.MONSTER;
}
else if (entity instanceof Squid) return CreatureID.SQUID;
else if (entity instanceof Slime) return CreatureID.SLIME;
else if (entity instanceof Ghast) return CreatureID.GHAST;
return null;
}
}

6
src/plugin.yml

@ -1,8 +1,8 @@
name: MobLoot
main: net.mcbat.MobLoot.MobLoot
main: com.stevenmattera.MobLoot.MobLoot
author: Steven Mattera
website: http://mc-bat.net
version: 3.01
website: http://stevenmattera.com
version: 4.0
commands:
mobloot:
aliases: [ml, loot]

Loading…
Cancel
Save