diff --git a/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java b/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java new file mode 100644 index 0000000..6d1a1e3 --- /dev/null +++ b/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.record; + +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; + +class RecordSystem_15 { + private RecordSystem_15(){} + + static int blockToId(Block block){ + return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java b/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java new file mode 100644 index 0000000..207a3fd --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.record; + +import org.bukkit.block.Block; + +class RecordSystem_8 { + private RecordSystem_8(){} + + @SuppressWarnings("deprecation") + static int blockToId(Block block){ + return block.getTypeId() << 4 + block.getData(); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index a969de8..84660b4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -19,16 +19,15 @@ package de.steamwar.fightsystem.record; +import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.SteamwarUser; -import net.minecraft.server.v1_15_R1.BlockPosition; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -164,22 +163,24 @@ public class RecordSystem { spawnEntity(e); } - public static synchronized void blockChange(BlockPosition pos, int blockState){ - int shortX = pos.getX() - Config.ArenaMinX; - int shortZ = pos.getZ() - Config.ArenaMinZ; + public static synchronized void blockChange(Block block){ + int blockState = blockToId(block); + + int shortX = block.getX() - Config.ArenaMinX; + int shortZ = block.getZ() - Config.ArenaMinZ; if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ //Short block packet Recorder.rByte(0x33); Recorder.rByte(shortX); - Recorder.rByte(pos.getY()); + Recorder.rByte(block.getY()); Recorder.rByte(shortZ); Recorder.rShort((short)blockState); }else{ //Block packet Recorder.rByte(0x30); - Recorder.rInt(pos.getX()); - Recorder.rByte(pos.getY()); - Recorder.rInt(pos.getZ()); + Recorder.rInt(block.getX()); + Recorder.rByte(block.getY()); + Recorder.rInt(block.getZ()); Recorder.rInt(blockState); } Recorder.flush(); @@ -269,10 +270,6 @@ public class RecordSystem { Recorder.flush(); } - public static synchronized void blockChange(Block block){ - blockChange(((CraftBlock)block).getPosition(), net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS())); - } - private static void checkWorldState(){ tick(); @@ -290,4 +287,17 @@ public class RecordSystem { entityMoves(e); entitySpeed(e); } + + private static int blockToId(Block block){ + switch(Core.getVersion()){ + case 8: + case 9: + case 10: + case 12: + return RecordSystem_8.blockToId(block); + case 15: + default: + return RecordSystem_15.blockToId(block); + } + } }