Dieser Commit ist enthalten in:
Ursprung
b5a9b3d068
Commit
c02d7c2c7d
@ -35,6 +35,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -49,7 +50,7 @@ public class REntityServer implements Listener {
|
|||||||
private static final Reflection.FieldAccessor<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0);
|
private static final Reflection.FieldAccessor<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0);
|
||||||
private static final Reflection.FieldAccessor<Integer> useEntityAction = Reflection.getField(useEntity, int.class, 1);
|
private static final Reflection.FieldAccessor<Integer> useEntityAction = Reflection.getField(useEntity, int.class, 1);
|
||||||
|
|
||||||
private final HashMap<Integer, REntity> entityMap = new HashMap<>();
|
private final ConcurrentHashMap<Integer, REntity> entityMap = new ConcurrentHashMap<>();
|
||||||
private final HashMap<Long, HashSet<REntity>> entities = new HashMap<>();
|
private final HashMap<Long, HashSet<REntity>> entities = new HashMap<>();
|
||||||
private final HashMap<Long, Set<Player>> players = new HashMap<>();
|
private final HashMap<Long, Set<Player>> players = new HashMap<>();
|
||||||
private final HashMap<Player, Location> lastLocation = new HashMap<>();
|
private final HashMap<Player, Location> lastLocation = new HashMap<>();
|
||||||
@ -60,26 +61,23 @@ public class REntityServer implements Listener {
|
|||||||
private BiFunction<Player, Object, Object> filter = (player, packet) -> {
|
private BiFunction<Player, Object, Object> filter = (player, packet) -> {
|
||||||
if (callback == null) return packet;
|
if (callback == null) return packet;
|
||||||
int target = useEntityTarget.get(packet);
|
int target = useEntityTarget.get(packet);
|
||||||
if (!entityMap.containsKey(target)) return packet;
|
|
||||||
|
|
||||||
REntity entity = entityMap.get(target);
|
REntity entity = entityMap.get(target);
|
||||||
int action = useEntityAction.get(packet);
|
if (entity == null) return packet;
|
||||||
if (action == 2) action = 0;
|
|
||||||
int finalAction = action;
|
|
||||||
|
|
||||||
|
EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT;
|
||||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||||
callback.onAction(player, entity, finalAction == 0 ? EntityAction.INTERACT : EntityAction.ATTACK);
|
callback.onAction(player, entity, action);
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
public REntityServer() {
|
public REntityServer() {
|
||||||
Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance());
|
Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance());
|
||||||
TinyProtocol.instance.addFilter(useEntity, filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCallback(EntityActionListener callback) {
|
public void setCallback(EntityActionListener callback) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
TinyProtocol.instance.addFilter(useEntity, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(Player player) {
|
public void addPlayer(Player player) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren