Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
e3535c379a
Commit
e0659c1bb2
@ -33,7 +33,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class HullHiderWrapper18 implements HullHiderWrapper {
|
public class HullHiderWrapper18 implements HullHiderWrapper {
|
||||||
|
|
||||||
private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftBlockData"), "getState", IBlockData.class);
|
private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class);
|
||||||
@Override
|
@Override
|
||||||
public Object generateBlockChangePacket(List<Hull.IntVector> changes) {
|
public Object generateBlockChangePacket(List<Hull.IntVector> changes) {
|
||||||
Object[] blockdata = new Object[changes.size()];
|
Object[] blockdata = new Object[changes.size()];
|
||||||
@ -48,15 +48,21 @@ public class HullHiderWrapper18 implements HullHiderWrapper {
|
|||||||
|
|
||||||
private Object generateBlockChangePacket(List<Hull.IntVector> changes, Object[] blockdata) {
|
private Object generateBlockChangePacket(List<Hull.IntVector> changes, Object[] blockdata) {
|
||||||
if(changes.size() > 1) {
|
if(changes.size() > 1) {
|
||||||
|
Hull.IntVector section = changes.get(0);
|
||||||
|
//section = new Hull.IntVector(ProtocolUtils.posToChunk(section.getX()), ProtocolUtils.posToChunk(section.getY()), ProtocolUtils.posToChunk(section.getZ()));
|
||||||
|
section = new Hull.IntVector(section.getX() >> 4, section.getY() >> 4, section.getZ() >> 4);
|
||||||
|
int xOffset = 16*section.getX();
|
||||||
|
int yOffset = 16*section.getY();
|
||||||
|
int zOffset = 16*section.getZ();
|
||||||
|
|
||||||
short[] pos = new short[changes.size()];
|
short[] pos = new short[changes.size()];
|
||||||
for(int i = 0; i < changes.size(); i++) {
|
for(int i = 0; i < changes.size(); i++) {
|
||||||
Hull.IntVector change = changes.get(i);
|
Hull.IntVector change = changes.get(i);
|
||||||
|
|
||||||
pos[i] = (short) ((change.getX()%16) << 8 + (change.getZ()%16) << 4 + change.getY()%16);
|
pos[i] = (short) (((change.getX()-xOffset) << 8) + ((change.getZ()-zOffset) << 4) + (change.getY()-yOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
Hull.IntVector section = changes.get(0);
|
return constructMultiBlockChange(section, pos, blockdata);
|
||||||
return constructMultiBlockChange(new Hull.IntVector(section.getX() >> 4, section.getY() >> 4, section.getZ() >> 4), pos, blockdata);
|
|
||||||
} else {
|
} else {
|
||||||
Hull.IntVector pos = changes.get(0);
|
Hull.IntVector pos = changes.get(0);
|
||||||
return new PacketPlayOutBlockChange(new BlockPosition(pos.getX(), pos.getY(), pos.getZ()), (IBlockData) blockdata[0]);
|
return new PacketPlayOutBlockChange(new BlockPosition(pos.getX(), pos.getY(), pos.getZ()), (IBlockData) blockdata[0]);
|
||||||
|
@ -83,8 +83,6 @@ public abstract class Countdown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(Countdown countdown : new ArrayList<>(currentCountdowns)) {
|
for(Countdown countdown : new ArrayList<>(currentCountdowns)) {
|
||||||
if(countdown.time - smallestTime <= 1)
|
|
||||||
countdown.prepareFinish();
|
|
||||||
countdown.time -= smallestTime;
|
countdown.time -= smallestTime;
|
||||||
countdown.show();
|
countdown.show();
|
||||||
}
|
}
|
||||||
@ -104,8 +102,6 @@ public abstract class Countdown {
|
|||||||
Bukkit.getOnlinePlayers().forEach(p -> sendCountdownMessage(p, message, time / divisor, appendix));
|
Bukkit.getOnlinePlayers().forEach(p -> sendCountdownMessage(p, message, time / divisor, appendix));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void prepareFinish() {}
|
|
||||||
|
|
||||||
public int getTimeLeft(){
|
public int getTimeLeft(){
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
@ -124,7 +120,6 @@ public abstract class Countdown {
|
|||||||
broadcast("COUNTDOWN_SECONDS", 1);
|
broadcast("COUNTDOWN_SECONDS", 1);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
prepareFinish();
|
|
||||||
broadcast("COUNTDOWN_SECOND", 1);
|
broadcast("COUNTDOWN_SECOND", 1);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -22,8 +22,10 @@ package de.steamwar.fightsystem.countdown;
|
|||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.events.BoardingEvent;
|
import de.steamwar.fightsystem.events.BoardingEvent;
|
||||||
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||||
import de.steamwar.fightsystem.utils.Message;
|
import de.steamwar.fightsystem.utils.Message;
|
||||||
|
import de.steamwar.fightsystem.utils.Region;
|
||||||
import de.steamwar.fightsystem.utils.SWSound;
|
import de.steamwar.fightsystem.utils.SWSound;
|
||||||
import de.steamwar.techhider.ProtocolUtils;
|
import de.steamwar.techhider.ProtocolUtils;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
@ -61,15 +63,10 @@ public class EnternCountdown extends Countdown {
|
|||||||
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
|
FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR);
|
||||||
fightPlayer.ifPlayer(player -> {
|
fightPlayer.ifPlayer(player -> {
|
||||||
FightSystem.getHullHider().updatePlayer(player);
|
FightSystem.getHullHider().updatePlayer(player);
|
||||||
FightSystem.getTechHider().reloadChunks(player, chunkPos, false);
|
FightSystem.getTechHider().reloadChunks(player, Fight.getOpposite(fightPlayer.getTeam()).getExtendRegion(), Region.EMPTY);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void prepareFinish() {
|
|
||||||
chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getEntity(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void broadcast(String message, int divisor) {
|
protected void broadcast(String message, int divisor) {
|
||||||
fightPlayer.ifPlayer(player -> {
|
fightPlayer.ifPlayer(player -> {
|
||||||
|
@ -40,7 +40,6 @@ import de.steamwar.fightsystem.winconditions.Winconditions;
|
|||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.techhider.ProtocolUtils;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
@ -262,7 +261,6 @@ public class FightTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) {
|
public void addMember(LivingEntity entity, SteamwarUser user, boolean silent) {
|
||||||
final List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, false);
|
|
||||||
FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this);
|
FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this);
|
||||||
fightPlayer.revive();
|
fightPlayer.revive();
|
||||||
players.put(entity.getUniqueId(), fightPlayer);
|
players.put(entity.getUniqueId(), fightPlayer);
|
||||||
@ -291,7 +289,7 @@ public class FightTeam {
|
|||||||
if(FightState.Running.contains(FightState.getFightState()))
|
if(FightState.Running.contains(FightState.getFightState()))
|
||||||
fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown());
|
fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown());
|
||||||
|
|
||||||
fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false));
|
fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, Config.ArenaRegion, fightPlayer.canEntern() ? Region.EMPTY : Fight.getOpposite(this).getExtendRegion()));
|
||||||
|
|
||||||
if(isLeaderless())
|
if(isLeaderless())
|
||||||
setLeader(fightPlayer, silent);
|
setLeader(fightPlayer, silent);
|
||||||
@ -304,7 +302,6 @@ public class FightTeam {
|
|||||||
Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer));
|
Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer));
|
||||||
|
|
||||||
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
|
fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator);
|
||||||
List<ProtocolUtils.ChunkPos> chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true);
|
|
||||||
players.remove(entity.getUniqueId());
|
players.remove(entity.getUniqueId());
|
||||||
team.removeEntry(entity.getName());
|
team.removeEntry(entity.getName());
|
||||||
Permanent.getSpectatorTeam().addEntry(entity.getName());
|
Permanent.getSpectatorTeam().addEntry(entity.getName());
|
||||||
@ -322,7 +319,7 @@ public class FightTeam {
|
|||||||
|
|
||||||
if(player.isOnline()){
|
if(player.isOnline()){
|
||||||
FightSystem.getHullHider().updatePlayer(player);
|
FightSystem.getHullHider().updatePlayer(player);
|
||||||
FightSystem.getTechHider().reloadChunks(player, chunksToReload, true);
|
FightSystem.getTechHider().reloadChunks(player, Config.ArenaRegion, Fight.getOpposite(this).getExtendRegion());
|
||||||
|
|
||||||
if(ArenaMode.VariableTeams.contains(Config.mode))
|
if(ArenaMode.VariableTeams.contains(Config.mode))
|
||||||
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
|
HotbarKit.SPECTATOR_KIT.loadToPlayer(player);
|
||||||
|
@ -49,7 +49,7 @@ public class Hull {
|
|||||||
private final Map<IntVector, Map<IntVector, BitSet>> blockVisibility = new HashMap<>();
|
private final Map<IntVector, Map<IntVector, BitSet>> blockVisibility = new HashMap<>();
|
||||||
private final Set<IntVector> uncoveredSurface = new HashSet<>();
|
private final Set<IntVector> uncoveredSurface = new HashSet<>();
|
||||||
|
|
||||||
private final Set<Player> players = new HashSet<>();
|
private final HashSet<Player> players = new HashSet<>();
|
||||||
private final Set<Entity> entities = new HashSet<>();
|
private final Set<Entity> entities = new HashSet<>();
|
||||||
private final Set<REntity> rentities = new HashSet<>();
|
private final Set<REntity> rentities = new HashSet<>();
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class Hull {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlockHidden(Player player, int x, int y, int z) {
|
public boolean isBlockHidden(Player player, int x, int y, int z) {
|
||||||
return players.contains(player) && region.inRegion(x, y, z) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX()));
|
return region.inRegion(x, y, z) && players.contains(player) && !visibility.get(((y - region.getMinY()) * region.getSizeZ() + (z - region.getMinZ())) * region.getSizeX() + (x - region.getMinX()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLocationHidden(Player player, Location location) {
|
public boolean isLocationHidden(Player player, Location location) {
|
||||||
|
@ -57,14 +57,18 @@ import java.util.function.Function;
|
|||||||
public class HullHider implements Listener {
|
public class HullHider implements Listener {
|
||||||
|
|
||||||
public static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18;
|
public static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18;
|
||||||
private final Map<FightTeam, Hull> hulls = new HashMap<>();
|
private final Map<FightTeam, Hull> hullMap = new HashMap<>();
|
||||||
|
private final Hull[] hulls;
|
||||||
private final Map<Class<?>, BiFunction<Player, Object, Object>> packetHiders = new HashMap<>();
|
private final Map<Class<?>, BiFunction<Player, Object, Object>> packetHiders = new HashMap<>();
|
||||||
|
|
||||||
public HullHider() {
|
public HullHider() {
|
||||||
if(!ENABLED)
|
if(!ENABLED) {
|
||||||
|
hulls = new Hull[0];
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Fight.teams().forEach(team -> hulls.put(team, new Hull(team)));
|
Fight.teams().forEach(team -> hullMap.put(team, new Hull(team)));
|
||||||
|
hulls = hullMap.values().toArray(new Hull[0]);
|
||||||
|
|
||||||
packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider);
|
packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider);
|
||||||
packetHiders.put(packetPlayOutExplosion, this::explosionHider);
|
packetHiders.put(packetPlayOutExplosion, this::explosionHider);
|
||||||
@ -94,7 +98,7 @@ public class HullHider implements Listener {
|
|||||||
if(!ENABLED)
|
if(!ENABLED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hulls.get(team).initialize();
|
hullMap.get(team).initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +118,7 @@ public class HullHider implements Listener {
|
|||||||
|
|
||||||
FightTeam team = Fight.getPlayerTeam(player);
|
FightTeam team = Fight.getPlayerTeam(player);
|
||||||
FightPlayer fp = Fight.getFightPlayer(player);
|
FightPlayer fp = Fight.getFightPlayer(player);
|
||||||
for(Map.Entry<FightTeam, Hull> hull : hulls.entrySet()) {
|
for(Map.Entry<FightTeam, Hull> hull : hullMap.entrySet()) {
|
||||||
if(hull.getKey() == team || (fp != null && fp.canEntern())) {
|
if(hull.getKey() == team || (fp != null && fp.canEntern())) {
|
||||||
hull.getValue().removePlayer(player, true);
|
hull.getValue().removePlayer(player, true);
|
||||||
} else {
|
} else {
|
||||||
@ -124,7 +128,8 @@ public class HullHider implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removePlayer(Player player, boolean activeRemoval) {
|
private void removePlayer(Player player, boolean activeRemoval) {
|
||||||
hulls.values().forEach(hull -> hull.removePlayer(player, activeRemoval));
|
for (Hull hull : hulls)
|
||||||
|
hull.removePlayer(player, activeRemoval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -135,7 +140,7 @@ public class HullHider implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void blockUpdate(Block block, Material changedType) {
|
public void blockUpdate(Block block, Material changedType) {
|
||||||
for (Hull hull : hulls.values())
|
for (Hull hull : hulls)
|
||||||
hull.updateBlockVisibility(block, changedType);
|
hull.updateBlockVisibility(block, changedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +148,7 @@ public class HullHider implements Listener {
|
|||||||
if(!ENABLED)
|
if(!ENABLED)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (Hull hull : hulls.values())
|
for (Hull hull : hulls)
|
||||||
if(hull.isBlockHidden(player, x, y, z))
|
if(hull.isBlockHidden(player, x, y, z))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -153,30 +158,34 @@ public class HullHider implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onSpawn(EntitySpawnEvent e) {
|
public void onSpawn(EntitySpawnEvent e) {
|
||||||
hulls.values().forEach(hull -> hull.checkEntity(e.getEntity()));
|
for (Hull hull : hulls)
|
||||||
|
hull.checkEntity(e.getEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onTick() {
|
private void onTick() {
|
||||||
Recording.iterateOverEntities(Objects::nonNull, entity -> {
|
Recording.iterateOverEntities(Objects::nonNull, entity -> {
|
||||||
for (Hull hull : hulls.values())
|
for (Hull hull : hulls)
|
||||||
hull.checkEntity(entity);
|
hull.checkEntity(entity);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (Hull hull : hulls.values())
|
for (Hull hull : hulls)
|
||||||
hull.sendUncoveredBlocks();
|
hull.sendUncoveredBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onDeath(EntityDeathEvent e) {
|
public void onDeath(EntityDeathEvent e) {
|
||||||
hulls.values().forEach(hull -> hull.removeEntity(e.getEntity()));
|
for(Hull hull : hulls)
|
||||||
|
hull.removeEntity(e.getEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateREntity(REntity e) {
|
public void updateREntity(REntity e) {
|
||||||
hulls.values().forEach(hull -> hull.checkREntity(e));
|
for(Hull hull : hulls)
|
||||||
|
hull.checkREntity(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void despawnREntity(REntity e) {
|
public void despawnREntity(REntity e) {
|
||||||
hulls.values().forEach(hull -> hull.removeREntity(e));
|
for(Hull hull : hulls)
|
||||||
|
hull.removeREntity(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -213,7 +222,7 @@ public class HullHider implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object packetHider(Player player, Object packet, Location location) {
|
private Object packetHider(Player player, Object packet, Location location) {
|
||||||
for(Hull hull : hulls.values()) {
|
for(Hull hull : hulls) {
|
||||||
if(hull.isLocationHidden(player, location))
|
if(hull.isLocationHidden(player, location))
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ import java.util.function.ObjIntConsumer;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class Region {
|
public class Region {
|
||||||
|
|
||||||
|
public static final Region EMPTY = Region.fromSize(-10000, -10000, -10000, 0, 0, 0);
|
||||||
|
|
||||||
public static Region withExtension(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) {
|
public static Region withExtension(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) {
|
||||||
return Region.fromSize(minX - extendX, minY - extendY, minZ - extendZ,
|
return Region.fromSize(minX - extendX, minY - extendY, minZ - extendZ,
|
||||||
sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2);
|
sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2);
|
||||||
|
@ -22,32 +22,36 @@ package de.steamwar.fightsystem.utils;
|
|||||||
import de.steamwar.core.CraftbukkitWrapper;
|
import de.steamwar.core.CraftbukkitWrapper;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.events.BoardingEvent;
|
||||||
|
import de.steamwar.fightsystem.events.TeamLeaveEvent;
|
||||||
|
import de.steamwar.fightsystem.events.TeamSpawnEvent;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
import de.steamwar.techhider.ProtocolUtils;
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
import de.steamwar.techhider.TechHider;
|
import de.steamwar.techhider.TechHider;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator {
|
public class TechHiderWrapper extends StateDependent implements TechHider.LocationEvaluator, Listener {
|
||||||
|
|
||||||
public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
|
public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
|
||||||
|
|
||||||
private final Region empty = Region.fromSize(-10000, -10000, -10000, 0, 0, 0);
|
private final ConcurrentHashMap<Player, Region> hiddenRegion = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final TechHider techHider;
|
private final TechHider techHider;
|
||||||
|
|
||||||
public TechHiderWrapper() {
|
public TechHiderWrapper() {
|
||||||
super(ENABLED, FightState.Schem);
|
super(ENABLED, FightState.Schem);
|
||||||
techHider = new TechHider(this, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities);
|
techHider = new TechHider(this, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks, Config.HiddenBlockEntities);
|
||||||
|
|
||||||
|
new StateDependentListener(ENABLED, FightState.Schem, this);
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,30 +63,41 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
|
|||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
techHider.disable();
|
techHider.disable();
|
||||||
|
hiddenRegion.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProtocolUtils.ChunkPos> prepareChunkReload(LivingEntity p, boolean hide) {
|
@EventHandler
|
||||||
if(!ENABLED || !(p instanceof Player))
|
public void teamJoin(TeamSpawnEvent e) {
|
||||||
return Collections.emptyList();
|
e.getFightPlayer().ifPlayer(player -> hiddenRegion.put(player, getHiddenRegion(player)));
|
||||||
|
}
|
||||||
|
|
||||||
List<ProtocolUtils.ChunkPos> chunksToReload = new ArrayList<>();
|
@EventHandler
|
||||||
Config.ArenaRegion.forEachChunk((x, z) -> {
|
public void boarding(BoardingEvent e) {
|
||||||
if(skipChunk((Player) p, x, z) == hide)
|
e.getFightPlayer().ifPlayer(player -> hiddenRegion.put(player, getHiddenRegion(player)));
|
||||||
chunksToReload.add(new ProtocolUtils.ChunkPos(x, z));
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void teamLeave(TeamLeaveEvent e) {
|
||||||
|
e.getFightPlayer().ifPlayer(player -> {
|
||||||
|
if(player.isOnline())
|
||||||
|
hiddenRegion.put(player, getHiddenRegion(player));
|
||||||
});
|
});
|
||||||
return chunksToReload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadChunks(Player p, List<ProtocolUtils.ChunkPos> chunksToReload, boolean hide) {
|
@EventHandler
|
||||||
if(!ENABLED || !FightState.Schem.contains(FightState.getFightState()))
|
public void playerQuit(PlayerQuitEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
hiddenRegion.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadChunks(Player player, Region region, Region exclusion) {
|
||||||
|
if(!ENABLED || !FightState.Schem.contains(FightState.getFightState()) || !player.isOnline())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
region.forEachChunk((chunkX, chunkZ) -> {
|
||||||
for(ProtocolUtils.ChunkPos chunk : chunksToReload){
|
if(exclusion.chunkOutside(chunkX, chunkZ))
|
||||||
if(skipChunk(p, chunk.x(), chunk.z()) != hide)
|
CraftbukkitWrapper.impl.sendChunk(player, chunkX, chunkZ);
|
||||||
CraftbukkitWrapper.impl.sendChunk(p, chunk.x(), chunk.z());
|
});
|
||||||
}
|
|
||||||
}, 40);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -92,13 +107,12 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean skipChunkSection(Player player, int chunkX, int chunkY, int chunkZ) {
|
public boolean skipChunkSection(Player player, int chunkX, int chunkY, int chunkZ) {
|
||||||
//TODO chunkhider skip sections
|
|
||||||
return getHiddenRegion(player).chunkSectionOutside(chunkX, chunkY, chunkZ);
|
return getHiddenRegion(player).chunkSectionOutside(chunkX, chunkY, chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TechHider.State check(Player player, int x, int y, int z) {
|
public TechHider.State check(Player player, int x, int y, int z) {
|
||||||
if(getHiddenRegion(player).inRegion(x, y, z)) {
|
if(hiddenRegion.computeIfAbsent(player, this::getHiddenRegion).inRegion(x, y, z)) {
|
||||||
if(FightSystem.getHullHider().isBlockHidden(player, x, y, z)) {
|
if(FightSystem.getHullHider().isBlockHidden(player, x, y, z)) {
|
||||||
return TechHider.State.HIDE;
|
return TechHider.State.HIDE;
|
||||||
} else {
|
} else {
|
||||||
@ -111,14 +125,14 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
|
|||||||
|
|
||||||
private Region getHiddenRegion(Player player) {
|
private Region getHiddenRegion(Player player) {
|
||||||
if(Config.isReferee(player))
|
if(Config.isReferee(player))
|
||||||
return empty;
|
return Region.EMPTY;
|
||||||
|
|
||||||
FightTeam team = Fight.getPlayerTeam(player);
|
FightTeam team = Fight.getPlayerTeam(player);
|
||||||
if(team == null)
|
if(team == null)
|
||||||
return Config.ArenaRegion;
|
return Config.ArenaRegion;
|
||||||
|
|
||||||
if(team.canPlayerEntern(player))
|
if(team.canPlayerEntern(player))
|
||||||
return empty;
|
return Region.EMPTY;
|
||||||
|
|
||||||
return Fight.getOpposite(team).getExtendRegion();
|
return Fight.getOpposite(team).getExtendRegion();
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren