Rename method setRightClicking

This commit is contained in:
libraryaddict 2021-09-11 02:33:01 +12:00
parent 3e6e4b3932
commit d35f6cd5d4
9 changed files with 55 additions and 21 deletions

View File

@ -150,7 +150,7 @@ public class DisguiseAPI {
watcher.setSwimming(watcher.isSwimming() && displayExtraAnimations);
if (!NmsVersion.v1_13.isSupported()) {
watcher.setRightClicking(watcher.isRightClicking() && displayExtraAnimations);
watcher.setRightHandRaised(watcher.isRightHandRaised() && displayExtraAnimations);
}
if (!displayExtraAnimations) {
@ -162,8 +162,8 @@ public class DisguiseAPI {
} else if (index == MetaIndex.LIVING_META && NmsVersion.v1_13.isSupported()) {
LivingWatcher livingWatcher = (LivingWatcher) watcher;
livingWatcher.setRightClicking(livingWatcher.isRightClicking() && displayExtraAnimations);
livingWatcher.setLeftClicking(livingWatcher.isLeftClicking() && displayExtraAnimations);
livingWatcher.setRightHandRaised(livingWatcher.isRightHandRaised() && displayExtraAnimations);
livingWatcher.setLeftHandRaised(livingWatcher.isLeftHandRaised() && displayExtraAnimations);
livingWatcher.setSpinning(livingWatcher.isSpinning() && displayExtraAnimations);
if (!displayExtraAnimations) {

View File

@ -20,6 +20,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import net.md_5.bungee.api.chat.BaseComponent;
@ -760,13 +761,25 @@ public class FlagWatcher {
sendData(MetaIndex.ENTITY_NO_GRAVITY);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() {
return isRightHandRaised();
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) {
setRightHandRaised(rightClicking);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
public boolean isRightHandRaised() {
return !NmsVersion.v1_13.isSupported() && getEntityFlag(4);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
public void setRightClicking(boolean setRightClicking) {
public void setRightHandRaised(boolean setRightClicking) {
if (NmsVersion.v1_13.isSupported()) {
return;
}

View File

@ -111,25 +111,27 @@ public class LivingWatcher extends FlagWatcher {
setHandFlag(1, rightHand);
}
@Override
@NmsAddedIn(NmsVersion.v1_13)
public boolean isRightClicking() {
public boolean isRightHandRaised() {
return isRightHandInUse() && getHandFlag(0);
}
@Override
@NmsAddedIn(NmsVersion.v1_13)
public void setRightClicking(boolean setRightClicking) {
public void setRightHandRaised(boolean setRightClicking) {
setHandInUse(true);
setHandFlag(0, setRightClicking);
}
@NmsAddedIn(NmsVersion.v1_13)
public boolean isLeftClicking() {
public boolean isLeftHandRaised() {
return !isRightHandInUse() && getHandFlag(0);
}
@NmsAddedIn(NmsVersion.v1_13)
public void setLeftClicking(boolean setLeftClicking) {
public void setLeftHandRaised(boolean setLeftClicking) {
setHandInUse(false);
setHandFlag(0, setLeftClicking);
@ -308,4 +310,16 @@ public class LivingWatcher extends FlagWatcher {
return originalValue;
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() {
return isRightHandRaised();
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) {
setRightHandRaised(rightClicking);
}
}

View File

@ -81,7 +81,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
itemStack = ReflectionManager.getBukkitItem(pair.getSecond());
}
if ((disguise.getWatcher().isRightClicking() || (disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isLeftClicking())) && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
if ((disguise.getWatcher().isRightHandRaised() || (disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isLeftHandRaised())) && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
if (itemStack != null && itemStack.getType() != Material.AIR) {
// Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<>();
@ -152,7 +152,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
}
if ((disguise.getWatcher().isRightClicking() || (disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isLeftClicking())) && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
if ((disguise.getWatcher().isRightHandRaised() || (disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isLeftHandRaised())) && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
if (itemStack == null) {
itemStack = packets.getPackets().get(0).getItemModifier().read(0);
}

View File

@ -106,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) -> {
@ -125,8 +133,6 @@ public class ParamInfoManager {
return String.CASE_INSENSITIVE_ORDER.compare(m1.getName(), m2.getName());
});
return methods.toArray(new WatcherMethod[0]);
}

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

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