geforkt von Mirrors/Paper
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. By: Wesley Wolfe <weswolf@aol.com>
Dieser Commit ist enthalten in:
Ursprung
a1a672d052
Commit
7383d52df7
@ -229,7 +229,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
public void chat(String msg) {
|
public void chat(String msg) {
|
||||||
if (getHandle().netServerHandler == null) return;
|
if (getHandle().netServerHandler == null) return;
|
||||||
|
|
||||||
getHandle().netServerHandler.chat(msg);
|
getHandle().netServerHandler.chat(msg, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean performCommand(String command) {
|
public boolean performCommand(String command) {
|
||||||
|
@ -0,0 +1,98 @@
|
|||||||
|
package org.bukkit.craftbukkit.util;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class LazyHashSet<E> implements Set<E> {
|
||||||
|
Set<E> reference = null;
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return getReference().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return getReference().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Object o) {
|
||||||
|
return getReference().contains(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<E> iterator() {
|
||||||
|
return getReference().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] toArray() {
|
||||||
|
return getReference().toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T[] toArray(T[] a) {
|
||||||
|
return getReference().toArray(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean add(E o) {
|
||||||
|
return getReference().add(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove(Object o) {
|
||||||
|
return getReference().remove(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsAll(Collection<?> c) {
|
||||||
|
return getReference().containsAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addAll(Collection<? extends E> c) {
|
||||||
|
return getReference().addAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean retainAll(Collection<?> c) {
|
||||||
|
return getReference().retainAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeAll(Collection<?> c) {
|
||||||
|
return getReference().removeAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
getReference().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<E> getReference() {
|
||||||
|
Set<E> reference = this.reference ;
|
||||||
|
if (reference != null) {
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
return this.reference = makeReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract Set<E> makeReference();
|
||||||
|
|
||||||
|
public boolean isLazy() {
|
||||||
|
return reference == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return 157 * getReference().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null || this.getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LazyHashSet<?> that = (LazyHashSet<?>) obj;
|
||||||
|
return (this.isLazy() && that.isLazy()) || this.getReference().equals(that.getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getReference().toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package org.bukkit.craftbukkit.util;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.server.EntityPlayer;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class LazyPlayerSet extends LazyHashSet<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
HashSet<Player> makeReference() {
|
||||||
|
if (reference != null) {
|
||||||
|
throw new IllegalStateException("Reference already created!");
|
||||||
|
}
|
||||||
|
List<EntityPlayer> players = MinecraftServer.getServer().getServerConfigurationManager().players;
|
||||||
|
HashSet<Player> reference = new HashSet<Player>(players.size());
|
||||||
|
for (EntityPlayer player : players) {
|
||||||
|
reference.add(player.getBukkitEntity());
|
||||||
|
}
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren