HullHider v2 #408
@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
@ -56,4 +57,11 @@ public class BlockIdWrapper14 implements BlockIdWrapper {
|
||||
getTypeAndData.invoke(nworld, pos, blockData, 1042);
|
||||
flagDirty.invoke(getChunkProvider.invoke(nworld), pos);
|
||||
}
|
||||
|
||||
private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block);
|
||||
private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block);
|
||||
@Override
|
||||
public Material idToMaterial(int blockState) {
|
||||
return (Material)getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(getByCombinedId.invoke(null, blockState)));
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
@ -37,4 +38,13 @@ public class BlockIdWrapper8 implements BlockIdWrapper {
|
||||
|
||||
world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Material idToMaterial(int blockState) {
|
||||
if((blockState >> 4) > 256) // Illegal blockstate / corrupted replay
|
||||
blockState = 0;
|
||||
|
||||
return Material.getMaterial(blockState >> 4);
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +437,10 @@ public class PacketProcessor implements Listener {
|
||||
if(!Config.ArenaRegion.in2dRegion(x, z))
|
||||
return; //Outside of the arena
|
||||
|
||||
execSync(() -> BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHiderWrapper.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState));
|
||||
execSync(() -> {
|
||||
BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHiderWrapper.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState);
|
||||
FightSystem.getHullHider().blockUpdate(Config.world.getBlockAt(x, y, z), BlockIdWrapper.impl.idToMaterial(blockState));
|
||||
});
|
||||
}
|
||||
|
||||
private void particle() throws IOException {
|
||||
|
@ -21,12 +21,14 @@ package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.core.VersionDependent;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public interface BlockIdWrapper {
|
||||
BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin());
|
||||
|
||||
Material idToMaterial(int blockState);
|
||||
int blockToId(Block block);
|
||||
void setBlock(World world, int x, int y, int z, int blockState);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.Recording;
|
||||
@ -27,6 +28,8 @@ import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -43,6 +46,7 @@ import java.util.Objects;
|
||||
|
||||
public class HullHider implements Listener {
|
||||
|
||||
private static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18;
|
||||
private final Map<FightTeam, Hull> hulls = new HashMap<>();
|
||||
|
||||
//SpawnPackets: PacketPlayOutSpawnEntity, PacketPlayOutSpawnEntityWeather, PacketPlayOutSpawnEntityLiving, PacketPlayOutSpawnEntityPainting, PacketPlayOutSpawnEntityPlayer
|
||||
@ -51,11 +55,11 @@ public class HullHider implements Listener {
|
||||
//Other: Effect, Particle, Explosion
|
||||
//Death: DestroyEntities
|
||||
public HullHider() {
|
||||
if(TechHiderWrapper.ENABLED)
|
||||
if(ENABLED)
|
||||
Fight.teams().forEach(team -> hulls.put(team, new Hull(team)));
|
||||
|
||||
new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this);
|
||||
new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) {
|
||||
new StateDependentListener(ENABLED, FightState.Schem, this);
|
||||
new StateDependent(ENABLED, FightState.Schem) {
|
||||
@Override
|
||||
public void enable() {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> addPlayer(player, true));
|
||||
@ -65,12 +69,12 @@ public class HullHider implements Listener {
|
||||
public void disable() {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> removePlayer(player, true));
|
||||
}
|
||||
};
|
||||
new StateDependentTask(TechHiderWrapper.ENABLED, FightState.Schem, this::onTick, 0, 1);
|
||||
}.register();
|
||||
new StateDependentTask(ENABLED, FightState.Schem, this::onTick, 0, 1);
|
||||
}
|
||||
|
||||
public void initialize(FightTeam team) {
|
||||
if(!TechHiderWrapper.ENABLED)
|
||||
if(!ENABLED)
|
||||
return;
|
||||
|
||||
hulls.get(team).initialize();
|
||||
@ -78,14 +82,14 @@ public class HullHider implements Listener {
|
||||
|
||||
|
||||
public void addPlayer(FightTeam team, Player player) {
|
||||
if(!TechHiderWrapper.ENABLED)
|
||||
if(!ENABLED)
|
||||
return;
|
||||
|
||||
hulls.get(team).addPlayer(player, true);
|
||||
}
|
||||
|
||||
public void removePlayer(FightTeam team, Player player) {
|
||||
if(!TechHiderWrapper.ENABLED)
|
||||
if(!ENABLED)
|
||||
return;
|
||||
|
||||
hulls.get(team).removePlayer(player, true);
|
||||
@ -118,10 +122,13 @@ public class HullHider implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockPhysic(BlockPhysicsEvent e) {
|
||||
if(FlatteningWrapper.impl.doRecord(e)) {
|
||||
for (Hull hull : hulls.values())
|
||||
hull.updateBlockVisibility(e.getBlock(), e.getChangedType());
|
||||
if(FlatteningWrapper.impl.doRecord(e))
|
||||
blockUpdate(e.getBlock(), e.getChangedType());
|
||||
}
|
||||
|
||||
public void blockUpdate(Block block, Material changedType) {
|
||||
for (Hull hull : hulls.values())
|
||||
hull.updateBlockVisibility(block, changedType);
|
||||
}
|
||||
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren