Fixed Misc disguises
Added AreaEffectCloudWatcher Readded regular Arrows Updated object ids Updated relative look and move packets Minor changes here and there
This commit is contained in:
parent
7dabbb7ce4
commit
8eb4beba83
@ -26,7 +26,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -205,13 +204,11 @@ public class DisguiseAPI {
|
|||||||
disguise = disguise.clone();
|
disguise = disguise.clone();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
|
||||||
field.setAccessible(true);
|
|
||||||
int id = field.getInt(null);
|
|
||||||
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
||||||
return id;
|
return id;
|
||||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
|
} catch (IllegalAccessException e) {
|
||||||
ex.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DisguiseListener implements Listener {
|
public class DisguiseListener implements Listener {
|
||||||
|
|
||||||
@ -218,7 +217,7 @@ public class DisguiseListener implements Listener {
|
|||||||
while (reference == null && attempts++ < 1000) {
|
while (reference == null && attempts++ < 1000) {
|
||||||
reference = "@";
|
reference = "@";
|
||||||
for (int i = 0; i < referenceLength; i++) {
|
for (int i = 0; i < referenceLength; i++) {
|
||||||
reference += alphabet[new Random().nextInt(alphabet.length)];
|
reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
|
||||||
}
|
}
|
||||||
if (DisguiseUtilities.getClonedDisguise(reference) != null) {
|
if (DisguiseUtilities.getClonedDisguise(reference) != null) {
|
||||||
reference = null;
|
reference = null;
|
||||||
|
@ -25,7 +25,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.TippedArrowWatcher;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
@ -137,9 +136,6 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
case WITHER_SKELETON:
|
case WITHER_SKELETON:
|
||||||
watcherClass = SkeletonWatcher.class;
|
watcherClass = SkeletonWatcher.class;
|
||||||
break;
|
break;
|
||||||
case ARROW:
|
|
||||||
watcherClass = TippedArrowWatcher.class;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
|
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
|
||||||
+ toReadable(disguiseType.name()) + "Watcher");
|
+ toReadable(disguiseType.name()) + "Watcher");
|
||||||
@ -240,7 +236,6 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
|
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
|
||||||
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
|
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
|
||||||
// Uncomment when I need to find the new datawatcher values for a class..
|
// Uncomment when I need to find the new datawatcher values for a class..
|
||||||
//TODO: Recomment this section when finished
|
|
||||||
int id = watch.getIndex();
|
int id = watch.getIndex();
|
||||||
Object val = watch.getValue();
|
Object val = watch.getValue();
|
||||||
Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
|
Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
|
||||||
|
@ -37,7 +37,6 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class Disguise {
|
public abstract class Disguise {
|
||||||
@ -106,7 +105,7 @@ public abstract class Disguise {
|
|||||||
((SkeletonWatcher)getWatcher()).setType(SkeletonType.WITHER);
|
((SkeletonWatcher)getWatcher()).setType(SkeletonType.WITHER);
|
||||||
} // Else if its a zombie, but the disguise type is a zombie villager. Set the value.
|
} // Else if its a zombie, but the disguise type is a zombie villager. Set the value.
|
||||||
else if (getType() == DisguiseType.ZOMBIE_VILLAGER) {
|
else if (getType() == DisguiseType.ZOMBIE_VILLAGER) {
|
||||||
((ZombieWatcher)getWatcher()).setProfession(Profession.values()[new Random().nextInt(Profession.values().length)]);
|
((ZombieWatcher)getWatcher()).setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
|
||||||
} else if (getType() == DisguiseType.ELDER_GUARDIAN) {
|
} else if (getType() == DisguiseType.ELDER_GUARDIAN) {
|
||||||
((GuardianWatcher)getWatcher()).setElder(true);
|
((GuardianWatcher)getWatcher()).setElder(true);
|
||||||
} // Else if its a horse. Set the horse watcher type
|
} // Else if its a horse. Set the horse watcher type
|
||||||
@ -145,6 +144,7 @@ public abstract class Disguise {
|
|||||||
case WITHER_SKULL:
|
case WITHER_SKULL:
|
||||||
velocitySpeed = 0.000001D;
|
velocitySpeed = 0.000001D;
|
||||||
break;
|
break;
|
||||||
|
case ARROW:
|
||||||
case TIPPED_ARROW:
|
case TIPPED_ARROW:
|
||||||
case SPECTRAL_ARROW:
|
case SPECTRAL_ARROW:
|
||||||
case BOAT:
|
case BOAT:
|
||||||
|
@ -12,47 +12,47 @@ import java.lang.reflect.Method;
|
|||||||
|
|
||||||
public enum DisguiseType {
|
public enum DisguiseType {
|
||||||
|
|
||||||
AREA_EFFECT_CLOUD,
|
AREA_EFFECT_CLOUD(3, 0),
|
||||||
ARMOR_STAND,
|
ARMOR_STAND(78),
|
||||||
ARROW,
|
ARROW(60, 0),
|
||||||
BAT,
|
BAT,
|
||||||
BLAZE,
|
BLAZE,
|
||||||
BOAT,
|
BOAT(1),
|
||||||
CAVE_SPIDER,
|
CAVE_SPIDER,
|
||||||
CHICKEN,
|
CHICKEN,
|
||||||
COW,
|
COW,
|
||||||
CREEPER,
|
CREEPER,
|
||||||
DONKEY,
|
DONKEY,
|
||||||
DRAGON_FIREBALL,
|
DRAGON_FIREBALL(93),
|
||||||
DROPPED_ITEM(1),
|
DROPPED_ITEM(1, 1),
|
||||||
EGG,
|
EGG(62),
|
||||||
ELDER_GUARDIAN,
|
ELDER_GUARDIAN,
|
||||||
ENDER_CRYSTAL,
|
ENDER_CRYSTAL(51),
|
||||||
ENDER_DRAGON,
|
ENDER_DRAGON,
|
||||||
ENDER_PEARL,
|
ENDER_PEARL(65),
|
||||||
ENDER_SIGNAL,
|
ENDER_SIGNAL(72),
|
||||||
ENDERMAN,
|
ENDERMAN,
|
||||||
ENDERMITE,
|
ENDERMITE,
|
||||||
EXPERIENCE_ORB,
|
EXPERIENCE_ORB,
|
||||||
FALLING_BLOCK(1),
|
FALLING_BLOCK(70, 1),
|
||||||
FIREBALL(0),
|
FIREBALL(63),
|
||||||
FIREWORK,
|
FIREWORK(76),
|
||||||
FISHING_HOOK,
|
FISHING_HOOK(90),
|
||||||
GHAST,
|
GHAST,
|
||||||
GIANT,
|
GIANT,
|
||||||
GUARDIAN,
|
GUARDIAN,
|
||||||
HORSE,
|
HORSE,
|
||||||
IRON_GOLEM,
|
IRON_GOLEM,
|
||||||
ITEM_FRAME,
|
ITEM_FRAME(71),
|
||||||
LEASH_HITCH,
|
LEASH_HITCH(77),
|
||||||
MAGMA_CUBE,
|
MAGMA_CUBE,
|
||||||
MINECART,
|
MINECART(10),
|
||||||
MINECART_CHEST(1),
|
MINECART_CHEST(10, 1),
|
||||||
MINECART_COMMAND(6),
|
MINECART_COMMAND(10, 6),
|
||||||
MINECART_FURNACE(2),
|
MINECART_FURNACE(10, 2),
|
||||||
MINECART_HOPPER(5),
|
MINECART_HOPPER(10, 5),
|
||||||
MINECART_MOB_SPAWNER(4),
|
MINECART_MOB_SPAWNER(10, 4),
|
||||||
MINECART_TNT(5),
|
MINECART_TNT(10, 3),
|
||||||
MULE,
|
MULE,
|
||||||
MUSHROOM_COW,
|
MUSHROOM_COW,
|
||||||
OCELOT,
|
OCELOT,
|
||||||
@ -60,30 +60,30 @@ public enum DisguiseType {
|
|||||||
PIG,
|
PIG,
|
||||||
PIG_ZOMBIE,
|
PIG_ZOMBIE,
|
||||||
PLAYER,
|
PLAYER,
|
||||||
PRIMED_TNT,
|
PRIMED_TNT(50),
|
||||||
RABBIT,
|
RABBIT,
|
||||||
SHEEP,
|
SHEEP,
|
||||||
SHULKER,
|
SHULKER,
|
||||||
SHULKER_BULLET,
|
SHULKER_BULLET(67),
|
||||||
SILVERFISH,
|
SILVERFISH,
|
||||||
SKELETON,
|
SKELETON,
|
||||||
SKELETON_HORSE,
|
SKELETON_HORSE,
|
||||||
SLIME,
|
SLIME,
|
||||||
SMALL_FIREBALL(0),
|
SMALL_FIREBALL(63),
|
||||||
SNOWBALL,
|
SNOWBALL(61),
|
||||||
SNOWMAN,
|
SNOWMAN,
|
||||||
SPECTRAL_ARROW,
|
SPECTRAL_ARROW(91),
|
||||||
SPIDER,
|
SPIDER,
|
||||||
SPLASH_POTION,
|
SPLASH_POTION(73, 0),
|
||||||
SQUID,
|
SQUID,
|
||||||
TIPPED_ARROW,
|
TIPPED_ARROW(92),
|
||||||
THROWN_EXP_BOTTLE,
|
THROWN_EXP_BOTTLE(75),
|
||||||
UNDEAD_HORSE,
|
UNDEAD_HORSE,
|
||||||
VILLAGER,
|
VILLAGER,
|
||||||
WITCH,
|
WITCH,
|
||||||
WITHER,
|
WITHER,
|
||||||
WITHER_SKELETON,
|
WITHER_SKELETON,
|
||||||
WITHER_SKULL,
|
WITHER_SKULL(66),
|
||||||
WOLF,
|
WOLF,
|
||||||
ZOMBIE,
|
ZOMBIE,
|
||||||
ZOMBIE_VILLAGER,
|
ZOMBIE_VILLAGER,
|
||||||
@ -97,6 +97,7 @@ public enum DisguiseType {
|
|||||||
for (DisguiseType type : values()) {
|
for (DisguiseType type : values()) {
|
||||||
try {
|
try {
|
||||||
DisguiseType toUse = type;
|
DisguiseType toUse = type;
|
||||||
|
String name;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
|
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
|
||||||
// Usable.
|
// Usable.
|
||||||
@ -117,12 +118,11 @@ public enum DisguiseType {
|
|||||||
case ELDER_GUARDIAN:
|
case ELDER_GUARDIAN:
|
||||||
toUse = DisguiseType.GUARDIAN;
|
toUse = DisguiseType.GUARDIAN;
|
||||||
break;
|
break;
|
||||||
case ARROW:
|
|
||||||
toUse = DisguiseType.TIPPED_ARROW;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
type.setEntityType(EntityType.valueOf(toUse.name()));
|
name = toUse.name();
|
||||||
|
type.setEntityType(EntityType.valueOf(name));
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
// This version of Spigot doesn't have the disguise.
|
// This version of Spigot doesn't have the disguise.
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ public enum DisguiseType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int defaultData = -1;
|
private int objectId = -1, defaultData = 0;
|
||||||
private EntityType entityType;
|
private EntityType entityType;
|
||||||
private Class<? extends FlagWatcher> watcherClass;
|
private Class<? extends FlagWatcher> watcherClass;
|
||||||
|
|
||||||
@ -208,6 +208,9 @@ public enum DisguiseType {
|
|||||||
int value = ints[i];
|
int value = ints[i];
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
|
objectId = value;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
defaultData = value;
|
defaultData = value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -231,10 +234,24 @@ public enum DisguiseType {
|
|||||||
return entityType;
|
return entityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The TYPE id of this entity. Different from the Object Id
|
||||||
|
* send in spawn packets when spawning miscs.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public int getTypeId() {
|
public int getTypeId() {
|
||||||
return (int) getEntityType().getTypeId();
|
return (int) getEntityType().getTypeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The object type send in packets when spawning a misc entity.
|
||||||
|
* Otherwise, -1.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getObjectId() {
|
||||||
|
return objectId;
|
||||||
|
}
|
||||||
|
|
||||||
public Class getWatcherClass() {
|
public Class getWatcherClass() {
|
||||||
return watcherClass;
|
return watcherClass;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Navid
|
||||||
|
*/
|
||||||
|
public class AreaEffectCloudWatcher extends FlagWatcher {
|
||||||
|
|
||||||
|
public AreaEffectCloudWatcher(Disguise disguise) {
|
||||||
|
super(disguise);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRadius() {
|
||||||
|
return (float) getValue(5, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColor() {
|
||||||
|
return (int) getValue(6, Color.BLACK.getRGB());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIgnoreRadius() {
|
||||||
|
return (boolean) getValue(7, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParticleId() {
|
||||||
|
return (int) getValue(8, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
setValue(5, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(int color) {
|
||||||
|
setValue(6, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIgnoreRadius(boolean ignore) {
|
||||||
|
setValue(7, ignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParticleId(int particleId) {
|
||||||
|
setValue(8, particleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,6 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
private ItemStack block;
|
private ItemStack block;
|
||||||
|
|
||||||
//TODO: Check this watcher and make sure it works
|
|
||||||
public FallingBlockWatcher(Disguise disguise) {
|
public FallingBlockWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,21 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
|||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Horse.Color;
|
import org.bukkit.entity.Horse.Color;
|
||||||
import org.bukkit.entity.Horse.Style;
|
import org.bukkit.entity.Horse.Style;
|
||||||
import org.bukkit.entity.Horse.Variant;
|
import org.bukkit.entity.Horse.Variant;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class HorseWatcher extends AgeableWatcher {
|
public class HorseWatcher extends AgeableWatcher {
|
||||||
|
|
||||||
public HorseWatcher(Disguise disguise) {
|
public HorseWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
setStyle(Style.values()[new Random().nextInt(Style.values().length)]);
|
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
|
||||||
setColor(Color.values()[new Random().nextInt(Color.values().length)]);
|
setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variant getVariant() {
|
public Variant getVariant() {
|
||||||
|
@ -2,14 +2,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
|||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class RabbitWatcher extends AgeableWatcher {
|
public class RabbitWatcher extends AgeableWatcher {
|
||||||
|
|
||||||
public RabbitWatcher(Disguise disguise) {
|
public RabbitWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
setType(RabbitType.values()[new Random().nextInt(RabbitType.values().length)]);
|
setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RabbitType getType() {
|
public RabbitType getType() {
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class SlimeWatcher extends LivingWatcher {
|
public class SlimeWatcher extends LivingWatcher {
|
||||||
|
|
||||||
public SlimeWatcher(Disguise disguise) {
|
public SlimeWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
setSize(new Random().nextInt(4) + 1);
|
setSize(DisguiseUtilities.random.nextInt(4) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,6 +11,10 @@ public class TippedArrowWatcher extends ArrowWatcher {
|
|||||||
|
|
||||||
public TippedArrowWatcher(Disguise disguise) {
|
public TippedArrowWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
|
int r = DisguiseUtilities.random.nextInt(256);
|
||||||
|
int g = DisguiseUtilities.random.nextInt(256);
|
||||||
|
int b = DisguiseUtilities.random.nextInt(256);
|
||||||
|
setColor(Color.fromRGB(r, g, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import org.bukkit.entity.Villager.Profession;
|
import org.bukkit.entity.Villager.Profession;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class VillagerWatcher extends AgeableWatcher {
|
public class VillagerWatcher extends AgeableWatcher {
|
||||||
|
|
||||||
public VillagerWatcher(Disguise disguise) {
|
public VillagerWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
setProfession(Profession.values()[new Random().nextInt(Profession.values().length)]);
|
setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profession getProfession() {
|
public Profession getProfession() {
|
||||||
|
@ -48,12 +48,14 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DisguiseUtilities {
|
public class DisguiseUtilities {
|
||||||
|
|
||||||
|
public static final Random random = new Random();
|
||||||
/**
|
/**
|
||||||
* This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of the plugin to do that.
|
* This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of the plugin to do that.
|
||||||
*/
|
*/
|
||||||
|
@ -30,8 +30,6 @@ public class DisguiseValues {
|
|||||||
case ZOMBIE_VILLAGER:
|
case ZOMBIE_VILLAGER:
|
||||||
type = DisguiseType.ZOMBIE;
|
type = DisguiseType.ZOMBIE;
|
||||||
break;
|
break;
|
||||||
case ARROW:
|
|
||||||
type = DisguiseType.TIPPED_ARROW;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PacketsManager {
|
public class PacketsManager {
|
||||||
@ -280,13 +279,12 @@ public class PacketsManager {
|
|||||||
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||||
entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, Integer.MAX_VALUE, true, false));
|
entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, Integer.MAX_VALUE, true, false));
|
||||||
entity.remove();
|
entity.remove();
|
||||||
//You know, as cheap as this may seem, this is pretty damn effective
|
|
||||||
} else if (disguise.getType().isMisc()) {
|
} else if (disguise.getType().isMisc()) {
|
||||||
//TODO: Fix miscs
|
//TODO: Fix falling blocks, BlockPosition Serializer in ProtocolLib
|
||||||
int id = disguise.getType().getTypeId();
|
int objectId = disguise.getType().getObjectId();
|
||||||
int data = ((MiscDisguise) disguise).getData();
|
int data = ((MiscDisguise) disguise).getData();
|
||||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||||
data = (((MiscDisguise) disguise).getId() + data << 12);
|
data = ((MiscDisguise) disguise).getId() + (data << 12);
|
||||||
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
|
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
|
||||||
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
|
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
|
||||||
data = disguisedEntity.getEntityId();
|
data = disguisedEntity.getEntityId();
|
||||||
@ -295,16 +293,15 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
||||||
spawnPackets[0] = ProtocolLibrary.getProtocolManager()
|
spawnPackets[0] = ProtocolLibrary.getProtocolManager()
|
||||||
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, id, data)
|
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
|
||||||
.createPacket(nmsEntity, id, data);
|
.createPacket(nmsEntity, objectId, data);
|
||||||
spawnPackets[0].getModifier().write(2, (int) Math.floor(loc.getY() * 32D));
|
spawnPackets[0].getModifier().write(8, pitch);
|
||||||
spawnPackets[0].getModifier().write(7, pitch);
|
spawnPackets[0].getModifier().write(9, yaw);
|
||||||
spawnPackets[0].getModifier().write(8, yaw);
|
|
||||||
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
if (data % 2 == 0) {
|
if (data % 2 == 0) {
|
||||||
spawnPackets[0].getModifier().write(3, (int) Math.floor((loc.getZ() + (data == 0 ? -1 : 1)) * 32D));
|
spawnPackets[0].getModifier().write(4, (int) Math.floor((loc.getZ() + (data == 0 ? -1 : 1)) * 32D));
|
||||||
} else {
|
} else {
|
||||||
spawnPackets[0].getModifier().write(1, (int) Math.floor((loc.getX() + (data == 3 ? -1 : 1)) * 32D));
|
spawnPackets[0].getModifier().write(2, (int) Math.floor((loc.getX() + (data == 3 ? -1 : 1)) * 32D));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,9 +384,13 @@ public class PacketsManager {
|
|||||||
value += 64;
|
value += 64;
|
||||||
break;
|
break;
|
||||||
case ENDER_DRAGON:
|
case ENDER_DRAGON:
|
||||||
|
//TODO: Enderdragon direction is... weird, consistently backwards
|
||||||
|
// value = (byte) (~value & 0xff);
|
||||||
|
break;
|
||||||
case WITHER_SKULL:
|
case WITHER_SKULL:
|
||||||
value -= 128;
|
value -= 128;
|
||||||
break;
|
break;
|
||||||
|
case ARROW:
|
||||||
case TIPPED_ARROW:
|
case TIPPED_ARROW:
|
||||||
case SPECTRAL_ARROW:
|
case SPECTRAL_ARROW:
|
||||||
value = (byte) -value;
|
value = (byte) -value;
|
||||||
@ -620,7 +621,7 @@ public class PacketsManager {
|
|||||||
// If the pitch is not the expected
|
// If the pitch is not the expected
|
||||||
if (pitch > 97 || pitch < 111)
|
if (pitch > 97 || pitch < 111)
|
||||||
return;
|
return;
|
||||||
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
|
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
|
||||||
// Min = 1.5
|
// Min = 1.5
|
||||||
// Cap = 97.5
|
// Cap = 97.5
|
||||||
// Max = 1.7
|
// Max = 1.7
|
||||||
@ -629,7 +630,7 @@ public class PacketsManager {
|
|||||||
// If the pitch is not the expected
|
// If the pitch is not the expected
|
||||||
if (pitch >= 63 || pitch <= 76)
|
if (pitch >= 63 || pitch <= 76)
|
||||||
return;
|
return;
|
||||||
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
|
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
|
||||||
// Min = 1
|
// Min = 1
|
||||||
// Cap = 63
|
// Cap = 63
|
||||||
// Max = 1.2
|
// Max = 1.2
|
||||||
@ -699,9 +700,9 @@ public class PacketsManager {
|
|||||||
mods.write(5, disSound.getDamageAndIdleSoundVolume());
|
mods.write(5, disSound.getDamageAndIdleSoundVolume());
|
||||||
float pitch;
|
float pitch;
|
||||||
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
|
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
|
||||||
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
|
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
|
||||||
} else
|
} else
|
||||||
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
|
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
|
||||||
if (disguise.getType() == DisguiseType.BAT)
|
if (disguise.getType() == DisguiseType.BAT)
|
||||||
pitch *= 95F;
|
pitch *= 95F;
|
||||||
pitch *= 63;
|
pitch *= 63;
|
||||||
@ -1355,10 +1356,10 @@ public class PacketsManager {
|
|||||||
} else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
|
} else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
|
||||||
packets[0] = sentPacket.shallowClone();
|
packets[0] = sentPacket.shallowClone();
|
||||||
StructureModifier<Byte> bytes = packets[0].getBytes();
|
StructureModifier<Byte> bytes = packets[0].getBytes();
|
||||||
byte yawValue = bytes.read(1);
|
byte yawValue = bytes.read(0);
|
||||||
bytes.write(1, getYaw(disguise.getType(), entity.getType(), yawValue));
|
bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue));
|
||||||
byte pitchValue = bytes.read(0);
|
byte pitchValue = bytes.read(1);
|
||||||
bytes.write(0, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
|
bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
|
||||||
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
|
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
StructureModifier<Double> doubles = packets[0].getDoubles();
|
StructureModifier<Double> doubles = packets[0].getDoubles();
|
||||||
Location loc = entity.getLocation();
|
Location loc = entity.getLocation();
|
||||||
|
@ -317,7 +317,9 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) {
|
public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) {
|
||||||
try {
|
try {
|
||||||
return clazz.getDeclaredConstructor(parameters);
|
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
|
||||||
|
declaredConstructor.setAccessible(true);
|
||||||
|
return declaredConstructor;
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
@ -339,7 +341,9 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
public static Field getNmsField(Class clazz, String fieldName) {
|
public static Field getNmsField(Class clazz, String fieldName) {
|
||||||
try {
|
try {
|
||||||
return clazz.getDeclaredField(fieldName);
|
Field declaredField = clazz.getDeclaredField(fieldName);
|
||||||
|
declaredField.setAccessible(true);
|
||||||
|
return declaredField;
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
@ -365,7 +369,9 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
public static Method getCraftMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
public static Method getCraftMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
||||||
try {
|
try {
|
||||||
return clazz.getDeclaredMethod(methodName, parameters);
|
Method declaredMethod = clazz.getDeclaredMethod(methodName, parameters);
|
||||||
|
declaredMethod.setAccessible(true);
|
||||||
|
return declaredMethod;
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
@ -374,7 +380,9 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
public static Method getNmsMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
public static Method getNmsMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
||||||
try {
|
try {
|
||||||
return clazz.getDeclaredMethod(methodName, parameters);
|
Method declaredMethod = clazz.getDeclaredMethod(methodName, parameters);
|
||||||
|
declaredMethod.setAccessible(true);
|
||||||
|
return declaredMethod;
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
@ -523,6 +531,7 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the NMS object EnumItemSlot from an EquipmentSlot.
|
* Creates the NMS object EnumItemSlot from an EquipmentSlot.
|
||||||
|
*
|
||||||
* @param slot
|
* @param slot
|
||||||
* @return null if the equipment slot is null
|
* @return null if the equipment slot is null
|
||||||
*/
|
*/
|
||||||
@ -550,6 +559,7 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the Bukkit object EquipmentSlot from an EnumItemSlot object.
|
* Creates the Bukkit object EquipmentSlot from an EnumItemSlot object.
|
||||||
|
*
|
||||||
* @return null if the object isn't an nms EnumItemSlot
|
* @return null if the object isn't an nms EnumItemSlot
|
||||||
*/
|
*/
|
||||||
public static EquipmentSlot createEquipmentSlot(Object enumItemSlot) {
|
public static EquipmentSlot createEquipmentSlot(Object enumItemSlot) {
|
||||||
@ -576,7 +586,8 @@ public class ReflectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets equipment from this entity based on the slot given.
|
* Gets equipment from this entity based on the slot given.
|
||||||
|
*
|
||||||
* @param slot
|
* @param slot
|
||||||
* @return null if the disguisedEntity is not an instance of a living entity
|
* @return null if the disguisedEntity is not an instance of a living entity
|
||||||
*/
|
*/
|
||||||
@ -602,6 +613,7 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Necessary for 1.9
|
* Necessary for 1.9
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String convertSoundEffectToString(Object soundEffect) {
|
public static String convertSoundEffectToString(Object soundEffect) {
|
||||||
@ -627,6 +639,7 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This creates a DataWatcherItem usable with WrappedWatchableObject
|
* This creates a DataWatcherItem usable with WrappedWatchableObject
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@ -654,5 +667,4 @@ public class ReflectionManager {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user