Read for information...

Now using ASM manipulation to remove invalid methods on load
Fixed imports
Fixed Chat Components being used in 1.12
Fixed tab complete showing args for disguise options you can't use
Disguise option permissions now demand a parameter to be the method name
Falling block disguises are now only usable with blocks
LibsDisguises command now tab completes the new options
Libs Disguises command lets you create a vanilla compatible item string
If a vehicle is disguised as a vehicle, don't give no gravity
Fixed horse disguise using almost random values for its flagwatcher settings
Renamed horse disguise setMouthOpen to setEating
Slightly better string for premium info jar location
Skip attributes packets if using older ProtocolLib jar
Don't cancel entity death if entity is dead
Improved disguise permissions checking
Fixed time parameter not being attributed properly
This commit is contained in:
libraryaddict 2020-02-19 12:57:39 +13:00
parent 668eec641e
commit 897a6629ae
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
65 changed files with 1205 additions and 513 deletions

View File

@ -47,7 +47,7 @@
</executions>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>me.libraryaddict.disguise.utilities.reflection.CompileMethods</mainClass>
<mainClass>me.libraryaddict.disguise.utilities.watchers.CompileMethods</mainClass>
</configuration>
</plugin>
</plugins>
@ -65,6 +65,12 @@
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -8,6 +8,7 @@ import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherSanitizer;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
@ -16,8 +17,6 @@ import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.io.File;
import java.util.Arrays;
@ -80,6 +79,7 @@ public class LibsDisguises extends JavaPlugin {
return;
}
WatcherSanitizer.init();
ReflectionManager.init();
PacketsManager.init();

View File

@ -6,11 +6,11 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
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;
@ -79,10 +79,11 @@ public class CopyDisguiseCommand implements CommandExecutor {
return true;
}*/
sendMessage(sender, LibsMsg.CLICK_TO_COPY, disguiseString, false);
sendMessage(sender, LibsMsg.CLICK_TO_COPY, LibsMsg.COPY_DISGUISE_NO_COPY, disguiseString, false);
if (disguise instanceof PlayerDisguise) {
sendMessage(sender, LibsMsg.CLICK_TO_COPY_WITH_SKIN, DisguiseParser.parseToString(disguise), true);
sendMessage(sender, LibsMsg.CLICK_TO_COPY_WITH_SKIN, LibsMsg.CLICK_TO_COPY_WITH_SKIN_NO_COPY,
DisguiseParser.parseToString(disguise), true);
}
DisguiseUtilities.setCopyDisguiseCommandUsed();
@ -90,7 +91,12 @@ public class CopyDisguiseCommand implements CommandExecutor {
return true;
}
private void sendMessage(CommandSender sender, LibsMsg msg, String string, boolean forceAbbrev) {
private void sendMessage(CommandSender sender, LibsMsg msg, LibsMsg oldVer, String string, boolean forceAbbrev) {
if (!NmsVersion.v1_13.isSupported()) {
sender.sendMessage(oldVer.get(string));
return;
}
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(msg.get()).append(" ");
if (string.length() > 256 || forceAbbrev) {

View File

@ -1,13 +1,12 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.LibsPremium;
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.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
@ -159,6 +158,10 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ParamInfoManager.getDisguiseWatcherMethods(disguisePerm.getWatcherClass())) {
if (!perms.isAllowedDisguise(disguisePerm, Collections.singletonList(method.getName()))) {
continue;
}
tabs.add(method.getName());
}
}

View File

@ -1,12 +1,12 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
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.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -85,8 +85,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
}
}
Class c = method.getParameterTypes()[0];
ParamInfo info = ParamInfoManager.getParamInfo(c);
ParamInfo info = ParamInfoManager.getParamInfo(method);
int value = ParamInfoManager.getValue(method);
ChatColor methodColor = ChatColor.YELLOW;

View File

@ -62,7 +62,7 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
List<String> tabs = new ArrayList<>();
for (DisguisePerm perm : perms.getAllowed()) {
tabs.addAll(getTabDisguiseSubOptions(sender, perms, perm, args, 0, getCurrentArg(args)));
tabs.addAll(getTabDisguiseOptions(sender, perms, perm, args, 0, getCurrentArg(origArgs)));
}
return filterTabs(tabs, origArgs);

View File

@ -4,8 +4,11 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.*;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
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.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;

View File

@ -6,6 +6,7 @@ import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.SkinUtils;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent;
@ -111,6 +112,7 @@ public class GrabSkinCommand implements CommandExecutor {
int start = 0;
int msg = 1;
if (NmsVersion.v1_13.isSupported()) {
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(LibsMsg.CLICK_TO_COPY.get());
while (start < string.length()) {
@ -136,6 +138,9 @@ public class GrabSkinCommand implements CommandExecutor {
}
sender.spigot().sendMessage(builder.create());
} else {
sender.sendMessage(LibsMsg.SKIN_DATA.get(string));
}
DisguiseUtilities.setGrabSkinCommandUsed();
}

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.commands;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
@ -9,11 +10,14 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
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;
@ -27,6 +31,7 @@ import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@ -206,10 +211,45 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
String gson = DisguiseUtilities.getGson().toJson(item);
String simple = ParamInfoManager.toString(item);
sendMessage(sender, LibsMsg.ITEM_SERIALIZED, gson);
// item{nbt} amount
// item amount data {nbt}
if (!gson.equals(simple)) {
sendMessage(sender, LibsMsg.ITEM_SIMPLE_STRING, simple);
String itemName = ReflectionManager.getItemName(item.getType());
ArrayList<String> mcArray = new ArrayList<>();
if (NmsVersion.v1_13.isSupported() && item.hasItemMeta()) {
mcArray.add(itemName + DisguiseUtilities.serialize(NbtFactory.fromItemTag(item)));
} else {
mcArray.add(itemName);
}
if (item.getAmount() != 1) {
mcArray.add(String.valueOf(item.getAmount()));
}
if (!NmsVersion.v1_13.isSupported()) {
if (item.getDurability() != 0) {
mcArray.add(String.valueOf(item.getDurability()));
}
if (item.hasItemMeta()) {
mcArray.add(DisguiseUtilities.serialize(NbtFactory.fromItemTag(item)));
}
}
String ldItem = StringUtils.join(mcArray, "-");
String mcItem = StringUtils.join(mcArray, " ");
sendMessage(sender, LibsMsg.ITEM_SERIALIZED, LibsMsg.ITEM_SERIALIZED_NO_COPY, gson);
if (!gson.equals(simple) && !ldItem.equals(simple) && !mcItem.equals(simple)) {
sendMessage(sender, LibsMsg.ITEM_SIMPLE_STRING, LibsMsg.ITEM_SIMPLE_STRING_NO_COPY, simple);
}
sendMessage(sender, LibsMsg.ITEM_SERIALIZED_MC, LibsMsg.ITEM_SERIALIZED_MC_NO_COPY, mcItem);
if (mcArray.size() > 1) {
sendMessage(sender, LibsMsg.ITEM_SERIALIZED_MC, LibsMsg.ITEM_SERIALIZED_MC_NO_COPY, ldItem);
}
} else if (args[0].equalsIgnoreCase("metainfo") || args[0].equalsIgnoreCase("meta")) {
if (!sender.hasPermission("libsdisguises.metainfo")) {
@ -235,6 +275,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
names.sort(String::compareToIgnoreCase);
if (NmsVersion.v1_13.isSupported()) {
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(LibsMsg.META_VALUES.get());
Iterator<String> itel = names.iterator();
@ -254,6 +295,10 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
}
sender.spigot().sendMessage(builder.create());
} else {
sender.sendMessage(
LibsMsg.META_VALUES_NO_CLICK.get(StringUtils.join(names, LibsMsg.META_VALUE_SEPERATOR.get())));
}
}
} else {
sender.sendMessage(LibsMsg.LIBS_COMMAND_WRONG_ARG.get());
@ -262,7 +307,12 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
return true;
}
private void sendMessage(CommandSender sender, LibsMsg prefix, String string) {
private void sendMessage(CommandSender sender, LibsMsg prefix, LibsMsg oldVer, String string) {
if (!NmsVersion.v1_13.isSupported()) {
sender.sendMessage(oldVer.get(string));
return;
}
int start = 0;
int msg = 1;
@ -286,7 +336,8 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, sub));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + " " + msg).create()));
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + (string.length() <= 256 ? "" : " " + msg))
.create()));
msg += 1;
}
@ -299,7 +350,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
String[] args = getArgs(origArgs);
if (args.length == 0)
tabs.add("Reload");
tabs.addAll(Arrays.asList("reload", "scoreboard", "permtest", "json", "metainfo"));
return filterTabs(tabs, origArgs);
}

View File

@ -13,9 +13,7 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -23,12 +21,9 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
@ -789,6 +784,14 @@ public abstract class Disguise {
if (getEntity() instanceof Player && !getWatcher().hasCustomName()) {
getWatcher().setCustomName("");
}
// If a horse is disguised as a horse, it should obey parent no gravity rule
if ((getEntity() instanceof Boat || getEntity() instanceof AbstractHorse) &&
(getWatcher() instanceof BoatWatcher || getWatcher() instanceof AbstractHorseWatcher)) {
getWatcher().setNoGravity(!getEntity().hasGravity());
} else {
getWatcher().setNoGravity(true);
}
}
/**

View File

@ -46,8 +46,6 @@ public class FlagWatcher {
public FlagWatcher(Disguise disguise) {
this.disguise = (TargetedDisguise) disguise;
equipment = new LibsEquipment(this);
setNoGravity(true);
}
private byte addEntityAnimations(byte originalValue, byte entityValue) {
@ -585,10 +583,12 @@ public class FlagWatcher {
}
}
@NmsAddedIn(val = NmsVersion.v1_14)
public boolean isSleeping() {
return sleeping;
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setSleeping(boolean sleeping) {
if (isSleeping() == sleeping) {
return;
@ -599,10 +599,12 @@ public class FlagWatcher {
updatePose();
}
@NmsAddedIn(val = NmsVersion.v1_14)
public boolean isSwimming() {
return swimming;
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setSwimming(boolean swimming) {
if (isSwimming() == swimming) {
return;

View File

@ -7,25 +7,19 @@ import java.util.Optional;
import java.util.UUID;
public abstract class AbstractHorseWatcher extends AgeableWatcher {
private static final int TAMED = 2, SADDLED = 4, REPRODUCED = 8, GRAZING = 16, REARING = 32, EATING = 64;
public AbstractHorseWatcher(Disguise disguise) {
super(disguise);
}
public Optional<UUID> getOwner() {
return getData(MetaIndex.HORSE_OWNER);
public UUID getOwner() {
return getData(MetaIndex.HORSE_OWNER).orElse(null);
}
/**
* If the horse has a chest
*
* @return Does horse have chest
*/
public boolean hasChest() {
return isHorseFlag(8);
}
public boolean isCarryingChest() {
return hasChest();
public void setOwner(UUID uuid) {
setData(MetaIndex.HORSE_OWNER, Optional.of(uuid));
sendData(MetaIndex.HORSE_OWNER);
}
/**
@ -33,8 +27,12 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
*
* @return Is horse breedable
*/
public boolean isBreedable() {
return isHorseFlag(16);
public boolean isReproduced() {
return isHorseFlag(REPRODUCED);
}
public void setReproduced(boolean reproduced) {
setHorseFlag(REPRODUCED, reproduced);
}
/**
@ -43,7 +41,11 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
* @return Is horse grazing
*/
public boolean isGrazing() {
return isHorseFlag(32);
return isHorseFlag(GRAZING);
}
public void setGrazing(boolean grazing) {
setHorseFlag(GRAZING, grazing);
}
/**
@ -51,20 +53,36 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
*
* @return Horse has mouth open
*/
public boolean isMouthOpen() {
return isHorseFlag(128);
public boolean isEating() {
return isHorseFlag(EATING);
}
public void setEating(boolean mouthOpen) {
setHorseFlag(EATING, mouthOpen);
}
public boolean isRearing() {
return isHorseFlag(64);
return isHorseFlag(REARING);
}
public void setRearing(boolean rear) {
setHorseFlag(REARING, rear);
}
public boolean isSaddled() {
return isHorseFlag(4);
return isHorseFlag(SADDLED);
}
public void setSaddled(boolean saddled) {
setHorseFlag(SADDLED, saddled);
}
public boolean isTamed() {
return isHorseFlag(2);
return isHorseFlag(TAMED);
}
public void setTamed(boolean tamed) {
setHorseFlag(TAMED, tamed);
}
private boolean isHorseFlag(int i) {
@ -75,19 +93,6 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
return getData(MetaIndex.HORSE_META);
}
public void setBreedable(boolean breedable) {
setCanBreed(breedable);
}
@Deprecated
public void setCanBreed(boolean breed) {
setHorseFlag(16, breed);
}
public void setCarryingChest(boolean chest) {
setHorseFlag(8, chest);
}
private void setHorseFlag(int i, boolean flag) {
byte j = getData(MetaIndex.HORSE_META);
@ -99,29 +104,4 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
sendData(MetaIndex.HORSE_META);
}
public void setGrazing(boolean grazing) {
setHorseFlag(32, grazing);
}
public void setMouthOpen(boolean mouthOpen) {
setHorseFlag(128, mouthOpen);
}
public void setOwner(UUID uuid) {
setData(MetaIndex.HORSE_OWNER, Optional.of(uuid));
sendData(MetaIndex.HORSE_OWNER);
}
public void setRearing(boolean rear) {
setHorseFlag(64, rear);
}
public void setSaddled(boolean saddled) {
setHorseFlag(4, saddled);
}
public void setTamed(boolean tamed) {
setHorseFlag(2, tamed);
}
}

View File

@ -1,11 +1,9 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.util.EulerAngle;
import com.comphenix.protocol.wrappers.Vector3F;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.util.EulerAngle;
public class ArmorStandWatcher extends LivingWatcher {
public ArmorStandWatcher(Disguise disguise) {

View File

@ -1,10 +1,9 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.inventory.ItemStack;
public class DroppedItemWatcher extends FlagWatcher {
public DroppedItemWatcher(Disguise disguise) {

View File

@ -1,7 +1,6 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
@ -36,10 +35,6 @@ public class FallingBlockWatcher extends FlagWatcher {
return gridLocked;
}
private short conRel(double oldCord, double newCord) {
return (short) (((oldCord - newCord) * 4096) * (isGridLocked() ? -1 : 1));
}
public void setGridLocked(boolean gridLocked) {
if (isGridLocked() == gridLocked) {
return;
@ -75,12 +70,16 @@ public class FallingBlockWatcher extends FlagWatcher {
}
}
private short conRel(double oldCord, double newCord) {
return (short) (((oldCord - newCord) * 4096) * (isGridLocked() ? -1 : 1));
}
public ItemStack getBlock() {
return block;
}
public void setBlock(ItemStack block) {
if (block == null || block.getType() == null || block.getType() == Material.AIR) {
if (block == null || block.getType() == null || block.getType() == Material.AIR || !block.getType().isBlock()) {
block = new ItemStack(Material.STONE);
}

View File

@ -1,8 +1,8 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class FishingHookWatcher extends FlagWatcher
{

View File

@ -1,11 +1,10 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class GuardianWatcher extends InsentientWatcher {
public GuardianWatcher(Disguise disguise) {

View File

@ -1,9 +1,8 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.MainHand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.inventory.MainHand;
public class InsentientWatcher extends LivingWatcher {
public InsentientWatcher(Disguise disguise) {

View File

@ -1,12 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class ItemFrameWatcher extends FlagWatcher {
public ItemFrameWatcher(Disguise disguise) {
super(disguise);

View File

@ -1,10 +1,9 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Art;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Art;
public class PaintingWatcher extends FlagWatcher
{

View File

@ -1,11 +1,10 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.inventory.ItemStack;
public class SplashPotionWatcher extends FlagWatcher {
private int potionId;

View File

@ -1,8 +1,8 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class WitherSkullWatcher extends FlagWatcher
{

View File

@ -1,11 +1,10 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.security.InvalidParameterException;
import org.bukkit.ChatColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.ChatColor;
import java.security.InvalidParameterException;
public class WitherWatcher extends InsentientWatcher
{

View File

@ -1,12 +1,11 @@
package me.libraryaddict.disguise.events;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class DisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();

View File

@ -1,14 +1,14 @@
package me.libraryaddict.disguise.utilities;
import lombok.Getter;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
import org.bukkit.Sound;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
/**
* Only living disguises go in here!

View File

@ -5,6 +5,10 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtList;
import com.comphenix.protocol.wrappers.nbt.NbtType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
@ -24,6 +28,7 @@ import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.reflection.*;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.bukkit.*;
import org.bukkit.entity.*;
@ -1946,6 +1951,70 @@ public class DisguiseUtilities {
"! Are you running " + "the latest " + "version of " + "ProtocolLib?");
}
public static String serialize(NbtBase base) {
return serialize(0, base);
}
private static String serialize(int depth, NbtBase base) {
switch (base.getType()) {
case TAG_COMPOUND:
StringBuilder builder = new StringBuilder();
builder.append("{");
for (String key : ((NbtCompound) base).getKeys()) {
NbtBase<Object> nbt = ((NbtCompound) base).getValue(key);
String val = serialize(depth + 1, nbt);
// Skip root empty values
if (depth == 0 && val.matches("0(\\.0)?")) {
continue;
}
if (builder.length() != 1) {
builder.append(",");
}
builder.append(key).append(":").append(val);
}
builder.append("}");
return builder.toString();
case TAG_LIST:
Collection col = ((NbtList) base).asCollection();
return "[" + StringUtils.join(col.stream().map(b -> serialize(depth + 1, (NbtBase) b)).toArray(), ",") +
"]";
case TAG_BYTE_ARRAY:
case TAG_INT_ARRAY:
case TAG_LONG_ARRAY:
Object[] array = (Object[]) base.getValue();
String[] str = new String[array.length];
for (int i = 0; i < array.length; i++) {
str[i] = array[i].toString();//+ getChar(base.getType());
}
return "[" + StringUtils.join(str, ",") + "]";
case TAG_BYTE:
case TAG_INT:
case TAG_LONG:
case TAG_FLOAT:
case TAG_SHORT:
case TAG_DOUBLE:
return base.getValue().toString();// + getChar(base.getType());
case TAG_STRING:
String val = (String) base.getValue();
return "\"" + val.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
case TAG_END:
return "";
default:
throw new IllegalArgumentException();
}
}
/**
* Create a new datawatcher but with the 'correct' values
*/

View File

@ -229,7 +229,7 @@ public class LibsPremium {
if (!foundJar) {
DisguiseUtilities.getLogger().warning(
"If you own the plugin, place the premium jar downloaded from https://www.spigotmc" +
".org/resources/libs-disguises.32453/ in " + new File("plugins/LibsDisguises/").getPath());
".org/resources/libs-disguises.32453/ in plugins/LibsDisguises/");
}
}

View File

@ -11,7 +11,6 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@ -94,7 +93,7 @@ public class LibsPackets {
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
if (isRemoveCancel) {
if (isRemoveCancel && !("%%__USER__%%".equals("%%__USER__%%") || "%%__USER__%%".equals("12345"))) {
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
}

View File

@ -1,14 +1,18 @@
package me.libraryaddict.disguise.utilities.packets.packethandlers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedAttribute;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.AbstractHorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -19,6 +23,18 @@ import java.util.List;
* Created by libraryaddict on 3/01/2019.
*/
public class PacketHandlerAttributes implements IPacketHandler {
private boolean skipAttributes = !NmsVersion.v1_14.isSupported() &&
ProtocolLibrary.getPlugin().getDescription().getVersion().equals("4.5.0");
public PacketHandlerAttributes() {
if (!skipAttributes) {
return;
}
DisguiseUtilities.getLogger()
.info("You are running ProtocolLib 4.5.0, attributes will not be handled; Update if you can.");
}
@Override
public PacketType[] getHandledPackets() {
return new PacketType[]{PacketType.Play.Server.UPDATE_ATTRIBUTES};
@ -29,6 +45,11 @@ public class PacketHandlerAttributes implements IPacketHandler {
Entity entity) {
packets.clear();
// Skip due to a bug in ProtocolLib
if (skipAttributes) {
return;
}
if (!disguise.isMiscDisguise()) {
packets.clear();
@ -36,12 +57,7 @@ public class PacketHandlerAttributes implements IPacketHandler {
PacketContainer updateAttributes = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
if (attribute.getAttributeKey().equals("generic.movementSpeed")) {
WrappedAttribute.Builder builder = WrappedAttribute.newBuilder(attribute);
builder.packet(updateAttributes);
attributes.add(builder.build());
} else if (attribute.getAttributeKey().equals("generic.maxHealth")) {
if (attribute.getAttributeKey().equals("generic.maxHealth")) {
WrappedAttribute.Builder builder;
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
@ -53,11 +69,18 @@ public class PacketHandlerAttributes implements IPacketHandler {
} else {
builder = WrappedAttribute.newBuilder();
builder.attributeKey("generic.maxHealth");
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
builder.baseValue(
DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
}
builder.packet(updateAttributes);
attributes.add(builder.build());
} else if (attribute.getAttributeKey().equals("generic.movementSpeed") &&
disguise.getWatcher() instanceof AbstractHorseWatcher) {
WrappedAttribute.Builder builder = WrappedAttribute.newBuilder(attribute);
builder.packet(updateAttributes);
attributes.add(builder.build());
}
}

View File

@ -21,7 +21,7 @@ public class PacketHandlerEntityStatus implements IPacketHandler {
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) {
// If the entity is updating their status, stop them from showing death
if (packets.getPackets().get(0).getBytes().read(0) == (byte) 3) {
if (!entity.isDead() && packets.getPackets().get(0).getBytes().read(0) == (byte) 3) {
packets.clear();
}
}

View File

@ -12,11 +12,11 @@ import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Art;
@ -88,7 +88,8 @@ public class PacketHandlerSpawn implements IPacketHandler {
disguisedEntity instanceof Damageable) {
builder.baseValue(((Damageable) disguisedEntity).getMaxHealth());
} else {
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
builder.baseValue(
DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
}
PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);

View File

@ -1,14 +1,5 @@
package me.libraryaddict.disguise.utilities.packets.packetlisteners;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
@ -17,11 +8,18 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
public class PacketListenerInventory extends PacketAdapter {
private LibsDisguises libsDisguises;

View File

@ -1,21 +1,19 @@
package me.libraryaddict.disguise.utilities.packets.packetlisteners;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Iterator;
import java.util.List;
public class PacketListenerTabList extends PacketAdapter {
public PacketListenerTabList(LibsDisguises plugin) {

View File

@ -1,7 +1,7 @@
package me.libraryaddict.disguise.utilities.parser.params;
package me.libraryaddict.disguise.utilities.params;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import java.util.HashMap;
import java.util.List;
@ -142,4 +142,11 @@ public abstract class ParamInfo {
public Set<String> getEnums(String tabComplete) {
return getValues().keySet();
}
/**
* Is the values it returns all it can do?
*/
public boolean isCustomValues() {
return true;
}
}

View File

@ -1,29 +1,29 @@
package me.libraryaddict.disguise.utilities.parser.params;
package me.libraryaddict.disguise.utilities.params;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
import me.libraryaddict.disguise.utilities.reflection.DisguiseMethods;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock;
import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class ParamInfoManager {
private static List<ParamInfo> paramList;
private static DisguiseMethods disguiseMethods;
@Getter
private static ParamInfoItemBlock paramInfoItemBlock;
public static List<ParamInfo> getParamInfos() {
return paramList;
@ -43,6 +43,15 @@ public class ParamInfoManager {
return info.toString(object);
}
public static ParamInfo getParamInfo(Method method) {
if (method.getDeclaringClass() == FallingBlockWatcher.class &&
method.getParameterTypes()[0] == ItemStack.class) {
return getParamInfoItemBlock();
}
return getParamInfo(method.getParameterTypes()[0]);
}
public static ParamInfo getParamInfo(Class c) {
for (ParamInfo info : getParamInfos()) {
if (!info.isParam(c)) {
@ -64,14 +73,16 @@ public class ParamInfoManager {
if (!method.getName().toLowerCase().equals(methodName.toLowerCase()))
continue;
return getParamInfo(method.getParameterTypes()[0]);
return getParamInfo(method);
}
return null;
}
static {
paramList = new ParamInfoTypes().getParamInfos();
ParamInfoTypes infoTypes = new ParamInfoTypes();
paramList = infoTypes.getParamInfos();
paramInfoItemBlock = infoTypes.getParamInfoBlock();
disguiseMethods = new DisguiseMethods();
//paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()));
@ -84,18 +95,6 @@ public class ParamInfoManager {
ArrayList<Method> methods = new ArrayList<>(disguiseMethods.getMethods(watcherClass));
Iterator<Method> itel = methods.iterator();
while (itel.hasNext()) {
Method method = itel.next();
if (!ReflectionManager.isSupported(method)) {
itel.remove();
} else if (getParamInfo(method.getParameterTypes()[0]) == null) {
itel.remove();
}
}
// Order first by their declaring class, the top class (SheepWatcher) goes before (FlagWatcher)
// Order methods in the same watcher by their name from A to Z
methods.sort((m1, m2) -> {

View File

@ -1,14 +1,13 @@
package me.libraryaddict.disguise.utilities.parser.params;
package me.libraryaddict.disguise.utilities.params;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedParticle;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.EntityPose;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.parser.params.types.base.*;
import me.libraryaddict.disguise.utilities.parser.params.types.custom.*;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.params.types.base.*;
import me.libraryaddict.disguise.utilities.params.types.custom.*;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
@ -26,6 +25,11 @@ import java.util.*;
* Created by libraryaddict on 7/09/2018.
*/
public class ParamInfoTypes {
public ParamInfoItemBlock getParamInfoBlock() {
return new ParamInfoItemBlock(ItemStack.class, "ItemStack", "ItemStack (Material,Amount?,Glow?)",
"An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials());
}
/**
* Constructor values are listed here for continuity
*/
@ -95,7 +99,7 @@ public class ParamInfoTypes {
paramInfos.add(new ParamInfoItemStackArray(ItemStack[].class, "ItemStack[]",
"Four ItemStacks (Material:Amount?:Glow?,Material:Amount?:Glow?..)",
"Four ItemStacks separated by a comma", getMaterials()));
paramInfos.add(new ParamInfoEnum(PotionEffectType.class, "Potion Effect",
paramInfos.add(new ParamInfoPotionEffect(PotionEffectType.class, "Potion Effect",
"View all the potion effects you can add", getPotions()));
paramInfos.add(new ParamInfoBlockPosition(BlockPosition.class, "Block Position", "Block Position (num,num,num)",

View File

@ -1,7 +1,7 @@
package me.libraryaddict.disguise.utilities.parser.params.types;
package me.libraryaddict.disguise.utilities.params.types;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import java.util.Map;
@ -44,4 +44,12 @@ public class ParamInfoEnum extends ParamInfo {
public String toString(Object object) {
return object.toString();
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return false;
}
}

View File

@ -1,7 +1,7 @@
package me.libraryaddict.disguise.utilities.parser.params.types.base;
package me.libraryaddict.disguise.utilities.params.types.base;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import java.util.List;
import java.util.Map;
@ -51,4 +51,12 @@ public class ParamInfoBoolean extends ParamInfo {
public int getMinArguments() {
return 0;
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return false;
}
}

View File

@ -1,6 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.base;
package me.libraryaddict.disguise.utilities.params.types.base;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 7/09/2018.

View File

@ -1,6 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.base;
package me.libraryaddict.disguise.utilities.params.types.base;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 7/09/2018.

View File

@ -1,6 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.base;
package me.libraryaddict.disguise.utilities.params.types.base;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 7/09/2018.

View File

@ -1,6 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.base;
package me.libraryaddict.disguise.utilities.params.types.base;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import org.bukkit.ChatColor;
/**

View File

@ -1,7 +1,7 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import com.comphenix.protocol.wrappers.BlockPosition;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 7/09/2018.

View File

@ -1,6 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import org.bukkit.Color;
import java.util.Map;
@ -60,4 +60,12 @@ public class ParamInfoColor extends ParamInfoEnum {
protected Object fromString(String string) {
return parseToColor(string);
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return true;
}
}

View File

@ -1,6 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import org.bukkit.util.EulerAngle;
/**

View File

@ -1,10 +1,9 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 7/09/2018.

View File

@ -0,0 +1,60 @@
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
/**
* Created by libraryaddict on 16/02/2020.
*/
public class ParamInfoItemBlock extends ParamInfoItemStack {
public ParamInfoItemBlock(Class paramClass, String name, String valueType, String description,
Material[] possibleValues) {
super(paramClass, name, valueType, description,
Arrays.stream(possibleValues).filter(Material::isBlock).toArray(Material[]::new));
}
@Override
public Object fromString(String string) {
String[] split = string.split("[ -]", -1);
if (split.length > (NmsVersion.v1_13.isSupported() ? 1 : 3)) {
throw new IllegalArgumentException();
}
Material material = ReflectionManager.getMaterial(split[0].toLowerCase());
if (material == null) {
material = Material.getMaterial(split[0].toUpperCase());
}
if (material == null) {
throw new IllegalArgumentException();
}
ItemStack itemStack;
if (!NmsVersion.v1_13.isSupported() && split.length > 1 && split[split.length - 1].matches("[0-9]+")) {
itemStack = new ItemStack(material, 1, Short.parseShort(split[split.length - 1]));
} else {
itemStack = new ItemStack(material, 1);
}
if (!itemStack.getType().isBlock()) {
throw new IllegalArgumentException();
}
return itemStack;
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return false;
}
}

View File

@ -0,0 +1,198 @@
package me.libraryaddict.disguise.utilities.params.types.custom;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Created by libraryaddict on 7/09/2018.
*/
public class ParamInfoItemStack extends ParamInfoEnum {
public ParamInfoItemStack(Class paramClass, String name, String valueType, String description,
Enum[] possibleValues) {
super(paramClass, name, valueType, description, possibleValues);
setOtherValues("null", "glow");
}
@Override
public boolean canTranslateValues() {
return false;
}
@Override
public boolean canReturnNull() {
return true;
}
@Override
public Object fromString(String string) {
return parseToItemstack(string);
}
@Override
public String toString(Object object) {
ItemStack item = (ItemStack) object;
ItemStack temp = new ItemStack(item.getType(), item.getAmount());
if (item.containsEnchantment(Enchantment.DURABILITY)) {
temp.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
}
if (temp.isSimilar(item)) {
String name = item.getType().name();
if (item.getAmount() != 1) {
name += ":" + item.getAmount();
}
if (item.containsEnchantment(Enchantment.DURABILITY)) {
name += ":" + TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("glow");
}
return name;
}
String itemName = ReflectionManager.getItemName(item.getType());
ArrayList<String> mcArray = new ArrayList<>();
if (NmsVersion.v1_13.isSupported() && item.hasItemMeta()) {
mcArray.add(itemName + DisguiseUtilities.serialize(NbtFactory.fromItemTag(item)));
} else {
mcArray.add(itemName);
}
if (item.getAmount() != 1) {
mcArray.add(String.valueOf(item.getAmount()));
}
if (!NmsVersion.v1_13.isSupported()) {
if (item.getDurability() != 0) {
mcArray.add(String.valueOf(item.getDurability()));
}
if (item.hasItemMeta()) {
mcArray.add(DisguiseUtilities.serialize(NbtFactory.fromItemTag(item)));
}
}
return StringUtils.join(mcArray, "-");
}
protected static ItemStack parseToItemstack(String string) {
if (string.startsWith("{") && string.endsWith("}")) {
try {
return DisguiseUtilities.getGson().fromJson(string, ItemStack.class);
}
catch (Exception ex) {
throw new IllegalArgumentException();
}
} else if (!string.matches("[a-zA-Z0-9_:,]+")) { // If it can't be simple parsed due to invalid chars
String[] split;
// If it matches /give @p stone {data}
if (string.matches("[^{]+?[ -]\\{.+?}")) {
split = string.substring(0, string.indexOf("{") - 1).split("[ -]");
split = Arrays.copyOf(split, split.length + 1);
split[split.length - 1] = string.substring(string.indexOf("{"));
} else if (string.matches("[^{ ]+?\\{.+?}( [0-9]+?)")) { // /give @p stone[data] <amount?>
split = new String[string.endsWith("}") ? 2 : 3];
split[0] = string.substring(0, string.indexOf("{"));
split[string.endsWith("}") ? 2 : 1] = string
.substring(string.indexOf("{"), string.lastIndexOf("}") + 1);
if (!string.endsWith("}")) {
split[1] = string.substring(string.lastIndexOf(" ") + 1);
}
} else {
split = string.split("[ -]");
}
Material material = ReflectionManager.getMaterial(split[0].toLowerCase());
if (material == null) {
material = Material.getMaterial(split[0].toUpperCase());
}
if (material == null) {
throw new IllegalArgumentException();
}
int amount = split.length > 1 && split[1].matches("[0-9]+") ? Integer.parseInt(split[1]) : 1;
ItemStack itemStack;
if (!NmsVersion.v1_13.isSupported() && split.length > 2 && split[2].matches("[0-9]+")) {
itemStack = new ItemStack(material, amount, Short.parseShort(split[2]));
} else {
itemStack = new ItemStack(material, amount);
}
if (split[split.length - 1].contains("{")) {
Bukkit.getUnsafe().modifyItemStack(itemStack, split[split.length - 1]);
}
return itemStack;
}
return parseToItemstack(string.split("[:,]")); // Split on colon or comma
}
protected static ItemStack parseToItemstack(String[] split) {
if (split[0].isEmpty() || split[0].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("null"))) {
return null;
}
Material material = Material.getMaterial(split[0].toUpperCase());
if (material == null) {
throw new IllegalArgumentException();
}
Integer amount = null;
boolean enchanted = false;
for (int i = 1; i < split.length; i++) {
String s = split[i];
if (!enchanted && s.equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("glow"))) {
enchanted = true;
} else if (s.matches("\\d+") && amount == null) {
amount = Integer.parseInt(s);
} else {
throw new IllegalArgumentException();
}
}
ItemStack itemStack = new ItemStack(material, amount == null ? 1 : amount);
if (enchanted) {
itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
}
return itemStack;
}
public boolean isParam(Class paramClass) {
return getParamClass().isAssignableFrom(paramClass);
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return true;
}
}

View File

@ -1,4 +1,4 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.inventory.ItemStack;
@ -90,4 +90,12 @@ public class ParamInfoItemStackArray extends ParamInfoItemStack {
return items;
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return true;
}
}

View File

@ -1,10 +1,10 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedParticle;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Color;
@ -154,4 +154,12 @@ public class ParamInfoParticle extends ParamInfoEnum {
return WrappedParticle.create(particle, data);
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return true;
}
}

View File

@ -0,0 +1,25 @@
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import org.bukkit.potion.PotionEffectType;
import java.util.Map;
/**
* Created by libraryaddict on 16/02/2020.
*/
public class ParamInfoPotionEffect extends ParamInfoEnum {
public ParamInfoPotionEffect(Class paramClass, String name, String description,
Map<String, Object> possibleValues) {
super(paramClass, name, description, possibleValues);
}
public boolean isParam(Class paramClass) {
return PotionEffectType.class.isAssignableFrom(paramClass);
}
@Override
public String toString(Object object) {
return ((PotionEffectType) object).getName();
}
}

View File

@ -1,9 +1,9 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 6/03/2019.
@ -13,6 +13,11 @@ public class ParamInfoTime extends ParamInfo {
super(paramClass, name, description);
}
@Override
public boolean isParam(Class classType) {
return classType == Long.class || classType == Long.TYPE;
}
@Override
protected Object fromString(String string) throws DisguiseParseException {
if (string.matches("[0-9]{13,}")) {
@ -36,4 +41,12 @@ public class ParamInfoTime extends ParamInfo {
public String toString(Object object) {
return object.toString();
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return true;
}
}

View File

@ -1,12 +1,11 @@
package me.libraryaddict.disguise.utilities.parser;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.Gson;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
@ -87,8 +86,8 @@ public class DisguiseParser {
continue;
} else if (getMethod.getReturnType() != setMethod.getParameterTypes()[0]) {
DisguiseUtilities.getLogger().severe(String
.format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName,
setMethod.getName(), setMethod.getDeclaringClass().getSimpleName()));
.format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'",
getName, setMethod.getName(), setMethod.getDeclaringClass().getSimpleName()));
continue;
}
@ -240,9 +239,9 @@ public class DisguiseParser {
}
}
private static HashMap<String, Boolean> getDisguiseOptions(CommandSender sender, String permNode,
private static HashMap<String, HashMap<String, Boolean>> getDisguiseOptions(CommandSender sender, String permNode,
DisguisePerm type) {
HashMap<String, Boolean> returns = new HashMap<>();
HashMap<String, HashMap<String, Boolean>> returns = new HashMap<>();
String beginning = "libsdisguises.options." + permNode.toLowerCase() + ".";
@ -252,10 +251,16 @@ public class DisguiseParser {
if (lowerPerm.startsWith(beginning)) {
String[] split = lowerPerm.substring(beginning.length()).split("\\.");
if (split.length > 1) {
if (split.length > 2) {
if (split[0].replace("_", "").equals(type.toReadable().toLowerCase().replace(" ", ""))) {
for (int i = 1; i < split.length; i++) {
returns.put(split[i], permission.getValue());
HashMap<String, Boolean> vals = new HashMap<>();
for (int i = 2; i < split.length; i++) {
vals.put(split[i], permission.getValue());
}
for (String s : split[1].split("/")) {
returns.put(s, vals);
}
}
}
@ -329,20 +334,23 @@ public class DisguiseParser {
* <p>
* Returns if command user can access the disguise creation permission type
*/
private static boolean hasPermissionOption(HashMap<String, Boolean> disguiseOptions, String string) {
string = string.toLowerCase();
private static boolean hasPermissionOption(HashMap<String, HashMap<String, Boolean>> disguiseOptions, String method,
String value) {
value = value.toLowerCase();
// If no permissions were defined, return true
if (disguiseOptions.isEmpty()) {
if (!disguiseOptions.containsKey(method.toLowerCase())) {
return true;
}
HashMap<String, Boolean> map = disguiseOptions.get(method.toLowerCase());
// If they were explictly defined, can just return the value
if (disguiseOptions.containsKey(string)) {
return disguiseOptions.get(string);
if (map.containsKey(value)) {
return map.get(value);
}
// If there is at least one whitelisted value, then they needed the whitelist to use it
return !disguiseOptions.containsValue(true);
return !map.containsValue(true);
}
public static String getName(CommandSender entity) {
@ -590,7 +598,8 @@ public class DisguiseParser {
throw new DisguiseParseException(LibsMsg.NO_PERM_DISGUISE);
}
HashMap<String, Boolean> disguiseOptions = getDisguiseOptions(sender, permNode, disguisePerm);
HashMap<String, HashMap<String, Boolean>> disguiseOptions = getDisguiseOptions(sender, permNode,
disguisePerm);
if (disguise == null) {
if (disguisePerm.isPlayer()) {
@ -600,7 +609,7 @@ public class DisguiseParser {
throw new DisguiseParseException(LibsMsg.PARSE_SUPPLY_PLAYER);
} else {
// If they can't use this name, throw error
if (!hasPermissionOption(disguiseOptions, args[1].toLowerCase())) {
if (!hasPermissionOption(disguiseOptions, "setname", args[1].toLowerCase())) {
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_NAME);
}
@ -634,37 +643,37 @@ public class DisguiseParser {
switch (disguisePerm.getType()) {
case FALLING_BLOCK:
case DROPPED_ITEM:
Material material = null;
ParamInfo info = disguisePerm.getType() == DisguiseType.FALLING_BLOCK ?
ParamInfoManager.getParamInfoItemBlock() :
ParamInfoManager.getParamInfo(ItemStack.class);
for (Material mat : Material.values()) {
if (!mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
continue;
try {
itemStack = (ItemStack) info
.fromString(new ArrayList<>(Collections.singletonList(args[1])));
}
material = mat;
catch (IllegalArgumentException ex) {
break;
}
if (material == null) {
break;
String optionName;
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK) {
optionName = "setblock";
} else {
optionName = "setitemstack";
}
itemStack = new ItemStack(material);
usedOptions.add(optionName);
doCheck(sender, permissions, disguisePerm, usedOptions);
if (!hasPermissionOption(disguiseOptions, itemStack.getType().name().toLowerCase())) {
if (!hasPermissionOption(disguiseOptions, optionName,
itemStack.getType().name().toLowerCase())) {
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_PARAM,
itemStack.getType().name(), disguisePerm.toReadable());
}
toSkip++;
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK) {
usedOptions.add("setblock");
} else {
usedOptions.add("setitemstack");
}
doCheck(sender, permissions, disguisePerm, usedOptions);
break;
case PAINTING:
case SPLASH_POTION:
@ -675,18 +684,20 @@ public class DisguiseParser {
miscId = Integer.parseInt(args[1]);
toSkip++;
if (!hasPermissionOption(disguiseOptions, miscId + "")) {
if (disguisePerm.getType() == DisguiseType.PAINTING) {
optionName = "setpainting";
} else {
optionName = "setpotionid";
}
usedOptions.add(optionName);
doCheck(sender, permissions, disguisePerm, usedOptions);
if (!hasPermissionOption(disguiseOptions, optionName, miscId + "")) {
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_PARAM, miscId + "",
disguisePerm.toReadable());
}
if (disguisePerm.getType() == DisguiseType.PAINTING) {
usedOptions.add("setpainting");
} else {
usedOptions.add("setpotionid");
}
doCheck(sender, permissions, disguisePerm, usedOptions);
break;
default:
break;
@ -720,7 +731,7 @@ public class DisguiseParser {
DisguiseParseException {
Method[] methods = ParamInfoManager.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
List<String> list = new ArrayList<>(Arrays.asList(args));
HashMap<String, Boolean> disguiseOptions = getDisguiseOptions(sender, permNode, disguisePerm);
HashMap<String, HashMap<String, Boolean>> disguiseOptions = getDisguiseOptions(sender, permNode, disguisePerm);
for (int argIndex = 0; argIndex < args.length; argIndex++) {
// This is the method name they provided
@ -737,9 +748,7 @@ public class DisguiseParser {
continue;
}
Class paramType = method.getParameterTypes()[0];
ParamInfo paramInfo = ParamInfoManager.getParamInfo(paramType);
ParamInfo paramInfo = ParamInfoManager.getParamInfo(method);
try {
// Store how many args there were before calling the param
@ -785,17 +794,17 @@ public class DisguiseParser {
usedOptions.add(methodToUse.getName().toLowerCase());
}
doCheck(sender, disguisePermission, disguisePerm, usedOptions);
if (!disguiseOptions.isEmpty()) {
String stringValue = ParamInfoManager.toString(valueToSet);
if (!hasPermissionOption(disguiseOptions, stringValue)) {
if (!hasPermissionOption(disguiseOptions, methodToUse.getName(), stringValue)) {
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_PARAM, stringValue,
disguisePerm.toReadable());
}
}
doCheck(sender, disguisePermission, disguisePerm, usedOptions);
if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) {
methodToUse.invoke(disguise.getWatcher(), valueToSet);
} else {

View File

@ -1,114 +0,0 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Created by libraryaddict on 7/09/2018.
*/
public class ParamInfoItemStack extends ParamInfoEnum {
public ParamInfoItemStack(Class paramClass, String name, String valueType, String description,
Enum[] possibleValues) {
super(paramClass, name, valueType, description, possibleValues);
setOtherValues("null", "glow");
}
@Override
public boolean canTranslateValues() {
return false;
}
@Override
public boolean canReturnNull() {
return true;
}
@Override
public Object fromString(String string) {
return parseToItemstack(string);
}
@Override
public String toString(Object object) {
ItemStack itemStack = (ItemStack) object;
ItemStack temp = new ItemStack(itemStack.getType(), itemStack.getAmount());
if (itemStack.containsEnchantment(Enchantment.DURABILITY)) {
temp.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
}
if (temp.isSimilar(itemStack)) {
String name = itemStack.getType().name();
if (itemStack.getAmount() != 1) {
name += ":" + itemStack.getAmount();
}
if (itemStack.containsEnchantment(Enchantment.DURABILITY)) {
name += ":" + TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("glow");
}
return name;
}
return DisguiseUtilities.getGson().toJson(object);
}
protected static ItemStack parseToItemstack(String string) {
if (string.startsWith("{") && string.endsWith("}")) {
try {
return DisguiseUtilities.getGson().fromJson(string, ItemStack.class);
}
catch (Exception ex) {
}
}
return parseToItemstack(string.split("[:,]")); // Split on colon or comma
}
protected static ItemStack parseToItemstack(String[] split) {
if (split[0].isEmpty() || split[0].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("null"))) {
return null;
}
Material material = Material.getMaterial(split[0].toUpperCase());
if (material == null) {
throw new IllegalArgumentException();
}
Integer amount = null;
boolean enchanted = false;
for (int i = 1; i < split.length; i++) {
String s = split[i];
if (!enchanted && s.equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("glow"))) {
enchanted = true;
} else if (s.matches("\\d+") && amount == null) {
amount = Integer.parseInt(s);
} else {
throw new IllegalArgumentException();
}
}
ItemStack itemStack = new ItemStack(material, amount == null ? 1 : amount);
if (enchanted) {
itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
}
return itemStack;
}
public boolean isParam(Class paramClass) {
return getParamClass().isAssignableFrom(paramClass);
}
}

View File

@ -1,54 +0,0 @@
package me.libraryaddict.disguise.utilities.reflection;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import java.util.HashMap;
public class DisguiseValues {
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
public static DisguiseValues getDisguiseValues(DisguiseType type) {
return values.get(type);
}
public static Class getNmsEntityClass(DisguiseType type) {
return getDisguiseValues(type).getNmsEntityClass();
}
private FakeBoundingBox adultBox;
private FakeBoundingBox babyBox;
private float[] entitySize;
private double maxHealth;
private Class nmsEntityClass;
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
values.put(type, this);
nmsEntityClass = classType;
this.maxHealth = maxHealth;
}
public FakeBoundingBox getAdultBox() {
return adultBox;
}
public FakeBoundingBox getBabyBox() {
return babyBox;
}
public double getMaxHealth() {
return maxHealth;
}
public Class getNmsEntityClass() {
return nmsEntityClass;
}
public void setAdultBox(FakeBoundingBox newBox) {
adultBox = newBox;
}
public void setBabyBox(FakeBoundingBox newBox) {
babyBox = newBox;
}
}

View File

@ -10,15 +10,12 @@ import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.*;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@ -1063,6 +1060,71 @@ public class ReflectionManager {
return value;
}
public static Material getMaterial(String name) {
try {
if (!NmsVersion.v1_13.isSupported()) {
Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName",
String.class);
return (Material) toMinecraft.invoke(null, name);
}
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name);
Object registry = getNmsField("IRegistry", "ITEM").get(null);
Method getMethod = getNmsMethod(getNmsClass("RegistryMaterials"), "get", mcKey.getClass());
Object item = getMethod.invoke(registry, mcKey);
if (item == null) {
return null;
}
Method getMaterial = getCraftMethod("util.CraftMagicNumbers", "getMaterial", getNmsClass("Item"));
return (Material) getMaterial.invoke(null, item);
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String getItemName(Material material) {
try {
Object item = getCraftMethod("util.CraftMagicNumbers", "getItem", Material.class).invoke(null, material);
if (item == null) {
return null;
}
Object registry;
if (NmsVersion.v1_13.isSupported()) {
registry = getNmsField("IRegistry", "ITEM").get(null);
} else {
registry = getNmsField("Item", "REGISTRY").get(null);
}
Method getMethod = getNmsMethod(registry.getClass(), NmsVersion.v1_13.isSupported() ? "getKey" : "b",
Object.class);
Object mcKey = getMethod.invoke(registry, item);
if (mcKey == null) {
return null;
}
return (String) getNmsMethod("MinecraftKey", "getKey").invoke(mcKey);
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Object getNmsVillagerData(VillagerData data) {
Object type = getVillagerType(data.getType());
Object profession = getVillagerProfession(data.getProfession());

View File

@ -0,0 +1,61 @@
package me.libraryaddict.disguise.utilities.reflection.asm;
import com.google.gson.Gson;
import org.objectweb.asm.*;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Map;
/**
* Created by libraryaddict on 17/02/2020.
*/
public class Asm13 implements IAsm {
public Class<?> createClassWithoutMethods(String className,
ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException,
IllegalAccessException, NoSuchMethodException, NoSuchFieldException {
ClassReader cr = new ClassReader(
getClass().getClassLoader().getResourceAsStream(className.replace(".", "/") + ".class"));
ClassWriter writer = new ClassWriter(cr, 0);
cr.accept(new ClassVisitor(Opcodes.ASM5, writer) {
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
String[] exceptions) {
Map.Entry<String, String> entry = illegalMethods.stream()
.filter(e -> e.getKey().equals(name) && e.getValue().equals(desc)).findFirst().orElse(null);
if (entry != null) {
return null;
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}, 0);
byte[] bytes = writer.toByteArray();
ClassLoader loader = getClass().getClassLoader();
Field field = loader.getClass().getDeclaredField("classes");
field.setAccessible(true);
Map<String, Class<?>> map = (Map<String, Class<?>>) field.get(loader);
Class newClass =
(Class<?>) getDefineClassMethod()
.invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length);
map.put(className, newClass);
return newClass;
}
private static Method getDefineClassMethod() throws NoSuchMethodException {
Method defineClass = ClassLoader.class
.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
defineClass.setAccessible(true);
return defineClass;
}
}

View File

@ -0,0 +1,60 @@
package me.libraryaddict.disguise.utilities.reflection.asm;
import org.objectweb.asm.*;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Map;
/**
* Created by libraryaddict on 17/02/2020.
*/
public class Asm14 implements IAsm {
public Class<?> createClassWithoutMethods(String className,
ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException,
IllegalAccessException, NoSuchMethodException, NoSuchFieldException {
ClassReader cr = new ClassReader(
getClass().getClassLoader().getResourceAsStream(className.replace(".", "/") + ".class"));
ClassWriter writer = new ClassWriter(cr, 0);
cr.accept(new ClassVisitor(Opcodes.ASM5, writer) {
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
String[] exceptions) {
Map.Entry<String, String> entry = illegalMethods.stream()
.filter(e -> e.getKey().equals(name) && e.getValue().equals(desc)).findFirst().orElse(null);
if (entry != null) {
return null;
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}, 0);
byte[] bytes = writer.toByteArray();
ClassLoader loader = getClass().getClassLoader();
Field field = loader.getClass().getDeclaredField("classes");
field.setAccessible(true);
Map<String, Class<?>> map = (Map<String, Class<?>>) field.get(loader);
Class newClass =
(Class<?>) getDefineClassMethod()
.invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length);
map.put(className, newClass);
return newClass;
}
private static Method getDefineClassMethod() throws NoSuchMethodException {
Method defineClass = ClassLoader.class
.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
defineClass.setAccessible(true);
return defineClass;
}
}

View File

@ -0,0 +1,15 @@
package me.libraryaddict.disguise.utilities.reflection.asm;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Map;
/**
* Created by libraryaddict on 17/02/2020.
*/
public interface IAsm {
public Class<?> createClassWithoutMethods(String className, ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException;
}

View File

@ -0,0 +1,41 @@
package me.libraryaddict.disguise.utilities.reflection.asm;
import lombok.Getter;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import java.lang.reflect.Type;
/**
* Created by libraryaddict on 17/02/2020.
*/
@Getter
public class WatcherInfo {
private int added = -1;
private int removed = -1;
private String watcher;
private String method;
private String param;
String descriptor;
public WatcherInfo(String string) {
String[] split = string.split(":", -1);
if (split.length > 3) {
descriptor = split[3];
added = Integer.parseInt(split[4]);
removed = Integer.parseInt(split[5]);
}
watcher = split[0];
method = split[1];
param = split[2];
}
public boolean isSupported() {
if (getAdded() >= 0 && added > ReflectionManager.getVersion().ordinal()) {
return false;
}
return getRemoved() < 0 || removed > ReflectionManager.getVersion().ordinal();
}
}

View File

@ -0,0 +1,60 @@
package me.libraryaddict.disguise.utilities.reflection.asm;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by libraryaddict on 17/02/2020.
*/
public class WatcherSanitizer {
public static void init() {
IAsm asm;
if (NmsVersion.v1_14.isSupported()) {
asm = new Asm14();
} else {
asm = new Asm13();
}
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
.collect(Collectors.toList());
LinkedHashMap<String, ArrayList<Map.Entry<String, String>>> toRemove = new LinkedHashMap<>();
for (String s : lines) {
WatcherInfo info = new WatcherInfo(s);
if (info.isSupported()) {
continue;
}
String path = "me.libraryaddict.disguise.disguisetypes." +
(info.getWatcher().equals("FlagWatcher") ? "" : "watchers.") + info.getWatcher();
toRemove.putIfAbsent(path, new ArrayList<>());
ArrayList<Map.Entry<String, String>> list = toRemove.get(path);
list.add(new HashMap.SimpleEntry(info.getMethod(), info.getDescriptor()));
}
for (Map.Entry<String, ArrayList<Map.Entry<String, String>>> entry : toRemove.entrySet()) {
Class result = asm.createClassWithoutMethods(entry.getKey(), entry.getValue());
}
}
catch (IOException | NoClassDefFoundError | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException e) {
e.printStackTrace();
}
}
}

View File

@ -187,8 +187,11 @@ public enum LibsMsg {
VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise on!"),
VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise off!"),
CLICK_TO_COPY(ChatColor.GREEN + "Click to Copy:"),
CLICK_TO_COPY_DATA(ChatColor.GOLD + "Data"),
SKIN_DATA(ChatColor.GREEN + "Skin Data: " + ChatColor.YELLOW + "%s"),
CLICK_TO_COPY_DATA(ChatColor.YELLOW + "Data"),
CLICK_TO_COPY_WITH_SKIN(ChatColor.GREEN + "Version with skin data:"),
CLICK_TO_COPY_WITH_SKIN_NO_COPY(ChatColor.GREEN + "Version with skin data: " + ChatColor.YELLOW + "%s"),
COPY_DISGUISE_NO_COPY(ChatColor.GREEN + "Data: " + ChatColor.YELLOW + "%s"),
CLICK_TO_COPY_HOVER(ChatColor.GOLD + "Click to Copy"),
CLICK_COPY(ChatColor.YELLOW + "" + ChatColor.BOLD + "%s"),
SKIN_API_IN_USE(ChatColor.RED + "mineskin.org is currently in use, please try again"),
@ -235,6 +238,7 @@ public enum LibsMsg {
META_INFO(ChatColor.GREEN + "Name: %s, Watcher: %s, Index: %s, Type: %s, Default: %s"),
META_NOT_FOUND(ChatColor.RED + "No meta exists under that name!"),
META_VALUES(ChatColor.BLUE + "Metas: " + ChatColor.DARK_AQUA),
META_VALUES_NO_CLICK(ChatColor.BLUE + "Metas, use as param for more info: " + ChatColor.DARK_AQUA),
META_VALUE_SEPERATOR(ChatColor.AQUA + ", " + ChatColor.DARK_AQUA),
META_CLICK_SHOW(ChatColor.GOLD + "Click to show %s"),
LIBS_PERM_CHECK_INFO_1(ChatColor.AQUA + "Now checking for the permission 'libsdisguises.disguise.pig'"),
@ -250,8 +254,14 @@ public enum LibsMsg {
CANT_ATTACK_DISGUISED_RECENTLY(ChatColor.RED + "You were disguised recently! Can't attack yet!"),
SWITCH_WORLD_DISGUISE_REMOVED(ChatColor.RED + "Disguise removed as you've switched worlds!"),
ACTION_BAR_MESSAGE(ChatColor.GOLD + "Currently disguised as %s"),
ITEM_SERIALIZED(ChatColor.GOLD + "Serialized, click to copy: "),
ITEM_SERIALIZED(ChatColor.GOLD + "Json Serialized, click to copy: "),
ITEM_SERIALIZED_MC(ChatColor.GOLD + "MC Serialized, click to copy: "),
ITEM_SERIALIZED_MC_LD(ChatColor.GOLD + "MC Serialized for LD, click to copy: "),
ITEM_SIMPLE_STRING(ChatColor.GOLD + "Simple, click to copy: "),
ITEM_SERIALIZED_NO_COPY(ChatColor.GOLD + "Json Serialized: " + ChatColor.YELLOW + "%s"),
ITEM_SERIALIZED_MC_NO_COPY(ChatColor.GOLD + "MC Serialized: " + ChatColor.YELLOW + "%s"),
ITEM_SERIALIZED_MC_LD_NO_COPY(ChatColor.GOLD + "MC Serialized for LD: " + ChatColor.YELLOW + "%s"),
ITEM_SIMPLE_STRING_NO_COPY(ChatColor.GOLD + "Simple: " + ChatColor.YELLOW + "%s"),
LIBS_SCOREBOARD_NO_TEAM(ChatColor.RED + "Not on a scoreboard team!"),
LIBS_SCOREBOARD_NO_TEAM_PUSH(ChatColor.RED + "Scoreboard team has pushing enabled!"),
LIBS_SCOREBOARD_SUCCESS(ChatColor.GOLD +

View File

@ -1,9 +1,9 @@
package me.libraryaddict.disguise.utilities.translations;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity;

View File

@ -1,10 +1,12 @@
package me.libraryaddict.disguise.utilities.reflection;
package me.libraryaddict.disguise.utilities.watchers;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MushroomCowWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseSoundEnums;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Sound;
@ -66,25 +68,23 @@ public class CompileMethods {
ArrayList<Class<?>> classes = ClassGetter
.getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers");
classes.add(FlagWatcher.class);
classes.add(MushroomCowWatcher.class);
classes.sort((c1, c2) -> c1.isAssignableFrom(c2) ? -1 : 1);
ArrayList<String> methods = new ArrayList<>();
for (Class c : classes) {
for (Method method : c.getMethods()) {
if (method.getParameterTypes().length != 1) {
if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) {
continue;
} else if (method.getName().startsWith("get")) {
continue;
} else if (method.isAnnotationPresent(Deprecated.class) &&
} else if (method.getParameterCount() > 1 && !method.isAnnotationPresent(NmsAddedIn.class) &&
!method.isAnnotationPresent(NmsRemovedIn.class)) {
continue;
} else if (!method.getReturnType().equals(Void.TYPE)) {
} else if (!(method.getName().startsWith("set") && method.getParameterCount() == 1) &&
!method.getName().startsWith("get") && !method.getName().startsWith("has") &&
!method.getName().startsWith("is")) {
continue;
} else if (method.getName().equals("removePotionEffect")) {
continue;
} else if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) {
continue;
} else if (LibsPremium.isPremium() && new Random().nextBoolean()) {
continue;
}
@ -104,10 +104,15 @@ public class CompileMethods {
removed = method.getDeclaringClass().getAnnotation(NmsRemovedIn.class).val().ordinal();
}
Class<?> param = method.getParameterTypes()[0];
String param = method.getParameterCount() == 1 ? method.getParameterTypes()[0].getName() : "";
String descriptor = "";
String s = ((added >= 0 || removed >= 0) ? added + ":" + removed + ":" : "") +
method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" + param.getName();
if (added >= 0 || removed >= 0) {
descriptor = ":" + getMethodDescriptor(method) + ":" + added + ":" + removed;
}
String s =
method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" + param + descriptor;
if (methods.contains(s)) {
continue;
@ -126,4 +131,44 @@ public class CompileMethods {
ex.printStackTrace();
}
}
static String getDescriptorForClass(final Class c) {
if (c.isPrimitive()) {
if (c == byte.class)
return "B";
if (c == char.class)
return "C";
if (c == double.class)
return "D";
if (c == float.class)
return "F";
if (c == int.class)
return "I";
if (c == long.class)
return "J";
if (c == short.class)
return "S";
if (c == boolean.class)
return "Z";
if (c == void.class)
return "V";
throw new RuntimeException("Unrecognized primitive " + c);
}
if (c.isArray())
return c.getName().replace('.', '/');
return ('L' + c.getName() + ';').replace('.', '/');
}
static String getMethodDescriptor(Method m) {
StringBuilder s = new StringBuilder("(");
for (final Class c : (m.getParameterTypes())) {
s.append(getDescriptorForClass(c));
}
return s.append(")") + getDescriptorForClass(m.getReturnType());
}
}

View File

@ -1,18 +1,21 @@
package me.libraryaddict.disguise.utilities.reflection;
package me.libraryaddict.disguise.utilities.watchers;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import org.apache.commons.lang.ClassUtils;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
@ -35,10 +38,19 @@ public class DisguiseMethods {
return methods;
}
public ArrayList<Method> getMethods() {
ArrayList<Method> methods = new ArrayList<>();
this.watcherMethods.values().forEach(methods::addAll);
return methods;
}
public DisguiseMethods() {
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
.collect(Collectors.toList());
HashMap<String, Class<? extends FlagWatcher>> classes = new HashMap<>();
classes.put(FlagWatcher.class.getSimpleName(), FlagWatcher.class);
@ -56,26 +68,19 @@ public class DisguiseMethods {
}
for (String line : lines) {
String[] split = line.split(":");
WatcherInfo info = new WatcherInfo(line);
if (split.length > 3) {
int added = Integer.parseInt(split[0]);
int removed = Integer.parseInt(split[1]);
if (added >= 0 && added > ReflectionManager.getVersion().ordinal()) {
continue;
} else if (removed >= 0 && removed <= ReflectionManager.getVersion().ordinal()) {
if (!info.isSupported() || info.getParam().isEmpty()) {
continue;
}
}
Class<? extends FlagWatcher> watcher = classes.get(split[split.length - 3]);
Class<? extends FlagWatcher> watcher = classes.get(info.getWatcher());
if (watcher == null) {
continue;
}
String paramName = split[split.length - 1];
String paramName = info.getParam();
Class param;
if (!paramName.contains(".")) {
@ -84,12 +89,24 @@ public class DisguiseMethods {
param = Class.forName(paramName);
}
Method method = watcher.getMethod(split[split.length - 2], param);
Method method = watcher.getMethod(info.getMethod(), param);
if (method.getParameterCount() != 1) {
continue;
} else if (method.getName().startsWith("get")) {
continue;
} else if (method.isAnnotationPresent(Deprecated.class)) {
continue;
} else if (!method.getReturnType().equals(Void.TYPE)) {
continue;
} else if (ParamInfoManager.getParamInfo(method) == null) {
continue;
}
watcherMethods.computeIfAbsent(watcher, (a) -> new ArrayList<>()).add(method);
}
}
catch (IOException | ClassNotFoundException | NoSuchMethodException e) {
catch (IOException | ClassNotFoundException | NoClassDefFoundError | NoSuchMethodException e) {
e.printStackTrace();
}
}