Skip to content

Commit

Permalink
more unnecessary-packet-intercept-reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 12, 2021
1 parent 379a8da commit 58be864
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,9 @@ public static DenizenEntityType getByEntity(Entity entity) {
public boolean isCustom() {
return customEntityType != null;
}

@Override
public String toString() {
return getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public void receiveDigPacket(final Player player) {
}
}

public boolean shouldInterceptChatPacket() {
return !ExecuteCommand.silencedPlayers.isEmpty() || PlayerReceivesMessageScriptEvent.instance.loaded;
}

public boolean sendPacket(final Player player, final PacketOutChat chat) {
if (ExecuteCommand.silencedPlayers.contains(player.getUniqueId())) {
return true;
Expand Down Expand Up @@ -136,6 +140,10 @@ public Boolean call() throws Exception {
return false;
}

public boolean shouldInterceptMetadata() {
return !GlowCommand.glowViewers.isEmpty();
}

public boolean sendPacket(Player player, PacketOutEntityMetadata entityMetadata) {
HashSet<UUID> players = GlowCommand.glowViewers.get(entityMetadata.getEntityId());
return players != null && entityMetadata.checkForGlow() && !players.contains(player.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ public PacketPlayOutEntityMetadata getModifiedMetadataFor(PacketPlayOutEntityMet
int watcherId = watcherObject.a();
if (watcherId == 2) { // 2: Custom name metadata
Optional<IChatBaseComponent> name = Optional.of(Handler.componentToNMS(FormattedTextHelper.parse(nameToApply, ChatColor.WHITE)));
data.set(i, new DataWatcher.Item(item.a(), name));
data.set(i, new DataWatcher.Item(watcherObject, name));
any = true;
}
else if (watcherId == 3) { // 3: custom name visible metadata
data.set(i, new DataWatcher.Item(item.a(), true));
data.set(i, new DataWatcher.Item(watcherObject, true));
any = true;
}
}
Expand Down Expand Up @@ -590,16 +590,19 @@ public boolean processMirrorForPacket(Packet<?> packet) {
}

public boolean processPacketHandlerForPacket(Packet<?> packet) {
if (packet instanceof PacketPlayOutChat) {
if (packet instanceof PacketPlayOutChat && packetHandler.shouldInterceptChatPacket()) {
return packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutChatImpl((PacketPlayOutChat) packet));
}
else if (packet instanceof PacketPlayOutEntityMetadata) {
else if (packet instanceof PacketPlayOutEntityMetadata && packetHandler.shouldInterceptMetadata()) {
return packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutEntityMetadataImpl((PacketPlayOutEntityMetadata) packet));
}
return false;
}

public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (FakeBlock.blocks.isEmpty()) {
return false;
}
try {
if (packet instanceof PacketPlayOutMapChunk) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUniqueID());
Expand Down

0 comments on commit 58be864

Please sign in to comment.