Add backwards support for 1.11.2, bugfixes, update to 1.12

This commit is contained in:
libraryaddict 2017-06-09 03:06:58 +12:00
parent 90de701eb5
commit 5ffa792e77
22 changed files with 558 additions and 410 deletions

View File

@ -19,6 +19,7 @@ UpdateGameProfiles: true
# Entities - Are entities disguises saved (This is everything that's not a player) # Entities - Are entities disguises saved (This is everything that's not a player)
# If you are using the dev builds, place your premium version of Lib's Disguises.jar inside the LibsDisguises folder # If you are using the dev builds, place your premium version of Lib's Disguises.jar inside the LibsDisguises folder
# This will enable premium only features for the dev builds. # This will enable premium only features for the dev builds.
# The saved disguises are saved in a json file format inside the plugin folder, there will be no other formats
SaveDisguises: SaveDisguises:
Players: false Players: false
Entities: false Entities: false

View File

@ -43,12 +43,12 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.11-R0.1-SNAPSHOT</version> <version>1.12-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.11-R0.1-SNAPSHOT</version> <version>1.12-R0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -41,18 +42,6 @@ import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
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;
import me.libraryaddict.disguise.utilities.DisguiseValues; import me.libraryaddict.disguise.utilities.DisguiseValues;
@ -77,15 +66,6 @@ public class LibsDisguises extends JavaPlugin {
return; return;
} }
try {
ReflectionManager.getNmsClass("EntityEvoker").getName();
}
catch (Exception ex) {
System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated server!");
System.err.println("[LibsDisguises] This plugin does not offer backwards support!");
return;
}
instance = this; instance = this;
saveDefaultConfig(); saveDefaultConfig();
@ -131,6 +111,7 @@ public class LibsDisguises extends JavaPlugin {
metrics.start(); metrics.start();
} }
catch (IOException e) { catch (IOException e) {
// Don't print error
} }
} }
@ -166,10 +147,11 @@ public class LibsDisguises extends JavaPlugin {
private void registerValues() { private void registerValues() {
for (DisguiseType disguiseType : DisguiseType.values()) { for (DisguiseType disguiseType : DisguiseType.values()) {
if (disguiseType.getEntityType() == null) { if (disguiseType.getEntityType() == null) {
System.out.println("EntityType for " + disguiseType.name() + " not found");
continue; continue;
} }
Class watcherClass = null; Class watcherClass;
try { try {
switch (disguiseType) { switch (disguiseType) {
@ -206,6 +188,10 @@ public class LibsDisguises extends JavaPlugin {
case STRAY: case STRAY:
watcherClass = SkeletonWatcher.class; watcherClass = SkeletonWatcher.class;
break; break;
case ILLUSIONER:
case EVOKER:
watcherClass = IllagerWizardWatcher.class;
break;
default: default:
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable( watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(
disguiseType.name()) + "Watcher"); disguiseType.name()) + "Watcher");
@ -289,6 +275,10 @@ public class LibsDisguises extends JavaPlugin {
case ARROW: case ARROW:
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
nmsEntityName = "TippedArrow"; nmsEntityName = "TippedArrow";
break;
case ILLUSIONER:
nmsEntityName = "IllagerIllusioner";
break;
default: default:
break; break;
} }
@ -354,7 +344,6 @@ public class LibsDisguises extends JavaPlugin {
System.err.println( System.err.println(
"Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName() + " which doesn't match up with " + flagType.getDefault().getClass()); "Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName() + " which doesn't match up with " + flagType.getDefault().getClass());
System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); System.err.println("Lib's Disguises will continue to load, but this will not work properly!");
continue;
} }
} }

View File

@ -1,24 +1,5 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.craftbukkit.v1_11_R1.command.CraftBlockCommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -28,6 +9,20 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.*;
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30; private int maxRadius = 30;
@ -49,7 +44,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
center = ((Player) sender).getLocation(); center = ((Player) sender).getLocation();
} }
else { else {
center = ((CraftBlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
} }
return center.getWorld().getNearbyEntities(center, radius, radius, radius); return center.getWorld().getNearbyEntities(center, radius, radius, radius);

View File

@ -1,24 +1,5 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.craftbukkit.v1_11_R1.command.CraftBlockCommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -30,6 +11,24 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30; private int maxRadius = 30;
@ -72,8 +71,9 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
Collections.sort(classes); Collections.sort(classes);
sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN sender.sendMessage(
+ StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."); ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN + StringUtils.join(classes,
ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + ".");
return true; return true;
} }
@ -105,11 +105,10 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
if (args.length == starting + 1) { if (args.length == starting + 1) {
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius" sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ?
+ (starting != 0 ? " and EntityType" : "")); " and EntityType" : ""));
return true; return true;
} } else if (args.length < 2) {
else if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise"); sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise");
return true; return true;
} }
@ -122,7 +121,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
int radius = Integer.parseInt(args[starting]); int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) { if (radius > maxRadius) {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); sender.sendMessage(
ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
radius = maxRadius; radius = maxRadius;
} }
@ -158,9 +158,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
if (sender instanceof Player) { if (sender instanceof Player) {
center = ((Player) sender).getLocation(); center = ((Player) sender).getLocation();
} } else {
else { center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
center = ((CraftBlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
} }
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) { for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
@ -169,8 +168,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) { if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
&& entity instanceof LivingEntity) {
miscDisguises++; miscDisguises++;
continue; continue;
} }
@ -196,14 +194,13 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
if (disguisedEntitys > 0) { if (disguisedEntitys > 0) {
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
} } else {
else {
sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!"); sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!");
} }
if (miscDisguises > 0) { if (miscDisguises > 0) {
sender.sendMessage(ChatColor.RED + "Failed to disguise " + miscDisguises sender.sendMessage(
+ " entities because the option to disguise a living entity as a non-living has been disabled in the config"); ChatColor.RED + "Failed to disguise " + miscDisguises + " entities because the option to disguise a living entity as a non-living has been disabled in the config");
} }
return true; return true;
@ -244,8 +241,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
for (String type : getAllowedDisguises(perms)) { for (String type : getAllowedDisguises(perms)) {
tabs.add(type); tabs.add(type);
} }
} } else {
else {
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[starting]); DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[starting]);
@ -256,13 +252,12 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
} }
} } else {
else {
ArrayList<String> usedOptions = new ArrayList<String>(); ArrayList<String> usedOptions = new ArrayList<String>();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 :
: starting + 1; i < args.length; i++) { starting + 1; i < args.length; i++) {
String arg = args[i]; String arg = args[i];
if (!method.getName().equalsIgnoreCase(arg)) if (!method.getName().equalsIgnoreCase(arg))
@ -288,8 +283,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
tabs.add(e); tabs.add(e);
} }
} } else {
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
@ -301,7 +295,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
if (addMethods) { if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add. // If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
disguiseType.getWatcherClass())) {
tabs.add(method.getName()); tabs.add(method.getName());
} }
} }
@ -316,31 +311,34 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at " + maxRadius + " blocks!"); sender.sendMessage(
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at " + maxRadius + " blocks!");
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join(
allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
if (allowedDisguises.contains("player")) { if (allowedDisguises.contains("player")) {
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>") sender.sendMessage(
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
} }
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" sender.sendMessage(
+ optional + ">").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" + optional + ">").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional sender.sendMessage(
+ "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">") (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">").replace(
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
} }
sender.sendMessage( sender.sendMessage(
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"); ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes");
} }
} }

