mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 03:43:40 +01:00
8797975de5
By: md_5 <git@md-5.net>
1705 lines
93 KiB
Diff
1705 lines
93 KiB
Diff
--- a/net/minecraft/server/network/PlayerConnection.java
|
|
+++ b/net/minecraft/server/network/PlayerConnection.java
|
|
@@ -158,6 +158,62 @@
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import java.util.concurrent.ExecutionException;
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
+import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
|
|
+import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
|
+import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving;
|
|
+import net.minecraft.network.protocol.game.PacketPlayOutSpawnPosition;
|
|
+import net.minecraft.util.MathHelper;
|
|
+import net.minecraft.world.entity.EntityInsentient;
|
|
+import net.minecraft.world.entity.animal.EntityFish;
|
|
+import net.minecraft.world.inventory.InventoryClickType;
|
|
+import net.minecraft.world.inventory.Slot;
|
|
+import net.minecraft.world.item.crafting.IRecipe;
|
|
+import net.minecraft.world.level.RayTrace;
|
|
+import net.minecraft.world.phys.MovingObjectPosition;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
+import org.bukkit.craftbukkit.util.CraftChatMessage;
|
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
|
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
|
+import org.bukkit.craftbukkit.util.Waitable;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.Event;
|
|
+import org.bukkit.event.block.Action;
|
|
+import org.bukkit.event.block.SignChangeEvent;
|
|
+import org.bukkit.event.inventory.ClickType;
|
|
+import org.bukkit.event.inventory.CraftItemEvent;
|
|
+import org.bukkit.event.inventory.InventoryAction;
|
|
+import org.bukkit.event.inventory.InventoryClickEvent;
|
|
+import org.bukkit.event.inventory.InventoryCreativeEvent;
|
|
+import org.bukkit.event.inventory.InventoryType.SlotType;
|
|
+import org.bukkit.event.inventory.SmithItemEvent;
|
|
+import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
+import org.bukkit.event.player.PlayerAnimationEvent;
|
|
+import org.bukkit.event.player.PlayerChatEvent;
|
|
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
+import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
|
+import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
+import org.bukkit.event.player.PlayerItemHeldEvent;
|
|
+import org.bukkit.event.player.PlayerKickEvent;
|
|
+import org.bukkit.event.player.PlayerMoveEvent;
|
|
+import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
|
+import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
|
+import org.bukkit.event.player.PlayerTeleportEvent;
|
|
+import org.bukkit.event.player.PlayerToggleFlightEvent;
|
|
+import org.bukkit.event.player.PlayerToggleSneakEvent;
|
|
+import org.bukkit.event.player.PlayerToggleSprintEvent;
|
|
+import org.bukkit.inventory.CraftingInventory;
|
|
+import org.bukkit.inventory.EquipmentSlot;
|
|
+import org.bukkit.inventory.InventoryView;
|
|
+import org.bukkit.inventory.SmithingInventory;
|
|
+import org.bukkit.util.NumberConversions;
|
|
+// CraftBukkit end
|
|
+
|
|
public class PlayerConnection implements ServerPlayerConnection, PacketListenerPlayIn {
|
|
|
|
static final Logger LOGGER = LogManager.getLogger();
|
|
@@ -169,7 +225,9 @@
|
|
private long keepAliveTime;
|
|
private boolean keepAlivePending;
|
|
private long keepAliveChallenge;
|
|
- private int chatSpamTickCount;
|
|
+ // CraftBukkit start - multithreaded fields
|
|
+ private AtomicInteger chatSpamTickCount = new AtomicInteger();
|
|
+ // CraftBukkit end
|
|
private int dropSpamTickCount;
|
|
private double firstGoodX;
|
|
private double firstGoodY;
|
|
@@ -203,7 +261,33 @@
|
|
this.player = entityplayer;
|
|
entityplayer.connection = this;
|
|
entityplayer.Q().a();
|
|
+
|
|
+ // CraftBukkit start - add fields and methods
|
|
+ this.cserver = minecraftserver.server;
|
|
+ }
|
|
+
|
|
+ private final org.bukkit.craftbukkit.CraftServer cserver;
|
|
+ public boolean processedDisconnect;
|
|
+ private int lastTick = MinecraftServer.currentTick;
|
|
+ private int allowedPlayerTicks = 1;
|
|
+ private int lastDropTick = MinecraftServer.currentTick;
|
|
+ private int lastBookTick = MinecraftServer.currentTick;
|
|
+ private int dropCount = 0;
|
|
+ private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6;
|
|
+ private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7;
|
|
+
|
|
+ // Get position of last block hit for BlockDamageLevel.STOPPED
|
|
+ private double lastPosX = Double.MAX_VALUE;
|
|
+ private double lastPosY = Double.MAX_VALUE;
|
|
+ private double lastPosZ = Double.MAX_VALUE;
|
|
+ private float lastPitch = Float.MAX_VALUE;
|
|
+ private float lastYaw = Float.MAX_VALUE;
|
|
+ private boolean justTeleported = false;
|
|
+
|
|
+ public CraftPlayer getPlayer() {
|
|
+ return (this.player == null) ? null : (CraftPlayer) this.player.getBukkitEntity();
|
|
}
|
|
+ // CraftBukkit end
|
|
|
|
public void tick() {
|
|
this.syncPosition();
|
|
@@ -252,7 +336,7 @@
|
|
this.server.getMethodProfiler().enter("keepAlive");
|
|
long i = SystemUtils.getMonotonicMillis();
|
|
|
|
- if (i - this.keepAliveTime >= 15000L) {
|
|
+ if (i - this.keepAliveTime >= 25000L) { // CraftBukkit
|
|
if (this.keepAlivePending) {
|
|
this.disconnect(new ChatMessage("disconnect.timeout"));
|
|
} else {
|
|
@@ -264,15 +348,21 @@
|
|
}
|
|
|
|
this.server.getMethodProfiler().exit();
|
|
+ // CraftBukkit start
|
|
+ for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !chatSpamTickCount.compareAndSet(spam, spam - 1); ) ;
|
|
+ /* Use thread-safe field access instead
|
|
if (this.chatSpamTickCount > 0) {
|
|
--this.chatSpamTickCount;
|
|
}
|
|
+ */
|
|
+ // CraftBukkit end
|
|
|
|
if (this.dropSpamTickCount > 0) {
|
|
--this.dropSpamTickCount;
|
|
}
|
|
|
|
if (this.player.F() > 0L && this.server.getIdleTimeout() > 0 && SystemUtils.getMonotonicMillis() - this.player.F() > (long) (this.server.getIdleTimeout() * 1000 * 60)) {
|
|
+ this.player.resetIdleTimer(); // CraftBukkit - SPIGOT-854
|
|
this.disconnect(new ChatMessage("multiplayer.disconnect.idling"));
|
|
}
|
|
|
|
@@ -296,16 +386,46 @@
|
|
return this.server.a(this.player.getProfile());
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ @Deprecated
|
|
public void disconnect(IChatBaseComponent ichatbasecomponent) {
|
|
+ disconnect(CraftChatMessage.fromComponent(ichatbasecomponent));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
+ public void disconnect(String s) {
|
|
+ // CraftBukkit start - fire PlayerKickEvent
|
|
+ if (this.processedDisconnect) {
|
|
+ return;
|
|
+ }
|
|
+ String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";
|
|
+
|
|
+ PlayerKickEvent event = new PlayerKickEvent(this.cserver.getPlayer(this.player), s, leaveMessage);
|
|
+
|
|
+ if (this.cserver.getServer().isRunning()) {
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+ }
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ // Do not kick the player
|
|
+ return;
|
|
+ }
|
|
+ // Send the possibly modified leave message
|
|
+ s = event.getReason();
|
|
+ final IChatBaseComponent ichatbasecomponent = CraftChatMessage.fromString(s, true)[0];
|
|
+ // CraftBukkit end
|
|
+
|
|
this.connection.sendPacket(new PacketPlayOutKickDisconnect(ichatbasecomponent), (future) -> {
|
|
this.connection.close(ichatbasecomponent);
|
|
});
|
|
+ this.a(ichatbasecomponent); // CraftBukkit - fire quit instantly
|
|
this.connection.stopReading();
|
|
MinecraftServer minecraftserver = this.server;
|
|
NetworkManager networkmanager = this.connection;
|
|
|
|
Objects.requireNonNull(this.connection);
|
|
- minecraftserver.executeSync(networkmanager::handleDisconnection);
|
|
+ // CraftBukkit - Don't wait
|
|
+ minecraftserver.postToMainThread(networkmanager::handleDisconnection);
|
|
}
|
|
|
|
private <T, R> void a(T t0, Consumer<R> consumer, BiFunction<ITextFilter, T, CompletableFuture<R>> bifunction) {
|
|
@@ -323,11 +443,11 @@
|
|
}
|
|
|
|
private void a(String s, Consumer<ITextFilter.a> consumer) {
|
|
- this.a((Object) s, consumer, ITextFilter::a);
|
|
+ this.a(s, consumer, ITextFilter::a); // CraftBukkit - decompile error
|
|
}
|
|
|
|
private void a(List<String> list, Consumer<List<ITextFilter.a>> consumer) {
|
|
- this.a((Object) list, consumer, ITextFilter::a);
|
|
+ this.a(list, consumer, ITextFilter::a); // CraftBukkit - decompile error
|
|
}
|
|
|
|
@Override
|
|
@@ -372,7 +492,34 @@
|
|
double d9 = entity.getMot().g();
|
|
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
|
|
|
|
- if (d10 - d9 > 100.0D && !this.isExemptPlayer()) {
|
|
+
|
|
+ // CraftBukkit start - handle custom speeds and skipped ticks
|
|
+ this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick;
|
|
+ this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1);
|
|
+ this.lastTick = (int) (System.currentTimeMillis() / 50);
|
|
+
|
|
+ ++this.receivedMovePacketCount;
|
|
+ int i = this.receivedMovePacketCount - this.knownMovePacketCount;
|
|
+ if (i > Math.max(this.allowedPlayerTicks, 5)) {
|
|
+ PlayerConnection.LOGGER.debug(this.player.getName() + " is sending move packets too frequently (" + i + " packets since last tick)");
|
|
+ i = 1;
|
|
+ }
|
|
+
|
|
+ if (d10 > 0) {
|
|
+ allowedPlayerTicks -= 1;
|
|
+ } else {
|
|
+ allowedPlayerTicks = 20;
|
|
+ }
|
|
+ double speed;
|
|
+ if (player.getAbilities().flying) {
|
|
+ speed = player.getAbilities().flyingSpeed * 20f;
|
|
+ } else {
|
|
+ speed = player.getAbilities().walkingSpeed * 10f;
|
|
+ }
|
|
+ speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
|
|
+
|
|
+ if (d10 - d9 > Math.max(100.0D, Math.pow((double) (10.0F * (float) i * speed), 2)) && !this.isExemptPlayer()) {
|
|
+ // CraftBukkit end
|
|
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8);
|
|
this.connection.sendPacket(new PacketPlayOutVehicleMove(entity));
|
|
return;
|
|
@@ -402,14 +549,72 @@
|
|
}
|
|
|
|
entity.setLocation(d3, d4, d5, f, f1);
|
|
+ player.setLocation(d3, d4, d5, this.player.getYRot(), this.player.getXRot()); // CraftBukkit
|
|
boolean flag2 = worldserver.getCubes(entity, entity.getBoundingBox().shrink(0.0625D));
|
|
|
|
if (flag && (flag1 || !flag2)) {
|
|
entity.setLocation(d0, d1, d2, f, f1);
|
|
+ player.setLocation(d0, d1, d2, this.player.getYRot(), this.player.getXRot()); // CraftBukkit
|
|
this.connection.sendPacket(new PacketPlayOutVehicleMove(entity));
|
|
return;
|
|
}
|
|
|
|
+ // CraftBukkit start - fire PlayerMoveEvent
|
|
+ Player player = this.getPlayer();
|
|
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
|
|
+ Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
|
|
+
|
|
+ // If the packet contains movement information then we update the To location with the correct XYZ.
|
|
+ to.setX(packetplayinvehiclemove.getX());
|
|
+ to.setY(packetplayinvehiclemove.getY());
|
|
+ to.setZ(packetplayinvehiclemove.getZ());
|
|
+
|
|
+
|
|
+ // If the packet contains look information then we update the To location with the correct Yaw & Pitch.
|
|
+ to.setYaw(packetplayinvehiclemove.getYaw());
|
|
+ to.setPitch(packetplayinvehiclemove.getPitch());
|
|
+
|
|
+ // Prevent 40 event-calls for less than a single pixel of movement >.>
|
|
+ double delta = Math.pow(this.lastPosX - to.getX(), 2) + Math.pow(this.lastPosY - to.getY(), 2) + Math.pow(this.lastPosZ - to.getZ(), 2);
|
|
+ float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch());
|
|
+
|
|
+ if ((delta > 1f / 256 || deltaAngle > 10f) && !this.player.isFrozen()) {
|
|
+ this.lastPosX = to.getX();
|
|
+ this.lastPosY = to.getY();
|
|
+ this.lastPosZ = to.getZ();
|
|
+ this.lastYaw = to.getYaw();
|
|
+ this.lastPitch = to.getPitch();
|
|
+
|
|
+ // Skip the first time we do this
|
|
+ if (from.getX() != Double.MAX_VALUE) {
|
|
+ Location oldTo = to.clone();
|
|
+ PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ // If the event is cancelled we move the player back to their old location.
|
|
+ if (event.isCancelled()) {
|
|
+ teleport(from);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // If a Plugin has changed the To destination then we teleport the Player
|
|
+ // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
|
|
+ // We only do this if the Event was not cancelled.
|
|
+ if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
|
|
+ this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // Check to see if the Players Location has some how changed during the call of the event.
|
|
+ // This can happen due to a plugin teleporting the player instead of using .setTo()
|
|
+ if (!from.equals(this.getPlayer().getLocation()) && this.justTeleported) {
|
|
+ this.justTeleported = false;
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
this.player.getWorldServer().getChunkProvider().movePlayer(this.player);
|
|
this.player.checkMovement(this.player.locX() - d0, this.player.locY() - d1, this.player.locZ() - d2);
|
|
this.clientVehicleIsFloating = d11 >= -0.03125D && !this.server.getAllowFlight() && this.a(entity);
|
|
@@ -428,7 +633,7 @@
|
|
@Override
|
|
public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.getWorldServer());
|
|
- if (packetplayinteleportaccept.b() == this.awaitingTeleport) {
|
|
+ if (packetplayinteleportaccept.b() == this.awaitingTeleport && this.awaitingPositionFromClient != null) { // CraftBukkit
|
|
this.player.setLocation(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
|
|
this.lastGoodX = this.awaitingPositionFromClient.x;
|
|
this.lastGoodY = this.awaitingPositionFromClient.y;
|
|
@@ -438,6 +643,7 @@
|
|
}
|
|
|
|
this.awaitingPositionFromClient = null;
|
|
+ this.player.getWorldServer().getChunkProvider().movePlayer(this.player); // CraftBukkit
|
|
}
|
|
|
|
}
|
|
@@ -445,7 +651,7 @@
|
|
@Override
|
|
public void a(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinrecipedisplayed, this, this.player.getWorldServer());
|
|
- Optional optional = this.server.getCraftingManager().getRecipe(packetplayinrecipedisplayed.b());
|
|
+ Optional<? extends IRecipe<?>> optional = this.server.getCraftingManager().getRecipe(packetplayinrecipedisplayed.b()); // CraftBukkit - decompile error
|
|
RecipeBookServer recipebookserver = this.player.getRecipeBook();
|
|
|
|
Objects.requireNonNull(recipebookserver);
|
|
@@ -475,6 +681,12 @@
|
|
@Override
|
|
public void a(PacketPlayInTabComplete packetplayintabcomplete) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.getWorldServer());
|
|
+ // CraftBukkit start
|
|
+ if (chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getProfile())) {
|
|
+ this.disconnect(new ChatMessage("disconnect.spam", new Object[0]));
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
StringReader stringreader = new StringReader(packetplayintabcomplete.c());
|
|
|
|
if (stringreader.canRead() && stringreader.peek() == '/') {
|
|
@@ -484,6 +696,7 @@
|
|
ParseResults<CommandListenerWrapper> parseresults = this.server.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener());
|
|
|
|
this.server.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
|
|
+ if (suggestions.isEmpty()) return; // CraftBukkit - don't send through empty suggestions - prevents [<args>] from showing for plugins with nothing more to offer
|
|
this.connection.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestions));
|
|
});
|
|
}
|
|
@@ -716,6 +929,7 @@
|
|
|
|
if (container instanceof ContainerMerchant) {
|
|
ContainerMerchant containermerchant = (ContainerMerchant) container;
|
|
+ CraftEventFactory.callTradeSelectEvent(this.player, i, containermerchant); // CraftBukkit
|
|
|
|
containermerchant.d(i);
|
|
containermerchant.g(i);
|
|
@@ -725,6 +939,13 @@
|
|
|
|
@Override
|
|
public void a(PacketPlayInBEdit packetplayinbedit) {
|
|
+ // CraftBukkit start
|
|
+ if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
|
|
+ this.disconnect("Book edited too quickly!");
|
|
+ return;
|
|
+ }
|
|
+ this.lastBookTick = MinecraftServer.currentTick;
|
|
+ // CraftBukkit end
|
|
int i = packetplayinbedit.d();
|
|
|
|
if (PlayerInventory.d(i) || i == 40) {
|
|
@@ -787,7 +1008,7 @@
|
|
this.a(list, (s) -> {
|
|
return IChatBaseComponent.ChatSerializer.a((IChatBaseComponent) (new ChatComponentText(s)));
|
|
}, itemstack1);
|
|
- this.player.getInventory().setItem(i, itemstack1);
|
|
+ this.player.getInventory().setItem(i, CraftEventFactory.handleEditBookEvent(player, i, itemstack, itemstack1)); // CraftBukkit
|
|
}
|
|
}
|
|
|
|
@@ -795,7 +1016,7 @@
|
|
NBTTagList nbttaglist = new NBTTagList();
|
|
|
|
if (this.player.R()) {
|
|
- Stream stream = list.stream().map((itextfilter_a) -> {
|
|
+ Stream<NBTTagString> stream = list.stream().map((itextfilter_a) -> { // CraftBukkit - decompile error
|
|
return NBTTagString.a((String) unaryoperator.apply(itextfilter_a.b()));
|
|
});
|
|
|
|
@@ -859,7 +1080,7 @@
|
|
} else {
|
|
WorldServer worldserver = this.player.getWorldServer();
|
|
|
|
- if (!this.player.wonGame) {
|
|
+ if (!this.player.wonGame && !this.player.isFrozen()) { // CraftBukkit
|
|
if (this.tickCount == 0) {
|
|
this.syncPosition();
|
|
}
|
|
@@ -869,7 +1090,7 @@
|
|
this.awaitingTeleportTime = this.tickCount;
|
|
this.b(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
|
|
}
|
|
-
|
|
+ this.allowedPlayerTicks = 20; // CraftBukkit
|
|
} else {
|
|
this.awaitingTeleportTime = this.tickCount;
|
|
double d0 = a(packetplayinflying.a(this.player.locX()));
|
|
@@ -881,7 +1102,15 @@
|
|
if (this.player.isPassenger()) {
|
|
this.player.setLocation(this.player.locX(), this.player.locY(), this.player.locZ(), f, f1);
|
|
this.player.getWorldServer().getChunkProvider().movePlayer(this.player);
|
|
+ this.allowedPlayerTicks = 20; // CraftBukkit
|
|
} else {
|
|
+ // CraftBukkit - Make sure the move is valid but then reset it for plugins to modify
|
|
+ double prevX = player.locX();
|
|
+ double prevY = player.locY();
|
|
+ double prevZ = player.locZ();
|
|
+ float prevYaw = player.getYRot();
|
|
+ float prevPitch = player.getXRot();
|
|
+ // CraftBukkit end
|
|
double d3 = this.player.locX();
|
|
double d4 = this.player.locY();
|
|
double d5 = this.player.locZ();
|
|
@@ -901,15 +1130,33 @@
|
|
++this.receivedMovePacketCount;
|
|
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
|
|
|
|
- if (i > 5) {
|
|
+ // CraftBukkit start - handle custom speeds and skipped ticks
|
|
+ this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick;
|
|
+ this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1);
|
|
+ this.lastTick = (int) (System.currentTimeMillis() / 50);
|
|
+
|
|
+ if (i > Math.max(this.allowedPlayerTicks, 5)) {
|
|
PlayerConnection.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getDisplayName().getString(), i);
|
|
i = 1;
|
|
}
|
|
|
|
+ if (packetplayinflying.hasRot || d11 > 0) {
|
|
+ allowedPlayerTicks -= 1;
|
|
+ } else {
|
|
+ allowedPlayerTicks = 20;
|
|
+ }
|
|
+ double speed;
|
|
+ if (player.getAbilities().flying) {
|
|
+ speed = player.getAbilities().flyingSpeed * 20f;
|
|
+ } else {
|
|
+ speed = player.getAbilities().walkingSpeed * 10f;
|
|
+ }
|
|
+
|
|
if (!this.player.H() && (!this.player.getWorldServer().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !this.player.isGliding())) {
|
|
float f2 = this.player.isGliding() ? 300.0F : 100.0F;
|
|
|
|
- if (d11 - d10 > (double) (f2 * (float) i) && !this.isExemptPlayer()) {
|
|
+ if (d11 - d10 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2)) && !this.isExemptPlayer()) {
|
|
+ // CraftBukkit end
|
|
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getDisplayName().getString(), d7, d8, d9);
|
|
this.b(this.player.locX(), this.player.locY(), this.player.locZ(), this.player.getYRot(), this.player.getXRot());
|
|
return;
|
|
@@ -928,6 +1175,7 @@
|
|
}
|
|
|
|
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
|
|
+ this.player.setOnGround(packetplayinflying.b()); // CraftBukkit - SPIGOT-5810, SPIGOT-5835: reset by this.player.move
|
|
double d12 = d8;
|
|
|
|
d7 = d0 - this.player.locX();
|
|
@@ -949,10 +1197,74 @@
|
|
if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.getCubes(this.player, axisalignedbb) || this.a((IWorldReader) worldserver, axisalignedbb))) {
|
|
this.b(d3, d4, d5, f, f1);
|
|
} else {
|
|
- this.clientIsFloating = d12 >= -0.03125D && this.player.gameMode.getGameMode() != EnumGamemode.SPECTATOR && !this.server.getAllowFlight() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isGliding() && this.a((Entity) this.player);
|
|
+ // CraftBukkit start - fire PlayerMoveEvent
|
|
+ // Rest to old location first
|
|
+ this.player.setLocation(prevX, prevY, prevZ, prevYaw, prevPitch);
|
|
+
|
|
+ Player player = this.getPlayer();
|
|
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
|
|
+ Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
|
|
+
|
|
+ // If the packet contains movement information then we update the To location with the correct XYZ.
|
|
+ if (packetplayinflying.hasPos) {
|
|
+ to.setX(packetplayinflying.x);
|
|
+ to.setY(packetplayinflying.y);
|
|
+ to.setZ(packetplayinflying.z);
|
|
+ }
|
|
+
|
|
+ // If the packet contains look information then we update the To location with the correct Yaw & Pitch.
|
|
+ if (packetplayinflying.hasRot) {
|
|
+ to.setYaw(packetplayinflying.yRot);
|
|
+ to.setPitch(packetplayinflying.xRot);
|
|
+ }
|
|
+
|
|
+ // Prevent 40 event-calls for less than a single pixel of movement >.>
|
|
+ double delta = Math.pow(this.lastPosX - to.getX(), 2) + Math.pow(this.lastPosY - to.getY(), 2) + Math.pow(this.lastPosZ - to.getZ(), 2);
|
|
+ float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch());
|
|
+
|
|
+ if ((delta > 1f / 256 || deltaAngle > 10f) && !this.player.isFrozen()) {
|
|
+ this.lastPosX = to.getX();
|
|
+ this.lastPosY = to.getY();
|
|
+ this.lastPosZ = to.getZ();
|
|
+ this.lastYaw = to.getYaw();
|
|
+ this.lastPitch = to.getPitch();
|
|
+
|
|
+ // Skip the first time we do this
|
|
+ if (from.getX() != Double.MAX_VALUE) {
|
|
+ Location oldTo = to.clone();
|
|
+ PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ // If the event is cancelled we move the player back to their old location.
|
|
+ if (event.isCancelled()) {
|
|
+ teleport(from);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // If a Plugin has changed the To destination then we teleport the Player
|
|
+ // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
|
|
+ // We only do this if the Event was not cancelled.
|
|
+ if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
|
|
+ this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // Check to see if the Players Location has some how changed during the call of the event.
|
|
+ // This can happen due to a plugin teleporting the player instead of using .setTo()
|
|
+ if (!from.equals(this.getPlayer().getLocation()) && this.justTeleported) {
|
|
+ this.justTeleported = false;
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ this.player.setLocation(d0, d1, d2, f, f1); // Copied from above
|
|
+
|
|
+ // MC-135989, SPIGOT-5564: isRiptiding
|
|
+ this.clientIsFloating = d12 >= -0.03125D && this.player.gameMode.getGameMode() != EnumGamemode.SPECTATOR && !this.server.getAllowFlight() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isGliding() && this.a((Entity) this.player) && !this.player.isRiptiding();
|
|
+ // CraftBukkit end
|
|
this.player.getWorldServer().getChunkProvider().movePlayer(this.player);
|
|
this.player.a(this.player.locY() - d6, packetplayinflying.b());
|
|
- this.player.setOnGround(packetplayinflying.b());
|
|
+ // this.player.setOnGround(packetplayinflying.b()); // CraftBukkit - moved up
|
|
if (flag) {
|
|
this.player.fallDistance = 0.0F;
|
|
}
|
|
@@ -980,19 +1292,80 @@
|
|
});
|
|
}
|
|
|
|
+ // CraftBukkit start - Delegate to teleport(Location)
|
|
public void a(double d0, double d1, double d2, float f, float f1) {
|
|
- this.a(d0, d1, d2, f, f1, Collections.emptySet(), true);
|
|
+ this.a(d0, d1, d2, f, f1, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
|
+ }
|
|
+
|
|
+ public void a(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) {
|
|
+ this.a(d0, d1, d2, f, f1, Collections.emptySet(), true, cause);
|
|
}
|
|
|
|
public void b(double d0, double d1, double d2, float f, float f1) {
|
|
- this.a(d0, d1, d2, f, f1, Collections.emptySet(), false);
|
|
+ this.b(d0, d1, d2, f, f1, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
|
+ }
|
|
+
|
|
+ public void b(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) {
|
|
+ this.a(d0, d1, d2, f, f1, Collections.emptySet(), false, cause);
|
|
}
|
|
|
|
public void a(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set) {
|
|
- this.a(d0, d1, d2, f, f1, set, false);
|
|
+ this.a(d0, d1, d2, f, f1, set, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
|
}
|
|
|
|
- public void a(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, boolean flag) {
|
|
+ public void a(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, PlayerTeleportEvent.TeleportCause cause) {
|
|
+ this.a(d0, d1, d2, f, f1, set, false, cause);
|
|
+ }
|
|
+
|
|
+ public boolean a(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, boolean flag, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status
|
|
+ Player player = this.getPlayer();
|
|
+ Location from = player.getLocation();
|
|
+
|
|
+ double x = d0;
|
|
+ double y = d1;
|
|
+ double z = d2;
|
|
+ float yaw = f;
|
|
+ float pitch = f1;
|
|
+
|
|
+ Location to = new Location(this.getPlayer().getWorld(), x, y, z, yaw, pitch);
|
|
+ // SPIGOT-5171: Triggered on join
|
|
+ if (from.equals(to)) {
|
|
+ this.internalTeleport(d0, d1, d2, f, f1, set, flag);
|
|
+ return false; // CraftBukkit - Return event status
|
|
+ }
|
|
+
|
|
+ PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause);
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled() || !to.equals(event.getTo())) {
|
|
+ set.clear(); // Can't relative teleport
|
|
+ to = event.isCancelled() ? event.getFrom() : event.getTo();
|
|
+ d0 = to.getX();
|
|
+ d1 = to.getY();
|
|
+ d2 = to.getZ();
|
|
+ f = to.getYaw();
|
|
+ f1 = to.getPitch();
|
|
+ }
|
|
+
|
|
+ this.internalTeleport(d0, d1, d2, f, f1, set, flag);
|
|
+ return event.isCancelled(); // CraftBukkit - Return event status
|
|
+ }
|
|
+
|
|
+ public void teleport(Location dest) {
|
|
+ internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.<PacketPlayOutPosition.EnumPlayerTeleportFlags>emptySet(), true);
|
|
+ }
|
|
+
|
|
+ private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, boolean flag) {
|
|
+ // CraftBukkit start
|
|
+ if (Float.isNaN(f)) {
|
|
+ f = 0;
|
|
+ }
|
|
+ if (Float.isNaN(f1)) {
|
|
+ f1 = 0;
|
|
+ }
|
|
+
|
|
+ this.justTeleported = true;
|
|
+ // CraftBukkit end
|
|
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX() : 0.0D;
|
|
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY() : 0.0D;
|
|
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ() : 0.0D;
|
|
@@ -1004,6 +1377,14 @@
|
|
this.awaitingTeleport = 0;
|
|
}
|
|
|
|
+ // CraftBukkit start - update last location
|
|
+ this.lastPosX = this.awaitingPositionFromClient.x;
|
|
+ this.lastPosY = this.awaitingPositionFromClient.y;
|
|
+ this.lastPosZ = this.awaitingPositionFromClient.z;
|
|
+ this.lastYaw = f;
|
|
+ this.lastPitch = f1;
|
|
+ // CraftBukkit end
|
|
+
|
|
this.awaitingTeleportTime = this.tickCount;
|
|
this.player.setLocation(d0, d1, d2, f, f1);
|
|
this.player.connection.sendPacket(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport, flag));
|
|
@@ -1012,6 +1393,7 @@
|
|
@Override
|
|
public void a(PacketPlayInBlockDig packetplayinblockdig) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
BlockPosition blockposition = packetplayinblockdig.b();
|
|
|
|
this.player.resetIdleTimer();
|
|
@@ -1022,14 +1404,46 @@
|
|
if (!this.player.isSpectator()) {
|
|
ItemStack itemstack = this.player.b(EnumHand.OFF_HAND);
|
|
|
|
- this.player.a(EnumHand.OFF_HAND, this.player.b(EnumHand.MAIN_HAND));
|
|
- this.player.a(EnumHand.MAIN_HAND, itemstack);
|
|
+ // CraftBukkit start - inspiration taken from DispenserRegistry (See SpigotCraft#394)
|
|
+ CraftItemStack mainHand = CraftItemStack.asCraftMirror(itemstack);
|
|
+ CraftItemStack offHand = CraftItemStack.asCraftMirror(this.player.b(EnumHand.MAIN_HAND));
|
|
+ PlayerSwapHandItemsEvent swapItemsEvent = new PlayerSwapHandItemsEvent(getPlayer(), mainHand.clone(), offHand.clone());
|
|
+ this.cserver.getPluginManager().callEvent(swapItemsEvent);
|
|
+ if (swapItemsEvent.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ if (swapItemsEvent.getOffHandItem().equals(offHand)) {
|
|
+ this.player.a(EnumHand.OFF_HAND, this.player.b(EnumHand.MAIN_HAND));
|
|
+ } else {
|
|
+ this.player.a(EnumHand.OFF_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getOffHandItem()));
|
|
+ }
|
|
+ if (swapItemsEvent.getMainHandItem().equals(mainHand)) {
|
|
+ this.player.a(EnumHand.MAIN_HAND, itemstack);
|
|
+ } else {
|
|
+ this.player.a(EnumHand.MAIN_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getMainHandItem()));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.player.clearActiveItem();
|
|
}
|
|
|
|
return;
|
|
case DROP_ITEM:
|
|
if (!this.player.isSpectator()) {
|
|
+ // limit how quickly items can be dropped
|
|
+ // If the ticks aren't the same then the count starts from 0 and we update the lastDropTick.
|
|
+ if (this.lastDropTick != MinecraftServer.currentTick) {
|
|
+ this.dropCount = 0;
|
|
+ this.lastDropTick = MinecraftServer.currentTick;
|
|
+ } else {
|
|
+ // Else we increment the drop count and check the amount.
|
|
+ this.dropCount++;
|
|
+ if (this.dropCount >= 20) {
|
|
+ LOGGER.warn(this.player.getName() + " dropped their items too quickly!");
|
|
+ this.disconnect("You dropped your items too quickly (Hacking?)");
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.player.dropItem(false);
|
|
}
|
|
|
|
@@ -1066,6 +1480,7 @@
|
|
@Override
|
|
public void a(PacketPlayInUseItem packetplayinuseitem) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
WorldServer worldserver = this.player.getWorldServer();
|
|
EnumHand enumhand = packetplayinuseitem.b();
|
|
ItemStack itemstack = this.player.b(enumhand);
|
|
@@ -1078,6 +1493,14 @@
|
|
|
|
if (blockposition.getY() < i) {
|
|
if (this.awaitingPositionFromClient == null && this.player.h((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.a((EntityHuman) this.player, blockposition)) {
|
|
+ // CraftBukkit start - Check if we can actually do something over this large a distance
|
|
+ Location eyeLoc = this.getPlayer().getEyeLocation();
|
|
+ double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ());
|
|
+ if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) {
|
|
+ return;
|
|
+ }
|
|
+ this.player.clearActiveItem(); // SPIGOT-4706
|
|
+ // CraftBukkit end
|
|
EnumInteractionResult enuminteractionresult = this.player.gameMode.a(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
|
|
|
|
if (enumdirection == EnumDirection.UP && !enuminteractionresult.a() && blockposition.getY() >= i - 1 && a(this.player, itemstack)) {
|
|
@@ -1101,12 +1524,51 @@
|
|
@Override
|
|
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
WorldServer worldserver = this.player.getWorldServer();
|
|
EnumHand enumhand = packetplayinblockplace.b();
|
|
ItemStack itemstack = this.player.b(enumhand);
|
|
|
|
this.player.resetIdleTimer();
|
|
if (!itemstack.isEmpty()) {
|
|
+ // CraftBukkit start
|
|
+ // Raytrace to look for 'rogue armswings'
|
|
+ float f1 = this.player.getXRot();
|
|
+ float f2 = this.player.getYRot();
|
|
+ double d0 = this.player.locX();
|
|
+ double d1 = this.player.locY() + (double) this.player.getHeadHeight();
|
|
+ double d2 = this.player.locZ();
|
|
+ Vec3D vec3d = new Vec3D(d0, d1, d2);
|
|
+
|
|
+ float f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F);
|
|
+ float f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F);
|
|
+ float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
|
+ float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
|
+ float f7 = f4 * f5;
|
|
+ float f8 = f3 * f5;
|
|
+ double d3 = player.gameMode.getGameMode()== EnumGamemode.CREATIVE ? 5.0D : 4.5D;
|
|
+ Vec3D vec3d1 = vec3d.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
|
|
+ MovingObjectPosition movingobjectposition = this.player.level.rayTrace(new RayTrace(vec3d, vec3d1, RayTrace.BlockCollisionOption.OUTLINE, RayTrace.FluidCollisionOption.NONE, player));
|
|
+
|
|
+ boolean cancelled;
|
|
+ if (movingobjectposition == null || movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.BLOCK) {
|
|
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack, enumhand);
|
|
+ cancelled = event.useItemInHand() == Event.Result.DENY;
|
|
+ } else {
|
|
+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition;
|
|
+ if (player.gameMode.firedInteract && player.gameMode.interactPosition.equals(movingobjectpositionblock.getBlockPosition()) && player.gameMode.interactHand == enumhand && ItemStack.equals(player.gameMode.interactItemStack, itemstack)) {
|
|
+ cancelled = player.gameMode.interactResult;
|
|
+ } else {
|
|
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand);
|
|
+ cancelled = event.useItemInHand() == Event.Result.DENY;
|
|
+ }
|
|
+ player.gameMode.firedInteract = false;
|
|
+ }
|
|
+
|
|
+ if (cancelled) {
|
|
+ this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
|
|
+ return;
|
|
+ }
|
|
EnumInteractionResult enuminteractionresult = this.player.gameMode.a(this.player, worldserver, itemstack, enumhand);
|
|
|
|
if (enuminteractionresult.b()) {
|
|
@@ -1127,7 +1589,7 @@
|
|
Entity entity = packetplayinspectate.a(worldserver);
|
|
|
|
if (entity != null) {
|
|
- this.player.a(worldserver, entity.locX(), entity.locY(), entity.locZ(), entity.getYRot(), entity.getXRot());
|
|
+ this.player.a(worldserver, entity.locX(), entity.locY(), entity.locZ(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
|
|
return;
|
|
}
|
|
}
|
|
@@ -1142,6 +1604,7 @@
|
|
PlayerConnection.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getDisplayName());
|
|
this.disconnect(new ChatMessage("multiplayer.requiredTexturePrompt.disconnect"));
|
|
}
|
|
+ this.cserver.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(getPlayer(), PlayerResourcePackStatusEvent.Status.values()[packetplayinresourcepackstatus.action.ordinal()])); // CraftBukkit
|
|
|
|
}
|
|
|
|
@@ -1161,11 +1624,26 @@
|
|
|
|
@Override
|
|
public void a(IChatBaseComponent ichatbasecomponent) {
|
|
+ // CraftBukkit start - Rarely it would send a disconnect line twice
|
|
+ if (this.processedDisconnect) {
|
|
+ return;
|
|
+ } else {
|
|
+ this.processedDisconnect = true;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getDisplayName().getString(), ichatbasecomponent.getString());
|
|
+ // CraftBukkit start - Replace vanilla quit message handling with our own.
|
|
+ /*
|
|
this.server.invalidatePingSample();
|
|
this.server.getPlayerList().sendMessage((new ChatMessage("multiplayer.player.left", new Object[]{this.player.getScoreboardDisplayName()})).a(EnumChatFormat.YELLOW), ChatMessageType.SYSTEM, SystemUtils.NIL_UUID);
|
|
+ */
|
|
+
|
|
this.player.p();
|
|
- this.server.getPlayerList().disconnect(this.player);
|
|
+ String quitMessage = this.server.getPlayerList().disconnect(this.player);
|
|
+ if ((quitMessage != null) && (quitMessage.length() > 0)) {
|
|
+ this.server.getPlayerList().sendMessage(CraftChatMessage.fromString(quitMessage));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.player.Q().b();
|
|
if (this.isExemptPlayer()) {
|
|
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
|
|
@@ -1180,6 +1658,15 @@
|
|
}
|
|
|
|
public void a(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
|
|
+ // CraftBukkit start
|
|
+ if (packet == null) {
|
|
+ return;
|
|
+ } else if (packet instanceof PacketPlayOutSpawnPosition) {
|
|
+ PacketPlayOutSpawnPosition packet6 = (PacketPlayOutSpawnPosition) packet;
|
|
+ this.player.compassTarget = new Location(this.getPlayer().getWorld(), packet6.pos.getX(), packet6.pos.getY(), packet6.pos.getZ());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
try {
|
|
this.connection.sendPacket(packet, genericfuturelistener);
|
|
} catch (Throwable throwable) {
|
|
@@ -1196,7 +1683,16 @@
|
|
@Override
|
|
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
if (packetplayinhelditemslot.b() >= 0 && packetplayinhelditemslot.b() < PlayerInventory.getHotbarSize()) {
|
|
+ PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.getInventory().selected, packetplayinhelditemslot.b());
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ this.sendPacket(new PacketPlayOutHeldItemSlot(this.player.getInventory().selected));
|
|
+ this.player.resetIdleTimer();
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (this.player.getInventory().selected != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) {
|
|
this.player.clearActiveItem();
|
|
}
|
|
@@ -1205,11 +1701,18 @@
|
|
this.player.resetIdleTimer();
|
|
} else {
|
|
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString());
|
|
+ this.disconnect("Invalid hotbar selection (Hacking?)"); // CraftBukkit
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void a(PacketPlayInChat packetplayinchat) {
|
|
+ // CraftBukkit start - async chat
|
|
+ // SPIGOT-3638
|
|
+ if (this.server.isStopped()) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
String s = StringUtils.normalizeSpace(packetplayinchat.b());
|
|
|
|
for (int i = 0; i < s.length(); ++i) {
|
|
@@ -1223,20 +1726,42 @@
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinchat, this, this.player.getWorldServer());
|
|
this.a(ITextFilter.a.a(s));
|
|
} else {
|
|
- this.a(s, this::a);
|
|
+ this.a(ITextFilter.a.a(s)); // CraftBukkit - filter NYI
|
|
}
|
|
|
|
}
|
|
|
|
private void a(ITextFilter.a itextfilter_a) {
|
|
- if (this.player.getChatFlags() == EnumChatVisibility.HIDDEN) {
|
|
+ if (this.player.isRemoved() || this.player.getChatFlags() == EnumChatVisibility.HIDDEN) { // CraftBukkit - dead men tell no tales
|
|
this.sendPacket(new PacketPlayOutChat((new ChatMessage("chat.disabled.options")).a(EnumChatFormat.RED), ChatMessageType.SYSTEM, SystemUtils.NIL_UUID));
|
|
} else {
|
|
this.player.resetIdleTimer();
|
|
String s = itextfilter_a.a();
|
|
|
|
- if (s.startsWith("/")) {
|
|
- this.handleCommand(s);
|
|
+ // CraftBukkit start
|
|
+ boolean isSync = s.startsWith("/");
|
|
+ if (isSync) {
|
|
+ try {
|
|
+ this.server.server.playerCommandState = true;
|
|
+ this.handleCommand(s);
|
|
+ } finally {
|
|
+ this.server.server.playerCommandState = false;
|
|
+ }
|
|
+ } else if (s.isEmpty()) {
|
|
+ LOGGER.warn(this.player.getName() + " tried to send an empty message");
|
|
+ } else if (getPlayer().isConversing()) {
|
|
+ final String conversationInput = s;
|
|
+ this.server.processQueue.add(new Runnable() {
|
|
+ @Override
|
|
+ public void run() {
|
|
+ getPlayer().acceptConversationInput(conversationInput);
|
|
+ }
|
|
+ });
|
|
+ } else if (this.player.getChatFlags() == EnumChatVisibility.SYSTEM) { // Re-add "Command Only" flag check
|
|
+ this.sendPacket(new PacketPlayOutChat((new ChatMessage("chat.cannotSend")).a(EnumChatFormat.RED), ChatMessageType.SYSTEM, SystemUtils.NIL_UUID));
|
|
+ } else if (true) {
|
|
+ this.chat(s, true);
|
|
+ // CraftBukkit end - the below is for reference. :)
|
|
} else {
|
|
String s1 = itextfilter_a.b();
|
|
ChatMessage chatmessage = s1.isEmpty() ? null : new ChatMessage("chat.type.text", new Object[]{this.player.getScoreboardDisplayName(), s1});
|
|
@@ -1247,28 +1772,198 @@
|
|
}, ChatMessageType.CHAT, this.player.getUniqueID());
|
|
}
|
|
|
|
- this.chatSpamTickCount += 20;
|
|
- if (this.chatSpamTickCount > 200 && !this.server.getPlayerList().isOp(this.player.getProfile())) {
|
|
- this.disconnect(new ChatMessage("disconnect.spam"));
|
|
+ // CraftBukkit start - replaced with thread safe throttle
|
|
+ // this.chatThrottle += 20;
|
|
+ if (chatSpamTickCount.addAndGet(20) > 200 && !this.server.getPlayerList().isOp(this.player.getProfile())) {
|
|
+ if (!isSync) {
|
|
+ Waitable waitable = new Waitable() {
|
|
+ @Override
|
|
+ protected Object evaluate() {
|
|
+ PlayerConnection.this.disconnect(new ChatMessage("disconnect.spam"));
|
|
+ return null;
|
|
+ }
|
|
+ };
|
|
+
|
|
+ this.server.processQueue.add(waitable);
|
|
+
|
|
+ try {
|
|
+ waitable.get();
|
|
+ } catch (InterruptedException e) {
|
|
+ Thread.currentThread().interrupt();
|
|
+ } catch (ExecutionException e) {
|
|
+ throw new RuntimeException(e);
|
|
+ }
|
|
+ } else {
|
|
+ this.disconnect(new ChatMessage("disconnect.spam"));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
+ // CraftBukkit start - add method
|
|
+ public void chat(String s, boolean async) {
|
|
+ if (s.isEmpty() || this.player.getChatFlags() == EnumChatVisibility.HIDDEN) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (!async && s.startsWith("/")) {
|
|
+ this.handleCommand(s);
|
|
+ } else if (this.player.getChatFlags() == EnumChatVisibility.SYSTEM) {
|
|
+ // Do nothing, this is coming from a plugin
|
|
+ } else {
|
|
+ Player player = this.getPlayer();
|
|
+ AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(server));
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (PlayerChatEvent.getHandlerList().getRegisteredListeners().length != 0) {
|
|
+ // Evil plugins still listening to deprecated event
|
|
+ final PlayerChatEvent queueEvent = new PlayerChatEvent(player, event.getMessage(), event.getFormat(), event.getRecipients());
|
|
+ queueEvent.setCancelled(event.isCancelled());
|
|
+ Waitable waitable = new Waitable() {
|
|
+ @Override
|
|
+ protected Object evaluate() {
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(queueEvent);
|
|
+
|
|
+ if (queueEvent.isCancelled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage());
|
|
+ PlayerConnection.this.server.console.sendMessage(message);
|
|
+ if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) {
|
|
+ for (EntityPlayer recipient : server.getPlayerList().players) {
|
|
+ recipient.getBukkitEntity().sendMessage(PlayerConnection.this.player.getUniqueID(), message);
|
|
+ }
|
|
+ } else {
|
|
+ for (Player player : queueEvent.getRecipients()) {
|
|
+ player.sendMessage(PlayerConnection.this.player.getUniqueID(), message);
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }};
|
|
+ if (async) {
|
|
+ server.processQueue.add(waitable);
|
|
+ } else {
|
|
+ waitable.run();
|
|
+ }
|
|
+ try {
|
|
+ waitable.get();
|
|
+ } catch (InterruptedException e) {
|
|
+ Thread.currentThread().interrupt(); // This is proper habit for java. If we aren't handling it, pass it on!
|
|
+ } catch (ExecutionException e) {
|
|
+ throw new RuntimeException("Exception processing chat event", e.getCause());
|
|
+ }
|
|
+ } else {
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
|
|
+ server.console.sendMessage(s);
|
|
+ if (((LazyPlayerSet) event.getRecipients()).isLazy()) {
|
|
+ for (EntityPlayer recipient : server.getPlayerList().players) {
|
|
+ recipient.getBukkitEntity().sendMessage(PlayerConnection.this.player.getUniqueID(), s);
|
|
+ }
|
|
+ } else {
|
|
+ for (Player recipient : event.getRecipients()) {
|
|
+ recipient.sendMessage(PlayerConnection.this.player.getUniqueID(), s);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
private void handleCommand(String s) {
|
|
- this.server.getCommandDispatcher().a(this.player.getCommandListener(), s);
|
|
+ // CraftBukkit start - whole method
|
|
+ this.LOGGER.info(this.player.getName() + " issued server command: " + s);
|
|
+
|
|
+ CraftPlayer player = this.getPlayer();
|
|
+
|
|
+ PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s, new LazyPlayerSet(server));
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ if (this.cserver.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
|
|
+ return;
|
|
+ }
|
|
+ } catch (org.bukkit.command.CommandException ex) {
|
|
+ player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
|
|
+ java.util.logging.Logger.getLogger(PlayerConnection.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
+ return;
|
|
+ }
|
|
+ // this.minecraftServer.getCommandDispatcher().a(this.player.getCommandListener(), s);
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
@Override
|
|
public void a(PacketPlayInArmAnimation packetplayinarmanimation) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinarmanimation, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
this.player.resetIdleTimer();
|
|
+ // CraftBukkit start - Raytrace to look for 'rogue armswings'
|
|
+ float f1 = this.player.getXRot();
|
|
+ float f2 = this.player.getYRot();
|
|
+ double d0 = this.player.locX();
|
|
+ double d1 = this.player.locY() + (double) this.player.getHeadHeight();
|
|
+ double d2 = this.player.locZ();
|
|
+ Vec3D vec3d = new Vec3D(d0, d1, d2);
|
|
+
|
|
+ float f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F);
|
|
+ float f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F);
|
|
+ float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
|
+ float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
|
+ float f7 = f4 * f5;
|
|
+ float f8 = f3 * f5;
|
|
+ double d3 = player.gameMode.getGameMode()== EnumGamemode.CREATIVE ? 5.0D : 4.5D;
|
|
+ Vec3D vec3d1 = vec3d.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
|
|
+ MovingObjectPosition movingobjectposition = this.player.level.rayTrace(new RayTrace(vec3d, vec3d1, RayTrace.BlockCollisionOption.OUTLINE, RayTrace.FluidCollisionOption.NONE, player));
|
|
+
|
|
+ if (movingobjectposition == null || movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.BLOCK) {
|
|
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getItemInHand(), EnumHand.MAIN_HAND);
|
|
+ }
|
|
+
|
|
+ // Arm swing animation
|
|
+ PlayerAnimationEvent event = new PlayerAnimationEvent(this.getPlayer());
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) return;
|
|
+ // CraftBukkit end
|
|
this.player.swingHand(packetplayinarmanimation.b());
|
|
}
|
|
|
|
@Override
|
|
public void a(PacketPlayInEntityAction packetplayinentityaction) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinentityaction, this, this.player.getWorldServer());
|
|
+ // CraftBukkit start
|
|
+ if (this.player.isRemoved()) return;
|
|
+ switch (packetplayinentityaction.c()) {
|
|
+ case PRESS_SHIFT_KEY:
|
|
+ case RELEASE_SHIFT_KEY:
|
|
+ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getPlayer(), packetplayinentityaction.c() == PacketPlayInEntityAction.EnumPlayerAction.PRESS_SHIFT_KEY);
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ break;
|
|
+ case START_SPRINTING:
|
|
+ case STOP_SPRINTING:
|
|
+ PlayerToggleSprintEvent e2 = new PlayerToggleSprintEvent(this.getPlayer(), packetplayinentityaction.c() == PacketPlayInEntityAction.EnumPlayerAction.START_SPRINTING);
|
|
+ this.cserver.getPluginManager().callEvent(e2);
|
|
+
|
|
+ if (e2.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.player.resetIdleTimer();
|
|
IJumpable ijumpable;
|
|
|
|
@@ -1326,6 +2021,7 @@
|
|
@Override
|
|
public void a(PacketPlayInUseEntity packetplayinuseentity) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
WorldServer worldserver = this.player.getWorldServer();
|
|
final Entity entity = packetplayinuseentity.a(worldserver);
|
|
|
|
@@ -1336,10 +2032,44 @@
|
|
|
|
if (this.player.f(entity) < 36.0D) {
|
|
packetplayinuseentity.a(new PacketPlayInUseEntity.c() {
|
|
- private void a(EnumHand enumhand, PlayerConnection.a playerconnection_a) {
|
|
+ private void a(EnumHand enumhand, PlayerConnection.a playerconnection_a, PlayerInteractEntityEvent event) { // CraftBukkit
|
|
ItemStack itemstack = PlayerConnection.this.player.b(enumhand).cloneItemStack();
|
|
+ // CraftBukkit start
|
|
+ ItemStack itemInHand = PlayerConnection.this.player.b(enumhand);
|
|
+ boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof EntityInsentient;
|
|
+ Item origItem = player.getInventory().getItemInHand() == null ? null : player.getInventory().getItemInHand().getItem();
|
|
+
|
|
+ cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ // Fish bucket - SPIGOT-4048
|
|
+ if ((entity instanceof EntityFish && origItem != null && origItem.getItem() == Items.WATER_BUCKET) && (event.isCancelled() || player.getInventory().getItemInHand() == null || player.getInventory().getItemInHand().getItem() != origItem)) {
|
|
+ sendPacket(new PacketPlayOutSpawnEntityLiving((EntityFish) entity));
|
|
+ player.containerMenu.updateInventory();
|
|
+ }
|
|
+
|
|
+ if (triggerLeashUpdate && (event.isCancelled() || player.getInventory().getItemInHand() == null || player.getInventory().getItemInHand().getItem() != origItem)) {
|
|
+ // Refresh the current leash state
|
|
+ sendPacket(new PacketPlayOutAttachEntity(entity, ((EntityInsentient) entity).getLeashHolder()));
|
|
+ }
|
|
+
|
|
+ if (event.isCancelled() || player.getInventory().getItemInHand() == null || player.getInventory().getItemInHand().getItem() != origItem) {
|
|
+ // Refresh the current entity metadata
|
|
+ sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));
|
|
+ }
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
EnumInteractionResult enuminteractionresult = playerconnection_a.run(PlayerConnection.this.player, entity, enumhand);
|
|
|
|
+ // CraftBukkit start
|
|
+ if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
|
|
+ player.containerMenu.updateInventory();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
if (enuminteractionresult.a()) {
|
|
CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.a(PlayerConnection.this.player, itemstack, entity);
|
|
if (enuminteractionresult.b()) {
|
|
@@ -1351,20 +2081,27 @@
|
|
|
|
@Override
|
|
public void a(EnumHand enumhand) {
|
|
- this.a(enumhand, EntityHuman::a);
|
|
+ this.a(enumhand, EntityHuman::a, new PlayerInteractEntityEvent((Player) getPlayer(), entity.getBukkitEntity(), (enumhand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
|
|
}
|
|
|
|
@Override
|
|
public void a(EnumHand enumhand, Vec3D vec3d) {
|
|
this.a(enumhand, (entityplayer, entity1, enumhand1) -> {
|
|
return entity1.a((EntityHuman) entityplayer, vec3d, enumhand1);
|
|
- });
|
|
+ }, new PlayerInteractAtEntityEvent((Player) getPlayer(), entity.getBukkitEntity(), new org.bukkit.util.Vector(vec3d.x, vec3d.y, vec3d.z), (enumhand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); // CraftBukkit
|
|
}
|
|
|
|
@Override
|
|
public void a() {
|
|
- if (!(entity instanceof EntityItem) && !(entity instanceof EntityExperienceOrb) && !(entity instanceof EntityArrow) && entity != PlayerConnection.this.player) {
|
|
+ // CraftBukkit start
|
|
+ if (!(entity instanceof EntityItem) && !(entity instanceof EntityExperienceOrb) && !(entity instanceof EntityArrow) && (entity != PlayerConnection.this.player || player.isSpectator())) {
|
|
+ ItemStack itemInHand = PlayerConnection.this.player.getItemInMainHand();
|
|
PlayerConnection.this.player.attack(entity);
|
|
+
|
|
+ if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
|
|
+ player.containerMenu.updateInventory();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
} else {
|
|
PlayerConnection.this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_entity_attacked"));
|
|
PlayerConnection.LOGGER.warn("Player {} tried to attack an invalid entity", PlayerConnection.this.player.getDisplayName().getString());
|
|
@@ -1409,19 +2146,303 @@
|
|
@Override
|
|
public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer());
|
|
+
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
+ CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit
|
|
+
|
|
this.player.o();
|
|
}
|
|
|
|
@Override
|
|
public void a(PacketPlayInWindowClick packetplayinwindowclick) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinwindowclick, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
this.player.resetIdleTimer();
|
|
- if (this.player.containerMenu.containerId == packetplayinwindowclick.b()) {
|
|
- if (this.player.isSpectator()) {
|
|
+ if (this.player.containerMenu.containerId == packetplayinwindowclick.b() && this.player.containerMenu.canUse(this.player)) { // CraftBukkit
|
|
+ boolean cancelled = this.player.isSpectator(); // CraftBukkit - see below if
|
|
+ if (false/*this.player.isSpectator()*/) { // CraftBukkit
|
|
this.player.containerMenu.updateInventory();
|
|
} else {
|
|
this.player.containerMenu.g();
|
|
- this.player.containerMenu.a(packetplayinwindowclick.c(), packetplayinwindowclick.d(), packetplayinwindowclick.g(), this.player);
|
|
+ // CraftBukkit start - Call InventoryClickEvent
|
|
+ if (packetplayinwindowclick.c() < -1 && packetplayinwindowclick.c() != -999) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ InventoryView inventory = this.player.containerMenu.getBukkitView();
|
|
+ SlotType type = inventory.getSlotType(packetplayinwindowclick.c());
|
|
+
|
|
+ InventoryClickEvent event;
|
|
+ ClickType click = ClickType.UNKNOWN;
|
|
+ InventoryAction action = InventoryAction.UNKNOWN;
|
|
+
|
|
+ ItemStack itemstack = ItemStack.EMPTY;
|
|
+
|
|
+ switch (packetplayinwindowclick.g()) {
|
|
+ case PICKUP:
|
|
+ if (packetplayinwindowclick.d() == 0) {
|
|
+ click = ClickType.LEFT;
|
|
+ } else if (packetplayinwindowclick.d() == 1) {
|
|
+ click = ClickType.RIGHT;
|
|
+ }
|
|
+ if (packetplayinwindowclick.d() == 0 || packetplayinwindowclick.d() == 1) {
|
|
+ action = InventoryAction.NOTHING; // Don't want to repeat ourselves
|
|
+ if (packetplayinwindowclick.c() == -999) {
|
|
+ if (!player.containerMenu.getCarried().isEmpty()) {
|
|
+ action = packetplayinwindowclick.d() == 0 ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR;
|
|
+ }
|
|
+ } else if (packetplayinwindowclick.c() < 0) {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ } else {
|
|
+ Slot slot = this.player.containerMenu.getSlot(packetplayinwindowclick.c());
|
|
+ if (slot != null) {
|
|
+ ItemStack clickedItem = slot.getItem();
|
|
+ ItemStack cursor = player.containerMenu.getCarried();
|
|
+ if (clickedItem.isEmpty()) {
|
|
+ if (!cursor.isEmpty()) {
|
|
+ action = packetplayinwindowclick.d() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE;
|
|
+ }
|
|
+ } else if (slot.isAllowed(player)) {
|
|
+ if (cursor.isEmpty()) {
|
|
+ action = packetplayinwindowclick.d() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF;
|
|
+ } else if (slot.isAllowed(cursor)) {
|
|
+ if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) {
|
|
+ int toPlace = packetplayinwindowclick.d() == 0 ? cursor.getCount() : 1;
|
|
+ toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount());
|
|
+ toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount());
|
|
+ if (toPlace == 1) {
|
|
+ action = InventoryAction.PLACE_ONE;
|
|
+ } else if (toPlace == cursor.getCount()) {
|
|
+ action = InventoryAction.PLACE_ALL;
|
|
+ } else if (toPlace < 0) {
|
|
+ action = toPlace != -1 ? InventoryAction.PICKUP_SOME : InventoryAction.PICKUP_ONE; // this happens with oversized stacks
|
|
+ } else if (toPlace != 0) {
|
|
+ action = InventoryAction.PLACE_SOME;
|
|
+ }
|
|
+ } else if (cursor.getCount() <= slot.getMaxStackSize()) {
|
|
+ action = InventoryAction.SWAP_WITH_CURSOR;
|
|
+ }
|
|
+ } else if (cursor.getItem() == clickedItem.getItem() && ItemStack.equals(cursor, clickedItem)) {
|
|
+ if (clickedItem.getCount() >= 0) {
|
|
+ if (clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) {
|
|
+ // As of 1.5, this is result slots only
|
|
+ action = InventoryAction.PICKUP_ALL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ break;
|
|
+ // TODO check on updates
|
|
+ case QUICK_MOVE:
|
|
+ if (packetplayinwindowclick.d() == 0) {
|
|
+ click = ClickType.SHIFT_LEFT;
|
|
+ } else if (packetplayinwindowclick.d() == 1) {
|
|
+ click = ClickType.SHIFT_RIGHT;
|
|
+ }
|
|
+ if (packetplayinwindowclick.d() == 0 || packetplayinwindowclick.d() == 1) {
|
|
+ if (packetplayinwindowclick.c() < 0) {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ } else {
|
|
+ Slot slot = this.player.containerMenu.getSlot(packetplayinwindowclick.c());
|
|
+ if (slot != null && slot.isAllowed(this.player) && slot.hasItem()) {
|
|
+ action = InventoryAction.MOVE_TO_OTHER_INVENTORY;
|
|
+ } else {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ break;
|
|
+ case SWAP:
|
|
+ if ((packetplayinwindowclick.d() >= 0 && packetplayinwindowclick.d() < 9) || packetplayinwindowclick.d() == 40) {
|
|
+ click = (packetplayinwindowclick.d() == 40) ? ClickType.SWAP_OFFHAND : ClickType.NUMBER_KEY;
|
|
+ Slot clickedSlot = this.player.containerMenu.getSlot(packetplayinwindowclick.c());
|
|
+ if (clickedSlot.isAllowed(player)) {
|
|
+ ItemStack hotbar = this.player.getInventory().getItem(packetplayinwindowclick.d());
|
|
+ boolean canCleanSwap = hotbar.isEmpty() || (clickedSlot.container == player.getInventory() && clickedSlot.isAllowed(hotbar)); // the slot will accept the hotbar item
|
|
+ if (clickedSlot.hasItem()) {
|
|
+ if (canCleanSwap) {
|
|
+ action = InventoryAction.HOTBAR_SWAP;
|
|
+ } else {
|
|
+ action = InventoryAction.HOTBAR_MOVE_AND_READD;
|
|
+ }
|
|
+ } else if (!clickedSlot.hasItem() && !hotbar.isEmpty() && clickedSlot.isAllowed(hotbar)) {
|
|
+ action = InventoryAction.HOTBAR_SWAP;
|
|
+ } else {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ } else {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ }
|
|
+ break;
|
|
+ case CLONE:
|
|
+ if (packetplayinwindowclick.d() == 2) {
|
|
+ click = ClickType.MIDDLE;
|
|
+ if (packetplayinwindowclick.c() < 0) {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ } else {
|
|
+ Slot slot = this.player.containerMenu.getSlot(packetplayinwindowclick.c());
|
|
+ if (slot != null && slot.hasItem() && player.getAbilities().instabuild && player.containerMenu.getCarried().isEmpty()) {
|
|
+ action = InventoryAction.CLONE_STACK;
|
|
+ } else {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ click = ClickType.UNKNOWN;
|
|
+ action = InventoryAction.UNKNOWN;
|
|
+ }
|
|
+ break;
|
|
+ case THROW:
|
|
+ if (packetplayinwindowclick.c() >= 0) {
|
|
+ if (packetplayinwindowclick.d() == 0) {
|
|
+ click = ClickType.DROP;
|
|
+ Slot slot = this.player.containerMenu.getSlot(packetplayinwindowclick.c());
|
|
+ if (slot != null && slot.hasItem() && slot.isAllowed(player) && !slot.getItem().isEmpty() && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
|
|
+ action = InventoryAction.DROP_ONE_SLOT;
|
|
+ } else {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ } else if (packetplayinwindowclick.d() == 1) {
|
|
+ click = ClickType.CONTROL_DROP;
|
|
+ Slot slot = this.player.containerMenu.getSlot(packetplayinwindowclick.c());
|
|
+ if (slot != null && slot.hasItem() && slot.isAllowed(player) && !slot.getItem().isEmpty() && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
|
|
+ action = InventoryAction.DROP_ALL_SLOT;
|
|
+ } else {
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ // Sane default (because this happens when they are holding nothing. Don't ask why.)
|
|
+ click = ClickType.LEFT;
|
|
+ if (packetplayinwindowclick.d() == 1) {
|
|
+ click = ClickType.RIGHT;
|
|
+ }
|
|
+ action = InventoryAction.NOTHING;
|
|
+ }
|
|
+ break;
|
|
+ case QUICK_CRAFT:
|
|
+ this.player.containerMenu.a(packetplayinwindowclick.c(), packetplayinwindowclick.d(), packetplayinwindowclick.g(), this.player);
|
|
+ break;
|
|
+ case PICKUP_ALL:
|
|
+ click = ClickType.DOUBLE_CLICK;
|
|
+ action = InventoryAction.NOTHING;
|
|
+ if (packetplayinwindowclick.c() >= 0 && !this.player.containerMenu.getCarried().isEmpty()) {
|
|
+ ItemStack cursor = this.player.containerMenu.getCarried();
|
|
+ action = InventoryAction.NOTHING;
|
|
+ // Quick check for if we have any of the item
|
|
+ if (inventory.getTopInventory().contains(CraftMagicNumbers.getMaterial(cursor.getItem())) || inventory.getBottomInventory().contains(CraftMagicNumbers.getMaterial(cursor.getItem()))) {
|
|
+ action = InventoryAction.COLLECT_TO_CURSOR;
|
|
+ }
|
|
+ }
|
|
+ break;
|
|
+ default:
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ if (packetplayinwindowclick.g() != InventoryClickType.QUICK_CRAFT) {
|
|
+ if (click == ClickType.NUMBER_KEY) {
|
|
+ event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.c(), click, action, packetplayinwindowclick.d());
|
|
+ } else {
|
|
+ event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.c(), click, action);
|
|
+ }
|
|
+
|
|
+ org.bukkit.inventory.Inventory top = inventory.getTopInventory();
|
|
+ if (packetplayinwindowclick.c() == 0 && top instanceof CraftingInventory) {
|
|
+ org.bukkit.inventory.Recipe recipe = ((CraftingInventory) top).getRecipe();
|
|
+ if (recipe != null) {
|
|
+ if (click == ClickType.NUMBER_KEY) {
|
|
+ event = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.c(), click, action, packetplayinwindowclick.d());
|
|
+ } else {
|
|
+ event = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.c(), click, action);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (packetplayinwindowclick.c() == 2 && top instanceof SmithingInventory) {
|
|
+ org.bukkit.inventory.ItemStack result = ((SmithingInventory) top).getResult();
|
|
+ if (result != null) {
|
|
+ if (click == ClickType.NUMBER_KEY) {
|
|
+ event = new SmithItemEvent(inventory, type, packetplayinwindowclick.c(), click, action, packetplayinwindowclick.d());
|
|
+ } else {
|
|
+ event = new SmithItemEvent(inventory, type, packetplayinwindowclick.c(), click, action);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ event.setCancelled(cancelled);
|
|
+ Container oldContainer = this.player.containerMenu; // SPIGOT-1224
|
|
+ cserver.getPluginManager().callEvent(event);
|
|
+ if (this.player.containerMenu != oldContainer) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ switch (event.getResult()) {
|
|
+ case ALLOW:
|
|
+ case DEFAULT:
|
|
+ this.player.containerMenu.a(packetplayinwindowclick.c(), packetplayinwindowclick.d(), packetplayinwindowclick.g(), this.player);
|
|
+ break;
|
|
+ case DENY:
|
|
+ /* Needs enum constructor in InventoryAction
|
|
+ if (action.modifiesOtherSlots()) {
|
|
+
|
|
+ } else {
|
|
+ if (action.modifiesCursor()) {
|
|
+ this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried()));
|
|
+ }
|
|
+ if (action.modifiesClicked()) {
|
|
+ this.player.playerConnection.sendPacket(new Packet103SetSlot(this.player.activeContainer.windowId, packet102windowclick.slot, this.player.activeContainer.getSlot(packet102windowclick.slot).getItem()));
|
|
+ }
|
|
+ }*/
|
|
+ switch (action) {
|
|
+ // Modified other slots
|
|
+ case PICKUP_ALL:
|
|
+ case MOVE_TO_OTHER_INVENTORY:
|
|
+ case HOTBAR_MOVE_AND_READD:
|
|
+ case HOTBAR_SWAP:
|
|
+ case COLLECT_TO_CURSOR:
|
|
+ case UNKNOWN:
|
|
+ this.player.containerMenu.updateInventory();
|
|
+ break;
|
|
+ // Modified cursor and clicked
|
|
+ case PICKUP_SOME:
|
|
+ case PICKUP_HALF:
|
|
+ case PICKUP_ONE:
|
|
+ case PLACE_ALL:
|
|
+ case PLACE_SOME:
|
|
+ case PLACE_ONE:
|
|
+ case SWAP_WITH_CURSOR:
|
|
+ this.player.connection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.player.containerMenu.getCarried()));
|
|
+ this.player.connection.sendPacket(new PacketPlayOutSetSlot(this.player.containerMenu.containerId, packetplayinwindowclick.c(), this.player.containerMenu.getSlot(packetplayinwindowclick.c()).getItem()));
|
|
+ break;
|
|
+ // Modified clicked only
|
|
+ case DROP_ALL_SLOT:
|
|
+ case DROP_ONE_SLOT:
|
|
+ this.player.connection.sendPacket(new PacketPlayOutSetSlot(this.player.containerMenu.containerId, packetplayinwindowclick.c(), this.player.containerMenu.getSlot(packetplayinwindowclick.c()).getItem()));
|
|
+ break;
|
|
+ // Modified cursor only
|
|
+ case DROP_ALL_CURSOR:
|
|
+ case DROP_ONE_CURSOR:
|
|
+ case CLONE_STACK:
|
|
+ this.player.connection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.player.containerMenu.getCarried()));
|
|
+ break;
|
|
+ // Nothing
|
|
+ case NOTHING:
|
|
+ break;
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (event instanceof CraftItemEvent || event instanceof SmithItemEvent) {
|
|
+ // Need to update the inventory on crafting to
|
|
+ // correctly support custom recipes
|
|
+ player.containerMenu.updateInventory();
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.f()).iterator();
|
|
|
|
while (objectiterator.hasNext()) {
|
|
@@ -1452,6 +2473,7 @@
|
|
@Override
|
|
public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer());
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
this.player.resetIdleTimer();
|
|
if (this.player.containerMenu.containerId == packetplayinenchantitem.b() && !this.player.isSpectator()) {
|
|
this.player.containerMenu.a((EntityHuman) this.player, packetplayinenchantitem.c());
|
|
@@ -1484,6 +2506,43 @@
|
|
|
|
boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45;
|
|
boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
|
|
+ if (flag || (flag1 && !ItemStack.matches(this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.b()).getItem(), packetplayinsetcreativeslot.getItemStack()))) { // Insist on valid slot
|
|
+ // CraftBukkit start - Call click event
|
|
+ InventoryView inventory = this.player.inventoryMenu.getBukkitView();
|
|
+ org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getItemStack());
|
|
+
|
|
+ SlotType type = SlotType.QUICKBAR;
|
|
+ if (flag) {
|
|
+ type = SlotType.OUTSIDE;
|
|
+ } else if (packetplayinsetcreativeslot.b() < 36) {
|
|
+ if (packetplayinsetcreativeslot.b() >= 5 && packetplayinsetcreativeslot.b() < 9) {
|
|
+ type = SlotType.ARMOR;
|
|
+ } else {
|
|
+ type = SlotType.CONTAINER;
|
|
+ }
|
|
+ }
|
|
+ InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.b(), item);
|
|
+ cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ itemstack = CraftItemStack.asNMSCopy(event.getCursor());
|
|
+
|
|
+ switch (event.getResult()) {
|
|
+ case ALLOW:
|
|
+ // Plugin cleared the id / stacksize checks
|
|
+ flag2 = true;
|
|
+ break;
|
|
+ case DEFAULT:
|
|
+ break;
|
|
+ case DENY:
|
|
+ // Reset the slot
|
|
+ if (packetplayinsetcreativeslot.b() >= 0) {
|
|
+ this.player.connection.sendPacket(new PacketPlayOutSetSlot(this.player.inventoryMenu.containerId, packetplayinsetcreativeslot.b(), this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.b()).getItem()));
|
|
+ this.player.connection.sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.EMPTY));
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
if (flag1 && flag2) {
|
|
if (itemstack.isEmpty()) {
|
|
@@ -1511,6 +2570,7 @@
|
|
}
|
|
|
|
private void a(PacketPlayInUpdateSign packetplayinupdatesign, List<ITextFilter.a> list) {
|
|
+ if (this.player.isFrozen()) return; // CraftBukkit
|
|
this.player.resetIdleTimer();
|
|
WorldServer worldserver = this.player.getWorldServer();
|
|
BlockPosition blockposition = packetplayinupdatesign.b();
|
|
@@ -1527,18 +2587,37 @@
|
|
|
|
if (!tileentitysign.d() || !this.player.getUniqueID().equals(tileentitysign.f())) {
|
|
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString());
|
|
+ this.sendPacket(tileentity.getUpdatePacket()); // CraftBukkit
|
|
return;
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ Player player = this.cserver.getPlayer(this.player);
|
|
+ int x = packetplayinupdatesign.b().getX();
|
|
+ int y = packetplayinupdatesign.b().getY();
|
|
+ int z = packetplayinupdatesign.b().getZ();
|
|
+ String[] lines = new String[4];
|
|
+
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
ITextFilter.a itextfilter_a = (ITextFilter.a) list.get(i);
|
|
|
|
if (this.player.R()) {
|
|
- tileentitysign.a(i, new ChatComponentText(itextfilter_a.b()));
|
|
+ lines[i] = EnumChatFormat.a(new ChatComponentText(EnumChatFormat.a(itextfilter_a.b())).getString());
|
|
} else {
|
|
- tileentitysign.a(i, new ChatComponentText(itextfilter_a.a()), new ChatComponentText(itextfilter_a.b()));
|
|
+ lines[i] = EnumChatFormat.a(new ChatComponentText(EnumChatFormat.a(itextfilter_a.a())).getString());
|
|
+ }
|
|
+ }
|
|
+ SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.cserver.getPlayer(this.player), lines);
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (!event.isCancelled()) {
|
|
+ IChatBaseComponent[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
|
|
+ for (int i = 0; i < components.length; i++) {
|
|
+ tileentitysign.a(i, components[i]);
|
|
}
|
|
+ tileentitysign.isEditable = false;
|
|
}
|
|
+ // CraftBukkit end
|
|
|
|
tileentitysign.update();
|
|
worldserver.notify(blockposition, iblockdata, iblockdata, 3);
|
|
@@ -1548,6 +2627,7 @@
|
|
|
|
@Override
|
|
public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
|
|
+ PlayerConnectionUtils.ensureMainThread(packetplayinkeepalive, this, this.player.getWorldServer()); // CraftBukkit
|
|
if (this.keepAlivePending && packetplayinkeepalive.b() == this.keepAliveChallenge) {
|
|
int i = (int) (SystemUtils.getMonotonicMillis() - this.keepAliveTime);
|
|
|
|
@@ -1562,7 +2642,17 @@
|
|
@Override
|
|
public void a(PacketPlayInAbilities packetplayinabilities) {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer());
|
|
- this.player.getAbilities().flying = packetplayinabilities.isFlying() && this.player.getAbilities().mayfly;
|
|
+ // CraftBukkit start
|
|
+ if (this.player.getAbilities().mayfly && this.player.getAbilities().flying != packetplayinabilities.isFlying()) {
|
|
+ PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(this.cserver.getPlayer(this.player), packetplayinabilities.isFlying());
|
|
+ this.cserver.getPluginManager().callEvent(event);
|
|
+ if (!event.isCancelled()) {
|
|
+ this.player.getAbilities().flying = packetplayinabilities.isFlying(); // Actually set the player's flying status
|
|
+ } else {
|
|
+ this.player.updateAbilities(); // Tell the player their ability was reverted
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
@Override
|
|
@@ -1571,8 +2661,50 @@
|
|
this.player.a(packetplayinsettings);
|
|
}
|
|
|
|
- @Override
|
|
- public void a(PacketPlayInCustomPayload packetplayincustompayload) {}
|
|
+ // CraftBukkit start
|
|
+ private static final MinecraftKey CUSTOM_REGISTER = new MinecraftKey("register");
|
|
+ private static final MinecraftKey CUSTOM_UNREGISTER = new MinecraftKey("unregister");
|
|
+
|
|
+ @Override
|
|
+ public void a(PacketPlayInCustomPayload packetplayincustompayload) {
|
|
+ PlayerConnectionUtils.ensureMainThread(packetplayincustompayload, this, this.player.getWorldServer());
|
|
+ if (packetplayincustompayload.identifier.equals(CUSTOM_REGISTER)) {
|
|
+ try {
|
|
+ String channels = packetplayincustompayload.data.toString(com.google.common.base.Charsets.UTF_8);
|
|
+ for (String channel : channels.split("\0")) {
|
|
+ getPlayer().addChannel(channel);
|
|
+ }
|
|
+ } catch (Exception ex) {
|
|
+ PlayerConnection.LOGGER.error("Couldn\'t register custom payload", ex);
|
|
+ this.disconnect("Invalid payload REGISTER!");
|
|
+ }
|
|
+ } else if (packetplayincustompayload.identifier.equals(CUSTOM_UNREGISTER)) {
|
|
+ try {
|
|
+ String channels = packetplayincustompayload.data.toString(com.google.common.base.Charsets.UTF_8);
|
|
+ for (String channel : channels.split("\0")) {
|
|
+ getPlayer().removeChannel(channel);
|
|
+ }
|
|
+ } catch (Exception ex) {
|
|
+ PlayerConnection.LOGGER.error("Couldn\'t unregister custom payload", ex);
|
|
+ this.disconnect("Invalid payload UNREGISTER!");
|
|
+ }
|
|
+ } else {
|
|
+ try {
|
|
+ byte[] data = new byte[packetplayincustompayload.data.readableBytes()];
|
|
+ packetplayincustompayload.data.readBytes(data);
|
|
+ cserver.getMessenger().dispatchIncomingMessage(player.getBukkitEntity(), packetplayincustompayload.identifier.toString(), data);
|
|
+ } catch (Exception ex) {
|
|
+ PlayerConnection.LOGGER.error("Couldn\'t dispatch custom payload", ex);
|
|
+ this.disconnect("Invalid custom payload!");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ }
|
|
+
|
|
+ public final boolean isDisconnected() {
|
|
+ return !this.player.joining && !this.connection.isConnected();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
@Override
|
|
public void a(PacketPlayInDifficultyChange packetplayindifficultychange) {
|