mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-26 11:08:12 +01:00
Backport some fixes, fix version in plugin yml
Still need to get automatic filtering fixed
This commit is contained in:
parent
565f169e94
commit
e41bb8753b
@ -52,7 +52,7 @@ processResources {
|
||||
|
||||
with copySpec {
|
||||
from 'src/main/resources'
|
||||
filter(ReplaceTokens, tokens: ['fullVersion': fullVersion])
|
||||
filter(ReplaceTokens, tokens: ['$fullVersion': fullVersion])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,16 @@
|
||||
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.AbstractSet;
|
||||
import java.util.Iterator;
|
||||
@ -7,18 +18,6 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
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.
|
||||
* <p>
|
||||
@ -37,7 +36,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
|
||||
ADDRESS {
|
||||
@Override
|
||||
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 {
|
||||
@Override
|
||||
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.
|
||||
*/
|
||||
protected ConcurrentMap<Object, TValue> valueLookup = createValueMap();
|
||||
private ConcurrentMap<Object, TValue> valueLookup = createValueMap();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
@ -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.
|
||||
* @param standardMethod - the standard key method.
|
||||
*/
|
||||
public ConcurrentPlayerMap(PlayerKey standardMethod) {
|
||||
private ConcurrentPlayerMap(PlayerKey standardMethod) {
|
||||
this.keyMethod = standardMethod;
|
||||
}
|
||||
|
||||
@ -107,7 +106,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
|
||||
* The default implementation uses a {@link ConcurrentHashMap}.
|
||||
* @return The value map.
|
||||
*/
|
||||
protected ConcurrentMap<Object, TValue> createValueMap() {
|
||||
private ConcurrentMap<Object, TValue> createValueMap() {
|
||||
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.
|
||||
* @return The key map.
|
||||
*/
|
||||
protected ConcurrentMap<Object, Player> createKeyCache() {
|
||||
private ConcurrentMap<Object, Player> createKeyCache() {
|
||||
return SafeCacheBuilder.newBuilder().
|
||||
weakValues().
|
||||
removalListener(
|
||||
new RemovalListener<Object, Player>() {
|
||||
@Override
|
||||
public void onRemoval(RemovalNotification<Object, Player> removed) {
|
||||
// We ignore explicit removal
|
||||
if (removed.wasEvicted()) {
|
||||
onCacheEvicted(removed.getKey());
|
||||
}
|
||||
}
|
||||
}).
|
||||
(RemovalListener<Object, Player>) removed -> {
|
||||
// We ignore explicit removal
|
||||
if (removed.wasEvicted()) {
|
||||
onCacheEvicted(removed.getKey());
|
||||
}
|
||||
}).
|
||||
build(
|
||||
new CacheLoader<Object, Player>() {
|
||||
@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.
|
||||
* @param key - the key.
|
||||
* @param player - the value that was evicted or collected.
|
||||
*/
|
||||
private void onCacheEvicted(Object key) {
|
||||
Player newPlayer = findOnlinePlayer(key);
|
||||
@ -165,7 +160,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
|
||||
* @param key - a non-null key.
|
||||
* @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()) {
|
||||
if (key.equals(keyMethod.apply(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.
|
||||
* @return The player, or NULL if not found.
|
||||
*/
|
||||
protected Player lookupPlayer(Object key) {
|
||||
private Player lookupPlayer(Object key) {
|
||||
try {
|
||||
return keyLookup.get(key);
|
||||
} 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.
|
||||
* @return The key.
|
||||
*/
|
||||
protected Object cachePlayerKey(Player player) {
|
||||
private Object cachePlayerKey(Player player) {
|
||||
Object key = keyMethod.apply(player);
|
||||
|
||||
keyLookup.put(key, player);
|
||||
|
@ -26,7 +26,6 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
private static WrappedBlockData createNewData(BlockData data) {
|
||||
private static WrappedBlockData createNewData(Object 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
|
||||
* @return The new Wrapped Block Data
|
||||
*/
|
||||
public static WrappedBlockData createData(BlockData data) {
|
||||
public static WrappedBlockData createData(Object data) {
|
||||
return NewBlockData.createNewData(data);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
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_LIST = MinecraftReflection.getStatisticListClass();
|
||||
|
||||
private static final MethodAccessor FIND_STATISTICS = Accessors.getMethodAccessor(
|
||||
FuzzyReflection.fromClass(STATISTIC_LIST).getMethodByParameters(
|
||||
"findStatistic", STATISTIC, new Class<?>[] { String.class }
|
||||
)
|
||||
);
|
||||
private static final FieldAccessor MAP_ACCESSOR = Accessors.getFieldAccessor(STATISTIC_LIST, Map.class, true);
|
||||
private static final FieldAccessor GET_NAME = Accessors.getFieldAccessor(STATISTIC, String.class, true);
|
||||
|
||||
static {
|
||||
try {
|
||||
FIND_STATISTICS = Accessors.getMethodAccessor(
|
||||
FuzzyReflection.fromClass(STATISTIC_LIST).getMethodByParameters(
|
||||
"findStatistic", STATISTIC, new Class<?>[]{String.class}));
|
||||
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;
|
||||
|
||||
@ -62,12 +72,7 @@ public class WrappedStatistic extends AbstractWrapper {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Object> map = (Map<Object, Object>) MAP_ACCESSOR.get(null);
|
||||
|
||||
return Iterables.transform(map.values(), new Function<Object, WrappedStatistic>() {
|
||||
@Override
|
||||
public WrappedStatistic apply(Object handle) {
|
||||
return fromHandle(handle);
|
||||
};
|
||||
});
|
||||
return map.values().stream().map(WrappedStatistic::fromHandle).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,10 @@
|
||||
name: ProtocolLib
|
||||
#version: ${project.fullVersion}
|
||||
version: 4.4.0
|
||||
version: 4.5.0-SNAPSHOT
|
||||
description: Provides read/write access to the Minecraft protocol.
|
||||
authors: [dmulloy2, comphenix]
|
||||
|
||||
main: com.comphenix.protocol.ProtocolLib
|
||||
load: startup
|
||||
load: STARTUP
|
||||
database: false
|
||||
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user