mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-16 04:33:56 -07:00
Implement new AsyncPlayerChatEvent. Addresses BUKKIT-2064
Added two utility collections for use with PlayerChatEvents allowing lazier initialization of events and less need to synchronize against the player list. Provided a hidden queue system for similar logic to pre-1.3 chat. When a plugin is listening for the deprecated PlayerChatEvent, all chat will be delayed to be mirror executed from the main thread. All developers are encouraged to immediately update to the developmental Bukkit chat API as a minimum transition for server stability. Additionally, changes were required to bring thread-safety to the flow logic. CopyOnWriteArrayList is the only viable means to produce thread safety with minimal diff; using a sane pre-implemented collection would require reworking of sections of NMS logic. As a minor change, implemented expected functionality for PlayerCommandPreProcessEvent. Setting the player should now change the player executing the command.
This commit is contained in:
@@ -19,6 +19,7 @@ import joptsimple.OptionSet;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||
import org.bukkit.event.world.WorldSaveEvent;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
public abstract class MinecraftServer implements Runnable, IMojangStatistics, ICommandListener {
|
||||
@@ -78,6 +79,7 @@ public abstract class MinecraftServer implements Runnable, IMojangStatistics, IC
|
||||
public ConsoleReader reader;
|
||||
public static int currentTick;
|
||||
public final Thread primaryThread;
|
||||
public java.util.Queue<PlayerChatEvent> chatQueue = new java.util.concurrent.ConcurrentLinkedQueue<PlayerChatEvent>();
|
||||
// CraftBukkit end
|
||||
|
||||
public MinecraftServer(OptionSet options) { // CraftBukkit - signature file -> OptionSet
|
||||
@@ -509,6 +511,28 @@ public abstract class MinecraftServer implements Runnable, IMojangStatistics, IC
|
||||
// CraftBukkit start - only send timeupdates to the people in that world
|
||||
this.server.getScheduler().mainThreadHeartbeat(this.ticks);
|
||||
|
||||
// Fix for old plugins still using deprecated event
|
||||
while (!chatQueue.isEmpty()) {
|
||||
PlayerChatEvent event = chatQueue.remove();
|
||||
org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String message = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
|
||||
console.sendMessage(message);
|
||||
if (((org.bukkit.craftbukkit.util.LazyPlayerSet) event.getRecipients()).isLazy()) {
|
||||
for (Object player : getServerConfigurationManager().players) {
|
||||
((EntityPlayer) player).sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
for (org.bukkit.entity.Player player : event.getRecipients()) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send timeupdates to everyone, it will get the right time from the world the player is in.
|
||||
if (this.ticks % 20 == 0) {
|
||||
for (int i = 0; i < this.getServerConfigurationManager().players.size(); ++i) {
|
||||
|
Reference in New Issue
Block a user