mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Partial fix for async packets
This commit is contained in:
parent
7d5e1b9c34
commit
10f9c4c9f9
@ -2,16 +2,16 @@
|
|||||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||||
* Copyright (C) 2012 Kristian S. Stangeland
|
* Copyright (C) 2012 Kristian S. Stangeland
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
* 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 2 of
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
||||||
* the License, or (at your option) any later version.
|
* 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;
|
* 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.
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
* See the GNU General Public License for more details.
|
* 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;
|
* You should have received a copy of the GNU General Public License along with this program;
|
||||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -26,12 +26,14 @@ import java.util.List;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketStream;
|
import com.comphenix.protocol.PacketStream;
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.events.NetworkMarker;
|
import com.comphenix.protocol.events.NetworkMarker;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.injector.PrioritizedListener;
|
import com.comphenix.protocol.injector.PrioritizedListener;
|
||||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.google.common.primitives.Longs;
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,11 +125,11 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the time the packet was initially queued for asynchronous processing.
|
* Retrieve the time the packet was initially queued for asynchronous processing.
|
||||||
* @return The initial time in number of milliseconds since 01.01.1970 00:00.
|
* @return The initial time in number of milliseconds since 01.01.1970 00:00.
|
||||||
*/
|
*/
|
||||||
public long getInitialTime() {
|
public long getInitialTime() {
|
||||||
return initialTime;
|
return initialTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the time the packet will be forcefully rejected.
|
* Retrieve the time the packet will be forcefully rejected.
|
||||||
@ -209,11 +211,11 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||||||
* Increment the number of times the current packet must be signalled as done before its transmitted.
|
* Increment the number of times the current packet must be signalled as done before its transmitted.
|
||||||
* <p>
|
* <p>
|
||||||
* This is useful if an asynchronous listener is waiting for further information before the
|
* This is useful if an asynchronous listener is waiting for further information before the
|
||||||
* packet can be sent to the user. A packet listener <b>MUST</b> eventually call
|
* packet can be sent to the user. A packet listener <b>MUST</b> eventually call
|
||||||
* {@link AsyncFilterManager#signalPacketTransmission(PacketEvent)},
|
* {@link AsyncFilterManager#signalPacketTransmission(PacketEvent)},
|
||||||
* even if the packet is cancelled, after this method is called.
|
* even if the packet is cancelled, after this method is called.
|
||||||
* <p>
|
* <p>
|
||||||
* It is recommended that processing outside a packet listener is wrapped in a synchronized block
|
* It is recommended that processing outside a packet listener is wrapped in a synchronized block
|
||||||
* using the {@link #getProcessingLock()} method.
|
* using the {@link #getProcessingLock()} method.
|
||||||
*
|
*
|
||||||
* @return The new processing delay.
|
* @return The new processing delay.
|
||||||
@ -331,7 +333,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current asynchronous listener handler.
|
* Set the current asynchronous listener handler.
|
||||||
* <p>
|
* <p>
|
||||||
* Used by the worker to update the value.
|
* Used by the worker to update the value.
|
||||||
* @param listenerHandler - new listener handler.
|
* @param listenerHandler - new listener handler.
|
||||||
@ -415,6 +417,10 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||||||
} else if (methods.size() == 1) {
|
} else if (methods.size() == 1) {
|
||||||
// We're in 1.2.5
|
// We're in 1.2.5
|
||||||
alwaysSync = true;
|
alwaysSync = true;
|
||||||
|
} else if (MinecraftVersion.getCurrentVersion().equals(MinecraftVersion.BOUNTIFUL_UPDATE)) {
|
||||||
|
// The centralized async marker was removed in 1.8
|
||||||
|
// The only packet I know for sure is async is incoming chat
|
||||||
|
return event.getPacketType() == PacketType.Play.Client.CHAT;
|
||||||
} else {
|
} else {
|
||||||
System.err.println("[ProtocolLib] Cannot determine asynchronous state of packets!");
|
System.err.println("[ProtocolLib] Cannot determine asynchronous state of packets!");
|
||||||
alwaysSync = true;
|
alwaysSync = true;
|
||||||
@ -426,7 +432,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// Wrap exceptions
|
// Wrap exceptions
|
||||||
return (Boolean) isMinecraftAsync.invoke(event.getPacket().getHandle());
|
return (Boolean) isMinecraftAsync.invoke(event.getPacket().getHandle());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new FieldAccessException("Illegal argument", e);
|
throw new FieldAccessException("Illegal argument", e);
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Locale;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
@ -310,4 +311,14 @@ public class MinecraftVersion implements Comparable<MinecraftVersion>, Serializa
|
|||||||
public static MinecraftVersion fromServerVersion(String serverVersion) {
|
public static MinecraftVersion fromServerVersion(String serverVersion) {
|
||||||
return new MinecraftVersion(extractVersion(serverVersion));
|
return new MinecraftVersion(extractVersion(serverVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MinecraftVersion currentVersion;
|
||||||
|
|
||||||
|
public static MinecraftVersion getCurrentVersion() {
|
||||||
|
if (currentVersion == null) {
|
||||||
|
currentVersion = new MinecraftVersion(Bukkit.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user