Don't synchronize with the main thread when registering async listeners

This commit is contained in:
Kristian S. Stangeland 2013-12-14 18:08:08 +01:00
parent 88a2385b1e
commit 96f24167bb
2 changed files with 36 additions and 2 deletions

View File

@ -19,6 +19,7 @@ package com.comphenix.protocol.async;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.ListeningWhitelist; import com.comphenix.protocol.events.ListeningWhitelist;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
@ -67,7 +68,8 @@ class NullPacketListener implements PacketListener {
private ListeningWhitelist cloneWhitelist(ListenerPriority priority, ListeningWhitelist whitelist) { private ListeningWhitelist cloneWhitelist(ListenerPriority priority, ListeningWhitelist whitelist) {
if (whitelist != null) if (whitelist != null)
return ListeningWhitelist.newBuilder(whitelist).priority(priority).build(); // We don't use the Bukkit API, so don't engage the ProtocolLib synchronization code
return ListeningWhitelist.newBuilder(whitelist).priority(priority).mergeOptions(ListenerOptions.ASYNC).build();
else else
return null; return null;
} }

View File

@ -420,7 +420,6 @@ public class ListeningWhitelist {
public Builder gamePhaseBoth() { public Builder gamePhaseBoth() {
return gamePhase(GamePhase.BOTH); return gamePhase(GamePhase.BOTH);
} }
/** /**
* Set the options to copy when constructing new whitelists. * Set the options to copy when constructing new whitelists.
* @param options - the options. * @param options - the options.
@ -431,6 +430,16 @@ public class ListeningWhitelist {
return this; return this;
} }
/**
* Set the options to copy when constructing new whitelists.
* @param options - the options.
* @return This builder, for chaining.
*/
public Builder options(Collection<ListenerOptions> options) {
this.options = safeSet(options);
return this;
}
/** /**
* Set the options to copy when constructing new whitelists. * Set the options to copy when constructing new whitelists.
* @param options - the options array. * @param options - the options array.
@ -441,6 +450,29 @@ public class ListeningWhitelist {
return this; return this;
} }
/**
* Options to merge into the current set of options.
* @param options - the options array.
* @return This builder, for chaining.
*/
public Builder mergeOptions(ListenerOptions... serverOptions) {
return mergeOptions(Arrays.asList(serverOptions));
}
/**
* Options to merge into the current set of options.
* @param options - the options array.
* @return This builder, for chaining.
*/
public Builder mergeOptions(Collection<ListenerOptions> serverOptions) {
if (options == null)
return options(serverOptions);
// Merge the options
this.options.addAll(serverOptions);
return this;
}
/** /**
* Construct a new whitelist from the values in this builder. * Construct a new whitelist from the values in this builder.
* @return The new whitelist. * @return The new whitelist.