From 8fb49ae09595a6e0cdf96b11b272e6bb87866bf9 Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:14:07 +0200 Subject: [PATCH 1/8] packet fuckery --- .../queueplugin/EventCanceler.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 158132c..30a9ccd 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -40,6 +40,26 @@ public void onPacketReceiving(PacketEvent ev) { public void onPacketSending(PacketEvent ev) { if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; + if (ev.getPacketType() == PacketType.Play.Server.MAP_CHUNK) return; + if (ev.getPacketType() == PacketType.Play.Server.BLOCK_CHANGE) return; + if (ev.getPacketType() == PacketType.Play.Server.MULTI_BLOCK_CHANGE) return; + if (ev.getPacketType() == PacketType.Play.Server.LIGHT_UPDATE) return; + if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; + if (ev.getPacketType() == PacketType.Play.Server.SERVER_DIFFICULTY) return; + if (ev.getPacketType() == PacketType.Play.Server.ABILITIES) return; + if (ev.getPacketType() == PacketType.Play.Server.HELD_ITEM_SLOT) return; + if (ev.getPacketType() == PacketType.Play.Server.RECIPE_UPDATE) return; + if (ev.getPacketType() == PacketType.Play.Server.RECIPES) return; + if (ev.getPacketType() == PacketType.Play.Server.COMMANDS) return; + if (ev.getPacketType() == PacketType.Play.Server.TAGS) return; + if (ev.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) return; + if (ev.getPacketType() == PacketType.Play.Server.CUSTOM_PAYLOAD) return; + if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; + if (ev.getPacketType() == PacketType.Play.Server.SPAWN_POSITION) return; + if (ev.getPacketType() == PacketType.Play.Server.GAME_STATE_CHANGE) return; + if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; + if (ev.getPacketType() == PacketType.Play.Server.VIEW_CENTRE) return; + if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; ev.setCancelled(true); } From 7be066ac5482d3e17ef408648a22e3777078943e Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:15:29 +0200 Subject: [PATCH 2/8] less packets --- src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 30a9ccd..00fa88d 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -40,10 +40,6 @@ public void onPacketReceiving(PacketEvent ev) { public void onPacketSending(PacketEvent ev) { if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; - if (ev.getPacketType() == PacketType.Play.Server.MAP_CHUNK) return; - if (ev.getPacketType() == PacketType.Play.Server.BLOCK_CHANGE) return; - if (ev.getPacketType() == PacketType.Play.Server.MULTI_BLOCK_CHANGE) return; - if (ev.getPacketType() == PacketType.Play.Server.LIGHT_UPDATE) return; if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; if (ev.getPacketType() == PacketType.Play.Server.SERVER_DIFFICULTY) return; if (ev.getPacketType() == PacketType.Play.Server.ABILITIES) return; From d7039922027f5bdfa85f850600b80045d89e5587 Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:16:55 +0200 Subject: [PATCH 3/8] less packets --- .../java/org/cloudanarchy/queueplugin/EventCanceler.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 00fa88d..5ac2a1b 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -41,13 +41,6 @@ public void onPacketSending(PacketEvent ev) { if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; - if (ev.getPacketType() == PacketType.Play.Server.SERVER_DIFFICULTY) return; - if (ev.getPacketType() == PacketType.Play.Server.ABILITIES) return; - if (ev.getPacketType() == PacketType.Play.Server.HELD_ITEM_SLOT) return; - if (ev.getPacketType() == PacketType.Play.Server.RECIPE_UPDATE) return; - if (ev.getPacketType() == PacketType.Play.Server.RECIPES) return; - if (ev.getPacketType() == PacketType.Play.Server.COMMANDS) return; - if (ev.getPacketType() == PacketType.Play.Server.TAGS) return; if (ev.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) return; if (ev.getPacketType() == PacketType.Play.Server.CUSTOM_PAYLOAD) return; if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; From 2773200101e4b3d0a055bbf78707728bd4880e0a Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:20:29 +0200 Subject: [PATCH 4/8] less packets --- src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 5ac2a1b..703cbd6 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -41,13 +41,11 @@ public void onPacketSending(PacketEvent ev) { if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; - if (ev.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) return; if (ev.getPacketType() == PacketType.Play.Server.CUSTOM_PAYLOAD) return; if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; if (ev.getPacketType() == PacketType.Play.Server.SPAWN_POSITION) return; if (ev.getPacketType() == PacketType.Play.Server.GAME_STATE_CHANGE) return; - if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; - if (ev.getPacketType() == PacketType.Play.Server.VIEW_CENTRE) return; + //if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; // if we dont send this, player has default skin lol if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; ev.setCancelled(true); } From 47f71689a80be241909d878381f1cbbf986aaced Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:21:59 +0200 Subject: [PATCH 5/8] less packets --- src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 703cbd6..ddd959b 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -41,9 +41,7 @@ public void onPacketSending(PacketEvent ev) { if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; - if (ev.getPacketType() == PacketType.Play.Server.CUSTOM_PAYLOAD) return; - if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; - if (ev.getPacketType() == PacketType.Play.Server.SPAWN_POSITION) return; + if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; // this is needed or client will not join if (ev.getPacketType() == PacketType.Play.Server.GAME_STATE_CHANGE) return; //if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; // if we dont send this, player has default skin lol if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; From 7a69b708c2bfeee76c6b2ea2efdb06e6f21d21e6 Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:22:41 +0200 Subject: [PATCH 6/8] less packets --- src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index ddd959b..42b8ca2 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -42,7 +42,6 @@ public void onPacketSending(PacketEvent ev) { if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; // this is needed or client will not join - if (ev.getPacketType() == PacketType.Play.Server.GAME_STATE_CHANGE) return; //if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; // if we dont send this, player has default skin lol if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; ev.setCancelled(true); From ff07fb48770564eaa79bed45776c7c417d5b45b5 Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:23:30 +0200 Subject: [PATCH 7/8] less packets --- .../java/org/cloudanarchy/queueplugin/EventCanceler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 42b8ca2..4204f83 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -38,12 +38,12 @@ public void onPacketReceiving(PacketEvent ev) { @Override public void onPacketSending(PacketEvent ev) { + if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; - if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; - if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; // this is needed or client will not join + if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; + if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; //if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; // if we dont send this, player has default skin lol - if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; ev.setCancelled(true); } From a488d4b9f40bd2619dba92bae8c90c12b00e2b0e Mon Sep 17 00:00:00 2001 From: nothub <48992448+nothub@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:31:20 +0200 Subject: [PATCH 8/8] less packets --- .../queueplugin/EventCanceler.java | 34 ++---- .../queueplugin/packets/AbstractPacket.java | 113 ++++++++++++++++++ .../packets/PacketS2CUpdateTime.java | 77 ++++++++++++ 3 files changed, 203 insertions(+), 21 deletions(-) create mode 100644 src/main/java/org/cloudanarchy/queueplugin/packets/AbstractPacket.java create mode 100644 src/main/java/org/cloudanarchy/queueplugin/packets/PacketS2CUpdateTime.java diff --git a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java index 4204f83..fb91e0b 100644 --- a/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java +++ b/src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java @@ -6,12 +6,10 @@ import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.PlayerAttemptPickupItemEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.raid.RaidTriggerEvent; import org.bukkit.plugin.java.JavaPlugin; +import org.cloudanarchy.queueplugin.packets.PacketS2CUpdateTime; import java.util.HashSet; import java.util.Set; @@ -38,38 +36,32 @@ public void onPacketReceiving(PacketEvent ev) { @Override public void onPacketSending(PacketEvent ev) { - if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) return; + // these are needed or a notchian client will not join if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return; - if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; // this is needed or client will not join + if (ev.getPacketType() == PacketType.Play.Server.POSITION) return; if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return; if (ev.getPacketType() == PacketType.Play.Server.CHAT) return; - //if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; // if we dont send this, player has default skin lol - ev.setCancelled(true); - } - @EventHandler - public void onEntitySpawn(EntitySpawnEvent ev) { - if (ev.getEntityType() == EntityType.PLAYER) return; - ev.setCancelled(true); - } + // if we dont send this, player has default skin lol + if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return; - @EventHandler - public void onBlockPhysics(BlockPhysicsEvent ev) { ev.setCancelled(true); - } - @EventHandler - public void onCommand(PlayerCommandPreprocessEvent ev) { - ev.setCancelled(true); + if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) { + PacketS2CUpdateTime p = new PacketS2CUpdateTime(ev.getPacket()); + p.setAgeOfTheWorld(p.getAgeOfTheWorld() - 420); + p.sendPacket(ev.getPlayer()); + } } @EventHandler - public void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent ev) { + public void onEntitySpawn(EntitySpawnEvent ev) { + if (ev.getEntityType() == EntityType.PLAYER) return; ev.setCancelled(true); } @EventHandler - public void onRaidTrigger(RaidTriggerEvent ev) { + public void onCommand(PlayerCommandPreprocessEvent ev) { ev.setCancelled(true); } diff --git a/src/main/java/org/cloudanarchy/queueplugin/packets/AbstractPacket.java b/src/main/java/org/cloudanarchy/queueplugin/packets/AbstractPacket.java new file mode 100644 index 0000000..f55429c --- /dev/null +++ b/src/main/java/org/cloudanarchy/queueplugin/packets/AbstractPacket.java @@ -0,0 +1,113 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.cloudanarchy.queueplugin.packets; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.google.common.base.Objects; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; + +public abstract class AbstractPacket { + // The packet we will be modifying + protected PacketContainer handle; + + /** + * Constructs a new strongly typed wrapper for the given packet. + * + * @param handle - handle to the raw packet data. + * @param type - the packet type. + */ + protected AbstractPacket(PacketContainer handle, PacketType type) { + // Make sure we're given a valid packet + if (handle == null) + throw new IllegalArgumentException("Packet handle cannot be NULL."); + if (!Objects.equal(handle.getType(), type)) + throw new IllegalArgumentException(handle.getHandle() + + " is not a packet of type " + type); + + this.handle = handle; + } + + /** + * Retrieve a handle to the raw packet data. + * + * @return Raw packet data. + */ + public PacketContainer getHandle() { + return handle; + } + + /** + * Send the current packet to the given receiver. + * + * @param receiver - the receiver. + * @throws RuntimeException If the packet cannot be sent. + */ + public void sendPacket(Player receiver) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, + getHandle()); + } catch (InvocationTargetException e) { + throw new RuntimeException("Cannot send packet.", e); + } + } + + /** + * Send the current packet to all online players. + */ + public void broadcastPacket() { + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException If the packet cannot be received. + * @deprecated Misspelled. recieve to receive + * @see #receivePacket(Player) + */ + @Deprecated + public void recievePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot recieve packet.", e); + } + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException if the packet cannot be received. + */ + public void receivePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot receive packet.", e); + } + } +} diff --git a/src/main/java/org/cloudanarchy/queueplugin/packets/PacketS2CUpdateTime.java b/src/main/java/org/cloudanarchy/queueplugin/packets/PacketS2CUpdateTime.java new file mode 100644 index 0000000..13d691c --- /dev/null +++ b/src/main/java/org/cloudanarchy/queueplugin/packets/PacketS2CUpdateTime.java @@ -0,0 +1,77 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.cloudanarchy.queueplugin.packets; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; + +public class PacketS2CUpdateTime extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.UPDATE_TIME; + + public PacketS2CUpdateTime() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public PacketS2CUpdateTime(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Age of the world. + *

+ * Notes: in ticks; not changed by server commands + * + * @return The current Age of the world + */ + public long getAgeOfTheWorld() { + return handle.getLongs().read(0); + } + + /** + * Set Age of the world. + * + * @param value - new value. + */ + public void setAgeOfTheWorld(long value) { + handle.getLongs().write(0, value); + } + + /** + * Retrieve Time of day. + *

+ * Notes: the world (or region) time, in ticks. If negative the sun will + * stop moving at the Math.abs of the time + * + * @return The current Time of day + */ + public long getTimeOfDay() { + return handle.getLongs().read(1); + } + + /** + * Set Time of day. + * + * @param value - new value. + */ + public void setTimeOfDay(long value) { + handle.getLongs().write(1, value); + } + +}