Merge 700012c92c
into 2686c9fec0
This commit is contained in:
commit
97b56ca3f4
|
@ -32,15 +32,7 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -76,7 +68,7 @@ class CommandPacket extends CommandBase {
|
|||
private final PacketTypeParser typeParser = new PacketTypeParser();
|
||||
|
||||
// Paged message
|
||||
private final Map<CommandSender, List<String>> pagedMessage = new WeakHashMap<CommandSender, List<String>>();
|
||||
private final Map<CommandSender, List<String>> pagedMessage = new WeakHashMap<>();
|
||||
|
||||
// Current registered packet types
|
||||
private final PacketTypeSet packetTypes = new PacketTypeSet();
|
||||
|
|
|
@ -16,6 +16,19 @@
|
|||
*/
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.error.DetailedErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.timing.TimedListenerManager;
|
||||
import com.comphenix.protocol.timing.TimingReportGenerator;
|
||||
import com.comphenix.protocol.updater.Updater;
|
||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
import com.comphenix.protocol.utility.Closer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -27,20 +40,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import com.comphenix.protocol.error.DetailedErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.timing.TimedListenerManager;
|
||||
import com.comphenix.protocol.timing.TimingReportGenerator;
|
||||
import com.comphenix.protocol.updater.Updater;
|
||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
import com.comphenix.protocol.utility.Closer;
|
||||
|
||||
/**
|
||||
* Handles the "protocol" administration command.
|
||||
*
|
||||
|
@ -52,9 +51,9 @@ class CommandProtocol extends CommandBase {
|
|||
*/
|
||||
public static final String NAME = "protocol";
|
||||
|
||||
private Plugin plugin;
|
||||
private Updater updater;
|
||||
private ProtocolConfig config;
|
||||
private final Plugin plugin;
|
||||
private final Updater updater;
|
||||
private final ProtocolConfig config;
|
||||
|
||||
public CommandProtocol(ErrorReporter reporter, Plugin plugin, Updater updater, ProtocolConfig config) {
|
||||
super(reporter, CommandBase.PERMISSION_ADMIN, NAME, 1);
|
||||
|
@ -65,27 +64,34 @@ class CommandProtocol extends CommandBase {
|
|||
|
||||
@Override
|
||||
protected boolean handleCommand(CommandSender sender, String[] args) {
|
||||
String subCommand = args[0];
|
||||
|
||||
// Only return TRUE if we executed the correct command
|
||||
if (subCommand.equalsIgnoreCase("config") || subCommand.equalsIgnoreCase("reload")) {
|
||||
reloadConfiguration(sender);
|
||||
} else if (subCommand.equalsIgnoreCase("check")) {
|
||||
checkVersion(sender, true);
|
||||
} else if (subCommand.equalsIgnoreCase("update")) {
|
||||
updateVersion(sender, true);
|
||||
} else if (subCommand.equalsIgnoreCase("timings")) {
|
||||
toggleTimings(sender, args);
|
||||
} else if (subCommand.equalsIgnoreCase("listeners")) {
|
||||
printListeners(sender);
|
||||
} else if (subCommand.equalsIgnoreCase("version")) {
|
||||
printVersion(sender);
|
||||
} else if (subCommand.equalsIgnoreCase("dump")) {
|
||||
dump(sender);
|
||||
} else {
|
||||
return false;
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "config":
|
||||
case "reload":
|
||||
reloadConfiguration(sender);
|
||||
break;
|
||||
case "check":
|
||||
checkVersion(sender, true);
|
||||
break;
|
||||
case "update":
|
||||
updateVersion(sender, true);
|
||||
break;
|
||||
case "timings":
|
||||
toggleTimings(sender, args);
|
||||
break;
|
||||
case "listeners":
|
||||
printListeners(sender);
|
||||
break;
|
||||
case "version":
|
||||
printVersion(sender);
|
||||
break;
|
||||
case "dump":
|
||||
dump(sender);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package com.comphenix.protocol;
|
||||
|
||||
import org.bukkit.conversations.Conversation;
|
||||
import org.bukkit.conversations.ConversationCanceller;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.ExactMatchConversationCanceller;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
import org.bukkit.conversations.*;
|
||||
|
||||
/**
|
||||
* Represents a conversation prompt that accepts a list of lines.
|
||||
|
@ -17,9 +12,9 @@ class MultipleLinesPrompt extends StringPrompt {
|
|||
* Represents a canceller that determines if the multiple lines prompt is finished.
|
||||
* @author Kristian
|
||||
*/
|
||||
public static interface MultipleConversationCanceller extends ConversationCanceller {
|
||||
public interface MultipleConversationCanceller extends ConversationCanceller {
|
||||
@Override
|
||||
public boolean cancelBasedOnInput(ConversationContext context, String currentLine);
|
||||
boolean cancelBasedOnInput(ConversationContext context, String currentLine);
|
||||
|
||||
/**
|
||||
* Determine if the current prompt is done based on the context, last
|
||||
|
@ -31,7 +26,7 @@ class MultipleLinesPrompt extends StringPrompt {
|
|||
* @param lineCount - number of lines.
|
||||
* @return TRUE if we are done, FALSE otherwise.
|
||||
*/
|
||||
public boolean cancelBasedOnInput(ConversationContext context, String currentLine,
|
||||
boolean cancelBasedOnInput(ConversationContext context, String currentLine,
|
||||
StringBuilder lines, int lineCount);
|
||||
}
|
||||
|
||||
|
@ -40,7 +35,7 @@ class MultipleLinesPrompt extends StringPrompt {
|
|||
* @author Kristian
|
||||
*/
|
||||
private static class MultipleWrapper implements MultipleConversationCanceller {
|
||||
private ConversationCanceller canceller;
|
||||
private final ConversationCanceller canceller;
|
||||
|
||||
public MultipleWrapper(ConversationCanceller canceller) {
|
||||
this.canceller = canceller;
|
||||
|
@ -142,7 +137,7 @@ class MultipleLinesPrompt extends StringPrompt {
|
|||
// Save the last line as well
|
||||
context.setSessionData(KEY_LAST, in);
|
||||
context.setSessionData(KEY_LINES, ++count);
|
||||
result.append(in + "\n");
|
||||
result.append(in).append("\n");
|
||||
|
||||
// And we're done
|
||||
if (endMarker.cancelBasedOnInput(context, in, result, count))
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package com.comphenix.protocol;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.collections.IntegerMap;
|
||||
|
@ -12,6 +7,11 @@ import com.google.common.base.Preconditions;
|
|||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Retrieve a packet type based on its version and ID, optionally with protocol and sender too.
|
||||
* @author Kristian
|
||||
|
@ -27,7 +27,7 @@ class PacketTypeLookup {
|
|||
public final IntegerMap<PacketType> STATUS_SERVER = new IntegerMap<>();
|
||||
public final IntegerMap<PacketType> LOGIN_CLIENT = new IntegerMap<>();
|
||||
public final IntegerMap<PacketType> LOGIN_SERVER = new IntegerMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the correct integer map for a specific protocol and sender.
|
||||
* @param protocol - the protocol.
|
||||
|
@ -36,7 +36,7 @@ class PacketTypeLookup {
|
|||
*/
|
||||
public IntegerMap<PacketType> getMap(Protocol protocol, Sender sender) {
|
||||
switch (protocol) {
|
||||
case HANDSHAKING:
|
||||
case HANDSHAKING:
|
||||
return sender == Sender.CLIENT ? HANDSHAKE_CLIENT : HANDSHAKE_SERVER;
|
||||
case PLAY:
|
||||
return sender == Sender.CLIENT ? GAME_CLIENT : GAME_SERVER;
|
||||
|
@ -60,7 +60,7 @@ class PacketTypeLookup {
|
|||
public final Map<String, PacketType> STATUS_SERVER = new ConcurrentHashMap<>();
|
||||
public final Map<String, PacketType> LOGIN_CLIENT = new ConcurrentHashMap<>();
|
||||
public final Map<String, PacketType> LOGIN_SERVER = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the correct integer map for a specific protocol and sender.
|
||||
* @param protocol - the protocol.
|
||||
|
@ -69,7 +69,7 @@ class PacketTypeLookup {
|
|||
*/
|
||||
public Map<String, PacketType> getMap(Protocol protocol, Sender sender) {
|
||||
switch (protocol) {
|
||||
case HANDSHAKING:
|
||||
case HANDSHAKING:
|
||||
return sender == Sender.CLIENT ? HANDSHAKE_CLIENT : HANDSHAKE_SERVER;
|
||||
case PLAY:
|
||||
return sender == Sender.CLIENT ? GAME_CLIENT : GAME_SERVER;
|
||||
|
@ -82,12 +82,12 @@ class PacketTypeLookup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Packet IDs from 1.6.4 and below
|
||||
private final IntegerMap<PacketType> legacyLookup = new IntegerMap<>();
|
||||
private final IntegerMap<PacketType> serverLookup = new IntegerMap<>();
|
||||
private final IntegerMap<PacketType> clientLookup = new IntegerMap<>();
|
||||
|
||||
|
||||
// Packets for 1.7.2
|
||||
private final ProtocolSenderLookup idLookup = new ProtocolSenderLookup();
|
||||
|
||||
|
@ -103,7 +103,7 @@ class PacketTypeLookup {
|
|||
*/
|
||||
public PacketTypeLookup addPacketTypes(Iterable<? extends PacketType> types) {
|
||||
Preconditions.checkNotNull(types, "types cannot be NULL");
|
||||
|
||||
|
||||
for (PacketType type : types) {
|
||||
// Skip unknown current packets
|
||||
if (type.getCurrentId() != PacketType.UNKNOWN_PACKET) {
|
||||
|
@ -114,7 +114,7 @@ class PacketTypeLookup {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a packet type from a legacy (1.6.4 and below) packet ID.
|
||||
* @param packetId - the legacy packet ID.
|
||||
|
@ -123,7 +123,7 @@ class PacketTypeLookup {
|
|||
public PacketType getFromLegacy(int packetId) {
|
||||
return legacyLookup.get(packetId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve an unmodifiable view of all the packet types with this name.
|
||||
* @param name - the name.
|
||||
|
@ -132,28 +132,27 @@ class PacketTypeLookup {
|
|||
public Collection<PacketType> getFromName(String name) {
|
||||
return Collections.unmodifiableCollection(nameLookup.get(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a packet type from a legacy (1.6.4 and below) packet ID.
|
||||
* @param packetId - the legacy packet ID.
|
||||
* @param preference - which packet type to look for first.
|
||||
* @return The corresponding packet type, or NULL if not found.
|
||||
*/
|
||||
public PacketType getFromLegacy(int packetId, Sender preference) {
|
||||
public PacketType getFromLegacy(int packetId, Sender preference) {
|
||||
if (preference == Sender.CLIENT)
|
||||
return getFirst(packetId, clientLookup, serverLookup);
|
||||
else
|
||||
return getFirst(packetId, serverLookup, clientLookup);
|
||||
}
|
||||
|
||||
|
||||
// Helper method for looking up in two sets
|
||||
private <T> T getFirst(int packetId, IntegerMap<T> first, IntegerMap<T> second) {
|
||||
if (first.containsKey(packetId))
|
||||
return first.get(packetId);
|
||||
else
|
||||
return second.get(packetId);
|
||||
T value = first.get(packetId);
|
||||
if (value == null) value = second.get(packetId);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a packet type from a protocol, sender and packet ID.
|
||||
* @param protocol - the current protocol.
|
||||
|
|
|
@ -56,7 +56,7 @@ public class ProtocolConfig {
|
|||
// Defaults
|
||||
private static final long DEFAULT_UPDATER_DELAY = 43200;
|
||||
|
||||
private Plugin plugin;
|
||||
private final Plugin plugin;
|
||||
private Configuration config;
|
||||
private boolean loadingSections;
|
||||
|
||||
|
@ -145,7 +145,7 @@ public class ProtocolConfig {
|
|||
/**
|
||||
* Load data sections.
|
||||
*
|
||||
* @param copyDefaults - whether or not to copy configuration defaults.
|
||||
* @param copyDefaults - whether to copy configuration defaults.
|
||||
*/
|
||||
private void loadSections(boolean copyDefaults) {
|
||||
if (config != null) {
|
||||
|
@ -231,7 +231,7 @@ public class ProtocolConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not ProtocolLib should determine if a new version has been released.
|
||||
* Retrieve whether ProtocolLib should determine if a new version has been released.
|
||||
*
|
||||
* @return TRUE if it should do this automatically, FALSE otherwise.
|
||||
*/
|
||||
|
@ -240,7 +240,7 @@ public class ProtocolConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not ProtocolLib should automatically download the new version.
|
||||
* Retrieve whether ProtocolLib should automatically download the new version.
|
||||
*
|
||||
* @return TRUE if it should, FALSE otherwise.
|
||||
*/
|
||||
|
@ -249,7 +249,7 @@ public class ProtocolConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not debug mode is enabled.
|
||||
* Determine whether debug mode is enabled.
|
||||
* <p>
|
||||
* This grants access to the filter command.
|
||||
*
|
||||
|
@ -260,7 +260,7 @@ public class ProtocolConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set whether or not debug mode is enabled.
|
||||
* Set whether debug mode is enabled.
|
||||
*
|
||||
* @param value - TRUE if it is enabled, FALSE otherwise.
|
||||
*/
|
||||
|
@ -275,7 +275,7 @@ public class ProtocolConfig {
|
|||
* @return Every suppressed report type.
|
||||
*/
|
||||
public ImmutableList<String> getSuppressedReports() {
|
||||
return ImmutableList.copyOf(getGlobalValue(SUPPRESSED_REPORTS, new ArrayList<String>()));
|
||||
return ImmutableList.copyOf(getGlobalValue(SUPPRESSED_REPORTS, new ArrayList<>()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,12 +16,7 @@
|
|||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.async.AsyncFilterManager;
|
||||
import com.comphenix.protocol.error.BasicErrorReporter;
|
||||
import com.comphenix.protocol.error.DelegatedErrorReporter;
|
||||
import com.comphenix.protocol.error.DetailedErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
import com.comphenix.protocol.error.*;
|
||||
import com.comphenix.protocol.injector.InternalManager;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
import com.comphenix.protocol.metrics.Statistics;
|
||||
|
@ -31,14 +26,22 @@ import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
|||
import com.comphenix.protocol.scheduler.Task;
|
||||
import com.comphenix.protocol.updater.Updater;
|
||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
import com.comphenix.protocol.utility.*;
|
||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||
import com.comphenix.protocol.utility.ChatExtensions;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Handler;
|
||||
|
@ -48,13 +51,6 @@ import java.util.logging.Logger;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* The main entry point for ProtocolLib.
|
||||
*
|
||||
|
@ -201,52 +197,45 @@ public class ProtocolLib extends JavaPlugin {
|
|||
*/
|
||||
private void initializeCommands() {
|
||||
// Initialize command handlers
|
||||
for (ProtocolCommand command : ProtocolCommand.values()) {
|
||||
try {
|
||||
switch (command) {
|
||||
case PROTOCOL:
|
||||
this.commandProtocol = new CommandProtocol(reporter, this, this.updater, config);
|
||||
break;
|
||||
case FILTER:
|
||||
this.commandFilter = new CommandFilter(reporter, this, config);
|
||||
break;
|
||||
case PACKET:
|
||||
this.commandPacket = new CommandPacket(reporter, this, logger, this.commandFilter, protocolManager);
|
||||
break;
|
||||
case LOGGING:
|
||||
this.packetLogging = new PacketLogging(this, protocolManager);
|
||||
break;
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (LinkageError e) {
|
||||
logger.warning("Failed to register command " + command.name() + ": " + e);
|
||||
} catch (Throwable e) {
|
||||
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND)
|
||||
.messageParam(command.name(), e.getMessage()).error(e));
|
||||
}
|
||||
String commandName = "?";
|
||||
try {
|
||||
commandName = "PROTOCOL";
|
||||
this.commandProtocol = new CommandProtocol(reporter, this, this.updater, config);
|
||||
commandName = "FILTER";
|
||||
this.commandFilter = new CommandFilter(reporter, this, config);
|
||||
commandName = "PACKET";
|
||||
this.commandPacket = new CommandPacket(reporter, this, logger, this.commandFilter, protocolManager);
|
||||
commandName = "LOGGING";
|
||||
this.packetLogging = new PacketLogging(this, protocolManager);
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (LinkageError e) {
|
||||
logger.warning("Failed to register command " + commandName + ": " + e);
|
||||
} catch (Throwable e) {
|
||||
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND)
|
||||
.messageParam(commandName, e.getMessage()).error(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a error reporter that may be filtered by the configuration.
|
||||
* Retrieve an error reporter that may be filtered by the configuration.
|
||||
*
|
||||
* @return The new default error reporter.
|
||||
*/
|
||||
private ErrorReporter getFilteredReporter(ErrorReporter reporter) {
|
||||
return new DelegatedErrorReporter(reporter) {
|
||||
private int lastModCount = -1;
|
||||
private Set<String> reports = new HashSet<>();
|
||||
private Set<String> reports;
|
||||
|
||||
@Override
|
||||
protected Report filterReport(Object sender, Report report, boolean detailed) {
|
||||
try {
|
||||
String canonicalName = ReportType.getReportName(sender, report.getType());
|
||||
String reportName = Iterables.getLast(Splitter.on("#").split(canonicalName)).toUpperCase();
|
||||
final String canonicalName = ReportType.getReportName(sender, report.getType());
|
||||
final String reportName = Iterables.getLast(Splitter.on("#").split(canonicalName)).toUpperCase();
|
||||
|
||||
if (config != null && config.getModificationCount() != this.lastModCount) {
|
||||
// Update our cached set again
|
||||
this.reports = new HashSet<>(config.getSuppressedReports());
|
||||
this.reports = ImmutableSet.copyOf(config.getSuppressedReports());
|
||||
this.lastModCount = config.getModificationCount();
|
||||
}
|
||||
|
||||
|
@ -288,10 +277,10 @@ public class ProtocolLib extends JavaPlugin {
|
|||
// Broadcast information to every user too
|
||||
this.redirectHandler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
public void publish(LogRecord logRecord) {
|
||||
// Only display warnings and above
|
||||
if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
|
||||
ProtocolLib.this.commandPacket.broadcastMessageSilently(record.getMessage(), permission);
|
||||
if (logRecord.getLevel().intValue() >= Level.WARNING.intValue()) {
|
||||
ProtocolLib.this.commandPacket.broadcastMessageSilently(logRecord.getMessage(), permission);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -614,12 +603,4 @@ public class ProtocolLib extends JavaPlugin {
|
|||
public ProtocolScheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
// Different commands
|
||||
private enum ProtocolCommand {
|
||||
FILTER,
|
||||
PACKET,
|
||||
PROTOCOL,
|
||||
LOGGING
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ package com.comphenix.protocol;
|
|||
import com.comphenix.protocol.error.BasicErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import java.util.List;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The main entry point for ProtocolLib.
|
||||
* @author dmulloy2
|
||||
|
|
|
@ -17,19 +17,13 @@
|
|||
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.google.common.collect.ContiguousSet;
|
||||
import com.google.common.collect.DiscreteDomain;
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Used to parse ranges in CommandPacket.
|
||||
*
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
final class RangeParser {
|
||||
|
@ -44,7 +38,7 @@ final class RangeParser {
|
|||
public static List<Range<Integer>> getRanges(String text, Range<Integer> legalRange) {
|
||||
return getRanges(new ArrayDeque<>(Collections.singletonList(text)), legalRange);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse ranges from an array of elements.
|
||||
* @param input the input to parse the ranges from
|
||||
|
@ -54,12 +48,12 @@ final class RangeParser {
|
|||
public static List<Range<Integer>> getRanges(Deque<String> input, Range<Integer> legalRange) {
|
||||
List<String> tokens = tokenizeInput(input);
|
||||
List<Range<Integer>> ranges = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < tokens.size(); i++) {
|
||||
Range<Integer> range;
|
||||
String current = tokens.get(i);
|
||||
String next = i + 1 < tokens.size() ? tokens.get(i + 1) : null;
|
||||
|
||||
|
||||
// Yoda equality is done for null-safety
|
||||
if ("-".equals(current)) {
|
||||
throw new IllegalArgumentException("A hyphen must appear between two numbers.");
|
||||
|
@ -70,71 +64,65 @@ final class RangeParser {
|
|||
// This is a proper range
|
||||
range = Range.closed(Integer.parseInt(current), Integer.parseInt(tokens.get(i + 2)));
|
||||
ranges.add(range);
|
||||
|
||||
|
||||
// Skip the two next tokens
|
||||
i += 2;
|
||||
|
||||
|
||||
} else {
|
||||
// Just a single number
|
||||
range = Range.singleton(Integer.parseInt(current));
|
||||
ranges.add(range);
|
||||
}
|
||||
|
||||
|
||||
// Validate ranges
|
||||
if (!legalRange.encloses(range)) {
|
||||
throw new IllegalArgumentException(range + " is not in the range " + range.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return simplify(ranges, legalRange.upperEndpoint());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simplify a list of ranges by assuming a maximum value.
|
||||
* Simplify a list of closed ranges by assuming that no range exceeds a certain maximum value.
|
||||
* @param ranges - the list of ranges to simplify.
|
||||
* @param maximum - the maximum value (minimum value is always 0).
|
||||
* @return A simplified list of ranges.
|
||||
*/
|
||||
private static List<Range<Integer>> simplify(List<Range<Integer>> ranges, int maximum) {
|
||||
List<Range<Integer>> result = new ArrayList<>();
|
||||
boolean[] set = new boolean[maximum + 1];
|
||||
int start = -1;
|
||||
|
||||
final List<Range<Integer>> result = new ArrayList<>();
|
||||
// + 1 to make sure we always have one bit in the end that is not set.
|
||||
final BitSet bitSet = new BitSet(maximum + 1);
|
||||
|
||||
// Set every ID
|
||||
for (Range<Integer> range : ranges) {
|
||||
for (int id : ContiguousSet.create(range, DiscreteDomain.integers())) {
|
||||
set[id] = true;
|
||||
}
|
||||
bitSet.set(range.lowerEndpoint(), range.upperEndpoint() + 1);
|
||||
}
|
||||
|
||||
// Generate ranges from this set
|
||||
for (int i = 0; i <= set.length; i++) {
|
||||
if (i < set.length && set[i]) {
|
||||
if (start < 0) {
|
||||
start = i;
|
||||
}
|
||||
} else {
|
||||
if (start >= 0) {
|
||||
result.add(Range.closed(start, i - 1));
|
||||
start = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
while (true) {
|
||||
start = bitSet.nextSetBit(end);
|
||||
if(start == -1) break;
|
||||
end = bitSet.nextClearBit(start);
|
||||
|
||||
result.add(Range.closed(start, end - 1));
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static List<String> tokenizeInput(Deque<String> input) {
|
||||
List<String> tokens = new ArrayList<>();
|
||||
|
||||
|
||||
// Tokenize the input
|
||||
while (!input.isEmpty()) {
|
||||
StringBuilder number = new StringBuilder();
|
||||
String text = input.peek();
|
||||
|
||||
|
||||
for (int j = 0; j < text.length(); j++) {
|
||||
char current = text.charAt(j);
|
||||
|
||||
|
||||
if (Character.isDigit(current)) {
|
||||
number.append(current);
|
||||
} else if (Character.isWhitespace(current)) {
|
||||
|
@ -145,20 +133,20 @@ final class RangeParser {
|
|||
tokens.add(number.toString());
|
||||
number.setLength(0);
|
||||
}
|
||||
|
||||
|
||||
tokens.add(Character.toString(current));
|
||||
} else {
|
||||
// We're no longer dealing with integers - quit
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add the number token, if it hasn't already
|
||||
if (number.length() > 0)
|
||||
tokens.add(number.toString());
|
||||
input.poll();
|
||||
}
|
||||
|
||||
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,6 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.comphenix.protocol.AsynchronousManager;
|
||||
import com.comphenix.protocol.PacketStream;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
|
@ -37,10 +31,15 @@ import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
|||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Represents a filter manager for asynchronous packets.
|
||||
* <p>
|
||||
|
@ -52,10 +51,10 @@ public class AsyncFilterManager implements AsynchronousManager {
|
|||
|
||||
private SortedPacketListenerList serverTimeoutListeners;
|
||||
private SortedPacketListenerList clientTimeoutListeners;
|
||||
private Set<PacketListener> timeoutListeners;
|
||||
private final Set<PacketListener> timeoutListeners;
|
||||
|
||||
private PacketProcessingQueue serverProcessingQueue;
|
||||
private PacketProcessingQueue clientProcessingQueue;
|
||||
private final PacketProcessingQueue serverProcessingQueue;
|
||||
private final PacketProcessingQueue clientProcessingQueue;
|
||||
|
||||
// Sending queues
|
||||
private final PlayerSendingHandler playerSendingHandler;
|
||||
|
@ -163,7 +162,7 @@ public class AsyncFilterManager implements AsynchronousManager {
|
|||
* If you already have a synchronous event, call this method with autoInject set to FALSE.
|
||||
*
|
||||
* @param listener - the packet listener that will receive these asynchronous events.
|
||||
* @param autoInject - whether or not to automatically create the corresponding synchronous listener,
|
||||
* @param autoInject - whether to automatically create the corresponding synchronous listener,
|
||||
* @return An asynchronous handler.
|
||||
*/
|
||||
public AsyncListenerHandler registerAsyncHandler(PacketListener listener, boolean autoInject) {
|
||||
|
@ -460,7 +459,7 @@ public class AsyncFilterManager implements AsynchronousManager {
|
|||
/**
|
||||
* Send any due packets, or clean up packets that have expired.
|
||||
* @param tickCounter Tick counter
|
||||
* @param onMainThread Whether or not to execute on the main thread
|
||||
* @param onMainThread Whether to execute on the main thread
|
||||
*/
|
||||
public void sendProcessedPackets(int tickCounter, boolean onMainThread) {
|
||||
// The server queue is unlikely to need checking that often
|
||||
|
|
|
@ -17,13 +17,6 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
|
@ -37,9 +30,15 @@ import com.comphenix.protocol.timing.TimedListenerManager.ListenerType;
|
|||
import com.comphenix.protocol.timing.TimedTracker;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Represents a handler for an asynchronous event.
|
||||
* <p>
|
||||
|
@ -78,30 +77,30 @@ public class AsyncListenerHandler {
|
|||
private final AtomicInteger started = new AtomicInteger();
|
||||
|
||||
// The packet listener
|
||||
private PacketListener listener;
|
||||
private final PacketListener listener;
|
||||
|
||||
// The filter manager
|
||||
private AsyncFilterManager filterManager;
|
||||
private final AsyncFilterManager filterManager;
|
||||
private NullPacketListener nullPacketListener;
|
||||
|
||||
// List of queued packets
|
||||
private ArrayBlockingQueue<PacketEvent> queuedPackets = new ArrayBlockingQueue<PacketEvent>(DEFAULT_CAPACITY);
|
||||
private final ArrayBlockingQueue<PacketEvent> queuedPackets = new ArrayBlockingQueue<>(DEFAULT_CAPACITY);
|
||||
|
||||
// List of cancelled tasks
|
||||
private final Set<Integer> stoppedTasks = new HashSet<Integer>();
|
||||
private final Set<Integer> stoppedTasks = new HashSet<>();
|
||||
private final Object stopLock = new Object();
|
||||
|
||||
// Processing task on the main thread
|
||||
private Task syncTask = null;
|
||||
|
||||
// Minecraft main thread
|
||||
private Thread mainThread;
|
||||
private final Thread mainThread;
|
||||
|
||||
// Warn plugins that the async listener handler must be started
|
||||
private Task warningTask;
|
||||
|
||||
// Timing manager
|
||||
private TimedListenerManager timedManager = TimedListenerManager.getInstance();
|
||||
private final TimedListenerManager timedManager = TimedListenerManager.getInstance();
|
||||
|
||||
/**
|
||||
* Construct a manager for an asynchronous packet handler.
|
||||
|
@ -354,10 +353,7 @@ public class AsyncListenerHandler {
|
|||
* @return A comma separated list of packet IDs in the whitelist, or the emtpy string.
|
||||
*/
|
||||
private String fromWhitelist(ListeningWhitelist whitelist) {
|
||||
if (whitelist == null)
|
||||
return "";
|
||||
else
|
||||
return Joiner.on(", ").join(whitelist.getTypes());
|
||||
return whitelist == null ? "" : Joiner.on(", ").join(whitelist.getTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -623,9 +619,7 @@ public class AsyncListenerHandler {
|
|||
}
|
||||
}
|
||||
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (ThreadDeath e) {
|
||||
} catch (OutOfMemoryError | ThreadDeath e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
// Minecraft doesn't want your Exception.
|
||||
|
@ -634,7 +628,7 @@ public class AsyncListenerHandler {
|
|||
|
||||
// Now, get the next non-cancelled listener
|
||||
if (!marker.hasExpired()) {
|
||||
for (; marker.getListenerTraversal().hasNext(); ) {
|
||||
while (marker.getListenerTraversal().hasNext()) {
|
||||
AsyncListenerHandler handler = marker.getListenerTraversal().next().getListener();
|
||||
|
||||
if (!handler.isCancelled()) {
|
||||
|
@ -669,7 +663,7 @@ public class AsyncListenerHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* Use the poision pill method to stop every worker thread.
|
||||
* Use the poison pill method to stop every worker thread.
|
||||
*/
|
||||
private void stopThreads() {
|
||||
// Poison Pill Shutdown
|
||||
|
|
|
@ -17,15 +17,6 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.comphenix.protocol.PacketStream;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
|
@ -38,6 +29,15 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.google.common.primitives.Longs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Contains information about the packet that is being processed by asynchronous listeners.
|
||||
* <p>
|
||||
|
@ -53,7 +53,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
private static final long serialVersionUID = -2621498096616187384L;
|
||||
|
||||
/**
|
||||
* Default number of milliseconds until a packet will rejected.
|
||||
* Default number of milliseconds until a packet will be rejected.
|
||||
*/
|
||||
public static final int DEFAULT_TIMEOUT_DELTA = 1800 * 1000;
|
||||
|
||||
|
@ -83,17 +83,17 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
// Used to determine if a packet must be reordered in the sending queue
|
||||
private Long queuedSendingIndex;
|
||||
|
||||
// Whether or not the packet has been processed by the listeners
|
||||
// Whether the packet has been processed by the listeners
|
||||
private volatile boolean processed;
|
||||
|
||||
// Whether or not the packet has been sent
|
||||
// Whether the packet has been sent
|
||||
private volatile boolean transmitted;
|
||||
|
||||
// Whether or not the asynchronous processing itself should be cancelled
|
||||
// Whether the asynchronous processing itself should be cancelled
|
||||
private volatile boolean asyncCancelled;
|
||||
|
||||
// Whether or not to delay processing
|
||||
private AtomicInteger processingDelay = new AtomicInteger();
|
||||
// Whether to delay processing
|
||||
private final AtomicInteger processingDelay = new AtomicInteger();
|
||||
|
||||
// Used to synchronize processing on the shared PacketEvent
|
||||
private Object processingLock = new Object();
|
||||
|
@ -103,11 +103,11 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
private transient int workerID;
|
||||
|
||||
// Determine if Minecraft processes this packet asynchronously
|
||||
private volatile static Method isMinecraftAsync;
|
||||
private volatile static boolean alwaysSync;
|
||||
private static volatile Method isMinecraftAsync;
|
||||
private static volatile boolean alwaysSync;
|
||||
|
||||
/**
|
||||
* Create a container for asyncronous packets.
|
||||
* Create a container for asynchronous packets.
|
||||
* @param initialTime - the current time in milliseconds since 01.01.1970 00:00.
|
||||
*/
|
||||
AsyncMarker(PacketStream packetStream, long sendingIndex, long initialTime, long timeoutDelta) {
|
||||
|
@ -194,7 +194,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not this packet has been processed by the async listeners.
|
||||
* Retrieve whether this packet has been processed by the async listeners.
|
||||
* @return TRUE if it has been processed, FALSE otherwise.
|
||||
*/
|
||||
public boolean isProcessed() {
|
||||
|
@ -202,7 +202,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not this packet has been processed by the async listeners.
|
||||
* Sets whether this packet has been processed by the async listeners.
|
||||
* @param processed - TRUE if it has, FALSE otherwise.
|
||||
*/
|
||||
void setProcessed(boolean processed) {
|
||||
|
@ -315,7 +315,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the asynchronous handling should be cancelled.
|
||||
* Set whether the asynchronous handling should be cancelled.
|
||||
* <p>
|
||||
* This is only relevant during the synchronous processing. Asynchronous
|
||||
* listeners should use the normal cancel-field to cancel a PacketEvent.
|
||||
|
@ -457,10 +457,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
|||
|
||||
@Override
|
||||
public int compareTo(AsyncMarker o) {
|
||||
if (o == null)
|
||||
return 1;
|
||||
else
|
||||
return Longs.compare(getNewSendingIndex(), o.getNewSendingIndex());
|
||||
return o == null ? 1 : Longs.compare(getNewSendingIndex(), o.getNewSendingIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,7 @@ public interface AsyncRunnable extends Runnable {
|
|||
* Retrieve a unique worker ID.
|
||||
* @return Unique worker ID.
|
||||
*/
|
||||
public int getID();
|
||||
int getID();
|
||||
|
||||
/**
|
||||
* Stop the given runnable.
|
||||
|
@ -37,13 +37,13 @@ public interface AsyncRunnable extends Runnable {
|
|||
* @return TRUE if the thread was stopped, FALSE if it was already stopped.
|
||||
* @throws InterruptedException if it is interrupted
|
||||
*/
|
||||
public boolean stop() throws InterruptedException;
|
||||
boolean stop() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Determine if we're running or not.
|
||||
* @return TRUE if we're running, FALSE otherwise.
|
||||
*/
|
||||
public boolean isRunning();
|
||||
boolean isRunning();
|
||||
|
||||
/**
|
||||
* Determine if this runnable has already run its course.
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package com.comphenix.protocol.async;
|
||||
|
||||
import com.comphenix.protocol.events.*;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
|
@ -28,9 +27,9 @@ import org.bukkit.plugin.Plugin;
|
|||
*/
|
||||
class NullPacketListener implements PacketListener {
|
||||
|
||||
private ListeningWhitelist sendingWhitelist;
|
||||
private ListeningWhitelist receivingWhitelist;
|
||||
private Plugin plugin;
|
||||
private final ListeningWhitelist sendingWhitelist;
|
||||
private final ListeningWhitelist receivingWhitelist;
|
||||
private final Plugin plugin;
|
||||
|
||||
/**
|
||||
* Create a no-op listener with the same whitelist and plugin as the given listener.
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.google.common.primitives.Longs;
|
|||
*/
|
||||
class PacketEventHolder implements Comparable<PacketEventHolder> {
|
||||
|
||||
private PacketEvent event;
|
||||
private final PacketEvent event;
|
||||
private long sendingIndex = 0;
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,12 +17,6 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
|
@ -31,6 +25,12 @@ import com.comphenix.protocol.events.PacketEvent;
|
|||
import com.comphenix.protocol.injector.PrioritizedListener;
|
||||
import com.google.common.collect.MinMaxPriorityQueue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
|
||||
/**
|
||||
* Handles the processing of every packet type.
|
||||
|
@ -58,13 +58,13 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||
* Number of packets we're processing concurrently.
|
||||
*/
|
||||
private final int maximumConcurrency;
|
||||
private Semaphore concurrentProcessing;
|
||||
private final Semaphore concurrentProcessing;
|
||||
|
||||
// Queued packets for being processed
|
||||
private Queue<PacketEventHolder> processingQueue;
|
||||
|
||||
// Packets for sending
|
||||
private PlayerSendingHandler sendingHandler;
|
||||
private final PlayerSendingHandler sendingHandler;
|
||||
|
||||
public PacketProcessingQueue(PlayerSendingHandler sendingHandler) {
|
||||
this(sendingHandler, INITIAL_CAPACITY, DEFAULT_QUEUE_LIMIT, DEFAULT_MAXIMUM_CONCURRENCY);
|
||||
|
@ -77,15 +77,14 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||
this.processingQueue = Synchronization.queue(MinMaxPriorityQueue.
|
||||
expectedSize(initialSize).
|
||||
maximumSize(maximumSize).
|
||||
<PacketEventHolder>create(), null);
|
||||
create(), null);
|
||||
} catch (IncompatibleClassChangeError e) {
|
||||
// Print in the console
|
||||
ProtocolLibrary.getErrorReporter().reportWarning(
|
||||
this, Report.newBuilder(REPORT_GUAVA_CORRUPT_MISSING).error(e));
|
||||
|
||||
// It's a Beta class after all
|
||||
this.processingQueue = Synchronization.queue(
|
||||
new PriorityQueue<PacketEventHolder>(), null);
|
||||
this.processingQueue = Synchronization.queue(new PriorityQueue<>(), null);
|
||||
}
|
||||
|
||||
this.maximumConcurrency = maximumConcurrency;
|
||||
|
@ -96,8 +95,8 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||
/**
|
||||
* Enqueue a packet for processing by the asynchronous listeners.
|
||||
* @param packet - packet to process.
|
||||
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||
* @return TRUE if we sucessfully queued the packet, FALSE if the queue ran out if space.
|
||||
* @param onMainThread - whether this is occurring on the main thread.
|
||||
* @return TRUE if we successfully queued the packet, FALSE if the queue ran out if space.
|
||||
*/
|
||||
public boolean enqueue(PacketEvent packet, boolean onMainThread) {
|
||||
try {
|
||||
|
@ -121,46 +120,45 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||
|
||||
/**
|
||||
* Called by the current method and each thread to signal that a packet might be ready for processing.
|
||||
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||
* @param onMainThread - whether this is occurring on the main thread.
|
||||
*/
|
||||
public void signalBeginProcessing(boolean onMainThread) {
|
||||
while (concurrentProcessing.tryAcquire()) {
|
||||
PacketEventHolder holder = processingQueue.poll();
|
||||
|
||||
// Any packet queued?
|
||||
if (holder != null) {
|
||||
PacketEvent packet = holder.getEvent();
|
||||
AsyncMarker marker = packet.getAsyncMarker();
|
||||
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketType());
|
||||
|
||||
marker.incrementProcessingDelay();
|
||||
|
||||
// Yes, removing the marker will cause the chain to stop
|
||||
if (list != null) {
|
||||
Iterator<PrioritizedListener<AsyncListenerHandler>> iterator = list.iterator();
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
marker.setListenerTraversal(iterator);
|
||||
iterator.next().getListener().enqueuePacket(packet);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// The packet has no further listeners. Just send it.
|
||||
if (marker.decrementProcessingDelay() == 0) {
|
||||
PacketSendingQueue sendingQueue = sendingHandler.getSendingQueue(packet, false);
|
||||
|
||||
// In case the player has logged out
|
||||
if (sendingQueue != null)
|
||||
sendingQueue.signalPacketUpdate(packet, onMainThread);
|
||||
}
|
||||
signalProcessingDone();
|
||||
|
||||
} else {
|
||||
if (holder == null) {
|
||||
// No more queued packets.
|
||||
signalProcessingDone();
|
||||
return;
|
||||
}
|
||||
|
||||
PacketEvent packet = holder.getEvent();
|
||||
AsyncMarker marker = packet.getAsyncMarker();
|
||||
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketType());
|
||||
|
||||
marker.incrementProcessingDelay();
|
||||
|
||||
// Yes, removing the marker will cause the chain to stop
|
||||
if (list != null) {
|
||||
Iterator<PrioritizedListener<AsyncListenerHandler>> iterator = list.iterator();
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
marker.setListenerTraversal(iterator);
|
||||
iterator.next().getListener().enqueuePacket(packet);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// The packet has no further listeners. Just send it.
|
||||
if (marker.decrementProcessingDelay() == 0) {
|
||||
PacketSendingQueue sendingQueue = sendingHandler.getSendingQueue(packet, false);
|
||||
|
||||
// In case the player has logged out
|
||||
if (sendingQueue != null)
|
||||
sendingQueue.signalPacketUpdate(packet, onMainThread);
|
||||
}
|
||||
signalProcessingDone();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -24,12 +29,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Represents packets ready to be transmitted to a client.
|
||||
*
|
||||
|
@ -38,18 +37,18 @@ import org.bukkit.entity.Player;
|
|||
abstract class PacketSendingQueue {
|
||||
|
||||
public static final int INITIAL_CAPACITY = 10;
|
||||
// Whether or not packet transmission must occur on a specific thread
|
||||
// Whether packet transmission must occur on a specific thread
|
||||
private final boolean notThreadSafe;
|
||||
private final PriorityBlockingQueue<PacketEventHolder> sendingQueue;
|
||||
// Asynchronous packet sending
|
||||
private final Executor asynchronousSender;
|
||||
// Whether or not we've run the cleanup procedure
|
||||
// Whether we've run the cleanup procedure
|
||||
private boolean cleanedUp = false;
|
||||
|
||||
/**
|
||||
* Create a packet sending queue.
|
||||
*
|
||||
* @param notThreadSafe - whether or not to synchronize with the main thread or a background thread.
|
||||
* @param notThreadSafe - whether to synchronize with the main thread or a background thread.
|
||||
*/
|
||||
public PacketSendingQueue(boolean notThreadSafe, Executor asynchronousSender) {
|
||||
this.sendingQueue = new PriorityBlockingQueue<>(INITIAL_CAPACITY);
|
||||
|
@ -79,7 +78,7 @@ abstract class PacketSendingQueue {
|
|||
* Invoked when one of the packets have finished processing.
|
||||
*
|
||||
* @param packetUpdated - the packet that has now been updated.
|
||||
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||
* @param onMainThread - whether this is occurring on the main thread.
|
||||
*/
|
||||
public synchronized void signalPacketUpdate(PacketEvent packetUpdated, boolean onMainThread) {
|
||||
|
||||
|
@ -105,7 +104,7 @@ abstract class PacketSendingQueue {
|
|||
/***
|
||||
* Invoked when a list of packet IDs are no longer associated with any listeners.
|
||||
* @param packetsRemoved - packets that no longer have any listeners.
|
||||
* @param onMainThread - whether or not this is occurring on the main thread.
|
||||
* @param onMainThread - whether this is occurring on the main thread.
|
||||
*/
|
||||
public synchronized void signalPacketUpdate(List<PacketType> packetsRemoved, boolean onMainThread) {
|
||||
Set<PacketType> lookup = new HashSet<>(packetsRemoved);
|
||||
|
@ -126,10 +125,10 @@ abstract class PacketSendingQueue {
|
|||
/**
|
||||
* Attempt to send any remaining packets.
|
||||
*
|
||||
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||
* @param onMainThread - whether this is occurring on the main thread.
|
||||
*/
|
||||
public void trySendPackets(boolean onMainThread) {
|
||||
// Whether or not to continue sending packets
|
||||
// Whether to continue sending packets
|
||||
boolean sending = true;
|
||||
|
||||
// Transmit as many packets as we can
|
||||
|
@ -255,7 +254,7 @@ abstract class PacketSendingQueue {
|
|||
}
|
||||
|
||||
/**
|
||||
* Whether or not the packet transmission must synchronize with the main thread.
|
||||
* Whether the packet transmission must synchronize with the main thread.
|
||||
*
|
||||
* @return TRUE if it must, FALSE otherwise.
|
||||
*/
|
||||
|
|
|
@ -17,22 +17,21 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.concurrency.ConcurrentPlayerMap;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.SortedPacketListenerList;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Contains every sending queue for every player.
|
||||
*
|
||||
|
@ -49,7 +48,7 @@ class PlayerSendingHandler {
|
|||
// Asynchronous packet sending
|
||||
private Executor asynchronousSender;
|
||||
|
||||
// Whether or not we're currently cleaning up
|
||||
// Whether we're currently cleaning up
|
||||
private volatile boolean cleaningUp;
|
||||
|
||||
/**
|
||||
|
@ -221,11 +220,9 @@ class PlayerSendingHandler {
|
|||
* @return Every sever packet queue.
|
||||
*/
|
||||
public List<PacketSendingQueue> getServerQueues() {
|
||||
List<PacketSendingQueue> result = new ArrayList<>();
|
||||
|
||||
for (QueueContainer queue : playerSendingQueues.values())
|
||||
result.add(queue.getServerQueue());
|
||||
return result;
|
||||
return playerSendingQueues.values().stream()
|
||||
.map(QueueContainer::getServerQueue)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,11 +230,9 @@ class PlayerSendingHandler {
|
|||
* @return Every client packet queue.
|
||||
*/
|
||||
public List<PacketSendingQueue> getClientQueues() {
|
||||
List<PacketSendingQueue> result = new ArrayList<>();
|
||||
|
||||
for (QueueContainer queue : playerSendingQueues.values())
|
||||
result.add(queue.getClientQueue());
|
||||
return result;
|
||||
return playerSendingQueues.values().stream()
|
||||
.map(QueueContainer::getClientQueue)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
|
||||
package com.comphenix.protocol.async;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Queue;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* Synchronization views copied from Google Guava.
|
||||
*
|
||||
|
@ -43,8 +43,7 @@ class Synchronization {
|
|||
*/
|
||||
public static <E> Queue<E> queue(Queue<E> queue, @Nullable Object mutex) {
|
||||
return (queue instanceof SynchronizedQueue) ?
|
||||
queue :
|
||||
new SynchronizedQueue<E>(queue, mutex);
|
||||
queue : new SynchronizedQueue<>(queue, mutex);
|
||||
}
|
||||
|
||||
private static class SynchronizedObject implements Serializable {
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.comphenix.protocol.PacketType;
|
|||
import com.comphenix.protocol.events.ListeningWhitelist;
|
||||
import com.comphenix.protocol.injector.PrioritizedListener;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -95,7 +96,7 @@ public abstract class AbstractConcurrentListenerMultimap<T> {
|
|||
|
||||
// Remove any listeners
|
||||
// Remove this listener. Note that priority is generally ignored.
|
||||
list.remove(new PrioritizedListener<T>(listener, whitelist.getPriority()));
|
||||
list.remove(new PrioritizedListener<>(listener, whitelist.getPriority()));
|
||||
|
||||
if (list.isEmpty()) {
|
||||
this.mapListeners.remove(type);
|
||||
|
|
|
@ -77,7 +77,7 @@ public class BlockingHashMap<TKey, TValue> {
|
|||
}
|
||||
}
|
||||
}).
|
||||
build(BlockingHashMap.<TKey, TValue> newInvalidCacheLoader());
|
||||
build(BlockingHashMap.newInvalidCacheLoader());
|
||||
|
||||
// Normal concurrent hash map
|
||||
locks = new ConcurrentHashMap<>();
|
||||
|
|
|
@ -17,6 +17,20 @@
|
|||
|
||||
package com.comphenix.protocol.error;
|
||||
|
||||
import com.comphenix.protocol.ProtocolConfig;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.collections.ExpireHashMap;
|
||||
import com.comphenix.protocol.error.Report.ReportBuilder;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.reflect.PrettyPrinter;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Primitives;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -30,22 +44,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.comphenix.protocol.ProtocolConfig;
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.collections.ExpireHashMap;
|
||||
import com.comphenix.protocol.error.Report.ReportBuilder;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.reflect.PrettyPrinter;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Primitives;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Internal class used to handle exceptions.
|
||||
*
|
||||
|
@ -68,7 +66,7 @@ public class DetailedErrorReporter implements ErrorReporter {
|
|||
public static final int DEFAULT_MAX_ERROR_COUNT = 20;
|
||||
|
||||
// Prevent spam per plugin too
|
||||
private ConcurrentMap<String, AtomicInteger> warningCount = new ConcurrentHashMap<String, AtomicInteger>();
|
||||
private ConcurrentMap<String, AtomicInteger> warningCount = new ConcurrentHashMap<>();
|
||||
|
||||
protected String prefix;
|
||||
protected String supportURL;
|
||||
|
@ -88,10 +86,10 @@ public class DetailedErrorReporter implements ErrorReporter {
|
|||
protected boolean detailedReporting;
|
||||
|
||||
// Map of global objects
|
||||
protected Map<String, Object> globalParameters = new HashMap<String, Object>();
|
||||
protected Map<String, Object> globalParameters = new HashMap<>();
|
||||
|
||||
// Reports to ignore
|
||||
private ExpireHashMap<Report, Boolean> rateLimited = new ExpireHashMap<Report, Boolean>();
|
||||
private ExpireHashMap<Report, Boolean> rateLimited = new ExpireHashMap<>();
|
||||
private final Object rateLock = new Object();
|
||||
|
||||
/**
|
||||
|
@ -124,7 +122,7 @@ public class DetailedErrorReporter implements ErrorReporter {
|
|||
if (plugin == null)
|
||||
throw new IllegalArgumentException("Plugin cannot be NULL.");
|
||||
|
||||
this.pluginReference = new WeakReference<Plugin>(plugin);
|
||||
this.pluginReference = new WeakReference<>(plugin);
|
||||
this.pluginName = getNameSafely(plugin);
|
||||
this.prefix = prefix;
|
||||
this.supportURL = supportURL;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package com.comphenix.protocol.error;
|
||||
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
||||
|
||||
/**
|
||||
* Represents a strongly-typed report. Subclasses should be immutable.
|
||||
* <p>
|
||||
|
@ -118,7 +118,7 @@ public class ReportType {
|
|||
public static ReportType[] getReports(Class<?> sender) {
|
||||
if (sender == null)
|
||||
throw new IllegalArgumentException("sender cannot be NULL.");
|
||||
List<ReportType> result = new ArrayList<ReportType>();
|
||||
List<ReportType> result = new ArrayList<>();
|
||||
|
||||
// Go through all the fields
|
||||
for (Field field : getReportFields(sender)) {
|
||||
|
|
|
@ -17,21 +17,6 @@
|
|||
|
||||
package com.comphenix.protocol.events;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.injector.StructureCache;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
|
@ -40,15 +25,8 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
|||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.cloning.AggregateCloner;
|
||||
import com.comphenix.protocol.reflect.cloning.*;
|
||||
import com.comphenix.protocol.reflect.cloning.AggregateCloner.BuilderParameters;
|
||||
import com.comphenix.protocol.reflect.cloning.BukkitCloner;
|
||||
import com.comphenix.protocol.reflect.cloning.Cloner;
|
||||
import com.comphenix.protocol.reflect.cloning.CollectionCloner;
|
||||
import com.comphenix.protocol.reflect.cloning.FieldCloner;
|
||||
import com.comphenix.protocol.reflect.cloning.GuavaOptionalCloner;
|
||||
import com.comphenix.protocol.reflect.cloning.ImmutableDetector;
|
||||
import com.comphenix.protocol.reflect.cloning.JavaOptionalCloner;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||
import com.comphenix.protocol.reflect.instances.MinecraftGenerator;
|
||||
|
@ -59,7 +37,18 @@ import com.comphenix.protocol.wrappers.Converters;
|
|||
import com.google.common.collect.Sets;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Represents a Minecraft packet indirectly.
|
||||
|
@ -270,7 +259,7 @@ public class PacketContainer extends AbstractStructure implements Serializable {
|
|||
modifierDest.write(fieldIndex, modifierSource.read(fieldIndex));
|
||||
else
|
||||
defaultTransform(modifierSource, modifierDest, getDefaultCloner(), fieldIndex);
|
||||
};
|
||||
}
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -27,13 +27,14 @@ import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
|||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.google.common.primitives.Primitives;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* Represents an object capable of converting wrapped Bukkit objects into NMS objects.
|
||||
|
@ -53,7 +54,7 @@ public class BukkitUnwrapper implements Unwrapper {
|
|||
public static final ReportType REPORT_CANNOT_FIND_UNWRAP_METHOD = new ReportType("Cannot find method.");
|
||||
public static final ReportType REPORT_CANNOT_READ_FIELD_HANDLE = new ReportType("Cannot read field 'handle'.");
|
||||
|
||||
private static final Map<Class<?>, Unwrapper> UNWRAPPER_CACHE = new ConcurrentHashMap<Class<?>, Unwrapper>();
|
||||
private static final ConcurrentMap<Class<?>, Unwrapper> UNWRAPPER_CACHE = new ConcurrentHashMap<>();
|
||||
private static BukkitUnwrapper DEFAULT;
|
||||
|
||||
// The current error reporter
|
||||
|
@ -154,11 +155,10 @@ public class BukkitUnwrapper implements Unwrapper {
|
|||
* @return An unwrapper for the given class.
|
||||
*/
|
||||
private Unwrapper getSpecificUnwrapper(final Class<?> type) {
|
||||
// See if we're already determined this
|
||||
if (UNWRAPPER_CACHE.containsKey(type)) {
|
||||
// We will never remove from the cache, so this ought to be thread safe
|
||||
return UNWRAPPER_CACHE.get(type);
|
||||
}
|
||||
// See if we've already determined this
|
||||
// We will never remove from the cache, so this ought to be thread safe
|
||||
final Unwrapper cached = UNWRAPPER_CACHE.get(type);
|
||||
if (cached != null) return cached;
|
||||
|
||||
try {
|
||||
final Method find = type.getMethod("getHandle");
|
||||
|
@ -253,36 +253,33 @@ public class BukkitUnwrapper implements Unwrapper {
|
|||
*/
|
||||
private Unwrapper getFieldUnwrapper(final Class<?> type) {
|
||||
// See if we succeeded
|
||||
FieldAccessor accessor = Accessors.getFieldAccessorOrNull(type, "handle", null);
|
||||
if (accessor != null) {
|
||||
Unwrapper fieldUnwrapper = new Unwrapper() {
|
||||
@Override
|
||||
public Object unwrapItem(Object wrappedObject) {
|
||||
try {
|
||||
if (wrappedObject instanceof Class) {
|
||||
return checkClass((Class<?>) wrappedObject, type, accessor.getField().getType());
|
||||
}
|
||||
|
||||
return accessor.get(wrappedObject);
|
||||
} catch (IllegalStateException e) {
|
||||
reporter.reportDetailed(this,
|
||||
Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).error(e)
|
||||
.callerParam(wrappedObject, accessor.getField())
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UNWRAPPER_CACHE.put(type, fieldUnwrapper);
|
||||
return fieldUnwrapper;
|
||||
|
||||
} else {
|
||||
final FieldAccessor accessor = Accessors.getFieldAccessorOrNull(type, "handle", null);
|
||||
if (accessor == null) {
|
||||
// Inform about this too
|
||||
reporter.reportDetailed(this,
|
||||
Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).callerParam(type)
|
||||
);
|
||||
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).callerParam(type));
|
||||
return null;
|
||||
}
|
||||
|
||||
Unwrapper fieldUnwrapper = new Unwrapper() {
|
||||
@Override
|
||||
public Object unwrapItem(Object wrappedObject) {
|
||||
try {
|
||||
if (wrappedObject instanceof Class) {
|
||||
return checkClass((Class<?>) wrappedObject, type, accessor.getField().getType());
|
||||
}
|
||||
|
||||
return accessor.get(wrappedObject);
|
||||
} catch (IllegalStateException e) {
|
||||
reporter.reportDetailed(this,
|
||||
Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).error(e)
|
||||
.callerParam(wrappedObject, accessor.getField())
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UNWRAPPER_CACHE.put(type, fieldUnwrapper);
|
||||
return fieldUnwrapper;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
import com.comphenix.protocol.wrappers.WrappedIntHashMap;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -38,11 +42,7 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Used to perform certain operations on entities.
|
||||
|
@ -287,9 +287,9 @@ class EntityUtilities {
|
|||
}
|
||||
|
||||
private List<Object> getPlayerConnections(List<Object> nmsPlayers) {
|
||||
List<Object> connections = new ArrayList<>(nmsPlayers.size());
|
||||
nmsPlayers.forEach(nmsPlayer -> connections.add(MinecraftFields.getPlayerConnection(nmsPlayer)));
|
||||
return connections;
|
||||
return nmsPlayers.stream()
|
||||
.map(MinecraftFields::getPlayerConnection)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<Object> unwrapBukkit(List<Player> players) {
|
||||
|
|
|
@ -170,9 +170,7 @@ public class PacketConstructor {
|
|||
|
||||
try {
|
||||
result = unwrapper.unwrapItem(values[i]);
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (ThreadDeath e) {
|
||||
} catch (OutOfMemoryError | ThreadDeath e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
lastException = e;
|
||||
|
@ -243,7 +241,7 @@ public class PacketConstructor {
|
|||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public static interface Unwrapper {
|
||||
public interface Unwrapper {
|
||||
|
||||
/**
|
||||
* Convert the given wrapped object to the equivalent net.minecraft.server object.
|
||||
|
@ -254,6 +252,6 @@ public class PacketConstructor {
|
|||
* @param wrappedObject - wrapped object or class.
|
||||
* @return The equivalent net.minecraft.server object or class.
|
||||
*/
|
||||
public Object unwrapItem(Object wrappedObject);
|
||||
Object unwrapItem(Object wrappedObject);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package com.comphenix.protocol.injector;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginLoadOrder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginLoadOrder;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Determine if a plugin using ProtocolLib is correct.
|
||||
*
|
||||
|
@ -174,11 +173,8 @@ class PluginVerifier {
|
|||
}
|
||||
|
||||
// No dependency - check the load order
|
||||
if (beforePlugin.getDescription().getLoad() == PluginLoadOrder.STARTUP &&
|
||||
afterPlugin.getDescription().getLoad() == PluginLoadOrder.POSTWORLD) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return beforePlugin.getDescription().getLoad() == PluginLoadOrder.STARTUP &&
|
||||
afterPlugin.getDescription().getLoad() == PluginLoadOrder.POSTWORLD;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,7 +184,7 @@ class PluginVerifier {
|
|||
* @return TRUE if the plugin has the given dependency, FALSE otherwise.
|
||||
*/
|
||||
private boolean hasDependency(Plugin plugin, Plugin dependency) {
|
||||
return hasDependency(plugin, dependency, Sets.<String>newHashSet());
|
||||
return hasDependency(plugin, dependency, Sets.newHashSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,11 +17,6 @@
|
|||
|
||||
package com.comphenix.protocol.injector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
|
||||
|
@ -35,6 +30,10 @@ import com.comphenix.protocol.timing.TimedListenerManager.ListenerType;
|
|||
import com.comphenix.protocol.timing.TimedTracker;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Registry of synchronous packet listeners.
|
||||
|
@ -43,7 +42,7 @@ import javax.annotation.Nullable;
|
|||
*/
|
||||
public final class SortedPacketListenerList extends AbstractConcurrentListenerMultimap<PacketListener> {
|
||||
// The current listener manager
|
||||
private TimedListenerManager timedManager = TimedListenerManager.getInstance();
|
||||
private final TimedListenerManager timedManager = TimedListenerManager.getInstance();
|
||||
|
||||
public SortedPacketListenerList() {
|
||||
super();
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
package com.comphenix.protocol.injector.netty.channel;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
|
@ -38,6 +25,17 @@ import io.netty.util.AttributeKey;
|
|||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class NettyChannelInjector implements Injector {
|
||||
|
||||
// an accessor used when we're unable to retrieve the actual packet field in an outbound packet send
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
package com.comphenix.protocol.injector.netty.manager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||
|
@ -28,12 +21,18 @@ import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
|||
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class NetworkManagerInjector implements ChannelListener {
|
||||
|
||||
private static final String INBOUND_INJECT_HANDLER_NAME = "protocol_lib_inbound_inject";
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.comphenix.protocol.injector.player;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerOptions;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
|
@ -10,6 +8,8 @@ import com.comphenix.protocol.events.PacketListener;
|
|||
import io.netty.channel.Channel;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface PlayerInjectionHandler {
|
||||
|
||||
/**
|
||||
|
@ -144,6 +144,6 @@ public interface PlayerInjectionHandler {
|
|||
/**
|
||||
* Immediately exit.
|
||||
*/
|
||||
BAIL_OUT;
|
||||
BAIL_OUT
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ package com.comphenix.protocol.injector.temporary;
|
|||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||
import com.comphenix.protocol.utility.ChatExtensions;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import net.bytebuddy.description.ByteCodeElement;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
|
@ -29,16 +27,15 @@ import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
|
|||
import net.bytebuddy.implementation.FieldAccessor;
|
||||
import net.bytebuddy.implementation.MethodCall;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.FieldValue;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
import net.bytebuddy.implementation.bind.annotation.*;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Create fake player instances that represents pre-authenticated clients.
|
||||
*/
|
||||
|
@ -86,38 +83,36 @@ public class TemporaryPlayerFactory {
|
|||
throw new IllegalStateException("Unable to find injector.");
|
||||
}
|
||||
|
||||
// Use the socket to get the address
|
||||
else if (methodName.equals("getPlayer")) {
|
||||
return injector.getPlayer();
|
||||
} else if (methodName.equals("getAddress")) {
|
||||
return injector.getAddress();
|
||||
} else if (methodName.equals("getServer")) {
|
||||
return server;
|
||||
}
|
||||
switch (methodName)
|
||||
{
|
||||
case "getPlayer":
|
||||
return injector.getPlayer();
|
||||
case "getAddress":
|
||||
// Use the socket to get the address
|
||||
return injector.getAddress();
|
||||
case "getServer":
|
||||
return server;
|
||||
case "chat":
|
||||
case "sendMessage":
|
||||
try {
|
||||
Object argument = args[0];
|
||||
|
||||
// Handle send message methods
|
||||
if (methodName.equals("chat") || methodName.equals("sendMessage")) {
|
||||
try {
|
||||
Object argument = args[0];
|
||||
|
||||
// Dynamic overloading
|
||||
if (argument instanceof String) {
|
||||
return sendMessage(injector, (String) argument);
|
||||
} else if (argument instanceof String[]) {
|
||||
for (String message : (String[]) argument) {
|
||||
sendMessage(injector, message);
|
||||
// Dynamic overloading
|
||||
if (argument instanceof String) {
|
||||
return sendMessage(injector, (String) argument);
|
||||
} else if (argument instanceof String[]) {
|
||||
for (String message : (String[]) argument) {
|
||||
sendMessage(injector, message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception exception) {
|
||||
throw exception.getCause();
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
throw exception.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
// Also, handle kicking
|
||||
if (methodName.equals("kickPlayer")) {
|
||||
injector.disconnect((String) args[0]);
|
||||
return null;
|
||||
return null;
|
||||
case "kickPlayer":
|
||||
injector.disconnect((String) args[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
// The fallback instance
|
||||
|
@ -127,9 +122,9 @@ public class TemporaryPlayerFactory {
|
|||
}
|
||||
|
||||
// Methods that are supported in the fallback instance
|
||||
if (methodName.equals("isOnline")) {
|
||||
if ("isOnline".equals(methodName)) {
|
||||
return injector.isConnected();
|
||||
} else if (methodName.equals("getName")) {
|
||||
} else if ("getName".equals(methodName)) {
|
||||
return "UNKNOWN[" + injector.getAddress() + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.comphenix.protocol.PacketType;
|
|||
import com.comphenix.protocol.injector.StructureCache;
|
||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.StreamSerializer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -189,10 +189,7 @@ public class PrettyPrinter {
|
|||
// Handle exceptions
|
||||
try {
|
||||
printValue(output, Array.get(array, i), component, stop, previous, hierachyIndex - 1, printer);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (ArrayIndexOutOfBoundsException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.comphenix.protocol.reflect.accessors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
final class DefaultFieldAccessor implements FieldAccessor {
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.comphenix.protocol.reflect.accessors;
|
|||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
final class DefaultMethodAccessor implements MethodAccessor {
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package com.comphenix.protocol.reflect.fuzzy;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Represents a matcher that matches members.
|
||||
|
@ -186,7 +187,7 @@ public abstract class AbstractFuzzyMember<T extends Member> implements AbstractF
|
|||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public static abstract class Builder<T extends AbstractFuzzyMember<?>> {
|
||||
public abstract static class Builder<T extends AbstractFuzzyMember<?>> {
|
||||
|
||||
protected T member = this.initialMember();
|
||||
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
|
||||
package com.comphenix.protocol.reflect.instances;
|
||||
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
|
||||
/**
|
||||
* Provides instance constructors using a list of existing values.
|
||||
|
@ -45,7 +46,7 @@ public class ExistingGenerator implements InstanceProvider {
|
|||
private int level;
|
||||
|
||||
public Node(Class<?> key, Object value, int level) {
|
||||
this.children = new HashMap<Class<?>, Node>();
|
||||
this.children = new HashMap<>();
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.level = level;
|
||||
|
@ -168,8 +169,8 @@ public class ExistingGenerator implements InstanceProvider {
|
|||
Class<?>[] path = getHierachy(type);
|
||||
Node current = start;
|
||||
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
Node next = getNext(current, path[i], readOnly);
|
||||
for (Class<?> clazz : path) {
|
||||
Node next = getNext(current, clazz, readOnly);
|
||||
|
||||
// Try every interface too
|
||||
if (next == null && readOnly) {
|
||||
|
|
|
@ -31,5 +31,5 @@ public interface InstanceProvider {
|
|||
* @return The instance, or NULL if the type cannot be created.
|
||||
* @throws NotConstructableException Thrown to indicate that this type cannot or should never be constructed.
|
||||
*/
|
||||
public abstract Object create(@Nullable Class<?> type);
|
||||
Object create(@Nullable Class<?> type);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.comphenix.protocol.scheduler;
|
||||
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class DefaultTask implements Task {
|
||||
private final int taskId;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package com.comphenix.protocol.scheduler;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface ProtocolScheduler {
|
||||
Task scheduleSyncRepeatingTask(Runnable task, long delay, long period);
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.comphenix.protocol.timing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an online algortihm of computing histograms over time.
|
||||
* @author Kristian
|
||||
|
@ -36,7 +36,7 @@ public class HistogramStream extends OnlineComputation {
|
|||
* @param binWidth - maximum number of observations in each bin.
|
||||
*/
|
||||
public HistogramStream(int binWidth) {
|
||||
this(new ArrayList<StatisticsStream>(), new StatisticsStream(), binWidth);
|
||||
this(new ArrayList<>(), new StatisticsStream(), binWidth);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.comphenix.protocol.timing;
|
||||
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
@ -7,11 +11,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Represents a system for recording the time spent by each packet listener.
|
||||
* @author Kristian
|
||||
|
@ -21,7 +20,7 @@ public class TimedListenerManager {
|
|||
ASYNC_SERVER_SIDE,
|
||||
ASYNC_CLIENT_SIDE,
|
||||
SYNC_SERVER_SIDE,
|
||||
SYNC_CLIENT_SIDE;
|
||||
SYNC_CLIENT_SIDE
|
||||
}
|
||||
|
||||
// The shared manager
|
||||
|
|
|
@ -19,7 +19,6 @@ package com.comphenix.protocol.updater;
|
|||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.utility.Closer;
|
||||
import com.comphenix.protocol.utility.SchedulerUtil;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
|
|
@ -18,10 +18,11 @@ import com.comphenix.protocol.error.ReportType;
|
|||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
|
@ -40,7 +41,7 @@ public abstract class Updater {
|
|||
protected boolean announce;
|
||||
protected Thread thread;
|
||||
protected UpdateResult result = UpdateResult.SUCCESS;
|
||||
protected List<Runnable> listeners = new CopyOnWriteArrayList<Runnable>();
|
||||
protected List<Runnable> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
protected Updater(Plugin plugin, UpdateType type, boolean announce) {
|
||||
this.plugin = plugin;
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.comphenix.protocol.utility;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Represents an abstract class loader that can only retrieve classes by their canonical name.
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package com.comphenix.protocol.utility;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.google.common.base.Ticker;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Represents a Guava CacheBuilder that is compatible with both Guava 10 and 13.
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ public class SafeCacheBuilder<K, V> {
|
|||
* @return A new cache builder.
|
||||
*/
|
||||
public static <K, V> SafeCacheBuilder<K, V> newBuilder() {
|
||||
return new SafeCacheBuilder<K, V>();
|
||||
return new SafeCacheBuilder<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.google.common.base.Defaults;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
@ -28,9 +30,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
/**
|
||||
* Automatically wraps an internal NMS class to a non-versioned, deofbuscated class.
|
||||
* Requirements:
|
||||
|
@ -48,8 +47,8 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||
public class AutoWrapper<T> implements EquivalentConverter<T> {
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private Map<Integer, Function<Object, Object>> wrappers = new HashMap<>();
|
||||
private Map<Integer, Function<Object, Object>> unwrappers = new HashMap<>();
|
||||
private final Map<Integer, Function<Object, Object>> wrappers = new HashMap<>();
|
||||
private final Map<Integer, Function<Object, Object>> unwrappers = new HashMap<>();
|
||||
|
||||
// lazy
|
||||
private FieldAccessor[] nmsAccessors;
|
||||
|
@ -58,8 +57,8 @@ public class AutoWrapper<T> implements EquivalentConverter<T> {
|
|||
private Object[] nmsDefaultArgs;
|
||||
private ConstructorAccessor nmsInstanceCreator;
|
||||
|
||||
private Class<T> wrapperClass;
|
||||
private Class<?> nmsClass;
|
||||
private final Class<T> wrapperClass;
|
||||
private final Class<?> nmsClass;
|
||||
|
||||
private AutoWrapper(Class<T> wrapperClass, Class<?> nmsClass) {
|
||||
this.wrapperClass = wrapperClass;
|
||||
|
|
|
@ -16,17 +16,16 @@
|
|||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.google.common.base.Objects;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* Copies a immutable net.minecraft.server.BlockPosition, which represents a integer 3D vector.
|
||||
|
@ -176,8 +175,7 @@ public class BlockPosition {
|
|||
|
||||
// Construct the underlying BlockPosition
|
||||
try {
|
||||
Object result = blockPositionConstructor.newInstance(specific.x, specific.y, specific.z);
|
||||
return result;
|
||||
return blockPositionConstructor.newInstance(specific.x, specific.y, specific.z);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot construct BlockPosition.", e);
|
||||
}
|
||||
|
@ -197,8 +195,7 @@ public class BlockPosition {
|
|||
if (intModifier.size() >= 3) {
|
||||
try {
|
||||
StructureModifier<Integer> instance = intModifier.withTarget(generic);
|
||||
BlockPosition result = new BlockPosition(instance.read(0), instance.read(1), instance.read(2));
|
||||
return result;
|
||||
return new BlockPosition(instance.read(0), instance.read(1), instance.read(2));
|
||||
} catch (FieldAccessException e) {
|
||||
// This is an exeptional work-around, so we don't want to burden the caller with the messy details
|
||||
throw new RuntimeException("Field access error.", e);
|
||||
|
|
|
@ -16,29 +16,11 @@
|
|||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.Either.Left;
|
||||
import com.comphenix.protocol.wrappers.Either.Right;
|
||||
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.injector.BukkitUnwrapper;
|
||||
import com.comphenix.protocol.injector.PacketConstructor;
|
||||
import com.comphenix.protocol.injector.PacketConstructor.Unwrapper;
|
||||
|
@ -54,21 +36,18 @@ import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
|||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.Either.Left;
|
||||
import com.comphenix.protocol.wrappers.Either.Right;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Dimension;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.FauxEnumConverter;
|
||||
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
@ -79,6 +58,14 @@ import org.bukkit.potion.PotionEffectType;
|
|||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.comphenix.protocol.utility.MinecraftReflection.getCraftBukkitClass;
|
||||
import static com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass;
|
||||
import static com.comphenix.protocol.wrappers.Converters.handle;
|
||||
|
@ -1458,7 +1445,7 @@ public class BukkitConverters {
|
|||
THE_NETHER_IMPL(-1),
|
||||
THE_END_IMPL(1);
|
||||
|
||||
int id;
|
||||
final int id;
|
||||
DimensionImpl(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.AbstractFuzzyMatcher;
|
||||
|
@ -16,6 +7,13 @@ import com.comphenix.protocol.reflect.fuzzy.FuzzyMatchers;
|
|||
import com.comphenix.protocol.utility.ClassSource;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrap a GNU Trove Collection class with an equivalent Java Collection class.
|
||||
* @author Kristian
|
||||
|
|
|
@ -182,8 +182,7 @@ public class WrappedAttributeModifier extends AbstractWrapper {
|
|||
|
||||
StructureModifier<String> stringMod = modifier.withType(String.class);
|
||||
if (stringMod.size() == 0) {
|
||||
Supplier<String> supplier = (Supplier<String>) modifier.withType(Supplier.class).read(0);
|
||||
this.name = supplier;
|
||||
this.name = (Supplier<String>) modifier.withType(Supplier.class).read(0);
|
||||
} else {
|
||||
this.name = () -> stringMod.read(0);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.comphenix.protocol.injector.BukkitUnwrapper;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
|
@ -33,12 +30,14 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||
import com.comphenix.protocol.wrappers.collection.ConvertedMap;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Represents a DataWatcher
|
||||
* @author dmulloy2
|
||||
|
@ -912,7 +911,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
|||
*/
|
||||
public static class Registry {
|
||||
private static boolean INITIALIZED = false;
|
||||
private static List<Serializer> REGISTRY = new ArrayList<>();
|
||||
private static final List<Serializer> REGISTRY = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Gets the first serializer associated with a given class.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.reflect.ExactReflection;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package com.comphenix.protocol.wrappers.collection;
|
||||
|
||||
/**
|
||||
* Represents a function that accepts two parameters.
|
||||
* @author Kristian
|
||||
* @param <T1> - type of the first parameter.
|
||||
* @param <T2> - type of the second parameter.
|
||||
* @param <TResult> - type of the return value.
|
||||
*/
|
||||
public interface BiFunction<T1, T2, TResult> {
|
||||
TResult apply(T1 arg1, T2 arg2);
|
||||
}
|
|
@ -23,10 +23,11 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Represents a map that wraps another map by transforming the entries going in and out.
|
||||
*
|
||||
*
|
||||
* @author Kristian
|
||||
*
|
||||
* @param <VInner> - type of the value in the entries in the inner invisible map.
|
||||
|
@ -34,14 +35,14 @@ import java.util.Set;
|
|||
*/
|
||||
public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverted<VInner, VOuter> implements Map<Key, VOuter> {
|
||||
// Inner map
|
||||
private Map<Key, VInner> inner;
|
||||
private final Map<Key, VInner> inner;
|
||||
|
||||
// Inner conversion
|
||||
private final BiFunction<Key, VOuter, VInner> innerConverter = this::toInner;
|
||||
|
||||
|
||||
// Outer conversion
|
||||
private final BiFunction<Key, VInner, VOuter> outerConverter = this::toOuter;
|
||||
|
||||
|
||||
public ConvertedMap(Map<Key, VInner> inner) {
|
||||
if (inner == null)
|
||||
throw new IllegalArgumentException("Inner map cannot be NULL.");
|
||||
|
@ -78,7 +79,7 @@ public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverte
|
|||
protected VOuter toOuter(Key key, VInner inner) {
|
||||
return toOuter(inner);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a value from the outer map to the internal inner map.
|
||||
* @param key - unused value.
|
||||
|
@ -88,7 +89,7 @@ public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverte
|
|||
protected VInner toInner(Key key, VOuter outer) {
|
||||
return toInner(outer);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public VOuter get(Object key) {
|
||||
|
@ -165,7 +166,7 @@ public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverte
|
|||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a collection of entries.
|
||||
* @param entries - the collection of entries.
|
||||
|
@ -177,7 +178,7 @@ public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverte
|
|||
final Collection<Entry<Key, VInner>> entries,
|
||||
final BiFunction<Key, VOuter, VInner> innerFunction,
|
||||
final BiFunction<Key, VInner, VOuter> outerFunction) {
|
||||
|
||||
|
||||
return new ConvertedSet<Entry<Key,VInner>, Entry<Key,VOuter>>(entries) {
|
||||
@Override
|
||||
protected Entry<Key, VInner> toInner(final Entry<Key, VOuter> outer) {
|
||||
|
@ -196,14 +197,14 @@ public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverte
|
|||
public VInner setValue(VInner value) {
|
||||
return innerFunction.apply(getKey(), outer.setValue(outerFunction.apply(getKey(), value)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("\"%s\": %s", getKey(), getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Entry<Key, VOuter> toOuter(final Entry<Key, VInner> inner) {
|
||||
return new Entry<Key, VOuter>() {
|
||||
|
@ -222,7 +223,7 @@ public abstract class ConvertedMap<Key, VInner, VOuter> extends AbstractConverte
|
|||
final VInner converted = innerFunction.apply(getKey(), value);
|
||||
return outerFunction.apply(getKey(), inner.setValue(converted));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("\"%s\": %s", getKey(), getValue());
|
||||
|
|
|
@ -123,7 +123,7 @@ public enum NbtType {
|
|||
classLookup.put(NbtCompound.class, TAG_COMPOUND);
|
||||
}
|
||||
|
||||
private NbtType(int rawID, Class<?> valueType) {
|
||||
NbtType(int rawID, Class<?> valueType) {
|
||||
this.rawID = rawID;
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
|
|
@ -6,24 +6,16 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
|
|||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||
import com.comphenix.protocol.utility.MinecraftMethods;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import net.bytebuddy.jar.asm.*;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.implementation.InvocationHandlerAdapter;
|
||||
import net.bytebuddy.jar.asm.ClassReader;
|
||||
import net.bytebuddy.jar.asm.ClassVisitor;
|
||||
import net.bytebuddy.jar.asm.MethodVisitor;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import net.bytebuddy.jar.asm.Type;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
/**
|
||||
* Manipulate tile entities.
|
||||
|
@ -91,7 +83,7 @@ class TileEntityAccessor<T extends BlockState> {
|
|||
created = EMPTY_ACCESSOR;
|
||||
}
|
||||
if (field != null) {
|
||||
created = new TileEntityAccessor<T>(field, state);
|
||||
created = new TileEntityAccessor<>(field, state);
|
||||
}
|
||||
accessor = cachedAccessors.putIfAbsent(craftBlockState, created);
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ class WrappedElement<TType> implements NbtWrapper<TType> {
|
|||
if (modifier == null) {
|
||||
synchronized (this) {
|
||||
if (MODIFIERS[index] == null) {
|
||||
MODIFIERS[index] = new StructureModifier<Object>(handle.getClass(), MinecraftReflection.getNBTBaseClass(), false);
|
||||
MODIFIERS[index] = new StructureModifier<>(handle.getClass(), MinecraftReflection.getNBTBaseClass(), false);
|
||||
}
|
||||
modifier = (StructureModifier<Object>) MODIFIERS[index];
|
||||
}
|
||||
|
@ -241,13 +241,13 @@ class WrappedElement<TType> implements NbtWrapper<TType> {
|
|||
result.append("{");
|
||||
|
||||
if (name != null && name.length() > 0)
|
||||
result.append("name: '" + name + "', ");
|
||||
result.append("name: '").append(name).append("', ");
|
||||
|
||||
result.append("value: ");
|
||||
|
||||
// Wrap quotation marks
|
||||
if (getType() == NbtType.TAG_STRING)
|
||||
result.append("'" + getValue() + "'");
|
||||
result.append("'").append(getValue()).append("'");
|
||||
else
|
||||
result.append(getValue());
|
||||
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
package com.comphenix.protocol.wrappers.nbt.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.comphenix.protocol.wrappers.nbt.*;
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtList;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtType;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtVisitor;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Serialize and deserialize NBT information from a configuration section.
|
||||
|
@ -237,7 +226,7 @@ public class NbtConfigurationSerializer {
|
|||
|
||||
// Read everything in order
|
||||
for (String key : sorted) {
|
||||
NbtBase<Object> base = (NbtBase<Object>) readNode(section, key.toString());
|
||||
NbtBase<Object> base = (NbtBase<Object>) readNode(section, key);
|
||||
base.setName(NbtList.EMPTY_NAME);
|
||||
list.getValue().add(base);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.comphenix.protocol.wrappers.ping;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.injector.BukkitUnwrapper;
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
|
@ -14,16 +13,9 @@ import com.comphenix.protocol.wrappers.AbstractWrapper;
|
|||
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedServerPing;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a server ping packet data.
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package com.comphenix.protocol.reflect.cloning;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AggregateClonerTest {
|
||||
|
||||
@BeforeAll
|
||||
|
@ -21,7 +22,7 @@ public class AggregateClonerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testArrays() {
|
||||
void testArrays() {
|
||||
List<Integer> input = Arrays.asList(1, 2, 3);
|
||||
assertEquals(input, AggregateCloner.DEFAULT.clone(input));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue