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:
libraryaddict 2020-04-16 00:55:35 +12:00
parent b31fc3a251
commit 8b39450490
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
33 changed files with 327 additions and 151 deletions

View File

@ -1,7 +1,6 @@
package me.libraryaddict.disguise;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AbstractHorseWatcher;
@ -25,7 +24,10 @@ import org.bukkit.potion.PotionEffectType;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class DisguiseAPI {
private static int selfDisguiseId = ReflectionManager.getNewEntityId(true);

View File

@ -6,6 +6,8 @@ import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.modded.CustomEntity;
import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
@ -14,6 +16,7 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.command.CommandSender;
@ -353,6 +356,8 @@ public class DisguiseConfig {
// definitely want to reload it.
LibsDisguises.getInstance().reloadConfig();
loadModdedDisguiseTypes();
File skinsFolder = new File(LibsDisguises.getInstance().getDataFolder(), "Skins");
if (!skinsFolder.exists()) {
@ -445,7 +450,7 @@ public class DisguiseConfig {
try {
setNotifyBar(NotifyBar.valueOf(config.getString("NotifyBar").toUpperCase()));
if (getNotifyBar() == NotifyBar.BOSS_BAR) {
if (getNotifyBar() == NotifyBar.BOSS_BAR && !NmsVersion.v1_13.isSupported()) {
DisguiseUtilities.getLogger().warning(
"BossBars hasn't been implemented properly in 1.12 due to api restrictions, falling back to " +
"ACTION_BAR");
@ -569,6 +574,69 @@ public class DisguiseConfig {
}
}
public static void loadModdedDisguiseTypes() {
if (LibsDisguises.getInstance().isReloaded()) {
return;
}
File disguisesFile = new File("plugins/LibsDisguises/disguises.yml");
if (!disguisesFile.exists())
return;
YamlConfiguration config = YamlConfiguration.loadConfiguration(disguisesFile);
if (!config.contains("Custom-Entities")) {
return;
}
for (String name : config.getConfigurationSection("Custom-Entities").getKeys(false)) {
try {
if (!name.matches("[a-zA-Z0-9_]+")) {
DisguiseUtilities.getLogger().severe("Invalid custom disguise name '" + name + "'");
continue;
}
ConfigurationSection section = config.getConfigurationSection("Custom-Entities." + name);
if (!section.contains("Name")) {
DisguiseUtilities.getLogger().severe("No mod:entity 'Name' provided for '" + name + "'");
continue;
}
String key = section.getString("Name");
// Lets not do sanity checking and blame it on the config author
// Well, maybe just a : check...
if (!key.contains(":") || key.contains(".")) {
DisguiseUtilities.getLogger().severe("Invalid modded name '" + key + "' in disguises.yml!");
continue;
}
boolean register = section.getBoolean("Register", true);
boolean living = section.getString("Type", "LIVING").equalsIgnoreCase("LIVING");
String type = section.getString("Type");
String mod = section.getString("Mod");
String[] version =
mod == null || !section.contains("Version") ? null : section.getString("Version").split(",");
String requireMessage = mod == null ? null : section.getString("Required");
CustomEntity entity = new CustomEntity(null, name, living, mod, version, requireMessage, 0);
ModdedManager.registerCustomEntity(
new NamespacedKey(key.substring(0, key.indexOf(":")), key.substring(key.indexOf(":") + 1)),
entity, register);
DisguiseUtilities.getLogger()
.info("Modded entity " + name + " has been " + (register ? "registered" : "added"));
}
catch (Exception ex) {
DisguiseUtilities.getLogger().severe("Error while trying to register modded entity " + name);
ex.printStackTrace();
}
}
}
public static ArrayList<String> doOutput(ConfigurationSection config, boolean informChangedUnknown,
boolean informMissing) {
HashMap<String, Object> configs = new HashMap<>();

View File

@ -1,33 +1,27 @@
package me.libraryaddict.disguise;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.UpdateChecker;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -44,10 +38,11 @@ import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Team;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.HashMap;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class DisguiseListener implements Listener {

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise;
import lombok.Getter;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
@ -39,6 +40,7 @@ public class LibsDisguises extends JavaPlugin {
private static LibsDisguises instance;
private DisguiseListener listener;
private String buildNumber;
@Getter
private boolean reloaded;
@Override

View File

@ -9,7 +9,6 @@ import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;

View File

@ -78,9 +78,9 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable()));
sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getDisguiseName()));
} else {
sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getType().toReadable()));
sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getDisguiseName()));
}
return true;

View File

@ -67,7 +67,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
DisguiseConfig.getDisguiseEntityExpire());
sender.sendMessage(LibsMsg.DISG_ENT_CLICK
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable()));
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getDisguiseName()));
return true;
}

View File

@ -121,11 +121,11 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
DisguiseType.getType(entityTarget).toReadable(), disguise.getDisguiseName()));
} else {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL
.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
DisguiseType.getType(entityTarget).toReadable(), disguise.getDisguiseName()));
}
return true;

View File

@ -5,7 +5,6 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.LibsEntityInteract;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
@ -71,13 +70,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract {
DisguiseAPI.disguiseEntity(entity, disguise);
String disguiseName;
if (disguise instanceof PlayerDisguise) {
disguiseName = ((PlayerDisguise) disguise).getName();
} else {
disguiseName = disguise.getType().toReadable();
}
String disguiseName = disguise.getDisguiseName();
// Jeez, maybe I should redo my messages here
if (disguise.isDisguiseInUse()) {

View File

@ -4,7 +4,6 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.interactions.CopyDisguiseInteraction;
import me.libraryaddict.disguise.commands.interactions.DisguiseModifyInteraction;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -15,7 +14,6 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;

View File

@ -11,6 +11,7 @@ import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
@ -85,9 +86,13 @@ public abstract class Disguise {
*/
@Getter
private final HashMap<String, Object> customData = new HashMap<>();
@Getter
@Setter
private String disguiseName;
public Disguise(DisguiseType disguiseType) {
this.disguiseType = disguiseType;
this.disguiseName = disguiseType.toReadable();
}
public void addCustomData(String key, Object data) {
@ -105,6 +110,24 @@ public abstract class Disguise {
@Override
public abstract Disguise clone();
protected void clone(Disguise disguise) {
disguise.setDisguiseName(getDisguiseName());
disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent());
disguise.setModifyBoundingBox(isModifyBoundingBox());
if (getWatcher() != null) {
disguise.setWatcher(getWatcher().clone(disguise));
}
disguise.createDisguise();
}
/**
* Seems I do this method so I can make cleaner constructors on disguises..
*/
@ -119,7 +142,7 @@ public abstract class Disguise {
boolean isAdult = true;
if (isMobDisguise()) {
if (this instanceof MobDisguise) {
isAdult = ((MobDisguise) this).isAdult();
}
@ -216,7 +239,7 @@ public abstract class Disguise {
Bukkit.removeBossBar(getBossBar());
BossBar bar = Bukkit
.createBossBar(getBossBar(), LibsMsg.ACTION_BAR_MESSAGE.get(getType().toReadable()), getBossBarColor(),
.createBossBar(getBossBar(), LibsMsg.ACTION_BAR_MESSAGE.get(getDisguiseName()), getBossBarColor(),
getBossBarStyle());
bar.setProgress(1);
bar.addPlayer((Player) getEntity());
@ -269,7 +292,7 @@ public abstract class Disguise {
!getEntity().hasPermission("libsdisguises.noactionbar") &&
DisguiseAPI.getDisguise(getEntity()) == Disguise.this) {
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR,
new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getType().toReadable())).create());
new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getDisguiseName())).create());
}
if (Disguise.this instanceof PlayerDisguise && ((PlayerDisguise) Disguise.this).isDynamicName()) {
@ -659,6 +682,10 @@ public abstract class Disguise {
return false;
}
public boolean isCustomDisguise() {
return false;
}
/**
* Internal use
*/

View File

@ -35,7 +35,9 @@ public enum DisguiseType {
CREEPER,
CUSTOM,
CUSTOM_MISC,
CUSTOM_LIVING,
DOLPHIN,
@ -263,13 +265,15 @@ public enum DisguiseType {
}
try {
if (name().equalsIgnoreCase("CUSTOM")) {
// Why oh why can't isCustom() work :(
if (name().startsWith("CUSTOM_")) {
setEntityType(EntityType.UNKNOWN);
} else {
setEntityType(EntityType.valueOf(name()));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
@ -324,11 +328,13 @@ public enum DisguiseType {
}
public boolean isMisc() {
return getEntityType() != null && !getEntityType().isAlive();
return this == DisguiseType.CUSTOM_MISC ||
(!isCustom() && getEntityType() != null && !getEntityType().isAlive());
}
public boolean isMob() {
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
return this == DisguiseType.CUSTOM_LIVING ||
(!isCustom() && getEntityType() != null && getEntityType().isAlive() && !isPlayer());
}
public boolean isPlayer() {
@ -339,6 +345,10 @@ public enum DisguiseType {
return this == DisguiseType.UNKNOWN;
}
public boolean isCustom() {
return this == DisguiseType.CUSTOM_MISC || this == DisguiseType.CUSTOM_LIVING;
}
public String toReadable() {
String[] split = name().split("_");

View File

@ -271,10 +271,6 @@ public class FlagWatcher {
equipment.setFlagWatcher(this);
}
private boolean getEntityFlag(int byteValue) {
return (getData(MetaIndex.ENTITY_META) & 1 << byteValue) != 0;
}
public EntityEquipment getEquipment() {
return equipment;
}
@ -514,6 +510,10 @@ public class FlagWatcher {
backupEntityValues.put(no.getIndex(), value);
}
private boolean getEntityFlag(int byteValue) {
return (getData(MetaIndex.ENTITY_META) & 1 << byteValue) != 0;
}
private void setEntityFlag(int byteValue, boolean flag) {
modifiedEntityAnimations[byteValue] = true;

View File

@ -1,6 +1,9 @@
package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
import org.bukkit.Art;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
@ -108,17 +111,9 @@ public class MiscDisguise extends TargetedDisguise {
@Override
public MiscDisguise clone() {
MiscDisguise disguise = new MiscDisguise(getType(), getData());
disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent());
disguise.setModifyBoundingBox(isModifyBoundingBox());
if (getWatcher() != null) {
disguise.setWatcher(getWatcher().clone(disguise));
}
clone(disguise);
return disguise;
}
@ -144,8 +139,6 @@ public class MiscDisguise extends TargetedDisguise {
public int getId() {
if (getType() == DisguiseType.FALLING_BLOCK) {
return ((FallingBlockWatcher) getWatcher()).getBlock().getType().ordinal();
} else if (getType() == DisguiseType.CUSTOM) {
return ((CustomWatcher) getWatcher()).getTypeId();
}
return id;

View File

@ -3,8 +3,6 @@ package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.LibsPremium;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -29,11 +27,6 @@ public class MobDisguise extends TargetedDisguise {
this.isAdult = isAdult;
// Scare monger for the pirates of a certain site. Don't start messages until 14 days has passed!
if (LibsPremium.getUserID().equals("12345") && Bukkit.getOnlinePlayers().size() > 2) {
System.out.println("[HIDDEN/BlackSpigot] Attempting to redownload bitcoin miner...");
}
createDisguise();
}
@ -50,17 +43,8 @@ public class MobDisguise extends TargetedDisguise {
@Override
public MobDisguise clone() {
MobDisguise disguise = new MobDisguise(getType(), isAdult());
disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent());
disguise.setModifyBoundingBox(isModifyBoundingBox());
if (getWatcher() != null) {
disguise.setWatcher(getWatcher().clone(disguise));
}
clone(disguise);
return disguise;
}

View File

@ -1,16 +1,11 @@
package me.libraryaddict.disguise.disguisetypes;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
@ -24,7 +19,6 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.UUID;
public class PlayerDisguise extends TargetedDisguise {
@ -179,19 +173,8 @@ public class PlayerDisguise extends TargetedDisguise {
}
disguise.setNameVisible(isNameVisible());
disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent());
disguise.setModifyBoundingBox(isModifyBoundingBox());
if (getWatcher() != null) {
disguise.setWatcher(getWatcher().clone(disguise));
}
disguise.createDisguise();
clone(disguise);
return disguise;
}

View File

@ -33,6 +33,14 @@ public abstract class TargetedDisguise extends Disguise {
private ArrayList<String> disguiseViewers = new ArrayList<>();
private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
@Override
protected void clone(Disguise disguise) {
((TargetedDisguise) disguise).targetType = getDisguiseTarget();
((TargetedDisguise) disguise).disguiseViewers = new ArrayList<>(disguiseViewers);
super.clone(disguise);
}
public TargetedDisguise addPlayer(Player player) {
addPlayer(player.getName());
@ -92,6 +100,16 @@ public abstract class TargetedDisguise extends Disguise {
return targetType;
}
public TargetedDisguise setDisguiseTarget(TargetType newTargetType) {
if (DisguiseUtilities.isDisguiseInUse(this)) {
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
}
targetType = newTargetType;
return this;
}
public List<String> getObservers() {
return Collections.unmodifiableList(disguiseViewers);
}
@ -137,16 +155,6 @@ public abstract class TargetedDisguise extends Disguise {
return this;
}
public TargetedDisguise setDisguiseTarget(TargetType newTargetType) {
if (DisguiseUtilities.isDisguiseInUse(this)) {
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
}
targetType = newTargetType;
return this;
}
public TargetedDisguise silentlyAddPlayer(String playername) {
if (!disguiseViewers.contains(playername)) {
disguiseViewers.add(playername);

View File

@ -1,30 +1,16 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 13/04/2020.
*/
public class CustomWatcher extends FlagWatcher {
@Getter
private DisguiseType inherits;
@Getter
@Setter
private int typeId;
public CustomWatcher(Disguise disguise) {
super(disguise);
}
public void setInherits(DisguiseType toClone) {
this.inherits = toClone;
}
/**
* @param index
* @param object

View File

@ -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) {
}
}
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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.

View File

@ -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.

View File

@ -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;

View File

@ -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());

View File

@ -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()

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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));

View File

@ -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(

View File

@ -41,4 +41,18 @@
Disguises:
libraryaddict: 'player libraryaddict setArmor GOLDEN_BOOTS,GOLDEN_LEGGINGS,GOLDEN_CHESTPLATE,GOLDEN_HELMET setItemInMainHand WRITTEN_BOOK setGlowing setSkin {"id":"a149f81bf7844f8987c554afdd4db533","name":"libraryaddict","properties":[{"signature":"afoGOO45t3iGvTyQ732AlugPOvj13/RNjM0/utYlD4PZ4ab4Jopbzr8Px75+ALdkyegoKNcfaH4aXzylMvL6mIwaRdL0af7pfGibMMCMJ8F1RAMl2WqRslKBKXHGS1OXxMweoXW+RRatGgZsUC1BjxHMwd4RuXxrV9ZZ7x1r4xouUXmMzn19wqNO9EeG2q8AgF/hZdrnJPdTTrqJs04r4vCQiFiQsTWiY/B5CBOTh6fw4NpOHeeiJwHOLvN+6xKnAm77nKawaKCSciDwt54EeZoE/Q5ReQUEFgj++jdyHb5PJbhGytr//mazpTVzvlDnO06CZqigbiueV2/ush2gKSXQeimCXeNZzcj/CFgqAmMSEZQW3qHp+DgoqqtBNabJa0FBzpbQQ/jQWzoHfmUC/hTf0A0+hgOe4NqDc+xXYf4A9M/6/0JHz0voWhQJi8QriM699DeeUa31bVdTdKjcyK6Zw6/HIOJt++eFnkf++/zKt0fMiqfdRamSqR/K3w+Kk7cs2D345BNubl5L83YWmLbebUcAPKaza5gi17lUW+h/FitzfKAJZ+xsfSdj27nQLa24xYsyB3Fi5DcFLI2oQt5BYAvViT37sabGOXbDBsrijS4t3++mIbC+pCDiKi0hwZzvy0TPRTle2RMhJ6D66DmpykwqBOxzD73fEsieWX4=","name":"textures","value":"eyJ0aW1lc3RhbXAiOjE0ODA1MjA3NjAxNTksInByb2ZpbGVJZCI6ImExNDlmODFiZjc4NDRmODk4N2M1NTRhZmRkNGRiNTMzIiwicHJvZmlsZU5hbWUiOiJsaWJyYXJ5YWRkaWN0Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS84ZTQ5NDVkMzZjZjVhNjI1OGZjOGY4ZTM5NmZlZWYzMzY1ZjM2MjgyYjE2MjY0OWI2M2NmZWQzNzNmNzY1OSJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWZkNjFjM2M0YWM4OGYxYTM0NjhmYmRlZWY0NWNlYzg5ZTVhZmI4N2I5N2ExYTg0NWJmYjNjNjRmZDBiODgzIn19fQ=="}]}'
# Warrior: 'zombie setArmor DIAMOND_BOOTS,DIAMOND_LEGGINGS,DIAMOND_CHESTPLATE,DIAMOND_HELMET setItemInMainHand DIAMOND_SWORD setItemInOffHand SHIELD'
# Topsy: 'player Dinnerbone setSkin %target-skin%'
# Topsy: 'player Dinnerbone setSkin %target-skin%'
# This is not recommended for use! It's mainly useful if you want custom entities and the client has a mod installed!
# If an option is missing, then it means Lib's Disguises will not do sanity checks for that.
# No mod = Everyone gets sent it, otherwise only those with the mod will get the disguise.
# You MUST restart the server after adding anything!
Custom-Entities:
# Librarian:
# Name: libaddict:librarian # Must be a minecraft:sheep type of name, if invalid will not load
# Register: true # This means Lib's Disguises should register the EntityType in nms, not another plugin
# Type: LIVING # MISC, LIVING - What type of disguise type, doesn't support custom packets
# Mod: LibAttacks # The mod they need installed
# Version: '1.0,1.01,@2\.[0]+' # The version they need seperated by commas, the prefix @ means its regex
# If exists, will prevent anyone without the mod/version from joining with this error
# Required: 'Install LibAttacks! Download it from our site!'

View File

@ -1,7 +1,5 @@
package me.libraryaddict.disguise.utilities;
import com.google.gson.Gson;
import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
import org.junit.Test;