Less bugs. Still writing
This commit is contained in:
parent
c78843aa2a
commit
19b61395ee
@ -1,6 +1,5 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
@ -16,7 +15,9 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.CraftSound;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -44,6 +45,7 @@ public class DisguiseAPI {
|
||||
*/
|
||||
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
||||
disguises.put(entity instanceof Player ? ((Player) entity).getName() : entity.getUniqueId(), disguise);
|
||||
disguise.constructWatcher(entity.getType(), entity.getEntityId());
|
||||
refresh(entity);
|
||||
}
|
||||
|
||||
@ -94,7 +96,22 @@ public class DisguiseAPI {
|
||||
if (loc.equals(soundLoc)) {
|
||||
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
|
||||
if (disSound != null) {
|
||||
soundType = disSound.ownsSound(soundName);
|
||||
if (((CraftEntity) entity).getHandle().dead) {
|
||||
soundType = SoundType.DEATH;
|
||||
System.out.print(soundType);
|
||||
} else {
|
||||
boolean hasInvun = false;
|
||||
if (entity instanceof LivingEntity) {
|
||||
net.minecraft.server.v1_5_R3.EntityLiving e = ((CraftLivingEntity) entity)
|
||||
.getHandle();
|
||||
hasInvun = e.noDamageTicks == e.maxNoDamageTicks;
|
||||
} else {
|
||||
net.minecraft.server.v1_5_R3.Entity e = ((CraftEntity) entity).getHandle();
|
||||
hasInvun = e.isInvulnerable();
|
||||
}
|
||||
soundType = disSound.getType(soundName, !hasInvun);
|
||||
System.out.print(soundType + " " + hasInvun);
|
||||
}
|
||||
if (soundType != null) {
|
||||
disguisedEntity = entity;
|
||||
break;
|
||||
@ -107,22 +124,24 @@ public class DisguiseAPI {
|
||||
}
|
||||
}
|
||||
if (disguisedEntity != null) {
|
||||
// TODO Check if they been damage with invincibility ticks
|
||||
Sound sound = null;
|
||||
DisguiseSound dSound = DisguiseSound.getType(DisguiseAPI.getDisguise(disguisedEntity).getType().name());
|
||||
if (dSound != null)
|
||||
sound = dSound.getSound(soundType);
|
||||
if (sound == null) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
if (sound == Sound.STEP_GRASS) {
|
||||
World world = ((CraftEntity) disguisedEntity).getHandle().world;
|
||||
Block b = Block.byId[world.getTypeId(soundLoc.getBlockX(), soundLoc.getBlockY() - 1,
|
||||
soundLoc.getBlockZ())];
|
||||
if (b != null)
|
||||
mods.write(0, b.stepSound.getStepSound());
|
||||
Disguise disguise = DisguiseAPI.getDisguise(disguisedEntity);
|
||||
if (disguise.replaceSounds()) {
|
||||
Sound sound = null;
|
||||
DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name());
|
||||
if (dSound != null)
|
||||
sound = dSound.getSound(soundType);
|
||||
if (sound == null) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
mods.write(0, CraftSound.getSound(sound));
|
||||
if (sound == Sound.STEP_GRASS) {
|
||||
World world = ((CraftEntity) disguisedEntity).getHandle().world;
|
||||
Block b = Block.byId[world.getTypeId(soundLoc.getBlockX(), soundLoc.getBlockY() - 1,
|
||||
soundLoc.getBlockZ())];
|
||||
if (b != null)
|
||||
mods.write(0, b.stepSound.getStepSound());
|
||||
} else {
|
||||
mods.write(0, CraftSound.getSound(sound));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -151,7 +170,7 @@ public class DisguiseAPI {
|
||||
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
||||
.get(entity.getEntityId());
|
||||
if (entry != null) {
|
||||
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray();
|
||||
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
|
||||
for (EntityPlayer player : players) {
|
||||
if (entity instanceof Player && !player.getBukkitEntity().canSee((Player) entity))
|
||||
continue;
|
||||
|
@ -1,24 +1,21 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Watchers.AgeableWatcher;
|
||||
import net.minecraft.server.v1_5_R3.Entity;
|
||||
import net.minecraft.server.v1_5_R3.EntityAgeable;
|
||||
import net.minecraft.server.v1_5_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R3.EntitySkeleton;
|
||||
import net.minecraft.server.v1_5_R3.EntityTypes;
|
||||
import net.minecraft.server.v1_5_R3.ItemStack;
|
||||
import net.minecraft.server.v1_5_R3.MathHelper;
|
||||
import net.minecraft.server.v1_5_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_5_R3.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_5_R3.EnumArt;
|
||||
import net.minecraft.server.v1_5_R3.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -30,18 +27,12 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
public class Disguise {
|
||||
protected DisguiseType disguiseType;
|
||||
private Entity entity = null;
|
||||
private boolean replaceSounds;
|
||||
private FlagWatcher watcher;
|
||||
|
||||
protected Disguise(DisguiseType newType) {
|
||||
protected Disguise(DisguiseType newType, boolean doSounds) {
|
||||
disguiseType = newType;
|
||||
}
|
||||
|
||||
public PacketContainer constructDestroyPacket(int entityId) {
|
||||
PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(Packets.Server.DESTROY_ENTITY);
|
||||
StructureModifier<Object> mods = destroyPacket.getModifier();
|
||||
mods.write(0, new int[] { entityId });
|
||||
return destroyPacket;
|
||||
replaceSounds = doSounds;
|
||||
}
|
||||
|
||||
public PacketContainer constructPacket(org.bukkit.entity.Entity e) {
|
||||
@ -76,7 +67,8 @@ public class Disguise {
|
||||
|
||||
} else if (getType().isMob()) {
|
||||
|
||||
entity = ((MobDisguise) this).getEntityLiving(((CraftEntity) e).getHandle().world, e.getLocation(), e.getEntityId());
|
||||
// entity = ((MobDisguise) this).getEntityLiving(((CraftEntity) e).getHandle().world, e.getLocation(),
|
||||
// e.getEntityId());
|
||||
double d1 = 3.9D;
|
||||
Vector vec = e.getVelocity();
|
||||
double d2 = vec.getX();
|
||||
@ -98,6 +90,31 @@ public class Disguise {
|
||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
||||
mods.write(0, e.getEntityId());
|
||||
mods.write(1, (byte) EntityTypes.a(entity));
|
||||
String name = toReadable(disguiseType.name());
|
||||
if (disguiseType == DisguiseType.WITHER_SKELETON) {
|
||||
name = "Skeleton";
|
||||
} else if (disguiseType == DisguiseType.PRIMED_TNT) {
|
||||
name = "TNTPrimed";
|
||||
} else if (disguiseType == DisguiseType.MINECART_TNT) {
|
||||
name = "MinecartTNT";
|
||||
} else if (disguiseType == DisguiseType.SPLASH_POTION)
|
||||
name = "Potion";
|
||||
else if (disguiseType == DisguiseType.GIANT)
|
||||
name = "Giant Zombie";
|
||||
else if (disguiseType == DisguiseType.DROPPED_ITEM)
|
||||
name = "Item";
|
||||
else if (disguiseType == DisguiseType.FIREBALL)
|
||||
name = "Large Fireball";
|
||||
try {
|
||||
Class entityClass = Class.forName("net.minecraft.server.v1_5_R3.Entity" + name);
|
||||
Field field = EntityTypes.class.getDeclaredField("e");
|
||||
field.setAccessible(true);
|
||||
Map map = (Map) field.get(null);
|
||||
mods.write(1, map.containsKey(entityClass) ? ((Integer) map.get(entityClass)).intValue() : 0);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
mods.write(2, entity.at.a(loc.getX()));
|
||||
mods.write(3, (int) Math.floor(loc.getY() * 32D));
|
||||
mods.write(4, entity.at.a(loc.getZ()));
|
||||
@ -115,7 +132,7 @@ public class Disguise {
|
||||
|
||||
} else if (getType().isMisc()) {
|
||||
|
||||
getEntity(((CraftEntity) e).getHandle().world, e.getLocation(), e.getEntityId());
|
||||
// getEntity(((CraftEntity) e).getHandle().world, e.getLocation(), e.getEntityId());
|
||||
int id = getType().getEntityId();
|
||||
int data = 0;
|
||||
if (((MiscDisguise) this).getId() >= 0)
|
||||
@ -159,9 +176,9 @@ public class Disguise {
|
||||
|
||||
} else if (getType().isPlayer()) {
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) getEntity(((CraftEntity) e).getHandle().world, e.getLocation(),
|
||||
e.getEntityId());
|
||||
entityPlayer.name = ((PlayerDisguise) this).getName();
|
||||
// EntityPlayer entityPlayer = (EntityPlayer) getEntity(((CraftEntity) e).getHandle().world, e.getLocation(),
|
||||
// e.getEntityId());
|
||||
// entityPlayer.name = ((PlayerDisguise) this).getName();
|
||||
spawnPacket = manager.createPacket(Packets.Server.NAMED_ENTITY_SPAWN);
|
||||
StructureModifier<Object> mods = spawnPacket.getModifier();
|
||||
mods.write(0, e.getEntityId());
|
||||
@ -182,37 +199,7 @@ public class Disguise {
|
||||
return spawnPacket;
|
||||
}
|
||||
|
||||
public Entity getEntity(World world, Location loc, int entityId) {
|
||||
if (entity != null) {
|
||||
entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
entity.id = entityId;
|
||||
return entity;
|
||||
}
|
||||
try {
|
||||
if (disguiseType == DisguiseType.PLAYER) {
|
||||
entity = new EntityPlayer(MinecraftServer.getServer(), world, ((PlayerDisguise) this).getName(),
|
||||
new PlayerInteractManager(world));
|
||||
} else {
|
||||
String name = toReadable(disguiseType.name());
|
||||
if (disguiseType == DisguiseType.WITHER_SKELETON) {
|
||||
name = "Skeleton";
|
||||
} else if (disguiseType == DisguiseType.PRIMED_TNT) {
|
||||
name = "TNTPrimed";
|
||||
} else if (disguiseType == DisguiseType.MINECART_TNT) {
|
||||
name = "MinecartTNT";
|
||||
}
|
||||
Class entityClass = Class.forName("net.minecraft.server.v1_5_R3.Entity" + name);
|
||||
Constructor<?> contructor = entityClass.getDeclaredConstructor(World.class);
|
||||
entity = (Entity) contructor.newInstance(world);
|
||||
if (disguiseType == DisguiseType.WITHER_SKELETON) {
|
||||
((EntitySkeleton) entity).setSkeletonType(1);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
entity.id = entityId;
|
||||
public void constructWatcher(EntityType type, int entityId) {
|
||||
try {
|
||||
String name;
|
||||
if (getType().isPlayer()) {
|
||||
@ -223,16 +210,18 @@ public class Disguise {
|
||||
Class watcherClass = Class.forName("me.libraryaddict.disguise.DisguiseTypes.Watchers." + name + "Watcher");
|
||||
Constructor<?> contructor = watcherClass.getDeclaredConstructor(int.class);
|
||||
watcher = (FlagWatcher) contructor.newInstance(entityId);
|
||||
if (watcher instanceof AgeableWatcher && this instanceof MobDisguise) {
|
||||
((AgeableWatcher) watcher).setValue(12, ((MobDisguise) this).isAdult() ? 0 : -23999);
|
||||
}
|
||||
WatcherValues entity = WatcherValues.valueOf(type.name());
|
||||
WatcherValues disguise = WatcherValues.valueOf(getType().name());
|
||||
for (int i : entity.getValues()) {
|
||||
if (disguise.getValue(i) != null && disguise.getValue(i).getClass() != entity.getValue(i).getClass())
|
||||
watcher.setValue(i, disguise.getValue(i));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// There is no watcher for this entity
|
||||
}
|
||||
if (watcher == null && entity instanceof EntityAgeable && this instanceof MobDisguise) {
|
||||
watcher = new AgeableWatcher(entityId);
|
||||
}
|
||||
if (watcher instanceof AgeableWatcher && this instanceof MobDisguise) {
|
||||
((AgeableWatcher) watcher).setValue(12, ((MobDisguise) this).isAdult() ? 0 : -23999);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public DisguiseType getType() {
|
||||
@ -247,6 +236,14 @@ public class Disguise {
|
||||
return watcher != null;
|
||||
}
|
||||
|
||||
public boolean replaceSounds() {
|
||||
return replaceSounds;
|
||||
}
|
||||
|
||||
public void setReplaceSounds(boolean areSoundsReplaced) {
|
||||
replaceSounds = areSoundsReplaced;
|
||||
}
|
||||
|
||||
private String toReadable(String string) {
|
||||
String[] strings = string.split("_");
|
||||
string = "";
|
||||
|
@ -12,7 +12,7 @@ public enum DisguiseSound {
|
||||
|
||||
BLAZE(Sound.BLAZE_HIT, null, Sound.BLAZE_DEATH, Sound.BLAZE_BREATH),
|
||||
|
||||
CAVE_SPIDER(Sound.SPIDER_IDLE, Sound.SPIDER_WALK, Sound.SPIDER_DEATH, Sound.PIG_IDLE),
|
||||
CAVE_SPIDER(Sound.SPIDER_IDLE, Sound.SPIDER_WALK, Sound.SPIDER_DEATH, Sound.SPIDER_IDLE),
|
||||
|
||||
CHICKEN(Sound.CHICKEN_HURT, Sound.CHICKEN_WALK, Sound.CHICKEN_HURT, Sound.CHICKEN_IDLE, Sound.CHICKEN_EGG_POP),
|
||||
|
||||
@ -28,7 +28,7 @@ public enum DisguiseSound {
|
||||
GHAST(Sound.GHAST_SCREAM, null, Sound.GHAST_DEATH, Sound.GHAST_MOAN, Sound.GHAST_CHARGE, Sound.GHAST_FIREBALL,
|
||||
Sound.GHAST_SCREAM2),
|
||||
|
||||
GIANT_ZOMBIE(Sound.HURT_FLESH, Sound.STEP_GRASS, null, null),
|
||||
GIANT(Sound.HURT_FLESH, Sound.STEP_GRASS, null, null),
|
||||
|
||||
IRON_GOLEM(Sound.IRONGOLEM_HIT, Sound.IRONGOLEM_WALK, Sound.IRONGOLEM_DEATH, Sound.IRONGOLEM_THROW),
|
||||
|
||||
@ -52,7 +52,7 @@ public enum DisguiseSound {
|
||||
|
||||
SLIME(Sound.SLIME_ATTACK, Sound.SLIME_WALK2, null, null, Sound.SLIME_WALK),
|
||||
|
||||
SPIDER(Sound.SPIDER_IDLE, Sound.SPIDER_WALK, Sound.SPIDER_DEATH, Sound.PIG_IDLE),
|
||||
SPIDER(Sound.SPIDER_IDLE, Sound.SPIDER_WALK, Sound.SPIDER_DEATH, Sound.SPIDER_IDLE),
|
||||
|
||||
WITHER(Sound.WITHER_HURT, null, Sound.WITHER_DEATH, Sound.WITHER_IDLE, Sound.WITHER_SHOOT, Sound.WITHER_SPAWN),
|
||||
|
||||
@ -74,8 +74,6 @@ public enum DisguiseSound {
|
||||
|
||||
public static DisguiseSound getType(String name) {
|
||||
try {
|
||||
if (name.equals("GIANT"))
|
||||
return DisguiseSound.GIANT_ZOMBIE;
|
||||
return valueOf(name);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
@ -124,16 +122,15 @@ public enum DisguiseSound {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if the original sound is owned by this disguise sound Ofc it won't be correct for commonly shared names. But
|
||||
* its the best I can possibly do
|
||||
* Used to check if this sound name is owned by this disguise sound.
|
||||
*/
|
||||
public SoundType ownsSound(String name) {
|
||||
public SoundType getType(String name, boolean ignoreDamage) {
|
||||
if (isCancelSound(name))
|
||||
return SoundType.CANCEL;
|
||||
if (disguiseSounds.get(SoundType.STEP) == Sound.STEP_GRASS && name.startsWith("step."))
|
||||
return SoundType.STEP;
|
||||
for (SoundType type : SoundType.values()) {
|
||||
if (!disguiseSounds.containsKey(type))
|
||||
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT))
|
||||
continue;
|
||||
Sound s = disguiseSounds.get(type);
|
||||
if (s != null)
|
||||
|
@ -5,33 +5,23 @@ public enum DisguiseType {
|
||||
EntityType.MOB), COW(EntityType.MOB), CREEPER(EntityType.MOB), EGG(EntityType.MISC, 62), ENDER_CRYSTAL(
|
||||
EntityType.MISC, 51), ENDER_DRAGON(EntityType.MOB), ENDER_PEARL(EntityType.MISC, 65), ENDER_SIGNAL(EntityType.MISC,
|
||||
72), ENDERMAN(EntityType.MOB), EXPERIENCE_ORB(EntityType.MISC), FALLING_BLOCK(EntityType.MISC, 70, 1), FIREWORKS(
|
||||
EntityType.MISC, 76), FISHING_HOOK(EntityType.MISC, 90), GHAST(EntityType.MOB), GIANT_ZOMBIE(EntityType.MOB), IRON_GOLEM(
|
||||
EntityType.MOB), ITEM(EntityType.MISC, 2, 1), ITEM_FRAME(EntityType.MISC, 71), LARGE_FIREBALL(EntityType.MISC, 63, 0), MAGMA_CUBE(
|
||||
EntityType.MOB), MINECART_CHEST(EntityType.MISC, 10, 1), MINECART_FURNACE(EntityType.MISC, 10, 2), MINECART_HOPPER(
|
||||
EntityType.MISC, 76), FISHING_HOOK(EntityType.MISC, 90), GHAST(EntityType.MOB), GIANT(EntityType.MOB), IRON_GOLEM(
|
||||
EntityType.MOB), DROPPED_ITEM(EntityType.MISC, 2, 1), ITEM_FRAME(EntityType.MISC, 71), FIREBALL(EntityType.MISC, 63,
|
||||
0), MAGMA_CUBE(EntityType.MOB), MINECART_CHEST(EntityType.MISC, 10, 1), MINECART_FURNACE(EntityType.MISC, 10, 2), MINECART_HOPPER(
|
||||
EntityType.MISC, 10), MINECART_MOB_SPAWNER(EntityType.MISC, 10, 4), MINECART_RIDEABLE(EntityType.MISC, 10, 0), MINECART_TNT(
|
||||
EntityType.MISC, 10, 3), MUSHROOM_COW(EntityType.MOB), OCELOT(EntityType.MOB), PAINTING(EntityType.MISC), PIG(EntityType.MOB), PIG_ZOMBIE(
|
||||
EntityType.MOB), PLAYER(EntityType.PLAYER), POTION(EntityType.MISC, 73), PRIMED_TNT(EntityType.MISC, 50), SHEEP(
|
||||
EntityType.MOB), SILVERFISH(EntityType.MOB), SKELETON(EntityType.MOB), SLIME(EntityType.MOB), SMALL_FIREBALL(
|
||||
EntityType.MISC, 64, 0), SNOWBALL(EntityType.MISC, 61), SNOWMAN(EntityType.MOB), SPIDER(EntityType.MOB), SQUID(
|
||||
EntityType.MOB), THROWN_EXP_BOTTLE(EntityType.MISC, 75), VILLAGER(EntityType.MOB), WITCH(EntityType.MOB), WITHER(
|
||||
EntityType.MOB), WITHER_SKELETON(EntityType.MOB), WITHER_SKULL(EntityType.MISC, 66), WOLF(EntityType.MOB), ZOMBIE(
|
||||
EntityType.MOB);
|
||||
EntityType.MISC, 10, 3), MUSHROOM_COW(EntityType.MOB), OCELOT(EntityType.MOB), PAINTING(EntityType.MISC), PIG(
|
||||
EntityType.MOB), PIG_ZOMBIE(EntityType.MOB), PLAYER(EntityType.PLAYER), SPLASH_POTION(EntityType.MISC, 73), PRIMED_TNT(
|
||||
EntityType.MISC, 50), SHEEP(EntityType.MOB), SILVERFISH(EntityType.MOB), SKELETON(EntityType.MOB), SLIME(
|
||||
EntityType.MOB), SMALL_FIREBALL(EntityType.MISC, 64, 0), SNOWBALL(EntityType.MISC, 61), SNOWMAN(EntityType.MOB), SPIDER(
|
||||
EntityType.MOB), SQUID(EntityType.MOB), THROWN_EXP_BOTTLE(EntityType.MISC, 75), VILLAGER(EntityType.MOB), WITCH(
|
||||
EntityType.MOB), WITHER(EntityType.MOB), WITHER_SKELETON(EntityType.MOB), WITHER_SKULL(EntityType.MISC, 66), WOLF(
|
||||
EntityType.MOB), ZOMBIE(EntityType.MOB);
|
||||
|
||||
public static enum EntityType {
|
||||
MISC, MOB, PLAYER;
|
||||
}
|
||||
|
||||
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
||||
if (entityType == org.bukkit.entity.EntityType.SPLASH_POTION)
|
||||
return DisguiseType.POTION;
|
||||
else if (entityType == org.bukkit.entity.EntityType.GIANT)
|
||||
return DisguiseType.GIANT_ZOMBIE;
|
||||
else if (entityType == org.bukkit.entity.EntityType.DROPPED_ITEM)
|
||||
return DisguiseType.ITEM;
|
||||
else if (entityType == org.bukkit.entity.EntityType.FIREBALL)
|
||||
return DisguiseType.LARGE_FIREBALL;
|
||||
else if (entityType == org.bukkit.entity.EntityType.SMALL_FIREBALL)
|
||||
return DisguiseType.LARGE_FIREBALL;
|
||||
return DisguiseType.valueOf(entityType.name());
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ public abstract class FlagWatcher {
|
||||
}
|
||||
private int entityId;
|
||||
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
|
||||
private HashMap<Integer, Object> softReplace = new HashMap<Integer, Object>();
|
||||
|
||||
protected FlagWatcher(int entityId) {
|
||||
this.entityId = entityId;
|
||||
@ -65,6 +66,10 @@ public abstract class FlagWatcher {
|
||||
watch.a(value);
|
||||
}
|
||||
}
|
||||
} else if (softReplace.containsKey(watch.a())) {
|
||||
if (watch.b().getClass() == softReplace.get(watch.a()).getClass()) {
|
||||
|
||||
}
|
||||
}
|
||||
newList.add(watch);
|
||||
}
|
||||
@ -83,6 +88,31 @@ public abstract class FlagWatcher {
|
||||
return newList;
|
||||
}
|
||||
|
||||
private WatchableObject processWatcher(WatchableObject watch, HashMap<Integer, Object> map) {
|
||||
boolean doD = watch.d();
|
||||
watch = new WatchableObject(watch.c(), watch.a(), watch.b());
|
||||
if (!doD)
|
||||
watch.a(false);
|
||||
if (map.get(watch.a()) == null) {
|
||||
return watch;
|
||||
} else {
|
||||
Object value = map.get(watch.a());
|
||||
if (watch.b().getClass() != value.getClass()) {
|
||||
watch.a(value);
|
||||
try {
|
||||
Field field = WatchableObject.class.getDeclaredField("a");
|
||||
field.setAccessible(true);
|
||||
field.set(watch, classTypes.get(value.getClass()));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
watch.a(value);
|
||||
}
|
||||
}
|
||||
return watch;
|
||||
}
|
||||
|
||||
public void displayName(boolean display) {
|
||||
if ((Byte) getValue(6) != (display ? 1 : 0)) {
|
||||
setValue(6, (byte) (display ? 1 : 0));
|
||||
|
@ -5,13 +5,11 @@ public class MiscDisguise extends Disguise {
|
||||
private int id = -1;
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType) {
|
||||
super(disguiseType);
|
||||
id = disguiseType.getDefaultId();
|
||||
data = disguiseType.getDefaultData();
|
||||
this(disguiseType, true, -1, -1);
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
||||
super(disguiseType);
|
||||
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
|
||||
super(disguiseType, replaceSounds);
|
||||
if (id == -1)
|
||||
id = disguiseType.getDefaultId();
|
||||
if (data == -1)
|
||||
@ -20,6 +18,10 @@ public class MiscDisguise extends Disguise {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
||||
this(disguiseType, true, id, data);
|
||||
}
|
||||
|
||||
public int getData() {
|
||||
return data;
|
||||
}
|
||||
|
@ -1,40 +1,26 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
import net.minecraft.server.v1_5_R3.Entity;
|
||||
import net.minecraft.server.v1_5_R3.EntityAgeable;
|
||||
import net.minecraft.server.v1_5_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_5_R3.EntityZombie;
|
||||
import net.minecraft.server.v1_5_R3.World;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Watchers.AgeableWatcher;
|
||||
|
||||
public class MobDisguise extends Disguise {
|
||||
|
||||
private boolean adult;
|
||||
private boolean isAdult;
|
||||
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
|
||||
super(disguiseType);
|
||||
adult = isAdult;
|
||||
super(disguiseType, true);
|
||||
}
|
||||
|
||||
protected EntityLiving getEntityLiving(World w, Location loc, int id) {
|
||||
Entity entity = getEntity(w, loc, id);
|
||||
if (!adult) {
|
||||
if (entity instanceof EntityAgeable)
|
||||
((EntityAgeable) entity).setAge(-24000);
|
||||
else if (entity instanceof EntityZombie)
|
||||
((EntityZombie) entity).setBaby(true);
|
||||
}
|
||||
if (entity instanceof EntityLiving)
|
||||
return (EntityLiving) entity;
|
||||
return null;
|
||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) {
|
||||
super(disguiseType, replaceSounds);
|
||||
this.isAdult = isAdult;
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
return adult;
|
||||
}
|
||||
|
||||
public void setAdult(boolean setAdult) {
|
||||
adult = setAdult;
|
||||
if (getWatcher() != null) {
|
||||
if (getWatcher() instanceof AgeableWatcher)
|
||||
return ((AgeableWatcher) getWatcher()).isAdult();
|
||||
return false;
|
||||
}
|
||||
return isAdult;
|
||||
}
|
||||
}
|
@ -4,7 +4,11 @@ public class PlayerDisguise extends Disguise {
|
||||
private String playerName;
|
||||
|
||||
public PlayerDisguise(String name) {
|
||||
super(DisguiseType.PLAYER);
|
||||
this(name, true);
|
||||
}
|
||||
|
||||
public PlayerDisguise(String name, boolean replaceSounds) {
|
||||
super(DisguiseType.PLAYER, replaceSounds);
|
||||
if (name.length() > 16)
|
||||
name = name.substring(0, 16);
|
||||
playerName = name;
|
||||
|
@ -0,0 +1,43 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public enum WatcherValues {
|
||||
ARROW(16, (byte) 0), BAT(16, (byte) 0), BLAZE(16, (byte) 0), BOAT(19, 40, 17, 10, 18, 0), CAVE_SPIDER(), CHICKEN(12, 0), COW(
|
||||
12, 0), CREEPER(16, (byte) 0, 17, (byte) 0), EGG(), ENDER_CRYSTAL(), ENDER_DRAGON(16, 300), ENDER_PEARL(), ENDER_SIGNAL(), ENDERMAN(
|
||||
16, (byte) 0, 17, (byte) 1, 18, (byte) 0), EXPERIENCE_ORB(), FALLING_BLOCK(), FIREWORKS(), FISHING_HOOK(), GHAST(16,
|
||||
(byte) 0), GIANT(), IRON_GOLEM(), DROPPED_ITEM(), ITEM_FRAME(2, 5, 3, (byte) 0), FIREBALL(), MAGMA_CUBE(16, (byte) 0,
|
||||
18, (byte) 0), MINECART_CHEST(16, (byte) 0, 17, 0, 18, 1, 19, 0, 20, 0, 21, 6, 22, (byte) 0), MINECART_FURNACE(16,
|
||||
(byte) 0, 17, 0, 18, 1, 19, 0, 20, 0, 21, 6, 22, (byte) 0), MINECART_HOPPER(16, (byte) 0, 17, 0, 18, 1, 19, 0, 20, 0,
|
||||
21, 6, 22, (byte) 0), MINECART_MOB_SPAWNER(16, (byte) 0, 17, 0, 18, 1, 19, 0, 20, 0, 21, 6, 22, (byte) 0), MINECART_RIDEABLE(
|
||||
16, (byte) 0, 17, 0, 18, 1, 19, 0, 20, 0, 21, 6, 22, (byte) 0), MINECART_TNT(16, (byte) 0, 17, 0, 18, 1, 19, 0, 20,
|
||||
0, 21, 6, 22, (byte) 0), MUSHROOM_COW(12, 0), OCELOT(12, 0, 16, (byte) 0, 17, "", 18, (byte) 0), PAINTING(), PIG(12,
|
||||
0, 16, (byte) 0), PIG_ZOMBIE(12, 0), PLAYER(8, 0, 9, (byte) 0, 10, (byte) 0), SPLASH_POTION(), PRIMED_TNT(), SHEEP(
|
||||
12, (byte) 0, 16, (byte) 0), SILVERFISH(), SKELETON(13, (byte) 0), SLIME(16, (byte) 0, 18, (byte) 0), SMALL_FIREBALL(), SNOWBALL(), SNOWMAN(), SPIDER(), SQUID(), THROWN_EXP_BOTTLE(), VILLAGER(
|
||||
16, 0), WITCH(), WITHER(16, 300), WITHER_SKELETON(13, (byte) 1), WITHER_SKULL(), WOLF(16, (byte) 0, 17, "", 18, 8,
|
||||
19, (byte) 0, 20, (byte) 14), ZOMBIE(13, (byte) 0);
|
||||
private HashMap<Integer, Object> values = new HashMap<Integer, Object>();
|
||||
|
||||
private WatcherValues(Object... obj) {
|
||||
for (int i = 0; i < obj.length; i += 2) {
|
||||
if (!values.containsKey(obj))
|
||||
values.put((Integer) obj[i], obj[i + 1]);
|
||||
else
|
||||
try {
|
||||
throw new Exception("Values in WatcherValues already contains " + obj + " for " + this.name());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Integer> getValues() {
|
||||
return values.keySet();
|
||||
}
|
||||
|
||||
public Object getValue(int no) {
|
||||
return values.get(no);
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@ package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher;
|
||||
|
||||
public class AgeableWatcher extends FlagWatcher {
|
||||
public abstract class AgeableWatcher extends FlagWatcher {
|
||||
|
||||
public AgeableWatcher(int entityId) {
|
||||
super(entityId);
|
||||
|
@ -0,0 +1,21 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher;
|
||||
|
||||
public class ArrowWatcher extends FlagWatcher {
|
||||
|
||||
protected ArrowWatcher(int entityId) {
|
||||
super(entityId);
|
||||
setValue(16, (byte) 0);
|
||||
}
|
||||
|
||||
public void setMoving(boolean moving) {
|
||||
setValue(16, (byte) (moving ? 1 : 0));
|
||||
}
|
||||
|
||||
public boolean isMoving() {
|
||||
return (Byte) getValue(16) == 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
public class ChickenWatcher extends AgeableWatcher {
|
||||
|
||||
public ChickenWatcher(int entityId) {
|
||||
super(entityId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
public class CowWatcher extends AgeableWatcher {
|
||||
|
||||
public CowWatcher(int entityId) {
|
||||
super(entityId);
|
||||
}
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ public class CreeperWatcher extends FlagWatcher {
|
||||
|
||||
public CreeperWatcher(int entityId) {
|
||||
super(entityId);
|
||||
setValue(16, (byte) -1);
|
||||
setValue(16, (byte) 0);
|
||||
setValue(17, 0);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher;
|
||||
|
||||
public class LivingEntityWatcher extends FlagWatcher {
|
||||
|
||||
protected LivingEntityWatcher(int entityId) {
|
||||
super(entityId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
public class MushroomCowWatcher extends AgeableWatcher {
|
||||
|
||||
public MushroomCowWatcher(int entityId) {
|
||||
super(entityId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
public class PigZombieWatcher extends AgeableWatcher {
|
||||
|
||||
public PigZombieWatcher(int entityId) {
|
||||
super(entityId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher;
|
||||
|
||||
public class SkeletonWatcher extends FlagWatcher {
|
||||
|
||||
protected SkeletonWatcher(int entityId) {
|
||||
super(entityId);
|
||||
setValue(13, (byte) 0);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher;
|
||||
|
||||
public class WitherSkeletonWatcher extends FlagWatcher {
|
||||
|
||||
protected WitherSkeletonWatcher(int entityId) {
|
||||
super(entityId);
|
||||
setValue(13, (byte) 1);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package me.libraryaddict.disguise.DisguiseTypes.Watchers;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.FlagWatcher;
|
||||
|
||||
public class ZombieWatcher extends FlagWatcher {
|
||||
public class ZombieWatcher extends AgeableWatcher {
|
||||
|
||||
public ZombieWatcher(int entityId) {
|
||||
super(entityId);
|
||||
|
@ -33,8 +33,10 @@ public class LibsDisguises extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||
System.out.print("[LibsDisguises] WARNING! WARNING! LibsDisguises couldn't find ProtocolLib! This plugin depends on it to run!");
|
||||
System.out.print("[LibsDisguises] WARNING! WARNING! LibsDisguises couldn't find ProtocolLib! LibsDisguises is now shutting down!");
|
||||
System.out
|
||||
.print("[LibsDisguises] WARNING! WARNING! LibsDisguises couldn't find ProtocolLib! This plugin depends on it to run!");
|
||||
System.out
|
||||
.print("[LibsDisguises] WARNING! WARNING! LibsDisguises couldn't find ProtocolLib! LibsDisguises is now shutting down!");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user