Update plugin to 1.13, bump maven version, bump java version to 1.8
This commit is contained in:
parent
992385c2d9
commit
49d716f285
@ -129,3 +129,5 @@ permissions:
|
||||
description: See the /disguisemodifyradius command in tab-completion
|
||||
libsdisguises.seecmd.disguisemodifyentity:
|
||||
description: See the /disguisemodifyentity command in tab-completion
|
||||
|
||||
api-version: 1.13
|
10
pom.xml
10
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>LibsDisguises</groupId>
|
||||
<artifactId>LibsDisguises</artifactId>
|
||||
<version>9.5.2-SNAPSHOT</version>
|
||||
<version>9.6.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
@ -28,8 +28,8 @@
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@ -43,12 +43,12 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-pre6-SNAPSHOT</version>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12-pre6-SNAPSHOT</version>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
@ -39,6 +39,18 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
LibsPremium.check(getDescription().getVersion());
|
||||
|
||||
if (ReflectionManager.getMinecraftVersion().startsWith("1.13")) {
|
||||
if (!LibsPremium.isPremium()) {
|
||||
System.out.println("[LibsDisguises] You must purchase the plugin to use 1.13!");
|
||||
System.out.println(
|
||||
"[LibsDisguises] This will be released free two weeks after all bugs have been fixed!");
|
||||
System.out.println(
|
||||
"[LibsDisguises] If you've already purchased the plugin, place the purchased jar inside the " +
|
||||
"Lib's Disguises plugin folder");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PacketsManager.init(this);
|
||||
DisguiseUtilities.init(this);
|
||||
|
||||
@ -426,6 +438,8 @@ public class LibsDisguises extends JavaPlugin {
|
||||
continue;
|
||||
}
|
||||
|
||||
disguiseType.setTypeId(ReflectionManager.getEntityType(nmsEntity));
|
||||
|
||||
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
||||
int entitySize = 0;
|
||||
|
||||
@ -449,36 +463,34 @@ public class LibsDisguises extends JavaPlugin {
|
||||
MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex());
|
||||
|
||||
if (flagType == null) {
|
||||
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " +
|
||||
watch.getIndex() + " can't be found!");
|
||||
System.err.println(
|
||||
"Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" +
|
||||
nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
|
||||
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
|
||||
System.err.println("[LibsDisguises] MetaIndex not found for " + disguiseType + "! Index: " +
|
||||
watch.getIndex());
|
||||
System.err.println("[LibsDisguises] Value: " + watch.getRawValue() + " (" +
|
||||
watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " +
|
||||
watcherClass.getSimpleName());
|
||||
continue;
|
||||
}
|
||||
|
||||
indexes.remove(flagType);
|
||||
|
||||
Object obj1 = ReflectionManager.convertInvalidItem(flagType.getDefault());
|
||||
Object obj2 = ReflectionManager.convertInvalidItem(watch.getValue());
|
||||
Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault());
|
||||
Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getValue());
|
||||
|
||||
if (obj1 != obj2 && ((obj1 == null || obj2 == null) || obj1.getClass() != obj2.getClass())) {
|
||||
System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " +
|
||||
watch.getIndex() + " has the wrong classtype!");
|
||||
System.err.println("MetaIndex has the " + "default of " + flagType.getDefault() + " (" +
|
||||
if (ourValue != nmsValue &&
|
||||
((ourValue == null || nmsValue == null) || ourValue.getClass() != nmsValue.getClass())) {
|
||||
System.err.println("[LibsDisguises] MetaIndex mismatch for " + disguiseType + "! Index: " +
|
||||
watch.getIndex());
|
||||
System.err.println("[LibsDisguises] MetaIndex: " + flagType.getDefault() + " (" +
|
||||
flagType.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " +
|
||||
watcherClass.getSimpleName());
|
||||
System.err.println("Where the internals is " + watch.getRawValue() + " (" +
|
||||
watch.getRawValue().getClass());
|
||||
System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
|
||||
System.err.println("[LibsDisguises] Minecraft: " + watch.getRawValue() + " (" +
|
||||
watch.getRawValue().getClass() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
for (MetaIndex index : indexes) {
|
||||
System.out.println(
|
||||
disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() +
|
||||
" at index " + index.getIndex());
|
||||
System.out.println("[LibsDisguises] " + disguiseType + " has MetaIndex remaining! " +
|
||||
index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
|
||||
}
|
||||
|
||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||
|
@ -181,7 +181,8 @@ public enum DisguiseType {
|
||||
ZOMBIE_VILLAGER;
|
||||
|
||||
static {
|
||||
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
|
||||
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older
|
||||
// versions of MC.
|
||||
// Without erroring up everything.
|
||||
|
||||
for (DisguiseType type : values()) {
|
||||
@ -191,7 +192,8 @@ public enum DisguiseType {
|
||||
String name;
|
||||
|
||||
/* 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.
|
||||
case ITEM_FRAME:
|
||||
break;
|
||||
@ -231,6 +233,7 @@ public enum DisguiseType {
|
||||
private EntityType entityType;
|
||||
|
||||
private int objectId = -1, defaultData = 0;
|
||||
private int typeId;
|
||||
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
@ -284,7 +287,11 @@ public enum DisguiseType {
|
||||
* @return
|
||||
*/
|
||||
public int getTypeId() {
|
||||
return (int) getEntityType().getTypeId();
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public Class<? extends FlagWatcher> getWatcherClass() {
|
||||
|
@ -4,12 +4,17 @@ import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.ComponentConverter;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import com.google.common.base.Strings;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -152,8 +157,8 @@ public class FlagWatcher {
|
||||
}
|
||||
}
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise()
|
||||
.getEntity() instanceof Player) {
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null &&
|
||||
getDisguise().getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
// Its a health packet
|
||||
if (watch.getIndex() == 6) {
|
||||
@ -194,7 +199,15 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
public String getCustomName() {
|
||||
return (String) getData(MetaIndex.ENTITY_CUSTOM_NAME);
|
||||
Optional<WrappedChatComponent> optional = getData(MetaIndex.ENTITY_CUSTOM_NAME);
|
||||
|
||||
if (optional.isPresent()) {
|
||||
BaseComponent[] base = ComponentConverter.fromWrapper(optional.get());
|
||||
|
||||
return TextComponent.toLegacyText(base);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected TargetedDisguise getDisguise() {
|
||||
@ -329,8 +342,8 @@ public class FlagWatcher {
|
||||
|
||||
Object value = entityValues.get(data.getIndex());
|
||||
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig
|
||||
.isMetadataPacketsEnabled() && data == MetaIndex.ENTITY_META) {
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() &&
|
||||
data == MetaIndex.ENTITY_META) {
|
||||
value = addEntityAnimations((byte) value,
|
||||
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
@ -391,11 +404,16 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
public void setCustomName(String name) {
|
||||
if (name != null && name.length() > 64) {
|
||||
name = name.substring(0, 64);
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.<WrappedChatComponent>empty());
|
||||
} else {
|
||||
if (name.length() > 64) {
|
||||
name = name.substring(0, 64);
|
||||
}
|
||||
|
||||
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name)));
|
||||
}
|
||||
|
||||
setData(MetaIndex.ENTITY_CUSTOM_NAME, name);
|
||||
sendData(MetaIndex.ENTITY_CUSTOM_NAME);
|
||||
}
|
||||
|
||||
@ -454,8 +472,8 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
protected void sendItemStack(EquipmentSlot slot, ItemStack itemStack) {
|
||||
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this || getDisguise()
|
||||
.getEntity() == null)
|
||||
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this ||
|
||||
getDisguise().getEntity() == null)
|
||||
return;
|
||||
|
||||
if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) {
|
||||
|
@ -1,15 +1,14 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
import com.comphenix.protocol.wrappers.Vector3F;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import com.google.common.base.Optional;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -27,11 +26,8 @@ public class MetaIndex<Y> {
|
||||
public static MetaIndex<Boolean> AREA_EFFECT_IGNORE_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 2,
|
||||
false);
|
||||
|
||||
public static MetaIndex<Integer> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, 0);
|
||||
|
||||
public static MetaIndex<Integer> AREA_EFFECT_PARTICLE_PARAM_1 = new MetaIndex<>(AreaEffectCloudWatcher.class, 4, 0);
|
||||
|
||||
public static MetaIndex<Integer> AREA_EFFECT_PARTICLE_PARAM_2 = new MetaIndex<>(AreaEffectCloudWatcher.class, 5, 0);
|
||||
public static MetaIndex<Particle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class,
|
||||
3, Particle.SPELL_MOB);
|
||||
|
||||
public static MetaIndex<Float> AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 0F);
|
||||
|
||||
@ -73,6 +69,8 @@ public class MetaIndex<Y> {
|
||||
|
||||
public static MetaIndex<Integer> BOAT_TYPE = new MetaIndex<>(BoatWatcher.class, 3, 0);
|
||||
|
||||
public static MetaIndex<Integer> BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0);
|
||||
|
||||
public static MetaIndex<Boolean> CREEPER_IGNITED = new MetaIndex<>(CreeperWatcher.class, 2, false);
|
||||
|
||||
public static MetaIndex<Boolean> CREEPER_POWERED = new MetaIndex<>(CreeperWatcher.class, 1, false);
|
||||
@ -83,7 +81,7 @@ public class MetaIndex<Y> {
|
||||
new ItemStack(Material.STONE));
|
||||
|
||||
public static MetaIndex<Optional<BlockPosition>> ENDER_CRYSTAL_BEAM = new MetaIndex<>(EnderCrystalWatcher.class, 0,
|
||||
Optional.<BlockPosition>absent());
|
||||
Optional.empty());
|
||||
|
||||
public static MetaIndex<Boolean> ENDER_CRYSTAL_PLATE = new MetaIndex<>(EnderCrystalWatcher.class, 1, false);
|
||||
|
||||
@ -92,11 +90,12 @@ public class MetaIndex<Y> {
|
||||
public static MetaIndex<Boolean> ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false);
|
||||
|
||||
public static MetaIndex<Optional<WrappedBlockData>> ENDERMAN_ITEM = new MetaIndex<>(EndermanWatcher.class, 0,
|
||||
Optional.<WrappedBlockData>absent());
|
||||
Optional.empty());
|
||||
|
||||
public static MetaIndex<Integer> ENTITY_AIR_TICKS = new MetaIndex<>(FlagWatcher.class, 1, 0);
|
||||
|
||||
public static MetaIndex<String> ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2, "");
|
||||
public static MetaIndex<Optional<WrappedChatComponent>> ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2,
|
||||
Optional.empty());
|
||||
|
||||
public static MetaIndex<Boolean> ENTITY_CUSTOM_NAME_VISIBLE = new MetaIndex<>(FlagWatcher.class, 3, false);
|
||||
|
||||
@ -132,7 +131,7 @@ public class MetaIndex<Y> {
|
||||
public static MetaIndex<Byte> HORSE_META = new MetaIndex<>(AbstractHorseWatcher.class, 0, (byte) 0);
|
||||
|
||||
public static MetaIndex<Optional<UUID>> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1,
|
||||
Optional.<UUID>absent());
|
||||
Optional.empty());
|
||||
|
||||
public static MetaIndex<Byte> ILLAGER_META = new MetaIndex<>(IllagerWatcher.class, 0, (byte) 0);
|
||||
|
||||
@ -181,7 +180,7 @@ public class MetaIndex<Y> {
|
||||
|
||||
public static MetaIndex<Boolean> PIG_SADDLED = new MetaIndex<>(PigWatcher.class, 0, false);
|
||||
|
||||
public static MetaIndex<Integer> PIG_UNKNOWN = new MetaIndex<>(PigWatcher.class, 1, 0);
|
||||
public static MetaIndex<Integer> PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0);
|
||||
|
||||
public static MetaIndex<Float> PLAYER_ABSORPTION = new MetaIndex<>(PlayerWatcher.class, 0, 0F);
|
||||
|
||||
@ -191,11 +190,11 @@ public class MetaIndex<Y> {
|
||||
|
||||
public static MetaIndex<Byte> PLAYER_SKIN = new MetaIndex<>(PlayerWatcher.class, 2, (byte) 127);
|
||||
|
||||
public static MetaIndex<NbtCompound> PLAYER_LEFT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 4,
|
||||
NbtFactory.ofCompound("None"));
|
||||
public static MetaIndex<NbtBase> PLAYER_LEFT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 4,
|
||||
NbtFactory.ofWrapper(NbtType.TAG_COMPOUND, "None"));
|
||||
|
||||
public static MetaIndex<NbtCompound> PLAYER_RIGHT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 5,
|
||||
NbtFactory.ofCompound("None"));
|
||||
public static MetaIndex<NbtBase> PLAYER_RIGHT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 5,
|
||||
NbtFactory.ofWrapper(NbtType.TAG_COMPOUND, "None"));
|
||||
|
||||
public static MetaIndex<Boolean> POLAR_BEAR_STANDING = new MetaIndex<>(PolarBearWatcher.class, 0, false);
|
||||
|
||||
@ -204,7 +203,7 @@ public class MetaIndex<Y> {
|
||||
public static MetaIndex<Byte> SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0);
|
||||
|
||||
public static MetaIndex<Optional<BlockPosition>> SHULKER_ATTACHED = new MetaIndex<>(ShulkerWatcher.class, 1,
|
||||
Optional.<BlockPosition>absent());
|
||||
Optional.empty());
|
||||
|
||||
public static MetaIndex<Byte> SHULKER_COLOR = new MetaIndex<>(ShulkerWatcher.class, 3, (byte) 10);
|
||||
|
||||
@ -225,7 +224,7 @@ public class MetaIndex<Y> {
|
||||
public static MetaIndex<Byte> TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0);
|
||||
|
||||
public static MetaIndex<Optional<UUID>> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1,
|
||||
Optional.<UUID>absent());
|
||||
Optional.empty());
|
||||
|
||||
public static MetaIndex<Integer> TIPPED_ARROW_COLOR = new MetaIndex<>(ArrowWatcher.class, 1, Color.WHITE.asRGB());
|
||||
|
||||
@ -259,6 +258,8 @@ public class MetaIndex<Y> {
|
||||
|
||||
public static MetaIndex<Boolean> ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false);
|
||||
|
||||
public static MetaIndex<Boolean> ZOMBIE_CONVERTING_DROWNED = new MetaIndex<>(ZombieWatcher.class, 3, false);
|
||||
|
||||
public static MetaIndex<Integer> ZOMBIE_PLACEHOLDER = new MetaIndex<>(ZombieWatcher.class, 1, 0);
|
||||
|
||||
public static MetaIndex<Integer> ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1, 0);
|
||||
@ -273,10 +274,13 @@ public class MetaIndex<Y> {
|
||||
catch (Exception ex) {
|
||||
SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, new ItemStack(Material.POTION));
|
||||
}
|
||||
|
||||
setValues();
|
||||
orderMetaIndexes();
|
||||
}
|
||||
|
||||
public static void eliminateBlankIndexes() {
|
||||
@Deprecated
|
||||
private static void eliminateBlankIndexes() {
|
||||
ArrayList<Entry<Class, ArrayList<MetaIndex>>> list = new ArrayList<>();
|
||||
|
||||
for (MetaIndex index : values()) {
|
||||
@ -292,6 +296,7 @@ public class MetaIndex<Y> {
|
||||
|
||||
if (entry == null) {
|
||||
entry = new AbstractMap.SimpleEntry(index.getFlagWatcher(), new ArrayList<MetaIndex>());
|
||||
|
||||
list.add(entry);
|
||||
}
|
||||
|
||||
@ -299,12 +304,7 @@ public class MetaIndex<Y> {
|
||||
}
|
||||
|
||||
for (Entry<Class, ArrayList<MetaIndex>> entry : list) {
|
||||
Collections.sort(entry.getValue(), new Comparator<MetaIndex>() {
|
||||
@Override
|
||||
public int compare(MetaIndex o1, MetaIndex o2) {
|
||||
return o1.getIndex() - o2.getIndex();
|
||||
}
|
||||
});
|
||||
entry.getValue().sort(Comparator.comparingInt(MetaIndex::getIndex));
|
||||
|
||||
for (MetaIndex ind : entry.getValue()) {
|
||||
ind._index = entry.getValue().indexOf(ind);
|
||||
@ -312,7 +312,7 @@ public class MetaIndex<Y> {
|
||||
}
|
||||
}
|
||||
|
||||
public static void orderMetaIndexes() {
|
||||
private static void orderMetaIndexes() {
|
||||
for (MetaIndex flagType : values()) {
|
||||
if (flagType.getFlagWatcher() == FlagWatcher.class)
|
||||
continue;
|
||||
@ -349,10 +349,10 @@ public class MetaIndex<Y> {
|
||||
continue;
|
||||
|
||||
if (found != null) {
|
||||
System.err.println(entry.getKey()
|
||||
.getSimpleName() + " has multiple FlagType's registered for the index " + i + " (" + type
|
||||
.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher()
|
||||
.getSimpleName() + ")");
|
||||
System.err.println(
|
||||
entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " +
|
||||
i + " (" + type.getFlagWatcher().getSimpleName() + ", " +
|
||||
found.getFlagWatcher().getSimpleName() + ")");
|
||||
continue loop;
|
||||
}
|
||||
|
||||
@ -377,15 +377,16 @@ public class MetaIndex<Y> {
|
||||
|
||||
MetaIndex index = (MetaIndex) field.get(null);
|
||||
|
||||
toPrint.add(index.getFlagWatcher().getSimpleName() + " " + field.getName() + " " + index
|
||||
.getIndex() + " " + index.getDefault().getClass().getSimpleName());
|
||||
toPrint.add(
|
||||
index.getFlagWatcher().getSimpleName() + " " + field.getName() + " " + index.getIndex() + " " +
|
||||
index.getDefault().getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Collections.sort(toPrint, String.CASE_INSENSITIVE_ORDER);
|
||||
toPrint.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (String s : toPrint) {
|
||||
System.out.println(s);
|
||||
@ -416,12 +417,7 @@ public class MetaIndex<Y> {
|
||||
list.add(type);
|
||||
}
|
||||
|
||||
Collections.sort(list, new Comparator<MetaIndex>() {
|
||||
@Override
|
||||
public int compare(MetaIndex o1, MetaIndex o2) {
|
||||
return Integer.compare(o1.getIndex(), o2.getIndex());
|
||||
}
|
||||
});
|
||||
list.sort(Comparator.comparingInt(MetaIndex::getIndex));
|
||||
|
||||
return list;
|
||||
}
|
||||
@ -460,15 +456,15 @@ public class MetaIndex<Y> {
|
||||
}
|
||||
|
||||
for (MetaIndex metaIndex : values()) {
|
||||
if (metaIndex == null || metaIndex.getFlagWatcher() != index.getFlagWatcher() || metaIndex
|
||||
.getIndex() != index.getIndex()) {
|
||||
if (metaIndex == null || metaIndex.getFlagWatcher() != index.getFlagWatcher() ||
|
||||
metaIndex.getIndex() != index.getIndex()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.err.println("[LibsDisguises] MetaIndex " + metaIndex.getFlagWatcher()
|
||||
.getSimpleName() + " at index " + metaIndex
|
||||
.getIndex() + " has already registered this! (" + metaIndex.getDefault() + "," + index
|
||||
.getDefault() + ")");
|
||||
System.err.println(
|
||||
"[LibsDisguises] MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " +
|
||||
metaIndex.getIndex() + " has already registered this! (" + metaIndex.getDefault() +
|
||||
"," + index.getDefault() + ")");
|
||||
}
|
||||
|
||||
values()[i] = metaIndexes[a];
|
||||
|
@ -1,16 +1,16 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class MiscDisguise extends TargetedDisguise {
|
||||
private int id = -1, data = 0;
|
||||
@ -19,6 +19,18 @@ public class MiscDisguise extends TargetedDisguise {
|
||||
this(disguiseType, -1, disguiseType.getDefaultData());
|
||||
}
|
||||
|
||||
public MiscDisguise(Material material, int data) {
|
||||
super(DisguiseType.DROPPED_ITEM);
|
||||
|
||||
apply(0, 0, new ItemStack(material, 1, (short) data));
|
||||
}
|
||||
|
||||
public MiscDisguise(ItemStack itemStack) {
|
||||
super(DisguiseType.DROPPED_ITEM);
|
||||
|
||||
apply(0, 0, itemStack);
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, int id) {
|
||||
this(disguiseType, id, disguiseType.getDefaultData());
|
||||
}
|
||||
@ -28,34 +40,37 @@ public class MiscDisguise extends TargetedDisguise {
|
||||
|
||||
if (!disguiseType.isMisc()) {
|
||||
throw new InvalidParameterException(
|
||||
"Expected a non-living DisguiseType while constructing MiscDisguise. Received " + disguiseType + " instead. Please use " + (
|
||||
disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise") + " instead");
|
||||
"Expected a non-living DisguiseType while constructing MiscDisguise. Received " + disguiseType +
|
||||
" instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise") +
|
||||
" instead");
|
||||
}
|
||||
|
||||
apply(id, data, new ItemStack(Material.STONE));
|
||||
}
|
||||
|
||||
private void apply(int id, int data, ItemStack itemStack) {
|
||||
createDisguise();
|
||||
|
||||
this.id = getType().getTypeId();
|
||||
this.data = getType().getDefaultData();
|
||||
switch (disguiseType) {
|
||||
|
||||
switch (getType()) {
|
||||
// The only disguises which should use a custom data.
|
||||
case PAINTING:
|
||||
((PaintingWatcher) getWatcher()).setArt(Art.values()[Math.max(0, id) % Art.values().length]);
|
||||
break;
|
||||
case FALLING_BLOCK:
|
||||
((FallingBlockWatcher) getWatcher()).setBlock(
|
||||
new ItemStack(Math.max(1, id), 1, (short) Math.max(0, data)));
|
||||
((FallingBlockWatcher) getWatcher()).setBlock(itemStack);
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id));
|
||||
break;
|
||||
case DROPPED_ITEM:
|
||||
|
||||
if (id > 0) {
|
||||
((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(1, data)));
|
||||
}
|
||||
((DroppedItemWatcher) getWatcher()).setItemStack(itemStack);
|
||||
break;
|
||||
case FISHING_HOOK: // Entity ID of whoever is holding fishing rod
|
||||
case ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving through his body?"
|
||||
case ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving
|
||||
// through his body?"
|
||||
case TIPPED_ARROW:
|
||||
case SPECTRAL_ARROW:
|
||||
case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
|
||||
@ -116,8 +131,9 @@ public class MiscDisguise extends TargetedDisguise {
|
||||
*/
|
||||
public int getId() {
|
||||
if (getType() == DisguiseType.FALLING_BLOCK) {
|
||||
return ((FallingBlockWatcher) getWatcher()).getBlock().getTypeId();
|
||||
return ((FallingBlockWatcher) getWatcher()).getBlock().getType().ordinal();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractHorseWatcher extends AgeableWatcher {
|
||||
public AbstractHorseWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
|
@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
@ -27,10 +28,6 @@ public class AreaEffectCloudWatcher extends FlagWatcher {
|
||||
return getData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS);
|
||||
}
|
||||
|
||||
public int getParticleId() {
|
||||
return getData(MetaIndex.AREA_EFFECT_PARTICLE);
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
if (radius > 30)
|
||||
radius = 30;
|
||||
@ -49,8 +46,12 @@ public class AreaEffectCloudWatcher extends FlagWatcher {
|
||||
sendData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS);
|
||||
}
|
||||
|
||||
public void setParticleId(int particleId) {
|
||||
setData(MetaIndex.AREA_EFFECT_PARTICLE, particleId);
|
||||
public void setParticleType(Particle particle) {
|
||||
setData(MetaIndex.AREA_EFFECT_PARTICLE, particle);
|
||||
sendData(MetaIndex.AREA_EFFECT_PARTICLE);
|
||||
}
|
||||
|
||||
public Particle getParticleType() {
|
||||
return getData(MetaIndex.AREA_EFFECT_PARTICLE);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.TreeSpecies;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.TreeSpecies;
|
||||
|
||||
public class BoatWatcher extends FlagWatcher {
|
||||
public BoatWatcher(Disguise disguise) {
|
||||
@ -45,8 +44,16 @@ public class BoatWatcher extends FlagWatcher {
|
||||
sendData(MetaIndex.BOAT_TYPE);
|
||||
}
|
||||
|
||||
public void setBoatShake(int number) {
|
||||
setData(MetaIndex.BOAT_SHAKE, number);
|
||||
sendData(MetaIndex.BOAT_SHAKE);
|
||||
}
|
||||
|
||||
public int getBoatShake() {
|
||||
return getData(MetaIndex.BOAT_SHAKE);
|
||||
}
|
||||
|
||||
public TreeSpecies getBoatType() {
|
||||
return TreeSpecies.getByData(getData(MetaIndex.BOAT_TYPE).byteValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
|
@ -1,85 +1,60 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
public class EndermanWatcher extends InsentientWatcher {
|
||||
|
||||
public class EndermanWatcher extends InsentientWatcher
|
||||
{
|
||||
|
||||
public EndermanWatcher(Disguise disguise)
|
||||
{
|
||||
public EndermanWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInMainHand()
|
||||
{
|
||||
public ItemStack getItemInMainHand() {
|
||||
Optional<WrappedBlockData> value = getData(MetaIndex.ENDERMAN_ITEM);
|
||||
|
||||
if (value.isPresent())
|
||||
{
|
||||
if (value.isPresent()) {
|
||||
WrappedBlockData pair = value.get();
|
||||
Material id = pair.getType();
|
||||
int data = pair.getData();
|
||||
|
||||
return new ItemStack(id, 1, (short) data);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(ItemStack itemstack)
|
||||
{
|
||||
setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability());
|
||||
public void setItemInMainHand(ItemStack itemstack) {
|
||||
setItemInMainHand(itemstack.getType(), itemstack.getDurability());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setItemInMainHand(int typeId)
|
||||
{
|
||||
setItemInMainHand(typeId, 0);
|
||||
}
|
||||
|
||||
public void setItemInMainHand(Material type)
|
||||
{
|
||||
public void setItemInMainHand(Material type) {
|
||||
setItemInMainHand(type, 0);
|
||||
}
|
||||
|
||||
public void setItemInMainHand(Material type, int data)
|
||||
{
|
||||
public void setItemInMainHand(Material type, int data) {
|
||||
Optional<WrappedBlockData> optional;
|
||||
|
||||
if (type == null)
|
||||
optional = Optional.<WrappedBlockData> absent();
|
||||
optional = Optional.empty();
|
||||
else
|
||||
optional = Optional.<WrappedBlockData> of(WrappedBlockData.createData(type, data));
|
||||
optional = Optional.of(WrappedBlockData.createData(type, data));
|
||||
|
||||
setData(MetaIndex.ENDERMAN_ITEM, optional);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setItemInMainHand(int typeId, int data)
|
||||
{
|
||||
setItemInMainHand(Material.getMaterial(typeId), data);
|
||||
}
|
||||
|
||||
public boolean isAggressive()
|
||||
{
|
||||
public boolean isAggressive() {
|
||||
return getData(MetaIndex.ENDERMAN_AGRESSIVE);
|
||||
}
|
||||
|
||||
public void setAggressive(boolean isAggressive)
|
||||
{
|
||||
public void setAggressive(boolean isAggressive) {
|
||||
setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive);
|
||||
sendData(MetaIndex.ENDERMAN_AGRESSIVE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ public class HorseWatcher extends AbstractHorseWatcher {
|
||||
|
||||
switch (horseValue) {
|
||||
case 1:
|
||||
return new ItemStack(Material.IRON_BARDING);
|
||||
return new ItemStack(Material.IRON_HORSE_ARMOR);
|
||||
case 2:
|
||||
return new ItemStack(Material.GOLD_BARDING);
|
||||
return new ItemStack(Material.GOLDEN_HORSE_ARMOR);
|
||||
case 3:
|
||||
return new ItemStack(Material.DIAMOND_BARDING);
|
||||
return new ItemStack(Material.DIAMOND_HORSE_ARMOR);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -67,13 +67,13 @@ public class HorseWatcher extends AbstractHorseWatcher {
|
||||
if (item != null) {
|
||||
Material mat = item.getType();
|
||||
|
||||
if (mat == Material.IRON_BARDING) {
|
||||
if (mat == Material.IRON_HORSE_ARMOR) {
|
||||
value = 1;
|
||||
}
|
||||
else if (mat == Material.GOLD_BARDING) {
|
||||
else if (mat == Material.GOLDEN_HORSE_ARMOR) {
|
||||
value = 2;
|
||||
}
|
||||
else if (mat == Material.DIAMOND_BARDING) {
|
||||
else if (mat == Material.DIAMOND_HORSE_ARMOR) {
|
||||
value = 3;
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,43 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
public class MinecartWatcher extends FlagWatcher {
|
||||
|
||||
public class MinecartWatcher extends FlagWatcher
|
||||
{
|
||||
|
||||
public MinecartWatcher(Disguise disguise)
|
||||
{
|
||||
public MinecartWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public ItemStack getBlockInCart()
|
||||
{
|
||||
int id = (int) getData(MetaIndex.MINECART_BLOCK) & 0xffff;
|
||||
int data = (int) getData(MetaIndex.MINECART_BLOCK) >> 16;
|
||||
|
||||
return new ItemStack(id, 1, (short) data);
|
||||
public ItemStack getBlockInCart() {
|
||||
return ReflectionManager.getItemStackByCombinedId(getData(MetaIndex.MINECART_BLOCK));
|
||||
}
|
||||
|
||||
public int getBlockYOffset()
|
||||
{
|
||||
return (int) getData(MetaIndex.MINECART_BLOCK_Y);
|
||||
public int getBlockYOffset() {
|
||||
return getData(MetaIndex.MINECART_BLOCK_Y);
|
||||
}
|
||||
|
||||
public boolean isViewBlockInCart()
|
||||
{
|
||||
return (boolean) getData(MetaIndex.MINECART_BLOCK_VISIBLE);
|
||||
public boolean isViewBlockInCart() {
|
||||
return getData(MetaIndex.MINECART_BLOCK_VISIBLE);
|
||||
}
|
||||
|
||||
public void setBlockInCart(ItemStack item)
|
||||
{
|
||||
int id = item.getTypeId();
|
||||
int data = item.getDurability();
|
||||
public void setBlockInCart(ItemStack item) {
|
||||
setData(MetaIndex.MINECART_BLOCK, ReflectionManager.getCombinedIdByItemStack(item));
|
||||
setData(MetaIndex.MINECART_BLOCK_VISIBLE, item != null && item.getType() != Material.AIR);
|
||||
|
||||
setData(MetaIndex.MINECART_BLOCK, id & 0xffff | data << 16);
|
||||
setData(MetaIndex.MINECART_BLOCK_VISIBLE, true); // Show block
|
||||
|
||||
sendData(MetaIndex.MINECART_BLOCK);
|
||||
sendData(MetaIndex.MINECART_BLOCK, MetaIndex.MINECART_BLOCK_VISIBLE);
|
||||
}
|
||||
|
||||
public void setBlockOffset(int i)
|
||||
{
|
||||
public void setBlockOffset(int i) {
|
||||
setData(MetaIndex.MINECART_BLOCK_Y, i);
|
||||
sendData(MetaIndex.MINECART_BLOCK_Y);
|
||||
}
|
||||
|
||||
public void setViewBlockInCart(boolean viewBlock)
|
||||
{
|
||||
public void setViewBlockInCart(boolean viewBlock) {
|
||||
setData(MetaIndex.MINECART_BLOCK_VISIBLE, viewBlock);
|
||||
sendData(MetaIndex.MINECART_BLOCK_VISIBLE);
|
||||
}
|
||||
|
@ -10,20 +10,11 @@ public class PigWatcher extends AgeableWatcher {
|
||||
}
|
||||
|
||||
public boolean isSaddled() {
|
||||
return (boolean) getData(MetaIndex.PIG_SADDLED);
|
||||
return getData(MetaIndex.PIG_SADDLED);
|
||||
}
|
||||
|
||||
public void setSaddled(boolean isSaddled) {
|
||||
setData(MetaIndex.PIG_SADDLED, isSaddled);
|
||||
sendData(MetaIndex.PIG_SADDLED);
|
||||
}
|
||||
|
||||
/* public int getUnknown() {
|
||||
return getData(FlagType.PIG_UNKNOWN);
|
||||
}
|
||||
|
||||
public void setUnknown(int unknown) {
|
||||
setData(FlagType.PIG_UNKNOWN, unknown);
|
||||
sendData(FlagType.PIG_UNKNOWN);
|
||||
}*/
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
|
@ -1,12 +1,11 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TameableWatcher extends AgeableWatcher
|
||||
{
|
||||
public TameableWatcher(Disguise disguise)
|
||||
|
@ -39,4 +39,12 @@ public class ZombieWatcher extends InsentientWatcher {
|
||||
sendData(MetaIndex.ZOMBIE_AGGRESSIVE);
|
||||
}
|
||||
|
||||
public boolean isConverting() {
|
||||
return getData(MetaIndex.ZOMBIE_CONVERTING_DROWNED);
|
||||
}
|
||||
|
||||
public void setConverting(boolean converting) {
|
||||
setData(MetaIndex.ZOMBIE_CONVERTING_DROWNED, converting);
|
||||
sendData(MetaIndex.ZOMBIE_CONVERTING_DROWNED);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -22,6 +23,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DisguiseParser {
|
||||
public static class DisguiseParseException extends Exception {
|
||||
@ -110,13 +112,7 @@ public class DisguiseParser {
|
||||
if (disguiseType != other.disguiseType)
|
||||
return false;
|
||||
|
||||
if (permName == null) {
|
||||
if (other.permName != null)
|
||||
return false;
|
||||
} else if (!permName.equals(other.permName))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return Objects.equals(permName, other.permName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,6 +581,7 @@ public class DisguiseParser {
|
||||
disguise = new MobDisguise(disguisePerm.getType(), adult);
|
||||
} else if (disguisePerm.isMisc()) {
|
||||
// Its a misc, we are going to use the MiscDisguise constructor.
|
||||
ItemStack itemStack = new ItemStack(Material.STONE);
|
||||
int miscId = -1;
|
||||
int miscData = -1;
|
||||
String secondArg = null;
|
||||
@ -607,6 +604,7 @@ public class DisguiseParser {
|
||||
disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
|
||||
for (Material mat : Material.values()) {
|
||||
if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
|
||||
itemStack = new ItemStack(mat);
|
||||
miscId = mat.getId();
|
||||
break;
|
||||
}
|
||||
@ -681,8 +679,13 @@ public class DisguiseParser {
|
||||
doCheck(sender, optionPermissions, usedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the disguise
|
||||
disguise = new MiscDisguise(disguisePerm.getType(), miscId, miscData);
|
||||
if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
|
||||
disguise = new MiscDisguise(itemStack);
|
||||
} else {
|
||||
disguise = new MiscDisguise(disguisePerm.getType(), miscId, miscData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -888,6 +891,7 @@ public class DisguiseParser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
throw new Exception();
|
||||
}
|
||||
@ -907,8 +911,26 @@ public class DisguiseParser {
|
||||
catch (Exception ex) {
|
||||
throw parseToException(param, valueString, methodName);
|
||||
}
|
||||
} else if (param.getName().equals("org.bukkit.entity.Parrot$Variant")) {
|
||||
} else if (param == Parrot.Variant.class) {
|
||||
value = callValueOf(param, valueString, methodName);
|
||||
} else if (param == Particle.class) {
|
||||
try {
|
||||
for (Particle type : Particle.values()) {
|
||||
if (type.name().replace("_", "")
|
||||
.equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) {
|
||||
value = type;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw parseToException(param, valueString, methodName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -979,21 +1001,13 @@ public class DisguiseParser {
|
||||
private static ItemStack parseToItemstack(Class param, String method, String string) throws DisguiseParseException {
|
||||
String[] split = string.split(":", -1);
|
||||
|
||||
int itemId = -1;
|
||||
|
||||
if (split[0].isEmpty() || split[0].equalsIgnoreCase("null")) {
|
||||
return null;
|
||||
} else if (isInteger(split[0])) {
|
||||
itemId = Integer.parseInt(split[0]);
|
||||
} else {
|
||||
try {
|
||||
itemId = Material.valueOf(split[0].toUpperCase()).getId();
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (itemId != -1) {
|
||||
Material material = Material.getMaterial(split[0]);
|
||||
|
||||
if (material != null) {
|
||||
short itemDura = 0;
|
||||
int amount = 1;
|
||||
boolean enchanted = false;
|
||||
@ -1018,7 +1032,7 @@ public class DisguiseParser {
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(itemId, amount, itemDura);
|
||||
ItemStack itemStack = new ItemStack(material, amount, itemDura);
|
||||
|
||||
if (enchanted) {
|
||||
itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
|
||||
|
@ -23,8 +23,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.backwards.BackwardMethods;
|
||||
import me.libraryaddict.disguise.utilities.backwards.BackwardsSupport;
|
||||
import me.libraryaddict.disguise.utilities.json.*;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -50,10 +48,7 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -81,7 +76,6 @@ public class DisguiseUtilities {
|
||||
private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File(
|
||||
"plugins/LibsDisguises/SavedDisguises");
|
||||
private static Gson gson;
|
||||
private static BackwardMethods methods;
|
||||
private static boolean pluginsUsed, commandsUsed;
|
||||
private static long libsDisguisesCalled;
|
||||
|
||||
@ -851,7 +845,6 @@ public class DisguiseUtilities {
|
||||
|
||||
public static void init(LibsDisguises disguises) {
|
||||
libsDisguises = disguises;
|
||||
methods = BackwardsSupport.getMethods();
|
||||
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex());
|
||||
@ -867,21 +860,43 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
||||
Object world = ((List) server.getClass().getField("worlds").get(server)).get(0);
|
||||
Class chunkClass = ReflectionManager.getNmsClass("Chunk");
|
||||
Object bedChunk = null;
|
||||
|
||||
Object bedChunk = ReflectionManager.getNmsClass("Chunk")
|
||||
.getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class)
|
||||
.newInstance(world, 0, 0);
|
||||
for (Constructor constructor : chunkClass.getConstructors()) {
|
||||
if (constructor.getParameterTypes().length != 8)
|
||||
continue;
|
||||
|
||||
Field cSection = bedChunk.getClass().getDeclaredField("sections");
|
||||
bedChunk = constructor
|
||||
.newInstance(world, 0, 0, Array.newInstance(ReflectionManager.getNmsClass("BiomeBase"), 0),
|
||||
null, null, null, 0L);
|
||||
break;
|
||||
}
|
||||
|
||||
if (bedChunk == null) {
|
||||
throw new IllegalStateException("[LibsDisguises] Cannot find constructor to create world chunk");
|
||||
}
|
||||
|
||||
Field cSection = chunkClass.getDeclaredField("sections");
|
||||
cSection.setAccessible(true);
|
||||
|
||||
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class)
|
||||
.newInstance(0, true);
|
||||
|
||||
Object block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class)
|
||||
.invoke(null, Material.BED_BLOCK.getId());
|
||||
Class blockClass = ReflectionManager.getNmsClass("Block");
|
||||
|
||||
Object block = blockClass.getMethod("getByName", String.class).invoke(null, "white_bed");
|
||||
Object blockData = ReflectionManager.getNmsMethod(blockClass, "getBlockData").invoke(block);
|
||||
Method method = null;
|
||||
|
||||
for (Method method1 : blockData.getClass().getMethods()) {
|
||||
if (!method1.getName().equals("set") || method1.getParameterTypes().length != 2)
|
||||
continue;
|
||||
|
||||
method = method1;
|
||||
break;
|
||||
}
|
||||
|
||||
Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class);
|
||||
Method setType = chunkSection.getClass()
|
||||
.getMethod("setType", int.class, int.class, int.class, ReflectionManager.getNmsClass("IBlockData"));
|
||||
Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class);
|
||||
@ -889,10 +904,12 @@ public class DisguiseUtilities {
|
||||
|
||||
for (BlockFace face : new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}) {
|
||||
int x = 1 + face.getModX();
|
||||
|
||||
int z = 1 + face.getModZ();
|
||||
|
||||
setType.invoke(chunkSection, x, 0, z, fromLegacyData.invoke(block, face.ordinal()));
|
||||
Object data = method.invoke(blockData, block.getClass().getField("FACING").get(null),
|
||||
ReflectionManager.getEnumDirection(face.ordinal()));
|
||||
|
||||
setType.invoke(chunkSection, x, 0, z, data);
|
||||
}
|
||||
|
||||
Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16);
|
||||
@ -1018,9 +1035,7 @@ public class DisguiseUtilities {
|
||||
}
|
||||
catch (
|
||||
|
||||
Exception ex)
|
||||
|
||||
{
|
||||
Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class LibsPremium {
|
||||
public static void check(String version) {
|
||||
thisPluginIsPaidFor = isPremium();
|
||||
|
||||
if (!isPremium() && version.contains("SNAPSHOT")) {
|
||||
if (!isPremium()) {
|
||||
File[] files = new File("plugins/LibsDisguises/").listFiles();
|
||||
|
||||
if (files == null)
|
||||
@ -58,7 +58,7 @@ public class LibsPremium {
|
||||
thisPluginIsPaidFor = (Boolean) m.invoke(null);
|
||||
|
||||
if (isPremium()) {
|
||||
System.out.println("[LibsDisguises] Found a premium Lib's Disguises jar");
|
||||
System.out.println("[LibsDisguises] Found a premium Lib's Disguises jar, premium enabled!");
|
||||
|
||||
break;
|
||||
} else {
|
||||
|
@ -501,11 +501,8 @@ public class PacketsManager {
|
||||
if (watchableObject.getValue() == null)
|
||||
continue;
|
||||
|
||||
if (Registry.get(watchableObject.getValue().getClass()) == null)
|
||||
continue;
|
||||
|
||||
WrappedDataWatcherObject obj = new WrappedDataWatcherObject(watchableObject.getIndex(),
|
||||
Registry.get(watchableObject.getValue().getClass()));
|
||||
WrappedDataWatcherObject obj = ReflectionManager
|
||||
.createDataWatcherObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||
|
||||
newWatcher.setObject(obj, watchableObject.getValue());
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MainHand;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
|
||||
@ -49,10 +49,6 @@ public class ReflectionFlagWatchers {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public ParamInfo(String className, String name, String description) throws ClassNotFoundException {
|
||||
this(Class.forName(className), name, description);
|
||||
}
|
||||
|
||||
public ParamInfo(Class paramClass, Enum[] enums, String name, String description) {
|
||||
this(name, description);
|
||||
this.enums = new String[enums.length];
|
||||
@ -143,14 +139,6 @@ public class ReflectionFlagWatchers {
|
||||
static {
|
||||
new ParamInfo(AnimalColor.class, "Animal Color", "View all the colors you can use for an animal color");
|
||||
new ParamInfo(Art.class, "Art", "View all the paintings you can use for a painting disguise");
|
||||
|
||||
try {
|
||||
new ParamInfo("org.bukkit.entity.Llama.Color", "Llama Color",
|
||||
"View all the colors you can use for a llama color");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
|
||||
new ParamInfo(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color");
|
||||
|
||||
new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots");
|
||||
@ -162,21 +150,10 @@ public class ReflectionFlagWatchers {
|
||||
new ParamInfo(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into");
|
||||
new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species");
|
||||
new ParamInfo(EulerAngle.class, "Euler Angle (X,Y,Z)", "Set the X,Y,Z directions on an armorstand");
|
||||
|
||||
try {
|
||||
new ParamInfo("org.bukkit.inventory.MainHand", "Main Hand", "Set the main hand for an entity");
|
||||
new ParamInfo("org.bukkit.entity.Llama.Color", "Llama Color",
|
||||
"View all the colors you can use for a llama color");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
|
||||
try {
|
||||
new ParamInfo("org.bukkit.entity.Parrot$Variant", "Parrot Variant",
|
||||
"View the different colors a parrot can be");
|
||||
}
|
||||
catch (ClassNotFoundException ex) {// Dont handle
|
||||
}
|
||||
new ParamInfo(MainHand.class, "Main Hand", "Set the main hand for an entity");
|
||||
new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color");
|
||||
new ParamInfo(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be");
|
||||
new ParamInfo(Particle.class, "Particle", "The different particles of Minecraft");
|
||||
|
||||
ArrayList<String> potionEnums = new ArrayList<>();
|
||||
|
||||
@ -229,9 +206,8 @@ public class ReflectionFlagWatchers {
|
||||
new ParamInfo(int[].class, "number,number,number..", "Numbers separated by an ,");
|
||||
|
||||
new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers separated by a ,");
|
||||
new ParamInfo(WrappedGameProfile.class, "GameProfile",
|
||||
"Get the gameprofile here https://sessionserver.mojang" +
|
||||
".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false");
|
||||
new ParamInfo(WrappedGameProfile.class, "GameProfile", "Get the gameprofile here https://sessionserver.mojang" +
|
||||
".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false");
|
||||
|
||||
Collections.sort(paramList, new Comparator<ParamInfo>() {
|
||||
@Override
|
||||
|
@ -5,11 +5,8 @@ import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
|
||||
import com.google.common.base.Optional;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
@ -17,6 +14,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ReflectionManager {
|
||||
@ -780,7 +778,7 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object convertInvalidItem(Object value) {
|
||||
public static Object convertInvalidMeta(Object value) {
|
||||
if (value instanceof Optional) {
|
||||
Optional opt = (Optional) value;
|
||||
|
||||
@ -810,7 +808,7 @@ public class ReflectionManager {
|
||||
val = getNmsItem((ItemStack) val);
|
||||
|
||||
if (val == null)
|
||||
return Optional.absent();
|
||||
return Optional.empty();
|
||||
else
|
||||
return Optional.of(val);
|
||||
}
|
||||
@ -844,32 +842,39 @@ public class ReflectionManager {
|
||||
}
|
||||
} else if (value instanceof ItemStack) {
|
||||
return getNmsItem((ItemStack) value);
|
||||
} else if (value instanceof Double)
|
||||
} else if (value instanceof Double) {
|
||||
return ((Double) value).floatValue();
|
||||
else if (value instanceof NbtCompound)
|
||||
} else if (value instanceof NbtWrapper) {
|
||||
return ((NbtWrapper) value).getHandle();
|
||||
} else if (value instanceof Particle) {
|
||||
return getParticleType((Particle) value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Object getParticleType(Particle particle) {
|
||||
try {
|
||||
return getCraftClass("CraftParticle").getMethod("toNMS", Particle.class).invoke(null, particle);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMinecraftVersion() {
|
||||
String version = Bukkit.getVersion();
|
||||
version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1);
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* This creates a DataWatcherItem usable with WrappedWatchableObject
|
||||
*
|
||||
* @param id
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private static Object createDataWatcherItem(int id, Object value) {
|
||||
public static WrappedDataWatcherObject createDataWatcherObject(int id, Object value) {
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
value = convertInvalidItem(value);
|
||||
value = convertInvalidMeta(value);
|
||||
|
||||
Serializer serializer;
|
||||
|
||||
@ -880,7 +885,8 @@ public class ReflectionManager {
|
||||
getNmsClass("IBlockData").isInstance(opt.get()) ? getNmsClass("IBlockData") : opt.get().getClass() :
|
||||
UUID.class), true);
|
||||
} else {
|
||||
serializer = Registry.get(value.getClass());
|
||||
serializer = Registry.get(getNmsClass("ParticleParam").isInstance(value) ? getNmsClass("ParticleParam") :
|
||||
value.getClass());
|
||||
}
|
||||
|
||||
if (serializer == null) {
|
||||
@ -894,12 +900,23 @@ public class ReflectionManager {
|
||||
"! Are you running " + "the latest " + "version of " + "ProtocolLib?");
|
||||
}
|
||||
|
||||
WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer);
|
||||
return new WrappedDataWatcherObject(id, serializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* This creates a DataWatcherItem usable with WrappedWatchableObject
|
||||
*
|
||||
* @param id
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static Object createDataWatcherItem(int id, Object value) {
|
||||
WrappedDataWatcherObject watcherObject = createDataWatcherObject(id, value);
|
||||
|
||||
Constructor construct = getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
|
||||
|
||||
try {
|
||||
return construct.newInstance(watcherObject.getHandle(), value);
|
||||
return construct.newInstance(watcherObject.getHandle(), convertInvalidMeta(value));
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
@ -908,6 +925,28 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getEntityType(Object nmsEntity) {
|
||||
try {
|
||||
Class classType = getNmsClass("EntityTypes");
|
||||
|
||||
for (Method m : getNmsClass("Entity").getMethods()) {
|
||||
if (m.getReturnType() != classType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object entityType = m.invoke(nmsEntity);
|
||||
Object registry = classType.getField("REGISTRY").get(null);
|
||||
|
||||
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static WrappedWatchableObject createWatchable(int index, Object obj) {
|
||||
Object watcherItem = createDataWatcherItem(index, obj);
|
||||
|
||||
@ -921,11 +960,41 @@ public class ReflectionManager {
|
||||
return id + (data << 12);
|
||||
}
|
||||
|
||||
public static ImmutablePair<Integer, Integer> getFromCombinedId(int combinedId) {
|
||||
int j = combinedId & 4095;
|
||||
int k = combinedId >> 12 & 15;
|
||||
public static int getCombinedIdByItemStack(ItemStack itemStack) {
|
||||
try {
|
||||
Object nmsItem = getNmsItem(itemStack);
|
||||
Object item = getNmsMethod("ItemStack", "getItem").invoke(nmsItem);
|
||||
Class blockClass = getNmsClass("Block");
|
||||
|
||||
return new ImmutablePair<>(j, k);
|
||||
Object nmsBlock = getNmsMethod(blockClass, "asBlock", getNmsClass("Item")).invoke(null, item);
|
||||
|
||||
return (int) getNmsMethod(blockClass, "getBlockData").invoke(nmsBlock);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static ItemStack getItemStackByCombinedId(int id) {
|
||||
try {
|
||||
Method idMethod = getNmsMethod("Block", "getByCombinedId", int.class);
|
||||
Object iBlockData = idMethod.invoke(null, id);
|
||||
Class iBlockClass = getNmsClass("IBlockData");
|
||||
|
||||
Method getBlock = getNmsMethod(iBlockClass, "getBlock");
|
||||
Object block = getBlock.invoke(iBlockData);
|
||||
|
||||
Method getItem = getNmsMethod("Block", "t", iBlockClass);
|
||||
|
||||
return getBukkitItem(getItem.invoke(block, iBlockData));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getWorldServer(World w) {
|
||||
|
@ -1,22 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 8/06/2017.
|
||||
*/
|
||||
public class BackwardMethods {
|
||||
|
||||
public boolean isOrderedIndexes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void doReplaceSounds() {
|
||||
}
|
||||
|
||||
public void replace(String old, String newString) {
|
||||
DisguiseSound.replace(old, newString);
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_10;
|
||||
import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_11;
|
||||
import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_9;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 8/06/2017.
|
||||
*/
|
||||
public class BackwardsSupport {
|
||||
public static BackwardMethods getMethods() {
|
||||
try {
|
||||
String version = ReflectionManager.getMinecraftVersion();
|
||||
|
||||
Class<? extends BackwardMethods> methods = BackwardMethods.class;
|
||||
|
||||
if (version.equals("1.9") || version.equals("1.9.1") || version.equals("1.9.2") || version
|
||||
.equals("1.9.3") || version.equals("1.9.4")) {
|
||||
methods = Version_1_9.class;
|
||||
} else if (version.equals("1.10") || version.equals("1.10.1") || version.equals("1.10.2")) {
|
||||
methods = Version_1_10.class;
|
||||
} else if (version.equals("1.11") || version.equals("1.11.1") || version.equals("1.11.2")) {
|
||||
methods = Version_1_11.class;
|
||||
}
|
||||
|
||||
if (methods != BackwardMethods.class) {
|
||||
if (!LibsPremium.isPremium()) {
|
||||
System.out.println("[LibsDisguises] You must purchase the plugin to use backwards compatibility!");
|
||||
methods = BackwardMethods.class;
|
||||
} else {
|
||||
System.out.println("[LibsDisguises] Enabled backwards support for " + version);
|
||||
}
|
||||
}
|
||||
|
||||
return setupMetadata(methods);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void getIndexes(Class backwardsClass, BackwardMethods backwards,
|
||||
HashMap<String, MetaIndex> newIndexes) throws IllegalAccessException {
|
||||
for (Field field : backwardsClass.getDeclaredFields()) {
|
||||
if (field.getType() != MetaIndex.class)
|
||||
continue;
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
if (newIndexes.containsKey(field.getName()))
|
||||
continue;
|
||||
|
||||
if (MetaIndex.setMetaIndex(field.getName(), (MetaIndex) field.get(backwards))) {
|
||||
newIndexes.put(field.getName(), MetaIndex.ENTITY_META);
|
||||
continue;
|
||||
}
|
||||
|
||||
newIndexes.put(field.getName(), (MetaIndex) field.get(backwards));
|
||||
}
|
||||
|
||||
backwardsClass = backwardsClass.getSuperclass();
|
||||
|
||||
if (backwardsClass.getSimpleName().contains("Version_"))
|
||||
getIndexes(backwardsClass, backwards, newIndexes);
|
||||
}
|
||||
|
||||
private static BackwardMethods setupMetadata(Class<? extends BackwardMethods> backwardsClass) {
|
||||
try {
|
||||
BackwardMethods backwards = backwardsClass.newInstance();
|
||||
|
||||
HashMap<String, MetaIndex> newIndexes = new HashMap<>();
|
||||
|
||||
getIndexes(backwardsClass, backwards, newIndexes);
|
||||
|
||||
MetaIndex.setValues();
|
||||
|
||||
HashSet<MetaIndex> indexes = new HashSet<>(newIndexes.values());
|
||||
indexes.remove(MetaIndex.ENTITY_META); // We do the hashmap stuff to prevent multiple versions
|
||||
// registering the same meta index
|
||||
|
||||
MetaIndex.addMetaIndexes(indexes.toArray(new MetaIndex[0]));
|
||||
|
||||
if (backwards.isOrderedIndexes()) {
|
||||
MetaIndex.eliminateBlankIndexes();
|
||||
MetaIndex.orderMetaIndexes();
|
||||
}
|
||||
|
||||
backwards.doReplaceSounds();
|
||||
|
||||
return backwards;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards.metadata;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 9/06/2017.
|
||||
* <p>
|
||||
* Supports 1.10.0 1.10.1 and 1.10.2
|
||||
*/
|
||||
public class Version_1_10 extends Version_1_11 {
|
||||
private MetaIndex ILLAGER_META;
|
||||
private MetaIndex ILLAGER_SPELL_TICKS;
|
||||
private MetaIndex<Integer> HORSE_VARIANT = new MetaIndex<>(HorseWatcher.class, 1, 0);
|
||||
private MetaIndex<Byte> SHULKER_COLOR;
|
||||
private MetaIndex<Optional<ItemStack>> DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0,
|
||||
Optional.of(new ItemStack(Material.STONE)));
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards.metadata;
|
||||
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.utilities.backwards.BackwardMethods;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 8/06/2017.
|
||||
* Supports 1.11.0 1.11.1 and 1.11.2
|
||||
*/
|
||||
public class Version_1_11 extends BackwardMethods {
|
||||
private MetaIndex ILLAGER_META;
|
||||
private MetaIndex PARROT_VARIANT;
|
||||
private MetaIndex PLAYER_LEFT_SHOULDER_ENTITY;
|
||||
private MetaIndex PLAYER_RIGHT_SHOULDER_ENTITY;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards.metadata;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 24/06/2017.
|
||||
*/
|
||||
public class Version_1_7 {
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards.metadata;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 24/06/2017.
|
||||
*/
|
||||
public class Version_1_8 {
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package me.libraryaddict.disguise.utilities.backwards.metadata;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 24/06/2017.
|
||||
* <p>
|
||||
* Intended for 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4
|
||||
*/
|
||||
public class Version_1_9 extends Version_1_10 {
|
||||
}
|
@ -1,19 +1,10 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
@ -22,6 +13,10 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PacketListenerClientInteract extends PacketAdapter {
|
||||
public PacketListenerClientInteract(LibsDisguises plugin) {
|
||||
@ -43,19 +38,20 @@ public class PacketListenerClientInteract extends PacketAdapter {
|
||||
|
||||
Entity entity = entityModifer.read(0);
|
||||
|
||||
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow || entity == observer) {
|
||||
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow ||
|
||||
entity == observer) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(),
|
||||
observer.getInventory().getItemInOffHand()}) {
|
||||
if (item == null || item.getType() != Material.INK_SACK)
|
||||
if (item == null || item.getType() != Material.INK_SAC)
|
||||
continue;
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
|
||||
if (disguise == null || (disguise.getType() != DisguiseType.SHEEP && disguise
|
||||
.getType() != DisguiseType.WOLF))
|
||||
if (disguise == null ||
|
||||
(disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF))
|
||||
continue;
|
||||
|
||||
AnimalColor color = AnimalColor.getColor(item.getDurability());
|
||||
|
@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -153,14 +154,14 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
} else {
|
||||
if (sound.equals("step.grass")) {
|
||||
try {
|
||||
int typeId = observer.getWorld().getBlockTypeIdAt((int) Math.floor(soundCords[0] / 8D),
|
||||
Block block = observer.getWorld().getBlockAt((int) Math.floor(soundCords[0] / 8D),
|
||||
(int) Math.floor(soundCords[1] / 8D), (int) Math.floor(soundCords[2] / 8D));
|
||||
|
||||
Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "getId", int.class)
|
||||
.invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId);
|
||||
|
||||
if (block != null) {
|
||||
Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
|
||||
Object nmsBlock = ReflectionManager.getCraftMethod("block.CraftBlock", "getNMSBlock")
|
||||
.invoke(block);
|
||||
|
||||
Object step = ReflectionManager.getNmsMethod("Block", "getStepSound").invoke(nmsBlock);
|
||||
|
||||
mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step));
|
||||
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
|
||||
|
@ -1,10 +0,0 @@
|
||||
package org.bukkit.inventory;
|
||||
|
||||
public enum EquipmentSlot {
|
||||
HAND,
|
||||
OFF_HAND,
|
||||
FEET,
|
||||
LEGS,
|
||||
CHEST,
|
||||
HEAD
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package org.bukkit.inventory;
|
||||
|
||||
public enum MainHand {
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
Loading…
Reference in New Issue
Block a user