View File

@ -4,8 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsVersion;
import me.libraryaddict.disguise.utilities.LibVersion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -59,7 +58,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
+ "/libsdisguises reload" + ChatColor.DARK_GREEN + "/libsdisguises reload" + ChatColor.DARK_GREEN
+ " to reload the config. All disguises will be blown by doing this."); + " to reload the config. All disguises will be blown by doing this.");
if (LibVersion.isPremium()) { if (LibsVersion.isPremium()) {
sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!");
} }
} }

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.omg.CORBA.UNKNOWN;
public enum DisguiseType { public enum DisguiseType {
AREA_EFFECT_CLOUD(3, 0), AREA_EFFECT_CLOUD(3, 0),
@ -71,6 +72,8 @@ public enum DisguiseType {
HUSK, HUSK,
ILLUSIONER,
IRON_GOLEM, IRON_GOLEM,
ITEM_FRAME(71), ITEM_FRAME(71),
@ -105,6 +108,8 @@ public enum DisguiseType {
PAINTING, PAINTING,
PARROT,
PIG, PIG,
PIG_ZOMBIE, PIG_ZOMBIE,
@ -212,7 +217,6 @@ public enum DisguiseType {
DisguiseType disguiseType = getType(entity.getType()); DisguiseType disguiseType = getType(entity.getType());
return disguiseType; return disguiseType;
} }
public static DisguiseType getType(EntityType entityType) { public static DisguiseType getType(EntityType entityType) {
@ -235,16 +239,16 @@ public enum DisguiseType {
int value = ints[i]; int value = ints[i];
switch (i) { switch (i) {
case 0: case 0:
objectId = value; objectId = value;
break; break;
case 1: case 1:
defaultData = value; defaultData = value;
break; break;
default: default:
break; break;
} }
} }
} }

View File

@ -5,8 +5,6 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
@ -19,7 +17,6 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
@ -224,6 +221,9 @@ public class FlagWatcher {
} }
protected <Y> Y getData(MetaIndex<Y> flagType) { protected <Y> Y getData(MetaIndex<Y> flagType) {
if (flagType == null)
return null;
if (entityValues.containsKey(flagType.getIndex())) { if (entityValues.containsKey(flagType.getIndex())) {
return (Y) entityValues.get(flagType.getIndex()); return (Y) entityValues.get(flagType.getIndex());
} }
@ -244,6 +244,9 @@ public class FlagWatcher {
} }
protected boolean hasValue(MetaIndex no) { protected boolean hasValue(MetaIndex no) {
if (no == null)
return false;
return entityValues.containsKey(no.getIndex()); return entityValues.containsKey(no.getIndex());
} }
@ -316,6 +319,9 @@ public class FlagWatcher {
List<WrappedWatchableObject> list = new ArrayList<>(); List<WrappedWatchableObject> list = new ArrayList<>();
for (MetaIndex data : dataValues) { for (MetaIndex data : dataValues) {
if (data == null)
continue;
if (!entityValues.containsKey(data.getIndex()) || entityValues.get(data.getIndex()) == null) { if (!entityValues.containsKey(data.getIndex()) || entityValues.get(data.getIndex()) == null) {
continue; continue;
} }
@ -370,6 +376,9 @@ public class FlagWatcher {
} }
protected void setBackupValue(MetaIndex no, Object value) { protected void setBackupValue(MetaIndex no, Object value) {
if (no == null)
return;
backupEntityValues.put(no.getIndex(), value); backupEntityValues.put(no.getIndex(), value);
} }
@ -518,6 +527,9 @@ public class FlagWatcher {
} }
protected <Y> void setData(MetaIndex<Y> id, Y value) { protected <Y> void setData(MetaIndex<Y> id, Y value) {
if (id == null)
return;
if (value == null && id.getDefault() instanceof ItemStack) if (value == null && id.getDefault() instanceof ItemStack)
throw new IllegalArgumentException("Cannot use null ItemStacks"); throw new IllegalArgumentException("Cannot use null ItemStacks");

View File

@ -4,6 +4,8 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.Vector3F; import com.comphenix.protocol.wrappers.Vector3F;
import com.comphenix.protocol.wrappers.WrappedBlockData; import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.disguisetypes.watchers.*;
import org.bukkit.Color; import org.bukkit.Color;
@ -104,7 +106,9 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> ENTITY_SILENT = new MetaIndex<>(FlagWatcher.class, 4, false); public static MetaIndex<Boolean> ENTITY_SILENT = new MetaIndex<>(FlagWatcher.class, 4, false);
public static MetaIndex<Byte> EVOKER_SPELL_TICKS = new MetaIndex<>(EvokerWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> ILLAGER_SPELL_TICKS = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0);
public static MetaIndex<Byte> ILLAGER_META = new MetaIndex<>(IllagerWatcher.class, 0, (byte) 0);
public static MetaIndex<BlockPosition> FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0, public static MetaIndex<BlockPosition> FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0,
BlockPosition.ORIGIN); BlockPosition.ORIGIN);
@ -173,6 +177,8 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0); public static MetaIndex<Integer> OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0);
public static MetaIndex<Integer> PARROT_VARIANT = new MetaIndex<>(ParrotWatcher.class, 0, 0);
public static MetaIndex<Boolean> PIG_SADDLED = new MetaIndex<>(PigWatcher.class, 0, false); 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_UNKNOWN = new MetaIndex<>(PigWatcher.class, 1, 0);
@ -185,6 +191,12 @@ public class MetaIndex<Y> {
public static MetaIndex<Byte> PLAYER_SKIN = new MetaIndex<>(PlayerWatcher.class, 2, (byte) 127); 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<NbtCompound> PLAYER_RIGHT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 5,
NbtFactory.ofCompound("None"));
public static MetaIndex<Boolean> POLAR_BEAR_STANDING = new MetaIndex<>(PolarBearWatcher.class, 0, false); public static MetaIndex<Boolean> POLAR_BEAR_STANDING = new MetaIndex<>(PolarBearWatcher.class, 0, false);
public static MetaIndex<Integer> RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0); public static MetaIndex<Integer> RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0);
@ -261,13 +273,55 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> ZOMBIE_VILLAGER_SHAKING = new MetaIndex<>(ZombieVillagerWatcher.class, 0, false); public static MetaIndex<Boolean> ZOMBIE_VILLAGER_SHAKING = new MetaIndex<>(ZombieVillagerWatcher.class, 0, false);
static { static {
setValues();
}
public static void fillInBlankIndexes() {
ArrayList<Entry<Class, ArrayList<MetaIndex>>> list = new ArrayList<>();
for (MetaIndex index : values()) {
Entry<Class, ArrayList<MetaIndex>> entry = null;
for (Entry e : list) {
if (e.getKey() != index.getFlagWatcher())
continue;
entry = e;
break;
}
if (entry == null) {
entry = new AbstractMap.SimpleEntry(index.getFlagWatcher(), new ArrayList<MetaIndex>());
list.add(entry);
}
entry.getValue().add(index);
}
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();
}
});
for (MetaIndex ind : entry.getValue()) {
ind._index = entry.getValue().indexOf(ind);
}
}
}
public static void orderMetaIndexes() {
for (MetaIndex flagType : values()) { for (MetaIndex flagType : values()) {
if (flagType.getFlagWatcher() == FlagWatcher.class) if (flagType.getFlagWatcher() == FlagWatcher.class)
continue; continue;
flagType._index += getNoIndexes(flagType.getFlagWatcher().getSuperclass()); flagType._index += getNoIndexes(flagType.getFlagWatcher().getSuperclass());
} }
}
public static void validateMetadata() {
// Simple verification for the dev that he's setting up the FlagType's properly. // Simple verification for the dev that he's setting up the FlagType's properly.
// All flag types should be from 0 to <Max Number> with no empty numbers. // All flag types should be from 0 to <Max Number> with no empty numbers.
// All flag types should never occur twice. // All flag types should never occur twice.
@ -384,6 +438,44 @@ public class MetaIndex<Y> {
return _values; return _values;
} }
public static void setValues() {
try {
_values = new MetaIndex[0];
for (Field field : MetaIndex.class.getFields()) {
if (field.getType() != MetaIndex.class)
continue;
MetaIndex index = (MetaIndex) field.get(null);
if (index == null)
continue;
_values = Arrays.copyOf(_values, _values.length + 1);
_values[_values.length - 1] = index;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void setMetaIndex(String name, MetaIndex metaIndex) {
try {
Field field = MetaIndex.class.getField(name);
MetaIndex index = (MetaIndex) field.get(null);
field.set(null, metaIndex);
}
catch (NoSuchFieldException ex) {
System.out.println("The field '" + name + "' doesn't exist in MetaIndex!");
Thread.dumpStack();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private Y _defaultValue; private Y _defaultValue;
private int _index; private int _index;
private Class<? extends FlagWatcher> _watcher; private Class<? extends FlagWatcher> _watcher;
@ -392,9 +484,6 @@ public class MetaIndex<Y> {
_index = index; _index = index;
_watcher = watcher; _watcher = watcher;
_defaultValue = defaultValue; _defaultValue = defaultValue;
_values = Arrays.copyOf(_values, _values.length + 1);
_values[_values.length - 1] = this;
} }
public Y getDefault() { public Y getDefault() {

View File

@ -0,0 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
/**
* Created by libraryaddict on 9/06/2017.
*/
public class IllagerWatcher extends InsentientWatcher {
public IllagerWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -3,18 +3,18 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class EvokerWatcher extends InsentientWatcher { public class IllagerWizardWatcher extends IllagerWatcher {
public EvokerWatcher(Disguise disguise) { public IllagerWizardWatcher(Disguise disguise) {
super(disguise); super(disguise);
} }
public void setSpellTicks(int spellTicks) { public void setSpellTicks(int spellTicks) {
setData(MetaIndex.EVOKER_SPELL_TICKS, (byte) spellTicks); setData(MetaIndex.ILLAGER_SPELL_TICKS, (byte) spellTicks);
sendData(MetaIndex.EVOKER_SPELL_TICKS); sendData(MetaIndex.ILLAGER_SPELL_TICKS);
} }
public int getSpellTicks() { public int getSpellTicks() {
return getData(MetaIndex.EVOKER_SPELL_TICKS); return getData(MetaIndex.ILLAGER_SPELL_TICKS);
} }
} }

View File

@ -0,0 +1,23 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.entity.Parrot;
/**
* Created by libraryaddict on 9/06/2017.
*/
public class ParrotWatcher extends TameableWatcher {
public ParrotWatcher(Disguise disguise) {
super(disguise);
}
public Parrot.Variant getVariant() {
return Parrot.Variant.values()[getData(MetaIndex.PARROT_VARIANT)];
}
public void setVariant(Parrot.Variant variant) {
setData(MetaIndex.PARROT_VARIANT, variant.ordinal());
sendData(MetaIndex.PARROT_VARIANT);
}
}

View File

@ -10,11 +10,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Ageable; import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Monster;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@ -23,7 +19,6 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -444,7 +439,7 @@ public class DisguiseParser {
} }
} }
private static boolean isNumeric(String string) { private static boolean isInteger(String string) {
try { try {
Integer.parseInt(string); Integer.parseInt(string);
return true; return true;
@ -463,7 +458,6 @@ public class DisguiseParser {
* @param args * @param args
* @param permissionMap * @param permissionMap
* @return * @return
* @throws DisguiseBaseCommand.DisguiseParseException
* @throws java.lang.IllegalAccessException * @throws java.lang.IllegalAccessException
* @throws java.lang.reflect.InvocationTargetException * @throws java.lang.reflect.InvocationTargetException
*/ */
@ -576,13 +570,13 @@ public class DisguiseParser {
// If the first arg is a number // If the first arg is a number
if (args[1].contains(":")) { if (args[1].contains(":")) {
String[] split = args[1].split(":"); String[] split = args[1].split(":");
if (isNumeric(split[1])) { if (isInteger(split[1])) {
secondArg = split[1]; secondArg = split[1];
} }
args[1] = split[0]; args[1] = split[0];
} }
if (isNumeric(args[1])) { if (isInteger(args[1])) {
miscId = Integer.parseInt(args[1]); miscId = Integer.parseInt(args[1]);
} else { } else {
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK || disguisePerm.getType() == DisguiseType.DROPPED_ITEM) { if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK || disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
@ -614,7 +608,7 @@ public class DisguiseParser {
} }
toSkip++; toSkip++;
// If they also defined a data value // If they also defined a data value
if (args.length > 2 && secondArg == null && isNumeric(args[2])) { if (args.length > 2 && secondArg == null && isInteger(args[2])) {
secondArg = args[2]; secondArg = args[2];
toSkip++; toSkip++;
} }
@ -706,7 +700,7 @@ public class DisguiseParser {
if (valueString != null) { if (valueString != null) {
if (int.class == param) { if (int.class == param) {
// Parse to integer // Parse to integer
if (isNumeric(valueString)) { if (isInteger(valueString)) {
value = Integer.parseInt(valueString); value = Integer.parseInt(valueString);
} else { } else {
throw parseToException("number", valueString, methodName); throw parseToException("number", valueString, methodName);
@ -806,7 +800,8 @@ public class DisguiseParser {
// Parse to potion effect // Parse to potion effect
try { try {
PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase()); PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
if (potionType == null && isNumeric(valueString)) {
if (potionType == null && isInteger(valueString)) {
potionType = PotionEffectType.getById(Integer.parseInt(valueString)); potionType = PotionEffectType.getById(Integer.parseInt(valueString));
} }
@ -878,6 +873,8 @@ public class DisguiseParser {
catch (Exception ex) { catch (Exception ex) {
throw parseToException("three numbers Number,Number,Number", valueString, methodName); throw parseToException("three numbers Number,Number,Number", valueString, methodName);
} }
} else if (param.getName().equals("org.bukkit.entity.Parrot$Variant")) {
value = callValueOf(param, valueString, methodName, "a parrot color");
} }
} }
@ -949,7 +946,7 @@ public class DisguiseParser {
int itemId = -1; int itemId = -1;
if (isNumeric(split[0])) { if (isInteger(split[0])) {
itemId = Integer.parseInt(split[0]); itemId = Integer.parseInt(split[0]);
} else { } else {
try { try {
@ -963,7 +960,7 @@ public class DisguiseParser {
short itemDura = 0; short itemDura = 0;
if (split.length > 1) { if (split.length > 1) {
if (isNumeric(split[1])) { if (isInteger(split[1])) {
itemDura = Short.parseShort(split[1]); itemDura = Short.parseShort(split[1]);
} else { } else {
throw parseToException("item ID:Durability combo", string, "%s"); throw parseToException("item ID:Durability combo", string, "%s");

View File

@ -69,6 +69,10 @@ public enum DisguiseSound {
Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
Sound.ENTITY_HORSE_ANGRY), Sound.ENTITY_HORSE_ANGRY),
ILLUSIONER("entity.illusion_illager.hurt", null, "entity.illusion_illager.death", "entity.illusion_illager.ambient",
"entity.illusion_illager.cast_spell", "entity.illusion_illager" + ".prepare_blindness",
"entity.illusion_illager.prepare_mirror", "entity.illusion_illager.mirror_move"),
IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH, IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH,
Sound.ENTITY_IRONGOLEM_ATTACK), Sound.ENTITY_IRONGOLEM_ATTACK),
@ -84,13 +88,28 @@ public enum DisguiseSound {
OCELOT(Sound.ENTITY_CAT_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CAT_HURT, Sound.ENTITY_CAT_AMBIENT, OCELOT(Sound.ENTITY_CAT_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CAT_HURT, Sound.ENTITY_CAT_AMBIENT,
Sound.ENTITY_CAT_PURR, Sound.ENTITY_CAT_PURREOW), Sound.ENTITY_CAT_PURR, Sound.ENTITY_CAT_PURREOW),
PARROT("entity.parrot.hurt", "entity.parrot.step", "entity.parrot.death", "entity.parrot.ambient",
"entity.parrot.eat", "entity.parrot.fly", "entity.parrot.imitate.blaze", "entity.parrot.imitate.creeper",
"entity.parrot.imitate.elder_guardian", "entity.parrot.imitate.enderdragon",
"entity.parrot.imitate.enderman", "entity.parrot.imitate.endermite",
"entity.parrot.imitate.evocation_illager", "entity.parrot.imitate.ghast", "entity.parrot.imitate.husk",
"entity.parrot.imitate.illusion_illager", "entity.parrot.imitate.magmacube",
"entity.parrot.imitate.polar_bear", "entity.parrot.imitate.shulker", "entity.parrot.imitate.silverfish",
"entity.parrot.imitate.skeleton", "entity.parrot.imitate.slime", "entity.parrot.imitate.spider",
"entity.parrot.imitate.stray", "entity.parrot.imitate.vex", "entity.parrot.imitate.vindication_illager",
"entity.parrot.imitate.witch", "entity.parrot.imitate.wither", "entity.parrot.imitate.wither_skeleton",
"entity.parrot.imitate.wolf", "entity.parrot.imitate.zombie", "entity.parrot.imitate.zombie_pigman",
"entity.parrot.imitate.zombie_villager"),
PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_AMBIENT), PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_AMBIENT),
PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIG_HURT, null, Sound.ENTITY_ZOMBIE_PIG_DEATH, Sound.ENTITY_ZOMBIE_PIG_AMBIENT, PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIG_HURT, null, Sound.ENTITY_ZOMBIE_PIG_DEATH, Sound.ENTITY_ZOMBIE_PIG_AMBIENT,
Sound.ENTITY_ZOMBIE_PIG_ANGRY), Sound.ENTITY_ZOMBIE_PIG_ANGRY),
PLAYER(Sound.ENTITY_PLAYER_HURT, PLAYER(Sound.ENTITY_PLAYER_HURT,
new Sound[]{Sound.BLOCK_STONE_STEP, Sound.BLOCK_GRASS_STEP, Sound.BLOCK_ANVIL_STEP, Sound.BLOCK_CLOTH_STEP, Sound.BLOCK_GLASS_STEP, Sound.BLOCK_GRAVEL_STEP, Sound.BLOCK_LADDER_STEP, Sound.BLOCK_METAL_STEP, Sound.BLOCK_SAND_STEP, Sound.BLOCK_SLIME_STEP, Sound.BLOCK_SNOW_STEP, Sound.BLOCK_WOOD_STEP}, new Sound[]{Sound.BLOCK_STONE_STEP, Sound.BLOCK_GRASS_STEP, Sound.BLOCK_ANVIL_STEP, Sound.BLOCK_CLOTH_STEP,
Sound.BLOCK_GLASS_STEP, Sound.BLOCK_GRAVEL_STEP, Sound.BLOCK_LADDER_STEP, Sound.BLOCK_METAL_STEP,
Sound.BLOCK_SAND_STEP, Sound.BLOCK_SLIME_STEP, Sound.BLOCK_SNOW_STEP, Sound.BLOCK_WOOD_STEP},
Sound.ENTITY_PLAYER_DEATH, null), Sound.ENTITY_PLAYER_DEATH, null),
RABBIT(Sound.ENTITY_RABBIT_HURT, Sound.ENTITY_RABBIT_JUMP, Sound.ENTITY_RABBIT_DEATH, Sound.ENTITY_RABBIT_AMBIENT), RABBIT(Sound.ENTITY_RABBIT_HURT, Sound.ENTITY_RABBIT_JUMP, Sound.ENTITY_RABBIT_DEATH, Sound.ENTITY_RABBIT_AMBIENT),

View File

@ -12,7 +12,6 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.PropertyMap; import com.mojang.authlib.properties.PropertyMap;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
@ -24,6 +23,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; 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 me.libraryaddict.disguise.utilities.json.*;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -46,8 +47,6 @@ import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -74,6 +73,7 @@ public class DisguiseUtilities {
private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File( private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File(
"plugins/LibsDisguises/SavedDisguises"); "plugins/LibsDisguises/SavedDisguises");
private static Gson gson; private static Gson gson;
private static BackwardMethods methods;
public static void saveDisguises() { public static void saveDisguises() {
Iterator<HashSet<TargetedDisguise>> itel = disguisesInUse.values().iterator(); Iterator<HashSet<TargetedDisguise>> itel = disguisesInUse.values().iterator();
@ -132,7 +132,7 @@ public class DisguiseUtilities {
} }
public static void saveDisguises(UUID owningEntity, Disguise[] disguise) { public static void saveDisguises(UUID owningEntity, Disguise[] disguise) {
if (!LibVersion.isPremium()) if (!LibsVersion.isPremium())
return; return;
try { try {
@ -171,7 +171,7 @@ public class DisguiseUtilities {
} }
public static Disguise[] getSavedDisguises(UUID entityUUID, boolean remove) { public static Disguise[] getSavedDisguises(UUID entityUUID, boolean remove) {
if (!isSavedDisguise(entityUUID) || !LibVersion.isPremium()) if (!isSavedDisguise(entityUUID) || !LibsVersion.isPremium())
return new Disguise[0]; return new Disguise[0];
File disguiseFile = new File(savedDisguises, entityUUID.toString()); File disguiseFile = new File(savedDisguises, entityUUID.toString());
@ -773,6 +773,7 @@ public class DisguiseUtilities {
public static void init(LibsDisguises disguises) { public static void init(LibsDisguises disguises) {
libsDisguises = disguises; libsDisguises = disguises;
methods = BackwardsSupport.getMethods();
GsonBuilder gsonBuilder = new GsonBuilder(); GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex()); gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex());
@ -848,7 +849,7 @@ public class DisguiseUtilities {
savedDisguiseList.add(UUID.fromString(key)); savedDisguiseList.add(UUID.fromString(key));
} }
LibVersion.check(libsDisguises); LibsVersion.check(libsDisguises);
} }
public static boolean isDisguiseInUse(Disguise disguise) { public static boolean isDisguiseInUse(Disguise disguise) {

View File

@ -10,7 +10,7 @@ import java.net.URLClassLoader;
/** /**
* Created by libraryaddict on 2/06/2017. * Created by libraryaddict on 2/06/2017.
*/ */
public class LibVersion { public class LibsVersion {
/** /**
* If you're seriously going to modify this to get the premium stuff for free, can you at least not * If you're seriously going to modify this to get the premium stuff for free, can you at least not
* distribute it? You didn't pay for it despite how cheap it is. You spend $8 on a trip to McDonalds * distribute it? You didn't pay for it despite how cheap it is. You spend $8 on a trip to McDonalds
@ -39,7 +39,12 @@ public class LibVersion {
thisPluginIsPaidFor = isPremium(); thisPluginIsPaidFor = isPremium();
if (!isPremium() && disguises.getDescription().getVersion().contains("SNAPSHOT")) { if (!isPremium() && disguises.getDescription().getVersion().contains("SNAPSHOT")) {
for (File file : new File("plugins/LibsDisguises/").listFiles()) { File[] files = new File("plugins/LibsDisguises/").listFiles();
if (files == null)
return;
for (File file : files) {
if (!file.isFile()) if (!file.isFile())
continue; continue;
@ -48,7 +53,7 @@ public class LibVersion {
try { try {
ClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()}); ClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()});
Class c = cl.loadClass(LibVersion.class.getName()); Class c = cl.loadClass(LibsVersion.class.getName());
Method m = c.getMethod("isPremium"); Method m = c.getMethod("isPremium");
thisPluginIsPaidFor = (Boolean) m.invoke(null); thisPluginIsPaidFor = (Boolean) m.invoke(null);
@ -56,10 +61,6 @@ public class LibVersion {
if (isPremium()) if (isPremium())
break; break;
} }
catch (ClassNotFoundException ex) {
if (disguises.getDescription().getVersion().contains("9.3.0-SNAPSHOT"))
thisPluginIsPaidFor = true;
}
catch (Exception ex) { catch (Exception ex) {
// Don't print off errors // Don't print off errors
} }

View File

@ -7,16 +7,13 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import com.mysql.fabric.xmlrpc.base.Param;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.TreeSpecies; import org.bukkit.TreeSpecies;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Horse; import org.bukkit.entity.*;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@ -37,9 +34,7 @@ public class ReflectionFlagWatchers {
private String description; private String description;
public ParamInfo(Class paramClass, String name, String description) { public ParamInfo(Class paramClass, String name, String description) {
this(name, description);
this.name = name;
this.description = description;
this.paramClass = paramClass; this.paramClass = paramClass;
Enum[] enums = (Enum[]) paramClass.getEnumConstants(); Enum[] enums = (Enum[]) paramClass.getEnumConstants();
@ -51,24 +46,37 @@ public class ReflectionFlagWatchers {
this.enums[i] = enums[i].name(); this.enums[i] = enums[i].name();
} }
} }
paramList.add(this);
}
private ParamInfo(String name, String description) {
this.name = name;
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) { public ParamInfo(Class paramClass, Enum[] enums, String name, String description) {
this.name = name; this(name, description);
this.enums = new String[enums.length]; this.enums = new String[enums.length];
this.description = description;
this.paramClass = paramClass; this.paramClass = paramClass;
for (int i = 0; i < enums.length; i++) { for (int i = 0; i < enums.length; i++) {
this.enums[i] = enums[i].name(); this.enums[i] = enums[i].name();
} }
paramList.add(this);
} }
public ParamInfo(Class paramClass, String name, String description, String[] enums) { public ParamInfo(Class paramClass, String name, String description, String[] enums) {
this.name = name; this(name, description);
this.enums = enums; this.enums = enums;
this.description = description;
this.paramClass = paramClass; this.paramClass = paramClass;
paramList.add(this);
} }
public boolean isEnums() { public boolean isEnums() {
@ -92,7 +100,7 @@ public class ReflectionFlagWatchers {
} }
} }
private static ArrayList<ParamInfo> paramList = new ArrayList<ParamInfo>(); private static ArrayList<ParamInfo> paramList = new ArrayList<>();
public static ArrayList<ParamInfo> getParamInfos() { public static ArrayList<ParamInfo> getParamInfos() {
return paramList; return paramList;
@ -131,19 +139,29 @@ public class ReflectionFlagWatchers {
} }
static { static {
paramList.add(new ParamInfo(AnimalColor.class, "Animal Color", "View all the colors you can use for an animal color")); new ParamInfo(AnimalColor.class, "Animal Color", "View all the colors you can use for an animal color");
paramList.add(new ParamInfo(Art.class, "Art", "View all the paintings you can use for a painting disguise")); new ParamInfo(Art.class, "Art", "View all the paintings you can use for a painting disguise");
paramList.add(new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color"));
paramList.add(new ParamInfo(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color"));
paramList.add(new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots"));
paramList.add(new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a villager"));
paramList.add(new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 5), "Direction",
"View the five directions usable on player setSleeping disguise"));
paramList.add(new ParamInfo(Rabbit.Type.class, "Rabbit Type", "View the kinds of rabbits you can turn into"));
paramList.add(new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species"));
ArrayList<String> potionEnums = new ArrayList<String>(); new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color");
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");
new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a villager");
new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 5), "Direction",
"View the five directions usable on player setSleeping disguise");
new ParamInfo(Rabbit.Type.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");
try {
new ParamInfo("org.bukkit.entity.Parrot$Variant", "Parrot Variant",
"View the different colors a parrot can be");
}
catch (ClassNotFoundException ex) {// Dont handle
}
ArrayList<String> potionEnums = new ArrayList<>();
for (PotionEffectType effectType : PotionEffectType.values()) { for (PotionEffectType effectType : PotionEffectType.values()) {
if (effectType == null) if (effectType == null)
@ -157,16 +175,17 @@ public class ReflectionFlagWatchers {
materials[i] = Material.values()[i].name(); materials[i] = Material.values()[i].name();
} }
paramList.add(new ParamInfo(ItemStack.class, "Item (id:damage)", "An ItemStack compromised of ID:Durability", materials)); new ParamInfo(ItemStack.class, "Item (id:damage)", "An ItemStack compromised of ID:Durability", materials);
paramList.add(new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..)", new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..)", "Four ItemStacks seperated by an ,",
"Four ItemStacks seperated by an ,", materials) { materials) {
@Override @Override
public String[] getEnums(String tabComplete) { public String[] getEnums(String tabComplete) {
String beginning = tabComplete.substring(0, tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0); String beginning = tabComplete.substring(0,
tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
String end = tabComplete.substring(tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0); String end = tabComplete.substring(tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
ArrayList<String> toReturn = new ArrayList<String>(); ArrayList<String> toReturn = new ArrayList<>();
for (String material : super.getEnums("")) { for (String material : super.getEnums("")) {
if (!material.toLowerCase().startsWith(end.toLowerCase())) if (!material.toLowerCase().startsWith(end.toLowerCase()))
@ -177,23 +196,22 @@ public class ReflectionFlagWatchers {
return toReturn.toArray(new String[0]); return toReturn.toArray(new String[0]);
} }
};
}); new ParamInfo(PotionEffectType.class, "Potion Effect", "View all the potion effects you can add",
potionEnums.toArray(new String[0]));
new ParamInfo(String.class, "Text", "A line of text");
new ParamInfo(boolean.class, "True/False", "True or False", new String[]{"true", "false"});
new ParamInfo(int.class, "Number", "A whole number, no decimcals");
new ParamInfo(double.class, "Number", "A number which can have decimals");
new ParamInfo(float.class, "Number", "A number which can have decimals");
paramList.add(new ParamInfo(PotionEffectType.class, "Potion Effect", "View all the potion effects you can add", new ParamInfo(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse");
potionEnums.toArray(new String[0]))); new ParamInfo(int[].class, "number,number,number...", "Numbers seperated by an ,");
paramList.add(new ParamInfo(String.class, "Text", "A line of text"));
paramList.add(new ParamInfo(boolean.class, "True/False", "True or False", new String[] { new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers seperated by an ,");
"true", "false" new ParamInfo(GameProfile.class, "GameProfile",
})); "Get the gameprofile here https://sessionserver.mojang.com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false");
paramList.add(new ParamInfo(int.class, "Number", "A whole number, no decimcals"));
paramList.add(new ParamInfo(double.class, "Number", "A number which can have decimals"));
paramList.add(new ParamInfo(float.class, "Number", "A number which can have decimals"));
paramList.add(new ParamInfo(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse"));
paramList.add(new ParamInfo(int[].class, "number,number,number...", "Numbers seperated by an ,"));
paramList.add(new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers seperated by an ,"));
paramList.add(new ParamInfo(GameProfile.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>() { Collections.sort(paramList, new Comparator<ParamInfo>() {
@Override @Override
@ -213,27 +231,21 @@ public class ReflectionFlagWatchers {
if (method.getParameterTypes().length != 1) { if (method.getParameterTypes().length != 1) {
itel.remove(); itel.remove();
} } else if (method.getName().startsWith("get")) {
else if (method.getName().startsWith("get")) {
itel.remove(); itel.remove();
} } else if (method.getAnnotation(Deprecated.class) != null) {
else if (method.getAnnotation(Deprecated.class) != null) {
itel.remove(); itel.remove();
} } else if (getParamInfo(method.getParameterTypes()[0]) == null) {
else if (getParamInfo(method.getParameterTypes()[0]) == null) {
itel.remove(); itel.remove();
} } else if (!method.getReturnType().equals(Void.TYPE)) {
else if (!method.getReturnType().equals(Void.TYPE)) {
itel.remove(); itel.remove();
} } else if (method.getName().equals("removePotionEffect")) {
else if (method.getName().equals("removePotionEffect")) {
itel.remove(); itel.remove();
} }
} }
for (String methodName : new String[] { for (String methodName : new String[]{"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf",
"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer" "setHearSelfDisguise", "setHidePlayer"}) {
}) {
try { try {
methods.add(Disguise.class.getMethod(methodName, boolean.class)); methods.add(Disguise.class.getMethod(methodName, boolean.class));
} }

View File

@ -1,47 +1,30 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import java.lang.reflect.Constructor; import com.comphenix.protocol.wrappers.*;
import java.lang.reflect.Field; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import java.lang.reflect.InvocationTargetException; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import java.lang.reflect.Method; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import java.lang.reflect.Modifier; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import java.util.ArrayList; import com.comphenix.protocol.wrappers.nbt.NbtBase;
import java.util.Map; import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import java.util.UUID; import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import java.util.regex.Pattern; import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
import com.google.common.base.Optional;
import com.google.gson.Gson;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Art; import org.bukkit.*;
import org.bukkit.Bukkit; import org.bukkit.entity.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import com.comphenix.protocol.wrappers.BlockPosition; import java.lang.reflect.*;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import java.util.ArrayList;
import com.comphenix.protocol.wrappers.MinecraftKey; import java.util.Map;
import com.comphenix.protocol.wrappers.Vector3F; import java.util.UUID;
import com.comphenix.protocol.wrappers.WrappedBlockData; import java.util.regex.Pattern;
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.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.google.common.base.Optional;
import com.google.gson.Gson;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
public class ReflectionManager { public class ReflectionManager {
private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
@ -863,6 +846,8 @@ public class ReflectionManager {
return getNmsItem((ItemStack) value); return getNmsItem((ItemStack) value);
} else if (value instanceof Double) } else if (value instanceof Double)
return ((Double) value).floatValue(); return ((Double) value).floatValue();
else if (value instanceof NbtCompound)
return ((NbtWrapper)value).getHandle();
return value; return value;
} }

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.utilities.backwards;
/**
* Created by libraryaddict on 8/06/2017.
*/
public class BackwardMethods {
public boolean isOrderedIndexes() {
return true;
}
}

View File

@ -0,0 +1,56 @@
package me.libraryaddict.disguise.utilities.backwards;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_1;
import java.lang.reflect.Field;
/**
* Created by libraryaddict on 8/06/2017.
*/
public class BackwardsSupport {
public static BackwardMethods getMethods() {
try {
String version = ReflectionManager.getBukkitVersion();
if (version.equals("v1_11_R1")) {
return setupMetadata(Version_1_1.class);
}
return setupMetadata(BackwardMethods.class);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static BackwardMethods setupMetadata(Class<? extends BackwardMethods> backwardsClass) {
try {
BackwardMethods backwards = backwardsClass.newInstance();
for (Field field : backwards.getClass().getFields()) {
if (field.getType() != MetaIndex.class)
continue;
MetaIndex.setMetaIndex(field.getName(), (MetaIndex) field.get(backwards));
}
MetaIndex.setValues();
if (backwards.isOrderedIndexes()) {
MetaIndex.fillInBlankIndexes();
MetaIndex.orderMetaIndexes();
}
return backwards;
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,18 @@
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_1 extends BackwardMethods {
private MetaIndex ILLAGER_META;
private MetaIndex PARROT_VARIANT;
private MetaIndex PLAYER_LEFT_SHOULDER_ENTITY;
private MetaIndex PLAYER_RIGHT_SHOULDER_ENTITY;
}

View File

@ -27,29 +27,24 @@ import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerSounds extends PacketAdapter public class PacketListenerSounds extends PacketAdapter {
{
/** /**
* This is a fix for the stupidity that is * This is a fix for the stupidity that is
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard" * "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
*/ */
private static boolean cancelSound; private static boolean cancelSound;
public PacketListenerSounds(LibsDisguises plugin) public PacketListenerSounds(LibsDisguises plugin) {
{
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS); super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
} }
@Override @Override
public void onPacketSending(PacketEvent event) public void onPacketSending(PacketEvent event) {
{ if (event.isCancelled()) {
if (event.isCancelled())
{
return; return;
} }
if (event.isAsync()) if (event.isAsync()) {
{
return; return;
} }
@ -62,20 +57,15 @@ public class PacketListenerSounds extends PacketAdapter
Player observer = event.getPlayer(); Player observer = event.getPlayer();
if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
{
SoundType soundType = null; SoundType soundType = null;
int[] soundCords = new int[] int[] soundCords = new int[]{(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)};
{
(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)
};
int chunkX = (int) Math.floor((soundCords[0] / 8D) / 16D); int chunkX = (int) Math.floor((soundCords[0] / 8D) / 16D);
int chunkZ = (int) Math.floor((soundCords[2] / 8D) / 16D); int chunkZ = (int) Math.floor((soundCords[2] / 8D) / 16D);
if (!observer.getWorld().isChunkLoaded(chunkX, chunkZ)) if (!observer.getWorld().isChunkLoaded(chunkX, chunkZ)) {
{
return; return;
} }
@ -87,87 +77,68 @@ public class PacketListenerSounds extends PacketAdapter
String soundEffect = ReflectionManager.convertSoundEffectToString(mods.read(0)); String soundEffect = ReflectionManager.convertSoundEffectToString(mods.read(0));
Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities(); Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities();
for (Entity entity : entities) for (Entity entity : entities) {
{
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
if (entityDisguise != null) if (entityDisguise != null) {
{
Location loc = entity.getLocation(); Location loc = entity.getLocation();
int[] entCords = new int[] int[] entCords = new int[]{(int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8)};
{
(int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8)
};
if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2]) if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2]) {
{
continue; continue;
} }
entitySound = DisguiseSound.getType(entity.getType().name()); entitySound = DisguiseSound.getType(entity.getType().name());
if (entitySound == null) if (entitySound == null) {
{
continue; continue;
} }
Object obj = null; Object obj = null;
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity) {
{ try {
try
{
// Use reflection so that this works for either int or double methods // Use reflection so that this works for either int or double methods
obj = LivingEntity.class.getMethod("getHealth").invoke(entity); obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
{
soundType = SoundType.DEATH; soundType = SoundType.DEATH;
} } else {
else
{
obj = null; obj = null;
} }
} }
catch (Exception e) catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
if (obj == null) if (obj == null) {
{
boolean hasInvun = false; boolean hasInvun = false;
Object nmsEntity = ReflectionManager.getNmsEntity(entity); Object nmsEntity = ReflectionManager.getNmsEntity(entity);
try try {
{ if (entity instanceof LivingEntity) {
if (entity instanceof LivingEntity) hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt(
{ nmsEntity) == ReflectionManager.getNmsField("EntityLiving",
hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks") "maxNoDamageTicks").getInt(nmsEntity);
.getInt(nmsEntity) == ReflectionManager.getNmsField("EntityLiving", "maxNoDamageTicks") } else {
.getInt(nmsEntity);
}
else
{
Class clazz = ReflectionManager.getNmsClass("DamageSource"); Class clazz = ReflectionManager.getNmsClass("DamageSource");
hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz) hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable",
.invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC").get(null)); clazz).invoke(nmsEntity,
ReflectionManager.getNmsField(clazz, "GENERIC").get(null));
} }
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
soundType = entitySound.getType(soundEffect, !hasInvun); soundType = entitySound.getType(soundEffect, !hasInvun);
} }
if (soundType != null) if (soundType != null) {
{
disguise = entityDisguise; disguise = entityDisguise;
disguisedEntity = entity; disguisedEntity = entity;
break; break;
@ -175,9 +146,7 @@ public class PacketListenerSounds extends PacketAdapter
} }
} }
if (disguise != null && disguise.isSoundsReplaced() if (disguise != null && disguise.isSoundsReplaced() && (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
&& (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer))
{
String sound = null; String sound = null;
DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name());
@ -185,92 +154,71 @@ public class PacketListenerSounds extends PacketAdapter
if (dSound != null) if (dSound != null)
sound = dSound.getSound(soundType); sound = dSound.getSound(soundType);
if (sound == null) if (sound == null) {
{
event.setCancelled(true); event.setCancelled(true);
} } else {
else if (sound.equals("step.grass")) {
{ try {
if (sound.equals("step.grass"))
{
try
{
int typeId = observer.getWorld().getBlockTypeIdAt((int) Math.floor(soundCords[0] / 8D), int typeId = observer.getWorld().getBlockTypeIdAt((int) Math.floor(soundCords[0] / 8D),
(int) Math.floor(soundCords[1] / 8D), (int) Math.floor(soundCords[2] / 8D)); (int) Math.floor(soundCords[1] / 8D), (int) Math.floor(soundCords[2] / 8D));
Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "getId", int.class) Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "getId",
.invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId); int.class).invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null),
typeId);
if (block != null) if (block != null) {
{
Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step)); mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step));
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
} }
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
// There is no else statement. Because seriously. This should never be null. Unless // There is no else statement. Because seriously. This should never be null. Unless
// someone is // someone is
// sending fake sounds. In which case. Why cancel it. // sending fake sounds. In which case. Why cancel it.
} } else {
else
{
mods.write(0, ReflectionManager.getCraftSoundEffect(sound)); mods.write(0, ReflectionManager.getCraftSoundEffect(sound));
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
// Time to change the pitch and volume // Time to change the pitch and volume
if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE) if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE) {
{
// If the volume is the default // If the volume is the default
if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) {
{
mods.write(5, dSound.getDamageAndIdleSoundVolume()); mods.write(5, dSound.getDamageAndIdleSoundVolume());
} }
// Here I assume its the default pitch as I can't calculate if its real. // Here I assume its the default pitch as I can't calculate if its real.
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity && ((MobDisguise) disguise).doesDisguiseAge()) {
&& ((MobDisguise) disguise).doesDisguiseAge())
{
boolean baby = false; boolean baby = false;
if (disguisedEntity instanceof Zombie) if (disguisedEntity instanceof Zombie) {
{
baby = ((Zombie) disguisedEntity).isBaby(); baby = ((Zombie) disguisedEntity).isBaby();
} } else if (disguisedEntity instanceof Ageable) {
else if (disguisedEntity instanceof Ageable)
{
baby = !((Ageable) disguisedEntity).isAdult(); baby = !((Ageable) disguisedEntity).isAdult();
} }
if (((MobDisguise) disguise).isAdult() == baby) if (((MobDisguise) disguise).isAdult() == baby) {
{
float pitch = (Float) mods.read(6); float pitch = (Float) mods.read(6);
if (baby) if (baby) {
{
// 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 = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
* 0.2F + 1.5F;
// Min = 1.5 // Min = 1.5
// Cap = 97.5 // Cap = 97.5
// Max = 1.7 // Max = 1.7
// Cap = 110.5 // Cap = 110.5
} } else {
else
{
// 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 = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
* 0.2F + 1.0F;
// Min = 1 // Min = 1
// Cap = 63 // Cap = 63
// Max = 1.2 // Max = 1.2
@ -292,11 +240,8 @@ public class PacketListenerSounds extends PacketAdapter
} }
} }
} }
} } else if (event.getPacketType() == Server.ENTITY_STATUS) {
else if (event.getPacketType() == Server.ENTITY_STATUS) if ((byte) mods.read(1) != 2) {
{
if ((byte) mods.read(1) != 2)
{
return; return;
} }
@ -305,9 +250,7 @@ public class PacketListenerSounds extends PacketAdapter
Disguise disguise = DisguiseAPI.getDisguise(observer, entity); Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise != null && !disguise.getType().isPlayer() if (disguise != null && !disguise.getType().isPlayer() && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
&& (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer()))
{
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
if (disSound == null) if (disSound == null)
@ -316,37 +259,28 @@ public class PacketListenerSounds extends PacketAdapter
SoundType soundType = null; SoundType soundType = null;
Object obj = null; Object obj = null;
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity) {
{ try {
try
{
obj = LivingEntity.class.getMethod("getHealth").invoke(entity); obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
{
soundType = SoundType.DEATH; soundType = SoundType.DEATH;
} } else {
else
{
obj = null; obj = null;
} }
} }
catch (Exception e) catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
if (obj == null) if (obj == null) {
{
soundType = SoundType.HURT; soundType = SoundType.HURT;
} }
if (disSound.getSound(soundType) == null if (disSound.getSound(
|| (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) soundType) == null || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) {
{ if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) {
if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())
{
cancelSound = !cancelSound; cancelSound = !cancelSound;
if (cancelSound) if (cancelSound)
@ -355,12 +289,10 @@ public class PacketListenerSounds extends PacketAdapter
disSound = DisguiseSound.getType(disguise.getType().name()); disSound = DisguiseSound.getType(disguise.getType().name());
if (disSound != null) if (disSound != null) {
{
String sound = disSound.getSound(soundType); String sound = disSound.getSound(soundType);
if (sound != null) if (sound != null) {
{
Location loc = entity.getLocation(); Location loc = entity.getLocation();
PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT); PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT);
@ -378,14 +310,10 @@ public class PacketListenerSounds extends PacketAdapter
float pitch; float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
{ pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F } else
+ 1.5F; pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
}
else
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;
@ -400,12 +328,10 @@ public class PacketListenerSounds extends PacketAdapter
mods.write(6, (int) pitch); mods.write(6, (int) pitch);
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }