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);
if (!NmsVersion.v1_13.isSupported()) {
watcher.setRightHandRaised(watcher.isRightHandRaised() && displayExtraAnimations);
watcher.setMainHandRaised(watcher.isMainHandRaised() && 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.setRightHandRaised(livingWatcher.isRightHandRaised() && displayExtraAnimations);
livingWatcher.setLeftHandRaised(livingWatcher.isLeftHandRaised() && displayExtraAnimations);
livingWatcher.setMainHandRaised(livingWatcher.isMainHandRaised() && displayExtraAnimations);
livingWatcher.setOffhandRaised(livingWatcher.isOffhandRaised() && displayExtraAnimations);
livingWatcher.setSpinning(livingWatcher.isSpinning() && 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.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;
@ -764,22 +763,22 @@ public class FlagWatcher {
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() {
return isRightHandRaised();
return isMainHandRaised();
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public void setRightClicking(boolean rightClicking) {
setRightHandRaised(rightClicking);
setMainHandRaised(rightClicking);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
public boolean isRightHandRaised() {
public boolean isMainHandRaised() {
return !NmsVersion.v1_13.isSupported() && getEntityFlag(4);
}
//@NmsRemovedIn(val = NmsVersion.v1_13)
public void setRightHandRaised(boolean setRightClicking) {
public void setMainHandRaised(boolean setRightClicking) {
if (NmsVersion.v1_13.isSupported()) {
return;
}

View File

@ -99,39 +99,39 @@ public class LivingWatcher extends FlagWatcher {
sendData(MetaIndex.LIVING_META);
}
private boolean isRightHandInUse() {
return getHandFlag(1);
private boolean isMainHandUsed() {
return !getHandFlag(1);
}
private void setHandInUse(boolean rightHand) {
if (isRightHandInUse() == rightHand) {
private void setHandInUse(boolean mainHand) {
if (isMainHandUsed() == mainHand) {
return;
}
setHandFlag(1, rightHand);
setHandFlag(1, !mainHand);
}
@Override
@NmsAddedIn(NmsVersion.v1_13)
public boolean isRightHandRaised() {
return isRightHandInUse() && getHandFlag(0);
public boolean isMainHandRaised() {
return isMainHandUsed() && getHandFlag(0);
}
@Override
@NmsAddedIn(NmsVersion.v1_13)
public void setRightHandRaised(boolean setRightClicking) {
public void setMainHandRaised(boolean setRightClicking) {
setHandInUse(true);
setHandFlag(0, setRightClicking);
}
@NmsAddedIn(NmsVersion.v1_13)
public boolean isLeftHandRaised() {
return !isRightHandInUse() && getHandFlag(0);
public boolean isOffhandRaised() {
return !isMainHandUsed() && getHandFlag(0);
}
@NmsAddedIn(NmsVersion.v1_13)
public void setLeftHandRaised(boolean setLeftClicking) {
public void setOffhandRaised(boolean setLeftClicking) {
setHandInUse(false);
setHandFlag(0, setLeftClicking);
@ -314,12 +314,12 @@ public class LivingWatcher extends FlagWatcher {
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
public boolean isRightClicking() {
return isRightHandRaised();
return isMainHandRaised();
}
@Deprecated
@NmsAddedIn(NmsVersion.v1_12)
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());
}
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) {
// Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<>();
if (DisguiseConfig.isMetaPacketsEnabled()) {
WrappedWatchableObject watch = ReflectionManager
.createWatchable(MetaIndex.LIVING_META, WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex()));
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.LIVING_META,
WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex()));
if (watch != null) {
list.add(watch);
@ -152,7 +154,9 @@ public class PacketHandlerEquipment implements IPacketHandler {
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) {
itemStack = packets.getPackets().get(0).getItemModifier().read(0);
}