Rename methods again, fix a equipment not blocking properly

This commit is contained in:
libraryaddict 2021-09-11 02:43:42 +12:00
parent d35f6cd5d4
commit f1b7cbf444
4 changed files with 28 additions and 25 deletions

View File

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

View File

@ -20,7 +20,6 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; 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.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
@ -764,22 +763,22 @@ public class FlagWatcher {
@Deprecated @Deprecated
@NmsAddedIn(NmsVersion.v1_12) @NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() { public boolean isRightClicking() {
return isRightHandRaised(); return isMainHandRaised();
} }
@Deprecated @Deprecated
@NmsAddedIn(NmsVersion.v1_12) @NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) { public void setRightClicking(boolean rightClicking) {
setRightHandRaised(rightClicking); setMainHandRaised(rightClicking);
} }
//@NmsRemovedIn(val = NmsVersion.v1_13) //@NmsRemovedIn(val = NmsVersion.v1_13)
public boolean isRightHandRaised() { public boolean isMainHandRaised() {
return !NmsVersion.v1_13.isSupported() && getEntityFlag(4); return !NmsVersion.v1_13.isSupported() && getEntityFlag(4);
} }
//@NmsRemovedIn(val = NmsVersion.v1_13) //@NmsRemovedIn(val = NmsVersion.v1_13)
public void setRightHandRaised(boolean setRightClicking) { public void setMainHandRaised(boolean setRightClicking) {
if (NmsVersion.v1_13.isSupported()) { if (NmsVersion.v1_13.isSupported()) {
return; return;
} }

View File

@ -99,39 +99,39 @@ public class LivingWatcher extends FlagWatcher {
sendData(MetaIndex.LIVING_META); sendData(MetaIndex.LIVING_META);
} }
private boolean isRightHandInUse() { private boolean isMainHandUsed() {
return getHandFlag(1); return !getHandFlag(1);
} }
private void setHandInUse(boolean rightHand) { private void setHandInUse(boolean mainHand) {
if (isRightHandInUse() == rightHand) { if (isMainHandUsed() == mainHand) {
return; return;
} }
setHandFlag(1, rightHand); setHandFlag(1, !mainHand);
} }
@Override @Override
@NmsAddedIn(NmsVersion.v1_13) @NmsAddedIn(NmsVersion.v1_13)
public boolean isRightHandRaised() { public boolean isMainHandRaised() {
return isRightHandInUse() && getHandFlag(0); return isMainHandUsed() && getHandFlag(0);
} }
@Override @Override
@NmsAddedIn(NmsVersion.v1_13) @NmsAddedIn(NmsVersion.v1_13)
public void setRightHandRaised(boolean setRightClicking) { public void setMainHandRaised(boolean setRightClicking) {
setHandInUse(true); setHandInUse(true);
setHandFlag(0, setRightClicking); setHandFlag(0, setRightClicking);
} }
@NmsAddedIn(NmsVersion.v1_13) @NmsAddedIn(NmsVersion.v1_13)
public boolean isLeftHandRaised() { public boolean isOffhandRaised() {
return !isRightHandInUse() && getHandFlag(0); return !isMainHandUsed() && getHandFlag(0);
} }
@NmsAddedIn(NmsVersion.v1_13) @NmsAddedIn(NmsVersion.v1_13)
public void setLeftHandRaised(boolean setLeftClicking) { public void setOffhandRaised(boolean setLeftClicking) {
setHandInUse(false); setHandInUse(false);
setHandFlag(0, setLeftClicking); setHandFlag(0, setLeftClicking);
@ -314,12 +314,12 @@ public class LivingWatcher extends FlagWatcher {
@Deprecated @Deprecated
@NmsAddedIn(NmsVersion.v1_12) @NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() { public boolean isRightClicking() {
return isRightHandRaised(); return isMainHandRaised();
} }
@Deprecated @Deprecated
@NmsAddedIn(NmsVersion.v1_12) @NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) { public void setRightClicking(boolean rightClicking) {
setRightHandRaised(rightClicking); setMainHandRaised(rightClicking);
} }
} }

View File

@ -81,14 +81,16 @@ public class PacketHandlerEquipment implements IPacketHandler {
itemStack = ReflectionManager.getBukkitItem(pair.getSecond()); itemStack = ReflectionManager.getBukkitItem(pair.getSecond());
} }
if ((disguise.getWatcher().isRightHandRaised() || (disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isLeftHandRaised())) && (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) { if (itemStack != null && itemStack.getType() != Material.AIR) {
// Convert the datawatcher // Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<>(); List<WrappedWatchableObject> list = new ArrayList<>();
if (DisguiseConfig.isMetaPacketsEnabled()) { if (DisguiseConfig.isMetaPacketsEnabled()) {
WrappedWatchableObject watch = ReflectionManager WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.LIVING_META,
.createWatchable(MetaIndex.LIVING_META, WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex())); WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex()));
if (watch != null) { if (watch != null) {
list.add(watch); list.add(watch);
@ -152,7 +154,9 @@ public class PacketHandlerEquipment implements IPacketHandler {
equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack)); equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
} }
if ((disguise.getWatcher().isRightHandRaised() || (disguise.getWatcher() instanceof LivingWatcher && ((LivingWatcher) disguise.getWatcher()).isLeftHandRaised())) && (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) { if (itemStack == null) {
itemStack = packets.getPackets().get(0).getItemModifier().read(0); itemStack = packets.getPackets().get(0).getItemModifier().read(0);
} }