Update for 1.17.1, bumped required PL version

This commit is contained in:
libraryaddict 2021-07-09 16:01:38 +12:00
parent c1afce7378
commit 5eaf7faa1b
3 changed files with 38 additions and 65 deletions

View File

@ -741,12 +741,11 @@ public abstract class Disguise {
if (getInternalArmorstandIds().length > 0) { if (getInternalArmorstandIds().length > 0) {
try { try {
for (PacketContainer packet : DisguiseUtilities.getDestroyPackets(getInternalArmorstandIds())) { PacketContainer packet = DisguiseUtilities.getDestroyPacket(getInternalArmorstandIds());
for (Player player : getEntity().getWorld().getPlayers()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
}
}
for (Player player : getEntity().getWorld().getPlayers()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
}
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -479,7 +479,7 @@ public class DisguiseUtilities {
} }
// If we are on 1.17, future release build or this dev build // If we are on 1.17, future release build or this dev build
return new String[]{"4.7.1", "521"}; return new String[]{"4.7.1", "528"};
} }
public static boolean isProtocolLibOutdated() { public static boolean isProtocolLibOutdated() {
@ -1097,14 +1097,16 @@ public class DisguiseUtilities {
} }
public static PacketContainer getDestroyPacket(int... ids) { public static PacketContainer getDestroyPacket(int... ids) {
if (NmsVersion.v1_17.isSupported() && ids.length != 1) {
throw new IllegalStateException("Should use getDestroyPackets for ints of len " + ids.length);
}
PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY);
if (NmsVersion.v1_17.isSupported()) { if (NmsVersion.v1_17.isSupported()) {
destroyPacket.getIntegers().write(0, ids[0]); List<Integer> ints = new ArrayList<>();
for (int id : ids) {
ints.add(id);
}
destroyPacket.getIntLists().write(0, ints);
} else { } else {
destroyPacket.getIntegerArrays().write(0, ids); destroyPacket.getIntegerArrays().write(0, ids);
} }
@ -1112,22 +1114,6 @@ public class DisguiseUtilities {
return destroyPacket; return destroyPacket;
} }
public static PacketContainer[] getDestroyPackets(int... ids) {
if (!NmsVersion.v1_17.isSupported()) {
return new PacketContainer[]{getDestroyPacket(ids)};
}
PacketContainer[] packets = new PacketContainer[ids.length];
for (int i = 0; i < packets.length; i++) {
packets[i] = new PacketContainer(Server.ENTITY_DESTROY);
packets[i].getIntegers().write(0, ids[i]);
}
return packets;
}
public static TargetedDisguise getDisguise(Player observer, Entity entity) { public static TargetedDisguise getDisguise(Player observer, Entity entity) {
int entityId = entity.getEntityId(); int entityId = entity.getEntityId();
@ -1837,12 +1823,10 @@ public class DisguiseUtilities {
ids[ids.length - 1] = DisguiseAPI.getSelfDisguiseId(); ids[ids.length - 1] = DisguiseAPI.getSelfDisguiseId();
// Send a packet to destroy the fake entity // Send a packet to destroy the fake entity
for (PacketContainer packet : getDestroyPackets(ids)) { try {
try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, getDestroyPacket(ids));
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } catch (Exception ex) {
} catch (Exception ex) { ex.printStackTrace();
ex.printStackTrace();
}
} }
// player.spigot().setCollidesWithEntities(true); // player.spigot().setCollidesWithEntities(true);
@ -3051,9 +3035,7 @@ public class DisguiseUtilities {
} }
if (destroyIds.length > 0) { if (destroyIds.length > 0) {
for (PacketContainer packet : getDestroyPackets(destroyIds)) { packets.add(getDestroyPacket(destroyIds));
packets.add(packet);
}
} }
return packets; return packets;

View File

@ -14,6 +14,7 @@ import org.bukkit.plugin.Plugin;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* Created by libraryaddict on 3/05/2020. * Created by libraryaddict on 3/05/2020.
@ -30,22 +31,19 @@ public class PacketListenerEntityDestroy extends PacketAdapter {
} }
if (!NmsVersion.v1_17.isSupported()) { if (!NmsVersion.v1_17.isSupported()) {
onPre17Packet(event); int[] entityIds = event.getPacket().getIntegerArrays().read(0);
return;
}
int[] toAdd = getToRemove(event.getPlayer(), event.getPacket().getIntegers().read(0)); for (int entityId : entityIds) {
handleEntityId(event.getPlayer(), entityId);
if (toAdd == null) {
return;
}
try {
for (PacketContainer container : DisguiseUtilities.getDestroyPackets(toAdd)) {
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), container);
} }
} catch (InvocationTargetException e) {
e.printStackTrace(); return;
}
List<Integer> entityIds = event.getPacket().getIntLists().read(0);
for (int entityId : entityIds) {
handleEntityId(event.getPlayer(), entityId);
} }
} }
@ -69,23 +67,17 @@ public class PacketListenerEntityDestroy extends PacketAdapter {
return disguise.getArmorstandIds(); return disguise.getArmorstandIds();
} }
public void onPre17Packet(PacketEvent event) { private void handleEntityId(Player player, int entityId) {
int[] entityIds = event.getPacket().getIntegerArrays().read(0); int[] toRemove = getToRemove(player, entityId);
for (int entityId : entityIds) { if (toRemove == null) {
int[] toRemove = getToRemove(event.getPlayer(), entityId); return;
}
if (toRemove == null) { try {
continue; ProtocolLibrary.getProtocolManager().sendServerPacket(player, DisguiseUtilities.getDestroyPacket(toRemove));
} } catch (InvocationTargetException e) {
e.printStackTrace();
try {
for (PacketContainer container : DisguiseUtilities.getDestroyPackets(toRemove)) {
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), container);
}
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} }
} }
} }