SteamWar/FightSystem
Archiviert
13
1

Techhider (except for Full chunks)

Dieser Commit ist enthalten in:
Lixfel 2019-05-28 06:16:16 +02:00
Ursprung 579d5bebf7
Commit 4ba8e49735
4 geänderte Dateien mit 173 neuen und 131 gelöschten Zeilen

Datei anzeigen

@ -51,71 +51,73 @@ Money:
Kits: Kits:
MemberDefault: default MemberDefault: default
LeaderDefault: default LeaderDefault: default
HiddenBlocks: Techhider:
- 7 ObfuscateWith: 1
- 8 HiddenBlocks:
- 9 - 7
- 25 - 8
- 27 - 9
- 28 - 25
- 29 - 27
- 33 - 28
- 34 - 29
- 46 - 33
- 49 - 34
- 54 - 46
- 55 - 49
- 63 - 54
- 68 - 55
- 69 - 63
- 70 - 68
- 71 - 69
- 72 - 70
- 75 - 71
- 76 - 72
- 77 - 75
- 93 - 76
- 94 - 77
- 117 - 93
- 131 - 94
- 132 - 117
- 143 - 131
- 146 - 132
- 147 - 143
- 148 - 146
- 149 - 147
- 150 - 148
- 152 - 149
- 154 - 150
- 157 - 152
- 158 - 154
- 165 - 157
- 167 - 158
- 218 - 165
- 219 - 167
- 220 - 218
- 221 - 219
- 223 - 220
- 224 - 221
- 225 - 223
- 226 - 224
- 227 - 225
- 228 - 226
- 229 - 227
- 230 - 228
- 231 - 229
- 232 - 230
- 233 - 231
- 234 - 232
HiddenBlockEntites: - 233
- minecraft:sign - 234
- minecraft:dispenser HiddenBlockEntites:
- minecraft:chest - minecraft:sign
- minecraft:trapped_chest - minecraft:dispenser
- minecraft:furnace - minecraft:chest
- minecraft:brewing_stand - minecraft:trapped_chest
- minecraft:hopper - minecraft:furnace
- minecraft:dropper - minecraft:brewing_stand
- minecraft:shulker_box - minecraft:hopper
- minecraft:jukebox - minecraft:dropper
- minecraft:comparator - minecraft:shulker_box
- minecraft:jukebox
- minecraft:comparator

Datei anzeigen

