Telesphoreo 2021-09-29 15:19:12 -05:00
commit 588d03dc41
35 changed files with 510 additions and 349 deletions

View file

@ -6,10 +6,12 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
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.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
@ -138,22 +140,35 @@ public class DisguiseAPI {
continue;
}
watcher.setUnsafeData(index, obj.getRawValue());
watcher.setUnsafeData(index, obj.getRawValue());
// Update the meta for 0, otherwise boolean be weird
if (index == MetaIndex.ENTITY_META) {
watcher.setSprinting(watcher.isSprinting() && displayExtraAnimations);
watcher.setFlyingWithElytra(watcher.isFlyingWithElytra() && displayExtraAnimations);
watcher.setRightClicking(watcher.isRightClicking() && displayExtraAnimations);
watcher.setSneaking(watcher.isSneaking() && displayExtraAnimations);
watcher.setSwimming(watcher.isSwimming() && displayExtraAnimations);
if (!NmsVersion.v1_13.isSupported()) {
watcher.setMainHandRaised(watcher.isMainHandRaised() && displayExtraAnimations);
}
if (!displayExtraAnimations) {
Arrays.fill(watcher.getModifiedEntityAnimations(), false);
}
watcher.setGlowing(watcher.isGlowing());
watcher.setInvisible(watcher.isInvisible());
} else if (index == MetaIndex.LIVING_META && NmsVersion.v1_13.isSupported()) {
LivingWatcher livingWatcher = (LivingWatcher) watcher;
livingWatcher.setMainHandRaised(livingWatcher.isMainHandRaised() && displayExtraAnimations);
livingWatcher.setOffhandRaised(livingWatcher.isOffhandRaised() && displayExtraAnimations);
livingWatcher.setSpinning(livingWatcher.isSpinning() && displayExtraAnimations);
if (!displayExtraAnimations) {
Arrays.fill(livingWatcher.getModifiedLivingAnimations(), false);
}
}
}

View file

@ -119,6 +119,10 @@ public class LibsDisguises extends JavaPlugin {
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!");
}
if (Bukkit.getVersion().contains("(MC: 1.17)")) {
getLogger().severe("Please update from MC 1.17! You should be using 1.17.1!");
}
try {
Class cl = Class.forName("org.bukkit.Server$Spigot");
} catch (ClassNotFoundException e) {

View file

@ -14,6 +14,7 @@ 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;
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStack;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
@ -174,6 +175,11 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
if (info != null && !info.isParam(boolean.class)) {
addMethods = false;
}
// Enderman can't hold non-blocks
if (disguisePerm.getType() == DisguiseType.ENDERMAN && prevArg.equalsIgnoreCase("setItemInMainHand")) {
info = ParamInfoManager.getParamInfoItemBlock();
}
}
// If the previous argument is a method

View file

@ -96,7 +96,7 @@ public class LDJson implements LDCommand {
int start = 0;
int msg = 1;
ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(prefix.get()));
ComponentBuilder builder = new ComponentBuilder("").append(prefix.getBase());
while (start < string.length()) {
int end = Math.min(256, string.length() - start);
@ -106,17 +106,17 @@ public class LDJson implements LDCommand {
builder.append(" ");
if (string.length() <= 256) {
builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_TO_COPY_DATA.get()));
builder.append(LibsMsg.CLICK_TO_COPY_DATA.getBase());
} else {
builder.reset();
builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(msg)));
builder.append(LibsMsg.CLICK_COPY.getBase(msg));
}
start += end;
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() + (string.length() <= 256 ? "" : " " + msg))
new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY_HOVER.getBase()).append((string.length() <= 256 ? "" : " " + msg))
.create()));
msg += 1;
}

View file

@ -48,7 +48,7 @@ public class LDMetaInfo implements LDCommand {
names.sort(String::compareToIgnoreCase);
// if (NmsVersion.v1_13.isSupported()) {
ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(LibsMsg.META_VALUES.get()));
ComponentBuilder builder = new ComponentBuilder("").append(LibsMsg.META_VALUES.getBase());
Iterator<String> itel = names.iterator();
@ -57,10 +57,10 @@ public class LDMetaInfo implements LDCommand {
builder.append(TextComponent.fromLegacyText(name));
builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/libsdisguises metainfo " + name));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(LibsMsg.META_CLICK_SHOW.get(name))));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, LibsMsg.META_CLICK_SHOW.getBase(name)));
if (itel.hasNext()) {
builder.append(TextComponent.fromLegacyText(LibsMsg.META_VALUE_SEPERATOR.get()));
builder.append(LibsMsg.META_VALUE_SEPERATOR.getBase());
}
}

View file

@ -62,6 +62,12 @@ public class LDScoreboard implements LDCommand {
continue;
}
DisguiseUtilities.DScoreTeam scoreboardName = ((PlayerDisguise) disguise).getScoreboardName();
if (scoreboardName.getTeamName() == null) {
continue;
}
ArrayList<Scoreboard> checked = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
@ -72,7 +78,7 @@ public class LDScoreboard implements LDCommand {
}
checked.add(board);
DisguiseUtilities.DScoreTeam scoreboardName = ((PlayerDisguise) disguise).getScoreboardName();
Team team = board.getTeam(scoreboardName.getTeamName());

View file

@ -33,7 +33,9 @@ public class CopyDisguiseCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (sender instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage!");
sender.sendMessage(ChatColor.RED +
"This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for " +
"non-admin usage!");
return true;
}
@ -51,8 +53,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
if (args[0].contains("-")) {
try {
target = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
} catch (Exception ignored) {
}
}
}
@ -67,8 +68,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
if (disguise == null) {
LibsDisguises.getInstance().getListener()
.addInteraction(sender.getName(), new CopyDisguiseInteraction(this),
DisguiseConfig.getDisguiseEntityExpire());
.addInteraction(sender.getName(), new CopyDisguiseInteraction(this), DisguiseConfig.getDisguiseEntityExpire());
LibsMsg.DISGUISECOPY_INTERACT.send(sender, DisguiseConfig.getDisguiseEntityExpire());
return true;
@ -79,8 +79,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
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, LibsMsg.CLICK_TO_COPY_WITH_SKIN_NO_COPY,
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();
@ -94,7 +93,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
return;
}*/
ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(msg.get())).append(" ");
ComponentBuilder builder = new ComponentBuilder("").append(msg.getBase()).append(" ");
if (string.length() > 256 || forceAbbrev) {
String[] split = DisguiseUtilities.split(string);
@ -136,18 +135,17 @@ public class CopyDisguiseCommand implements CommandExecutor {
sections++;
builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(sections)));
builder.append(LibsMsg.CLICK_COPY.getBase(sections));
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, current.toString()));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + " " + sections).create()));
new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY_HOVER.getBase()).append(" " + sections).create()));
current = new StringBuilder();
}
} else {
builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(string)));
builder.append(LibsMsg.CLICK_COPY.getBase(string));
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, string));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get()).create()));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, LibsMsg.CLICK_TO_COPY_HOVER.getBase()));
}
sender.spigot().sendMessage(builder.create());

