Merge branch 'master' into seperate_schemdata
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
# Conflicts: # CommonCore
Dieser Commit ist enthalten in:
Commit
a005bdaefb
@ -1 +1 @@
|
||||
Subproject commit e52e9c5ccd8ef9b87ce06d4eeeaaa4044afa89b5
|
||||
Subproject commit d22bb36fc348fae373713b83235cef67010cf020
|
@ -35,10 +35,7 @@ public class PlayerJoinedEvent implements Listener{
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
private void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(!Statement.productionDatabase()) {
|
||||
SteamwarUser.createOrUpdateUsername(player.getUniqueId(), player.getName());
|
||||
}
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}, (oldName, newName) -> {});
|
||||
|
||||
if(user.getUserGroup() != UserGroup.Member) {
|
||||
UserGroup group = user.getUserGroup();
|
||||
|
@ -23,6 +23,7 @@ import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -39,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public class REntityServer implements Listener {
|
||||
@ -48,7 +50,17 @@ public class REntityServer implements Listener {
|
||||
|
||||
private static final Class<?> useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity");
|
||||
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 Class<?> useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction");
|
||||
private static final Reflection.FieldAccessor<?> useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0);
|
||||
private static final Function<Object, Integer> getEntityAction;
|
||||
static {
|
||||
if(Core.getVersion() > 15) {
|
||||
Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a");
|
||||
getEntityAction = value -> ((Enum<?>) useEntityGetAction.invoke(value)).ordinal();
|
||||
} else {
|
||||
getEntityAction = value -> ((Enum<?>) value).ordinal();
|
||||
}
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<Integer, REntity> entityMap = new ConcurrentHashMap<>();
|
||||
private final HashMap<Long, HashSet<REntity>> entities = new HashMap<>();
|
||||
@ -58,16 +70,13 @@ public class REntityServer implements Listener {
|
||||
|
||||
private EntityActionListener callback = null;
|
||||
|
||||
private BiFunction<Player, Object, Object> filter = (player, packet) -> {
|
||||
if (callback == null) return packet;
|
||||
int target = useEntityTarget.get(packet);
|
||||
REntity entity = entityMap.get(target);
|
||||
if (entity == null) return packet;
|
||||
private final BiFunction<Player, Object, Object> filter = (player, packet) -> {
|
||||
REntity entity = entityMap.get(useEntityTarget.get(packet));
|
||||
if (entity == null)
|
||||
return packet;
|
||||
|
||||
/*EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT;
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||
callback.onAction(player, entity, action);
|
||||
});*/
|
||||
EntityAction action = getEntityAction.apply(useEntityAction.get(packet)) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT;
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> callback.onAction(player, entity, action));
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -192,7 +201,14 @@ public class REntityServer implements Listener {
|
||||
if(location == null)
|
||||
return;
|
||||
|
||||
forChunkInView(player, location, (x, z) -> players.get(chunkToId(x, z)).remove(player));
|
||||
forChunkInView(player, location, (x, z) -> {
|
||||
long id = chunkToId(x, z);
|
||||
Set<Player> playersInChunk = players.get(id);
|
||||
playersInChunk.remove(player);
|
||||
if(playersInChunk.isEmpty())
|
||||
players.remove(id);
|
||||
});
|
||||
viewDistance.remove(player);
|
||||
}
|
||||
|
||||
private void onMissing(Set<Player> of, Set<Player> in, Consumer<Consumer<Object>> packetProvider) {
|
||||
@ -228,7 +244,12 @@ public class REntityServer implements Listener {
|
||||
|
||||
private void removePlayerFromChunk(Player player, int x, int z) {
|
||||
long id = chunkToId(x, z);
|
||||
players.get(id).remove(player);
|
||||
|
||||
Set<Player> playersInChunk = players.get(id);
|
||||
playersInChunk.remove(player);
|
||||
if(playersInChunk.isEmpty())
|
||||
players.remove(id);
|
||||
|
||||
for(REntity entity : entities.getOrDefault(id, emptyEntities)) {
|
||||
entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren