Archiviert
13
0

Backport some fixes, fix version in plugin yml

Still need to get automatic filtering fixed
Dieser Commit ist enthalten in:
Dan Mulloy 2019-05-04 01:45:41 -04:00
Ursprung 565f169e94
Commit e41bb8753b
5 geänderte Dateien mit 52 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -52,7 +52,7 @@ processResources {
with copySpec { with copySpec {
from 'src/main/resources' from 'src/main/resources'
filter(ReplaceTokens, tokens: ['fullVersion': fullVersion]) filter(ReplaceTokens, tokens: ['$fullVersion': fullVersion])
} }
} }

Datei anzeigen

@ -1,5 +1,16 @@
package com.comphenix.protocol.concurrency; package com.comphenix.protocol.concurrency;
import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.comphenix.protocol.utility.Util;
import com.google.common.base.Function;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.RemovalListener;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.UncheckedExecutionException;
import org.bukkit.entity.Player;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.Iterator; import java.util.Iterator;
@ -7,18 +18,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.bukkit.entity.Player;
import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.comphenix.protocol.utility.Util;
import com.google.common.base.Function;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.UncheckedExecutionException;
/** /**
* Represents a concurrent player map. * Represents a concurrent player map.
* <p> * <p>
@ -37,7 +36,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
ADDRESS { ADDRESS {
@Override @Override
public Object apply(Player player) { public Object apply(Player player) {
return player.getAddress(); return player == null ? null : player.getAddress();
} }
}, },
@ -47,7 +46,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
NAME { NAME {
@Override @Override
public Object apply(Player player) { public Object apply(Player player) {
return player.getName(); return player == null ? null : player.getName();
} }
}, },
} }
@ -55,17 +54,17 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
/** /**
* An internal map of player keys to values. * An internal map of player keys to values.
*/ */
protected ConcurrentMap<Object, TValue> valueLookup = createValueMap(); private ConcurrentMap<Object, TValue> valueLookup = createValueMap();
/** /**
* A cache of the associated keys for each player. * A cache of the associated keys for each player.
*/ */
protected ConcurrentMap<Object, Player> keyLookup = createKeyCache(); private ConcurrentMap<Object, Player> keyLookup = createKeyCache();
/** /**
* The method used to retrieve a unique key for a player. * The method used to retrieve a unique key for a player.
*/ */
protected final Function<Player, Object> keyMethod; private final Function<Player, Object> keyMethod;
/** /**
* Construct a new concurrent player map that uses each player's address as key. * Construct a new concurrent player map that uses each player's address as key.
@ -89,7 +88,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* Construct a new concurrent player map using the given standard key method. * Construct a new concurrent player map using the given standard key method.
* @param standardMethod - the standard key method. * @param standardMethod - the standard key method.
*/ */
public ConcurrentPlayerMap(PlayerKey standardMethod) { private ConcurrentPlayerMap(PlayerKey standardMethod) {
this.keyMethod = standardMethod; this.keyMethod = standardMethod;
} }
@ -107,7 +106,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* The default implementation uses a {@link ConcurrentHashMap}. * The default implementation uses a {@link ConcurrentHashMap}.
* @return The value map. * @return The value map.
*/ */
protected ConcurrentMap<Object, TValue> createValueMap() { private ConcurrentMap<Object, TValue> createValueMap() {
return Maps.newConcurrentMap(); return Maps.newConcurrentMap();
} }
@ -115,19 +114,16 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* Construct a cache of keys and the associated player. * Construct a cache of keys and the associated player.
* @return The key map. * @return The key map.
*/ */
protected ConcurrentMap<Object, Player> createKeyCache() { private ConcurrentMap<Object, Player> createKeyCache() {
return SafeCacheBuilder.newBuilder(). return SafeCacheBuilder.newBuilder().
weakValues(). weakValues().
removalListener( removalListener(
new RemovalListener<Object, Player>() { (RemovalListener<Object, Player>) removed -> {
@Override // We ignore explicit removal
public void onRemoval(RemovalNotification<Object, Player> removed) { if (removed.wasEvicted()) {
// We ignore explicit removal onCacheEvicted(removed.getKey());
if (removed.wasEvicted()) { }
onCacheEvicted(removed.getKey()); }).
}
}
}).
build( build(
new CacheLoader<Object, Player>() { new CacheLoader<Object, Player>() {
@Override @Override
@ -147,7 +143,6 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
/** /**
* Invoked when an entry in the cache has been evicted, typically by the garbage collector. * Invoked when an entry in the cache has been evicted, typically by the garbage collector.
* @param key - the key. * @param key - the key.
* @param player - the value that was evicted or collected.
*/ */
private void onCacheEvicted(Object key) { private void onCacheEvicted(Object key) {
Player newPlayer = findOnlinePlayer(key); Player newPlayer = findOnlinePlayer(key);
@ -165,7 +160,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* @param key - a non-null key. * @param key - a non-null key.
* @return The player with the given key, or NULL if not found. * @return The player with the given key, or NULL if not found.
*/ */
protected Player findOnlinePlayer(Object key) { private Player findOnlinePlayer(Object key) {
for (Player player : Util.getOnlinePlayers()) { for (Player player : Util.getOnlinePlayers()) {
if (key.equals(keyMethod.apply(player))) { if (key.equals(keyMethod.apply(player))) {
return player; return player;
@ -179,7 +174,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* @param key - the key of the player we are locating. * @param key - the key of the player we are locating.
* @return The player, or NULL if not found. * @return The player, or NULL if not found.
*/ */
protected Player lookupPlayer(Object key) { private Player lookupPlayer(Object key) {
try { try {
return keyLookup.get(key); return keyLookup.get(key);
} catch (UncheckedExecutionException e) { } catch (UncheckedExecutionException e) {
@ -192,7 +187,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* @param player - the player whose key we want to retrieve. * @param player - the player whose key we want to retrieve.
* @return The key. * @return The key.
*/ */
protected Object cachePlayerKey(Player player) { private Object cachePlayerKey(Player player) {
Object key = keyMethod.apply(player); Object key = keyMethod.apply(player);
keyLookup.put(key, player); keyLookup.put(key, player);

Datei anzeigen

@ -26,7 +26,6 @@ import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.MinecraftVersion;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
/** /**
* Represents a wrapper around IBlockData. * Represents a wrapper around IBlockData.
@ -157,7 +156,7 @@ public abstract class WrappedBlockData extends AbstractWrapper implements Clonab
return new NewBlockData(FROM_LEGACY_DATA.invoke(null, material, (byte) data)); return new NewBlockData(FROM_LEGACY_DATA.invoke(null, material, (byte) data));
} }
private static WrappedBlockData createNewData(BlockData data) { private static WrappedBlockData createNewData(Object data) {
return new NewBlockData(GET_HANDLE.invoke(data)); return new NewBlockData(GET_HANDLE.invoke(data));
} }
} }
@ -324,7 +323,7 @@ public abstract class WrappedBlockData extends AbstractWrapper implements Clonab
* @param data Spigot block data * @param data Spigot block data
* @return The new Wrapped Block Data * @return The new Wrapped Block Data
*/ */
public static WrappedBlockData createData(BlockData data) { public static WrappedBlockData createData(Object data) {
return NewBlockData.createNewData(data); return NewBlockData.createNewData(data);
} }

Datei anzeigen

@ -1,6 +1,7 @@
package com.comphenix.protocol.wrappers; package com.comphenix.protocol.wrappers;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.Accessors;
@ -18,13 +19,22 @@ public class WrappedStatistic extends AbstractWrapper {
private static final Class<?> STATISTIC = MinecraftReflection.getStatisticClass(); private static final Class<?> STATISTIC = MinecraftReflection.getStatisticClass();
private static final Class<?> STATISTIC_LIST = MinecraftReflection.getStatisticListClass(); private static final Class<?> STATISTIC_LIST = MinecraftReflection.getStatisticListClass();
private static final MethodAccessor FIND_STATISTICS = Accessors.getMethodAccessor(
FuzzyReflection.fromClass(STATISTIC_LIST).getMethodByParameters( static {
"findStatistic", STATISTIC, new Class<?>[] { String.class } try {
) FIND_STATISTICS = Accessors.getMethodAccessor(
); FuzzyReflection.fromClass(STATISTIC_LIST).getMethodByParameters(
private static final FieldAccessor MAP_ACCESSOR = Accessors.getFieldAccessor(STATISTIC_LIST, Map.class, true); "findStatistic", STATISTIC, new Class<?>[]{String.class}));
private static final FieldAccessor GET_NAME = Accessors.getFieldAccessor(STATISTIC, String.class, true); MAP_ACCESSOR = Accessors.getFieldAccessor(STATISTIC_LIST, Map.class, true);
GET_NAME = Accessors.getFieldAccessor(STATISTIC, String.class, true);
} catch (Exception ex) {
// TODO - find an alternative
}
}
private static MethodAccessor FIND_STATISTICS;
private static FieldAccessor MAP_ACCESSOR;
private static FieldAccessor GET_NAME;
private final String name; private final String name;
@ -62,12 +72,7 @@ public class WrappedStatistic extends AbstractWrapper {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<Object, Object> map = (Map<Object, Object>) MAP_ACCESSOR.get(null); Map<Object, Object> map = (Map<Object, Object>) MAP_ACCESSOR.get(null);
return Iterables.transform(map.values(), new Function<Object, WrappedStatistic>() { return map.values().stream().map(WrappedStatistic::fromHandle).collect(Collectors.toList());
@Override
public WrappedStatistic apply(Object handle) {
return fromHandle(handle);
};
});
} }
/** /**

Datei anzeigen

@ -1,11 +1,10 @@
name: ProtocolLib name: ProtocolLib
#version: ${project.fullVersion} version: 4.5.0-SNAPSHOT
version: 4.4.0
description: Provides read/write access to the Minecraft protocol. description: Provides read/write access to the Minecraft protocol.
authors: [dmulloy2, comphenix] authors: [dmulloy2, comphenix]
main: com.comphenix.protocol.ProtocolLib main: com.comphenix.protocol.ProtocolLib
load: startup load: STARTUP
database: false database: false
commands: commands: