Archiviert
13
0

Correctly clean up the old injection handler.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-13 21:34:03 +01:00
Ursprung 74d83b3ed6
Commit c568481da3
2 geänderte Dateien mit 95 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -1,17 +1,18 @@
package com.comphenix.protocol.injector.netty; package com.comphenix.protocol.injector.netty;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import com.google.common.collect.ForwardingList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
// Hopefully, CB won't version these as well // Hopefully, CB won't version these as well
import net.minecraft.util.io.netty.channel.ChannelFuture; import net.minecraft.util.io.netty.channel.ChannelFuture;
import net.minecraft.util.io.netty.channel.ChannelHandler; import net.minecraft.util.io.netty.channel.ChannelHandler;
class BootstrapList extends ForwardingList<Object> { class BootstrapList implements List<Object> {
private List<Object> delegate; private List<Object> delegate;
private ChannelHandler handler; private ChannelHandler handler;
@ -33,30 +34,25 @@ class BootstrapList extends ForwardingList<Object> {
} }
@Override @Override
protected List<Object> delegate() { public synchronized boolean add(Object element) {
return delegate;
}
@Override
public boolean add(Object element) {
processElement(element); processElement(element);
return super.add(element); return delegate.add(element);
} }
@Override @Override
public boolean addAll(Collection<? extends Object> collection) { public synchronized boolean addAll(Collection<? extends Object> collection) {
List<Object> copy = Lists.newArrayList(collection); List<Object> copy = Lists.newArrayList(collection);
// Process the collection before we pass it on // Process the collection before we pass it on
for (Object element : copy) { for (Object element : copy) {
processElement(element); processElement(element);
} }
return super.addAll(copy); return delegate.addAll(copy);
} }
@Override @Override
public Object set(int index, Object element) { public synchronized Object set(int index, Object element) {
Object old = super.set(index, element); Object old = delegate.set(index, element);
// Handle the old future, and the newly inserted future // Handle the old future, and the newly inserted future
if (old != element) { if (old != element) {
@ -110,8 +106,90 @@ class BootstrapList extends ForwardingList<Object> {
/** /**
* Close and revert all changes. * Close and revert all changes.
*/ */
public void close() { public synchronized void close() {
for (Object element : this) for (Object element : this)
unprocessElement(element); unprocessElement(element);
} }
// Boiler plate
public synchronized int size() {
return delegate.size();
}
public synchronized boolean isEmpty() {
return delegate.isEmpty();
}
public boolean contains(Object o) {
return delegate.contains(o);
}
public synchronized Iterator<Object> iterator() {
return delegate.iterator();
}
public synchronized Object[] toArray() {
return delegate.toArray();
}
public synchronized <T> T[] toArray(T[] a) {
return delegate.toArray(a);
}
public synchronized boolean remove(Object o) {
return delegate.remove(o);
}
public synchronized boolean containsAll(Collection<?> c) {
return delegate.containsAll(c);
}
public synchronized boolean addAll(int index, Collection<? extends Object> c) {
return delegate.addAll(index, c);
}
public synchronized boolean removeAll(Collection<?> c) {
return delegate.removeAll(c);
}
public synchronized boolean retainAll(Collection<?> c) {
return delegate.retainAll(c);
}
public synchronized void clear() {
delegate.clear();
}
public synchronized Object get(int index) {
return delegate.get(index);
}
public synchronized void add(int index, Object element) {
delegate.add(index, element);
}
public synchronized Object remove(int index) {
return delegate.remove(index);
}
public synchronized int indexOf(Object o) {
return delegate.indexOf(o);
}
public synchronized int lastIndexOf(Object o) {
return delegate.lastIndexOf(o);
}
public synchronized ListIterator<Object> listIterator() {
return delegate.listIterator();
}
public synchronized ListIterator<Object> listIterator(int index) {
return delegate.listIterator(index);
}
public synchronized List<Object> subList(int fromIndex, int toIndex) {
return delegate.subList(fromIndex, toIndex);
}
// End boiler plate
} }

Datei anzeigen

@ -5,7 +5,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -112,10 +111,9 @@ public class NettyProtocolInjector implements ChannelListener {
final List<Object> list = (List<Object>) field.getValue(); final List<Object> list = (List<Object>) field.getValue();
// Synchronize with each list before we attempt to replace them. // Synchronize with each list before we attempt to replace them.
// We also reapply the synchronized list wrapper. field.setValue(new BootstrapList(
field.setValue(Collections.synchronizedList(new BootstrapList(
list, connectionHandler list, connectionHandler
))); ));
} }
injected = true; injected = true;