@ -16,9 +16,9 @@ public class BlockPlaceListener implements Listener {
if(Fight.getPlayerTeam(player) == null) if(Fight.getPlayerTeam(player) == null)
event.setCancelled(true); event.setCancelled(true);
else if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) { else if(FightSystem.getFightState() != FightState.RUNNING) {
event.setCancelled(true); event.setCancelled(true);
if(FightSystem.getPlugin().getFightState() == FightState.PRE_RUNNING) { if(FightSystem.getFightState() == FightState.PRE_RUNNING || FightSystem.getFightState() == FightState.SETUP) {
player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke setzen!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke setzen!");
} else } else
player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr setzen!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr setzen!");

Datei anzeigen

@ -81,6 +81,7 @@ public class Config {
public static List<Integer> HiddenBlocks; public static List<Integer> HiddenBlocks;
public static List<String> HiddenBlockEntities; public static List<String> HiddenBlockEntities;
public static int ObfuscateWith;
public static void load(){ public static void load(){
if(!new File("plugins/" + FightSystem.getPlugin().getName() + "/config.yml").exists()) { if(!new File("plugins/" + FightSystem.getPlugin().getName() + "/config.yml").exists()) {
@ -139,8 +140,9 @@ public class Config {
MemberDefault = config.getString("Kits.MemberDefault"); MemberDefault = config.getString("Kits.MemberDefault");
LeaderDefault = config.getString("Kits.LeaderDefault"); LeaderDefault = config.getString("Kits.LeaderDefault");
HiddenBlocks = config.getIntegerList("HiddenBlocks"); HiddenBlocks = config.getIntegerList("Techhider.HiddenBlocks");
HiddenBlockEntities = config.getStringList("HiddenBlockEntities"); HiddenBlockEntities = config.getStringList("Techhider.HiddenBlockEntities");
ObfuscateWith = config.getInt("Techhider.ObfuscateWith");
if(SchemsizeX < 0){ if(SchemsizeX < 0){
SchemsizeX = -SchemsizeX; SchemsizeX = -SchemsizeX;

Datei anzeigen

@ -6,12 +6,17 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
import com.comphenix.protocol.wrappers.WrappedBlockData; import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.FightSystem;
import me.yaruma.fightsystem.fight.Fight;
import me.yaruma.fightsystem.fight.FightTeam;
import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,14 +25,45 @@ import java.util.List;
public class TechHider { public class TechHider {
private static int arenaMinX;
private static int arenaMaxX;
private static int arenaMinZ;
private static int arenaMaxZ;
private static int blueMinX;
private static int blueMaxX;
private static int blueMinZ;
private static int blueMaxZ;
private static int redMinX;
private static int redMaxX;
private static int redMinZ;
private static int redMaxZ;
private static int obfuscateShift4;
private static Material obfuscateMaterial;
public static void init(){ public static void init(){
arenaMinX = Config.ArenaMinX / 16 - (Config.ArenaMinX % 16 < 0 ? 1 : 0);
arenaMinZ = Config.ArenaMinZ / 16 - (Config.ArenaMinZ % 16 < 0 ? 1 : 0);
arenaMaxX = Config.ArenaMaxX / 16 + (Config.ArenaMaxX % 16 > 0 ? 1 : 0);
arenaMaxZ = Config.ArenaMaxZ / 16 + (Config.ArenaMaxZ % 16 > 0 ? 1 : 0);
blueMinX = Config.TeamBlueCornerX / 16 - (Config.TeamBlueCornerX % 16 < 0 ? 1 : 0);
blueMinZ = Config.TeamBlueCornerZ / 16 - (Config.TeamBlueCornerZ % 16 < 0 ? 1 : 0);
int max = Config.TeamBlueCornerX + Config.SchemsizeX;
blueMaxX = max / 16 + (max % 16 > 0 ? 1 : 0);
max = Config.TeamBlueCornerZ + Config.SchemsizeZ;
blueMaxZ = max / 16 + (max % 16 > 0 ? 1 : 0);
redMinX = Config.TeamRedCornerX / 16 - (Config.TeamRedCornerX % 16 < 0 ? 1 : 0);
redMinZ = Config.TeamRedCornerZ / 16 - (Config.TeamRedCornerZ % 16 < 0 ? 1 : 0);
max = Config.TeamRedCornerX + Config.SchemsizeX;
redMaxX = max / 16 + (max % 16 > 0 ? 1 : 0);
max = Config.TeamRedCornerZ + Config.SchemsizeZ;
redMaxZ = max / 16 + (max % 16 > 0 ? 1 : 0);
obfuscateShift4 = Config.ObfuscateWith << 4;
//noinspection deprecation
obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith);
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
@Override @Override
public void onPacketSending(PacketEvent e) { public void onPacketSending(PacketEvent e) {
Player p = e.getPlayer();
//TODO: Check for Which chunks to hide
PacketContainer packet = e.getPacket(); PacketContainer packet = e.getPacket();
StructureModifier<Integer> ints = packet.getIntegers(); StructureModifier<Integer> ints = packet.getIntegers();
StructureModifier<byte[]> byteArray = packet.getByteArrays(); StructureModifier<byte[]> byteArray = packet.getByteArrays();
@ -36,11 +72,15 @@ public class TechHider {
int chunkX = ints.read(0); int chunkX = ints.read(0);
int chunkZ = ints.read(1); int chunkZ = ints.read(1);
Player p = e.getPlayer();
if(bypass(p, chunkX, chunkZ))
return;
boolean changed = false; boolean changed = false;
for(int i = nmsTags.size() - 1; i >= 0; i--){ for(int i = nmsTags.size() - 1; i >= 0; i--){
NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i)); NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i));
if(nbt.getString("id").equals("minecraft:sign")){ if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){
nmsTags.remove(i); nmsTags.remove(i);
changed = true; changed = true;
} }
@ -72,7 +112,7 @@ public class TechHider {
int blockId = actPalette >> 4; int blockId = actPalette >> 4;
if(Config.HiddenBlocks.contains(blockId)){ if(Config.HiddenBlocks.contains(blockId)){
byte[] a = writeVarInt(16); byte[] a = writeVarInt(obfuscateShift4);
for(int j = 0; j < actPaletteLength; j++){ for(int j = 0; j < actPaletteLength; j++){
newData.remove(i); newData.remove(i);
} }
@ -119,42 +159,45 @@ public class TechHider {
} }
}); });
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
@SuppressWarnings("deprecation")
@Override @Override
public void onPacketSending(PacketEvent e) { public void onPacketSending(PacketEvent e) {
Player p = e.getPlayer();
//TODO: Check for Which chunks to hide
PacketContainer packet = e.getPacket(); PacketContainer packet = e.getPacket();
StructureModifier<WrappedBlockData> blockStructure = packet.getBlockData(); StructureModifier<WrappedBlockData> blockStructure = packet.getBlockData();
BlockPosition pos = packet.getBlockPositionModifier().read(0);
WrappedBlockData block = packet.getBlockData().read(0); Player p = e.getPlayer();
if(bypass(p, pos.getX() / 16, pos.getZ() / 16))
return;
WrappedBlockData block = blockStructure.read(0);
if(Config.HiddenBlocks.contains(block.getType().getId())){ if(Config.HiddenBlocks.contains(block.getType().getId())){
block.setType(Material.STONE); block.setType(obfuscateMaterial);
blockStructure.write(0, block); blockStructure.write(0, block);
e.setCancelled(true);
} }
} }
}); });
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
@SuppressWarnings("deprecation")
@Override @Override
public void onPacketSending(PacketEvent e) { public void onPacketSending(PacketEvent e) {
Player p = e.getPlayer();
//TODO: Check for Which chunks to hide
PacketContainer packet = e.getPacket(); PacketContainer packet = e.getPacket();
StructureModifier<MultiBlockChangeInfo[]> blockStructure = packet.getMultiBlockChangeInfoArrays(); StructureModifier<MultiBlockChangeInfo[]> blockStructure = packet.getMultiBlockChangeInfoArrays();
MultiBlockChangeInfo[] changes = blockStructure.read(0); MultiBlockChangeInfo[] changes = blockStructure.read(0);
boolean changed = false;
int i = 0; Player p = e.getPlayer();
ChunkCoordIntPair pos = changes[0].getChunk();
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
return;
boolean changed = false;
for(MultiBlockChangeInfo mbci : changes){ for(MultiBlockChangeInfo mbci : changes){
WrappedBlockData block = mbci.getData(); WrappedBlockData block = mbci.getData();
if(Config.HiddenBlocks.contains(block.getType().getId())){ if(Config.HiddenBlocks.contains(block.getType().getId())){
changed = true; changed = true;
block.setType(Material.STONE); block.setType(obfuscateMaterial);
mbci.setData(block); mbci.setData(block);
} }
i++;
} }
if(changed){ if(changed){
@ -165,10 +208,11 @@ public class TechHider {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) {
@Override @Override
public void onPacketSending(PacketEvent e) { public void onPacketSending(PacketEvent e) {
Player p = e.getPlayer();
//TODO: Check for Which chunks to hide
PacketContainer packet = e.getPacket(); PacketContainer packet = e.getPacket();
BlockPosition pos = packet.getBlockPositionModifier().read(0);
Player p = e.getPlayer();
if(bypass(p, pos.getX() / 16, pos.getZ() / 16))
return;
e.setCancelled(true); e.setCancelled(true);
} }
@ -177,17 +221,41 @@ public class TechHider {
@Override @Override
public void onPacketReceiving(PacketEvent e) { public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
//TODO: Check for Which chunks to hide
PacketContainer packet = e.getPacket(); if(p.getGameMode() == GameMode.SPECTATOR){
e.setCancelled(true);
}
}
});
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer();
System.out.println("EntityUse!"); if(p.getGameMode() == GameMode.SPECTATOR){
e.setCancelled(true); e.setCancelled(true);
}
} }
}); });
} }
public static int readVarInt(byte[] array, int startPos) { private static boolean bypass(Player p, int chunkX, int chunkZ){
if( ! (arenaMinX <= chunkX && chunkX <= arenaMaxX && arenaMinZ <= chunkZ && chunkZ <= arenaMaxZ)){
//Außerhalb der Arena
return true;
}
FightTeam ft = Fight.getPlayerTeam(p);
if(ft == null){
return false;
}else if(ft == Fight.getBlueTeam()){
return Config.Entern || ! (redMinX <= chunkX && chunkX <= redMaxX && redMinZ <= chunkZ && chunkZ <= redMaxZ);
}else{
return Config.Entern || ! (blueMinX <= chunkX && chunkX <= blueMaxX && blueMinZ <= chunkZ && chunkZ <= blueMaxZ);
}
}
private static int readVarInt(byte[] array, int startPos) {
int numRead = 0; int numRead = 0;
int result = 0; int result = 0;
byte read; byte read;
@ -205,7 +273,7 @@ public class TechHider {
return result; return result;
} }
public static int readVarIntLength(byte[] array, int startPos) { private static int readVarIntLength(byte[] array, int startPos) {
int numRead = 0; int numRead = 0;
byte read; byte read;
do { do {
@ -219,25 +287,7 @@ public class TechHider {
return numRead; return numRead;
} }
public static long readVarLong() { private static byte[] writeVarInt(int value) {
int numRead = 0;
long result = 0;
byte read = 0;
do {
//read = readByte();
int value = (read & 0b01111111);
result |= (value << (7 * numRead));
numRead++;
if (numRead > 10) {
break;
}
} while ((read & 0b10000000) != 0);
return result;
}
public static byte[] writeVarInt(int value) {
ArrayList<Byte> buffer = new ArrayList<>(); ArrayList<Byte> buffer = new ArrayList<>();
do { do {
byte temp = (byte)(value & 0b01111111); byte temp = (byte)(value & 0b01111111);
@ -250,16 +300,4 @@ public class TechHider {
} while (value != 0); } while (value != 0);
return Bytes.toArray(buffer); return Bytes.toArray(buffer);
} }
public static void writeVarLong(long value) {
do {
byte temp = (byte)(value & 0b01111111);
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
value >>>= 7;
if (value != 0) {
temp |= 0b10000000;
}
//writeByte(temp);
} while (value != 0);
}
} }