mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-16 15:38:14 +01:00
Read desc
Convert the disguisetype to use entitytypes dymanically set when the disguisetypes are loaded, so if the entitytype doesn't exist. The plugin will still load.
This commit is contained in:
parent
ce14a91e9a
commit
1818f5f1e6
@ -131,6 +131,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
||||
}
|
||||
DisguiseType disguiseType = null;
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
if (type.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase(type.name()) || type.name().replace("_", "").equalsIgnoreCase(args[0])) {
|
||||
disguiseType = type;
|
||||
break;
|
||||
|
@ -86,6 +86,9 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
private void registerValues() {
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
if (disguiseType.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
Class watcherClass = null;
|
||||
try {
|
||||
String name;
|
||||
@ -117,17 +120,13 @@ public class LibsDisguises extends JavaPlugin {
|
||||
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + name + "Watcher");
|
||||
} catch (Exception ex) {
|
||||
// There is no watcher for this entity, or a error was thrown.
|
||||
try {
|
||||
Class c = disguiseType.getEntityType().getEntityClass();
|
||||
if (Ageable.class.isAssignableFrom(c)) {
|
||||
watcherClass = AgeableWatcher.class;
|
||||
} else if (LivingEntity.class.isAssignableFrom(c)) {
|
||||
watcherClass = LivingWatcher.class;
|
||||
} else {
|
||||
watcherClass = FlagWatcher.class;
|
||||
}
|
||||
} catch (Exception ex1) {
|
||||
ex1.printStackTrace();
|
||||
Class c = disguiseType.getEntityType().getEntityClass();
|
||||
if (Ageable.class.isAssignableFrom(c)) {
|
||||
watcherClass = AgeableWatcher.class;
|
||||
} else if (LivingEntity.class.isAssignableFrom(c)) {
|
||||
watcherClass = LivingWatcher.class;
|
||||
} else {
|
||||
watcherClass = FlagWatcher.class;
|
||||
}
|
||||
}
|
||||
disguiseType.setWatcherClass(watcherClass);
|
||||
|
@ -67,6 +67,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||
}
|
||||
DisguiseType type = null;
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
if (disguiseType.getEntityType() == null) {
|
||||
continue;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase(disguiseType.name())
|
||||
|| disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) {
|
||||
type = disguiseType;
|
||||
|
@ -52,6 +52,10 @@ public abstract class Disguise {
|
||||
protected void createDisguise(DisguiseType newType, boolean doSounds) {
|
||||
if (getWatcher() != null)
|
||||
return;
|
||||
if (newType.getEntityType() == null) {
|
||||
throw new RuntimeException("DisguiseType " + newType
|
||||
+ " was attempted to construct a disguise, but this version of craftbukkit does not have that entity");
|
||||
}
|
||||
// Set the disguise type
|
||||
disguiseType = newType;
|
||||
// Set the option to replace the sounds
|
||||
|
@ -4,131 +4,166 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public enum DisguiseType {
|
||||
ARROW(EntityType.ARROW, 60),
|
||||
ARROW(60),
|
||||
|
||||
BAT(EntityType.BAT),
|
||||
BAT(),
|
||||
|
||||
BLAZE(EntityType.BLAZE),
|
||||
BLAZE(),
|
||||
|
||||
BOAT(EntityType.BOAT, 1),
|
||||
BOAT(1),
|
||||
|
||||
CAVE_SPIDER(EntityType.CAVE_SPIDER),
|
||||
CAVE_SPIDER(),
|
||||
|
||||
CHICKEN(EntityType.CHICKEN),
|
||||
CHICKEN(),
|
||||
|
||||
COW(EntityType.COW),
|
||||
COW(),
|
||||
|
||||
CREEPER(EntityType.CREEPER),
|
||||
CREEPER(),
|
||||
|
||||
DONKEY(EntityType.HORSE),
|
||||
DONKEY(),
|
||||
|
||||
DROPPED_ITEM(EntityType.DROPPED_ITEM, 2, 1),
|
||||
DROPPED_ITEM(2, 1),
|
||||
|
||||
EGG(EntityType.EGG, 62),
|
||||
EGG(62),
|
||||
|
||||
ENDER_CRYSTAL(EntityType.ENDER_CRYSTAL, 51),
|
||||
ENDER_CRYSTAL(51),
|
||||
|
||||
ENDER_DRAGON(EntityType.ENDER_DRAGON),
|
||||
ENDER_DRAGON(),
|
||||
|
||||
ENDER_PEARL(EntityType.ENDER_PEARL, 65),
|
||||
ENDER_PEARL(65),
|
||||
|
||||
ENDER_SIGNAL(EntityType.ENDER_SIGNAL, 72),
|
||||
ENDER_SIGNAL(72),
|
||||
|
||||
ENDERMAN(EntityType.ENDERMAN),
|
||||
ENDERMAN(),
|
||||
|
||||
EXPERIENCE_ORB(EntityType.EXPERIENCE_ORB),
|
||||
EXPERIENCE_ORB(),
|
||||
|
||||
FALLING_BLOCK(EntityType.FALLING_BLOCK, 70, 1),
|
||||
FALLING_BLOCK(70, 1),
|
||||
|
||||
FIREBALL(EntityType.FIREBALL, 63, 0),
|
||||
FIREBALL(63, 0),
|
||||
|
||||
FIREWORK(EntityType.FIREWORK, 76),
|
||||
FIREWORK(76),
|
||||
|
||||
FISHING_HOOK(EntityType.FISHING_HOOK, 90),
|
||||
FISHING_HOOK(90),
|
||||
|
||||
GHAST(EntityType.GHAST),
|
||||
GHAST(),
|
||||
|
||||
GIANT(EntityType.GIANT),
|
||||
GIANT(),
|
||||
|
||||
HORSE(EntityType.HORSE),
|
||||
HORSE(),
|
||||
|
||||
IRON_GOLEM(EntityType.IRON_GOLEM),
|
||||
IRON_GOLEM(),
|
||||
|
||||
ITEM_FRAME(EntityType.ITEM_FRAME, 71),
|
||||
ITEM_FRAME(71),
|
||||
|
||||
LEASH_HITCH(EntityType.LEASH_HITCH, 77),
|
||||
LEASH_HITCH(77),
|
||||
|
||||
MAGMA_CUBE(EntityType.MAGMA_CUBE),
|
||||
MAGMA_CUBE(),
|
||||
|
||||
MINECART(EntityType.MINECART, 10, 0),
|
||||
MINECART(10, 0),
|
||||
|
||||
MINECART_CHEST(EntityType.MINECART_CHEST, 10, 1),
|
||||
MINECART_CHEST(10, 1),
|
||||
|
||||
MINECART_FURNACE(EntityType.MINECART_FURNACE, 10, 2),
|
||||
MINECART_FURNACE(10, 2),
|
||||
|
||||
MINECART_HOPPER(EntityType.MINECART_HOPPER, 10),
|
||||
MINECART_HOPPER(10),
|
||||
|
||||
MINECART_MOB_SPAWNER(EntityType.MINECART_MOB_SPAWNER, 10, 4),
|
||||
MINECART_MOB_SPAWNER(10, 4),
|
||||
|
||||
MINECART_TNT(EntityType.MINECART_TNT, 10, 3),
|
||||
MINECART_TNT(10, 3),
|
||||
|
||||
MULE(EntityType.HORSE),
|
||||
MULE(),
|
||||
|
||||
MUSHROOM_COW(EntityType.MUSHROOM_COW),
|
||||
MUSHROOM_COW(),
|
||||
|
||||
OCELOT(EntityType.OCELOT),
|
||||
OCELOT(),
|
||||
|
||||
PAINTING(EntityType.PAINTING),
|
||||
PAINTING(),
|
||||
|
||||
PIG(EntityType.PIG),
|
||||
PIG(),
|
||||
|
||||
PIG_ZOMBIE(EntityType.PIG_ZOMBIE),
|
||||
PIG_ZOMBIE(),
|
||||
|
||||
PLAYER(EntityType.PLAYER),
|
||||
PLAYER(),
|
||||
|
||||
PRIMED_TNT(EntityType.PRIMED_TNT, 50),
|
||||
PRIMED_TNT(50),
|
||||
|
||||
SHEEP(EntityType.SHEEP),
|
||||
SHEEP(),
|
||||
|
||||
SILVERFISH(EntityType.SILVERFISH),
|
||||
SILVERFISH(),
|
||||
|
||||
SKELETON(EntityType.SKELETON),
|
||||
SKELETON(),
|
||||
|
||||
SKELETON_HORSE(EntityType.HORSE),
|
||||
SKELETON_HORSE(),
|
||||
|
||||
SLIME(EntityType.SLIME),
|
||||
SLIME(),
|
||||
|
||||
SMALL_FIREBALL(EntityType.SMALL_FIREBALL, 64, 0),
|
||||
SMALL_FIREBALL(64, 0),
|
||||
|
||||
SNOWBALL(EntityType.SNOWBALL, 61),
|
||||
SNOWBALL(61),
|
||||
|
||||
SNOWMAN(EntityType.SNOWMAN),
|
||||
SNOWMAN(),
|
||||
|
||||
SPIDER(EntityType.SPIDER),
|
||||
SPIDER(),
|
||||
|
||||
SPLASH_POTION(EntityType.SPLASH_POTION, 73),
|
||||
SPLASH_POTION(73),
|
||||
|
||||
SQUID(EntityType.SQUID),
|
||||
SQUID(),
|
||||
|
||||
THROWN_EXP_BOTTLE(EntityType.THROWN_EXP_BOTTLE, 75),
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
|
||||
UNDEAD_HORSE(EntityType.HORSE),
|
||||
UNDEAD_HORSE(),
|
||||
|
||||
VILLAGER(EntityType.VILLAGER),
|
||||
VILLAGER(),
|
||||
|
||||
WITCH(EntityType.WITCH),
|
||||
WITCH(),
|
||||
|
||||
WITHER(EntityType.WITHER),
|
||||
WITHER(),
|
||||
|
||||
WITHER_SKELETON(EntityType.SKELETON),
|
||||
WITHER_SKELETON(),
|
||||
|
||||
WITHER_SKULL(EntityType.WITHER_SKULL, 66),
|
||||
WITHER_SKULL(66),
|
||||
|
||||
WOLF(EntityType.WOLF),
|
||||
WOLF(),
|
||||
|
||||
ZOMBIE(EntityType.ZOMBIE),
|
||||
ZOMBIE(),
|
||||
|
||||
ZOMBIE_VILLAGER(EntityType.ZOMBIE);
|
||||
ZOMBIE_VILLAGER();
|
||||
static {
|
||||
for (DisguiseType type : values()) {
|
||||
try {
|
||||
EntityType entityType;
|
||||
switch (type) {
|
||||
case DONKEY:
|
||||
entityType = EntityType.HORSE;
|
||||
break;
|
||||
case MULE:
|
||||
entityType = EntityType.HORSE;
|
||||
break;
|
||||
case UNDEAD_HORSE:
|
||||
entityType = EntityType.HORSE;
|
||||
break;
|
||||
case SKELETON_HORSE:
|
||||
entityType = EntityType.HORSE;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
entityType = EntityType.ZOMBIE;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
entityType = EntityType.SKELETON;
|
||||
break;
|
||||
default:
|
||||
entityType = EntityType.valueOf(type.name());
|
||||
break;
|
||||
}
|
||||
if (entityType != null) {
|
||||
type.setEntityType(entityType);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
||||
return DisguiseType.valueOf(entityType.name());
|
||||
@ -140,8 +175,11 @@ public enum DisguiseType {
|
||||
private EntityType entityType;
|
||||
private Class watcherClass;
|
||||
|
||||
private DisguiseType(EntityType newType, int... obj) {
|
||||
entityType = newType;
|
||||
private void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
private DisguiseType(int... obj) {
|
||||
for (int i = 0; i < obj.length; i++) {
|
||||
int value = obj[i];
|
||||
switch (i) {
|
||||
|
Loading…
Reference in New Issue
Block a user