Fixed bossbars disabling self, added support for modded custom entities, disguises now refer to themselves with the right disguise name when possible, cleaned up some code, fixed bossbar error when a server uses a bad bossbar name in their own system
This commit is contained in:
@@ -973,12 +973,17 @@ public class DisguiseUtilities {
|
||||
bars.forEachRemaining(barList::add);
|
||||
|
||||
for (KeyedBossBar bar : barList) {
|
||||
if (!bar.getKey().getNamespace().equalsIgnoreCase("libsdisguises")) {
|
||||
continue;
|
||||
}
|
||||
// Catch error incase someone added an invalid bossbar name
|
||||
try {
|
||||
if (!bar.getKey().getNamespace().equalsIgnoreCase("libsdisguises")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bar.removeAll();
|
||||
Bukkit.removeBossBar(bar.getKey());
|
||||
bar.removeAll();
|
||||
Bukkit.removeBossBar(bar.getKey());
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@@ -9,7 +9,8 @@ import java.lang.reflect.Type;
|
||||
/**
|
||||
* Created by libraryaddict on 1/06/2017.
|
||||
*/
|
||||
public class SerializerDisguise implements JsonDeserializer<Disguise>, JsonSerializer<Disguise>, InstanceCreator<Disguise> {
|
||||
public class SerializerDisguise implements JsonDeserializer<Disguise>, JsonSerializer<Disguise>,
|
||||
InstanceCreator<Disguise> {
|
||||
|
||||
@Override
|
||||
public Disguise deserialize(JsonElement json, Type typeOfT,
|
||||
@@ -53,7 +54,9 @@ public class SerializerDisguise implements JsonDeserializer<Disguise>, JsonSeria
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Disguise src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src.isPlayerDisguise())
|
||||
if (src.isCustomDisguise()) {
|
||||
return context.serialize(src, CustomDisguise.class);
|
||||
} else if (src.isPlayerDisguise())
|
||||
return context.serialize(src, PlayerDisguise.class);
|
||||
else if (src.isMobDisguise())
|
||||
return context.serialize(src, MobDisguise.class);
|
||||
|
@@ -4,8 +4,6 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
@@ -16,7 +14,10 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 3/01/2019.
|
||||
|
@@ -12,8 +12,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 3/01/2019.
|
||||
|
@@ -14,7 +14,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PacketsManager {
|
||||
private static PacketListener clientInteractEntityListener;
|
||||
|
@@ -61,7 +61,8 @@ public class PacketHandlerAttributes implements IPacketHandler {
|
||||
if (attribute.getAttributeKey().equals("generic.maxHealth")) {
|
||||
WrappedAttribute.Builder builder;
|
||||
|
||||
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher &&
|
||||
((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
||||
builder = WrappedAttribute.newBuilder();
|
||||
builder.attributeKey("generic.maxHealth");
|
||||
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
||||
|
@@ -9,7 +9,6 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.CustomWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
@@ -25,7 +24,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -233,10 +231,10 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, disguisedEntity.getUniqueId());
|
||||
|
||||
if (disguise.getType() != DisguiseType.CUSTOM) {
|
||||
if (!disguise.getType().isCustom()) {
|
||||
mods.write(2, disguise.getType().getTypeId());
|
||||
} else {
|
||||
mods.write(2, ((CustomWatcher) disguise.getWatcher()).getTypeId());
|
||||
mods.write(2, ((CustomDisguise) disguise).getCustomEntity().getTypeId());
|
||||
}
|
||||
|
||||
// region Vector calculations
|
||||
@@ -309,7 +307,13 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
PacketContainer spawnEntity;
|
||||
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
Object entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType());
|
||||
Object entityType;
|
||||
|
||||
if (disguise.isCustomDisguise()) {
|
||||
entityType = ((CustomDisguise) disguise).getCustomEntity().getEntityType();
|
||||
} else {
|
||||
entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType());
|
||||
}
|
||||
|
||||
Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z,
|
||||
loc.getPitch(), loc.getYaw(), entityType, data,
|
||||
@@ -319,6 +323,11 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params);
|
||||
} else {
|
||||
int objectId = disguise.getType().getObjectId();
|
||||
|
||||
if (disguise.isCustomDisguise()) {
|
||||
objectId = ((CustomDisguise) disguise).getCustomEntity().getTypeId();
|
||||
}
|
||||
|
||||
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
||||
|
||||
spawnEntity = ProtocolLibrary.getProtocolManager()
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package me.libraryaddict.disguise.utilities.params.types.custom;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@@ -4,6 +4,8 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.modded.CustomEntity;
|
||||
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
@@ -302,7 +304,7 @@ public class DisguiseParser {
|
||||
ArrayList<DisguisePerm> perms = new ArrayList<>();
|
||||
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
if (disguiseType.getEntityType() == null) {
|
||||
if (disguiseType.getEntityType() == null || disguiseType.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -313,6 +315,8 @@ public class DisguiseParser {
|
||||
perms.add(entry.getKey());
|
||||
}
|
||||
|
||||
perms.addAll(ModdedManager.getDisguiseTypes());
|
||||
|
||||
return perms.toArray(new DisguisePerm[0]);
|
||||
}
|
||||
|
||||
@@ -595,6 +599,7 @@ public class DisguiseParser {
|
||||
ArrayList<String> usedOptions = new ArrayList<>();
|
||||
Disguise disguise = null;
|
||||
DisguisePerm disguisePerm;
|
||||
String name;
|
||||
|
||||
if (args[0].startsWith("@")) {
|
||||
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
|
||||
@@ -608,6 +613,7 @@ public class DisguiseParser {
|
||||
}
|
||||
|
||||
disguisePerm = new DisguisePerm(disguise.getType());
|
||||
name = disguise.getDisguiseName();
|
||||
|
||||
if (disguisePerm.isUnknown()) {
|
||||
throw new DisguiseParseException(LibsMsg.PARSE_CANT_DISG_UNKNOWN);
|
||||
@@ -622,18 +628,32 @@ public class DisguiseParser {
|
||||
}
|
||||
} else {
|
||||
disguisePerm = getDisguisePerm(args[0]);
|
||||
Entry<DisguisePerm, String> customDisguise = DisguiseConfig.getRawCustomDisguise(args[0]);
|
||||
|
||||
if (customDisguise != null) {
|
||||
args = DisguiseUtilities.split(customDisguise.getValue());
|
||||
}
|
||||
|
||||
args = parsePlaceholders(args, sender, target);
|
||||
|
||||
if (disguisePerm == null) {
|
||||
throw new DisguiseParseException(LibsMsg.PARSE_DISG_NO_EXIST, args[0]);
|
||||
}
|
||||
|
||||
name = disguisePerm.toReadable();
|
||||
|
||||
if (disguisePerm.getType().isCustom()) {
|
||||
CustomEntity ent = ModdedManager.getCustomEntity(disguisePerm.toReadable());
|
||||
|
||||
if (ent == null) {
|
||||
throw new DisguiseParseException(LibsMsg.PARSE_CANT_DISG_UNKNOWN);
|
||||
}
|
||||
|
||||
disguise = new CustomDisguise(ent);
|
||||
}
|
||||
|
||||
Entry<DisguisePerm, String> customDisguise = DisguiseConfig.getRawCustomDisguise(args[0]);
|
||||
|
||||
if (customDisguise != null) {
|
||||
args = DisguiseUtilities.split(customDisguise.getValue());
|
||||
name = customDisguise.getKey().toReadable();
|
||||
}
|
||||
|
||||
args = parsePlaceholders(args, sender, target);
|
||||
|
||||
if (disguisePerm.isUnknown()) {
|
||||
throw new DisguiseParseException(LibsMsg.PARSE_CANT_DISG_UNKNOWN);
|
||||
}
|
||||
@@ -665,12 +685,14 @@ public class DisguiseParser {
|
||||
|
||||
// Construct the player disguise
|
||||
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
|
||||
name = ((PlayerDisguise) disguise).getName();
|
||||
toSkip++;
|
||||
}
|
||||
} else if (disguisePerm.isMob()) { // Its a mob, use the mob constructor
|
||||
boolean adult = true;
|
||||
|
||||
if (args.length > 1) {
|
||||
boolean adult = true;
|
||||
|
||||
if (args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("baby")) ||
|
||||
args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"))) {
|
||||
usedOptions.add("setbaby");
|
||||
@@ -678,10 +700,13 @@ public class DisguiseParser {
|
||||
adult = args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"));
|
||||
|
||||
toSkip++;
|
||||
disguise = new MobDisguise(disguisePerm.getType(), adult);
|
||||
} else {
|
||||
disguise = new MobDisguise(disguisePerm.getType());
|
||||
}
|
||||
} else {
|
||||
disguise = new MobDisguise(disguisePerm.getType());
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -763,6 +788,8 @@ public class DisguiseParser {
|
||||
}
|
||||
}
|
||||
|
||||
disguise.setDisguiseName(name);
|
||||
|
||||
// Copy strings to their new range
|
||||
String[] newArgs = new String[args.length - toSkip];
|
||||
System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip);
|
||||
|
@@ -384,6 +384,10 @@ public class DisguisePermissions {
|
||||
if (disguiseType.isMisc()) {
|
||||
return 3;
|
||||
}
|
||||
} else if (permissionName.equals("custom")) {
|
||||
if (disguiseType.isMisc()) {
|
||||
return 3;
|
||||
}
|
||||
} else if (permissionName.equals("*")) {
|
||||
return 4;
|
||||
}
|
||||
|
@@ -1294,6 +1294,56 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object registerEntityType(NamespacedKey key) {
|
||||
try {
|
||||
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(key.toString());
|
||||
|
||||
Class typesClass = getNmsClass("IRegistry");
|
||||
|
||||
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
||||
|
||||
Constructor c = getNmsClass("EntityTypes").getConstructors()[0];
|
||||
|
||||
// UGLY :D
|
||||
Object entityType = c.newInstance(null, null, false, false, false, false, null);
|
||||
|
||||
for (Field f : entityType.getClass().getDeclaredFields()) {
|
||||
if (f.getType() != String.class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
f.setAccessible(true);
|
||||
f.set(entityType, key.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
typesClass.getMethod("a", typesClass, mcKey.getClass(), Object.class)
|
||||
.invoke(null, registry, mcKey, entityType);
|
||||
|
||||
return entityType;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Failed to find EntityType id for " + key);
|
||||
}
|
||||
|
||||
public static int getEntityTypeId(Object entityTypes) {
|
||||
try {
|
||||
Class typesClass = getNmsClass("IRegistry");
|
||||
|
||||
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
||||
|
||||
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Failed to find EntityType id for " + entityTypes);
|
||||
}
|
||||
|
||||
public static int getEntityTypeId(EntityType entityType) {
|
||||
try {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
@@ -1315,6 +1365,22 @@ public class ReflectionManager {
|
||||
throw new IllegalStateException("Failed to find EntityType id for " + entityType);
|
||||
}
|
||||
|
||||
public static Object getEntityType(NamespacedKey name) {
|
||||
try {
|
||||
Class typesClass = getNmsClass("IRegistry");
|
||||
|
||||
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
||||
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name.toString());
|
||||
|
||||
return registry.getClass().getMethod("a", mcKey.getClass()).invoke(registry, mcKey);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("The entity " + name + " is not registered!");
|
||||
}
|
||||
|
||||
public static Object getNmsEntityPose(EntityPose entityPose) {
|
||||
return Enum.valueOf(getNmsClass("EntityPose"), entityPose.name());
|
||||
}
|
||||
@@ -1417,6 +1483,10 @@ public class ReflectionManager {
|
||||
case ARROW:
|
||||
watcherClass = TippedArrowWatcher.class;
|
||||
break;
|
||||
case CUSTOM_LIVING:
|
||||
case CUSTOM_MISC:
|
||||
watcherClass = CustomWatcher.class;
|
||||
break;
|
||||
case COD:
|
||||
case SALMON:
|
||||
watcherClass = FishWatcher.class;
|
||||
@@ -1617,7 +1687,7 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
try {
|
||||
if (disguiseType == DisguiseType.UNKNOWN) {
|
||||
if (disguiseType == DisguiseType.UNKNOWN || disguiseType.isCustom()) {
|
||||
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
|
||||
|
||||
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
||||
|
@@ -234,7 +234,8 @@ public enum LibsMsg {
|
||||
GRAB_DISG_HELP_2(ChatColor.DARK_GREEN + "/grabskin <Optional Name> https://somesite.com/myskin.png"),
|
||||
GRAB_DISG_HELP_3(ChatColor.DARK_GREEN + "/grabskin <Optional Name> myskin.png - Skins must be in the folder!"),
|
||||
GRAB_DISG_HELP_4(ChatColor.DARK_GREEN + "/grabskin <Optional Name> <Player name or UUID>"),
|
||||
GRAB_DISG_HELP_5(ChatColor.GREEN + "If you want the slim Alex version of the skin, append :slim. So 'myskin.png:slim'"),
|
||||
GRAB_DISG_HELP_5(
|
||||
ChatColor.GREEN + "If you want the slim Alex version of the skin, append :slim. So 'myskin.png:slim'"),
|
||||
GRAB_DISG_HELP_6(
|
||||
ChatColor.GREEN + "You will be sent the skin data, but you can also use the saved names in disguises"),
|
||||
CUSTOM_DISGUISE_NAME_CONFLICT(
|
||||
|
Reference in New Issue
Block a user