summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2012-08-03 06:24:55 -0500
committerWesley Wolfe <weswolf@aol.com>2012-08-03 23:44:45 -0500
commit02d6703da779a5876ceaf5d2fd2dd9833a7a6621 (patch)
tree03ac669aa3c8f9f1d91c98142de9d2eb36644f0c /src/main/java/org/bukkit
parent4942f5184a29e945d7b47aaf8b93f668ea20ce28 (diff)
downloadcraftbukkit-02d6703da779a5876ceaf5d2fd2dd9833a7a6621.tar
craftbukkit-02d6703da779a5876ceaf5d2fd2dd9833a7a6621.tar.gz
craftbukkit-02d6703da779a5876ceaf5d2fd2dd9833a7a6621.tar.lz
craftbukkit-02d6703da779a5876ceaf5d2fd2dd9833a7a6621.tar.xz
craftbukkit-02d6703da779a5876ceaf5d2fd2dd9833a7a6621.zip
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.
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java98
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java25
3 files changed, 124 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index dd82cb32..b1906046 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -229,7 +229,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void chat(String msg) {
if (getHandle().netServerHandler == null) return;
- getHandle().netServerHandler.chat(msg);
+ getHandle().netServerHandler.chat(msg, false);
}
public boolean performCommand(String command) {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
new file mode 100644
index 00000000..ad83fd87
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
@@ -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();
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
new file mode 100644
index 00000000..df090190
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
@@ -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;
+ }
+
+}