mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-09 12:20:16 +01:00
Don't synchronize with the main thread when registering async listeners
This commit is contained in:
parent
88a2385b1e
commit
96f24167bb
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user