View file

@ -123,7 +123,7 @@ public class GrabSkinCommand implements CommandExecutor {
int msg = 1;
//if (NmsVersion.v1_13.isSupported()) {
ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(LibsMsg.CLICK_TO_COPY.get()));
ComponentBuilder builder = new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY.getBase());
while (start < string.length()) {
int end = Math.min(256, string.length() - start);
@ -133,16 +133,17 @@ public class GrabSkinCommand implements CommandExecutor {
builder.append(" ");
if (string.length() <= 256) {
builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_TO_COPY_DATA.get()));
builder.append(LibsMsg.CLICK_TO_COPY_DATA.getBase());
} else {
builder.reset();
builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(msg)));
builder.append(LibsMsg.CLICK_COPY.getBase(msg));
}
start += end;
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()));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("").append(LibsMsg.CLICK_TO_COPY_HOVER.getBase()).append(" " + msg).create()));
msg += 1;
}

View file

@ -358,8 +358,7 @@ public abstract class Disguise {
removeBossBar();
BossBar bar = Bukkit.createBossBar(getBossBar(),
BaseComponent.toLegacyText(DisguiseUtilities.getColoredChat(LibsMsg.ACTION_BAR_MESSAGE.get(getDisguiseName()))), getBossBarColor(),
BossBar bar = Bukkit.createBossBar(getBossBar(), BaseComponent.toLegacyText(LibsMsg.ACTION_BAR_MESSAGE.getBase(getDisguiseName())), getBossBarColor(),
getBossBarStyle());
bar.setProgress(1);
bar.addPlayer((Player) getEntity());
@ -378,7 +377,7 @@ public abstract class Disguise {
protected void doActionBar() {
if (getNotifyBar() == DisguiseConfig.NotifyBar.ACTION_BAR && getEntity() instanceof Player && !getEntity().hasPermission("libsdisguises.noactionbar") &&
DisguiseAPI.getDisguise(getEntity()) == Disguise.this) {
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, LibsMsg.ACTION_BAR_MESSAGE.getChat(getDisguiseName()));
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, LibsMsg.ACTION_BAR_MESSAGE.getBase(getDisguiseName()));
}
if (isDynamicName()) {

View file

@ -168,7 +168,11 @@ public class FlagWatcher {
sendHeadPacket();
}
private byte addEntityAnimations(byte originalValue, byte entityValue) {
protected byte addEntityAnimations(MetaIndex index, byte originalValue, byte entityValue) {
if (index != MetaIndex.ENTITY_META) {
return originalValue;
}
for (int i = 0; i < 6; i++) {
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations[i]) {
originalValue = (byte) (originalValue | 1 << i);
@ -294,10 +298,12 @@ public class FlagWatcher {
}
if (value != null) {
if (isEntityAnimationsAdded() && id == MetaIndex.ENTITY_META.getIndex()) {
value = addEntityAnimations((byte) value, (byte) watch.getRawValue());
if (isEntityAnimationsAdded() && (index == MetaIndex.ENTITY_META || index == MetaIndex.LIVING_META)) {
value = addEntityAnimations(index, (byte) value, (byte) watch.getRawValue());
doSneakCheck((Byte) value);
if (index == MetaIndex.ENTITY_META) {
doSneakCheck((Byte) value);
}
}
boolean isDirty = watch.getDirtyState();
@ -754,13 +760,25 @@ public class FlagWatcher {
sendData(MetaIndex.ENTITY_NO_GRAVITY);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() {
return isMainHandRaised();
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) {
setMainHandRaised(rightClicking);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
public boolean isMainHandRaised() {
return !NmsVersion.v1_13.isSupported() && getEntityFlag(4);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
public void setRightClicking(boolean setRightClicking) {
public void setMainHandRaised(boolean setRightClicking) {
if (NmsVersion.v1_13.isSupported()) {
return;
}
@ -835,8 +853,8 @@ public class FlagWatcher {
Object value = entityValues.get(data.getIndex());
if (isEntityAnimationsAdded() && DisguiseConfig.isMetaPacketsEnabled() && data == MetaIndex.ENTITY_META) {
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
if (isEntityAnimationsAdded() && DisguiseConfig.isMetaPacketsEnabled() && (data == MetaIndex.ENTITY_META || data == MetaIndex.LIVING_META)) {
value = addEntityAnimations(data, (byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
}
WrappedWatchableObject watch = ReflectionManager.createWatchable(data, value);

View file

@ -112,7 +112,7 @@ public class MetaIndex<Y> {
public static MetaIndex<Byte> ARROW_PIERCE_LEVEL = new MetaIndex<>(ArrowWatcher.class, 2, (byte) 0);
@NmsAddedIn(NmsVersion.v1_17)
public static MetaIndex<Integer> AXOLOTL_VARIENT = new MetaIndex<>(AxolotlWatcher.class, 0, 0);
public static MetaIndex<Integer> AXOLOTL_VARIANT = new MetaIndex<>(AxolotlWatcher.class, 0, 0);
@NmsAddedIn(NmsVersion.v1_17)
public static MetaIndex<Boolean> AXOLOTL_PLAYING_DEAD = new MetaIndex<>(AxolotlWatcher.class, 1, false);
@ -387,7 +387,7 @@ public class MetaIndex<Y> {
/**
* The main hand of the living entity
*/
public static MetaIndex<Byte> LIVING_HAND = new MetaIndex<>(LivingWatcher.class, 0, (byte) 0);
public static MetaIndex<Byte> LIVING_META = new MetaIndex<>(LivingWatcher.class, 0, (byte) 0);
/**
* How much health the living entity has, generally only visible on bosses due to their health bar

View file

@ -48,7 +48,7 @@ public class ArmorStandWatcher extends LivingWatcher {
}
public boolean isMarker() {
return getArmorStandFlag(10);
return getArmorStandFlag(16);
}
public boolean isNoBasePlate() {

View file

@ -21,12 +21,12 @@ public class AxolotlWatcher extends AgeableWatcher {
sendData(MetaIndex.AXOLOTL_PLAYING_DEAD);
}
public Axolotl.Variant getVarient() {
return Axolotl.Variant.values()[getData(MetaIndex.AXOLOTL_VARIENT)];
public Axolotl.Variant getVariant() {
return Axolotl.Variant.values()[getData(MetaIndex.AXOLOTL_VARIANT)];
}
public void setVarient(Axolotl.Variant varient) {
setData(MetaIndex.AXOLOTL_VARIENT, varient.ordinal());
sendData(MetaIndex.AXOLOTL_VARIENT);
public void setVariant(Axolotl.Variant variant) {
setData(MetaIndex.AXOLOTL_VARIANT, variant.ordinal());
sendData(MetaIndex.AXOLOTL_VARIANT);
}
}

View file

@ -32,12 +32,17 @@ public class EndermanWatcher extends InsentientWatcher {
}
public void setItemInMainHand(Material type) {
if (!type.isBlock()) {
return;
}
Optional<WrappedBlockData> optional;
if (type == null)
if (type == null) {
optional = Optional.empty();
else
} else {
optional = Optional.of(WrappedBlockData.createData(type));
}
setData(MetaIndex.ENDERMAN_ITEM, optional);
sendData(MetaIndex.ENDERMAN_ITEM);

View file

@ -54,13 +54,23 @@ public class FallingBlockWatcher extends FlagWatcher {
if (getDisguise().isDisguiseInUse() && getDisguise().getEntity() != null) {
PacketContainer relMove = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
StructureModifier<Short> shorts = relMove.getShorts();
relMove.getModifier().write(0, getDisguise().getEntity().getEntityId());
Location loc = getDisguise().getEntity().getLocation();
relMove.getModifier().write(0, getDisguise().getEntity().getEntityId());
shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5));
shorts.write(1, conRel(loc.getY(), loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5));
if (NmsVersion.v1_14.isSupported()) {
StructureModifier<Short> shorts = relMove.getShorts();
shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5));
shorts.write(1, conRel(loc.getY(), loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5));
} else {
StructureModifier<Integer> ints = relMove.getIntegers();
ints.write(0, (int) conRel(loc.getX(), loc.getBlockX() + 0.5));
ints.write(1, (int) conRel(loc.getY(), loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
ints.write(2, (int) conRel(loc.getZ(), loc.getBlockZ() + 0.5));
}
try {
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {

View file

@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.inventory.MainHand;
@ -34,7 +33,7 @@ public class InsentientWatcher extends LivingWatcher {
if (flag) {
setData(MetaIndex.INSENTIENT_META, (byte) (b0 | i));
} else {
setData(MetaIndex.INSENTIENT_META, (byte) (b0 & i));
setData(MetaIndex.INSENTIENT_META, (byte) (b0 & -(i + 1)));
}
sendData(MetaIndex.INSENTIENT_META);
@ -56,12 +55,5 @@ public class InsentientWatcher extends LivingWatcher {
}
setInsentientFlag(4, enraged);
if (!getDisguise().isDisguiseInUse() || enraged) {
return;
}
// TODO Check if a less hacky fix is possible
DisguiseUtilities.refreshTrackers(getDisguise());
}
}

View file

@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
import lombok.Getter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
@ -25,6 +26,8 @@ public class LivingWatcher extends FlagWatcher {
private double maxHealth;
private boolean maxHealthSet;
private HashSet<String> potionEffects = new HashSet<>();
@Getter
private boolean[] modifiedLivingAnimations = new boolean[3];
public LivingWatcher(Disguise disguise) {
super(disguise);
@ -36,6 +39,7 @@ public class LivingWatcher extends FlagWatcher {
clone.potionEffects = (HashSet<String>) potionEffects.clone();
clone.maxHealth = maxHealth;
clone.maxHealthSet = maxHealthSet;
clone.modifiedLivingAnimations = Arrays.copyOf(modifiedLivingAnimations, modifiedLivingAnimations.length);
return clone;
}
@ -79,31 +83,60 @@ public class LivingWatcher extends FlagWatcher {
}*/
private boolean getHandFlag(int byteValue) {
return (getData(MetaIndex.LIVING_HAND) & 1 << byteValue) != 0;
return (getData(MetaIndex.LIVING_META) & 1 << byteValue) != 0;
}
private void setHandFlag(int byteValue, boolean flag) {
byte b0 = getData(MetaIndex.LIVING_HAND);
byte b0 = getData(MetaIndex.LIVING_META);
modifiedLivingAnimations[byteValue] = true;
if (flag) {
setData(MetaIndex.LIVING_HAND, (byte) (b0 | 1 << byteValue));
setData(MetaIndex.LIVING_META, (byte) (b0 | 1 << byteValue));
} else {
setData(MetaIndex.LIVING_HAND, (byte) (b0 & ~(1 << byteValue)));
setData(MetaIndex.LIVING_META, (byte) (b0 & ~(1 << byteValue)));
}
sendData(MetaIndex.LIVING_HAND);
sendData(MetaIndex.LIVING_META);
}
@NmsAddedIn(NmsVersion.v1_13)
public boolean isRightClicking() {
return getHandFlag(0);
private boolean isMainHandUsed() {
return !getHandFlag(1);
}
private void setHandInUse(boolean mainHand) {
if (isMainHandUsed() == mainHand) {
return;
}
setHandFlag(1, !mainHand);
}
@Override
@NmsAddedIn(NmsVersion.v1_13)
public void setRightClicking(boolean setRightClicking) {
public boolean isMainHandRaised() {
return isMainHandUsed() && getHandFlag(0);
}
@Override
@NmsAddedIn(NmsVersion.v1_13)
public void setMainHandRaised(boolean setRightClicking) {
setHandInUse(true);
setHandFlag(0, setRightClicking);
}
@NmsAddedIn(NmsVersion.v1_13)
public boolean isOffhandRaised() {
return !isMainHandUsed() && getHandFlag(0);
}
@NmsAddedIn(NmsVersion.v1_13)
public void setOffhandRaised(boolean setLeftClicking) {
setHandInUse(false);
setHandFlag(0, setLeftClicking);
}
@NmsAddedIn(NmsVersion.v1_13)
public boolean isSpinning() {
return getHandFlag(2);
@ -262,4 +295,31 @@ public class LivingWatcher extends FlagWatcher {
setData(MetaIndex.LIVING_ARROWS, Math.max(0, Math.min(127, arrowsNo)));
sendData(MetaIndex.LIVING_ARROWS);
}
@Override
protected byte addEntityAnimations(MetaIndex index, byte originalValue, byte entityValue) {
if (index != MetaIndex.LIVING_META) {
return super.addEntityAnimations(index, originalValue, entityValue);
}
for (int i = 0; i < 3; i++) {
if ((entityValue & 1 << i) != 0 && !modifiedLivingAnimations[i]) {
originalValue = (byte) (originalValue | 1 << i);
}
}
return originalValue;
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() {
return isMainHandRaised();
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) {
setMainHandRaised(rightClicking);
}
}

View file

@ -478,8 +478,9 @@ public class DisguiseUtilities {
return new String[]{"4.6.0"};
}
// If we are on 1.17, future release build or this dev build
return new String[]{"4.7.0"};
// If we are on 1.17, you need this release or dev build
// ProtocolLib is a little funny in that it provides next release version as the current version
return new String[]{"4.7.0", "528"};
}
public static boolean isProtocolLibOutdated() {
@ -1366,11 +1367,7 @@ public class DisguiseUtilities {
public static void init() {
try {
// Force an exception to be thrown if it doesn't contain trackedPlayerMap
Class tracker = ReflectionManager.getNmsClass("EntityTrackerEntry");
tracker.getDeclaredField("trackedPlayerMap");
// Don't really need this here, but it's insurance!
// Check if we enable the paperdisguiselistener
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
} catch (Exception ignored) {
}
@ -1857,7 +1854,7 @@ public class DisguiseUtilities {
// TODO Store reflection fields
// If the tracker exists. Remove himself from his tracker
if (!runningPaper) {
if (!isRunningPaper() || NmsVersion.v1_17.isSupported()) {
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
((Set<Object>) trackedPlayersObj).remove(ReflectionManager.getPlayerConnectionOrPlayer(player));
@ -2396,7 +2393,7 @@ public class DisguiseUtilities {
// TODO Store reflection fields
// Check for code differences in PaperSpigot vs Spigot
if (!runningPaper) {
if (!isRunningPaper() || NmsVersion.v1_17.isSupported()) {
// Add himself to his own entity tracker
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
@ -2499,7 +2496,7 @@ public class DisguiseUtilities {
}
public static void sendMessage(CommandSender sender, LibsMsg msg, Object... args) {
BaseComponent[] components = msg.getChat(args);
BaseComponent[] components = msg.getBase(args);
if (components.length > 0) {
sender.spigot().sendMessage(components);

View file

@ -530,7 +530,7 @@ public class DisguiseListener implements Listener {
DisguiseUtilities.doBoundingBox((TargetedDisguise) disguise);
}
if (!NmsVersion.v1_17.isSupported() && DisguiseConfig.isStopShulkerDisguisesFromMoving()) {
if (DisguiseConfig.isStopShulkerDisguisesFromMoving()) {
Disguise disguise;
if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) {

View file

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities.mineskin;
import com.google.gson.Gson;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.SkinUtils;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
@ -65,11 +66,11 @@ public class MineSkinAPI {
}
private void printDebug(String message) {
if (!isDebugging()) {
if (!isDebugging() || LibsDisguises.getInstance() == null) {
return;
}
System.out.println("[MineSkinAPI] " + message);
LibsDisguises.getInstance().getLogger().info("[MineSkinAPI] " + message);
}
private MineSkinResponse doPost(SkinUtils.SkinCallback callback, String path, String skinUrl, File file, SkinUtils.ModelType modelType) {

View file

@ -8,6 +8,7 @@ import com.mojang.datafixers.util.Pair;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
@ -80,14 +81,16 @@ public class PacketHandlerEquipment implements IPacketHandler {
itemStack = ReflectionManager.getBukkitItem(pair.getSecond());
}
if (disguise.getWatcher().isRightClicking() && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
if ((disguise.getWatcher().isMainHandRaised() && slot == EquipmentSlot.HAND) ||
(disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isOffhandRaised() &&
slot == EquipmentSlot.OFF_HAND)) {
if (itemStack != null && itemStack.getType() != Material.AIR) {
// Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<>();
if (DisguiseConfig.isMetaPacketsEnabled()) {
WrappedWatchableObject watch = ReflectionManager
.createWatchable(MetaIndex.LIVING_HAND, WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_HAND.getIndex()));
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.LIVING_META,
WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex()));
if (watch != null) {
list.add(watch);
@ -96,7 +99,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
list = disguise.getWatcher().convert(observer, list);
} else {
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
if (obj.getIndex() == MetaIndex.LIVING_HAND.getIndex()) {
if (obj.getIndex() == MetaIndex.LIVING_META.getIndex()) {
list.add(obj);
break;
}
@ -151,7 +154,9 @@ public class PacketHandlerEquipment implements IPacketHandler {
equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
}
if (disguise.getWatcher().isRightClicking() && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
if ((disguise.getWatcher().isMainHandRaised() && slot == EquipmentSlot.HAND) ||
(disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isOffhandRaised() &&
slot == EquipmentSlot.OFF_HAND)) {
if (itemStack == null) {
itemStack = packets.getPackets().get(0).getItemModifier().read(0);
}
@ -159,7 +164,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
if (itemStack != null && itemStack.getType() != Material.AIR) {
// Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<>();
MetaIndex toUse = NmsVersion.v1_13.isSupported() ? MetaIndex.LIVING_HAND : MetaIndex.ENTITY_META;
MetaIndex toUse = NmsVersion.v1_13.isSupported() ? MetaIndex.LIVING_META : MetaIndex.ENTITY_META;
if (DisguiseConfig.isMetaPacketsEnabled()) {
WrappedWatchableObject watch =

View file

@ -12,6 +12,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
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.reflection.NmsVersion;
import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Location;
import org.bukkit.entity.AbstractHorse;
@ -26,13 +27,12 @@ import java.util.ArrayList;
* Created by libraryaddict on 3/01/2019.
*/
public class PacketHandlerMovement implements IPacketHandler {
private final boolean invalid =
LibsPremium.getUserID().matches("[0-9]+") && Integer.parseInt(LibsPremium.getUserID()) < 2;
private final boolean invalid = LibsPremium.getUserID().matches("[0-9]+") && Integer.parseInt(LibsPremium.getUserID()) < 2;
@Override
public PacketType[] getHandledPackets() {
return new PacketType[]{PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_LOOK,
PacketType.Play.Server.ENTITY_TELEPORT, PacketType.Play.Server.REL_ENTITY_MOVE};
return new PacketType[]{PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.ENTITY_TELEPORT,
PacketType.Play.Server.REL_ENTITY_MOVE};
}
private short conRel(double oldCord, double newCord) {
@ -40,8 +40,7 @@ public class PacketHandlerMovement implements IPacketHandler {
}
@Override
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) {
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
handle2(disguise, sentPacket, packets, observer, entity);
int len = disguise.getMultiNameLength();
@ -74,8 +73,7 @@ public class PacketHandlerMovement implements IPacketHandler {
packets.getPackets().addAll(toAdd);
}
public void handle2(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) {
public void handle2(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
if (invalid && RandomUtils.nextDouble() < 0.1) {
packets.clear();
return;
@ -84,8 +82,7 @@ public class PacketHandlerMovement implements IPacketHandler {
double yMod = DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier();
// If falling block should be appearing in center of blocks
if (disguise.getType() == DisguiseType.FALLING_BLOCK &&
((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
if (disguise.getType() == DisguiseType.FALLING_BLOCK && ((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
packets.clear();
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK) {
@ -108,32 +105,60 @@ public class PacketHandlerMovement implements IPacketHandler {
doubles.write(1, y + yMod);
doubles.write(2, loc.getBlockZ() + 0.5);
} else {
StructureModifier<Short> shorts = movePacket.getShorts();
int x;
int y;
int z;
Vector diff = new Vector(shorts.read(0) / 4096D, shorts.read(1) / 4096D, shorts.read(2) / 4096D);
if (NmsVersion.v1_14.isSupported()) {
StructureModifier<Short> shorts = movePacket.getShorts();
x = shorts.read(0);
y = shorts.read(1);
z = shorts.read(2);
} else {
StructureModifier<Integer> ints = movePacket.getIntegers();
x = ints.read(0);
y = ints.read(1);
z = ints.read(2);
}
Vector diff = new Vector(x / 4096D, y / 4096D, z / 4096D);
Location newLoc = loc.clone().subtract(diff);
double origY = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0);
double newY = newLoc.getBlockY() + (newLoc.getY() % 1 >= 0.85 ? 1 : newLoc.getY() % 1 >= 0.35 ? .5 : 0);
boolean sameBlock =
loc.getBlockX() == newLoc.getBlockX() && newY == origY && loc.getBlockZ() == newLoc.getBlockZ();
boolean sameBlock = loc.getBlockX() == newLoc.getBlockX() && newY == origY && loc.getBlockZ() == newLoc.getBlockZ();
if (sameBlock) {
// Make no modifications but don't send anything
return;
} else {
shorts.write(0, conRel(loc.getBlockX(), newLoc.getBlockX()));
shorts.write(1, conRel(origY, newY));
shorts.write(2, conRel(loc.getBlockZ(), newLoc.getBlockZ()));
x = conRel(loc.getBlockX(), newLoc.getBlockX());
y = conRel(origY, newY);
z = conRel(loc.getBlockZ(), newLoc.getBlockZ());
if (NmsVersion.v1_14.isSupported()) {
StructureModifier<Short> shorts = movePacket.getShorts();
shorts.write(0, (short) x);
shorts.write(1, (short) y);
shorts.write(2, (short) z);
} else {
StructureModifier<Integer> ints = movePacket.getIntegers();
ints.write(0, x);
ints.write(1, y);
ints.write(2, z);
}
}
}
packets.addPacket(movePacket);
return;
} else if (disguise.getType() == DisguiseType.RABBIT &&
(sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE ||
sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)) {
(sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE || sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)) {
// When did the rabbit disguise last hop
long lastHop = 999999;
@ -148,8 +173,7 @@ public class PacketHandlerMovement implements IPacketHandler {
if (lastHop < 100 || lastHop > 500) {
if (lastHop > 500) {
entity.removeMetadata("LibsRabbitHop", LibsDisguises.getInstance());
entity.setMetadata("LibsRabbitHop",
new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
entity.setMetadata("LibsRabbitHop", new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
}
PacketContainer statusPacket = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS);
@ -160,8 +184,7 @@ public class PacketHandlerMovement implements IPacketHandler {
}
}
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK &&
disguise.getType() == DisguiseType.WITHER_SKULL) {
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) {
// Stop wither skulls from looking
packets.clear();
} else {
@ -197,8 +220,7 @@ public class PacketHandlerMovement implements IPacketHandler {
bytes.write(0, yawValue);
bytes.write(1, pitchValue);
if (entity == observer.getVehicle() &&
AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
if (entity == observer.getVehicle() && AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
packet.getIntegers().write(0, DisguiseAPI.getEntityAttachmentId());
@ -206,8 +228,7 @@ public class PacketHandlerMovement implements IPacketHandler {
packet.getBytes().write(1, pitchValue);
packets.addPacket(packet);
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT &&
disguise.getType() == DisguiseType.ITEM_FRAME) {
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
StructureModifier<Double> doubles = movePacket.getDoubles();
Location loc = entity.getLocation();

View file

@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities.packets.packetlisteners;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -13,7 +12,6 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
/**

View file

@ -17,15 +17,18 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
import me.libraryaddict.disguise.utilities.sounds.SoundGroup.SoundType;
import org.bukkit.Location;
import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
public class PacketListenerSounds extends PacketAdapter {
/**
* This is a fix for the stupidity that is
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
* This is a fix for the stupidity that is "I can't separate the sounds from the sounds the player
* heard, and the sounds of the entity tracker heard"
*/
private static boolean cancelSound;
@ -38,247 +41,234 @@ public class PacketListenerSounds extends PacketAdapter {
if (event.isCancelled()) {
return;
}
if (event.isAsync()) {
return;
}
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
{
if (event.getPlayer().getName().contains("UNKNOWN[")) {
return;
}
event.setPacket(event.getPacket().deepClone());
StructureModifier<Object> mods = event.getPacket().getModifier();
if (event.getPacketType() == Server.ENTITY_STATUS) {
handleEntityStatus(event);
} else if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
handleNamedSoundEffect(event);
}
}
private void handleNamedSoundEffect(PacketEvent event) {
StructureModifier<Object> mods = event.getPacket().getModifier();
Player observer = event.getPlayer();
if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
SoundType soundType = null;
SoundType soundType = null;
Entity disguisedEntity = null;
SoundGroup entitySound = null;
Object soundEffectObj = mods.read(0);
Entity disguisedEntity = null;
SoundGroup soundGroup = null;
Object soundEffectObj = mods.read(0);
Disguise disguise = null;
Disguise disguise = null;
int[] soundCords = new int[]{(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)};
int[] soundCords = new int[]{(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)};
loop:
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
for (TargetedDisguise entityDisguise : disguises) {
Entity entity = entityDisguise.getEntity();
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
for (TargetedDisguise entityDisguise : disguises) {
Entity entity = entityDisguise.getEntity();
if (entity == null || entity.getWorld() != observer.getWorld()) {
continue;
}
if (!entityDisguise.canSee(observer)) {
continue;
}
Location loc = entity.getLocation();
int[] entCords = new int[]{(int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8)};
if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2]) {
continue;
}
entitySound = SoundGroup.getGroup(entity.getType().name());
if (entitySound == null) {
continue;
}
if ((!(entity instanceof LivingEntity)) || ((LivingEntity) entity).getHealth() > 0) {
boolean hasInvun = ReflectionManager.hasInvul(entity);
soundType = entitySound.getType(soundEffectObj, !hasInvun);
} else {
soundType = SoundType.DEATH;
}
if (soundType != null) {
disguise = entityDisguise;
disguisedEntity = entity;
break loop;
}
}
}
if (disguise != null && disguise.isSoundsReplaced() &&
(disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
Object sound = null;
SoundGroup disguiseSound = SoundGroup.getGroup(disguise);
if (disguiseSound != null) {
sound = disguiseSound.getSound(soundType);
if (entity == null || entity.getWorld() != observer.getWorld()) {
continue;
}
if (sound == null) {
event.setCancelled(true);
} else {
Enum soundCat = ReflectionManager.getSoundCategory(disguise.getType());
float volume = (float) mods.read(5);
float pitch = (float) mods.read(6);
// Time to change the pitch and volume
if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE) {
// If the volume is the default
if (volume == entitySound.getDamageAndIdleSoundVolume()) {
volume = disguiseSound.getDamageAndIdleSoundVolume();
}
// Here I assume its the default pitch as I can't calculate if its real.
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity &&
((MobDisguise) disguise).doesDisguiseAge()) {
boolean baby = false;
if (disguisedEntity instanceof Zombie) {
baby = ((Zombie) disguisedEntity).isBaby();
} else if (disguisedEntity instanceof Ageable) {
baby = !((Ageable) disguisedEntity).isAdult();
}
if (((MobDisguise) disguise).isAdult() == baby) {
if (baby) {
// If the pitch is not the expected
if (pitch < 1.5 || pitch > 1.7) {
return;
}
pitch = (DisguiseUtilities.random.nextFloat() -
DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
} else {
// If the pitch is not the expected
if (pitch < 1 || pitch > 1.2) {
return;
}
pitch = (DisguiseUtilities.random.nextFloat() -
DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
}
}
}
if (sound.getClass().getSimpleName().equals("MinecraftKey")) {
PacketContainer newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT);
StructureModifier<Object> newModifs = newPacket.getModifier();
newModifs.write(0, sound);
newModifs.write(1, soundCat);
newModifs.write(2, mods.read(2));
newModifs.write(3, mods.read(3));
newModifs.write(4, mods.read(4));
newModifs.write(5, volume);
newModifs.write(6, pitch);
event.setPacket(newPacket);
} else {
mods.write(0, sound);
mods.write(1, soundCat);
mods.write(5, volume);
mods.write(6, pitch);
}
}
if (!entityDisguise.canSee(observer)) {
continue;
}
}
} else if (event.getPacketType() == Server.ENTITY_STATUS) {
if ((byte) mods.read(1) != 2) {
return;
}
// It made a damage animation
Disguise disguise = DisguiseUtilities.getDisguise(observer, event.getPacket().getIntegers().read(0));
Location loc = entity.getLocation();
if (disguise == null) {
return;
}
int[] entCords = new int[]{(int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8)};
Entity entity = disguise.getEntity();
if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2]) {
continue;
}
if (!disguise.getType().isPlayer() &&
(disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
SoundGroup disSound = SoundGroup.getGroup(entity.getType().name());
disguise = entityDisguise;
disguisedEntity = entity;
soundGroup = SoundGroup.getGroup(entity.getType().name());
if (disSound == null) {
if (soundGroup.getSound(soundEffectObj) == null) {
return;
}
SoundType soundType = SoundType.HURT;
Object obj = null;
if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) {
if ((!(entity instanceof LivingEntity)) || ((LivingEntity) entity).getHealth() > 0) {
boolean hasInvun = ReflectionManager.hasInvul(entity);
soundType = soundGroup.getType(soundEffectObj, !hasInvun);
} else {
soundType = SoundType.DEATH;
}
}
if (disguise != null) {
break;
}
}
if (disSound.getSound(soundType) == null ||
(disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) {
if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) {
cancelSound = !cancelSound;
if (disguise == null || !disguise.isSoundsReplaced()) {
return;
}
if (cancelSound) {
return;
}
// Blocks null and CANCEL, HURT and DEATH are 100% handled by entity status!
if (soundType != SoundType.STEP && soundType != SoundType.IDLE) {
event.setCancelled(true);
return;
}
if (disguisedEntity == observer && !disguise.isSelfDisguiseSoundsReplaced()) {
return;
}
Object sound = null;
SoundGroup disguiseSound = SoundGroup.getGroup(disguise);
if (disguiseSound != null) {
sound = disguiseSound.getSound(soundType);
}
if (sound == null) {
event.setCancelled(true);
return;
}
Enum soundCat = ReflectionManager.getSoundCategory(disguise.getType());
float volume = (float) mods.read(5);
float pitch = (float) mods.read(6);
// If the volume is the default
if (volume == soundGroup.getDamageAndIdleSoundVolume()) {
volume = disguiseSound.getDamageAndIdleSoundVolume();
}
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity && ((MobDisguise) disguise).doesDisguiseAge()) {
if (((MobDisguise) disguise).isAdult()) {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
} else {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.4F;
}
}
if (sound.getClass().getSimpleName().equals("MinecraftKey")) {
PacketContainer newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT);
StructureModifier<Object> newModifs = newPacket.getModifier();
newModifs.write(0, sound);
newModifs.write(1, soundCat);
newModifs.write(2, mods.read(2));
newModifs.write(3, mods.read(3));
newModifs.write(4, mods.read(4));
newModifs.write(5, volume);
newModifs.write(6, pitch);
event.setPacket(newPacket);
} else {
mods.write(0, sound);
mods.write(1, soundCat);
mods.write(5, volume);
mods.write(6, pitch);
}
}
private void handleEntityStatus(PacketEvent event) {
StructureModifier<Object> mods = event.getPacket().getModifier();
Player observer = event.getPlayer();
if ((byte) mods.read(1) != 2) {
return;
}
// It made a damage animation
Disguise disguise = DisguiseUtilities.getDisguise(observer, event.getPacket().getIntegers().read(0));
if (disguise == null) {
return;
}
Entity entity = disguise.getEntity();
if (disguise instanceof TargetedDisguise) {
Set<TargetedDisguise> discs = DisguiseUtilities.getDisguises().get(entity.getEntityId());
for (TargetedDisguise targetedDisguise : discs) {
if (targetedDisguise != disguise) {
continue;
}
if (!targetedDisguise.canSee(observer)) {
return;
}
}
}
SoundType soundType = SoundType.HURT;
if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) {
soundType = SoundType.DEATH;
}
if (entity == event.getPlayer() && !disguise.getType().isPlayer()) {
if (!disguise.isSelfDisguiseSoundsReplaced()) {
cancelSound = !cancelSound;
if (cancelSound) {
return;
}
}
}
SoundGroup disSound = SoundGroup.getGroup(entity.getType().name());
if (disSound == null) {
return;
}
if (disSound.getSound(soundType) != null) {
disSound = SoundGroup.getGroup(disguise);
if (disSound != null) {
Object sound = disSound.getSound(soundType);
if (sound != null) {
Location loc = entity.getLocation();
PacketContainer packet = new PacketContainer(
sound.getClass().getSimpleName().equals("MinecraftKey") ? Server.CUSTOM_SOUND_EFFECT : Server.NAMED_SOUND_EFFECT);
mods = packet.getModifier();
mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh
mods.write(2, (int) (loc.getX() * 8D));
mods.write(3, (int) (loc.getY() * 8D));
mods.write(4, (int) (loc.getZ() * 8D));
mods.write(5, disSound.getDamageAndIdleSoundVolume());
float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.4F;
} else {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
}
disSound = SoundGroup.getGroup(disguise);
if (disguise.getType() == DisguiseType.BAT) {
pitch *= 0.95F;
}
if (disSound != null) {
Object sound = disSound.getSound(soundType);
mods.write(6, pitch);
if (sound != null) {
Location loc = entity.getLocation();
PacketContainer packet = new PacketContainer(
sound.getClass().getSimpleName().equals("MinecraftKey") ?
Server.CUSTOM_SOUND_EFFECT : Server.NAMED_SOUND_EFFECT);
mods = packet.getModifier();
mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh
mods.write(2, (int) (loc.getX() * 8D));
mods.write(3, (int) (loc.getY() * 8D));
mods.write(4, (int) (loc.getZ() * 8D));
mods.write(5, disSound.getDamageAndIdleSoundVolume());
float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) *
0.2F + 1.5F;
} else {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) *
0.2F + 1.0F;
}
if (disguise.getType() == DisguiseType.BAT) {
pitch *= 0.95F;
}
/* pitch *= 63;
if (pitch < 0)
pitch = 0;
if (pitch > 255)
pitch = 255;*/
mods.write(6, pitch);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
event.setCancelled(true);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
}
}

View file

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities.params;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock;
@ -50,6 +51,11 @@ public class ParamInfoManager {
return getParamInfoSoundGroup();
}
// Enderman can't hold non-blocks
if (method.getWatcherClass() == EndermanWatcher.class && method.getName().equalsIgnoreCase("setItemInMainHand")) {
return getParamInfoItemBlock();
}
if (method.getWatcherClass() == FallingBlockWatcher.class && (method.getParam() == Material.class || method.getParam() == ItemStack.class)) {
return getParamInfoItemBlock();
}
@ -58,6 +64,10 @@ public class ParamInfoManager {
}
public static ParamInfo getParamInfo(Class c) {
if (c.isAnonymousClass()) {
c = c.getSuperclass();
}
for (ParamInfo info : getParamInfos()) {
if (!info.isParam(c)) {
continue;
@ -96,12 +106,20 @@ public class ParamInfoManager {
}
public static WatcherMethod[] getDisguiseWatcherMethods(@Nullable Class<? extends FlagWatcher> watcherClass) {
return getDisguiseWatcherMethods(watcherClass, false);
}
public static WatcherMethod[] getDisguiseWatcherMethods(@Nullable Class<? extends FlagWatcher> watcherClass, boolean includeIgnored) {
if (watcherClass == null) {
return new WatcherMethod[0];
}
ArrayList<WatcherMethod> methods = new ArrayList<>(disguiseMethods.getMethods(watcherClass));
if (!includeIgnored) {
methods.removeIf(WatcherMethod::isHideFromTab);
}
// 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) -> {
@ -115,8 +133,6 @@ public class ParamInfoManager {
return String.CASE_INSENSITIVE_ORDER.compare(m1.getName(), m2.getName());
});
return methods.toArray(new WatcherMethod[0]);
}

View file

@ -31,8 +31,7 @@ import java.util.*;
*/
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());
return new ParamInfoItemBlock(ItemStack.class, "ItemStack", "ItemStack (Material)", "An ItemStack compromised of Material", getMaterials());
}
public ParamInfoSoundGroup getParamInfoSoundGroup() {
@ -96,6 +95,10 @@ public class ParamInfoTypes {
paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type"));
paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant",
"The different variants for mushroom cows"));
if (NmsVersion.v1_17.isSupported()) {
paramInfos.add(new ParamInfoEnum(Axolotl.Variant.class, "Axolotl Variant", "The variant of Axolotl"));
}
} else {
paramInfos.add(new ParamInfoEnum(Ocelot.Type.class, "Ocelot Type", "The type of ocelot"));
}
@ -129,7 +132,7 @@ public class ParamInfoTypes {
"Set how long the disguise lasts, <Num><Time><Num>... where <Time> is (s/sec)(m/min)(h/hour)(d/day) " +
"etc. 30m20secs = 30 minutes, 20 seconds"));
paramInfos.add(new ParamInfoEnum(ChatColor.class, "ChatColor", "A chat color"));
paramInfos.add(new ParamInfoChatColor(ChatColor.class, "ChatColor", "A chat color"));
paramInfos.add(new ParamInfoEnum(GolemCrack.class, "Golem Cracked", "The stage a golem has been cracked"));
// Register base types

View file

@ -0,0 +1,17 @@
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
/**
* Created by libraryaddict on 1/08/2021.
*/
public class ParamInfoChatColor extends ParamInfoEnum {
public ParamInfoChatColor(Class<? extends Enum> paramClass, String name, String description) {
super(paramClass, name, description);
}
@Override
public String toString(Object object) {
return ((Enum) object).name();
}
}

View file

@ -64,7 +64,7 @@ public class DisguiseParser {
FlagWatcher watcher = type.getWatcherClass().getConstructor(Disguise.class).newInstance(disguise);
WatcherMethod[] methods = ParamInfoManager.getDisguiseWatcherMethods(watcher.getClass());
WatcherMethod[] methods = ParamInfoManager.getDisguiseWatcherMethods(watcher.getClass(), true);
for (WatcherMethod setMethod : methods) {
// Invalidate methods that can't be handled normally
@ -939,7 +939,7 @@ public class DisguiseParser {
public static void callMethods(CommandSender sender, Disguise disguise, DisguisePermissions disguisePermission, DisguisePerm disguisePerm,
Collection<String> usedOptions, String[] args, String permNode) throws Throwable {
WatcherMethod[] methods = ParamInfoManager.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
WatcherMethod[] methods = ParamInfoManager.getDisguiseWatcherMethods(disguise.getWatcher().getClass(), true);
List<String> list = new ArrayList<>(Arrays.asList(args));
HashMap<String, HashMap<String, Boolean>> disguiseOptions = getDisguiseOptions(sender, permNode, disguisePerm);

View file

@ -18,10 +18,11 @@ public class WatcherMethod {
private final Class returnType;
private final Class param;
private final boolean randomDefault;
private final boolean hideFromTab;
@Override
public String toString() {
return "WatcherMethod{" + "watcherClass=" + watcherClass + ", method=" + method + ", name='" + name + '\'' + ", returnType=" + returnType + ", param=" +
param + ", randomDefault=" + randomDefault + '}';
param + ", randomDefault=" + randomDefault + ", hideFromTab=" + hideFromTab + '}';
}
}

View file

@ -879,7 +879,7 @@ public class ReflectionManager {
bb.put(6, (byte) (bb.get(6) & 0x0f)); // clear version
bb.put(6, (byte) (bb.get(6) | DisguiseConfig.getUUIDGeneratedVersion())); // set to version X (Default 4)
bb.position(0);
bb.rewind();
long firstLong = bb.getLong();
long secondLong = bb.getLong();

View file

@ -316,16 +316,15 @@ public enum LibsMsg {
return string;
}
public BaseComponent[] getChat(Object... strings) {
String string = get(strings);
return DisguiseUtilities.getColoredChat(string);
}
public void send(CommandSender player, Object... strings) {
DisguiseUtilities.sendMessage(player, this, strings);
}
@Deprecated
public BaseComponent[] getBase(Object... strings) {
return DisguiseUtilities.getColoredChat(get(strings));
}
@Deprecated
public String get(Object... strings) {
int matches = StringUtils.countMatches(getRaw(), "%s");

View file

@ -59,7 +59,7 @@ public class TranslateFiller {
continue;
}
for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(type.getWatcherClass())) {
for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(type.getWatcherClass(), true)) {
Class para = method.getParam();
String className = method.getWatcherClass().getSimpleName().replace("Watcher", "");

View file

@ -84,7 +84,7 @@ public class DisguiseMethods {
continue;
}
if (info.isDeprecated() && info.getRemoved() < 0) {
if (info.isDeprecated() && info.getAdded() != 0 && info.getRemoved() < 0) {
continue;
}
@ -103,7 +103,7 @@ public class DisguiseMethods {
MethodHandle method = MethodHandles.publicLookup().findVirtual(watcher, info.getMethod(), type);
WatcherMethod m = new WatcherMethod(watcher, method, info.getMethod(), returnType, param, info.isRandomDefault());
WatcherMethod m = new WatcherMethod(watcher, method, info.getMethod(), returnType, param, info.isRandomDefault(), info.isDeprecated() && info.getAdded() ==0);
methods.add(m);
@ -155,7 +155,7 @@ public class DisguiseMethods {
try {
WatcherMethod method = new WatcherMethod(disguiseClass,
MethodHandles.publicLookup().findVirtual(disguiseClass, methodName, MethodType.methodType(returnType, cl)), methodName,
null, cl, randomDefault);
null, cl, randomDefault, false);
methods.add(method);
@ -166,7 +166,7 @@ public class DisguiseMethods {
WatcherMethod getMethod = new WatcherMethod(disguiseClass,
MethodHandles.publicLookup().findVirtual(disguiseClass, getName, MethodType.methodType(cl)), getName, cl, null,
randomDefault);
randomDefault, false);
methods.add(getMethod);
break;

View file

@ -1,7 +1,6 @@
# This config is called sanity, because you shouldn't need to change the stuff in here
# Stop shulker disguises from moving, they're weird. This option only effects PLAYERS that are disguised, other entities disguised as shulkers will NOT be effected!
# This is ignored in 1.17+ as its fixed in those versions
#Stop shulker disguises from moving, they're weird. This option only effects PLAYERS that are disguised, other entities disguised as shulkers will NOT be effected!
StopShulkerDisguisesFromMoving: true
# This means that the plugin doesn't need to constantly call Mojang just to find a skin for an offline player

View file

@ -25,7 +25,7 @@ commands:
permission: libsdisguises.seecmd.disguisehelp
description: Help command for LibsDisguises.
undisguise:
aliases: [u, und, undis, undisg]
aliases: [und, undis, undisg]
permission: libsdisguises.seecmd.undisguise
description: Undisguise yourself.
undisguiseentity: