From ebfdaa783d5183941df7fa255b0b4f874dd9cd58 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 24 Apr 2021 20:16:16 +0200 Subject: [PATCH 01/33] Adding Spectate ArenaMode + first classes Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/ArenaMode.java | 8 +- .../de/steamwar/fightsystem/FightSystem.java | 4 +- .../fightsystem/commands/KitCommand.java | 2 +- .../fightsystem/commands/LeaveCommand.java | 2 +- .../commands/LockschemCommand.java | 2 +- .../countdown/NoPlayersOnlineCountdown.java | 4 +- .../countdown/PreRunningCountdown.java | 2 +- .../countdown/PreSchemCountdown.java | 2 +- .../fightsystem/fight/FightSchematic.java | 2 +- .../steamwar/fightsystem/fight/FightTeam.java | 4 +- .../fightsystem/listener/FightScoreboard.java | 4 +- .../fightsystem/listener/HotbarGUI.java | 2 +- .../fightsystem/listener/InFightDamage.java | 2 +- .../listener/InFightInventory.java | 2 +- .../fightsystem/listener/IngameDeath.java | 2 +- .../fightsystem/listener/SetupQuit.java | 2 +- .../fightsystem/listener/Spectate.java | 73 +++ .../fightsystem/listener/WaterRemover.java | 2 +- .../fightsystem/record/PacketProcessor.java | 423 ++++++++++++++++++ .../fightsystem/record/PacketSource.java | 79 ++++ 20 files changed, 600 insertions(+), 23 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java index 70edcef..a745a3e 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -29,7 +29,8 @@ public enum ArenaMode { EVENT, TEST, CHECK, - PREPARE; + PREPARE, + SPECTATE; public static final Set All = Collections.unmodifiableSet(EnumSet.allOf(ArenaMode.class)); @@ -39,14 +40,15 @@ public enum ArenaMode { public static final Set Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); public static final Set Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED)); public static final Set Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); + public static final Set Spectate = Collections.unmodifiableSet(EnumSet.of(SPECTATE)); + public static final Set AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE))); public static final Set AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); public static final Set AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT))); public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); - public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT))); + public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, SPECTATE))); public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT)); public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); - public static final Set Fight = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED, EVENT)); public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE))); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 16a8072..b84f9b7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -127,8 +127,8 @@ public class FightSystem extends JavaPlugin { new SkipCommand(); new WinCommand(); - new OneShotStateDependent(ArenaMode.All, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!")); - new OneShotStateDependent(ArenaMode.All, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!")); + new OneShotStateDependent(ArenaMode.AntiSpectate, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!")); + new OneShotStateDependent(ArenaMode.AntiSpectate, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!")); new OneShotStateDependent(ArenaMode.AntiTest, FightState.Running, FightStatistics::start); try { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java index 585262b..fd73f66 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class KitCommand implements CommandExecutor { public KitCommand() { - new StateDependentCommand(ArenaMode.All, FightState.Setup, "kit", this); + new StateDependentCommand(ArenaMode.AntiSpectate, FightState.Setup, "kit", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java index 7e3327e..5c95c72 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class LeaveCommand implements CommandExecutor { public LeaveCommand() { - new StateDependentCommand(ArenaMode.All, FightState.Setup, "leave", this); + new StateDependentCommand(ArenaMode.AntiSpectate, FightState.Setup, "leave", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 6070d12..fdaff2e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -37,7 +37,7 @@ import org.bukkit.entity.Player; public class LockschemCommand implements CommandExecutor { public LockschemCommand() { - new StateDependentCommand(ArenaMode.All, FightState.All, "lockschem", this); + new StateDependentCommand(ArenaMode.AntiSpectate, FightState.All, "lockschem", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java index fc8ed95..15b433f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java @@ -34,8 +34,8 @@ public class NoPlayersOnlineCountdown extends Countdown implements Listener { public NoPlayersOnlineCountdown() { super(Config.NoPlayerOnlineDuration, null, false); - new StateDependentListener(ArenaMode.All, FightState.PreLeaderSetup, this); - new StateDependentCountdown(ArenaMode.All, FightState.PreLeaderSetup, this){ + new StateDependentListener(ArenaMode.AntiSpectate, FightState.PreLeaderSetup, this); + new StateDependentCountdown(ArenaMode.AntiSpectate, FightState.PreLeaderSetup, this){ @Override public void enable() { if(Bukkit.getOnlinePlayers().isEmpty()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java index 4506ace..f5ad64c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -29,7 +29,7 @@ public class PreRunningCountdown extends Countdown { public PreRunningCountdown() { super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true); - new StateDependentCountdown(ArenaMode.All, FightState.PreRunning, this); + new StateDependentCountdown(ArenaMode.AntiSpectate, FightState.PreRunning, this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java index e0084a4..fed7dd6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java @@ -29,7 +29,7 @@ public class PreSchemCountdown extends Countdown { public PreSchemCountdown() { super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false); - new StateDependentCountdown(ArenaMode.All, FightState.PreSchemSetup, this); + new StateDependentCountdown(ArenaMode.AntiSpectate, FightState.PreSchemSetup, this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7a76a2c..7ec3d43 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -56,7 +56,7 @@ public class FightSchematic extends StateDependent { private int schematic = 0; public FightSchematic(FightTeam team, boolean rotate) { - super(ArenaMode.All, FightState.PostSchemSetup); + super(ArenaMode.AntiSpectate, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); this.rotate = rotate; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index bc0dfc7..dcdacea 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -394,7 +394,7 @@ public class FightTeam implements IFightTeam{ private class KitLoader extends StateDependent { private KitLoader() { - super(ArenaMode.All, FightState.Ingame); + super(ArenaMode.AntiSpectate, FightState.Ingame); register(); } @@ -419,7 +419,7 @@ public class FightTeam implements IFightTeam{ private class SpectateHandler extends StateDependent { private SpectateHandler() { - super(ArenaMode.All, FightState.Spectate); + super(ArenaMode.AntiSpectate, FightState.Spectate); register(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java index 7b98067..7de7628 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -55,8 +55,8 @@ public class FightScoreboard implements Listener, ScoreboardCallback { } public FightScoreboard(){ - new StateDependentListener(ArenaMode.All, FightState.All, this); - new StateDependentTask(ArenaMode.All, FightState.All, this::updateScoreboard, 0, 20); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.All, this); + new StateDependentTask(ArenaMode.AntiSpectate, FightState.All, this::updateScoreboard, 0, 20); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java index 2827c50..b8bb8c1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.meta.ItemMeta; public class HotbarGUI implements Listener { public HotbarGUI() { - new StateDependentListener(ArenaMode.All, FightState.Setup, this); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java index d525e6c..660429d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java @@ -36,7 +36,7 @@ import java.util.Objects; public class InFightDamage implements Listener { public InFightDamage() { - new StateDependentListener(ArenaMode.All, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.Running, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java index c72a812..47ae4ed 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java @@ -39,7 +39,7 @@ import org.bukkit.inventory.ItemStack; public class InFightInventory implements Listener { public InFightInventory() { - new StateDependentListener(ArenaMode.All, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.Running, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java index 6bf1074..b942f76 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java @@ -40,7 +40,7 @@ import org.bukkit.event.player.PlayerQuitEvent; public class IngameDeath implements Listener { public IngameDeath() { - new StateDependentListener(ArenaMode.All, FightState.Ingame, this); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.Ingame, this); } @EventHandler(priority = EventPriority.HIGH) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java index 3b083e7..de61a4d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java @@ -32,7 +32,7 @@ import org.bukkit.event.player.PlayerQuitEvent; public class SetupQuit implements Listener { public SetupQuit(){ - new StateDependentListener(ArenaMode.All, FightState.Setup, this); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java new file mode 100644 index 0000000..8e62379 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java @@ -0,0 +1,73 @@ +/* + 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.listener; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; + +public class Spectate implements Listener { + + public Spectate(){ + new StateDependentListener(ArenaMode.Spectate, FightState.All, this); + } + + @EventHandler + public void onLogin(PlayerLoginEvent e){ + Player player = e.getPlayer(); + + if(InspectCommand.inspecting){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ + e.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); + } + } + } + + @EventHandler + public void onPhysics(BlockPhysicsEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockExplosion(BlockExplodeEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void handlePlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOW) + public void handlePlayerInteract(PlayerInteractEvent event) { + event.setCancelled(true); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java index 40ae32e..5aa30ca 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -35,7 +35,7 @@ public class WaterRemover implements Listener { private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth; public WaterRemover() { - new StateDependentListener(ArenaMode.All, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiSpectate, FightState.Running, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java new file mode 100644 index 0000000..8d71506 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -0,0 +1,423 @@ +/* + 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 com.sk89q.worldedit.EditSession; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.Schematic; +import de.steamwar.sql.SteamwarUser; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.*; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +import java.io.EOFException; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; + +class PacketProcessor { + + private static final World world = Bukkit.getWorlds().get(0); + private final Map packetCounter = new HashMap<>(); + + private final PacketSource source; + private final BukkitTask task; + private final LinkedList syncList = new LinkedList<>(); + + + public PacketProcessor(PacketSource source){ + this.source = source; + if(source.async()) { + Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); + }else + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::process, 1, 1); + } + + private void runSync() { + synchronized (syncList) { + for(Runnable runnable : syncList) { + try{ + runnable.run(); + }catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to execute packet", e); + } + } + syncList.clear(); + } + } + + private void execSync(Runnable runnable){ + if (!source.async()) { + runnable.run(); + return; + } + + synchronized (syncList) { + syncList.add(runnable); + } + } + + private void playerJoins() throws IOException { + int entityId = source.rInt(); + int userId = source.rInt(); + SteamwarUser user = SteamwarUser.get(userId); + if(user == null) + throw new IOException("Unknown user " + userId); + + execSync(() -> new RPlayer(user.getUUID(), user.getUserName(), entityId)); + } + + private void entityMoves() throws IOException { + int entityId = source.rInt(); + double locX = source.rDouble(); + double locY = source.rDouble(); + double locZ = source.rDouble(); + float pitch = source.rFloat(); + float yaw = source.rFloat(); + byte headYaw = source.rByte(); + + execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw)); + } + + private void entityDespawns() throws IOException { + int entityId = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).remove()); + } + + private void entitySneak() throws IOException { + int entityId = source.rInt(); + boolean sneaking = source.rBoolean(); + + execSync(() -> REntity.getEntity(entityId).sneak(sneaking)); + } + + private void entityAnimation() throws IOException { + int entityId = source.rInt(); + byte animation = source.rByte(); + + execSync(() -> REntity.getEntity(entityId).animation(animation)); + } + + private void tntSpawn() throws IOException { + int entityId = source.rInt(); + + execSync(() -> new RTnT(entityId)); + } + + private void entityVelocity() throws IOException { + int entityId = source.rInt(); + + double dX = source.rDouble(); + double dY = source.rDouble(); + double dZ = source.rDouble(); + + execSync(() -> { + REntity entity = REntity.getEntity(entityId); + if(entity != null) + entity.setMotion(dX, dY, dZ); + }); + } + + private void playerItem() throws IOException { + int entityId = source.rInt(); + String item = source.rString(); + boolean enchanted = source.rBoolean(); + String slot = source.rString(); + + execSync(() -> ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot)); + } + + private void arrowSpawn() throws IOException { + int entityId = source.rInt(); + + execSync(() -> new RArrow(entityId)); + } + + private void fireballSpawn() throws IOException { + int entityId = source.rInt(); + + execSync(() -> new RFireball(entityId)); + } + + private void send(ChatMessageType type) throws IOException { + String message = source.rString(); + + BaseComponent[] text = TextComponent.fromLegacyText(message); + Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(type, text)); + } + + private void shortBlock() throws IOException { + int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinX; + int y = Byte.toUnsignedInt(source.rByte()); + int z = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinZ; + int blockState = source.rShort(); + + setBlock(x, y, z, blockState); + } + + private void block() throws IOException { + int x = source.rInt(); + int y = Byte.toUnsignedInt(source.rByte()); + int z = source.rInt(); + int blockState = source.rInt(); + + setBlock(x, y, z, blockState); + } + + private void setBlock(int x, int y, int z, int blockState){ + if(Config.ArenaMinX > x || Config.ArenaMaxX < x || Config.ArenaMinZ > z || Config.ArenaMaxZ < z) + return; //Outside of the arena + + if (!InspectCommand.inspecting && Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { + blockState = Config.ObfuscateWith; + } + IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); + execSync(() -> { + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.removeTileEntity(pos); + cworld.setTypeAndData(pos, blockData, 1042); + cworld.getChunkProvider().flagDirty(pos); + }); + } + + private void particle() throws IOException { + double x = source.rDouble(); + double y = source.rDouble(); + double z = source.rDouble(); + + String particleName = source.rString(); + + execSync(() -> world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1)); + } + + private void sound() throws IOException { + int x = source.rInt(); + int y = source.rInt(); + int z = source.rInt(); + + String soundName = source.rString(); + String soundCategory = source.rString(); + + float volume = source.rFloat(); + float pitch = source.rFloat(); + + Sound sound = Sound.valueOf(soundName); + SoundCategory sCategory = SoundCategory.valueOf(soundCategory); + + execSync(() -> world.playSound(new Location(world, x, y, z), sound, sCategory, volume, pitch)); + } + + private void soundAtPlayer() throws IOException { + String soundName = source.rString(); + + float volume = source.rFloat(); + float pitch = source.rFloat(); + + Sound sound = Sound.valueOf(soundName); + + execSync(() -> { + for(Player player : Bukkit.getOnlinePlayers()){ + player.playSound(player.getLocation(), sound, volume, pitch); + } + }); + } + + private void pasteSchem(int pasteX, int cornerY, int pasteZ, int cornerX, int cornerZ, boolean rotate, String prefix) throws IOException { + int schemId = source.rInt(); + + Schematic schem = Schematic.getSchemFromDB(schemId); + DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""))); + execSync(() -> { + try { + EditSession e = Paster.pasteSchematic(schem, pasteX, cornerY, pasteZ, rotate); + Paster.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + } catch (NoClipboardException | IOException e) { + throw new SecurityException("Could not load Clipboard", e); + } + }); + } + + private void teams() throws IOException { + int blueId = source.rInt(); + int redId = source.rInt(); + + execSync(() -> BlockTextCreator.pasteTeamNames(blueId, redId)); + } + + private void scoreboardTitle() throws IOException { + String title = source.rString(); + + SpectateSystem.getScoreboard().setTitle(title); + } + + private void scoreboardData() throws IOException { + String key = source.rString(); + int value = source.rInt(); + + SpectateSystem.getScoreboard().addValue(key, value); + } + + private void endSpectating(){ + WorldLoader.reloadWorld(); + SpectateSystem.getScoreboard().setTitle("§eKein Kampf"); + + for(Map.Entry entry : packetCounter.entrySet()){ + System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue()); + } + + packetCounter.clear(); + } + + private void bow() { + //TODO implement Bow + } + + private void damage() throws IOException { + int entityId = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).damage()); + } + + private void fireTick() throws IOException { + int entityId = source.rInt(); + + execSync(() -> REntity.getEntity(entityId).setOnFire()); + } + + private void process(){ + + try{ + boolean tickFinished = false; + while(!source.isClosed() && !tickFinished){ + byte packetType = source.rByte(); + packetCounter.compute(packetType, (key, value) -> value != null ? value + 1 : 1); + switch(packetType){ + case 0x00: + playerJoins(); + break; + case 0x01: + entityMoves(); + break; + case 0x02: + entityDespawns(); + break; + case 0x03: + entitySneak(); + break; + case 0x04: + entityAnimation(); + break; + case 0x05: + tntSpawn(); + break; + case 0x06: + entityVelocity(); + break; + case 0x07: + playerItem(); + break; + case 0x08: + arrowSpawn(); + break; + case 0x09: + fireballSpawn(); + break; + case 0x0A: + case 0x0B: + damage(); + case 0x0C: + fireTick(); + case 0x30: + block(); + break; + case 0x31: + particle(); + break; + case 0x32: + sound(); + break; + case 0x33: + shortBlock(); + break; + case 0x34: + soundAtPlayer(); + break; + case (byte) 0xA0: + send(ChatMessageType.CHAT); + break; + case (byte) 0xA1: + send(ChatMessageType.ACTION_BAR); + break; + case (byte) 0xA2: + send(ChatMessageType.SYSTEM); + break; + case (byte) 0xB0: + pasteSchem(Config.TeamBluePasteX, Config.TeamBlueCornerY, Config.TeamBluePasteZ, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + break; + case (byte) 0xB1: + pasteSchem(Config.TeamRedPasteX, Config.TeamRedCornerY, Config.TeamRedPasteZ, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.TeamRedRotate, Config.TeamRedPrefix); + break; + case (byte) 0xB2: + teams(); + break; + case (byte) 0xC0: + scoreboardTitle(); + break; + case (byte) 0xC1: + scoreboardData(); + break; + case (byte) 0xEF: + // Comment + source.rString(); + break; + case (byte) 0xFF: + //Tick + if(!source.async()) + tickFinished = true; + break; + default: + Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing: " + packetType); + source.close(); + } + } + } catch (EOFException e) { + Bukkit.getLogger().log(Level.INFO, "The FightServer is offline"); + source.close(); + } catch(IOException e){ + Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); + source.close(); + } + + if(source.isClosed()){ + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::endSpectating); + task.cancel(); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java new file mode 100644 index 0000000..4297f29 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java @@ -0,0 +1,79 @@ +/* + 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.Bukkit; + +import java.io.DataInputStream; +import java.io.IOException; +import java.util.logging.Level; + +public abstract class PacketSource { + + protected final DataInputStream inputStream; + + protected PacketSource(DataInputStream inputStream){ + this.inputStream = inputStream; + new PacketProcessor(this); + } + + public byte rByte() throws IOException { + return inputStream.readByte(); + } + + public boolean rBoolean() throws IOException { + return inputStream.readBoolean(); + } + + public short rShort() throws IOException { + return inputStream.readShort(); + } + + public int rInt() throws IOException { + return inputStream.readInt(); + } + + public long rLong() throws IOException { + return inputStream.readLong(); + } + + public float rFloat() throws IOException { + return inputStream.readFloat(); + } + + public double rDouble() throws IOException { + return inputStream.readDouble(); + } + + public String rString() throws IOException { + return inputStream.readUTF(); + } + + public void close(){ + try { + inputStream.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); + } + } + + abstract boolean isClosed(); + abstract boolean async(); +} From 9a997371d6c416fceaf847daed15fd1e5616ddc8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 26 Apr 2021 20:08:23 +0200 Subject: [PATCH 02/33] Some more work Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/Region.java | 6 +++++- .../de/steamwar/fightsystem/record/PacketProcessor.java | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index 470b8d0..7352c69 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -140,7 +140,11 @@ public class Region { } public boolean in2dRegion(Block block){ - return minX <= block.getX() && block.getX() < maxX && minZ <= block.getZ() && block.getZ() <= maxZ; + return in2dRegion(block.getX(), block.getZ()); + } + + public boolean in2dRegion(int x, int z) { + return minX <= x && x < maxX && minZ <= z && z <= maxZ; } public boolean inRegion(Block block){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index 8d71506..c7fdf23 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -20,7 +20,9 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.EditSession; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; @@ -173,9 +175,9 @@ class PacketProcessor { } private void shortBlock() throws IOException { - int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinX; + int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaRegion.getMinX(); int y = Byte.toUnsignedInt(source.rByte()); - int z = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinZ; + int z = Byte.toUnsignedInt(source.rByte()) + Config.ArenaRegion.getMinZ(); int blockState = source.rShort(); setBlock(x, y, z, blockState); @@ -191,7 +193,7 @@ class PacketProcessor { } private void setBlock(int x, int y, int z, int blockState){ - if(Config.ArenaMinX > x || Config.ArenaMaxX < x || Config.ArenaMinZ > z || Config.ArenaMaxZ < z) + if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena if (!InspectCommand.inspecting && Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { From 26ccf98d44b8d35d937a8b4203408ee281d3c774 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 15:23:35 +0200 Subject: [PATCH 03/33] WIP Signed-off-by: Lixfel --- .../fightsystem/commands/RemoveCommand.java | 2 +- .../fightsystem/record/PacketProcessor.java | 72 ++-- .../steamwar/fightsystem/record/REntity.java | 347 ++++++++++++++++++ .../fightsystem/record/RecordSystem.java | 2 +- .../steamwar/fightsystem/utils/TechHider.java | 32 +- 5 files changed, 403 insertions(+), 52 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java index 29ba6d2..b538532 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class RemoveCommand implements CommandExecutor { public RemoveCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "die", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index c7fdf23..50685e4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -19,36 +19,37 @@ package de.steamwar.fightsystem.record; -import com.sk89q.worldedit.EditSession; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.utils.ColorConverter; -import de.steamwar.sql.NoClipboardException; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.*; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; import java.io.IOException; -import java.util.HashMap; import java.util.LinkedList; -import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.logging.Level; class PacketProcessor { private static final World world = Bukkit.getWorlds().get(0); - private final Map packetCounter = new HashMap<>(); private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); + private final Set hiddenBlockIds = TechHider.getHiddenBlockIds(); + private final int obfuscateWith = TechHider.getObfuscateWith(); public PacketProcessor(PacketSource source){ @@ -103,13 +104,13 @@ class PacketProcessor { float yaw = source.rFloat(); byte headYaw = source.rByte(); - execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw)); + execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, pitch, yaw, headYaw)); } private void entityDespawns() throws IOException { int entityId = source.rInt(); - execSync(() -> REntity.getEntity(entityId).remove()); + execSync(() -> REntity.getEntity(entityId).die()); } private void entitySneak() throws IOException { @@ -129,7 +130,7 @@ class PacketProcessor { private void tntSpawn() throws IOException { int entityId = source.rInt(); - execSync(() -> new RTnT(entityId)); + execSync(() -> new REntity(entityId, EntityType.PRIMED_TNT)); } private void entityVelocity() throws IOException { @@ -142,7 +143,7 @@ class PacketProcessor { execSync(() -> { REntity entity = REntity.getEntity(entityId); if(entity != null) - entity.setMotion(dX, dY, dZ); + entity.setVelocity(dX, dY, dZ); }); } @@ -152,19 +153,19 @@ class PacketProcessor { boolean enchanted = source.rBoolean(); String slot = source.rString(); - execSync(() -> ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot)); + execSync(() -> REntity.getEntity(entityId).setItem(item, enchanted, slot)); } private void arrowSpawn() throws IOException { int entityId = source.rInt(); - execSync(() -> new RArrow(entityId)); + execSync(() -> new REntity(entityId, EntityType.ARROW)); } private void fireballSpawn() throws IOException { int entityId = source.rInt(); - execSync(() -> new RFireball(entityId)); + execSync(() -> new REntity(entityId, EntityType.FIREBALL)); } private void send(ChatMessageType type) throws IOException { @@ -196,8 +197,8 @@ class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - if (!InspectCommand.inspecting && Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { - blockState = Config.ObfuscateWith; + if (TechHider.ENABLED && hiddenBlockIds.contains(blockState)) { + blockState = obfuscateWith; } IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); execSync(() -> { @@ -251,19 +252,10 @@ class PacketProcessor { }); } - private void pasteSchem(int pasteX, int cornerY, int pasteZ, int cornerX, int cornerZ, boolean rotate, String prefix) throws IOException { + private void pasteSchem(FightTeam team) throws IOException { int schemId = source.rInt(); - Schematic schem = Schematic.getSchemFromDB(schemId); - DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""))); - execSync(() -> { - try { - EditSession e = Paster.pasteSchematic(schem, pasteX, cornerY, pasteZ, rotate); - Paster.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - } catch (NoClipboardException | IOException e) { - throw new SecurityException("Could not load Clipboard", e); - } - }); + execSync(() -> team.pasteSchem(Schematic.getSchemFromDB(schemId))); } private void teams() throws IOException { @@ -287,18 +279,17 @@ class PacketProcessor { } private void endSpectating(){ + REntity.dieAll(); WorldLoader.reloadWorld(); SpectateSystem.getScoreboard().setTitle("§eKein Kampf"); - - for(Map.Entry entry : packetCounter.entrySet()){ - System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue()); - } - - packetCounter.clear(); } - private void bow() { - //TODO implement Bow + private void bow() throws IOException { + int entityId = source.rInt(); + boolean drawn = source.rBoolean(); + boolean offHand = source.rBoolean(); + + execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, offHand)); } private void damage() throws IOException { @@ -309,8 +300,9 @@ class PacketProcessor { private void fireTick() throws IOException { int entityId = source.rInt(); + boolean perma = source.rBoolean(); - execSync(() -> REntity.getEntity(entityId).setOnFire()); + execSync(() -> REntity.getEntity(entityId).setOnFire(perma)); } private void process(){ @@ -319,7 +311,6 @@ class PacketProcessor { boolean tickFinished = false; while(!source.isClosed() && !tickFinished){ byte packetType = source.rByte(); - packetCounter.compute(packetType, (key, value) -> value != null ? value + 1 : 1); switch(packetType){ case 0x00: playerJoins(); @@ -352,10 +343,14 @@ class PacketProcessor { fireballSpawn(); break; case 0x0A: + bow(); + break; case 0x0B: damage(); + break; case 0x0C: fireTick(); + break; case 0x30: block(); break; @@ -381,10 +376,10 @@ class PacketProcessor { send(ChatMessageType.SYSTEM); break; case (byte) 0xB0: - pasteSchem(Config.TeamBluePasteX, Config.TeamBlueCornerY, Config.TeamBluePasteZ, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + pasteSchem(Fight.getBlueTeam()); break; case (byte) 0xB1: - pasteSchem(Config.TeamRedPasteX, Config.TeamRedCornerY, Config.TeamRedPasteZ, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.TeamRedRotate, Config.TeamRedPrefix); + pasteSchem(Fight.getRedTeam()); break; case (byte) 0xB2: teams(); @@ -401,6 +396,7 @@ class PacketProcessor { break; case (byte) 0xFF: //Tick + execSync(REntity::tickFire); if(!source.async()) tickFinished = true; break; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java new file mode 100644 index 0000000..9b8df3d --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -0,0 +1,347 @@ +package de.steamwar.fightsystem.record; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.*; +import de.steamwar.core.Core; +import de.steamwar.sql.SteamwarUser; +import net.royawesome.jlibnoise.MathHelper; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scoreboard.NameTagVisibility; +import org.bukkit.scoreboard.Team; + +import java.util.*; + +public class REntity { + + private static final Map entities = new HashMap<>(); + + public static REntity getEntity(int internalId){ + return entities.get(internalId); + } + + public static void tickFire() { + entities.forEach((integer, entity) -> { + if(entity.fireTick > 0) { + entity.fireTick--; + if(entity.fireTick == 0) { + //TODO + /*DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 0); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher);*/ + } + } + }); + } + + public static void playerJoins(Player player){ + /*for(REntity entity : entities.values()){ + entity.sendToPlayer(player); + entity.sendLocation(player); + if(entity.fireTick != 0) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher); + } + if(entity.sneaks) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher); + } + }*/ + } + + public static void dieAll(){ + entities.forEach((id, entity) -> entity.broadcastDeath()); + entities.clear(); + } + + private static final Team team; + + static { + if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam("Replay") == null) + team = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam("Replay"); + else + team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam("Replay"); + team.setNameTagVisibility(NameTagVisibility.NEVER); + } + + private static int entityCount = Integer.MAX_VALUE; + private static final Random random = new Random(); + + private final int internalId, entityId; + private final UUID uuid; + private final EntityType entityType; + private final PlayerInfoData playerInfoData; + private final Map itemSlots = new HashMap<>(); + + private double locX, locY, locZ; + private byte yaw, pitch, headYaw; + private int fireTick; + private boolean sneaks; + + public REntity(int internalId, int userId){ + this.internalId = internalId; + this.entityType = EntityType.PLAYER; + this.entityId = entityCount--; + + SteamwarUser user = SteamwarUser.get(userId); + this.uuid = user.getUUID(); + this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromOfflinePlayer(Bukkit.getOfflinePlayer(uuid)), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); + entities.put(internalId, this); + + //TODO: Spawn him! + } + + public REntity(int internalId, EntityType entityType){ + this.internalId = internalId; + this.entityType = entityType; + this.entityId = entityCount--; + this.playerInfoData = null; + this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L); + entities.put(internalId, this); + + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnEntityPacket()); + } + + public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw){ + this.locX = locX; + this.locY = locY; + this.locZ = locZ; + this.yaw = (byte)((int)(yaw * 256.0F / 360.0F)); + this.pitch = (byte)((int)(pitch * 256.0F / 360.0F)); + this.headYaw = headYaw; + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getTeleportPacket()); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHeadRotationPacket()); + } + + public void animation(byte animation) { + PacketContainer animationPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ANIMATION); + StructureModifier ints = animationPacket.getIntegers(); + ints.write(0, entityId); + ints.write(1, (int) animation); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(animationPacket); + } + + public void setVelocity(double dX, double dY, double dZ) { + PacketContainer velocityPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY); + StructureModifier ints = velocityPacket.getIntegers(); + ints.write(0, entityId); + ints.write(1, calcVelocity(dX)); + ints.write(2, calcVelocity(dY)); + ints.write(3, calcVelocity(dZ)); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(velocityPacket); + } + + public void damage() { + PacketContainer statusPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_STATUS); + statusPacket.getIntegers().write(0, entityId); + statusPacket.getBytes().write(0, (byte) 2); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(statusPacket); + } + + public void sneak(boolean sneaking) { + sneaks = sneaking; + /* + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher);*/ + } + + public void setOnFire(boolean perma) { + if(!perma) { + fireTick = 21; + } else { + fireTick = -1; + } + + /*DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher);*/ + } + + public void setBowDrawn(boolean drawn, boolean offHand) { + /*DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher); + + private void sendDataWatcher(DataWatcher dataWatcher) { + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + */ + } + + public void setItem(String item, boolean enchanted, String slot) { + ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1); + if(enchanted) + stack.addEnchantment(Enchantment.DURABILITY, 1); + itemSlots.put(slot, stack); + + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack)); + } + + public void die(){ + broadcastDeath(); + entities.remove(internalId); + } + + private void broadcastDeath(){ + if(entityType == EntityType.PLAYER){ + PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); + infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData())); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(infoPacket); + team.removeEntry(name); + } + + PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY); + destroyPacket.getIntegerArrays().write(0, new int[]{entityId}); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(destroyPacket); + } + + private int entityTypeToId(){ + //TODO + return 0; + } + + private int calcVelocity(double value) { + return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000); + } + + private void fillPositioningPacket(PacketContainer packet, StructureModifier ints){ + ints.write(0, entityId); + if(Core.getVersion() > 8){ + StructureModifier doubles = packet.getDoubles(); + doubles.write(0, locX); + doubles.write(1, locY); + doubles.write(2, locZ); + }else{ + ints.write(1, MathHelper.floor(locX * 32)); + ints.write(2, MathHelper.floor(locY * 32)); + ints.write(3, MathHelper.floor(locZ * 32)); + } + } + + private void fillByteRotation(PacketContainer packet){ + StructureModifier bytes = packet.getBytes(); + bytes.write(0, yaw); + bytes.write(1, pitch); + } + + private PacketContainer getTeleportPacket(){ + PacketContainer teleportPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_TELEPORT); + fillPositioningPacket(teleportPacket, teleportPacket.getIntegers()); + fillByteRotation(teleportPacket); + return teleportPacket; + } + + private PacketContainer getHeadRotationPacket(){ + PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION); + headRotation.getIntegers().write(0, entityId); + headRotation.getBytes().write(1, headYaw); + return headRotation; + } + + private PacketContainer getSpawnEntityPacket(){ + PacketContainer spawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY); + StructureModifier ints = spawnPacket.getIntegers(); + fillPositioningPacket(spawnPacket, ints); + spawnPacket.getUUIDs().write(0, uuid); + if(Core.getVersion() > 8){ + spawnPacket.getUUIDs().write(0, uuid); + ints.write(1, 0); // dX + ints.write(2, 0); // dY + ints.write(3, 0); // dZ + } + ints.write(4, (int)pitch); + ints.write(5, (int)yaw); + if(Core.getVersion() > 12){ + spawnPacket.getEntityTypeModifier().write(0, entityType); + }else{ + ints.write(6, entityTypeToId()); + } + return spawnPacket; + } + + private PacketContainer getEquipmentPacket(String slot, ItemStack stack){ + PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT); + StructureModifier ints = equipmentPacket.getIntegers(); + ints.write(0, entityId); + if(Core.getVersion() > 8){ + switch(slot){ + case "MAINHAND": + case "OFFHAND": + ints.write(1, 0); + break; + case "HEAD": + ints.write(1, 4); + break; + case "CHEST": + ints.write(1, 3); + break; + case "LEGS": + ints.write(1, 2); + break; + case "FEET": + default: + ints.write(1, 1); + } + }else{ + equipmentPacket.getItemSlots().write(0, EnumWrappers.ItemSlot.valueOf(slot)); + } + equipmentPacket.getItemModifier().write(0, stack); + return equipmentPacket; + } + + private PacketContainer getPlayerInfoPacket(){ + PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER); + infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData)); + return infoPacket; + } + + private PacketContainer getNamedSpawnPacket(){ + PacketContainer namedSpawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN); + StructureModifier ints = namedSpawnPacket.getIntegers(); + fillPositioningPacket(namedSpawnPacket, ints); + namedSpawnPacket.getUUIDs().write(0, uuid); + fillByteRotation(namedSpawnPacket); + if(Core.getVersion() < 13){ + namedSpawnPacket.getDataWatcherModifier().write(0, new WrappedDataWatcher()); + } + return namedSpawnPacket; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 52e31ba..f60741e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -157,7 +157,7 @@ public class RecordSystem { public static synchronized void item(Player p, ItemStack item, String slot){ Recorder.rByte(0x07); Recorder.rInt(p.getEntityId()); - Recorder.rString(item.getType().getKey().toString()); + Recorder.rString("minecraft:" + item.getType().name().toLowerCase()); Recorder.rBoolean(!item.getEnchantments().isEmpty()); Recorder.rString(slot); Recorder.flush(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 3a3308e..58aa1d1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -50,7 +50,7 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider extends StateDependent { - private static final boolean enabled = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; + public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; private final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); private final Map packetCache = new HashMap<>(); @@ -59,16 +59,10 @@ public class TechHider extends StateDependent { private final int threadMultiplier; public TechHider(){ - super(enabled, FightState.Schem); + super(ENABLED, FightState.Schem); - Set hiddenBlockIds = VersionedCallable.call( - new VersionedCallable<>(TechHider_8::getHiddenBlockIds, 8), - new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), - new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); - int obfuscateWith = VersionedCallable.call( - new VersionedCallable<>(TechHider_8::getObfuscateWith, 8), - new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), - new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); + Set hiddenBlockIds = getHiddenBlockIds(); + int obfuscateWith = getObfuscateWith(); obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith.toUpperCase()); chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8), @@ -263,8 +257,22 @@ public class TechHider extends StateDependent { } }; + public static Set getHiddenBlockIds(){ + return VersionedCallable.call( + new VersionedCallable<>(TechHider_8::getHiddenBlockIds, 8), + new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), + new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); + } + + public static int getObfuscateWith(){ + return VersionedCallable.call( + new VersionedCallable<>(TechHider_8::getObfuscateWith, 8), + new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), + new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); + } + public static List prepareChunkReload(Player p, boolean hide){ - if(!enabled) + if(!ENABLED) return Collections.emptyList(); List chunksToReload = new ArrayList<>(); Config.ArenaRegion.forEachChunk((x, z) -> { @@ -275,7 +283,7 @@ public class TechHider extends StateDependent { } public static void reloadChunks(Player p, List chunksToReload, boolean hide){ - if(!enabled) + if(!ENABLED) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { for(ChunkPos chunk : chunksToReload){ From 48426c9a86b4e1cab3bee5c8c51bdd453dc2ca5f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 17:40:24 +0200 Subject: [PATCH 04/33] WIP Signed-off-by: Lixfel --- .../fightsystem/record/RecordSystem_14.java | 52 ++++++ .../fightsystem/record/RecordSystem_15.java | 21 +++ .../fightsystem/record/RecordSystem_8.java | 7 +- .../fightsystem/fight/FightSchematic.java | 53 +------ .../steamwar/fightsystem/fight/FightTeam.java | 6 +- .../fightsystem/fight/FightWorld.java | 17 +- .../fightsystem/fight/FreezeWorld.java | 73 +++++++++ .../fightsystem/listener/FightScoreboard.java | 29 +++- .../fightsystem/record/BlockTextCreator.java | 150 ++++++++++++++++++ .../fightsystem/record/PacketProcessor.java | 38 ++--- .../steamwar/fightsystem/record/REntity.java | 129 +++++++++------ .../fightsystem/record/RecordSystem.java | 13 ++ 12 files changed, 458 insertions(+), 130 deletions(-) create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java diff --git a/FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java b/FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java new file mode 100644 index 0000000..5e65cb4 --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java @@ -0,0 +1,52 @@ +/* + 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 net.minecraft.server.v1_14_R1.BlockPosition; +import net.minecraft.server.v1_14_R1.EntityPose; +import net.minecraft.server.v1_14_R1.IBlockData; +import net.minecraft.server.v1_14_R1.WorldServer; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; + +import java.util.Objects; + +public class RecordSystem_14 { + private RecordSystem_14(){} + + static int blockToId(Block block){ + return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); + } + + static Object getPose(boolean sneaking){ + return sneaking ? EntityPose.SNEAKING : EntityPose.STANDING; + } + + static void setBlock(World world, int x, int y, int z, int blockState){ + IBlockData blockData = Objects.requireNonNull(net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.fromId(blockState)); + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.removeTileEntity(pos); + cworld.setTypeAndData(pos, blockData, 1042); + cworld.getChunkProvider().flagDirty(pos); + } +} diff --git a/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java b/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java index 6d1a1e3..db63363 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java @@ -19,13 +19,34 @@ package de.steamwar.fightsystem.record; +import net.minecraft.server.v1_15_R1.BlockPosition; +import net.minecraft.server.v1_15_R1.EntityPose; +import net.minecraft.server.v1_15_R1.IBlockData; +import net.minecraft.server.v1_15_R1.WorldServer; +import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; +import java.util.Objects; + 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()); } + + static Object getPose(boolean sneaking){ + return sneaking ? EntityPose.CROUCHING : EntityPose.STANDING; + } + + static void setBlock(World world, int x, int y, int z, int blockState){ + IBlockData blockData = Objects.requireNonNull(net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.fromId(blockState)); + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.removeTileEntity(pos); + cworld.setTypeAndData(pos, blockData, 1042); + cworld.getChunkProvider().flagDirty(pos); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java b/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java index 207a3fd..19dfa53 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java @@ -19,13 +19,18 @@ package de.steamwar.fightsystem.record; +import org.bukkit.World; import org.bukkit.block.Block; +@SuppressWarnings("deprecation") class RecordSystem_8 { private RecordSystem_8(){} - @SuppressWarnings("deprecation") static int blockToId(Block block){ return block.getTypeId() << 4 + block.getData(); } + + static void setBlock(World world, int x, int y, int z, int blockState){ + world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7ec3d43..5dc4346 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -25,7 +25,6 @@ import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; @@ -33,13 +32,12 @@ import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.*; -import org.bukkit.event.inventory.InventoryMoveItemEvent; import java.io.IOException; import java.util.List; @@ -145,7 +143,7 @@ public class FightSchematic extends StateDependent { throw securityException; } - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } @@ -174,45 +172,4 @@ public class FightSchematic extends StateDependent { block.setType(replacement); }); } - - private static class FreezeWorld implements Listener { - private FreezeWorld(){ - Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); - } - - @EventHandler - public void onBlockPhysicsEvent(BlockPhysicsEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onPistonExtend(BlockPistonExtendEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onPistonRetract(BlockPistonRetractEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onBlockGrow(BlockGrowEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onRedstoneEvent(BlockRedstoneEvent e){ - e.setNewCurrent(e.getOldCurrent()); - } - - @EventHandler - public void onBlockDispense(BlockDispenseEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onInventoryMoveEvent(InventoryMoveItemEvent e){ - e.setCancelled(true); - } - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index dcdacea..944d194 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -83,10 +83,10 @@ public class FightTeam implements IFightTeam{ new KitLoader(); new SpectateHandler(); - if(FightScoreboard.getScoreboard().getTeam(name) == null) - team = FightScoreboard.getScoreboard().registerNewTeam(name); + if(FightScoreboard.getBukkit().getTeam(name) == null) + team = FightScoreboard.getBukkit().registerNewTeam(name); else - team = FightScoreboard.getScoreboard().getTeam(name); + team = FightScoreboard.getBukkit().getTeam(name); assert team != null; setTeamColor(team, color); //noinspection deprecation diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java index 342f1a4..a6343fd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -38,7 +38,7 @@ public class FightWorld extends StateDependent { paper = Bukkit.getVersion().contains("git-Paper"); } - private final World world = Bukkit.getWorlds().get(0); + private static final World world = Bukkit.getWorlds().get(0); public FightWorld() { super(ArenaMode.Restartable, FightState.Schem); @@ -56,6 +56,19 @@ public class FightWorld extends StateDependent { @Override public void disable() { + resetWorld(); + } + + public static void forceLoad(){ + Config.ArenaRegion.forEachChunk((cX, cZ) -> { + world.loadChunk(cX, cZ); + world.setChunkForceLoaded(cX, cZ, true); + }); + world.setSpawnLocation(Config.SpecSpawn); + world.setKeepSpawnInMemory(true); + } + + public static void resetWorld(){ for(Entity entity : world.getEntities()){ if(entity.getType() != EntityType.PLAYER){ entity.remove(); @@ -68,7 +81,7 @@ public class FightWorld extends StateDependent { Bukkit.unloadWorld(backup, false); } - private void resetChunk(World backup, int x, int z, boolean isPaper){ + private static void resetChunk(World backup, int x, int z, boolean isPaper){ VersionedRunnable.call( new VersionedRunnable(() -> FightWorld_8.resetChunk(world, backup, x, z, isPaper), 8), new VersionedRunnable(() -> FightWorld_9.resetChunk(world, backup, x, z, isPaper), 9), diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java new file mode 100644 index 0000000..b3efc75 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java @@ -0,0 +1,73 @@ +/* + 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.fight; + +import de.steamwar.fightsystem.IFightSystem; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.*; +import org.bukkit.event.inventory.InventoryMoveItemEvent; + +public class FreezeWorld implements Listener { + public FreezeWorld(){ + Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); + } + + public void disable(){ + HandlerList.unregisterAll(this); + } + + @EventHandler + public void onBlockPhysicsEvent(BlockPhysicsEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onPistonExtend(BlockPistonExtendEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onPistonRetract(BlockPistonRetractEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onBlockGrow(BlockGrowEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onRedstoneEvent(BlockRedstoneEvent e){ + e.setNewCurrent(e.getOldCurrent()); + } + + @EventHandler + public void onBlockDispense(BlockDispenseEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onInventoryMoveEvent(InventoryMoveItemEvent e){ + e.setCancelled(true); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java index 7de7628..ad00139 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -43,20 +43,28 @@ import java.util.*; public class FightScoreboard implements Listener, ScoreboardCallback { - private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); + public static Scoreboard getBukkit() { + return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); + } + private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); + private static FightScoreboard scoreboard; + + public static FightScoreboard getScoreboard(){ + return scoreboard; + } + + private boolean replaying = false; private int index = 0; private String title = ""; private final HashMap scores = new HashMap<>(); - public static Scoreboard getScoreboard() { - return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); - } public FightScoreboard(){ new StateDependentListener(ArenaMode.AntiSpectate, FightState.All, this); new StateDependentTask(ArenaMode.AntiSpectate, FightState.All, this::updateScoreboard, 0, 20); + scoreboard = this; } @EventHandler @@ -106,7 +114,9 @@ public class FightScoreboard implements Listener, ScoreboardCallback { } private void updateScoreboard() { - scores.clear(); + if(replaying) + return; + switch((index++ / 10) % 3){ case 0: generalScoreboard(); @@ -119,12 +129,17 @@ public class FightScoreboard implements Listener, ScoreboardCallback { } } - private void setTitle(String t) { + public void setReplaying(boolean replaying) { + this.replaying = replaying; + } + + public void setTitle(String t) { + scores.clear(); title = t; RecordSystem.scoreboardTitle(t); } - private void addScore(String string, int i) { + public void addScore(String string, int i) { scores.put(string, i); RecordSystem.scoreboardData(string, i); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java new file mode 100644 index 0000000..957286f --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java @@ -0,0 +1,150 @@ +/* + 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 com.sk89q.jnbt.NBTInputStream; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; +import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.World; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.utils.ColorConverter; +import de.steamwar.sql.Team; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.zip.GZIPInputStream; + +public class BlockTextCreator { + private BlockTextCreator(){} + + private static final int BETWEEN_CHARACTERS_WIDTH = 1; + + private static final World WORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); + + + private static BlockArrayClipboard[] createText(String text){ + List result = new ArrayList<>(); + for(char c : text.toCharArray()){ + try { + try { + result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + nameConversion(c) + ".schem"))))).read()); + } catch (FileNotFoundException e) { + Bukkit.getLogger().log(Level.WARNING, "Could not display character " + c + " due to missing file!"); + result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/.schem"))))).read()); + } + }catch (IOException e) { + throw new SecurityException("Could not load text", e); + } + } + return result.toArray(new BlockArrayClipboard[0]); + } + + private static String nameConversion(char c) { + switch (Character.toUpperCase(c)) { + case '/': + return "slash"; + default: + return c + ""; + } + } + + private static int[] characterSize(BlockArrayClipboard[] characters){ + int[] lengthes = new int[characters.length]; + for(int i = 0; i < lengthes.length; i++) + lengthes[i] = characters[i].getDimensions().getBlockX(); + return lengthes; + } + + private static int[] textOffsets(int[] lengthes){ + int[] offsets = new int[lengthes.length]; + int previousOffset = 0; + for(int i = 0; i < offsets.length; i++){ + offsets[i] = previousOffset; + previousOffset += lengthes[i] + BETWEEN_CHARACTERS_WIDTH; + } + return offsets; + } + + private static int textLength(int[] lengthes, int[] offsets){ + if(lengthes.length == 0) + return 0; + return lengthes[lengthes.length - 1] + offsets[offsets.length - 1]; + } + + private static void pasteChar(BlockArrayClipboard character, int charOffset, int length, int x, int y, int z, AffineTransform transform, DyeColor c){ + BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); + BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); + v = transform.apply(v.toVector3()).toBlockPoint(); + v = v.add(x, y, z); + + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1); + ClipboardHolder ch = new ClipboardHolder(character); + ch.setTransform(transform); + Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build()); + e.flushSession(); + } + + private static void pasteText(String text, int x, int y, int z, AffineTransform transform, DyeColor c){ + BlockArrayClipboard[] characters = createText(text); + int[] lengthes = characterSize(characters); + int[] offsets = textOffsets(lengthes); + int length = textLength(lengthes, offsets); + + for(int i = 0; i < characters.length; i++) + pasteChar(characters[i], offsets[i], length, x, y, z, transform, c); + Paster.replaceTeamColor( + WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1), + c, + x - length / 2, y, z, length, 6, 0); + } + + private static void pasteForTeam(int teamId, int x, int z, boolean rotate, String color){ + Team team = Team.get(teamId); + AffineTransform aT = new AffineTransform(); + if(rotate){ + aT = aT.rotateY(180); + z += Config.SchemsizeZ / 2; + }else + z -= Config.SchemsizeZ / 2; + DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(color).replace("§", ""))); + pasteText(team.getTeamKuerzel(), x, Config.upperArenaBorder + 10, z, aT, c); + } + + public static void pasteTeamNames(int teamBlueId, int teamRedId){ + pasteForTeam(teamBlueId, Config.TeamBluePasteX, Config.TeamBluePasteZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + pasteForTeam(teamRedId, Config.TeamRedPasteX, Config.TeamRedPasteZ, Config.TeamRedRotate, Config.TeamRedPrefix); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index 50685e4..50839ab 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -23,9 +23,11 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.fight.FightWorld; +import de.steamwar.fightsystem.fight.FreezeWorld; +import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.sql.Schematic; -import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -50,10 +52,12 @@ class PacketProcessor { private final LinkedList syncList = new LinkedList<>(); private final Set hiddenBlockIds = TechHider.getHiddenBlockIds(); private final int obfuscateWith = TechHider.getObfuscateWith(); + private final FreezeWorld freezer = new FreezeWorld(); public PacketProcessor(PacketSource source){ this.source = source; + FightScoreboard.getScoreboard().setReplaying(true); if(source.async()) { Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); @@ -88,11 +92,8 @@ class PacketProcessor { private void playerJoins() throws IOException { int entityId = source.rInt(); int userId = source.rInt(); - SteamwarUser user = SteamwarUser.get(userId); - if(user == null) - throw new IOException("Unknown user " + userId); - execSync(() -> new RPlayer(user.getUUID(), user.getUserName(), entityId)); + execSync(() -> new REntity(entityId, userId)); } private void entityMoves() throws IOException { @@ -197,17 +198,7 @@ class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - if (TechHider.ENABLED && hiddenBlockIds.contains(blockState)) { - blockState = obfuscateWith; - } - IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); - execSync(() -> { - WorldServer cworld = ((CraftWorld)world).getHandle(); - BlockPosition pos = new BlockPosition(x, y, z); - cworld.removeTileEntity(pos); - cworld.setTypeAndData(pos, blockData, 1042); - cworld.getChunkProvider().flagDirty(pos); - }); + execSync(() -> RecordSystem.setBlock(x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); } private void particle() throws IOException { @@ -268,20 +259,22 @@ class PacketProcessor { private void scoreboardTitle() throws IOException { String title = source.rString(); - SpectateSystem.getScoreboard().setTitle(title); + FightScoreboard.getScoreboard().setTitle(title); } private void scoreboardData() throws IOException { String key = source.rString(); int value = source.rInt(); - SpectateSystem.getScoreboard().addValue(key, value); + FightScoreboard.getScoreboard().addScore(key, value); } - private void endSpectating(){ + private void endReplay(){ REntity.dieAll(); - WorldLoader.reloadWorld(); - SpectateSystem.getScoreboard().setTitle("§eKein Kampf"); + FightScoreboard.getScoreboard().setReplaying(false); + freezer.disable(); + //TODO: Stop server if singular replay + FightWorld.resetWorld(); } private void bow() throws IOException { @@ -306,7 +299,6 @@ class PacketProcessor { } private void process(){ - try{ boolean tickFinished = false; while(!source.isClosed() && !tickFinished){ @@ -414,7 +406,7 @@ class PacketProcessor { } if(source.isClosed()){ - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::endSpectating); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::endReplay); task.cancel(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java index 9b8df3d..e001101 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -6,11 +6,11 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.*; import de.steamwar.core.Core; +import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.sql.SteamwarUser; import net.royawesome.jlibnoise.MathHelper; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.OfflinePlayer; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; +import java.lang.reflect.InvocationTargetException; import java.util.*; public class REntity { @@ -33,39 +34,52 @@ public class REntity { if(entity.fireTick > 0) { entity.fireTick--; if(entity.fireTick == 0) { - //TODO /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); dataWatcher.register(dataWatcherObject, (byte) 0); dataWatcher.markDirty(dataWatcherObject); entity.sendDataWatcher(dataWatcher);*/ + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, (byte) 0, true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(watcher)); } } }); } - public static void playerJoins(Player player){ - /*for(REntity entity : entities.values()){ - entity.sendToPlayer(player); - entity.sendLocation(player); + public static void playerJoins(Player player) throws InvocationTargetException { + for(REntity entity : entities.values()){ + if(entity.entityType == EntityType.PLAYER){ + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getPlayerInfoPacket()); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getNamedSpawnPacket()); + for (Map.Entry entry : entity.itemSlots.entrySet()) { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue())); + } + }else{ + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getSpawnEntityPacket()); + } + //ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein? if(entity.fireTick != 0) { + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, (byte) 1, true); + /*ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); dataWatcher.register(dataWatcherObject, (byte) 1); dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher); + entity.sendDataWatcher(dataWatcher);*/ } if(entity.sneaks) { - DataWatcher dataWatcher = new DataWatcher(null); - + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(6, RecordSystem.getPose(true), true); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); + /*DataWatcher dataWatcher = new DataWatcher(null); DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher); + entity.sendDataWatcher(dataWatcher);*/ } - }*/ + } } public static void dieAll(){ @@ -73,27 +87,33 @@ public class REntity { entities.clear(); } + private static final String SCOREBOARD_TEAMNAME = "Replay"; private static final Team team; static { - if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam("Replay") == null) - team = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam("Replay"); + if(FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME) == null) + team = FightScoreboard.getBukkit().registerNewTeam(SCOREBOARD_TEAMNAME); else - team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam("Replay"); + team = FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME); team.setNameTagVisibility(NameTagVisibility.NEVER); } private static int entityCount = Integer.MAX_VALUE; private static final Random random = new Random(); - private final int internalId, entityId; + private final int internalId; + private final int entityId; private final UUID uuid; private final EntityType entityType; private final PlayerInfoData playerInfoData; private final Map itemSlots = new HashMap<>(); - private double locX, locY, locZ; - private byte yaw, pitch, headYaw; + private double locX; + private double locY; + private double locZ; + private byte yaw; + private byte pitch; + private byte headYaw; private int fireTick; private boolean sneaks; @@ -107,7 +127,9 @@ public class REntity { this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromOfflinePlayer(Bukkit.getOfflinePlayer(uuid)), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); entities.put(internalId, this); - //TODO: Spawn him! + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket()); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getNamedSpawnPacket()); + team.addEntry(user.getUserName()); } public REntity(int internalId, EntityType entityType){ @@ -159,14 +181,19 @@ public class REntity { public void sneak(boolean sneaking) { sneaks = sneaking; - /* - DataWatcher dataWatcher = new DataWatcher(null); + /*DataWatcher dataWatcher = new DataWatcher(null); DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); - dataWatcher.markDirty(dataWatcherObject); + dataWatcher.markDirty(dataWatcherObject);*/ - sendDataWatcher(dataWatcher);*/ + WrappedDataWatcher watcher = new WrappedDataWatcher(); + if(Core.getVersion() > 12){ + watcher.setObject(6, RecordSystem.getPose(sneaking), true); + }else{ + watcher.setObject(0, sneaking ? (byte) 2 : (byte) 0, true); + } + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setOnFire(boolean perma) { @@ -177,31 +204,29 @@ public class REntity { } /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); dataWatcher.register(dataWatcherObject, (byte) 1); - dataWatcher.markDirty(dataWatcherObject); + dataWatcher.markDirty(dataWatcherObject);*/ - sendDataWatcher(dataWatcher);*/ + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, (byte) 1, true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setBowDrawn(boolean drawn, boolean offHand) { /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a); dataWatcher.register(dataWatcherObject, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))); dataWatcher.markDirty(dataWatcherObject); - - sendDataWatcher(dataWatcher); - - private void sendDataWatcher(DataWatcher dataWatcher) { - PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); - - for(Player player : Bukkit.getOnlinePlayers()){ - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - } */ + + WrappedDataWatcher watcher = new WrappedDataWatcher(); + if(Core.getVersion() > 8){ + watcher.setObject(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)), true); + }else{ + watcher.setObject(0, (byte)0x10, true); + } + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setItem(String item, boolean enchanted, String slot) { @@ -222,9 +247,9 @@ public class REntity { if(entityType == EntityType.PLAYER){ PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); - infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData())); + infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData)); ProtocolLibrary.getProtocolManager().broadcastServerPacket(infoPacket); - team.removeEntry(name); + team.removeEntry(playerInfoData.getProfile().getName()); } PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY); @@ -232,11 +257,6 @@ public class REntity { ProtocolLibrary.getProtocolManager().broadcastServerPacket(destroyPacket); } - private int entityTypeToId(){ - //TODO - return 0; - } - private int calcVelocity(double value) { return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000); } @@ -261,6 +281,13 @@ public class REntity { bytes.write(1, pitch); } + private PacketContainer getDataWatcherPacket(WrappedDataWatcher dataWatcher) { + PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA); + metadataPacket.getIntegers().write(0, entityId); + metadataPacket.getDataWatcherModifier().write(0, dataWatcher); + return metadataPacket; + } + private PacketContainer getTeleportPacket(){ PacketContainer teleportPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_TELEPORT); fillPositioningPacket(teleportPacket, teleportPacket.getIntegers()); @@ -291,7 +318,17 @@ public class REntity { if(Core.getVersion() > 12){ spawnPacket.getEntityTypeModifier().write(0, entityType); }else{ - ints.write(6, entityTypeToId()); + switch(entityType){ + case PRIMED_TNT: + ints.write(6, 50); + break; + case ARROW: + ints.write(6, 60); + break; + case FIREBALL: + ints.write(6, 63); + break; + } } return spawnPacket; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index f60741e..9af466b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.record; import de.steamwar.core.VersionedCallable; +import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -323,6 +324,18 @@ public class RecordSystem { private static int blockToId(Block block){ return VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_8.blockToId(block), 8), + new VersionedCallable<>(() -> RecordSystem_14.blockToId(block), 14), new VersionedCallable<>(() -> RecordSystem_15.blockToId(block), 15)); } + + public static Object getPose(boolean sneaking){ + return VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_14.getPose(sneaking), 14), + new VersionedCallable<>(() -> RecordSystem_15.getPose(sneaking), 15)); + } + + public static void setBlock(int x, int y, int z, int blockState){ + VersionedRunnable.call(new VersionedRunnable(() -> RecordSystem_8.setBlock(WORLD, x, y, z, blockState), 8), + new VersionedRunnable(() -> RecordSystem_14.setBlock(WORLD, x, y, z, blockState), 14), + new VersionedRunnable(() -> RecordSystem_15.setBlock(WORLD, x, y, z, blockState), 15)); + } } From 573c518e33f4c9d31e48408272fc289565f51080 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 20:15:03 +0200 Subject: [PATCH 05/33] First errorless full spectate solution Signed-off-by: Lixfel --- .../fightsystem/fight/FightTeam_14.java | 22 ++- .../fightsystem/fight/FightTeam_8.java | 23 ++- .../de/steamwar/fightsystem/utils/Region.java | 4 + .../fightsystem/fight/FightSchematic.java | 117 +++++++++++--- .../steamwar/fightsystem/fight/FightTeam.java | 22 ++- .../fightsystem/listener/FightScoreboard.java | 7 +- .../fightsystem/record/BlockTextCreator.java | 150 ------------------ .../fightsystem/record/PacketProcessor.java | 19 ++- .../fightsystem/record/RecordSystem.java | 10 ++ 9 files changed, 177 insertions(+), 197 deletions(-) delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java diff --git a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java index d648d9b..38b0170 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.fight; +import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -27,6 +28,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; +import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; @@ -38,7 +40,6 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.Region; -import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -102,7 +103,7 @@ public class FightTeam_14 { } } - static void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) throws NoClipboardException { + static void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); World w = new BukkitWorld(Bukkit.getWorlds().get(0)); @@ -134,6 +135,23 @@ public class FightTeam_14 { e.flushSession(); } + static void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){ + BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); + BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); + v = aT.apply(v.toVector3()).toBlockPoint(); + v = v.add(x, y, z); + + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1); + ClipboardHolder ch = new ClipboardHolder(character); + ch.setTransform(aT); + Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build()); + e.flushSession(); + } + + static Clipboard loadSchem(NBTInputStream stream) throws IOException { + return new SpongeSchematicReader(stream).read(); + } + public static boolean checkPistonMoving(Block block){ return block.getType() == Material.MOVING_PISTON; } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java index 2894747..f62cb60 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.fight; +import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; @@ -29,6 +30,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; +import com.sk89q.worldedit.extent.clipboard.io.SchematicReader; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.transform.AffineTransform; @@ -37,7 +39,6 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.Region; -import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -99,7 +100,7 @@ public class FightTeam_8 { } } - static void pasteSchematic(Clipboard clipboard, Region paste, boolean rotate) throws NoClipboardException { + static void pasteSchematic(Clipboard clipboard, Region paste, boolean rotate) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); Vector v = new Vector(paste.centerX(), paste.getMinY(), paste.centerZ()); @@ -129,6 +130,24 @@ public class FightTeam_8 { e.flushQueue(); } + static void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){ + World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + Vector offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); + Vector v = Vector.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); + v = aT.apply(v).toBlockPoint(); + v = v.add(x, y, z); + + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); + ClipboardHolder ch = new ClipboardHolder(character, w.getWorldData()); + ch.setTransform(aT); + Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); + e.flushQueue(); + } + + static Clipboard loadSchem(NBTInputStream stream) throws IOException { + return new SchematicReader(stream).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData()); + } + public static boolean checkPistonMoving(Block block){ return block.getType() == Material.PISTON_MOVING_PIECE; } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index dbb1672..4f38486 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -71,6 +71,10 @@ public class Region { return maxZ; } + public int getSizeZ() { + return maxZ - minZ; + } + public double posToChunk(int pos){ return pos / 16.0; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7765704..a319384 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -19,8 +19,11 @@ package de.steamwar.fightsystem.fight; +import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.transform.AffineTransform; +import de.steamwar.core.VersionedCallable; import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; @@ -30,7 +33,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; -import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.DyeColor; @@ -39,10 +41,14 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.event.HandlerList; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.logging.Level; +import java.util.zip.GZIPInputStream; public class FightSchematic extends StateDependent { @@ -75,7 +81,7 @@ public class FightSchematic extends StateDependent { clipboard = schem.load(); } catch (IOException e) { team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!"); - Bukkit.getLogger().log(Level.SEVERE, "Couldn't load Schematic " + schem.getSchemName(), e); + Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getSchemName()); } } @@ -111,33 +117,38 @@ public class FightSchematic extends StateDependent { Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); } + private void replaceTeamColor(Clipboard clipboard){ + DyeColor c = ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK; + VersionedRunnable.call(new VersionedRunnable(() -> { + try { + FightTeam_8.replaceTeamColor(clipboard, c); + } catch (WorldEditException ex) { + throw new SecurityException("Error recoloring schematic", ex); + } + }, 8), + new VersionedRunnable(() -> { + try { + FightTeam_12.replaceTeamColor(clipboard, c); + } catch (WorldEditException ex) { + throw new SecurityException("Error recoloring schematic", ex); + } + }, 12), + new VersionedRunnable(() -> { + try { + FightTeam_14.replaceTeamColor(clipboard, c); + } catch (WorldEditException ex) { + throw new SecurityException("Error recoloring schematic", ex); + } + }, 14)); + } + private void paste(){ FreezeWorld freezer = new FreezeWorld(); - DyeColor c = ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK; try { - VersionedRunnable.call(new VersionedRunnable(() -> { - try { - FightTeam_8.replaceTeamColor(clipboard, c); - FightTeam_8.pasteSchematic(clipboard, region, rotate); - } catch (NoClipboardException | WorldEditException ex) { - throw new SecurityException("Error pasting schematic", ex); - } - }, 8), new VersionedRunnable(() -> { - try { - FightTeam_12.replaceTeamColor(clipboard, c); - FightTeam_8.pasteSchematic(clipboard, region, rotate); - } catch (NoClipboardException | WorldEditException ex) { - throw new SecurityException("Error pasting schematic", ex); - } - }, 12), new VersionedRunnable(() -> { - try { - FightTeam_14.replaceTeamColor(clipboard, c); - FightTeam_14.pasteSchematic(clipboard, region, rotate); - } catch (NoClipboardException | WorldEditException ex) { - throw new SecurityException("Error pasting schematic", ex); - } - }, 14)); + replaceTeamColor(clipboard); + VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.pasteSchematic(clipboard, region, rotate), 8), + new VersionedRunnable(() -> FightTeam_14.pasteSchematic(clipboard, region, rotate), 14)); } catch (SecurityException securityException) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); @@ -148,6 +159,62 @@ public class FightSchematic extends StateDependent { Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } + private Clipboard loadTextSchem(String schemName){ + return VersionedCallable.call(new VersionedCallable<>(() -> FightTeam_8.loadSchem(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + schemName + ".schematic"))))), 8), + new VersionedCallable<>(() -> FightTeam_14.loadSchem(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + schemName + ".schem"))))), 14)); + } + + public void pasteTeamName(){ + List characters = new ArrayList<>(); + for(char c : team.getName().toCharArray()){ + try { + try { + characters.add(loadTextSchem(c == '/' ? "slash" : String.valueOf(c))); + } catch (RuntimeException e) { + Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", c); + characters.add(loadTextSchem("")); + } + }catch (RuntimeException e) { + throw new SecurityException("Could not load text", e); + } + } + + //Calc character sizes + int[] lengthes = new int[characters.size()]; + for(int i = 0; i < lengthes.length; i++) + lengthes[i] = characters.get(i).getDimensions().getBlockX(); + + //Calc character offsets + int[] offsets = new int[lengthes.length]; + int previousOffset = 0; + for(int i = 0; i < offsets.length; i++){ + offsets[i] = previousOffset; + previousOffset += lengthes[i] + 1; // 1 is the distance between characters + } + + int length = lengthes.length == 0 ? 0 : lengthes[lengthes.length - 1] + offsets[offsets.length - 1]; + + int z = team.getSchemRegion().centerZ(); + AffineTransform aT = new AffineTransform(); + + if(rotate){ + aT = aT.rotateY(180); + z += team.getSchemRegion().getSizeZ() / 2; + }else{ + z -= team.getSchemRegion().getSizeZ() / 2; + } + + for(int i = 0; i < characters.size(); i++){ + replaceTeamColor(characters.get(i)); + pasteChar(characters.get(i), offsets[i], length, team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), z, aT); + } + } + + private void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){ + VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.pasteChar(character, charOffset, length, x, y, z, aT), 8), + new VersionedRunnable(() -> FightTeam_14.pasteChar(character, charOffset, length, x, y, z, aT), 14)); + } + @Override public void disable() { if(!Config.ReplaceObsidianBedrock) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index ab51a16..daa2f0d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -54,9 +54,9 @@ public class FightTeam implements IFightTeam{ private final Map players = new HashMap<>(); private final Set invited = new HashSet<>(); - private final String name; - private final String prefix; - private final ChatColor color; + private String name; + private String prefix; + private ChatColor color; private final FightSchematic schematic; private final Team team; private final boolean blue; @@ -72,13 +72,11 @@ public class FightTeam implements IFightTeam{ this.spawn = spawn; this.schemRegion = schemRegion; this.extendRegion = extendRegion; - this.name = name; - this.prefix = prefix; this.ready = false; this.skip = false; this.blue = blue; this.designatedLeader = designatedLeader; - this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); + setPrefixAndName(prefix, name); this.schematic = new FightSchematic(this, rotate); new KitLoader(); new SpectateHandler(); @@ -94,6 +92,12 @@ public class FightTeam implements IFightTeam{ team.setAllowFriendlyFire(false); } + public void setPrefixAndName(String prefix, String name){ + this.name = name; + this.prefix = prefix; + this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); + } + public UUID getDesignatedLeader(){ return designatedLeader; } @@ -296,13 +300,17 @@ public class FightTeam implements IFightTeam{ public void pasteSchem(Schematic schematic){ setSchem(schematic); - if(Config.test()) + if(Config.test() || RecordSystem.isReplaying()) this.schematic.enable(); else if(Fight.getOpposite(this).hasSchematic()){ FightSystem.setPostSchemState(); } } + public void pasteTeamName(){ + schematic.pasteTeamName(); + } + public void setSchem(Schematic schematic){ this.schematic.setSchematic(schematic); broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java index c648d83..49ff309 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -54,7 +54,6 @@ public class FightScoreboard implements Listener, ScoreboardCallback { return scoreboard; } - private boolean replaying = false; private int index = 0; private String title = ""; @@ -113,7 +112,7 @@ public class FightScoreboard implements Listener, ScoreboardCallback { } private void updateScoreboard() { - if(replaying) + if(RecordSystem.isReplaying()) return; if ((index++ / 5) % 2 == 0) { @@ -125,10 +124,6 @@ public class FightScoreboard implements Listener, ScoreboardCallback { } } - public void setReplaying(boolean replaying) { - this.replaying = replaying; - } - public void setTitle(String t) { scores.clear(); title = t; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java deleted file mode 100644 index 957286f..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/BlockTextCreator.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - 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 com.sk89q.jnbt.NBTInputStream; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; -import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.transform.AffineTransform; -import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.world.World; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.utils.ColorConverter; -import de.steamwar.sql.Team; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.DyeColor; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.zip.GZIPInputStream; - -public class BlockTextCreator { - private BlockTextCreator(){} - - private static final int BETWEEN_CHARACTERS_WIDTH = 1; - - private static final World WORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); - - - private static BlockArrayClipboard[] createText(String text){ - List result = new ArrayList<>(); - for(char c : text.toCharArray()){ - try { - try { - result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + nameConversion(c) + ".schem"))))).read()); - } catch (FileNotFoundException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not display character " + c + " due to missing file!"); - result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/.schem"))))).read()); - } - }catch (IOException e) { - throw new SecurityException("Could not load text", e); - } - } - return result.toArray(new BlockArrayClipboard[0]); - } - - private static String nameConversion(char c) { - switch (Character.toUpperCase(c)) { - case '/': - return "slash"; - default: - return c + ""; - } - } - - private static int[] characterSize(BlockArrayClipboard[] characters){ - int[] lengthes = new int[characters.length]; - for(int i = 0; i < lengthes.length; i++) - lengthes[i] = characters[i].getDimensions().getBlockX(); - return lengthes; - } - - private static int[] textOffsets(int[] lengthes){ - int[] offsets = new int[lengthes.length]; - int previousOffset = 0; - for(int i = 0; i < offsets.length; i++){ - offsets[i] = previousOffset; - previousOffset += lengthes[i] + BETWEEN_CHARACTERS_WIDTH; - } - return offsets; - } - - private static int textLength(int[] lengthes, int[] offsets){ - if(lengthes.length == 0) - return 0; - return lengthes[lengthes.length - 1] + offsets[offsets.length - 1]; - } - - private static void pasteChar(BlockArrayClipboard character, int charOffset, int length, int x, int y, int z, AffineTransform transform, DyeColor c){ - BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); - BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); - v = transform.apply(v.toVector3()).toBlockPoint(); - v = v.add(x, y, z); - - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1); - ClipboardHolder ch = new ClipboardHolder(character); - ch.setTransform(transform); - Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build()); - e.flushSession(); - } - - private static void pasteText(String text, int x, int y, int z, AffineTransform transform, DyeColor c){ - BlockArrayClipboard[] characters = createText(text); - int[] lengthes = characterSize(characters); - int[] offsets = textOffsets(lengthes); - int length = textLength(lengthes, offsets); - - for(int i = 0; i < characters.length; i++) - pasteChar(characters[i], offsets[i], length, x, y, z, transform, c); - Paster.replaceTeamColor( - WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1), - c, - x - length / 2, y, z, length, 6, 0); - } - - private static void pasteForTeam(int teamId, int x, int z, boolean rotate, String color){ - Team team = Team.get(teamId); - AffineTransform aT = new AffineTransform(); - if(rotate){ - aT = aT.rotateY(180); - z += Config.SchemsizeZ / 2; - }else - z -= Config.SchemsizeZ / 2; - DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(color).replace("§", ""))); - pasteText(team.getTeamKuerzel(), x, Config.upperArenaBorder + 10, z, aT, c); - } - - public static void pasteTeamNames(int teamBlueId, int teamRedId){ - pasteForTeam(teamBlueId, Config.TeamBluePasteX, Config.TeamBluePasteZ, Config.TeamBlueRotate, Config.TeamBluePrefix); - pasteForTeam(teamRedId, Config.TeamRedPasteX, Config.TeamRedPasteZ, Config.TeamRedRotate, Config.TeamRedPrefix); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index 50839ab..c4bb6a6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -28,6 +28,7 @@ import de.steamwar.fightsystem.fight.FreezeWorld; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.sql.Schematic; +import de.steamwar.sql.Team; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -39,7 +40,6 @@ import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; import java.io.IOException; import java.util.LinkedList; -import java.util.Objects; import java.util.Set; import java.util.logging.Level; @@ -57,7 +57,7 @@ class PacketProcessor { public PacketProcessor(PacketSource source){ this.source = source; - FightScoreboard.getScoreboard().setReplaying(true); + RecordSystem.setReplaying(true); if(source.async()) { Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); @@ -253,7 +253,16 @@ class PacketProcessor { int blueId = source.rInt(); int redId = source.rInt(); - execSync(() -> BlockTextCreator.pasteTeamNames(blueId, redId)); + execSync(() -> { + pasteForTeam(blueId, Fight.getBlueTeam()); + pasteForTeam(redId, Fight.getRedTeam()); + }); + } + + private void pasteForTeam(int teamId, FightTeam fightTeam){ + Team team = Team.get(teamId); + fightTeam.setPrefixAndName("§" + team.getTeamColor(), team.getTeamKuerzel()); + fightTeam.pasteTeamName(); } private void scoreboardTitle() throws IOException { @@ -271,10 +280,10 @@ class PacketProcessor { private void endReplay(){ REntity.dieAll(); - FightScoreboard.getScoreboard().setReplaying(false); freezer.disable(); //TODO: Stop server if singular replay FightWorld.resetWorld(); + RecordSystem.setReplaying(false); } private void bow() throws IOException { @@ -393,7 +402,7 @@ class PacketProcessor { tickFinished = true; break; default: - Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing: " + packetType); + Bukkit.getLogger().log(Level.SEVERE, "Unknown packet {} recieved, closing.", packetType); source.close(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 9af466b..87952f4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -40,6 +40,16 @@ import org.bukkit.util.Vector; public class RecordSystem { private RecordSystem(){} + private static boolean replaying = false; + + public static boolean isReplaying(){ + return replaying; + } + + public static void setReplaying(boolean replaying){ + RecordSystem.replaying = replaying; + } + private static final World WORLD = Bukkit.getWorlds().get(0); public static void init(){ From 6e784810a1608cf1fbb3b6311023c74346c37179 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 31 May 2021 14:53:25 +0200 Subject: [PATCH 06/33] First full replay implementation Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/ArenaMode.java | 13 +- .../src/de/steamwar/fightsystem/Config.java | 16 +- .../de/steamwar/fightsystem/fight/IFight.java | 2 +- .../de/steamwar/fightsystem/FightSystem.java | 26 +- .../fightsystem/commands/KitCommand.java | 2 +- .../fightsystem/commands/LeaveCommand.java | 2 +- .../commands/LockschemCommand.java | 2 +- .../fightsystem/commands/ReplayCommand.java | 70 ++++ .../fightsystem/countdown/Countdown.java | 4 +- .../countdown/NoPlayersOnlineCountdown.java | 4 +- .../countdown/PostSchemCountdown.java | 1 + .../countdown/PreRunningCountdown.java | 2 +- .../countdown/PreSchemCountdown.java | 2 +- .../de/steamwar/fightsystem/fight/Fight.java | 12 +- .../fightsystem/fight/FightSchematic.java | 8 +- .../steamwar/fightsystem/fight/FightTeam.java | 16 +- .../fightsystem/fight/FreezeWorld.java | 18 + .../steamwar/fightsystem/listener/Chat.java | 4 +- .../fightsystem/listener/EventJoin.java | 4 +- .../fightsystem/listener/FightScoreboard.java | 13 +- .../fightsystem/listener/HotbarGUI.java | 2 +- .../fightsystem/listener/InFightDamage.java | 2 +- .../listener/InFightInventory.java | 2 +- .../fightsystem/listener/IngameDeath.java | 6 +- .../fightsystem/listener/Permanent.java | 3 + .../fightsystem/listener/Recording.java | 89 +++-- .../fightsystem/listener/SetupQuit.java | 2 +- .../fightsystem/listener/Spectate.java | 73 ---- .../fightsystem/listener/WaterRemover.java | 2 +- .../fightsystem/record/FileRecorder.java | 139 ++----- .../fightsystem/record/FileSource.java | 51 +++ .../fightsystem/record/GlobalRecorder.java | 107 ++++++ .../fightsystem/record/LiveRecorder.java | 70 ++++ .../fightsystem/record/LiveServer.java | 62 ++++ .../fightsystem/record/LiveSource.java | 56 +++ .../fightsystem/record/PacketProcessor.java | 32 +- .../fightsystem/record/PacketSource.java | 2 +- .../steamwar/fightsystem/record/REntity.java | 77 ++-- .../fightsystem/record/RecordSystem.java | 351 ------------------ .../steamwar/fightsystem/record/Recorder.java | 272 ++++++++++++-- .../record/SpectateConnection.java | 147 -------- .../fightsystem/states/FightState.java | 1 + FightSystem_Main/src/plugin.yml | 1 + 43 files changed, 911 insertions(+), 859 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/commands/ReplayCommand.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/LiveRecorder.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/LiveServer.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java index a745a3e..1e83039 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -30,7 +30,7 @@ public enum ArenaMode { TEST, CHECK, PREPARE, - SPECTATE; + REPLAY; public static final Set All = Collections.unmodifiableSet(EnumSet.allOf(ArenaMode.class)); @@ -40,15 +40,16 @@ public enum ArenaMode { public static final Set Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); public static final Set Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED)); public static final Set Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); - public static final Set Spectate = Collections.unmodifiableSet(EnumSet.of(SPECTATE)); + public static final Set Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY)); - public static final Set AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE))); + public static final Set AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY))); + public static final Set Replayable = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST)); public static final Set AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); public static final Set AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT))); public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); - public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, SPECTATE))); - public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT)); + public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, REPLAY))); + public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY)); public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); - public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE))); + public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 1fcf4e8..4318e6f 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -118,7 +118,7 @@ public class Config { public static final int EventTeamRedID; public static final boolean BothTeamsPublic; public static final int MaximumTeamMembers; - public static final boolean SpectateSystem; + public static final boolean LiveReplay; //check parameter public static final int CheckSchemID; @@ -126,9 +126,10 @@ public class Config { public static final ArenaMode mode; - //live recorder parameter + //replay system parameter public static final String spectateIP = "127.0.0.1"; public static final int spectatePort = 2222; + public static final int ReplayID; static{ if(!new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) { @@ -335,7 +336,7 @@ public class Config { OnlyPublicSchematics = event.publicSchemsOnly(); MaximumTeamMembers = event.getMaximumTeamMembers(); } - SpectateSystem = event.spectateSystem(); + LiveReplay = event.spectateSystem(); }else{ //No event TeamRedColor = config.getString("Output.TeamRedPrefix"); @@ -347,7 +348,7 @@ public class Config { EventTeamRedID = 0; BothTeamsPublic = true; MaximumTeamMembers = Integer.MAX_VALUE; - SpectateSystem = false; + LiveReplay = false; } String blueLeader = System.getProperty("blueLeader", null); @@ -364,6 +365,7 @@ public class Config { CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0")); Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false")); + ReplayID = Integer.parseInt(System.getProperty("replay", "0")); if(Ranked){ mode = ArenaMode.RANKED; @@ -375,6 +377,8 @@ public class Config { mode = ArenaMode.EVENT; }else if(EventKampfID == -1){ mode = ArenaMode.TEST; + }else if(ReplayID != 0){ + mode = ArenaMode.REPLAY; }else{ mode = ArenaMode.NORMAL; } @@ -383,7 +387,7 @@ public class Config { public static boolean test(){ return ArenaMode.Test.contains(mode); } - public static boolean recording(){ - return mode == ArenaMode.EVENT; + public static boolean replayserver(){ + return ReplayID == -1; } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java b/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java index dc15ff5..1c44e1a 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java @@ -27,7 +27,7 @@ public class IFight { private static IFightTeam redTeam; private static IFightTeam blueTeam; - static void init(IFightTeam redTeam, IFightTeam blueTeam){ + public static void init(IFightTeam redTeam, IFightTeam blueTeam){ IFight.redTeam = redTeam; IFight.blueTeam = blueTeam; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index b84f9b7..b0ff4bf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -26,10 +26,12 @@ import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; +import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; -import de.steamwar.fightsystem.record.RecordSystem; -import de.steamwar.fightsystem.record.Recorder; +import de.steamwar.fightsystem.record.FileRecorder; +import de.steamwar.fightsystem.record.LiveRecorder; +import de.steamwar.fightsystem.record.PacketProcessor; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.utils.EnterHandler; @@ -57,8 +59,7 @@ public class FightSystem extends JavaPlugin { @Override public void onEnable() { - Fight.init(); - RecordSystem.init(); + IFight.init(Fight.getRedTeam(), Fight.getBlueTeam()); new EntityDamage(); new WaterRemover(); @@ -123,12 +124,16 @@ public class FightSystem extends JavaPlugin { new AkCommand(); new LeaderCommand(); new LockschemCommand(); + new ReplayCommand(); new StateCommand(); new SkipCommand(); new WinCommand(); - new OneShotStateDependent(ArenaMode.AntiSpectate, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!")); - new OneShotStateDependent(ArenaMode.AntiSpectate, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!")); + new LiveRecorder(); + new FileRecorder(); + + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!")); + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!")); new OneShotStateDependent(ArenaMode.AntiTest, FightState.Running, FightStatistics::start); try { @@ -148,14 +153,11 @@ public class FightSystem extends JavaPlugin { }else{ Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); } + }else if(Config.mode == ArenaMode.REPLAY) { + FightWorld.forceLoad(); } } - @Override - public void onDisable() { - Recorder.closeAll(); - } - public static void setPreLeaderState() { FightState.setFightState(FightState.PRE_LEADER_SETUP); @@ -181,6 +183,8 @@ public class FightSystem extends JavaPlugin { public static void setSpectateState(FightTeam winFightTeam, String windescription) { FightState.setFightState(FightState.SPECTATE); + if(PacketProcessor.isReplaying()) + return; if(winFightTeam != null) { Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java index fd73f66..000711d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class KitCommand implements CommandExecutor { public KitCommand() { - new StateDependentCommand(ArenaMode.AntiSpectate, FightState.Setup, "kit", this); + new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "kit", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java index 5c95c72..902f779 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class LeaveCommand implements CommandExecutor { public LeaveCommand() { - new StateDependentCommand(ArenaMode.AntiSpectate, FightState.Setup, "leave", this); + new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "leave", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java index fdaff2e..27dbb97 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -37,7 +37,7 @@ import org.bukkit.entity.Player; public class LockschemCommand implements CommandExecutor { public LockschemCommand() { - new StateDependentCommand(ArenaMode.AntiSpectate, FightState.All, "lockschem", this); + new StateDependentCommand(ArenaMode.AntiReplay, FightState.All, "lockschem", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReplayCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReplayCommand.java new file mode 100644 index 0000000..170705b --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReplayCommand.java @@ -0,0 +1,70 @@ +/* + 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.commands; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.record.FileRecorder; +import de.steamwar.fightsystem.record.FileSource; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.IOException; + +public class ReplayCommand implements CommandExecutor { + + public ReplayCommand() { + new StateDependentCommand(ArenaMode.Replayable, FightState.All, "replay", this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) { + return false; + } + Player player = (Player) sender; + + if(!Config.test()){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!user.getUserGroup().isTeamGroup()){ + sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar."); + return false; + } + } + + if(!FileRecorder.getFile().exists()){ + sender.sendMessage(FightSystem.PREFIX + "§cKein Replay vorhanden."); + return false; + } + + try { + new FileSource(FileRecorder.getFile()); + } catch (IOException e) { + sender.sendMessage(FightSystem.PREFIX + "§cDas Replay konnte nicht gestartet werden."); + } + return false; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java index 35ef83b..05c2a23 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -23,7 +23,7 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.listener.BasicListener; -import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -108,7 +108,7 @@ public abstract class Countdown { } private void broadcast(String message){ - RecordSystem.actionBar(message); + GlobalRecorder.getInstance().actionBar(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) BasicListener.toActionbar(p, msg); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java index 15b433f..5ab54d7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java @@ -34,8 +34,8 @@ public class NoPlayersOnlineCountdown extends Countdown implements Listener { public NoPlayersOnlineCountdown() { super(Config.NoPlayerOnlineDuration, null, false); - new StateDependentListener(ArenaMode.AntiSpectate, FightState.PreLeaderSetup, this); - new StateDependentCountdown(ArenaMode.AntiSpectate, FightState.PreLeaderSetup, this){ + new StateDependentListener(ArenaMode.AntiReplay, FightState.PreLeaderSetup, this); + new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreLeaderSetup, this){ @Override public void enable() { if(Bukkit.getOnlinePlayers().isEmpty()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java index a388fbd..18ef8de 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java @@ -30,6 +30,7 @@ public class PostSchemCountdown extends Countdown { public PostSchemCountdown() { super(Config.SetupDuration, null, false); new StateDependentCountdown(ArenaMode.AntiTest, FightState.PostSchemSetup, this); + //TODO: Replaying? } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java index f5ad64c..36a6b79 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -29,7 +29,7 @@ public class PreRunningCountdown extends Countdown { public PreRunningCountdown() { super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true); - new StateDependentCountdown(ArenaMode.AntiSpectate, FightState.PreRunning, this); + new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreRunning, this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java index fed7dd6..6dbe901 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java @@ -29,7 +29,7 @@ public class PreSchemCountdown extends Countdown { public PreSchemCountdown() { super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false); - new StateDependentCountdown(ArenaMode.AntiSpectate, FightState.PreSchemSetup, this); + new StateDependentCountdown(ArenaMode.AntiReplay, FightState.PreSchemSetup, this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index dd56cf4..7ea0ee2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -28,10 +28,12 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.sql.Schematic; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Sound; import org.bukkit.entity.Player; import java.lang.reflect.InvocationTargetException; @@ -45,10 +47,6 @@ public class Fight { private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.BlueRotate, true, Config.BlueLeader); - public static void init(){ - IFight.init(redTeam, blueTeam); - } - public static FightTeam getPlayerTeam(Player player) { if(redTeam.isPlayerInTeam(player)) return redTeam; @@ -91,7 +89,7 @@ public class Fight { } public static void playSound(Sound sound, float volume, float pitch) { - RecordSystem.soundAtPlayer(sound.name(), volume, pitch); + GlobalRecorder.getInstance().soundAtPlayer(sound.name(), volume, pitch); //volume: max. 100, pitch: max. 2 Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index a319384..74d512f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -28,7 +28,7 @@ import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; @@ -60,7 +60,7 @@ public class FightSchematic extends StateDependent { private int schematic = 0; public FightSchematic(FightTeam team, boolean rotate) { - super(ArenaMode.AntiSpectate, FightState.PostSchemSetup); + super(ArenaMode.AntiReplay, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); this.rotate = rotate; @@ -110,9 +110,9 @@ public class FightSchematic extends StateDependent { } if(team.isBlue()) - RecordSystem.blueSchem(schematic); + GlobalRecorder.getInstance().blueSchem(schematic); else - RecordSystem.redSchem(schematic); + GlobalRecorder.getInstance().redSchem(schematic); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index daa2f0d..7c4a8e2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -26,10 +26,10 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.listener.BasicListener; -import de.steamwar.fightsystem.listener.PersonalKitCreator; -import de.steamwar.fightsystem.record.RecordSystem; -import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.listener.FightScoreboard; +import de.steamwar.fightsystem.listener.PersonalKitCreator; +import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.Region; @@ -202,7 +202,7 @@ public class FightTeam implements IFightTeam{ player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(ArenaMode.NotOnBau.contains(Config.mode)) Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); - RecordSystem.playerJoins(player); + GlobalRecorder.getInstance().playerJoins(player); TechHider.reloadChunks(player, chunksToReload, false); if(isLeaderless()) @@ -220,7 +220,7 @@ public class FightTeam implements IFightTeam{ if(fightPlayer.equals(leader)) setLeader(null); - RecordSystem.entityDespawns(player); + GlobalRecorder.getInstance().entityDespawns(player); Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); player.getInventory().clear(); @@ -300,7 +300,7 @@ public class FightTeam implements IFightTeam{ public void pasteSchem(Schematic schematic){ setSchem(schematic); - if(Config.test() || RecordSystem.isReplaying()) + if(Config.test()) this.schematic.enable(); else if(Fight.getOpposite(this).hasSchematic()){ FightSystem.setPostSchemState(); @@ -406,7 +406,7 @@ public class FightTeam implements IFightTeam{ private class KitLoader extends StateDependent { private KitLoader() { - super(ArenaMode.AntiSpectate, FightState.Ingame); + super(ArenaMode.AntiReplay, FightState.Ingame); register(); } @@ -431,7 +431,7 @@ public class FightTeam implements IFightTeam{ private class SpectateHandler extends StateDependent { private SpectateHandler() { - super(ArenaMode.AntiSpectate, FightState.Spectate); + super(ArenaMode.AntiReplay, FightState.Spectate); register(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java index b3efc75..d82cbbf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java @@ -22,10 +22,13 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.IFightSystem; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.*; import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; public class FreezeWorld implements Listener { public FreezeWorld(){ @@ -70,4 +73,19 @@ public class FreezeWorld implements Listener { public void onInventoryMoveEvent(InventoryMoveItemEvent e){ e.setCancelled(true); } + + @EventHandler + public void onBlockExplosion(BlockExplodeEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void handlePlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOW) + public void handlePlayerInteract(PlayerInteractEvent event) { + event.setCancelled(true); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java index 8e89799..973a706 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java @@ -24,7 +24,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import net.md_5.bungee.api.chat.BaseComponent; @@ -64,7 +64,7 @@ public class Chat implements Listener { } private void broadcastChat(String message) { - RecordSystem.chat(message); + GlobalRecorder.getInstance().chat(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) BasicListener.toChat(p, msg); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java index 55195dc..dc3cca0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -42,7 +42,7 @@ public class EventJoin implements Listener { @EventHandler public void playerLogin(PlayerLoginEvent event) { - if(!Config.SpectateSystem) + if(!Config.LiveReplay) return; Player player = event.getPlayer(); @@ -89,7 +89,7 @@ public class EventJoin implements Listener { FightSystem.setEventLeiter(player); return; } - if(Config.SpectateSystem) + if(Config.LiveReplay) player.kickPlayer("§cDu bist kein Kampfteilnehmer"); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java index 49ff309..c747520 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -24,7 +24,8 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.record.PacketProcessor; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; @@ -61,8 +62,8 @@ public class FightScoreboard implements Listener, ScoreboardCallback { public FightScoreboard(){ - new StateDependentListener(ArenaMode.AntiSpectate, FightState.All, this); - new StateDependentTask(ArenaMode.AntiSpectate, FightState.All, this::updateScoreboard, 0, 20); + new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this); + new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::updateScoreboard, 0, 20); scoreboard = this; } @@ -112,7 +113,7 @@ public class FightScoreboard implements Listener, ScoreboardCallback { } private void updateScoreboard() { - if(RecordSystem.isReplaying()) + if(PacketProcessor.isReplaying()) return; if ((index++ / 5) % 2 == 0) { @@ -127,12 +128,12 @@ public class FightScoreboard implements Listener, ScoreboardCallback { public void setTitle(String t) { scores.clear(); title = t; - RecordSystem.scoreboardTitle(t); + GlobalRecorder.getInstance().scoreboardTitle(t); } public void addScore(String string, int i) { scores.put(string, i); - RecordSystem.scoreboardData(string, i); + GlobalRecorder.getInstance().scoreboardData(string, i); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java index 092f0aa..8b3b07f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.meta.ItemMeta; public class HotbarGUI implements Listener { public HotbarGUI() { - new StateDependentListener(ArenaMode.AntiSpectate, FightState.Setup, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java index 660429d..f83f39a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java @@ -36,7 +36,7 @@ import java.util.Objects; public class InFightDamage implements Listener { public InFightDamage() { - new StateDependentListener(ArenaMode.AntiSpectate, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java index 128b391..d63cccf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java @@ -40,7 +40,7 @@ import org.bukkit.inventory.ItemStack; public class InFightInventory implements Listener { public InFightInventory() { - new StateDependentListener(ArenaMode.AntiSpectate, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java index b942f76..8c896c5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java @@ -26,7 +26,7 @@ import de.steamwar.fightsystem.countdown.SWSound; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; @@ -40,7 +40,7 @@ import org.bukkit.event.player.PlayerQuitEvent; public class IngameDeath implements Listener { public IngameDeath() { - new StateDependentListener(ArenaMode.AntiSpectate, FightState.Ingame, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this); } @EventHandler(priority = EventPriority.HIGH) @@ -71,7 +71,7 @@ public class IngameDeath implements Listener { if(fightPlayer.isLiving()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); team.getFightPlayer(player).setOut(); - RecordSystem.entityDespawns(player); + GlobalRecorder.getInstance().entityDespawns(player); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java index d57e883..4463317 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java @@ -25,6 +25,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.REntity; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.SteamwarUser; @@ -81,6 +82,8 @@ public class Permanent implements Listener { if(ArenaMode.NotOnBau.contains(Config.mode)) Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5); } + + REntity.playerJoins(player); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java index 9a414ba..bb08635 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java @@ -25,15 +25,16 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -55,6 +56,7 @@ public class Recording implements Listener { private static final int AIR = 0; private static final Random random = new Random(); + private static final World world = Bukkit.getWorlds().get(0); private static final PacketAdapter BOW_PACKET_PROCESSOR = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.BLOCK_PLACE) { @Override public void onPacketReceiving(PacketEvent event) { @@ -66,23 +68,22 @@ public class Recording implements Listener { (hand == EnumWrappers.Hand.OFF_HAND && p.getInventory().getItemInOffHand().getType() == Material.BOW))) return; - RecordSystem.bowSpan(p, true, hand != EnumWrappers.Hand.MAIN_HAND); + GlobalRecorder.getInstance().bowSpan(p, true, hand != EnumWrappers.Hand.MAIN_HAND); } }; - private static final PacketAdapter BOW_PACKET_DEDRAW_PROCESSOR = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.BLOCK_DIG) { @Override public void onPacketReceiving(PacketEvent e) { PacketContainer packetDig = e.getPacket(); if(packetDig.getPlayerDigTypes().read(0) == EnumWrappers.PlayerDigType.RELEASE_USE_ITEM) { - RecordSystem.bowSpan(e.getPlayer(), false, false); + GlobalRecorder.getInstance().bowSpan(e.getPlayer(), false, false); } } }; public Recording() { - new StateDependentListener(Config.recording(), FightState.All, this); - new StateDependent(Config.recording(), FightState.Ingame){ + new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this); + new StateDependent(ArenaMode.AntiReplay, FightState.Ingame){ @Override public void enable() { Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { @@ -98,7 +99,7 @@ public class Recording implements Listener { despawnTNT(); } }.register(); - new StateDependent(Config.recording(), FightState.Ingame) { + new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) { @Override public void enable() { ProtocolLibrary.getProtocolManager().addPacketListener(BOW_PACKET_PROCESSOR); @@ -111,6 +112,17 @@ public class Recording implements Listener { ProtocolLibrary.getProtocolManager().removePacketListener(BOW_PACKET_DEDRAW_PROCESSOR); } }.register(); + new StateDependentTask(ArenaMode.AntiReplay, FightState.All, () -> { + GlobalRecorder.getInstance().tick(); + + if(FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording()) + return; + + for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){ + GlobalRecorder.getInstance().entityMoves(tnt); + GlobalRecorder.getInstance().entitySpeed(tnt); + } + }, 1, 1); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -118,7 +130,7 @@ public class Recording implements Listener { if(isNotSent(e.getPlayer())) return; - RecordSystem.entityMoves(e.getPlayer()); + GlobalRecorder.getInstance().entityMoves(e.getPlayer()); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @@ -126,12 +138,12 @@ public class Recording implements Listener { if(isNotSent(e.getEntity())) return; - RecordSystem.entityDespawns(e.getEntity()); + GlobalRecorder.getInstance().entityDespawns(e.getEntity()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBroadcast(BroadcastMessageEvent e){ - RecordSystem.systemChat(e.getMessage()); + GlobalRecorder.getInstance().systemChat(e.getMessage()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -139,7 +151,7 @@ public class Recording implements Listener { if(isNotSent(e.getPlayer())) return; - RecordSystem.playerSneak(e.getPlayer(), e.isSneaking()); + GlobalRecorder.getInstance().playerSneak(e.getPlayer(), e.isSneaking()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -148,7 +160,7 @@ public class Recording implements Listener { return; if(e.getAnimationType() == PlayerAnimationType.ARM_SWING) - RecordSystem.entityAnimation(e.getPlayer(), AIR); + GlobalRecorder.getInstance().entityAnimation(e.getPlayer(), AIR); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -160,10 +172,10 @@ public class Recording implements Listener { if(isNotSent(p)) return; - RecordSystem.damageAnimation(p); + GlobalRecorder.getInstance().damageAnimation(p); if(e.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK || e.getCause() == EntityDamageEvent.DamageCause.FIRE) - RecordSystem.setOnFire(p, false); + GlobalRecorder.getInstance().setOnFire(p, false); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -175,22 +187,21 @@ public class Recording implements Listener { if(isNotSent(p)) return; - RecordSystem.setOnFire(p, false); + GlobalRecorder.getInstance().setOnFire(p, false); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTNTSpawn(EntitySpawnEvent e){ - //TODO: Falling block if(e.getEntityType() != EntityType.PRIMED_TNT) return; - RecordSystem.tntSpawn(e.getEntity()); + GlobalRecorder.getInstance().tntSpawn(e.getEntity()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPhysics(BlockPhysicsEvent e){ if(e.getBlock() == e.getSourceBlock() || e.getChangedType() == Material.AIR) - RecordSystem.blockChange(e.getBlock()); + GlobalRecorder.getInstance().blockChange(e.getBlock()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -199,9 +210,9 @@ public class Recording implements Listener { return; Location loc = e.getLocation(); - RecordSystem.entityDespawns(e.getEntity()); - RecordSystem.particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_HUGE.name()); - RecordSystem.sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); + GlobalRecorder.getInstance().entityDespawns(e.getEntity()); + GlobalRecorder.getInstance().particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_HUGE.name()); + GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -209,7 +220,7 @@ public class Recording implements Listener { if(isNotSent(e.getPlayer())) return; - RecordSystem.item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND"); + GlobalRecorder.getInstance().item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND"); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -218,16 +229,16 @@ public class Recording implements Listener { return; Player player = e.getPlayer(); - RecordSystem.item(player, disarmNull(e.getMainHandItem()), "MAINHAND"); - RecordSystem.item(player, disarmNull(e.getOffHandItem()), "OFFHAND"); + GlobalRecorder.getInstance().item(player, disarmNull(e.getMainHandItem()), "MAINHAND"); + GlobalRecorder.getInstance().item(player, disarmNull(e.getOffHandItem()), "OFFHAND"); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onProjectileSpawn(ProjectileLaunchEvent e){ if(e.getEntityType() == EntityType.FIREBALL) - RecordSystem.fireballSpawn(e.getEntity()); + GlobalRecorder.getInstance().fireballSpawn(e.getEntity()); else if(e.getEntityType() == EntityType.ARROW) - RecordSystem.arrowSpawn(e.getEntity()); + GlobalRecorder.getInstance().arrowSpawn(e.getEntity()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -241,17 +252,17 @@ public class Recording implements Listener { switch(e.getSlot()){ case 103: - RecordSystem.item(player, disarmNull(e.getCurrentItem()), "HEAD"); + GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "HEAD"); break; case 102: - RecordSystem.item(player, disarmNull(e.getCurrentItem()), "CHEST"); + GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "CHEST"); break; case 101: - RecordSystem.item(player, disarmNull(e.getCurrentItem()), "LEGS"); + GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "LEGS"); break; case 100: default: - RecordSystem.item(player, disarmNull(e.getCurrentItem()), "FEET"); + GlobalRecorder.getInstance().item(player, disarmNull(e.getCurrentItem()), "FEET"); } } @@ -264,12 +275,12 @@ public class Recording implements Listener { continue; Player player = fp.getPlayer(); - RecordSystem.item(player, disarmNull(player.getInventory().getItemInMainHand()), "MAINHAND"); - RecordSystem.item(player, disarmNull(player.getInventory().getItemInOffHand()), "OFFHAND"); - RecordSystem.item(player, disarmNull(player.getInventory().getHelmet()), "HEAD"); - RecordSystem.item(player, disarmNull(player.getInventory().getChestplate()), "CHEST"); - RecordSystem.item(player, disarmNull(player.getInventory().getLeggings()), "LEGS"); - RecordSystem.item(player, disarmNull(player.getInventory().getBoots()), "FEET"); + GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getItemInMainHand()), "MAINHAND"); + GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getItemInOffHand()), "OFFHAND"); + GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getHelmet()), "HEAD"); + GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getChestplate()), "CHEST"); + GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS"); + GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getBoots()), "FEET"); } } @@ -282,13 +293,13 @@ public class Recording implements Listener { private void despawnTeam(FightTeam team){ for(FightPlayer player : team.getPlayers()){ if(player.isLiving()) - RecordSystem.entityDespawns(player.getPlayer()); + GlobalRecorder.getInstance().entityDespawns(player.getPlayer()); } } private void despawnTNT(){ for(TNTPrimed tnt : Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)) - RecordSystem.entityDespawns(tnt); + GlobalRecorder.getInstance().entityDespawns(tnt); } private boolean isNotSent(Player p){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java index de61a4d..87d4b7e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java @@ -32,7 +32,7 @@ import org.bukkit.event.player.PlayerQuitEvent; public class SetupQuit implements Listener { public SetupQuit(){ - new StateDependentListener(ArenaMode.AntiSpectate, FightState.Setup, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java deleted file mode 100644 index 8e62379..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Spectate.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - 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.listener; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.sql.SteamwarUser; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockExplodeEvent; -import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; - -public class Spectate implements Listener { - - public Spectate(){ - new StateDependentListener(ArenaMode.Spectate, FightState.All, this); - } - - @EventHandler - public void onLogin(PlayerLoginEvent e){ - Player player = e.getPlayer(); - - if(InspectCommand.inspecting){ - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ - e.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); - } - } - } - - @EventHandler - public void onPhysics(BlockPhysicsEvent event) { - event.setCancelled(true); - } - - @EventHandler - public void onBlockExplosion(BlockExplodeEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void handlePlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) { - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.LOW) - public void handlePlayerInteract(PlayerInteractEvent event) { - event.setCancelled(true); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java index 5aa30ca..d33dc58 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -35,7 +35,7 @@ public class WaterRemover implements Listener { private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth; public WaterRemover() { - new StateDependentListener(ArenaMode.AntiSpectate, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index 42aabd1..9552bb0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -19,120 +19,59 @@ package de.steamwar.fightsystem.record; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; -import org.bukkit.World; import java.io.*; -import java.util.logging.Level; import java.util.zip.GZIPOutputStream; -public class FileRecorder extends Recorder { +public class FileRecorder extends StateDependent implements Recorder { - private final DataOutputStream outputStream; + private static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "recording.recording"); + private DataOutputStream outputStream; + + public static File getFile() { + return file; + } public FileRecorder(){ - super(); - World world = Bukkit.getWorlds().get(0); - File file = new File(world.getWorldFolder(), world.getName() + ".recording"); + super(ArenaMode.AntiReplay, FightState.Schem); + } + + @Override + public DataOutputStream getStream() { + return outputStream; + } + + @Override + public void enable() { try{ - file.createNewFile(); - outputStream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file), 4096))); + outputStream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file), 4096)){ + @Override + public synchronized void flush() { + //Don't flush explicitly (performance) + } + + @Override + public void close() throws IOException { + try{ + super.flush(); + }catch(IOException e){ + //do nothing + } + super.close(); + } + }); }catch(IOException e){ throw new SecurityException("Could not open file", e); } + Recorder.super.enable(); } @Override - protected void writeBoolean(boolean b) { - try { - outputStream.writeBoolean(b); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeByte(int b) { - try { - outputStream.writeByte(b); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeShort(short s) { - try { - outputStream.writeShort(s); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeInt(int i) { - try { - outputStream.writeInt(i); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeLong(long l) { - try { - outputStream.writeLong(l); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeFloat(float f) { - try { - outputStream.writeFloat(f); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeDouble(double d) { - try { - outputStream.writeDouble(d); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void writeString(String s) { - try { - outputStream.writeUTF(s); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - close(); - } - } - - @Override - protected void doFlush() { - - } - - @Override - protected void closeRecorder() { - try { - outputStream.close(); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not close OutputStream", e); - } + public void disable() { + Recorder.super.disable(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java new file mode 100644 index 0000000..28d0e03 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java @@ -0,0 +1,51 @@ +/* + 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.Bukkit; + +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.logging.Level; +import java.util.zip.GZIPInputStream; + +public class FileSource extends PacketSource { + + public FileSource(File fightFile) throws IOException { + super(new DataInputStream(new GZIPInputStream(new FileInputStream(fightFile)))); + } + + @Override + boolean isClosed() { + try{ + return inputStream.available() == 0; + }catch (IOException e){ + Bukkit.getLogger().log(Level.WARNING, "On close test exception", e); + return true; + } + } + + @Override + boolean async() { + return false; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java new file mode 100644 index 0000000..2a3664d --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java @@ -0,0 +1,107 @@ +/* + 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 java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class GlobalRecorder extends OutputStream implements Recorder { + + private static final GlobalRecorder recorder = new GlobalRecorder(); + + public static GlobalRecorder getInstance(){ + return recorder; + } + + private final List streams = new ArrayList<>(); + private final DataOutputStream outputStream = new DataOutputStream(this); + + public void add(OutputStream stream){ + streams.add(stream); + } + + public void remove(OutputStream stream){ + streams.remove(stream); + } + + public boolean recording(){ + return !streams.isEmpty(); + } + + @Override + public DataOutputStream getStream() { + return outputStream; + } + + @Override + public void write(int i) throws IOException { + foreach(stream -> stream.write(i)); + } + + @Override + public void write(byte[] bytes, int i, int i1) throws IOException { + foreach(stream -> stream.write(bytes, i, i1)); + } + + @Override + public void flush() throws IOException { + foreach(OutputStream::flush); + } + + @Override + public void close() throws IOException { + foreach(OutputStream::close); + } + + private void foreach(IOThrower thrower) throws IOException { + //Custom iterator to allow removal of current element during iteration in underlying list + Iterator it = new Iterator() { + + private int pos = 0; + private int size = streams.size(); + + @Override + public boolean hasNext() { + return pos < streams.size(); + } + + @Override + public OutputStream next() { + if(size > streams.size()){ + pos--; + size--; + } + return streams.get(pos++); + } + }; + + while(it.hasNext()) { + thrower.run(it.next()); + } + } + + interface IOThrower{ + void run(OutputStream stream) throws IOException; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveRecorder.java new file mode 100644 index 0000000..8b6c735 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveRecorder.java @@ -0,0 +1,70 @@ +/* + 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 de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import org.bukkit.Bukkit; + +import java.io.*; +import java.net.Socket; +import java.util.logging.Level; + +public class LiveRecorder extends StateDependent implements Recorder { + + private DataOutputStream outputStream; + private Socket socket; + + public LiveRecorder(){ + super(Config.LiveReplay, FightState.All); + register(); + } + + @Override + public void enable() { + try { + socket = new Socket(Config.spectateIP, Config.spectatePort); + socket.setSoTimeout(1); // Wait a maximum of 1ms on a blocking operation (flush) + socket.setSoLinger(true, 1); // Wait a maximum of 1ms on disable + socket.setTcpNoDelay(true); // Don't wait on ack + outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), 1024)); + } catch (IOException e) { + Bukkit.getLogger().log(Level.WARNING, "Could not init connection to spectate server", e); + disable(); + } + Recorder.super.enable(); + } + + @Override + public void disable() { + try { + socket.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.WARNING, "IOException on socket close", e); + } + Recorder.super.disable(); + } + + @Override + public DataOutputStream getStream() { + return outputStream; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveServer.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveServer.java new file mode 100644 index 0000000..b58f0fa --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveServer.java @@ -0,0 +1,62 @@ +/* + 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 de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Bukkit; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.logging.Level; + +public class LiveServer { + + private final ServerSocket socket; + + public LiveServer() throws IOException { + socket = new ServerSocket(Config.spectatePort); + Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::acceptConnections); + } + + public void close(){ + try { + socket.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not close socket", e); + } + } + + private void acceptConnections(){ + try { + while(!socket.isClosed()){ + Socket s = socket.accept(); + if(PacketProcessor.isReplaying()){ + s.close(); + }else{ + new LiveSource(s); + } + } + } catch (IOException e) { + Bukkit.getLogger().log(Level.INFO, "Stopping accepting connections", e); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java new file mode 100644 index 0000000..cecf54a --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java @@ -0,0 +1,56 @@ +/* + 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.Bukkit; + +import java.io.DataInputStream; +import java.io.IOException; +import java.net.Socket; +import java.util.logging.Level; + +public class LiveSource extends PacketSource { + private final Socket socket; + + protected LiveSource(Socket socket) throws IOException { + super(new DataInputStream(socket.getInputStream())); + this.socket = socket; + } + + @Override + public void close() { + super.close(); + try { + socket.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); + } + } + + @Override + boolean isClosed() { + return socket.isClosed(); + } + + @Override + boolean async() { + return true; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index c4bb6a6..dd85b7c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -19,11 +19,13 @@ package de.steamwar.fightsystem.record; +import de.steamwar.core.VersionedRunnable; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.EventSpectateCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.fight.FreezeWorld; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.TechHider; @@ -43,7 +45,13 @@ import java.util.LinkedList; import java.util.Set; import java.util.logging.Level; -class PacketProcessor { +public class PacketProcessor { + + static boolean replaying = false; + + public static boolean isReplaying(){ + return replaying; + } private static final World world = Bukkit.getWorlds().get(0); @@ -57,7 +65,7 @@ class PacketProcessor { public PacketProcessor(PacketSource source){ this.source = source; - RecordSystem.setReplaying(true); + replaying = true; if(source.async()) { Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); @@ -198,7 +206,7 @@ class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - execSync(() -> RecordSystem.setBlock(x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); + execSync(() -> setBlockInternal(x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); } private void particle() throws IOException { @@ -281,9 +289,13 @@ class PacketProcessor { private void endReplay(){ REntity.dieAll(); freezer.disable(); - //TODO: Stop server if singular replay - FightWorld.resetWorld(); - RecordSystem.setReplaying(false); + replaying = false; + if(Config.replayserver() || ArenaMode.AntiReplay.contains(Config.mode)) { + FightSystem.setSpectateState(null, "Replay ends"); + }else{ + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cReplay beendet"); + new EventSpectateCountdown().enable(); + } } private void bow() throws IOException { @@ -419,4 +431,10 @@ class PacketProcessor { task.cancel(); } } + + private static void setBlockInternal(int x, int y, int z, int blockState){ + VersionedRunnable.call(new VersionedRunnable(() -> RecordSystem_8.setBlock(world, x, y, z, blockState), 8), + new VersionedRunnable(() -> RecordSystem_14.setBlock(world, x, y, z, blockState), 14), + new VersionedRunnable(() -> RecordSystem_15.setBlock(world, x, y, z, blockState), 15)); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java index 4297f29..79bc2a6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java @@ -70,7 +70,7 @@ public abstract class PacketSource { try { inputStream.close(); } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); + Bukkit.getLogger().log(Level.SEVERE, "IOException on disable", e); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java index e001101..ddf0315 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.*; import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.sql.SteamwarUser; import net.royawesome.jlibnoise.MathHelper; @@ -20,6 +21,7 @@ import org.bukkit.scoreboard.Team; import java.lang.reflect.InvocationTargetException; import java.util.*; +import java.util.logging.Level; public class REntity { @@ -47,38 +49,46 @@ public class REntity { }); } - public static void playerJoins(Player player) throws InvocationTargetException { - for(REntity entity : entities.values()){ - if(entity.entityType == EntityType.PLAYER){ - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getPlayerInfoPacket()); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getNamedSpawnPacket()); - for (Map.Entry entry : entity.itemSlots.entrySet()) { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue())); + public static void playerJoins(Player player) { + try{ + for(REntity entity : entities.values()){ + if(entity.entityType == EntityType.PLAYER){ + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getPlayerInfoPacket()); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getNamedSpawnPacket()); + for (Map.Entry entry : entity.itemSlots.entrySet()) { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue())); + } + }else{ + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getSpawnEntityPacket()); + } + //ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein? + if(entity.fireTick != 0) { + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, (byte) 1, true); + /*ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); + DataWatcher dataWatcher = new DataWatcher(null); + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher);*/ + } + if(entity.sneaks) { + WrappedDataWatcher watcher = new WrappedDataWatcher(); + if(Core.getVersion() > 12){ + watcher.setObject(6, getPose(true), true); + }else{ + watcher.setObject(0, (byte) 2, true); + } + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); + /*DataWatcher dataWatcher = new DataWatcher(null); + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher);*/ } - }else{ - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getSpawnEntityPacket()); - } - //ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein? - if(entity.fireTick != 0) { - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 1, true); - /*ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); - DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 1); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ - } - if(entity.sneaks) { - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(6, RecordSystem.getPose(true), true); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); - dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ } + }catch(InvocationTargetException e){ + Bukkit.getLogger().log(Level.SEVERE, "Could not sync player", e); } } @@ -189,7 +199,7 @@ public class REntity { WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 12){ - watcher.setObject(6, RecordSystem.getPose(sneaking), true); + watcher.setObject(6, getPose(sneaking), true); }else{ watcher.setObject(0, sneaking ? (byte) 2 : (byte) 0, true); } @@ -381,4 +391,9 @@ public class REntity { } return namedSpawnPacket; } + + private static Object getPose(boolean sneaking){ + return VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_14.getPose(sneaking), 14), + new VersionedCallable<>(() -> RecordSystem_15.getPose(sneaking), 15)); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java deleted file mode 100644 index 87952f4..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ /dev/null @@ -1,351 +0,0 @@ -/* - 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 de.steamwar.core.VersionedCallable; -import de.steamwar.core.VersionedRunnable; -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.*; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.sql.SteamwarUser; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class RecordSystem { - private RecordSystem(){} - - private static boolean replaying = false; - - public static boolean isReplaying(){ - return replaying; - } - - public static void setReplaying(boolean replaying){ - RecordSystem.replaying = replaying; - } - - private static final World WORLD = Bukkit.getWorlds().get(0); - - public static void init(){ - if(!Config.recording()) - return; - - Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), RecordSystem::checkWorldState, 1, 1); - if (Config.SpectateSystem) - new SpectateConnection(); - new FileRecorder(); - if(Config.mode == ArenaMode.EVENT) - teamIds(Config.EventTeamBlueID, Config.EventTeamRedID); - } - - /* - * PlayerJoinPacket (0x00) + int EntityId + int SWUserId - * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + byte headyaw - * EntityDespawnsPacket (0x02) + int EntityId - * PlayerSneakPacket (0x03) + int EntityId + boolean sneaks - * EntityAnimationPacket (0x04) + int EntityId + byte animation - * TNTSpawnPacket (0x05) + int EntityId - * EntitySpeedPacket (0x06) + int EntityId + double dx, dy, dz - * PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot - * ArrowSpawnPacket (0x08) + int EntityId - * FireballSpawnPacket (0x09) + int EntityId - * BowSpanPacket (0x0A) + int EntityId + boolean start + hand - * PlayerDamagePacket (0x0B) + int EntityId - * SetOnFire (0x0C) + int EntityId + boolean perma - * - * - * BlockPacket (0x30) + pos int, byte, int + int BlockState - * ParticlePacket (0x31) + double x, y, z + string particleType - * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch - * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState - * SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch - * - * - * ChatPacket (0xA0) + String message - * ActionBarPacket (0xA1) + String message - * SystemPacket (0xA2) + String message - * BlueSchemPacket (0xB0) + int blueSchemId - * RedSchemPacket (0xB1) + int redSchemId - * TeamIDPacket (0xB2) + int blueTeamId, redTeamId - * ScoreboardTitlePacket (0xC0) + String scoreboardTitle - * ScoreboardDataPacket (0xC1) + String key + int value - * - * CommentPacket (0xfe) + String comment - * TickPacket (0xff) - * */ - - public static synchronized void playerJoins(Player p){ - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - - Recorder.rByte(0x00); - Recorder.rInt(p.getEntityId()); - Recorder.rInt(user.getId()); - entityMoves(p); - } - - public static synchronized void entityMoves(Entity e){ - Location location = e.getLocation(); - - Recorder.rByte(0x01); - Recorder.rInt(e.getEntityId()); - Recorder.rDouble(location.getX()); - Recorder.rDouble(location.getY()); - Recorder.rDouble(location.getZ()); - Recorder.rFloat(location.getPitch()); - Recorder.rFloat(location.getYaw()); - Recorder.rByte((int)(VersionedCallable.call( - new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8), - new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9), - new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10), - new VersionedCallable<>(() -> FightWorld_12.headRotation(e), 12), - new VersionedCallable<>(() -> FightWorld_14.headRotation(e), 14), - new VersionedCallable<>(() -> FightWorld_15.headRotation(e), 15) - ) * 256 / 360)); - Recorder.flush(); - } - - public static synchronized void entityDespawns(Entity e){ - Recorder.rByte(0x02); - Recorder.rInt(e.getEntityId()); - Recorder.flush(); - } - - public static synchronized void playerSneak(Player p, boolean sneaks){ - Recorder.rByte(0x03); - Recorder.rInt(p.getEntityId()); - Recorder.rBoolean(sneaks); - Recorder.flush(); - } - - public static synchronized void entityAnimation(Entity e, int animation){ - Recorder.rByte(0x04); - Recorder.rInt(e.getEntityId()); - Recorder.rByte(animation); - Recorder.flush(); - } - - public static synchronized void tntSpawn(Entity e){ - Recorder.rByte(0x05); - spawnEntity(e); - } - - public static synchronized void entitySpeed(Entity e){ - Vector velocity = e.getVelocity(); - Recorder.rByte(0x06); - Recorder.rInt(e.getEntityId()); - Recorder.rDouble(velocity.getX()); - Recorder.rDouble(velocity.getY()); - Recorder.rDouble(velocity.getZ()); - Recorder.flush(); - } - - public static synchronized void item(Player p, ItemStack item, String slot){ - Recorder.rByte(0x07); - Recorder.rInt(p.getEntityId()); - Recorder.rString("minecraft:" + item.getType().name().toLowerCase()); - Recorder.rBoolean(!item.getEnchantments().isEmpty()); - Recorder.rString(slot); - Recorder.flush(); - } - - public static synchronized void arrowSpawn(Entity e){ - Recorder.rByte(0x08); - spawnEntity(e); - if(e.getFireTicks() > 0) - setOnFire(e, true); - } - - public static synchronized void fireballSpawn(Entity e){ - Recorder.rByte(0x09); - spawnEntity(e); - } - - public static synchronized void bowSpan(Entity e, boolean start, boolean offHand) { - Recorder.rByte(0x0A); - Recorder.rInt(e.getEntityId()); - Recorder.rBoolean(start); - Recorder.rBoolean(offHand); - Recorder.flush(); - } - - public static synchronized void damageAnimation(Player p) { - Recorder.rByte(0x0B); - Recorder.rInt(p.getEntityId()); - Recorder.flush(); - } - - public static synchronized void setOnFire(Entity e, boolean perma) { - Recorder.rByte(0x0C); - Recorder.rInt(e.getEntityId()); - Recorder.rBoolean(perma); - Recorder.flush(); - } - - public static synchronized void blockChange(Block block){ - int blockState = blockToId(block); - - int shortX = block.getX() - Config.ArenaRegion.getMinX(); - int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); - if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ - //Short block packet - Recorder.rByte(0x33); - Recorder.rByte(shortX); - Recorder.rByte(block.getY()); - Recorder.rByte(shortZ); - Recorder.rShort((short)blockState); - }else{ - //Block packet - Recorder.rByte(0x30); - Recorder.rInt(block.getX()); - Recorder.rByte(block.getY()); - Recorder.rInt(block.getZ()); - Recorder.rInt(blockState); - } - Recorder.flush(); - } - - public static synchronized void particle(double x, double y, double z, String particleType){ - Recorder.rByte(0x31); - Recorder.rDouble(x); - Recorder.rDouble(y); - Recorder.rDouble(z); - Recorder.rString(particleType); - Recorder.flush(); - } - - public static synchronized void sound(int x, int y, int z, String soundType, String soundCategory, float volume, float pitch){ - Recorder.rByte(0x32); - Recorder.rInt(x); - Recorder.rInt(y); - Recorder.rInt(z); - Recorder.rString(soundType); - Recorder.rString(soundCategory); - Recorder.rFloat(volume); - Recorder.rFloat(pitch); - Recorder.flush(); - } - - public static synchronized void soundAtPlayer(String soundType, float volume, float pitch){ - Recorder.rByte(0x34); - Recorder.rString(soundType); - Recorder.rFloat(volume); - Recorder.rFloat(pitch); - Recorder.flush(); - } - - public static synchronized void chat(String s) { - Recorder.rByte(0xA0); - Recorder.rString(s); - Recorder.flush(); - } - - public static synchronized void actionBar(String s) { - Recorder.rByte(0xA1); - Recorder.rString(s); - Recorder.flush(); - } - - public static synchronized void systemChat(String s) { - Recorder.rByte(0xA2); - Recorder.rString(s); - Recorder.flush(); - } - - public static synchronized void blueSchem(int schemId) { - Recorder.rByte(0xB0); - Recorder.rInt(schemId); - Recorder.flush(); - } - - public static synchronized void redSchem(int schemId) { - Recorder.rByte(0xB1); - Recorder.rInt(schemId); - Recorder.flush(); - } - - public static synchronized void teamIds(int blueTeamId, int redTeamId) { - Recorder.rByte(0xB2); - Recorder.rInt(blueTeamId); - Recorder.rInt(redTeamId); - Recorder.flush(); - } - - public static synchronized void scoreboardTitle(String title){ - Recorder.rByte(0xC0); - Recorder.rString(title); - Recorder.flush(); - } - - public static synchronized void scoreboardData(String key, int value){ - Recorder.rByte(0xC1); - Recorder.rString(key); - Recorder.rInt(value); - Recorder.flush(); - } - - public static synchronized void tick(){ - Recorder.rByte(0xff); - Recorder.flush(); - } - - private static void checkWorldState(){ - tick(); - - if(FightState.getFightState() == FightState.SPECTATE) - return; - - for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){ - entityMoves(tnt); - entitySpeed(tnt); - } - } - - private static void spawnEntity(Entity e){ - Recorder.rInt(e.getEntityId()); - entityMoves(e); - entitySpeed(e); - } - - private static int blockToId(Block block){ - return VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_8.blockToId(block), 8), - new VersionedCallable<>(() -> RecordSystem_14.blockToId(block), 14), - new VersionedCallable<>(() -> RecordSystem_15.blockToId(block), 15)); - } - - public static Object getPose(boolean sneaking){ - return VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_14.getPose(sneaking), 14), - new VersionedCallable<>(() -> RecordSystem_15.getPose(sneaking), 15)); - } - - public static void setBlock(int x, int y, int z, int blockState){ - VersionedRunnable.call(new VersionedRunnable(() -> RecordSystem_8.setBlock(WORLD, x, y, z, blockState), 8), - new VersionedRunnable(() -> RecordSystem_14.setBlock(WORLD, x, y, z, blockState), 14), - new VersionedRunnable(() -> RecordSystem_15.setBlock(WORLD, x, y, z, blockState), 15)); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index a332331..e9ced16 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -19,72 +19,264 @@ package de.steamwar.fightsystem.record; -import java.util.ArrayList; -import java.util.List; +import de.steamwar.core.VersionedCallable; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.*; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; -public abstract class Recorder { +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.logging.Level; - private static final List recorders = new ArrayList<>(); +public interface Recorder { + DataOutputStream getStream(); - public static void rBoolean(boolean b){ - recorders.forEach((recorder) -> recorder.writeBoolean(b)); + default void enable() { + GlobalRecorder.getInstance().add(getStream()); + + if(ArenaMode.Event.contains(Config.mode)){ + teamIds(Config.EventTeamBlueID, Config.EventTeamRedID); + } + + enableTeam(Fight.getBlueTeam()); + enableTeam(Fight.getRedTeam()); } - public static void rByte(int b){ - recorders.forEach((recorder) -> recorder.writeByte(b)); + default void enableTeam(FightTeam team){ + if(FightState.Schem.contains(FightState.getFightState())){ + if(team.isBlue()) + blueSchem(team.getSchematic()); + else + redSchem(team.getSchematic()); + } + + if(FightState.AntiSpectate.contains(FightState.getFightState())){ + for(FightPlayer player : team.getPlayers()){ + if(player.isLiving()){ + playerJoins(player.getPlayer()); + } + } + } } - public static void rShort(short s){ - recorders.forEach((recorder) -> recorder.writeShort(s)); + default void disable() { + GlobalRecorder.getInstance().remove(getStream()); + try { + getStream().close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not close OutputStream", e); + } } - public static void rInt(int i){ - recorders.forEach((recorder) -> recorder.writeInt(i)); + /* + * PlayerJoinPacket (0x00) + int EntityId + int SWUserId + * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + byte headyaw + * EntityDespawnsPacket (0x02) + int EntityId + * PlayerSneakPacket (0x03) + int EntityId + boolean sneaks + * EntityAnimationPacket (0x04) + int EntityId + byte animation + * TNTSpawnPacket (0x05) + int EntityId + * EntitySpeedPacket (0x06) + int EntityId + double dx, dy, dz + * PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot + * ArrowSpawnPacket (0x08) + int EntityId + * FireballSpawnPacket (0x09) + int EntityId + * BowSpanPacket (0x0A) + int EntityId + boolean start + hand + * PlayerDamagePacket (0x0B) + int EntityId + * SetOnFire (0x0C) + int EntityId + boolean perma + * + * + * BlockPacket (0x30) + pos int, byte, int + int BlockState + * ParticlePacket (0x31) + double x, y, z + string particleType + * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch + * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState + * SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch + * + * + * ChatPacket (0xA0) + String message + * ActionBarPacket (0xA1) + String message + * SystemPacket (0xA2) + String message + * BlueSchemPacket (0xB0) + int blueSchemId + * RedSchemPacket (0xB1) + int redSchemId + * TeamIDPacket (0xB2) + int blueTeamId, redTeamId + * ScoreboardTitlePacket (0xC0) + String scoreboardTitle + * ScoreboardDataPacket (0xC1) + String key + int value + * + * CommentPacket (0xfe) + String comment + * TickPacket (0xff) + * */ + + default void playerJoins(Player p){ + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + + write(0x00, p.getEntityId(), user.getId()); + entityMoves(p); } - public static void rLong(long l){ - recorders.forEach((recorder) -> recorder.writeLong(l)); + default void entityMoves(Entity e){ + Location location = e.getLocation(); + write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (int)(VersionedCallable.call( + new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8), + new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9), + new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10), + new VersionedCallable<>(() -> FightWorld_12.headRotation(e), 12), + new VersionedCallable<>(() -> FightWorld_14.headRotation(e), 14), + new VersionedCallable<>(() -> FightWorld_15.headRotation(e), 15) + ) * 256 / 360)); } - public static void rFloat(float f){ - recorders.forEach((recorder) -> recorder.writeFloat(f)); + default void entityDespawns(Entity e){ + write(0x02, e.getEntityId()); } - public static void rDouble(double d){ - recorders.forEach((recorder) -> recorder.writeDouble(d)); + default void playerSneak(Player p, boolean sneaks){ + write(0x03, p.getEntityId(), sneaks); } - public static void rString(String s){ - recorders.forEach((recorder) -> recorder.writeString(s)); + default void entityAnimation(Entity e, int animation){ + write(0x04, e.getEntityId(), animation); } - public static void flush(){ - recorders.forEach(Recorder::doFlush); + default void tntSpawn(Entity e){ + write(0x05, e.getEntityId()); + entityMoves(e); + entitySpeed(e); } - public static void closeAll(){ - while(!recorders.isEmpty()) - recorders.get(0).close(); + default void entitySpeed(Entity e){ + Vector velocity = e.getVelocity(); + write(0x06, e.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ()); } - protected Recorder(){ - recorders.add(this); + default void item(Player p, ItemStack item, String slot){ + write(0x07, p.getEntityId(), "minecraft:" + item.getType().name().toLowerCase(), !item.getEnchantments().isEmpty(), slot); } - protected void close(){ - closeRecorder(); - recorders.remove(this); + default void arrowSpawn(Entity e){ + write(0x08, e.getEntityId()); + entityMoves(e); + entitySpeed(e); + if(e.getFireTicks() > 0) + setOnFire(e, true); } - protected abstract void writeBoolean(boolean b); - protected abstract void writeByte(int b); - protected abstract void writeShort(short s); - protected abstract void writeInt(int i); - protected abstract void writeLong(long l); - protected abstract void writeFloat(float f); - protected abstract void writeDouble(double d); - protected abstract void writeString(String s); - protected abstract void doFlush(); + default void fireballSpawn(Entity e){ + write(0x09, e.getEntityId()); + entityMoves(e); + entitySpeed(e); + } - protected abstract void closeRecorder(); + default void bowSpan(Entity e, boolean start, boolean offHand) { + write(0x0a, e.getEntityId(), start, offHand); + } + + default void damageAnimation(Player p) { + write(0x0b, p.getEntityId()); + } + + default void setOnFire(Entity e, boolean perma) { + write(0x0c, e.getEntityId(), perma); + } + + default void blockChange(Block block){ + int blockState = VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_8.blockToId(block), 8), + new VersionedCallable<>(() -> RecordSystem_14.blockToId(block), 14), + new VersionedCallable<>(() -> RecordSystem_15.blockToId(block), 15)); + + int shortX = block.getX() - Config.ArenaRegion.getMinX(); + int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); + if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ + //Short block packet + write(0x33, shortX, block.getY(), shortZ, (short)blockState); + }else{ + //Block packet + write(0x30, block.getX(), block.getY(), block.getZ(), blockState); + } + } + + default void particle(double x, double y, double z, String particleType){ + write(0x31, x, y, z, particleType); + } + + default void sound(int x, int y, int z, String soundType, String soundCategory, float volume, float pitch){ + write(0x32, x, y, z, soundType, soundCategory, volume, pitch); + } + + default void soundAtPlayer(String soundType, float volume, float pitch){ + write(0x34, soundType, volume, pitch); + } + + default void chat(String s) { + write(0xa0, s); + } + + default void actionBar(String s) { + write(0xa1, s); + } + + default void systemChat(String s) { + write(0xa2, s); + } + + default void blueSchem(int schemId) { + write(0xb0, schemId); + } + + default void redSchem(int schemId) { + write(0xb1, schemId); + } + + default void teamIds(int blueTeamId, int redTeamId) { + write(0xb2, blueTeamId, redTeamId); + } + + default void scoreboardTitle(String title){ + write(0xc0, title); + } + + default void scoreboardData(String key, int value){ + write(0xc1, key, value); + } + + default void tick(){ + write(0xff); + } + + default void write(int id, Object... objects){ + DataOutputStream stream = getStream(); + try { + stream.writeByte(id); + for(Object o : objects){ + if(o instanceof Byte) + stream.writeByte((Byte)o); + else if(o instanceof Short) + stream.writeShort((Short)o); + else if(o instanceof Integer) + stream.writeInt((Integer)o); + else if(o instanceof Float) + stream.writeFloat((Float)o); + else if(o instanceof Double) + stream.writeDouble((Double)o); + else if(o instanceof String) + stream.writeUTF((String)o); + else + throw new SecurityException("Undefined write for: " + o.getClass().getName()); + } + stream.flush(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + try { + stream.close(); + } catch (IOException ioException) { + Bukkit.getLogger().log(Level.SEVERE, "Could not close", e); + } + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java deleted file mode 100644 index 9951321..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - 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 de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; - -import java.io.*; -import java.net.Socket; -import java.util.logging.Level; - -public class SpectateConnection extends Recorder{ - - private Socket socket; - private DataOutputStream outputStream; - - SpectateConnection(){ - super(); - try { - this.socket = new Socket(Config.spectateIP, Config.spectatePort); - socket.setSoTimeout(1); // Wait a maximum of 1ms on a blocking operation (flush) - socket.setSoLinger(true, 1); // Wait a maximum of 1ms on close - socket.setTcpNoDelay(true); // Don't wait always on ack - this.outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); - } catch (IOException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not init connection to spectate server", e); - close(); - } - } - - @Override - protected void writeBoolean(boolean b) { - try{ - outputStream.writeBoolean(b); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeByte(int b) { - try{ - outputStream.writeByte(b); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeShort(short s) { - try{ - outputStream.writeShort(s); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeInt(int i) { - try{ - outputStream.writeInt(i); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeLong(long l) { - try{ - outputStream.writeLong(l); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeFloat(float f) { - try{ - outputStream.writeFloat(f); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeDouble(double d) { - try{ - outputStream.writeDouble(d); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void writeString(String s) { - try{ - outputStream.writeUTF(s); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); - } - } - - @Override - protected void doFlush() { - try{ - outputStream.flush(); - } catch (IOException e) { - close(); - Bukkit.getLogger().log(Level.SEVERE, "Could not flush", e); - } - } - - @Override - protected void closeRecorder() { - try { - socket.close(); - outputStream.close(); - } catch (IOException e) { - Bukkit.getLogger().log(Level.WARNING, "IOException on socket close", e); - } - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java index 52c1490..93f00a6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -43,6 +43,7 @@ public enum FightState { public static final Set TeamFix = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING, SPECTATE)); public static final Set Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP))); public static final Set AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING))); + public static final Set AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE))); private static final Map stateDependentFeatures = new HashMap<>(); private static FightState fightState = PRE_LEADER_SETUP; diff --git a/FightSystem_Main/src/plugin.yml b/FightSystem_Main/src/plugin.yml index eae2084..88fbbec 100644 --- a/FightSystem_Main/src/plugin.yml +++ b/FightSystem_Main/src/plugin.yml @@ -18,6 +18,7 @@ commands: remove: leader: lockschem: + replay: state: skip: win: \ No newline at end of file From 58e8bf9fac7224b4fa7acc3d8bcf457ec17b9287 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 31 May 2021 15:10:32 +0200 Subject: [PATCH 07/33] Improved error handling Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 6 ++ .../fightsystem/record/GlobalRecorder.java | 56 ++++++++----------- .../steamwar/fightsystem/record/Recorder.java | 4 +- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index b0ff4bf..0db7f9c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -30,6 +30,7 @@ import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.FileRecorder; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.LiveRecorder; import de.steamwar.fightsystem.record.PacketProcessor; import de.steamwar.fightsystem.states.FightState; @@ -158,6 +159,11 @@ public class FightSystem extends JavaPlugin { } } + @Override + public void onDisable() { + GlobalRecorder.getInstance().close(); + } + public static void setPreLeaderState() { FightState.setFightState(FightState.PRE_LEADER_SETUP); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java index 2a3664d..b0e9824 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java @@ -19,12 +19,14 @@ package de.steamwar.fightsystem.record; +import org.bukkit.Bukkit; + import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; +import java.util.logging.Level; public class GlobalRecorder extends OutputStream implements Recorder { @@ -34,19 +36,19 @@ public class GlobalRecorder extends OutputStream implements Recorder { return recorder; } - private final List streams = new ArrayList<>(); + private final List recorders = new ArrayList<>(); private final DataOutputStream outputStream = new DataOutputStream(this); - public void add(OutputStream stream){ - streams.add(stream); + public void add(Recorder recorder){ + recorders.add(recorder); } - public void remove(OutputStream stream){ - streams.remove(stream); + public void remove(Recorder recorder){ + recorders.remove(recorder); } public boolean recording(){ - return !streams.isEmpty(); + return !recorders.isEmpty(); } @Override @@ -55,49 +57,35 @@ public class GlobalRecorder extends OutputStream implements Recorder { } @Override - public void write(int i) throws IOException { + public void write(int i) { foreach(stream -> stream.write(i)); } @Override - public void write(byte[] bytes, int i, int i1) throws IOException { + public void write(byte[] bytes, int i, int i1) { foreach(stream -> stream.write(bytes, i, i1)); } @Override - public void flush() throws IOException { + public void flush() { foreach(OutputStream::flush); } @Override - public void close() throws IOException { + public void close() { foreach(OutputStream::close); } - private void foreach(IOThrower thrower) throws IOException { - //Custom iterator to allow removal of current element during iteration in underlying list - Iterator it = new Iterator() { - - private int pos = 0; - private int size = streams.size(); - - @Override - public boolean hasNext() { - return pos < streams.size(); + private void foreach(IOThrower thrower) { + for(int i = 0; i < recorders.size(); i++) { + Recorder stream = recorders.get(i); + try{ + thrower.run(stream.getStream()); + }catch (IOException e){ + Bukkit.getLogger().log(Level.SEVERE, "Could not operate on OutputStream", e); + stream.disable(); + i--; // Recorder was removed from recorders } - - @Override - public OutputStream next() { - if(size > streams.size()){ - pos--; - size--; - } - return streams.get(pos++); - } - }; - - while(it.hasNext()) { - thrower.run(it.next()); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index e9ced16..225a82e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -41,7 +41,7 @@ public interface Recorder { DataOutputStream getStream(); default void enable() { - GlobalRecorder.getInstance().add(getStream()); + GlobalRecorder.getInstance().add(this); if(ArenaMode.Event.contains(Config.mode)){ teamIds(Config.EventTeamBlueID, Config.EventTeamRedID); @@ -69,7 +69,7 @@ public interface Recorder { } default void disable() { - GlobalRecorder.getInstance().remove(getStream()); + GlobalRecorder.getInstance().remove(this); try { getStream().close(); } catch (IOException e) { From 97a6e430989e09fb96643526dce5022e26d724b6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 26 Jul 2021 21:10:01 +0200 Subject: [PATCH 08/33] Hotfix Techhider NPE --- .../src/de/steamwar/fightsystem/utils/TechHider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 3a3308e..9f8e8a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -88,7 +88,7 @@ public class TechHider extends StateDependent { public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); - if(p.getGameMode() == GameMode.SPECTATOR) + if(p == null || p.getGameMode() == GameMode.SPECTATOR) e.setCancelled(true); } }); From 098d5638e3538db246215f946998280e278dead1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 21 Aug 2021 10:25:26 +0200 Subject: [PATCH 09/33] Fixing missing header Signed-off-by: Lixfel --- .../steamwar/fightsystem/record/REntity.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java index ddf0315..ef768a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -1,3 +1,22 @@ +/* + 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 com.comphenix.protocol.PacketType; From e52885b126d20b402211efdaa36da884dc4cf516 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 21 Aug 2021 10:35:41 +0200 Subject: [PATCH 10/33] Remove TODO Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/countdown/PostSchemCountdown.java | 1 - 1 file changed, 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java index 18ef8de..a388fbd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java @@ -30,7 +30,6 @@ public class PostSchemCountdown extends Countdown { public PostSchemCountdown() { super(Config.SetupDuration, null, false); new StateDependentCountdown(ArenaMode.AntiTest, FightState.PostSchemSetup, this); - //TODO: Replaying? } @Override From 20f3b609cb149f35571314748fb9db1f76e3d3d3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 21 Aug 2021 21:09:57 +0200 Subject: [PATCH 11/33] DB-Replayintegration Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 41 +++++++++---------- .../fightsystem/record/FileRecorder.java | 2 +- .../fightsystem/record/FileSource.java | 18 ++++++++ .../fightsystem/states/FightState.java | 1 + .../fightsystem/utils/FightStatistics.java | 10 +++++ 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 3391b94..1d2b46d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -30,10 +30,7 @@ import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; -import de.steamwar.fightsystem.record.FileRecorder; -import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.fightsystem.record.LiveRecorder; -import de.steamwar.fightsystem.record.PacketProcessor; +import de.steamwar.fightsystem.record.*; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.utils.EnterHandler; @@ -109,7 +106,6 @@ public class FightSystem extends JavaPlugin { new RankedPlayerLeftWincondition(); new WinconditionPercentTimeout(); - //noinspection InstantiationOfUtilityClass new HellsBells(); new NoPlayersOnlineCountdown(); @@ -160,6 +156,7 @@ public class FightSystem extends JavaPlugin { } }else if(Config.mode == ArenaMode.REPLAY) { FightWorld.forceLoad(); + FileSource.startReplay(); } } @@ -192,26 +189,26 @@ public class FightSystem extends JavaPlugin { } public static void setSpectateState(FightTeam winFightTeam, String windescription) { + if(!PacketProcessor.isReplaying()){ + if(winFightTeam != null) { + Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); + } else { + Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); + } + } + FightState.setFightState(FightState.SPECTATE); - if(PacketProcessor.isReplaying()) - return; - if(winFightTeam != null) { - Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); - } else { - Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); - } + if(!Config.test() && !PacketProcessor.isReplaying()){ + if(Config.mode == ArenaMode.EVENT) { + if (winFightTeam == null) + getEventFight().setErgebnis(0); + else if (winFightTeam.isBlue()) + getEventFight().setErgebnis(1); + else + getEventFight().setErgebnis(2); + } - if(Config.mode == ArenaMode.EVENT) { - if (winFightTeam == null) - getEventFight().setErgebnis(0); - else if (winFightTeam.isBlue()) - getEventFight().setErgebnis(1); - else - getEventFight().setErgebnis(2); - } - - if(!Config.test()){ FightStatistics.saveStats(winFightTeam, windescription); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index 9552bb0..d1d3ce4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -37,7 +37,7 @@ public class FileRecorder extends StateDependent implements Recorder { } public FileRecorder(){ - super(ArenaMode.AntiReplay, FightState.Schem); + super(ArenaMode.AntiReplay, FightState.Recording); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java index 28d0e03..8ecb428 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java @@ -19,17 +19,35 @@ package de.steamwar.fightsystem.record; +import de.steamwar.fightsystem.Config; import org.bukkit.Bukkit; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.logging.Level; import java.util.zip.GZIPInputStream; public class FileSource extends PacketSource { + public static void startReplay() { + if(Config.replayserver()) + return; + + try { + Files.copy( + de.steamwar.sql.Fight.getReplay(Config.ReplayID), + FileRecorder.getFile().toPath(), + StandardCopyOption.REPLACE_EXISTING); + new FileSource(FileRecorder.getFile()); + } catch (IOException e) { + throw new SecurityException("Could not start replay", e); + } + } + public FileSource(File fightFile) throws IOException { super(new DataInputStream(new GZIPInputStream(new FileInputStream(fightFile)))); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java index 93f00a6..84deb25 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -42,6 +42,7 @@ public enum FightState { public static final Set Ingame = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING)); public static final Set TeamFix = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING, SPECTATE)); public static final Set Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP))); + public static final Set Recording = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, SPECTATE))); public static final Set AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING))); public static final Set AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE))); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 4e7928f..3075e68 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -19,23 +19,27 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.FileRecorder; import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.sql.Elo; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; +import java.nio.file.Files; import java.sql.Timestamp; import java.time.Instant; import java.util.logging.Level; import static de.steamwar.sql.Fight.create; +import static de.steamwar.sql.Fight.setReplay; public class FightStatistics { private FightStatistics(){} @@ -92,6 +96,12 @@ public class FightStatistics { savePlayerStats(fp, fightId); for (FightPlayer fp : Fight.getRedTeam().getPlayers()) savePlayerStats(fp, fightId); + + setReplay(fightId, Files.readAllBytes(FileRecorder.getFile().toPath())); + + if(ArenaMode.Event.contains(Config.mode)){ + FightSystem.getEventFight().setFight(fightId); + } }catch(Exception e){ Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } From 74565853bb9a76e177718a9ff73ab45833ea9a0e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 21 Aug 2021 21:14:37 +0200 Subject: [PATCH 12/33] Close Stream Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/FileSource.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java index 8ecb428..3af2c12 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java @@ -22,10 +22,7 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import org.bukkit.Bukkit; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; +import java.io.*; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.logging.Level; @@ -37,11 +34,13 @@ public class FileSource extends PacketSource { if(Config.replayserver()) return; + InputStream input = de.steamwar.sql.Fight.getReplay(Config.ReplayID); try { Files.copy( - de.steamwar.sql.Fight.getReplay(Config.ReplayID), + input, FileRecorder.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING); + input.close(); new FileSource(FileRecorder.getFile()); } catch (IOException e) { throw new SecurityException("Could not start replay", e); From 7d1c34d31ed21732e1dd7f597c53667e361e47ef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Aug 2021 07:30:50 +0200 Subject: [PATCH 13/33] Fix bugs Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/ArenaMode.java | 2 +- .../fightsystem/commands/RemoveCommand.java | 2 +- .../fightsystem/fight/FightSchematic.java | 2 +- .../steamwar/fightsystem/fight/FightTeam.java | 2 +- .../fightsystem/listener/Shutdown.java | 6 +- .../fightsystem/record/FileRecorder.java | 1 + .../fightsystem/record/FileSource.java | 3 - .../fightsystem/record/PacketProcessor.java | 6 +- .../steamwar/fightsystem/record/REntity.java | 76 +++++-------------- .../steamwar/fightsystem/record/Recorder.java | 46 ++++++----- 10 files changed, 56 insertions(+), 90 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java index 1e83039..a3a5fee 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -49,7 +49,7 @@ public enum ArenaMode { public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, REPLAY))); public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY)); - public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); + public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED, REPLAY)); public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java index b538532..29ba6d2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class RemoveCommand implements CommandExecutor { public RemoveCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "die", this); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 74d512f..21756a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -60,7 +60,7 @@ public class FightSchematic extends StateDependent { private int schematic = 0; public FightSchematic(FightTeam team, boolean rotate) { - super(ArenaMode.AntiReplay, FightState.PostSchemSetup); + super(ArenaMode.All, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); this.rotate = rotate; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 7c4a8e2..78cdb11 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -170,7 +170,7 @@ public class FightTeam implements IFightTeam{ playerSet.forEach(this::addMember); - if(isLeaderless()){ + if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){ for(Player player : Bukkit.getOnlinePlayers()){ if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){ addMember(player); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java index be3e243..e088314 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; @@ -36,7 +37,10 @@ public class Shutdown implements Listener { @EventHandler(priority = EventPriority.HIGH) public void handlePlayerQuit(PlayerQuitEvent event) { - //Shutdown server if nobody online and its not an event server + if(Config.replayserver()) + return; + + //Shutdown server if nobody online if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) Bukkit.shutdown(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index d1d3ce4..f462a83 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -38,6 +38,7 @@ public class FileRecorder extends StateDependent implements Recorder { public FileRecorder(){ super(ArenaMode.AntiReplay, FightState.Recording); + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java index 3af2c12..0540a2e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java @@ -20,12 +20,10 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; import java.io.*; import java.nio.file.Files; import java.nio.file.StandardCopyOption; -import java.util.logging.Level; import java.util.zip.GZIPInputStream; public class FileSource extends PacketSource { @@ -56,7 +54,6 @@ public class FileSource extends PacketSource { try{ return inputStream.available() == 0; }catch (IOException e){ - Bukkit.getLogger().log(Level.WARNING, "On close test exception", e); return true; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index dd85b7c..0942347 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -101,7 +101,7 @@ public class PacketProcessor { int entityId = source.rInt(); int userId = source.rInt(); - execSync(() -> new REntity(entityId, userId)); + execSync(() -> new REntity(entityId, userId)); } private void entityMoves() throws IOException { @@ -289,13 +289,13 @@ public class PacketProcessor { private void endReplay(){ REntity.dieAll(); freezer.disable(); - replaying = false; if(Config.replayserver() || ArenaMode.AntiReplay.contains(Config.mode)) { FightSystem.setSpectateState(null, "Replay ends"); }else{ Bukkit.broadcastMessage(FightSystem.PREFIX + "§cReplay beendet"); new EventSpectateCountdown().enable(); } + replaying = false; } private void bow() throws IOException { @@ -421,7 +421,7 @@ public class PacketProcessor { } catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "The FightServer is offline"); source.close(); - } catch(IOException e){ + } catch(IOException e) { Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); source.close(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java index ef768a8..6e2d067 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -24,6 +24,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.*; +import com.mojang.authlib.GameProfile; import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.listener.FightScoreboard; @@ -55,14 +56,7 @@ public class REntity { if(entity.fireTick > 0) { entity.fireTick--; if(entity.fireTick == 0) { - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 0); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 0, true); - ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(watcher)); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(0, (byte)0)); } } }); @@ -82,28 +76,14 @@ public class REntity { } //ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein? if(entity.fireTick != 0) { - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 1, true); - /*ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); - DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 1); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 1)); } if(entity.sneaks) { - WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 12){ - watcher.setObject(6, getPose(true), true); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, getPose(true))); }else{ - watcher.setObject(0, (byte) 2, true); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 2)); } - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); - dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ } } }catch(InvocationTargetException e){ @@ -153,7 +133,7 @@ public class REntity { SteamwarUser user = SteamwarUser.get(userId); this.uuid = user.getUUID(); - this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromOfflinePlayer(Bukkit.getOfflinePlayer(uuid)), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); + this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromHandle(new GameProfile(uuid, user.getUserName())), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); entities.put(internalId, this); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket()); @@ -211,18 +191,11 @@ public class REntity { public void sneak(boolean sneaking) { sneaks = sneaking; - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); - dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); - dataWatcher.markDirty(dataWatcherObject);*/ - - WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 12){ - watcher.setObject(6, getPose(sneaking), true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, getPose(sneaking))); }else{ - watcher.setObject(0, sneaking ? (byte) 2 : (byte) 0, true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, sneaking ? (byte) 2 : (byte) 0)); } - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setOnFire(boolean perma) { @@ -232,36 +205,21 @@ public class REntity { fireTick = -1; } - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 1); - dataWatcher.markDirty(dataWatcherObject);*/ - - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 1, true); - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte) 1)); } public void setBowDrawn(boolean drawn, boolean offHand) { - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))); - dataWatcher.markDirty(dataWatcherObject); - */ - - WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 8){ - watcher.setObject(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)), true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)))); }else{ - watcher.setObject(0, (byte)0x10, true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte)0x10)); } - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setItem(String item, boolean enchanted, String slot) { ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1); if(enchanted) - stack.addEnchantment(Enchantment.DURABILITY, 1); + stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1); itemSlots.put(slot, stack); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack)); @@ -310,10 +268,12 @@ public class REntity { bytes.write(1, pitch); } - private PacketContainer getDataWatcherPacket(WrappedDataWatcher dataWatcher) { + private PacketContainer getDataWatcherPacket(int index, Object value) { PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA); metadataPacket.getIntegers().write(0, entityId); - metadataPacket.getDataWatcherModifier().write(0, dataWatcher); + WrappedWatchableObject watchable = new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(value.getClass())), value); + watchable.setDirtyState(true); + metadataPacket.getWatchableCollectionModifier().write(0, Collections.singletonList(watchable)); return metadataPacket; } @@ -327,7 +287,7 @@ public class REntity { private PacketContainer getHeadRotationPacket(){ PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION); headRotation.getIntegers().write(0, entityId); - headRotation.getBytes().write(1, headYaw); + headRotation.getBytes().write(0, headYaw); return headRotation; } @@ -366,7 +326,7 @@ public class REntity { PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT); StructureModifier ints = equipmentPacket.getIntegers(); ints.write(0, entityId); - if(Core.getVersion() > 8){ + if(Core.getVersion() == 8){ switch(slot){ case "MAINHAND": case "OFFHAND": diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 225a82e..577b870 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -122,7 +122,7 @@ public interface Recorder { default void entityMoves(Entity e){ Location location = e.getLocation(); - write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (int)(VersionedCallable.call( + write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (byte)(VersionedCallable.call( new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8), new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9), new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10), @@ -141,7 +141,7 @@ public interface Recorder { } default void entityAnimation(Entity e, int animation){ - write(0x04, e.getEntityId(), animation); + write(0x04, e.getEntityId(), (byte)animation); } default void tntSpawn(Entity e){ @@ -194,10 +194,10 @@ public interface Recorder { int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ //Short block packet - write(0x33, shortX, block.getY(), shortZ, (short)blockState); + write(0x33, (byte)shortX, (byte)block.getY(), (byte)shortZ, (short)blockState); }else{ //Block packet - write(0x30, block.getX(), block.getY(), block.getZ(), blockState); + write(0x30, block.getX(), (byte)block.getY(), block.getZ(), blockState); } } @@ -252,24 +252,28 @@ public interface Recorder { default void write(int id, Object... objects){ DataOutputStream stream = getStream(); try { - stream.writeByte(id); - for(Object o : objects){ - if(o instanceof Byte) - stream.writeByte((Byte)o); - else if(o instanceof Short) - stream.writeShort((Short)o); - else if(o instanceof Integer) - stream.writeInt((Integer)o); - else if(o instanceof Float) - stream.writeFloat((Float)o); - else if(o instanceof Double) - stream.writeDouble((Double)o); - else if(o instanceof String) - stream.writeUTF((String)o); - else - throw new SecurityException("Undefined write for: " + o.getClass().getName()); + synchronized (stream) { + stream.writeByte(id); + for(Object o : objects){ + if(o instanceof Boolean) + stream.writeBoolean((Boolean)o); + else if(o instanceof Byte) + stream.writeByte((Byte)o); + else if(o instanceof Short) + stream.writeShort((Short)o); + else if(o instanceof Integer) + stream.writeInt((Integer)o); + else if(o instanceof Float) + stream.writeFloat((Float)o); + else if(o instanceof Double) + stream.writeDouble((Double)o); + else if(o instanceof String) + stream.writeUTF((String)o); + else + throw new SecurityException("Undefined write for: " + o.getClass().getName()); + } + stream.flush(); } - stream.flush(); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); try { From 0357a7a30730473f786c395d2470c89e848a384f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 24 Aug 2021 08:16:57 +0200 Subject: [PATCH 14/33] Embedded Schem + Arena relative replay Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 5 +- .../fightsystem/fight/FightSchematic.java | 5 + .../steamwar/fightsystem/fight/FightTeam.java | 9 + .../fightsystem/record/FileSource.java | 4 +- .../fightsystem/record/LiveSource.java | 3 +- .../fightsystem/record/PacketProcessor.java | 312 +++++++++--------- .../fightsystem/record/PacketSource.java | 44 +-- .../steamwar/fightsystem/record/Recorder.java | 91 +++-- .../winconditions/WinconditionTimeTechKO.java | 2 +- 9 files changed, 246 insertions(+), 229 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 4318e6f..2837356 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -63,7 +63,7 @@ public class Config { private static final int BlueToRedX; private static final int BlueToRedY; - public static final int BlueToRedZ; + private static final int BlueToRedZ; public static final int PreperationArea; public static final int WaterDepth; @@ -390,4 +390,7 @@ public class Config { public static boolean replayserver(){ return ReplayID == -1; } + public static boolean blueNegZ(){ + return BlueToRedZ > 0; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 21756a4..af1d0b1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -85,6 +85,11 @@ public class FightSchematic extends StateDependent { } } + public void setSchematic(int schemId, Clipboard clipboard) { + this.schematic = schemId; + this.clipboard = clipboard; + } + public void reset(){ schematic = 0; clipboard = null; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 78cdb11..92ed1af 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.fight; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; @@ -299,7 +300,15 @@ public class FightTeam implements IFightTeam{ public void pasteSchem(Schematic schematic){ setSchem(schematic); + testPasteAction(); + } + public void pasteSchem(int schemId, Clipboard clipboard){ + this.schematic.setSchematic(schemId, clipboard); + testPasteAction(); + } + + private void testPasteAction(){ if(Config.test()) this.schematic.enable(); else if(Fight.getOpposite(this).hasSchematic()){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java index 0540a2e..c283504 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java @@ -46,13 +46,13 @@ public class FileSource extends PacketSource { } public FileSource(File fightFile) throws IOException { - super(new DataInputStream(new GZIPInputStream(new FileInputStream(fightFile)))); + super(new GZIPInputStream(new FileInputStream(fightFile))); } @Override boolean isClosed() { try{ - return inputStream.available() == 0; + return available() == 0; }catch (IOException e){ return true; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java index cecf54a..3a1fad5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java @@ -21,7 +21,6 @@ package de.steamwar.fightsystem.record; import org.bukkit.Bukkit; -import java.io.DataInputStream; import java.io.IOException; import java.net.Socket; import java.util.logging.Level; @@ -30,7 +29,7 @@ public class LiveSource extends PacketSource { private final Socket socket; protected LiveSource(Socket socket) throws IOException { - super(new DataInputStream(socket.getInputStream())); + super(socket.getInputStream()); this.socket = socket; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index 0942347..57c53fd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -19,6 +19,8 @@ package de.steamwar.fightsystem.record; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.core.Core; import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; @@ -55,6 +57,8 @@ public class PacketProcessor { private static final World world = Bukkit.getWorlds().get(0); + private final PacketParser[] packetDecoder = new PacketParser[256]; + private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); @@ -62,10 +66,50 @@ public class PacketProcessor { private final int obfuscateWith = TechHider.getObfuscateWith(); private final FreezeWorld freezer = new FreezeWorld(); + private boolean rotateZ = false; + private int arenaMinX = Config.ArenaRegion.getMinX(); + private int arenaMinY = Config.BluePasteRegion.getMinY(); + private int arenaMinZ = Config.ArenaRegion.getMinZ(); + + private boolean tickFinished = false; public PacketProcessor(PacketSource source){ this.source = source; replaying = true; + + packetDecoder[0x00] = this::playerJoins; + packetDecoder[0x01] = this::entityMoves; + packetDecoder[0x02] = this::entityDespawns; + packetDecoder[0x03] = this::entitySneak; + packetDecoder[0x04] = this::entityAnimation; + packetDecoder[0x05] = this::tntSpawn; + packetDecoder[0x06] = this::entityVelocity; + packetDecoder[0x07] = this::playerItem; + packetDecoder[0x08] = this::arrowSpawn; + packetDecoder[0x09] = this::fireballSpawn; + packetDecoder[0x0a] = this::bow; + packetDecoder[0x0b] = this::damage; + packetDecoder[0x0c] = this::fireTick; + packetDecoder[0x20] = this::arenaInfo; + packetDecoder[0x30] = this::block; + packetDecoder[0x31] = this::particle; + packetDecoder[0x32] = this::sound; + packetDecoder[0x33] = this::shortBlock; + packetDecoder[0x34] = this::soundAtPlayer; + packetDecoder[0x35] = this::shortRelativeBlock; + packetDecoder[0xa0] = () -> send(ChatMessageType.CHAT); + packetDecoder[0xa1] = () -> send(ChatMessageType.ACTION_BAR); + packetDecoder[0xa2] = () -> send(ChatMessageType.SYSTEM); + packetDecoder[0xb0] = () -> pasteSchem(Fight.getBlueTeam()); + packetDecoder[0xb1] = () -> pasteSchem(Fight.getRedTeam()); + packetDecoder[0xb2] = this::teams; + packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam()); + packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam()); + packetDecoder[0xc0] = this::scoreboardTitle; + packetDecoder[0xc1] = this::scoreboardData; + packetDecoder[0xef] = source::readUTF; + packetDecoder[0xff] = this::tick; + if(source.async()) { Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); @@ -98,56 +142,59 @@ public class PacketProcessor { } private void playerJoins() throws IOException { - int entityId = source.rInt(); - int userId = source.rInt(); + int entityId = source.readInt(); + int userId = source.readInt(); execSync(() -> new REntity(entityId, userId)); } private void entityMoves() throws IOException { - int entityId = source.rInt(); - double locX = source.rDouble(); - double locY = source.rDouble(); - double locZ = source.rDouble(); - float pitch = source.rFloat(); - float yaw = source.rFloat(); - byte headYaw = source.rByte(); + int entityId = source.readInt(); + double locX = source.readDouble() - arenaMinX + Config.ArenaRegion.getMinX(); + double locY = source.readDouble() - arenaMinY + Config.BluePasteRegion.getMinY(); + double z = source.readDouble() - arenaMinZ; + if(rotateZ) + z = Config.ArenaRegion.getSizeZ() - z; + double locZ = z + Config.ArenaRegion.getMinZ(); + float pitch = source.readFloat(); + float yaw = source.readFloat() + (rotateZ ? 360 : 0); + byte headYaw = (byte)((source.readByte() + (rotateZ ? 128 : 0)) % 256); execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, pitch, yaw, headYaw)); } private void entityDespawns() throws IOException { - int entityId = source.rInt(); + int entityId = source.readInt(); execSync(() -> REntity.getEntity(entityId).die()); } private void entitySneak() throws IOException { - int entityId = source.rInt(); - boolean sneaking = source.rBoolean(); + int entityId = source.readInt(); + boolean sneaking = source.readBoolean(); execSync(() -> REntity.getEntity(entityId).sneak(sneaking)); } private void entityAnimation() throws IOException { - int entityId = source.rInt(); - byte animation = source.rByte(); + int entityId = source.readInt(); + byte animation = source.readByte(); execSync(() -> REntity.getEntity(entityId).animation(animation)); } private void tntSpawn() throws IOException { - int entityId = source.rInt(); + int entityId = source.readInt(); execSync(() -> new REntity(entityId, EntityType.PRIMED_TNT)); } private void entityVelocity() throws IOException { - int entityId = source.rInt(); + int entityId = source.readInt(); - double dX = source.rDouble(); - double dY = source.rDouble(); - double dZ = source.rDouble(); + double dX = source.readDouble(); + double dY = source.readDouble(); + double dZ = rotateZ ? -source.readDouble() : source.readDouble(); execSync(() -> { REntity entity = REntity.getEntity(entityId); @@ -157,49 +204,71 @@ public class PacketProcessor { } private void playerItem() throws IOException { - int entityId = source.rInt(); - String item = source.rString(); - boolean enchanted = source.rBoolean(); - String slot = source.rString(); + int entityId = source.readInt(); + String item = source.readUTF(); + boolean enchanted = source.readBoolean(); + String slot = source.readUTF(); execSync(() -> REntity.getEntity(entityId).setItem(item, enchanted, slot)); } private void arrowSpawn() throws IOException { - int entityId = source.rInt(); + int entityId = source.readInt(); execSync(() -> new REntity(entityId, EntityType.ARROW)); } private void fireballSpawn() throws IOException { - int entityId = source.rInt(); + int entityId = source.readInt(); execSync(() -> new REntity(entityId, EntityType.FIREBALL)); } private void send(ChatMessageType type) throws IOException { - String message = source.rString(); + String message = source.readUTF(); BaseComponent[] text = TextComponent.fromLegacyText(message); Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(type, text)); } + private void arenaInfo() throws IOException { + rotateZ = source.readBoolean() != Config.blueNegZ(); + arenaMinY = Byte.toUnsignedInt(source.readByte()); + arenaMinX = source.readInt(); + arenaMinZ = source.readInt(); + } + private void shortBlock() throws IOException { - int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaRegion.getMinX(); - int y = Byte.toUnsignedInt(source.rByte()); - int z = Byte.toUnsignedInt(source.rByte()) + Config.ArenaRegion.getMinZ(); - int blockState = source.rShort(); + int x = Byte.toUnsignedInt(source.readByte()) + Config.ArenaRegion.getMinX(); + int y = Byte.toUnsignedInt(source.readByte()); + int z = Byte.toUnsignedInt(source.readByte()) + Config.ArenaRegion.getMinZ(); + int blockState = source.readShort(); setBlock(x, y, z, blockState); } - private void block() throws IOException { - int x = source.rInt(); - int y = Byte.toUnsignedInt(source.rByte()); - int z = source.rInt(); - int blockState = source.rInt(); + private void shortRelativeBlock() throws IOException { + int x = Byte.toUnsignedInt(source.readByte()); + int y = Byte.toUnsignedInt(source.readByte()); + int z = Byte.toUnsignedInt(source.readByte()); + int blockState = source.readShort(); - setBlock(x, y, z, blockState); + if(rotateZ) + z = Config.ArenaRegion.getSizeZ() - z; + + setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState); + } + + private void block() throws IOException { + int x = source.readInt() - arenaMinX; + int y = Byte.toUnsignedInt(source.readByte()) - arenaMinY; + int z = source.readInt() - arenaMinZ; + int blockState = source.readInt(); + + if(rotateZ) + z = Config.ArenaRegion.getSizeZ() - z; + + setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState); } private void setBlock(int x, int y, int z, int blockState){ @@ -210,25 +279,25 @@ public class PacketProcessor { } private void particle() throws IOException { - double x = source.rDouble(); - double y = source.rDouble(); - double z = source.rDouble(); + double x = source.readDouble(); + double y = source.readDouble(); + double z = source.readDouble(); - String particleName = source.rString(); + String particleName = source.readUTF(); execSync(() -> world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1)); } private void sound() throws IOException { - int x = source.rInt(); - int y = source.rInt(); - int z = source.rInt(); + int x = source.readInt(); + int y = source.readInt(); + int z = source.readInt(); - String soundName = source.rString(); - String soundCategory = source.rString(); + String soundName = source.readUTF(); + String soundCategory = source.readUTF(); - float volume = source.rFloat(); - float pitch = source.rFloat(); + float volume = source.readFloat(); + float pitch = source.readFloat(); Sound sound = Sound.valueOf(soundName); SoundCategory sCategory = SoundCategory.valueOf(soundCategory); @@ -237,10 +306,10 @@ public class PacketProcessor { } private void soundAtPlayer() throws IOException { - String soundName = source.rString(); + String soundName = source.readUTF(); - float volume = source.rFloat(); - float pitch = source.rFloat(); + float volume = source.readFloat(); + float pitch = source.readFloat(); Sound sound = Sound.valueOf(soundName); @@ -252,14 +321,21 @@ public class PacketProcessor { } private void pasteSchem(FightTeam team) throws IOException { - int schemId = source.rInt(); + int schemId = source.readInt(); execSync(() -> team.pasteSchem(Schematic.getSchemFromDB(schemId))); } + private void pasteEmbeddedSchem(FightTeam team) throws IOException { + int schemId = source.readInt(); + Clipboard clipboard = Schematic.clipboardFromStream(source, Core.getVersion() > 12); + + execSync(() -> team.pasteSchem(schemId, clipboard)); + } + private void teams() throws IOException { - int blueId = source.rInt(); - int redId = source.rInt(); + int blueId = source.readInt(); + int redId = source.readInt(); execSync(() -> { pasteForTeam(blueId, Fight.getBlueTeam()); @@ -274,14 +350,14 @@ public class PacketProcessor { } private void scoreboardTitle() throws IOException { - String title = source.rString(); + String title = source.readUTF(); FightScoreboard.getScoreboard().setTitle(title); } private void scoreboardData() throws IOException { - String key = source.rString(); - int value = source.rInt(); + String key = source.readUTF(); + int value = source.readInt(); FightScoreboard.getScoreboard().addScore(key, value); } @@ -299,123 +375,43 @@ public class PacketProcessor { } private void bow() throws IOException { - int entityId = source.rInt(); - boolean drawn = source.rBoolean(); - boolean offHand = source.rBoolean(); + int entityId = source.readInt(); + boolean drawn = source.readBoolean(); + boolean offHand = source.readBoolean(); execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, offHand)); } private void damage() throws IOException { - int entityId = source.rInt(); + int entityId = source.readInt(); execSync(() -> REntity.getEntity(entityId).damage()); } private void fireTick() throws IOException { - int entityId = source.rInt(); - boolean perma = source.rBoolean(); + int entityId = source.readInt(); + boolean perma = source.readBoolean(); execSync(() -> REntity.getEntity(entityId).setOnFire(perma)); } + private void tick(){ + execSync(REntity::tickFire); + if(!source.async()) + tickFinished = true; + } + private void process(){ + tickFinished = false; try{ - boolean tickFinished = false; while(!source.isClosed() && !tickFinished){ - byte packetType = source.rByte(); - switch(packetType){ - case 0x00: - playerJoins(); - break; - case 0x01: - entityMoves(); - break; - case 0x02: - entityDespawns(); - break; - case 0x03: - entitySneak(); - break; - case 0x04: - entityAnimation(); - break; - case 0x05: - tntSpawn(); - break; - case 0x06: - entityVelocity(); - break; - case 0x07: - playerItem(); - break; - case 0x08: - arrowSpawn(); - break; - case 0x09: - fireballSpawn(); - break; - case 0x0A: - bow(); - break; - case 0x0B: - damage(); - break; - case 0x0C: - fireTick(); - break; - case 0x30: - block(); - break; - case 0x31: - particle(); - break; - case 0x32: - sound(); - break; - case 0x33: - shortBlock(); - break; - case 0x34: - soundAtPlayer(); - break; - case (byte) 0xA0: - send(ChatMessageType.CHAT); - break; - case (byte) 0xA1: - send(ChatMessageType.ACTION_BAR); - break; - case (byte) 0xA2: - send(ChatMessageType.SYSTEM); - break; - case (byte) 0xB0: - pasteSchem(Fight.getBlueTeam()); - break; - case (byte) 0xB1: - pasteSchem(Fight.getRedTeam()); - break; - case (byte) 0xB2: - teams(); - break; - case (byte) 0xC0: - scoreboardTitle(); - break; - case (byte) 0xC1: - scoreboardData(); - break; - case (byte) 0xEF: - // Comment - source.rString(); - break; - case (byte) 0xFF: - //Tick - execSync(REntity::tickFire); - if(!source.async()) - tickFinished = true; - break; - default: - Bukkit.getLogger().log(Level.SEVERE, "Unknown packet {} recieved, closing.", packetType); - source.close(); + int packetType = Byte.toUnsignedInt(source.readByte()); + PacketParser parser = packetDecoder[packetType]; + if(parser != null){ + parser.process(); + }else{ + Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing."); + source.close(); } } } catch (EOFException e) { @@ -437,4 +433,8 @@ public class PacketProcessor { new VersionedRunnable(() -> RecordSystem_14.setBlock(world, x, y, z, blockState), 14), new VersionedRunnable(() -> RecordSystem_15.setBlock(world, x, y, z, blockState), 15)); } + + private interface PacketParser{ + void process() throws IOException; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java index 79bc2a6..855959f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java @@ -23,52 +23,20 @@ import org.bukkit.Bukkit; import java.io.DataInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.logging.Level; -public abstract class PacketSource { +public abstract class PacketSource extends DataInputStream { - protected final DataInputStream inputStream; - - protected PacketSource(DataInputStream inputStream){ - this.inputStream = inputStream; + protected PacketSource(InputStream inputStream){ + super(inputStream); new PacketProcessor(this); } - public byte rByte() throws IOException { - return inputStream.readByte(); - } - - public boolean rBoolean() throws IOException { - return inputStream.readBoolean(); - } - - public short rShort() throws IOException { - return inputStream.readShort(); - } - - public int rInt() throws IOException { - return inputStream.readInt(); - } - - public long rLong() throws IOException { - return inputStream.readLong(); - } - - public float rFloat() throws IOException { - return inputStream.readFloat(); - } - - public double rDouble() throws IOException { - return inputStream.readDouble(); - } - - public String rString() throws IOException { - return inputStream.readUTF(); - } - + @Override public void close(){ try { - inputStream.close(); + super.close(); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "IOException on disable", e); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 577b870..56ec873 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.*; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -35,6 +36,8 @@ import org.bukkit.util.Vector; import java.io.DataOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.logging.Level; public interface Recorder { @@ -47,6 +50,7 @@ public interface Recorder { teamIds(Config.EventTeamBlueID, Config.EventTeamRedID); } + arenaInfo(); enableTeam(Fight.getBlueTeam()); enableTeam(Fight.getRedTeam()); } @@ -92,20 +96,26 @@ public interface Recorder { * PlayerDamagePacket (0x0B) + int EntityId * SetOnFire (0x0C) + int EntityId + boolean perma * + * ArenaInfo (0x20) + bool blueNegZ + byte arenaY + int arenaMinX + int arenaMinZ * * BlockPacket (0x30) + pos int, byte, int + int BlockState * ParticlePacket (0x31) + double x, y, z + string particleType * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState * SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch + * ShortBlockPacket (0x35) + pos relative to ArenaMinX,BluePasteY,ArenaMinZ byte, byte, byte + short BlockState * * * ChatPacket (0xA0) + String message * ActionBarPacket (0xA1) + String message * SystemPacket (0xA2) + String message + * * BlueSchemPacket (0xB0) + int blueSchemId * RedSchemPacket (0xB1) + int redSchemId * TeamIDPacket (0xB2) + int blueTeamId, redTeamId + * BlueEmbeddedSchemPacket (0xB3) + int blueSchemId + gzipt NBT blob + * RedEmbeddedSchemPacket (0xB4) + int redSchemId + gzipt NBT blob + * * ScoreboardTitlePacket (0xC0) + String scoreboardTitle * ScoreboardDataPacket (0xC1) + String key + int value * @@ -185,16 +195,22 @@ public interface Recorder { write(0x0c, e.getEntityId(), perma); } + default void arenaInfo(){ + write(0x20, Config.blueNegZ(), (byte)Config.BluePasteRegion.getMinY(), + Config.ArenaRegion.getMinX(), Config.ArenaRegion.getMinZ()); + } + default void blockChange(Block block){ int blockState = VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_8.blockToId(block), 8), new VersionedCallable<>(() -> RecordSystem_14.blockToId(block), 14), new VersionedCallable<>(() -> RecordSystem_15.blockToId(block), 15)); int shortX = block.getX() - Config.ArenaRegion.getMinX(); + int shortY = block.getY() - Config.BluePasteRegion.getMinY(); int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); - if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ + if((short)blockState == blockState && shortX >= 0 && shortX < 256 && shortY >= 0 && shortZ >= 0 && shortZ < 256){ //Short block packet - write(0x33, (byte)shortX, (byte)block.getY(), (byte)shortZ, (short)blockState); + write(0x35, (byte)shortX, (byte)shortY, (byte)shortZ, (short)blockState); }else{ //Block packet write(0x30, block.getX(), (byte)block.getY(), block.getZ(), blockState); @@ -225,16 +241,26 @@ public interface Recorder { write(0xa2, s); } + default void teamIds(int blueTeamId, int redTeamId) { + write(0xb2, blueTeamId, redTeamId); + } + default void blueSchem(int schemId) { - write(0xb0, schemId); + try { + write(0xb3, schemId, Schematic.getSchemFromDB(schemId).schemData()); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); + write(0xb0, schemId); + } } default void redSchem(int schemId) { - write(0xb1, schemId); - } - - default void teamIds(int blueTeamId, int redTeamId) { - write(0xb2, blueTeamId, redTeamId); + try { + write(0xb4, schemId, Schematic.getSchemFromDB(schemId).schemData()); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); + write(0xb1, schemId); + } } default void scoreboardTitle(String title){ @@ -252,28 +278,28 @@ public interface Recorder { default void write(int id, Object... objects){ DataOutputStream stream = getStream(); try { - synchronized (stream) { - stream.writeByte(id); - for(Object o : objects){ - if(o instanceof Boolean) - stream.writeBoolean((Boolean)o); - else if(o instanceof Byte) - stream.writeByte((Byte)o); - else if(o instanceof Short) - stream.writeShort((Short)o); - else if(o instanceof Integer) - stream.writeInt((Integer)o); - else if(o instanceof Float) - stream.writeFloat((Float)o); - else if(o instanceof Double) - stream.writeDouble((Double)o); - else if(o instanceof String) - stream.writeUTF((String)o); - else - throw new SecurityException("Undefined write for: " + o.getClass().getName()); - } - stream.flush(); + stream.writeByte(id); + for(Object o : objects){ + if(o instanceof Boolean) + stream.writeBoolean((Boolean)o); + else if(o instanceof Byte) + stream.writeByte((Byte)o); + else if(o instanceof Short) + stream.writeShort((Short)o); + else if(o instanceof Integer) + stream.writeInt((Integer)o); + else if(o instanceof Float) + stream.writeFloat((Float)o); + else if(o instanceof Double) + stream.writeDouble((Double)o); + else if(o instanceof String) + stream.writeUTF((String)o); + else if(o instanceof InputStream) + copy((InputStream) o, stream); + else + throw new SecurityException("Undefined write for: " + o.getClass().getName()); } + stream.flush(); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); try { @@ -283,4 +309,11 @@ public interface Recorder { } } } + + static void copy(InputStream var0, OutputStream var1) throws IOException { + int var5; + for(byte[] var4 = new byte[8192]; (var5 = var0.read(var4)) > 0;) { + var1.write(var4, 0, var5); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index 7dea0d1..dfc9f6d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -52,7 +52,7 @@ public class WinconditionTimeTechKO extends Wincondition { public WinconditionTimeTechKO(){ super("TechKO"); - if(Config.BlueToRedZ > 0) { + if(Config.blueNegZ()) { smallerZteam = Fight.getBlueTeam(); biggerZteam = Fight.getRedTeam(); }else{ From c164c7ebfefa6cf7ba5804cc3f4919ec140e8549 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 27 Aug 2021 22:34:20 +0200 Subject: [PATCH 15/33] Hotfix BlockPhysicsEvent sub 1.12 recording Signed-off-by: Lixfel --- .../fightsystem/listener/Recording.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java index bb08635..0460e50 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java @@ -25,6 +25,7 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; +import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -123,6 +124,22 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entitySpeed(tnt); } }, 1, 1); + if(Core.getVersion() > 12){ + new StateDependentListener(ArenaMode.AntiReplay, FightState.All, new Listener() { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPhysics(BlockPhysicsEvent e){ + if(e.getBlock() == e.getSourceBlock() || e.getChangedType() == Material.AIR) + GlobalRecorder.getInstance().blockChange(e.getBlock()); + } + }); + }else{ + new StateDependentListener(ArenaMode.AntiReplay, FightState.All, new Listener() { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPhysics(BlockPhysicsEvent e){ + GlobalRecorder.getInstance().blockChange(e.getBlock()); + } + }); + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -198,12 +215,6 @@ public class Recording implements Listener { GlobalRecorder.getInstance().tntSpawn(e.getEntity()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockPhysics(BlockPhysicsEvent e){ - if(e.getBlock() == e.getSourceBlock() || e.getChangedType() == Material.AIR) - GlobalRecorder.getInstance().blockChange(e.getBlock()); - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onExplosion(EntityExplodeEvent e){ if(e.getEntityType() != EntityType.PRIMED_TNT) From 0604d4b7256e03801d24aec7a1d142f5d8ce6136 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 27 Aug 2021 22:40:09 +0200 Subject: [PATCH 16/33] Hotfix Testarena NPE Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/Recorder.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 56ec873..d61df19 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -247,6 +247,9 @@ public interface Recorder { default void blueSchem(int schemId) { try { + if(schemId == 0) + throw new IOException(); + write(0xb3, schemId, Schematic.getSchemFromDB(schemId).schemData()); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); @@ -256,6 +259,9 @@ public interface Recorder { default void redSchem(int schemId) { try { + if(schemId == 0) + throw new IOException(); + write(0xb4, schemId, Schematic.getSchemFromDB(schemId).schemData()); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); From f8c96b196d12edac9d7ec55cc0e15011566df56b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 27 Aug 2021 23:06:26 +0200 Subject: [PATCH 17/33] Hotfix more robust schem handling Signed-off-by: Lixfel --- .../steamwar/fightsystem/record/Recorder.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index d61df19..d9f2f40 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -246,26 +246,23 @@ public interface Recorder { } default void blueSchem(int schemId) { - try { - if(schemId == 0) - throw new IOException(); - - write(0xb3, schemId, Schematic.getSchemFromDB(schemId).schemData()); - } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); - write(0xb0, schemId); - } + schem(0xb3, 0xb0, schemId); } default void redSchem(int schemId) { + schem(0xb4, 0xb1, schemId); + } + + default void schem(int embedId, int noEmbedId, int schemId){ try { if(schemId == 0) throw new IOException(); - write(0xb4, schemId, Schematic.getSchemFromDB(schemId).schemData()); + write(embedId, schemId, Schematic.getSchemFromDB(schemId).schemData()); } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); - write(0xb1, schemId); + if(schemId != 0) + Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); + write(noEmbedId, schemId); } } @@ -308,11 +305,7 @@ public interface Recorder { stream.flush(); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); - try { - stream.close(); - } catch (IOException ioException) { - Bukkit.getLogger().log(Level.SEVERE, "Could not close", e); - } + disable(); } } From fa66d32852a332aa2e6372a7d88b86464e98a77e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 28 Aug 2021 09:55:35 +0200 Subject: [PATCH 18/33] Fix forceload Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightWorld.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java index a6343fd..93e53bd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.fight; +import de.steamwar.core.Core; import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; @@ -62,9 +63,9 @@ public class FightWorld extends StateDependent { public static void forceLoad(){ Config.ArenaRegion.forEachChunk((cX, cZ) -> { world.loadChunk(cX, cZ); - world.setChunkForceLoaded(cX, cZ, true); + if(Core.getVersion() > 12) + world.setChunkForceLoaded(cX, cZ, true); }); - world.setSpawnLocation(Config.SpecSpawn); world.setKeepSpawnInMemory(true); } From 96bd358d29704ed34628d22116059d27e9dc1f65 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Aug 2021 10:42:42 +0200 Subject: [PATCH 19/33] New VersionDependent system Signed-off-by: Lixfel --- FightSystem_10/pom.xml | 20 +- .../listener/PersonalKitCreator_10.java | 36 --- .../CraftbukkitWrapper10.java} | 33 ++- FightSystem_12/pom.xml | 17 +- .../fightsystem/fight/FightTeam12.java | 9 +- .../fightsystem/listener/ArrowStopper12.java | 30 +++ .../listener/PersonalKitCreator_12.java | 36 --- .../CraftbukkitWrapper12.java} | 33 ++- .../fightsystem/utils/TechHider12.java | 124 ++++++++++ .../fightsystem/utils/TechHider_12.java | 122 ---------- .../WorldeditWrapper12.java} | 32 +-- FightSystem_14/pom.xml | 20 +- .../listener/PersonalKitCreator_14.java | 42 ---- .../fightsystem/listener/WaterRemover_14.java | 59 ----- .../BlockIdWrapper14.java} | 59 +++-- .../CraftbukkitWrapper14.java} | 33 ++- .../utils/FlatteningWrapper14.java | 111 +++++++++ .../SWSound14.java} | 19 +- .../fightsystem/utils/TechHider14.java | 199 +++++++++++++++ .../fightsystem/utils/TechHider_14.java | 226 ------------------ .../WorldeditWrapper14.java} | 48 ++-- FightSystem_15/pom.xml | 20 +- .../listener/PersonalKitCreator_15.java | 36 --- .../BlockIdWrapper15.java} | 59 +++-- .../CraftbukkitWrapper15.java} | 33 ++- .../fightsystem/utils/TechHider_15.java | 54 ----- FightSystem_8/pom.xml | 15 +- .../fightsystem/fight/FightTeam8.java | 13 +- .../fightsystem/listener/ArrowPickup8.java | 17 +- .../fightsystem/listener/ArrowStopper8.java | 21 +- .../DenyWorldInteraction8.java} | 19 +- .../fightsystem/listener/WaterRemover_8.java | 40 ---- ...{TechHider_8.java => BlockIdWrapper8.java} | 29 ++- .../fightsystem/utils/BountifulWrapper8.java | 58 +++++ .../CraftbukkitWrapper8.java} | 30 ++- .../fightsystem/utils/FlatteningWrapper8.java | 89 +++++++ .../Countdown_8.java => utils/SWSound8.java} | 19 +- .../TechHider8.java} | 25 +- .../WorldeditWrapper8.java} | 49 ++-- FightSystem_9/pom.xml | 20 +- ...ArrowListener_9.java => ArrowPickup9.java} | 2 +- .../listener/DenyWorldInteraction9.java | 6 +- .../listener/PersonalKitCreator_9.java | 36 --- .../BountifulWrapper9.java} | 35 ++- .../CraftbukkitWrapper9.java} | 33 ++- .../Countdown_9.java => utils/SWSound9.java} | 19 +- .../de/steamwar/fightsystem/IFightSystem.java | 52 ---- .../de/steamwar/fightsystem/fight/IFight.java | 42 ---- {FightSystem_API => FightSystem_Core}/pom.xml | 26 +- .../src/config.yml | 0 .../de/steamwar/fightsystem/ArenaMode.java | 4 +- .../src/de/steamwar/fightsystem/Config.java | 16 +- .../de/steamwar/fightsystem/FightSystem.java | 22 +- .../fightsystem/VersionDependent.java | 41 ++++ .../fightsystem/commands/AcceptCommand.java | 0 .../fightsystem/commands/AkCommand.java | 0 .../fightsystem/commands/CommandInjector.java | 0 .../fightsystem/commands/Commands.java | 0 .../fightsystem/commands/DeclineCommand.java | 0 .../de/steamwar/fightsystem/commands/GUI.java | 0 .../fightsystem/commands/GamemodeCommand.java | 0 .../fightsystem/commands/InviteCommand.java | 0 .../fightsystem/commands/KitCommand.java | 0 .../fightsystem/commands/LeaderCommand.java | 0 .../fightsystem/commands/LeaveCommand.java | 0 .../commands/LockschemCommand.java | 0 .../fightsystem/commands/ReadyCommand.java | 0 .../fightsystem/commands/RemoveCommand.java | 0 .../fightsystem/commands/ReplayCommand.java | 0 .../fightsystem/commands/SkipCommand.java | 0 .../fightsystem/commands/StateCommand.java | 0 .../fightsystem/commands/WinCommand.java | 0 .../fightsystem/countdown/Countdown.java | 26 +- .../countdown/EnternCountdown.java | 7 +- .../countdown/EventSpectateCountdown.java | 1 + .../countdown/NoPlayersOnlineCountdown.java | 0 .../countdown/PostSchemCountdown.java | 0 .../countdown/PreRunningCountdown.java | 1 + .../countdown/PreSchemCountdown.java | 1 + .../countdown/SpectateOverCountdown.java | 2 +- .../countdown/TimeOverCountdown.java | 1 + .../fightsystem/event/HellsBells.java | 2 +- .../de/steamwar/fightsystem/fight/Fight.java | 0 .../fightsystem/fight/FightPlayer.java | 0 .../fightsystem/fight/FightSchematic.java | 67 ++---- .../steamwar/fightsystem/fight/FightTeam.java | 27 +-- .../fightsystem/fight/FightWorld.java | 36 +-- .../fightsystem/fight/FreezeWorld.java | 4 +- .../de/steamwar/fightsystem/fight/Kit.java | 18 +- .../fightsystem/listener/ArenaBorder.java | 0 .../fightsystem/listener/ArrowPickup.java | 6 +- .../fightsystem/listener/ArrowStopper.java | 13 +- .../fightsystem/listener/BasicListener.java | 14 +- .../steamwar/fightsystem/listener/Chat.java | 3 +- .../steamwar/fightsystem/listener/Check.java | 0 .../listener/DenyWorldInteraction.java | 11 +- .../fightsystem/listener/EntityDamage.java | 0 .../fightsystem/listener/EventJoin.java | 0 .../fightsystem/listener/FightScoreboard.java | 0 .../fightsystem/listener/HotbarGUI.java | 0 .../fightsystem/listener/InFightDamage.java | 0 .../listener/InFightInventory.java | 13 +- .../fightsystem/listener/IngameDeath.java | 5 +- .../fightsystem/listener/NormalJoin.java | 0 .../fightsystem/listener/Permanent.java | 0 .../listener/PersonalKitCreator.java | 0 .../fightsystem/listener/PistonListener.java | 1 - .../fightsystem/listener/PrepareSchem.java | 16 +- .../fightsystem/listener/RankedJoin.java | 0 .../fightsystem/listener/Recording.java | 31 +-- .../fightsystem/listener/ResourcePack.java | 15 +- .../fightsystem/listener/SetupQuit.java | 0 .../fightsystem/listener/Shutdown.java | 0 .../fightsystem/listener/TeamArea.java | 0 .../fightsystem/listener/TestJoin.java | 0 .../fightsystem/listener/WaterRemover.java | 12 +- .../fightsystem/record/FileRecorder.java | 0 .../fightsystem/record/FileSource.java | 0 .../fightsystem/record/GlobalRecorder.java | 0 .../fightsystem/record/LiveRecorder.java | 0 .../fightsystem/record/LiveServer.java | 0 .../fightsystem/record/LiveSource.java | 0 .../fightsystem/record/PacketProcessor.java | 36 +-- .../fightsystem/record/PacketSource.java | 0 .../steamwar/fightsystem/record/REntity.java | 11 +- .../steamwar/fightsystem/record/Recorder.java | 25 +- .../fightsystem/states/FightState.java | 0 .../fightsystem/states/IStateDependent.java | 0 .../states/OneShotStateDependent.java | 0 .../fightsystem/states/StateDependent.java | 0 .../states/StateDependentCommand.java | 0 .../states/StateDependentCountdown.java | 0 .../states/StateDependentListener.java | 0 .../states/StateDependentTask.java | 0 .../fightsystem/utils/BlockIdWrapper.java | 42 ++++ .../fightsystem/utils/BountifulWrapper.java | 43 ++++ .../fightsystem/utils/ColorConverter.java | 6 +- .../fightsystem/utils/CraftbukkitWrapper.java | 27 ++- .../fightsystem/utils/EnterHandler.java | 0 .../fightsystem/utils/FightStatistics.java | 0 .../fightsystem/utils/FlatteningWrapper.java | 53 ++++ .../fightsystem/utils/ITechHider.java | 18 +- .../fightsystem/utils/ItemBuilder.java | 0 .../de/steamwar/fightsystem/utils/Region.java | 4 +- .../steamwar/fightsystem/utils/SWSound.java | 40 ++++ .../steamwar/fightsystem/utils/TechHider.java | 42 +--- .../fightsystem/utils/WorldeditWrapper.java | 43 ++++ .../EventTeamOffWincondition.java | 0 .../winconditions/PercentWincondition.java | 0 .../winconditions/PrintableWincondition.java | 0 .../RankedPlayerLeftWincondition.java | 0 .../winconditions/Wincondition.java | 0 .../winconditions/WinconditionAllDead.java | 0 .../WinconditionCaptainDead.java | 0 .../WinconditionHeartRatioTimeout.java | 0 .../WinconditionPercentSystem.java | 0 .../WinconditionPercentTimeout.java | 0 .../winconditions/WinconditionPoints.java | 0 .../WinconditionPumpkinTechKO.java | 0 .../WinconditionRelativePercent.java | 0 .../winconditions/WinconditionTimeTechKO.java | 2 +- .../winconditions/WinconditionTimeout.java | 0 .../WinconditionWaterTechKO.java | 4 +- .../winconditions/Winconditions.java | 4 +- .../src/plugin.yml | 0 FightSystem_Main/pom.xml | 45 ++-- .../fightsystem/listener/BasicListener.java | 47 ---- pom.xml | 22 +- 168 files changed, 1554 insertions(+), 1581 deletions(-) delete mode 100644 FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java rename FightSystem_10/src/de/steamwar/fightsystem/{fight/FightWorld_10.java => utils/CraftbukkitWrapper10.java} (69%) rename FightSystem_9/src/de/steamwar/fightsystem/fight/FightTeam_9.java => FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java (78%) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java delete mode 100644 FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java rename FightSystem_12/src/de/steamwar/fightsystem/{fight/FightWorld_12.java => utils/CraftbukkitWrapper12.java} (69%) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java delete mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java rename FightSystem_12/src/de/steamwar/fightsystem/{fight/FightTeam_12.java => utils/WorldeditWrapper12.java} (75%) delete mode 100644 FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java delete mode 100644 FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java rename FightSystem_14/src/de/steamwar/fightsystem/{record/RecordSystem_14.java => utils/BlockIdWrapper14.java} (50%) rename FightSystem_14/src/de/steamwar/fightsystem/{fight/FightWorld_14.java => utils/CraftbukkitWrapper14.java} (69%) create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java rename FightSystem_14/src/de/steamwar/fightsystem/{countdown/Countdown_14.java => utils/SWSound14.java} (78%) create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java delete mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java rename FightSystem_14/src/de/steamwar/fightsystem/{fight/FightTeam_14.java => utils/WorldeditWrapper14.java} (88%) delete mode 100644 FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java rename FightSystem_15/src/de/steamwar/fightsystem/{record/RecordSystem_15.java => utils/BlockIdWrapper15.java} (50%) rename FightSystem_15/src/de/steamwar/fightsystem/{fight/FightWorld_15.java => utils/CraftbukkitWrapper15.java} (69%) delete mode 100644 FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java rename FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java => FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java (76%) rename FightSystem_API/src/de/steamwar/fightsystem/countdown/SWSound.java => FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java (79%) rename FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java => FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java (73%) rename FightSystem_8/src/de/steamwar/fightsystem/{utils/ColorConverter_8.java => listener/DenyWorldInteraction8.java} (74%) delete mode 100644 FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java rename FightSystem_8/src/de/steamwar/fightsystem/utils/{TechHider_8.java => BlockIdWrapper8.java} (63%) create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java rename FightSystem_8/src/de/steamwar/fightsystem/{fight/FightWorld_8.java => utils/CraftbukkitWrapper8.java} (70%) create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java rename FightSystem_8/src/de/steamwar/fightsystem/{countdown/Countdown_8.java => utils/SWSound8.java} (79%) rename FightSystem_8/src/de/steamwar/fightsystem/{record/RecordSystem_8.java => utils/TechHider8.java} (58%) rename FightSystem_8/src/de/steamwar/fightsystem/{fight/FightTeam_8.java => utils/WorldeditWrapper8.java} (86%) rename FightSystem_9/src/de/steamwar/fightsystem/listener/{PickupArrowListener_9.java => ArrowPickup9.java} (95%) rename FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java => FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java (90%) delete mode 100644 FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java rename FightSystem_9/src/de/steamwar/fightsystem/{listener/BasicListener_9.java => utils/BountifulWrapper9.java} (55%) rename FightSystem_9/src/de/steamwar/fightsystem/{fight/FightWorld_9.java => utils/CraftbukkitWrapper9.java} (69%) rename FightSystem_9/src/de/steamwar/fightsystem/{countdown/Countdown_9.java => utils/SWSound9.java} (78%) delete mode 100644 FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java delete mode 100644 FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java rename {FightSystem_API => FightSystem_Core}/pom.xml (60%) rename {FightSystem_Main => FightSystem_Core}/src/config.yml (100%) rename {FightSystem_API => FightSystem_Core}/src/de/steamwar/fightsystem/ArenaMode.java (98%) rename {FightSystem_API => FightSystem_Core}/src/de/steamwar/fightsystem/Config.java (97%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/FightSystem.java (95%) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/VersionDependent.java rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/AcceptCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/AkCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/CommandInjector.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/Commands.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/DeclineCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/GUI.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/GamemodeCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/InviteCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/KitCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/LeaderCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/LeaveCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/LockschemCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/ReadyCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/RemoveCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/ReplayCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/SkipCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/StateCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/commands/WinCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/Countdown.java (87%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/EnternCountdown.java (89%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java (97%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java (97%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java (97%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java (96%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java (96%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/event/HellsBells.java (99%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/Fight.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/FightPlayer.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/FightSchematic.java (66%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/FightTeam.java (95%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/FightWorld.java (65%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/FreezeWorld.java (95%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/fight/Kit.java (92%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/ArenaBorder.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/ArrowPickup.java (85%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/ArrowStopper.java (91%) rename FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java => FightSystem_Core/src/de/steamwar/fightsystem/listener/BasicListener.java (69%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/Chat.java (96%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/Check.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java (91%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/EntityDamage.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/EventJoin.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/FightScoreboard.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/HotbarGUI.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/InFightDamage.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/InFightInventory.java (93%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/IngameDeath.java (93%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/NormalJoin.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/Permanent.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/PistonListener.java (98%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/PrepareSchem.java (83%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/RankedJoin.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/Recording.java (90%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/ResourcePack.java (60%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/SetupQuit.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/Shutdown.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/TeamArea.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/TestJoin.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/listener/WaterRemover.java (82%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/FileRecorder.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/FileSource.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/GlobalRecorder.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/LiveRecorder.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/LiveServer.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/LiveSource.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/PacketProcessor.java (93%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/PacketSource.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/REntity.java (97%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/record/Recorder.java (90%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/FightState.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/IStateDependent.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/OneShotStateDependent.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/StateDependent.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/StateDependentCommand.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/StateDependentCountdown.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/StateDependentListener.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/states/StateDependentTask.java (100%) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/utils/ColorConverter.java (86%) rename FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java => FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java (53%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/utils/EnterHandler.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/utils/FightStatistics.java (100%) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java rename {FightSystem_API => FightSystem_Core}/src/de/steamwar/fightsystem/utils/ITechHider.java (90%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/utils/ItemBuilder.java (100%) rename {FightSystem_API => FightSystem_Core}/src/de/steamwar/fightsystem/utils/Region.java (98%) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/SWSound.java rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/utils/TechHider.java (84%) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/Wincondition.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java (98%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java (100%) rename {FightSystem_Main => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java (95%) rename {FightSystem_API => FightSystem_Core}/src/de/steamwar/fightsystem/winconditions/Winconditions.java (95%) rename {FightSystem_Main => FightSystem_Core}/src/plugin.yml (100%) delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java diff --git a/FightSystem_10/pom.xml b/FightSystem_10/pom.xml index 66633c1..3e87409 100644 --- a/FightSystem_10/pom.xml +++ b/FightSystem_10/pom.xml @@ -17,28 +17,10 @@ FightSystem_10 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar - FightSystem_9 - 1.0 - - - steamwar - FightSystem_API + FightSystem_Core 1.0 diff --git a/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java b/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java deleted file mode 100644 index d02d944..0000000 --- a/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - 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.listener; - -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -import java.util.HashSet; -import java.util.Set; - -public class PersonalKitCreator_10 { - - public static boolean hasItems(ItemStack stack){ - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } -} diff --git a/FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java similarity index 69% rename from FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java rename to FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java index 849b070..3e20fe9 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java +++ b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,24 +15,29 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.fight.FightWorld; import net.minecraft.server.v1_10_R1.Chunk; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -public class FightWorld_10 { - private FightWorld_10(){} +import java.util.HashSet; +import java.util.Set; - static void resetChunk(World world, World backup, int x, int z, boolean isPaper){ +public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrapper { + @Override + public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_10_R1.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); @@ -40,7 +45,7 @@ public class FightWorld_10 { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!isPaper) { + if (!FightWorld.isPaper()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); @@ -50,11 +55,21 @@ public class FightWorld_10 { } } - public static void sendResourcePack(Player player, String pack, String sha1){ + @Override + public void sendResourcePack(Player player, String pack, String sha1) { ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); } - public static float headRotation(Entity e){ + @Override + public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } } diff --git a/FightSystem_12/pom.xml b/FightSystem_12/pom.xml index 0c0bcba..e5c8537 100644 --- a/FightSystem_12/pom.xml +++ b/FightSystem_12/pom.xml @@ -17,28 +17,15 @@ FightSystem_12 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar - FightSystem_10 + FightSystem_8 1.0 steamwar - FightSystem_API + FightSystem_Core 1.0 diff --git a/FightSystem_9/src/de/steamwar/fightsystem/fight/FightTeam_9.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java similarity index 78% rename from FightSystem_9/src/de/steamwar/fightsystem/fight/FightTeam_9.java rename to FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java index 51c04ce..7f24260 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/fight/FightTeam_9.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java @@ -22,11 +22,10 @@ package de.steamwar.fightsystem.fight; import org.bukkit.ChatColor; import org.bukkit.scoreboard.Team; -class FightTeam_9 { - private FightTeam_9(){} +public class FightTeam12 implements FightTeam.IFightTeam { - static void setTeamColor(Team team, ChatColor color){ - FightTeam_8.setTeamColor(team, color); - team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + @Override + public void setTeamColor(Team team, ChatColor color){ + team.setColor(color); } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java b/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java new file mode 100644 index 0000000..08b42cc --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java @@ -0,0 +1,30 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.listener; + +import org.bukkit.entity.Arrow; + +public class ArrowStopper12 implements ArrowStopper.IArrowStopper { + + @Override + public boolean isInBlock(Arrow e) { + return e.isInBlock(); + } +} diff --git a/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java b/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java deleted file mode 100644 index a76bdc8..0000000 --- a/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - 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.listener; - -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -import java.util.HashSet; -import java.util.Set; - -public class PersonalKitCreator_12 { - - public static boolean hasItems(ItemStack stack){ - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } -} \ No newline at end of file diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java similarity index 69% rename from FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java rename to FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java index be3596e..1c03c20 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,24 +15,29 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.fight.FightWorld; import net.minecraft.server.v1_12_R1.Chunk; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -public class FightWorld_12 { - private FightWorld_12(){} +import java.util.HashSet; +import java.util.Set; - static void resetChunk(World world, World backup, int x, int z, boolean isPaper){ +public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrapper { + @Override + public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_12_R1.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); @@ -40,7 +45,7 @@ public class FightWorld_12 { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!isPaper) { + if (!FightWorld.isPaper()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); @@ -50,11 +55,21 @@ public class FightWorld_12 { } } - public static void sendResourcePack(Player player, String pack, String sha1){ + @Override + public void sendResourcePack(Player player, String pack, String sha1) { ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); } - public static float headRotation(Entity e){ + @Override + public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java new file mode 100644 index 0000000..3f4ec39 --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java @@ -0,0 +1,124 @@ +/* + 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.utils; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.nbt.NbtBase; +import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.Set; +import java.util.logging.Level; + +import static de.steamwar.fightsystem.utils.ITechHider.bypass; + +public class TechHider12 extends PacketAdapter { + + private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); + private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); + + public TechHider12() { + super(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK); + } + + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + StructureModifier ints = packet.getIntegers(); + + int chunkX = ints.read(0); + int chunkZ = ints.read(1); + Player p = e.getPlayer(); + if(bypass(p, chunkX, chunkZ)) + return; + + packet = packet.shallowClone(); + e.setPacket(packet); + StructureModifier>> list = packet.getListNbtModifier(); + List> nmsTags = list.read(0); + boolean changed = false; + for(int i = nmsTags.size() - 1; i >= 0; i--){ + NbtCompound nbt = (NbtCompound)nmsTags.get(i); + if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ + nmsTags.remove(i); + changed = true; + } + } + if(changed) + list.write(0, nmsTags); + + changed = false; + StructureModifier byteArray = packet.getByteArrays(); + byte [] data = byteArray.read(0); + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); + int i = 0; + + while(i < data.length){ + byte bitsPerBlock = data[i++]; + buffer.writeByte(bitsPerBlock); + + if(bitsPerBlock != 13){ + int paletteLength = ITechHider.readVarInt(data, i); + int paletteLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, paletteLengthLength); + i += paletteLengthLength; + + for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ + int entry = ITechHider.readVarInt(data, i); + i += ITechHider.readVarIntLength(data, i); + + if(hiddenBlockIds.contains(entry)){ + entry = obfuscateWith; + changed = true; + } + buffer.writeBytes(ITechHider.writeVarInt(entry)); + } + }else{ + buffer.writeByte(data[++i]); //Empty palette + Bukkit.getLogger().log(Level.SEVERE, "Full chunk occured"); + } + + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + + buffer.writeBytes(data, i, 4096); + i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048 + } + + if(changed){ + data = new byte[buffer.readableBytes()]; + buffer.readBytes(data); + byteArray.write(0, data); + } + } +} diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java deleted file mode 100644 index 4286cd5..0000000 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - 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.utils; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.StructureModifier; -import com.comphenix.protocol.wrappers.nbt.NbtBase; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.IFightSystem; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.Set; -import java.util.logging.Level; - -import static de.steamwar.fightsystem.utils.ITechHider.bypass; - -class TechHider_12 { - private TechHider_12(){} - - static PacketAdapter chunkHider(Set hiddenBlockIds, int obfuscateWith){ - return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - StructureModifier ints = packet.getIntegers(); - - int chunkX = ints.read(0); - int chunkZ = ints.read(1); - Player p = e.getPlayer(); - if(bypass(p, chunkX, chunkZ)) - return; - - packet = packet.shallowClone(); - e.setPacket(packet); - StructureModifier>> list = packet.getListNbtModifier(); - List> nmsTags = list.read(0); - boolean changed = false; - for(int i = nmsTags.size() - 1; i >= 0; i--){ - NbtCompound nbt = (NbtCompound)nmsTags.get(i); - if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ - nmsTags.remove(i); - changed = true; - } - } - if(changed) - list.write(0, nmsTags); - - changed = false; - StructureModifier byteArray = packet.getByteArrays(); - byte [] data = byteArray.read(0); - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - while(i < data.length){ - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - - if(bitsPerBlock != 13){ - int paletteLength = ITechHider.readVarInt(data, i); - int paletteLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int entry = ITechHider.readVarInt(data, i); - i += ITechHider.readVarIntLength(data, i); - - if(hiddenBlockIds.contains(entry)){ - entry = obfuscateWith; - changed = true; - } - buffer.writeBytes(ITechHider.writeVarInt(entry)); - } - }else{ - buffer.writeByte(data[++i]); //Empty palette - Bukkit.getLogger().log(Level.SEVERE, "Full chunk 1.12 occured"); - } - - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); - i += dataArrayLengthLength; - i += dataArrayLength * 8; - - buffer.writeBytes(data, i, 4096); - i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048 - } - - if(changed){ - data = new byte[buffer.readableBytes()]; - buffer.readBytes(data); - byteArray.write(0, data); - } - } - }; - } -} diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java similarity index 75% rename from FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java rename to FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java index 0f3b5c6..25be503 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,24 +15,18 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; -import org.bukkit.scoreboard.Team; -import java.util.Collections; -import java.util.Set; - -class FightTeam_12 { - private FightTeam_12(){} +public class WorldeditWrapper12 extends WorldeditWrapper8 { @SuppressWarnings("deprecation") private static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData(); @@ -42,16 +36,10 @@ class FightTeam_12 { @SuppressWarnings("deprecation") private static final BaseBlock CONCRETE_POWDER = new BaseBlock(Material.CONCRETE_POWDER.getId(), COLOR_TO_REPLACE); - private static final Set CONCRETE_SET = Collections.singleton(CONCRETE); - private static final Set CONCRETE_POWDER_SET = Collections.singleton(CONCRETE_POWDER); - - static void setTeamColor(Team team, ChatColor color){ - team.setColor(color); - team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); - } - - static void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { - FightTeam_8.replaceTeamColor(clipboard, c); + @SuppressWarnings("deprecation") + @Override + public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { + super.replaceTeamColor(clipboard, c); Vector minimum = clipboard.getRegion().getMinimumPoint(); BaseBlock concrete = new BaseBlock(CONCRETE.getId(), c.getWoolData()); diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml index 3d7c934..ad025b7 100644 --- a/FightSystem_14/pom.xml +++ b/FightSystem_14/pom.xml @@ -17,19 +17,6 @@ FightSystem_14 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar @@ -47,12 +34,7 @@ steamwar - FightSystem_API - 1.0 - - - steamwar - FightSystem_12 + FightSystem_Core 1.0 diff --git a/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java b/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java deleted file mode 100644 index 74b3b44..0000000 --- a/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - 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.listener; - -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class PersonalKitCreator_14 { - private PersonalKitCreator_14(){} - - public static boolean hasAttributeModifier(ItemStack stack){ - return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers(); - } - - public static boolean hasItems(ItemStack stack){ - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } -} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java b/FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java deleted file mode 100644 index 3b03787..0000000 --- a/FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - 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.listener; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Waterlogged; - -class WaterRemover_14 { - private WaterRemover_14(){} - - static boolean isWater(Block block){ - if(block.getType() == Material.WATER) - return true; - - BlockData data = block.getBlockData(); - if(!(data instanceof Waterlogged)) - return false; - - return ((Waterlogged) data).isWaterlogged(); - } - - static boolean removeWater(Block block){ - if(block.getType() == Material.WATER){ - block.setType(Material.AIR); - return true; - } - - BlockData data = block.getBlockData(); - if(!(data instanceof Waterlogged)) - return false; - - Waterlogged waterlogged = (Waterlogged) data; - if(waterlogged.isWaterlogged()){ - block.setType(Material.AIR); - return true; - } - - return false; - } -} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java similarity index 50% rename from FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java rename to FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 5e65cb4..78101c3 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/record/RecordSystem_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,33 +15,29 @@ 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; +package de.steamwar.fightsystem.utils; -import net.minecraft.server.v1_14_R1.BlockPosition; -import net.minecraft.server.v1_14_R1.EntityPose; -import net.minecraft.server.v1_14_R1.IBlockData; -import net.minecraft.server.v1_14_R1.WorldServer; +import de.steamwar.fightsystem.Config; +import net.minecraft.server.v1_14_R1.*; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; -public class RecordSystem_14 { - private RecordSystem_14(){} - - static int blockToId(Block block){ +public class BlockIdWrapper14 implements BlockIdWrapper.IBlockIdWrapper { + @Override + public int blockToId(Block block) { return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); } - static Object getPose(boolean sneaking){ - return sneaking ? EntityPose.SNEAKING : EntityPose.STANDING; - } - - static void setBlock(World world, int x, int y, int z, int blockState){ + @Override + public void setBlock(World world, int x, int y, int z, int blockState) { IBlockData blockData = Objects.requireNonNull(net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.fromId(blockState)); WorldServer cworld = ((CraftWorld)world).getHandle(); BlockPosition pos = new BlockPosition(x, y, z); @@ -49,4 +45,35 @@ public class RecordSystem_14 { cworld.setTypeAndData(pos, blockData, 1042); cworld.getChunkProvider().flagDirty(pos); } + + @Override + public Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ + hiddenBlockIds.add(net.minecraft.server.v1_14_R1.Block.getCombinedId(data)); + } + } + + if(Config.HiddenBlocks.contains("water")){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : net.minecraft.server.v1_14_R1.Block.REGISTRY_ID){ + if(data.p() == water){ + hiddenBlockIds.add(net.minecraft.server.v1_14_R1.Block.getCombinedId(data)); + } + } + } + + return hiddenBlockIds; + } + + @Override + public int getObfuscateWith() { + return net.minecraft.server.v1_14_R1.Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); + } + + @Override + public Object getPose(boolean sneaking) { + return sneaking ? EntityPose.SNEAKING : EntityPose.STANDING; + } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java similarity index 69% rename from FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java rename to FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java index f2b9412..14c5989 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,31 +15,36 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.fight.FightWorld; import net.minecraft.server.v1_14_R1.Chunk; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -public class FightWorld_14 { - private FightWorld_14(){} +import java.util.HashSet; +import java.util.Set; - static void resetChunk(World world, World backup, int x, int z, boolean isPaper){ +public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrapper { + @Override + public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_14_R1.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!isPaper) { + if (!FightWorld.isPaper()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); @@ -51,11 +56,21 @@ public class FightWorld_14 { } } - public static void sendResourcePack(Player player, String pack, String sha1){ + @Override + public void sendResourcePack(Player player, String pack, String sha1) { ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); } - public static float headRotation(Entity e){ + @Override + public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java new file mode 100644 index 0000000..dc3ed90 --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java @@ -0,0 +1,111 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BlockDataMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Objects; + +public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper { + @Override + public DyeColor getSilver() { + return DyeColor.LIGHT_GRAY; + } + + @Override + public boolean isWater(Block block) { + if(block.getType() == Material.WATER) + return true; + + BlockData data = block.getBlockData(); + if(!(data instanceof Waterlogged)) + return false; + + return ((Waterlogged) data).isWaterlogged(); + } + + @Override + public boolean removeWater(Block block) { + if(block.getType() == Material.WATER){ + block.setType(Material.AIR); + return true; + } + + BlockData data = block.getBlockData(); + if(!(data instanceof Waterlogged)) + return false; + + Waterlogged waterlogged = (Waterlogged) data; + if(waterlogged.isWaterlogged()){ + block.setType(Material.AIR); + return true; + } + + return false; + } + + @Override + public boolean containsBlockMeta(ItemMeta meta) { + return meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData(); + } + + @Override + public boolean hasAttributeModifier(ItemStack stack) { + return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers(); + } + + @Override + public Material onBreak(Material type) { + switch(type){ + case REDSTONE_WIRE: + return Material.REDSTONE; + case PISTON_HEAD: + return Material.PISTON; + case ICE: + return Material.AIR; + default: + return type; + } + } + + @Override + public boolean doRecord(BlockPhysicsEvent e) { + return e.getBlock() == e.getSourceBlock() || e.getChangedType() == Material.AIR; + } + + @Override + public void forceLoadChunk(World world, int cX, int cZ) { + world.setChunkForceLoaded(cX, cZ, true); + } + + @Override + public boolean checkPistonMoving(Block block) { + return block.getType() == Material.MOVING_PISTON; + } +} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/countdown/Countdown_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/SWSound14.java similarity index 78% rename from FightSystem_14/src/de/steamwar/fightsystem/countdown/Countdown_14.java rename to FightSystem_14/src/de/steamwar/fightsystem/utils/SWSound14.java index 0195bdc..77fde1d 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/countdown/Countdown_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/SWSound14.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,16 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.countdown; +package de.steamwar.fightsystem.utils; import org.bukkit.Sound; -class Countdown_14 { - private Countdown_14(){} - - static Sound getSound(SWSound sound){ +public class SWSound14 implements SWSound.ISWSound { + @Override + public Sound getSound(SWSound sound) { switch(sound){ case ENTITY_WITHER_DEATH: return Sound.ENTITY_WITHER_DEATH; @@ -32,6 +31,8 @@ class Countdown_14 { return Sound.BLOCK_NOTE_BLOCK_BASS; case BLOCK_NOTE_PLING: return Sound.BLOCK_NOTE_BLOCK_PLING; + case ENTITY_GENERIC_EXPLODE: + return Sound.ENTITY_GENERIC_EXPLODE; default: return null; } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java new file mode 100644 index 0000000..8f6cff3 --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java @@ -0,0 +1,199 @@ +/* + 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.utils; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.nbt.NbtBase; +import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import org.bukkit.entity.Player; + +import java.nio.ByteBuffer; +import java.nio.LongBuffer; +import java.util.List; +import java.util.Set; + +import static de.steamwar.fightsystem.utils.ITechHider.bypass; + +public class TechHider14 extends PacketAdapter { + + private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); + private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); + + public TechHider14(){ + super(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK); + } + + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + StructureModifier ints = packet.getIntegers(); + + int chunkX = ints.read(0); + int chunkZ = ints.read(1); + Player p = e.getPlayer(); + if(bypass(p, chunkX, chunkZ)) + return; + + packet = packet.shallowClone(); + e.setPacket(packet); + StructureModifier>> list = packet.getListNbtModifier(); + List> nmsTags = list.read(0); + boolean changed = false; + for(int i = nmsTags.size() - 1; i >= 0; i--){ + NbtBase nbtBase = nmsTags.get(i); + assert nbtBase instanceof NbtCompound; + NbtCompound nbt = (NbtCompound) nbtBase; + if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ + nmsTags.remove(i); + changed = true; + } + } + if(changed){ + list.write(0, nmsTags); + } + + changed = false; + StructureModifier byteArray = packet.getByteArrays(); + int primaryBitMask = ints.read(2); + byte[] data = byteArray.read(0); + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); + int i = 0; + + //int chunkY = 0; + while(primaryBitMask != 0){ + while((primaryBitMask & 1) == 0){ + primaryBitMask >>= 1; + //chunkY++; + } + + buffer.writeBytes(data, i, 2); // Block count + i += 2; + byte bitsPerBlock = data[i++]; + buffer.writeByte(bitsPerBlock); + + if(bitsPerBlock < 9){ + int paletteLength = ITechHider.readVarInt(data, i); + int paletteLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, paletteLengthLength); + i += paletteLengthLength; + for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ + int blockId = ITechHider.readVarInt(data, i); + int actPaletteLength = ITechHider.readVarIntLength(data, i); + + if(hiddenBlockIds.contains(blockId)){ + buffer.writeBytes(ITechHider.writeVarInt(obfuscateWith)); + changed = true; + }else{ + buffer.writeBytes(data, i, actPaletteLength); + } + i += actPaletteLength; + } + + //We modify only the chunk palette for performance reasons + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + }else{ + //Full Chunk/no palette, so the chunk has to be crawled through + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLengthLength); + i += dataArrayLengthLength; + + ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8); + VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); + + for(int pos = 0; pos < 4096; pos++){ + if(hiddenBlockIds.contains(values.get(pos))){ + changed = true; + values.set(pos, obfuscateWith); + } + } + + for(long l : values.backing) + buffer.writeLong(l); + + i += dataArrayLength * 8; + } + + primaryBitMask >>= 1; + //chunkY++; + } + buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why + + if(changed){ + data = new byte[buffer.readableBytes()]; + buffer.readBytes(data); + byteArray.write(0, data); + } + } + + private static final class VariableValueArray { + private final long[] backing; + private final int bitsPerValue; + private final long valueMask; + + public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) { + this.bitsPerValue = bitsPerEntry; + this.backing = new long[dataArrayLength]; + buffer.get(backing); + this.valueMask = (1L << this.bitsPerValue) - 1; + } + + public int get(int index) { + index *= bitsPerValue; + int i0 = index >> 6; + int i1 = index & 0x3f; + + long value = backing[i0] >>> i1; + + // The value is divided over two long values + if (i1 + bitsPerValue > 64) { + value |= backing[++i0] << 64 - i1; + } + + return (int) (value & valueMask); + } + + public void set(int index, int value) { + index *= bitsPerValue; + int i0 = index >> 6; + int i1 = index & 0x3f; + + backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; + int i2 = i1 + bitsPerValue; + // The value is divided over two long values + if (i2 > 64) { + i0++; + backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1; + } + } + } +} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java deleted file mode 100644 index 39546ec..0000000 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - 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.utils; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.StructureModifier; -import com.comphenix.protocol.wrappers.nbt.NbtBase; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.IFightSystem; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.entity.Player; - -import java.nio.ByteBuffer; -import java.nio.LongBuffer; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static de.steamwar.fightsystem.utils.ITechHider.bypass; - -public class TechHider_14 { - private TechHider_14(){} - - static Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ - hiddenBlockIds.add(Block.getCombinedId(data)); - } - } - - if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : Block.REGISTRY_ID){ - if(data.p() == water){ - hiddenBlockIds.add(Block.getCombinedId(data)); - } - } - } - - return hiddenBlockIds; - } - - static int getObfuscateWith() { - return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); - } - - static PacketAdapter chunkHider(Set hiddenBlockIds, int obfuscateWith){ - /* - * Bevor editing this function read and understand: https://wiki.vg/Chunk_Format - * */ - return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - StructureModifier ints = packet.getIntegers(); - - int chunkX = ints.read(0); - int chunkZ = ints.read(1); - Player p = e.getPlayer(); - if(bypass(p, chunkX, chunkZ)) - return; - - packet = packet.shallowClone(); - e.setPacket(packet); - StructureModifier>> list = packet.getListNbtModifier(); - List> nmsTags = list.read(0); - boolean changed = false; - for(int i = nmsTags.size() - 1; i >= 0; i--){ - NbtBase nbtBase = nmsTags.get(i); - assert nbtBase instanceof NbtCompound; - NbtCompound nbt = (NbtCompound) nbtBase; - if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ - nmsTags.remove(i); - changed = true; - } - } - if(changed){ - list.write(0, nmsTags); - } - - changed = false; - StructureModifier byteArray = packet.getByteArrays(); - int primaryBitMask = ints.read(2); - byte[] data = byteArray.read(0); - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - int chunkY = 0; - while(primaryBitMask != 0){ - while((primaryBitMask & 1) == 0){ - primaryBitMask >>= 1; - chunkY++; - } - - buffer.writeBytes(data, i, 2); // Block count - i += 2; - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - - if(bitsPerBlock < 9){ - int paletteLength = ITechHider.readVarInt(data, i); - int paletteLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int blockId = ITechHider.readVarInt(data, i); - int actPaletteLength = ITechHider.readVarIntLength(data, i); - - if(hiddenBlockIds.contains(blockId)){ - buffer.writeBytes(ITechHider.writeVarInt(obfuscateWith)); - changed = true; - }else{ - buffer.writeBytes(data, i, actPaletteLength); - } - i += actPaletteLength; - } - - //We modify only the chunk palette for performance reasons - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); - i += dataArrayLengthLength; - i += dataArrayLength * 8; - }else{ - //Full Chunk/no palette, so the chunk has to be crawled through - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLengthLength); - i += dataArrayLengthLength; - - ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8); - VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); - - for(int pos = 0; pos < 4096; pos++){ - if(hiddenBlockIds.contains(values.get(pos))){ - changed = true; - values.set(pos, obfuscateWith); - } - } - - for(long l : values.backing) - buffer.writeLong(l); - - i += dataArrayLength * 8; - } - - primaryBitMask >>= 1; - chunkY++; - } - buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why - - if(changed){ - data = new byte[buffer.readableBytes()]; - buffer.readBytes(data); - byteArray.write(0, data); - } - } - }; - } - - private static final class VariableValueArray { - private final long[] backing; - private final int bitsPerValue; - private final long valueMask; - - public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) { - this.bitsPerValue = bitsPerEntry; - this.backing = new long[dataArrayLength]; - buffer.get(backing); - this.valueMask = (1L << this.bitsPerValue) - 1; - } - - public int get(int index) { - index *= bitsPerValue; - int i0 = index >> 6; - int i1 = index & 0x3f; - - long value = backing[i0] >>> i1; - - // The value is divided over two long values - if (i1 + bitsPerValue > 64) { - value |= backing[++i0] << 64 - i1; - } - - return (int) (value & valueMask); - } - - public void set(int index, int value) { - index *= bitsPerValue; - int i0 = index >> 6; - int i1 = index & 0x3f; - - backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; - int i2 = i1 + bitsPerValue; - // The value is divided over two long values - if (i2 > 64) { - i0++; - backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1; - } - } - } -} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java similarity index 88% rename from FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java rename to FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 38b0170..aa19d25 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,9 +15,9 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; @@ -39,21 +39,19 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.utils.Region; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.DyeColor; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.scoreboard.Team; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.util.Objects; +import java.util.zip.GZIPInputStream; -public class FightTeam_14 { - private FightTeam_14(){} +public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); @@ -63,12 +61,8 @@ public class FightTeam_14 { private static final BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(); private static final BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(); - static void setTeamColor(Team team, ChatColor color){ - team.setColor(color); - team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); - } - - static void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { + @Override + public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); BaseBlock wool = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock(); BaseBlock clay = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock(); @@ -103,7 +97,8 @@ public class FightTeam_14 { } } - static void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { + @Override + public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); World w = new BukkitWorld(Bukkit.getWorlds().get(0)); @@ -135,7 +130,8 @@ public class FightTeam_14 { e.flushSession(); } - static void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){ + @Override + public void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT) { BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); v = aT.apply(v.toVector3()).toBlockPoint(); @@ -148,15 +144,13 @@ public class FightTeam_14 { e.flushSession(); } - static Clipboard loadSchem(NBTInputStream stream) throws IOException { - return new SpongeSchematicReader(stream).read(); + @Override + public Clipboard loadChar(String charName) throws IOException { + return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schem"))))).read(); } - public static boolean checkPistonMoving(Block block){ - return block.getType() == Material.MOVING_PISTON; - } - - public static void saveSchem(Schematic schem, Region region, int minY) { + @Override + public void saveSchem(Schematic schem, Region region, int minY) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); BlockVector3 min = BlockVector3.at(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ())); diff --git a/FightSystem_15/pom.xml b/FightSystem_15/pom.xml index 8858c54..7aa938d 100644 --- a/FightSystem_15/pom.xml +++ b/FightSystem_15/pom.xml @@ -17,19 +17,6 @@ FightSystem_15 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar @@ -47,12 +34,7 @@ steamwar - FightSystem_API - 1.0 - - - steamwar - FightSystem_14 + FightSystem_Core 1.0 diff --git a/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java b/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java deleted file mode 100644 index eec0197..0000000 --- a/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - 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.listener; - -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -import java.util.HashSet; -import java.util.Set; - -public class PersonalKitCreator_15 { - - public static boolean hasItems(ItemStack stack){ - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } -} diff --git a/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java similarity index 50% rename from FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java rename to FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java index db63363..c88034f 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,33 +15,29 @@ 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; +package de.steamwar.fightsystem.utils; -import net.minecraft.server.v1_15_R1.BlockPosition; -import net.minecraft.server.v1_15_R1.EntityPose; -import net.minecraft.server.v1_15_R1.IBlockData; -import net.minecraft.server.v1_15_R1.WorldServer; +import de.steamwar.fightsystem.Config; +import net.minecraft.server.v1_15_R1.*; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; -class RecordSystem_15 { - private RecordSystem_15(){} - - static int blockToId(Block block){ +public class BlockIdWrapper15 implements BlockIdWrapper.IBlockIdWrapper { + @Override + public int blockToId(Block block) { return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); } - static Object getPose(boolean sneaking){ - return sneaking ? EntityPose.CROUCHING : EntityPose.STANDING; - } - - static void setBlock(World world, int x, int y, int z, int blockState){ + @Override + public void setBlock(World world, int x, int y, int z, int blockState) { IBlockData blockData = Objects.requireNonNull(net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.fromId(blockState)); WorldServer cworld = ((CraftWorld)world).getHandle(); BlockPosition pos = new BlockPosition(x, y, z); @@ -49,4 +45,35 @@ class RecordSystem_15 { cworld.setTypeAndData(pos, blockData, 1042); cworld.getChunkProvider().flagDirty(pos); } + + @Override + public Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ + hiddenBlockIds.add(net.minecraft.server.v1_15_R1.Block.getCombinedId(data)); + } + } + + if(Config.HiddenBlocks.contains("water")){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : net.minecraft.server.v1_15_R1.Block.REGISTRY_ID){ + if(data.getFluid() == water){ + hiddenBlockIds.add(net.minecraft.server.v1_15_R1.Block.getCombinedId(data)); + } + } + } + + return hiddenBlockIds; + } + + @Override + public int getObfuscateWith() { + return net.minecraft.server.v1_15_R1.Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); + } + + @Override + public Object getPose(boolean sneaking) { + return sneaking ? EntityPose.CROUCHING : EntityPose.STANDING; + } } diff --git a/FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java similarity index 69% rename from FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java rename to FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java index b4c53b8..8d55c47 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,31 +15,36 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.fight.FightWorld; import net.minecraft.server.v1_15_R1.Chunk; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -public class FightWorld_15 { - private FightWorld_15(){} +import java.util.HashSet; +import java.util.Set; - static void resetChunk(World world, World backup, int x, int z, boolean isPaper){ +public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrapper { + @Override + public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_15_R1.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!isPaper) { + if (!FightWorld.isPaper()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); @@ -51,11 +56,21 @@ public class FightWorld_15 { } } - public static void sendResourcePack(Player player, String pack, String sha1){ + @Override + public void sendResourcePack(Player player, String pack, String sha1) { ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); } - public static float headRotation(Entity e){ + @Override + public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } } diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java deleted file mode 100644 index e5d5e03..0000000 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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.utils; - -import de.steamwar.fightsystem.Config; -import net.minecraft.server.v1_15_R1.*; - -import java.util.HashSet; -import java.util.Set; - -class TechHider_15 { - private TechHider_15(){} - - static Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ - hiddenBlockIds.add(Block.getCombinedId(data)); - } - } - - if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : Block.REGISTRY_ID){ - if(data.getFluid() == water){ - hiddenBlockIds.add(Block.getCombinedId(data)); - } - } - } - - return hiddenBlockIds; - } - - static int getObfuscateWith() { - return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); - } -} diff --git a/FightSystem_8/pom.xml b/FightSystem_8/pom.xml index 2fabd6f..3ec6b70 100644 --- a/FightSystem_8/pom.xml +++ b/FightSystem_8/pom.xml @@ -17,19 +17,6 @@ FightSystem_8 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar @@ -40,7 +27,7 @@ steamwar - FightSystem_API + FightSystem_Core 1.0 diff --git a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java similarity index 76% rename from FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java rename to FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java index 919fa23..de213b8 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java @@ -19,11 +19,14 @@ package de.steamwar.fightsystem.fight; -import org.bukkit.entity.Player; +import org.bukkit.ChatColor; +import org.bukkit.scoreboard.Team; -public interface IFightTeam { +public class FightTeam8 implements FightTeam.IFightTeam { + + @Override + public void setTeamColor(Team team, ChatColor color){ + team.setPrefix("§" + color.getChar()); + } - boolean isBlue(); - boolean isPlayerInTeam(Player player); - boolean canPlayerEntern(Player player); } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/countdown/SWSound.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java similarity index 79% rename from FightSystem_API/src/de/steamwar/fightsystem/countdown/SWSound.java rename to FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java index 46cd3f8..f5a9c7e 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/countdown/SWSound.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,12 +15,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.countdown; +package de.steamwar.fightsystem.listener; -public enum SWSound { - ENTITY_WITHER_DEATH, - BLOCK_NOTE_PLING, - BLOCK_NOTE_BASS +import org.bukkit.event.Listener; + +public class ArrowPickup8 implements Listener { } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java similarity index 73% rename from FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java rename to FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java index af749e0..1c1c96c 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/ColorConverter_14.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,16 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; -import org.bukkit.DyeColor; +import org.bukkit.entity.Arrow; -class ColorConverter_14 { - private ColorConverter_14(){} - - static DyeColor getSilver(){ - return DyeColor.LIGHT_GRAY; +public class ArrowStopper8 implements ArrowStopper.IArrowStopper { + @Override + public boolean isInBlock(Arrow e) { + return false; } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/ColorConverter_8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java similarity index 74% rename from FightSystem_8/src/de/steamwar/fightsystem/utils/ColorConverter_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java index 3255431..db0b29c 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/ColorConverter_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,16 +15,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; -import org.bukkit.DyeColor; +import org.bukkit.event.Listener; -class ColorConverter_8 { - private ColorConverter_8(){} - - static DyeColor getSilver(){ - return DyeColor.SILVER; - } +public class DenyWorldInteraction8 implements Listener { } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java deleted file mode 100644 index 4f7bab9..0000000 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - 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.listener; - -import org.bukkit.Material; -import org.bukkit.block.Block; - -public class WaterRemover_8 { - private WaterRemover_8(){} - - static boolean isWater(Block block){ - Material type = block.getType(); - return type == Material.WATER || type == Material.STATIONARY_WATER; - } - - static boolean removeWater(Block block){ - if(isWater(block)){ - block.setType(Material.AIR); - return true; - } - return false; - } -} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java similarity index 63% rename from FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index ccf7943..723e2f0 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,20 +15,31 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; import java.util.HashSet; import java.util.Set; -class TechHider_8 { - private TechHider_8(){} +public class BlockIdWrapper8 implements BlockIdWrapper.IBlockIdWrapper { + @Override + public int blockToId(Block block) { + return block.getTypeId() << 4 + block.getData(); + } - static Set getHiddenBlockIds() { + @Override + public void setBlock(World world, int x, int y, int z, int blockState) { + world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); + } + + @Override + public Set getHiddenBlockIds() { Set hiddenBlockIds = new HashSet<>(); for(String tag : Config.HiddenBlocks){ hiddenBlockIds.add(Material.matchMaterial(tag).getId() << 4); @@ -36,7 +47,13 @@ class TechHider_8 { return hiddenBlockIds; } - static int getObfuscateWith() { + @Override + public int getObfuscateWith() { return Material.matchMaterial(Config.ObfuscateWith).getId() << 4; } + + @Override + public Object getPose(boolean sneaking) { + return null; + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java new file mode 100644 index 0000000..6d9c805 --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -0,0 +1,58 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import com.comphenix.protocol.wrappers.EnumWrappers; +import net.md_5.bungee.api.chat.BaseComponent; +import net.minecraft.server.v1_8_R3.ChatComponentText; +import net.minecraft.server.v1_8_R3.PacketPlayOutChat; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; + +public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { + @Override + public boolean bowInHand(EnumWrappers.Hand hand, Player p) { + return p.getInventory().getItemInHand().getType() == Material.BOW; + } + + @Override + public void toActionbar(Player player, BaseComponent... components) { + PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(BaseComponent.toLegacyText(components)), (byte)2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + @Override + public void toChat(Player player, BaseComponent... components) { + PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(BaseComponent.toLegacyText(components)), (byte)0); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + @Override + public void setAttackSpeed(Player player) { + // nothing to do + } + + @Override + public void setNametagVisibility(Team team) { + //nothing to do + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java similarity index 70% rename from FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java index 9d25c29..89aedc7 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,9 +15,9 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import de.steamwar.core.events.ChunkListener; import net.minecraft.server.v1_8_R3.Chunk; @@ -26,13 +26,17 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -public class FightWorld_8 { - private FightWorld_8(){} +import java.util.HashSet; +import java.util.Set; - static void resetChunk(World world, World backup, int x, int z, boolean isPaper){ +public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapper { + @Override + public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); @@ -47,11 +51,21 @@ public class FightWorld_8 { } } - public static void sendResourcePack(Player player, String pack, String sha1){ + @Override + public void sendResourcePack(Player player, String pack, String sha1) { ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); } - public static float headRotation(Entity e){ + @Override + public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java new file mode 100644 index 0000000..5782625 --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java @@ -0,0 +1,89 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper { + @Override + public DyeColor getSilver() { + return DyeColor.SILVER; + } + + @Override + public boolean isWater(Block block) { + Material type = block.getType(); + return type == Material.WATER || type == Material.STATIONARY_WATER; + } + + @Override + public boolean removeWater(Block block) { + if(isWater(block)){ + block.setType(Material.AIR); + return true; + } + return false; + } + + @Override + public boolean containsBlockMeta(ItemMeta meta) { + return false; + } + + @Override + public boolean hasAttributeModifier(ItemStack stack) { + return false; + } + + @Override + public Material onBreak(Material type) { + switch(type){ + case REDSTONE_WIRE: + return Material.REDSTONE; + case PISTON_EXTENSION: + return Material.PISTON_BASE; + case ICE: + return Material.AIR; + default: + return type; + } + } + + @Override + public boolean doRecord(BlockPhysicsEvent e) { + return e.getChangedType() != e.getBlock().getType(); + } + + @Override + public void forceLoadChunk(World world, int cX, int cZ) { + // not possible in 1.8 + } + + @Override + public boolean checkPistonMoving(Block block) { + return block.getType() == Material.PISTON_MOVING_PIECE; + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/countdown/Countdown_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/SWSound8.java similarity index 79% rename from FightSystem_8/src/de/steamwar/fightsystem/countdown/Countdown_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/SWSound8.java index 4224ecd..d4a6e21 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/countdown/Countdown_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/SWSound8.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,16 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.countdown; +package de.steamwar.fightsystem.utils; import org.bukkit.Sound; -class Countdown_8 { - private Countdown_8(){} - - static Sound getSound(SWSound sound){ +public class SWSound8 implements SWSound.ISWSound { + @Override + public Sound getSound(SWSound sound) { switch(sound){ case ENTITY_WITHER_DEATH: return Sound.WITHER_DEATH; @@ -32,6 +31,8 @@ class Countdown_8 { return Sound.NOTE_BASS; case BLOCK_NOTE_PLING: return Sound.NOTE_PLING; + case ENTITY_GENERIC_EXPLODE: + return Sound.EXPLODE; default: return null; } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java similarity index 58% rename from FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java index 19dfa53..3a8e4f6 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,22 +15,23 @@ 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; +package de.steamwar.fightsystem.utils; -import org.bukkit.World; -import org.bukkit.block.Block; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketEvent; +import de.steamwar.fightsystem.FightSystem; -@SuppressWarnings("deprecation") -class RecordSystem_8 { - private RecordSystem_8(){} +public class TechHider8 extends PacketAdapter { - static int blockToId(Block block){ - return block.getTypeId() << 4 + block.getData(); + public TechHider8() { + super(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK); } - static void setBlock(World world, int x, int y, int z, int blockState){ - world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); + @Override + public void onPacketSending(PacketEvent e) { + // no implementation availible } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java similarity index 86% rename from FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index f62cb60..d12b387 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,9 +15,9 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; @@ -38,20 +38,19 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.utils.Region; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.scoreboard.Team; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.util.zip.GZIPInputStream; -public class FightTeam_8 { - private FightTeam_8(){} +public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { @SuppressWarnings("deprecation") private static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData(); @@ -67,11 +66,9 @@ public class FightTeam_8 { @SuppressWarnings("deprecation") private static final BaseBlock CARPET = new BaseBlock(Material.CARPET.getId(), COLOR_TO_REPLACE); - static void setTeamColor(Team team, ChatColor color){ - team.setPrefix("§" + color.getChar()); - } - - static void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { + @SuppressWarnings("deprecation") + @Override + public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { Vector minimum = clipboard.getRegion().getMinimumPoint(); BaseBlock wool = new BaseBlock(WOOL.getId(), c.getWoolData()); BaseBlock clay = new BaseBlock(CLAY.getId(), c.getWoolData()); @@ -100,10 +97,11 @@ public class FightTeam_8 { } } - static void pasteSchematic(Clipboard clipboard, Region paste, boolean rotate) { + @Override + public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); - Vector v = new Vector(paste.centerX(), paste.getMinY(), paste.centerZ()); + Vector v = new Vector(region.centerX(), region.getMinY(), region.centerZ()); Vector offset = clipboard.getMinimumPoint().subtract(clipboard.getOrigin()); AffineTransform aT = new AffineTransform(); if(rotate){ @@ -130,7 +128,8 @@ public class FightTeam_8 { e.flushQueue(); } - static void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){ + @Override + public void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); Vector v = Vector.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); @@ -144,15 +143,13 @@ public class FightTeam_8 { e.flushQueue(); } - static Clipboard loadSchem(NBTInputStream stream) throws IOException { - return new SchematicReader(stream).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData()); + @Override + public Clipboard loadChar(String charName) throws IOException { + return new SchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schematic"))))).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData()); } - public static boolean checkPistonMoving(Block block){ - return block.getType() == Material.PISTON_MOVING_PIECE; - } - - public static void saveSchem(Schematic schem, Region region, int minY) { + @Override + public void saveSchem(Schematic schem, Region region, int minY) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector min = new Vector(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ())); diff --git a/FightSystem_9/pom.xml b/FightSystem_9/pom.xml index 769e6c2..8cf317c 100644 --- a/FightSystem_9/pom.xml +++ b/FightSystem_9/pom.xml @@ -17,28 +17,10 @@ FightSystem_9 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar - FightSystem_8 - 1.0 - - - steamwar - FightSystem_API + FightSystem_Core 1.0 diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/PickupArrowListener_9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java similarity index 95% rename from FightSystem_9/src/de/steamwar/fightsystem/listener/PickupArrowListener_9.java rename to FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java index 19a547a..28ce13b 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/PickupArrowListener_9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java @@ -23,7 +23,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerPickupArrowEvent; -class PickupArrowListener_9 implements Listener { +public class ArrowPickup9 implements Listener { @EventHandler public void onArrowPickup(PlayerPickupArrowEvent e){ diff --git a/FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java similarity index 90% rename from FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java rename to FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java index 5a805c9..c5c6733 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/listener/DenyWorldInteraction_10.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem.listener; @@ -23,7 +23,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerSwapHandItemsEvent; -public class DenyWorldInteraction_10 implements Listener { +public class DenyWorldInteraction9 implements Listener { @EventHandler public void onSwapItems(PlayerSwapHandItemsEvent event) { diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java deleted file mode 100644 index 956e46a..0000000 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - 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.listener; - -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -import java.util.HashSet; -import java.util.Set; - -public class PersonalKitCreator_9 { - - public static boolean hasItems(ItemStack stack){ - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } -} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/BasicListener_9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java similarity index 55% rename from FightSystem_9/src/de/steamwar/fightsystem/listener/BasicListener_9.java rename to FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index f90fa8a..ba721de 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/BasicListener_9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,29 +15,44 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.utils; +import com.comphenix.protocol.wrappers.EnumWrappers; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Material; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; -class BasicListener_9 { - private BasicListener_9(){} +public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { + @Override + public boolean bowInHand(EnumWrappers.Hand hand, Player p) { + return (hand == EnumWrappers.Hand.MAIN_HAND && p.getInventory().getItemInMainHand().getType() == Material.BOW) || + (hand == EnumWrappers.Hand.OFF_HAND && p.getInventory().getItemInOffHand().getType() == Material.BOW); + } - static void toActionbar(Player player, BaseComponent... components){ + @Override + public void toActionbar(Player player, BaseComponent... components) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, components); } - static void toChat(Player player, BaseComponent... components){ + @Override + public void toChat(Player player, BaseComponent... components) { player.spigot().sendMessage(ChatMessageType.CHAT, components); } - static void setAttackSpeed(Player player){ + @Override + public void setAttackSpeed(Player player) { AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); attribute.setBaseValue(16); } + + @Override + public void setNametagVisibility(Team team) { + team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + } } diff --git a/FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java similarity index 69% rename from FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java rename to FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java index f35afb4..bb13e18 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,24 +15,29 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.fight.FightWorld; import net.minecraft.server.v1_9_R2.Chunk; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; -public class FightWorld_9 { - private FightWorld_9(){} +import java.util.HashSet; +import java.util.Set; - static void resetChunk(World world, World backup, int x, int z, boolean isPaper){ +public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper { + @Override + public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_9_R2.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); @@ -40,7 +45,7 @@ public class FightWorld_9 { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!isPaper) { + if (!FightWorld.isPaper()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); @@ -50,11 +55,21 @@ public class FightWorld_9 { } } - public static void sendResourcePack(Player player, String pack, String sha1){ + @Override + public void sendResourcePack(Player player, String pack, String sha1) { ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); } - public static float headRotation(Entity e){ + @Override + public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } } diff --git a/FightSystem_9/src/de/steamwar/fightsystem/countdown/Countdown_9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/SWSound9.java similarity index 78% rename from FightSystem_9/src/de/steamwar/fightsystem/countdown/Countdown_9.java rename to FightSystem_9/src/de/steamwar/fightsystem/utils/SWSound9.java index 71e345a..3589c09 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/countdown/Countdown_9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/SWSound9.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,16 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.countdown; +package de.steamwar.fightsystem.utils; import org.bukkit.Sound; -class Countdown_9 { - private Countdown_9(){} - - static Sound getSound(SWSound sound){ +public class SWSound9 implements SWSound.ISWSound { + @Override + public Sound getSound(SWSound sound){ switch(sound){ case ENTITY_WITHER_DEATH: return Sound.ENTITY_WITHER_DEATH; @@ -32,6 +31,8 @@ class Countdown_9 { return Sound.BLOCK_NOTE_BASS; case BLOCK_NOTE_PLING: return Sound.BLOCK_NOTE_PLING; + case ENTITY_GENERIC_EXPLODE: + return Sound.ENTITY_GENERIC_EXPLODE; default: return null; } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java deleted file mode 100644 index 5725381..0000000 --- a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - 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; - -import de.steamwar.sql.EventFight; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class IFightSystem { - private IFightSystem(){} - - private static Plugin plugin; - private static EventFight eventFight; - private static Player eventLeiter; - - public static void init(Plugin plugin){ - IFightSystem.plugin = plugin; - } - static void setEventFight(EventFight ef){ - eventFight = ef; - } - static void setEventLeiter(Player el){ - eventLeiter = el; - } - - public static Plugin getPlugin(){ - return plugin; - } - public static EventFight getEventFight(){ - return eventFight; - } - public static Player getEventLeiter(){ - return eventLeiter; - } -} diff --git a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java b/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java deleted file mode 100644 index 1c44e1a..0000000 --- a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFight.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - 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.fight; - -import org.bukkit.entity.Player; - -public class IFight { - private IFight(){} - - private static IFightTeam redTeam; - private static IFightTeam blueTeam; - - public static void init(IFightTeam redTeam, IFightTeam blueTeam){ - IFight.redTeam = redTeam; - IFight.blueTeam = blueTeam; - } - - public static IFightTeam getPlayerTeam(Player player) { - if(redTeam.isPlayerInTeam(player)) - return redTeam; - if(blueTeam.isPlayerInTeam(player)) - return blueTeam; - return null; - } -} diff --git a/FightSystem_API/pom.xml b/FightSystem_Core/pom.xml similarity index 60% rename from FightSystem_API/pom.xml rename to FightSystem_Core/pom.xml index a2faacd..a9f81ed 100644 --- a/FightSystem_API/pom.xml +++ b/FightSystem_Core/pom.xml @@ -14,29 +14,23 @@ ${project.basedir}/.. - FightSystem_API + FightSystem_Core 1.0 - - src - - - src - - **/*.java - **/*.kt - - - - - steamwar Spigot - 1.12 + 1.15 system - ${main.basedir}/lib/Spigot-1.12.jar + ${main.basedir}/lib/Spigot-1.15.jar + + + steamwar + WorldEdit + 1.0 + system + ${main.basedir}/lib/WorldEdit-1.12.jar \ No newline at end of file diff --git a/FightSystem_Main/src/config.yml b/FightSystem_Core/src/config.yml similarity index 100% rename from FightSystem_Main/src/config.yml rename to FightSystem_Core/src/config.yml diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java similarity index 98% rename from FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java rename to FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java index a3a5fee..bcfb258 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java similarity index 97% rename from FightSystem_API/src/de/steamwar/fightsystem/Config.java rename to FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 2837356..ac9b04d 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem; @@ -132,12 +132,12 @@ public class Config { public static final int ReplayID; static{ - if(!new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) { - IFightSystem.getPlugin().saveDefaultConfig(); + if(!new File(FightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) { + FightSystem.getPlugin().saveDefaultConfig(); Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml"))); + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(FightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml"))); File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), config.getString("Arenaconfig", "config.yml")); if(!worldConfigFile.exists()) { @@ -326,7 +326,7 @@ public class Config { EventTeamRedID = team2.getTeamId(); BothTeamsPublic = EventTeamRedID == 0 && EventTeamBlueID == 0; - IFightSystem.setEventFight(eventFight); + FightSystem.setEventFight(eventFight); Event event = Event.get(eventFight.getEventID()); if(BothTeamsPublic) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java similarity index 95% rename from FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java rename to FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 1d2b46d..2927bda 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -20,14 +20,12 @@ package de.steamwar.fightsystem; import de.steamwar.core.CommandRemover; -import de.steamwar.core.Core; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.event.HellsBells; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; -import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.*; @@ -49,17 +47,16 @@ public class FightSystem extends JavaPlugin { public static final String PREFIX = "§eArena§8» "; private static FightSystem plugin; + private static EventFight eventFight; + private static Player eventLeiter; @Override public void onLoad() { plugin = this; - IFightSystem.init(this); } @Override public void onEnable() { - IFight.init(Fight.getRedTeam(), Fight.getBlueTeam()); - new EntityDamage(); new WaterRemover(); new Permanent(); @@ -74,7 +71,7 @@ public class FightSystem extends JavaPlugin { new DenyWorldInteraction(); new EventJoin(); new Recording(); - // new ResourcePack(); + //new ResourcePack(); new Check(); new Shutdown(); new SetupQuit(); @@ -85,8 +82,7 @@ public class FightSystem extends JavaPlugin { new PersonalKitCreator(); new FightScoreboard(); new ArrowStopper(); - if(Core.getVersion() > 8) - new ArrowPickup(); + new ArrowPickup(); new EnterHandler(); new TechHider(); @@ -214,15 +210,19 @@ public class FightSystem extends JavaPlugin { } public static void setEventLeiter(Player el){ - IFightSystem.setEventLeiter(el); + eventLeiter = el; } public static Player getEventLeiter(){ - return IFightSystem.getEventLeiter(); + return eventLeiter; } public static EventFight getEventFight(){ - return IFightSystem.getEventFight(); + return eventFight; + } + + public static void setEventFight(EventFight ef){ + eventFight = ef; } public static FightSystem getPlugin() { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/VersionDependent.java b/FightSystem_Core/src/de/steamwar/fightsystem/VersionDependent.java new file mode 100644 index 0000000..d44a1e6 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/VersionDependent.java @@ -0,0 +1,41 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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; + +import de.steamwar.core.Core; + +import java.lang.reflect.InvocationTargetException; + +public class VersionDependent { + private VersionDependent() {} + + public static T getVersionImpl(String className){ + for(int version = Core.getVersion(); version >= 8; version--) { + try { + return (T) Class.forName(className + version).getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new SecurityException("Could not load version dependent class", e); + } catch (ClassNotFoundException e) { + // try next version + } + } + throw new SecurityException("Unable to find version dependent implementation for " + className); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/AkCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/AkCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/CommandInjector.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/CommandInjector.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/CommandInjector.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/CommandInjector.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GamemodeCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/GamemodeCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/InviteCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/InviteCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/KitCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/KitCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaveCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaveCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReadyCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/ReadyCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/RemoveCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/RemoveCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReplayCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReplayCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/ReplayCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/ReplayCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/StateCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/StateCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/WinCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/WinCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java similarity index 87% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java index 05c2a23..f847bb9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -19,11 +19,11 @@ package de.steamwar.fightsystem.countdown; -import de.steamwar.core.Core; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.listener.BasicListener; import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.utils.SWSound; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -39,7 +39,7 @@ public abstract class Countdown { private static final List currentCountdowns = new ArrayList<>(); private final int totalTime; - private final Sound sound; + protected final Sound sound; private final boolean level; protected int time; @@ -48,31 +48,13 @@ public abstract class Countdown { public abstract String countdownCounting(); public abstract void countdownFinished(); - public Countdown(int time, SWSound sound, boolean level) { + protected Countdown(int time, SWSound sound, boolean level) { this.totalTime = time; this.time = time; - this.sound = getSound(sound); + this.sound = sound != null ? sound.getSound() : null; this.level = level; } - public static Sound getSound(SWSound sound){ - if(sound == null) - return null; - - switch (Core.getVersion()){ - case 8: - return Countdown_8.getSound(sound); - case 9: - case 10: - case 12: - return Countdown_9.getSound(sound); - case 14: - case 15: - default: - return Countdown_14.getSound(sound); - } - } - public void enable() { time = totalTime; task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java similarity index 89% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index f08a8fe..ec78cc6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -23,6 +23,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.listener.BasicListener; +import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.utils.TechHider; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; @@ -59,19 +60,19 @@ public class EnternCountdown extends Countdown { BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting())); break; case 60: case 30: case 20: case 15: case 10: case 5: case 4: case 3: case 2: - player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F); + player.playSound(player.getLocation(), sound, 100.0F, 1.0F); BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time + " §rSekunden " + countdownCounting())); break; case 1: - player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F); + player.playSound(player.getLocation(), sound, 100.0F, 1.0F); BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a1 §rSekunde " + countdownCounting())); chunkPos = TechHider.prepareChunkReload(player, false); break; case 0: - player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 2.0F); + player.playSound(player.getLocation(), sound, 100.0F, 2.0F); disable(); countdownFinished(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java similarity index 97% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java index abaa890..a26a14d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; +import de.steamwar.fightsystem.utils.SWSound; public class EventSpectateCountdown extends Countdown { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java similarity index 97% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java index 36a6b79..9a5dac4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; +import de.steamwar.fightsystem.utils.SWSound; public class PreRunningCountdown extends Countdown { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java similarity index 97% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java index 6dbe901..f9c007a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; +import de.steamwar.fightsystem.utils.SWSound; public class PreSchemCountdown extends Countdown { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java similarity index 96% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java index 5946085..92ac120 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -22,9 +22,9 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; +import de.steamwar.fightsystem.utils.SWSound; public class SpectateOverCountdown extends Countdown { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java similarity index 96% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index 96a6cab..a45e12c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.utils.SWSound; import org.bukkit.Bukkit; public class TimeOverCountdown extends Countdown { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java similarity index 99% rename from FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java rename to FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java index 1d3d87f..72a7b40 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java @@ -22,7 +22,7 @@ package de.steamwar.fightsystem.event; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.winconditions.Winconditions; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java similarity index 66% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index af1d0b1..a9a1bcb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -19,12 +19,9 @@ package de.steamwar.fightsystem.fight; -import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.transform.AffineTransform; -import de.steamwar.core.VersionedCallable; -import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -33,6 +30,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; +import de.steamwar.fightsystem.utils.WorldeditWrapper; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.DyeColor; @@ -41,14 +39,11 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.event.HandlerList; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.logging.Level; -import java.util.zip.GZIPInputStream; public class FightSchematic extends StateDependent { @@ -122,29 +117,8 @@ public class FightSchematic extends StateDependent { Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); } - private void replaceTeamColor(Clipboard clipboard){ - DyeColor c = ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK; - VersionedRunnable.call(new VersionedRunnable(() -> { - try { - FightTeam_8.replaceTeamColor(clipboard, c); - } catch (WorldEditException ex) { - throw new SecurityException("Error recoloring schematic", ex); - } - }, 8), - new VersionedRunnable(() -> { - try { - FightTeam_12.replaceTeamColor(clipboard, c); - } catch (WorldEditException ex) { - throw new SecurityException("Error recoloring schematic", ex); - } - }, 12), - new VersionedRunnable(() -> { - try { - FightTeam_14.replaceTeamColor(clipboard, c); - } catch (WorldEditException ex) { - throw new SecurityException("Error recoloring schematic", ex); - } - }, 14)); + private void replaceTeamColor(Clipboard clipboard) throws WorldEditException { + WorldeditWrapper.impl.replaceTeamColor(clipboard, ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK); } private void paste(){ @@ -152,35 +126,33 @@ public class FightSchematic extends StateDependent { try { replaceTeamColor(clipboard); - VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.pasteSchematic(clipboard, region, rotate), 8), - new VersionedRunnable(() -> FightTeam_14.pasteSchematic(clipboard, region, rotate), 14)); - } catch (SecurityException securityException) { + WorldeditWrapper.impl.pasteSchematic(clipboard, region, rotate); + } catch (WorldEditException e) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); - throw securityException; + throw new SecurityException("Could not paste schematic", e); } Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } - private Clipboard loadTextSchem(String schemName){ - return VersionedCallable.call(new VersionedCallable<>(() -> FightTeam_8.loadSchem(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + schemName + ".schematic"))))), 8), - new VersionedCallable<>(() -> FightTeam_14.loadSchem(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + schemName + ".schem"))))), 14)); + private Clipboard loadTextSchem(String schemName) throws IOException { + return WorldeditWrapper.impl.loadChar(schemName); } public void pasteTeamName(){ List characters = new ArrayList<>(); for(char c : team.getName().toCharArray()){ try { + characters.add(loadTextSchem(c == '/' ? "slash" : String.valueOf(c))); + } catch (IOException e) { + Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", c); try { - characters.add(loadTextSchem(c == '/' ? "slash" : String.valueOf(c))); - } catch (RuntimeException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", c); characters.add(loadTextSchem("")); + }catch (IOException ex) { + throw new SecurityException("Could not load text", ex); } - }catch (RuntimeException e) { - throw new SecurityException("Could not load text", e); } } @@ -210,16 +182,15 @@ public class FightSchematic extends StateDependent { } for(int i = 0; i < characters.size(); i++){ - replaceTeamColor(characters.get(i)); - pasteChar(characters.get(i), offsets[i], length, team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), z, aT); + try { + replaceTeamColor(characters.get(i)); + } catch (WorldEditException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e); + } + WorldeditWrapper.impl.pasteChar(characters.get(i), offsets[i], length, team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), z, aT); } } - private void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){ - VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.pasteChar(character, charOffset, length, x, y, z, aT), 8), - new VersionedRunnable(() -> FightTeam_14.pasteChar(character, charOffset, length, x, y, z, aT), 14)); - } - @Override public void disable() { if(!Config.ReplaceObsidianBedrock) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java similarity index 95% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 92ed1af..fab2aea 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -21,17 +21,17 @@ package de.steamwar.fightsystem.fight; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.comms.packets.TablistNamePacket; -import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.listener.BasicListener; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.TechHider; @@ -48,7 +48,9 @@ import org.bukkit.scoreboard.Team; import java.util.*; -public class FightTeam implements IFightTeam{ +public class FightTeam { + + private static final IFightTeam impl = VersionDependent.getVersionImpl(FightTeam.class.getName()); private UUID designatedLeader; private FightPlayer leader; @@ -87,7 +89,8 @@ public class FightTeam implements IFightTeam{ else team = FightScoreboard.getBukkit().getTeam(name); assert team != null; - setTeamColor(team, color); + impl.setTeamColor(team, color); + BountifulWrapper.impl.setNametagVisibility(team); //noinspection deprecation team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); team.setAllowFriendlyFire(false); @@ -131,12 +134,10 @@ public class FightTeam implements IFightTeam{ return true; } - @Override public boolean isPlayerInTeam(Player player) { return players.containsKey(player); } - @Override public boolean canPlayerEntern(Player player) { return getFightPlayer(player).canEntern(); } @@ -196,7 +197,7 @@ public class FightTeam implements IFightTeam{ player.setHealth(20); player.setFoodLevel(20); player.getInventory().clear(); - BasicListener.setAttackSpeed(player); + BountifulWrapper.impl.setAttackSpeed(player); player.teleport(spawn); if(Kit.getAvailableKits(false).size() > 1 || Config.PersonalKits) player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); @@ -237,7 +238,6 @@ public class FightTeam implements IFightTeam{ return leader == null; } - @Override public boolean isBlue(){ return blue; } @@ -402,17 +402,14 @@ public class FightTeam implements IFightTeam{ return currentHearts / maximumHearts; } - private void setTeamColor(Team team, ChatColor color){ - VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.setTeamColor(team, color), 8), - new VersionedRunnable(() -> FightTeam_9.setTeamColor(team, color), 9), - new VersionedRunnable(() -> FightTeam_12.setTeamColor(team, color), 12), - new VersionedRunnable(() -> FightTeam_14.setTeamColor(team, color), 14)); - } - public ChatColor getColor() { return color; } + public interface IFightTeam { + void setTeamColor(Team team, ChatColor color); + } + private class KitLoader extends StateDependent { private KitLoader() { super(ArenaMode.AntiReplay, FightState.Ingame); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java similarity index 65% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java index 93e53bd..b3cacb5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -19,12 +19,12 @@ package de.steamwar.fightsystem.fight; -import de.steamwar.core.Core; -import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.utils.CraftbukkitWrapper; +import de.steamwar.fightsystem.utils.FlatteningWrapper; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -33,13 +33,12 @@ import org.bukkit.entity.EntityType; public class FightWorld extends StateDependent { - private static final boolean paper; - - static{ - paper = Bukkit.getVersion().contains("git-Paper"); - } - private static final World world = Bukkit.getWorlds().get(0); + private static final boolean paper = Bukkit.getVersion().contains("git-Paper"); + + public static boolean isPaper(){ + return paper; + } public FightWorld() { super(ArenaMode.Restartable, FightState.Schem); @@ -51,10 +50,6 @@ public class FightWorld extends StateDependent { //unused } - public static boolean isPaper(){ - return paper; - } - @Override public void disable() { resetWorld(); @@ -63,8 +58,7 @@ public class FightWorld extends StateDependent { public static void forceLoad(){ Config.ArenaRegion.forEachChunk((cX, cZ) -> { world.loadChunk(cX, cZ); - if(Core.getVersion() > 12) - world.setChunkForceLoaded(cX, cZ, true); + FlatteningWrapper.impl.forceLoadChunk(world, cX, cZ); }); world.setKeepSpawnInMemory(true); } @@ -78,17 +72,7 @@ public class FightWorld extends StateDependent { World backup = new WorldCreator(world.getName() + "/backup").createWorld(); assert backup != null; - Config.ArenaRegion.forEachChunk((x, z) -> resetChunk(backup, x, z, FightWorld.isPaper())); + Config.ArenaRegion.forEachChunk((x, z) -> CraftbukkitWrapper.impl.resetChunk(world, backup, x, z)); Bukkit.unloadWorld(backup, false); } - - private static void resetChunk(World backup, int x, int z, boolean isPaper){ - VersionedRunnable.call( - new VersionedRunnable(() -> FightWorld_8.resetChunk(world, backup, x, z, isPaper), 8), - new VersionedRunnable(() -> FightWorld_9.resetChunk(world, backup, x, z, isPaper), 9), - new VersionedRunnable(() -> FightWorld_10.resetChunk(world, backup, x, z, isPaper), 10), - new VersionedRunnable(() -> FightWorld_12.resetChunk(world, backup, x, z, isPaper), 12), - new VersionedRunnable(() -> FightWorld_14.resetChunk(world, backup, x, z, isPaper), 14), - new VersionedRunnable(() -> FightWorld_15.resetChunk(world, backup, x, z, isPaper), 15)); - } -} +} \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java similarity index 95% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java index d82cbbf..f3aa5d3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FreezeWorld.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.fight; -import de.steamwar.fightsystem.IFightSystem; +import de.steamwar.fightsystem.FightSystem; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -32,7 +32,7 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent; public class FreezeWorld implements Listener { public FreezeWorld(){ - Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); + Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); } public void disable(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java similarity index 92% rename from FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java rename to FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index e37b47f..84df9b5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -19,13 +19,13 @@ package de.steamwar.fightsystem.fight; -import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.Commands; import de.steamwar.fightsystem.commands.GUI; -import de.steamwar.fightsystem.listener.*; +import de.steamwar.fightsystem.listener.PersonalKitCreator; +import de.steamwar.fightsystem.utils.CraftbukkitWrapper; +import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.sql.PersonalKit; @@ -38,7 +38,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BlockDataMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; @@ -188,21 +187,16 @@ public class Kit { return true; //Check for attribute modifiers - if(Core.getVersion() >= 14 && PersonalKitCreator_14.hasAttributeModifier(stack)){ + if(FlatteningWrapper.impl.hasAttributeModifier(stack)){ return true; } if(stack.hasItemMeta()){ ItemMeta meta = stack.getItemMeta(); - if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData()) + if(FlatteningWrapper.impl.containsBlockMeta(meta)) return true; //Blocks always upwards slabs etc. - if(VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8), - new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9), - new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10), - new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12), - new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14), - new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15))) + if(CraftbukkitWrapper.impl.hasItems(stack)) return true; //Blocks prefilled inventories } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowPickup.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java similarity index 85% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowPickup.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java index b8d4693..ccf9acd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowPickup.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java @@ -19,16 +19,14 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; public class ArrowPickup { public ArrowPickup() { - if(Core.getVersion() > 8){ - new StateDependentListener(ArenaMode.All, FightState.All, new PickupArrowListener_9()); - } + new StateDependentListener(ArenaMode.All, FightState.All, VersionDependent.getVersionImpl(ArrowPickup.class.getName())); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java similarity index 91% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 35d8af1..47fcecf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,11 +15,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.Bukkit; @@ -36,6 +37,8 @@ public class ArrowStopper { private static final Vector NULL_VECTOR = new Vector(0, 0, 0); private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; + private static final IArrowStopper impl = VersionDependent.getVersionImpl(ArrowStopper.class.getName()); + public ArrowStopper() { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } @@ -90,7 +93,11 @@ public class ArrowStopper { boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ(); boolean otherSide = teamFrom == overMid; return otherSide || - entity.isInBlock() || + impl.isInBlock(entity) || entity.getVelocity().equals(NULL_VECTOR); } + + public interface IArrowStopper { + boolean isInBlock(Arrow e); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/BasicListener.java similarity index 69% rename from FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/BasicListener.java index 5cd86f6..f63dc1c 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/BasicListener.java @@ -19,17 +19,19 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.utils.BountifulWrapper; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.entity.Player; -class BasicListener_8 { - private BasicListener_8(){} +public class BasicListener { + private BasicListener(){} - static void toActionbar(Player player, BaseComponent... components){ - player.spigot().sendMessage(components); + public static boolean notFighting(Player p){ + return Fight.getFightPlayer(p) == null; } - static void toChat(Player player, BaseComponent... components){ - player.spigot().sendMessage(components); + public static void toActionbar(Player player, BaseComponent... components){ + BountifulWrapper.impl.toActionbar(player, components); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java similarity index 96% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java index 973a706..21fdd77 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java @@ -27,6 +27,7 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.BountifulWrapper; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -67,6 +68,6 @@ public class Chat implements Listener { GlobalRecorder.getInstance().chat(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) - BasicListener.toChat(p, msg); + BountifulWrapper.impl.toChat(p, msg); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Check.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/Check.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java similarity index 91% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java index 78b5d50..998f8cb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java @@ -19,8 +19,8 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import net.md_5.bungee.api.chat.TextComponent; @@ -40,11 +40,10 @@ public class DenyWorldInteraction implements Listener { public DenyWorldInteraction() { new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this); new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this); - if(Core.getVersion() > 9){ - Listener listener = new DenyWorldInteraction_10(); - new StateDependentListener(ArenaMode.Test, FightState.PreRunning, listener); - new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, listener); - } + + Listener listener = VersionDependent.getVersionImpl(DenyWorldInteraction.class.getName()); + new StateDependentListener(ArenaMode.Test, FightState.PreRunning, listener); + new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, listener); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamage.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/EntityDamage.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamage.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/EntityDamage.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/EventJoin.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/EventJoin.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/HotbarGUI.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/HotbarGUI.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightInventory.java similarity index 93% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightInventory.java index d63cccf..70ae2ba 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightInventory.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.FlatteningWrapper; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Material; import org.bukkit.event.EventHandler; @@ -81,17 +82,7 @@ public class InFightInventory implements Listener { public void onBlockBreak(BlockBreakEvent event) { Inventory inventory = event.getPlayer().getInventory(); - Material type = event.getBlock().getType(); - switch(type){ - case REDSTONE_WIRE: - type = Material.REDSTONE; - break; - case PISTON_HEAD: - type = Material.PISTON; - break; - case ICE: - return; - } + Material type = FlatteningWrapper.impl.onBreak(event.getBlock().getType()); ItemStack itemStack; for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java similarity index 93% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java index 8c896c5..89b3b3c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java @@ -21,8 +21,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; @@ -54,7 +53,7 @@ public class IngameDeath implements Listener { return; Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §cist gestorben!"); - Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); + Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F); team.getFightPlayer(player).setOut(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java similarity index 98% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java index 5be57c1..adb4195 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -23,7 +23,6 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPistonExtendEvent; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java similarity index 83% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index a9c68e9..e1a39ad 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -19,18 +19,16 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.VersionedCallable; -import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.fight.FightTeam_14; -import de.steamwar.fightsystem.fight.FightTeam_8; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.Region; +import de.steamwar.fightsystem.utils.WorldeditWrapper; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.World; @@ -60,9 +58,7 @@ public class PrepareSchem implements Listener { try{ region.forEach((x, y, z) -> { - if(VersionedCallable.call( - new VersionedCallable<>(() -> FightTeam_8.checkPistonMoving(world.getBlockAt(x, y, z)), 8), - new VersionedCallable<>(() -> FightTeam_14.checkPistonMoving(world.getBlockAt(x, y, z)), 14))){ + if(FlatteningWrapper.impl.checkPistonMoving(world.getBlockAt(x, y, z))){ FightSystem.shutdown(FightSystem.PREFIX + "§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen."); throw new IllegalStateException(); } @@ -72,12 +68,10 @@ public class PrepareSchem implements Listener { } try{ - VersionedRunnable.call( - new VersionedRunnable(() -> FightTeam_8.saveSchem(schem, region, minY), 8), - new VersionedRunnable(() -> FightTeam_14.saveSchem(schem, region, minY), 14)); + WorldeditWrapper.impl.saveSchem(schem, region, minY); }catch(IllegalStateException e){ FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen."); - return; + throw new SecurityException("Could not save schem", e); } schem.setSchemType(Config.SchematicType.checkType()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/RankedJoin.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/RankedJoin.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java similarity index 90% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 0460e50..86d4377 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -25,7 +25,6 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; -import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -36,6 +35,9 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.utils.BountifulWrapper; +import de.steamwar.fightsystem.utils.FlatteningWrapper; +import de.steamwar.fightsystem.utils.SWSound; import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -65,8 +67,7 @@ public class Recording implements Listener { EnumWrappers.Hand hand = packet.getHands().read(0); Player p = event.getPlayer(); - if(!((hand == EnumWrappers.Hand.MAIN_HAND && p.getInventory().getItemInMainHand().getType() == Material.BOW) || - (hand == EnumWrappers.Hand.OFF_HAND && p.getInventory().getItemInOffHand().getType() == Material.BOW))) + if(!BountifulWrapper.impl.bowInHand(hand, p)) return; GlobalRecorder.getInstance().bowSpan(p, true, hand != EnumWrappers.Hand.MAIN_HAND); @@ -124,22 +125,6 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entitySpeed(tnt); } }, 1, 1); - if(Core.getVersion() > 12){ - new StateDependentListener(ArenaMode.AntiReplay, FightState.All, new Listener() { - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockPhysics(BlockPhysicsEvent e){ - if(e.getBlock() == e.getSourceBlock() || e.getChangedType() == Material.AIR) - GlobalRecorder.getInstance().blockChange(e.getBlock()); - } - }); - }else{ - new StateDependentListener(ArenaMode.AntiReplay, FightState.All, new Listener() { - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockPhysics(BlockPhysicsEvent e){ - GlobalRecorder.getInstance().blockChange(e.getBlock()); - } - }); - } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -163,6 +148,12 @@ public class Recording implements Listener { GlobalRecorder.getInstance().systemChat(e.getMessage()); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPhysics(BlockPhysicsEvent e){ + if(FlatteningWrapper.impl.doRecord(e)) + GlobalRecorder.getInstance().blockChange(e.getBlock()); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onSneak(PlayerToggleSneakEvent e){ if(isNotSent(e.getPlayer())) @@ -223,7 +214,7 @@ public class Recording implements Listener { Location loc = e.getLocation(); GlobalRecorder.getInstance().entityDespawns(e.getEntity()); GlobalRecorder.getInstance().particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_HUGE.name()); - GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); + GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), SWSound.ENTITY_GENERIC_EXPLODE, EnumWrappers.SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ResourcePack.java similarity index 60% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/ResourcePack.java index 019ff5e..dfe27c8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ResourcePack.java @@ -1,11 +1,10 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.*; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -21,7 +20,7 @@ public class ResourcePack implements Listener { @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - sendResourcePack(player, "https://steamwar.de/antixray.zip", "3e94f5abeb07cc95067b27705615ec14666abe7b"); + CraftbukkitWrapper.impl.sendResourcePack(player, "https://steamwar.de/antixray.zip", "3e94f5abeb07cc95067b27705615ec14666abe7b"); } @EventHandler @@ -34,14 +33,4 @@ public class ResourcePack implements Listener { player.sendMessage(FightSystem.PREFIX + "§cDa du abgelehnt hast, musst du nun in der Serverliste erst einmal wieder Ressourcenpakete von SteamWar aktivieren."); player.kickPlayer(null); } - - private void sendResourcePack(Player player, String pack, String sha1){ - VersionedRunnable.call( - new VersionedRunnable(() -> FightWorld_8.sendResourcePack(player, pack, sha1), 8), - new VersionedRunnable(() -> FightWorld_9.sendResourcePack(player, pack, sha1), 9), - new VersionedRunnable(() -> FightWorld_10.sendResourcePack(player, pack, sha1), 10), - new VersionedRunnable(() -> FightWorld_12.sendResourcePack(player, pack, sha1), 12), - new VersionedRunnable(() -> FightWorld_14.sendResourcePack(player, pack, sha1), 14), - new VersionedRunnable(() -> FightWorld_15.sendResourcePack(player, pack, sha1), 15)); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/SetupQuit.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/SetupQuit.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java similarity index 82% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java rename to FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index d33dc58..ae8059e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -19,11 +19,11 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.FlatteningWrapper; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; @@ -55,9 +55,7 @@ public class WaterRemover implements Listener { private void checkBlock(Block b) { //checks for water and removes it, if present - if(!VersionedCallable.call( - new VersionedCallable<>(() -> WaterRemover_8.removeWater(b), 8), - new VersionedCallable<>(() -> WaterRemover_14.removeWater(b), 14))) + if(!FlatteningWrapper.impl.removeWater(b)) return; if(b.getY() < MIN_Y) @@ -69,10 +67,4 @@ public class WaterRemover implements Listener { checkBlock(b.getRelative(BlockFace.NORTH)); checkBlock(b.getRelative(BlockFace.SOUTH)); } - - public static boolean isWater(Block block){ - return VersionedCallable.call( - new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8), - new VersionedCallable<>(() -> WaterRemover_14.isWater(block), 14)); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/GlobalRecorder.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/GlobalRecorder.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/GlobalRecorder.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveRecorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveRecorder.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/LiveRecorder.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/LiveRecorder.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveServer.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveServer.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/LiveServer.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/LiveServer.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveSource.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/LiveSource.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/LiveSource.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java similarity index 93% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 57c53fd..1caa6c0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -29,7 +29,10 @@ import de.steamwar.fightsystem.countdown.EventSpectateCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FreezeWorld; +import de.steamwar.fightsystem.listener.BasicListener; import de.steamwar.fightsystem.listener.FightScoreboard; +import de.steamwar.fightsystem.utils.BlockIdWrapper; +import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.sql.Schematic; import de.steamwar.sql.Team; @@ -38,7 +41,6 @@ import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.*; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; @@ -62,8 +64,8 @@ public class PacketProcessor { private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); - private final Set hiddenBlockIds = TechHider.getHiddenBlockIds(); - private final int obfuscateWith = TechHider.getObfuscateWith(); + private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); + private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); private final FreezeWorld freezer = new FreezeWorld(); private boolean rotateZ = false; @@ -228,7 +230,19 @@ public class PacketProcessor { String message = source.readUTF(); BaseComponent[] text = TextComponent.fromLegacyText(message); - Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(type, text)); + Bukkit.getOnlinePlayers().forEach(p -> { + switch(type){ + case CHAT: + BountifulWrapper.impl.toChat(p, text); + break; + case SYSTEM: + p.spigot().sendMessage(text); + break; + case ACTION_BAR: + BasicListener.toActionbar(p, text); + break; + } + }); } private void arenaInfo() throws IOException { @@ -275,7 +289,7 @@ public class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - execSync(() -> setBlockInternal(x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); + execSync(() -> BlockIdWrapper.impl.setBlock(world, x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); } private void particle() throws IOException { @@ -313,11 +327,7 @@ public class PacketProcessor { Sound sound = Sound.valueOf(soundName); - execSync(() -> { - for(Player player : Bukkit.getOnlinePlayers()){ - player.playSound(player.getLocation(), sound, volume, pitch); - } - }); + execSync(() -> Fight.playSound(sound, volume, pitch)); } private void pasteSchem(FightTeam team) throws IOException { @@ -428,12 +438,6 @@ public class PacketProcessor { } } - private static void setBlockInternal(int x, int y, int z, int blockState){ - VersionedRunnable.call(new VersionedRunnable(() -> RecordSystem_8.setBlock(world, x, y, z, blockState), 8), - new VersionedRunnable(() -> RecordSystem_14.setBlock(world, x, y, z, blockState), 14), - new VersionedRunnable(() -> RecordSystem_15.setBlock(world, x, y, z, blockState), 15)); - } - private interface PacketParser{ void process() throws IOException; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketSource.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/PacketSource.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/PacketSource.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java similarity index 97% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java index 6e2d067..880b41d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java @@ -26,8 +26,8 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.*; import com.mojang.authlib.GameProfile; import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.listener.FightScoreboard; +import de.steamwar.fightsystem.utils.BlockIdWrapper; import de.steamwar.sql.SteamwarUser; import net.royawesome.jlibnoise.MathHelper; import org.bukkit.Bukkit; @@ -80,7 +80,7 @@ public class REntity { } if(entity.sneaks) { if(Core.getVersion() > 12){ - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, getPose(true))); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(true))); }else{ ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 2)); } @@ -192,7 +192,7 @@ public class REntity { sneaks = sneaking; if(Core.getVersion() > 12){ - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, getPose(sneaking))); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(sneaking))); }else{ ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, sneaking ? (byte) 2 : (byte) 0)); } @@ -370,9 +370,4 @@ public class REntity { } return namedSpawnPacket; } - - private static Object getPose(boolean sneaking){ - return VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_14.getPose(sneaking), 14), - new VersionedCallable<>(() -> RecordSystem_15.getPose(sneaking), 15)); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java similarity index 90% rename from FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java rename to FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index d9f2f40..4e6525a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -19,11 +19,15 @@ package de.steamwar.fightsystem.record; -import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.fight.*; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.utils.BlockIdWrapper; +import de.steamwar.fightsystem.utils.CraftbukkitWrapper; +import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -132,14 +136,7 @@ public interface Recorder { default void entityMoves(Entity e){ Location location = e.getLocation(); - write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (byte)(VersionedCallable.call( - new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8), - new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9), - new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10), - new VersionedCallable<>(() -> FightWorld_12.headRotation(e), 12), - new VersionedCallable<>(() -> FightWorld_14.headRotation(e), 14), - new VersionedCallable<>(() -> FightWorld_15.headRotation(e), 15) - ) * 256 / 360)); + write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (byte) (CraftbukkitWrapper.impl.headRotation(e) * 256 / 360)); } default void entityDespawns(Entity e){ @@ -201,9 +198,7 @@ public interface Recorder { } default void blockChange(Block block){ - int blockState = VersionedCallable.call(new VersionedCallable<>(() -> RecordSystem_8.blockToId(block), 8), - new VersionedCallable<>(() -> RecordSystem_14.blockToId(block), 14), - new VersionedCallable<>(() -> RecordSystem_15.blockToId(block), 15)); + int blockState = BlockIdWrapper.impl.blockToId(block); int shortX = block.getX() - Config.ArenaRegion.getMinX(); int shortY = block.getY() - Config.BluePasteRegion.getMinY(); @@ -221,8 +216,8 @@ public interface Recorder { write(0x31, x, y, z, particleType); } - default void sound(int x, int y, int z, String soundType, String soundCategory, float volume, float pitch){ - write(0x32, x, y, z, soundType, soundCategory, volume, pitch); + default void sound(int x, int y, int z, SWSound soundType, String soundCategory, float volume, float pitch){ + write(0x32, x, y, z, soundType.getSound().name(), soundCategory, volume, pitch); } default void soundAtPlayer(String soundType, float volume, float pitch){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/IStateDependent.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/IStateDependent.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/OneShotStateDependent.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/OneShotStateDependent.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependent.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependent.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCommand.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCommand.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCountdown.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCountdown.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentListener.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentListener.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentTask.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java rename to FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentTask.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java new file mode 100644 index 0000000..d293875 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -0,0 +1,42 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import de.steamwar.fightsystem.VersionDependent; +import org.bukkit.World; +import org.bukkit.block.Block; + +import java.util.Set; + +public class BlockIdWrapper { + private BlockIdWrapper() {} + + public static final IBlockIdWrapper impl = VersionDependent.getVersionImpl(BlockIdWrapper.class.getName()); + + public interface IBlockIdWrapper { + int blockToId(Block block); + void setBlock(World world, int x, int y, int z, int blockState); + + Set getHiddenBlockIds(); + int getObfuscateWith(); + + Object getPose(boolean sneaking); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java new file mode 100644 index 0000000..e6705b8 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -0,0 +1,43 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import com.comphenix.protocol.wrappers.EnumWrappers; +import de.steamwar.fightsystem.VersionDependent; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; + +public class BountifulWrapper { + private BountifulWrapper() {} + + public static final IBountifulWrapper impl = VersionDependent.getVersionImpl(BountifulWrapper.class.getName()); + + public interface IBountifulWrapper { + boolean bowInHand(EnumWrappers.Hand hand, Player p); + + void toActionbar(Player player, BaseComponent... components); + void toChat(Player player, BaseComponent... components); + + void setAttackSpeed(Player player); + + void setNametagVisibility(Team team); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ColorConverter.java similarity index 86% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/ColorConverter.java index faa10ac..32f4451 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ColorConverter.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ColorConverter.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.core.VersionedRunnable; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -47,10 +46,7 @@ public class ColorConverter { chat2dye.put(ChatColor.DARK_GREEN, DyeColor.GREEN); chat2dye.put(ChatColor.DARK_RED, DyeColor.RED); chat2dye.put(ChatColor.BLACK, DyeColor.BLACK); - //Rosa 9pink, Braun 3brown - - VersionedRunnable.call(new VersionedRunnable(() -> chat2dye.put(ChatColor.GRAY, ColorConverter_8.getSilver()), 8), - new VersionedRunnable(() -> chat2dye.put(ChatColor.GRAY, ColorConverter_14.getSilver()), 14)); + chat2dye.put(ChatColor.GRAY, FlatteningWrapper.impl.getSilver()); } public static DyeColor chat2dye(ChatColor color){ diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java similarity index 53% rename from FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java index aa34f31..a39b895 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,22 +15,25 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.utils; -import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; +import de.steamwar.fightsystem.VersionDependent; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; -import java.util.Set; +public class CraftbukkitWrapper { + private CraftbukkitWrapper() {} -public class PersonalKitCreator_8 { + public static final ICraftbukkitWrapper impl = VersionDependent.getVersionImpl(CraftbukkitWrapper.class.getName()); - public static boolean hasItems(ItemStack stack){ - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); + public interface ICraftbukkitWrapper { + void resetChunk(World world, World backup, int x, int z); + void sendResourcePack(Player player, String pack, String sha1); + float headRotation(Entity e); + boolean hasItems(ItemStack stack); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java new file mode 100644 index 0000000..a3b09e2 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java @@ -0,0 +1,53 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import de.steamwar.fightsystem.VersionDependent; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class FlatteningWrapper { + private FlatteningWrapper() {} + + public static final IFlatteningWrapper impl = VersionDependent.getVersionImpl(FlatteningWrapper.class.getName()); + + public interface IFlatteningWrapper { + DyeColor getSilver(); + + boolean isWater(Block block); + boolean removeWater(Block block); + + boolean containsBlockMeta(ItemMeta meta); + boolean hasAttributeModifier(ItemStack stack); + + Material onBreak(Material type); + + boolean doRecord(BlockPhysicsEvent e); + + void forceLoadChunk(World world, int cX, int cZ); + + boolean checkPistonMoving(Block block); + } +} diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java similarity index 90% rename from FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java index ade4044..c772ec2 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,15 +15,15 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem.utils; import com.google.common.primitives.Bytes; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.IFightSystem; -import de.steamwar.fightsystem.fight.IFight; -import de.steamwar.fightsystem.fight.IFightTeam; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -33,10 +33,10 @@ public class ITechHider { private ITechHider (){} static boolean bypass(Player p, int chunkX, int chunkZ){ - if(p == IFightSystem.getEventLeiter()) + if(p == FightSystem.getEventLeiter()) return true; - IFightTeam ft = IFight.getPlayerTeam(p); + FightTeam ft = Fight.getPlayerTeam(p); if(ft == null){ return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); }else if(ft.isBlue()){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ItemBuilder.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/ItemBuilder.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java similarity index 98% rename from FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 4f38486..809b530 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem.utils; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/SWSound.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/SWSound.java new file mode 100644 index 0000000..9d6ece4 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/SWSound.java @@ -0,0 +1,40 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import de.steamwar.fightsystem.VersionDependent; +import org.bukkit.Sound; + +public enum SWSound { + ENTITY_WITHER_DEATH, + BLOCK_NOTE_PLING, + BLOCK_NOTE_BASS, + ENTITY_GENERIC_EXPLODE; + + private static final ISWSound impl = VersionDependent.getVersionImpl(SWSound.class.getName()); + + public Sound getSound() { + return impl.getSound(this); + } + + public interface ISWSound { + Sound getSound(SWSound sound); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java similarity index 84% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java index 49e39e6..6414551 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -31,12 +31,11 @@ import com.comphenix.protocol.wrappers.ChunkCoordIntPair; import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; import com.comphenix.protocol.wrappers.WrappedBlockData; import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; import de.steamwar.core.events.ChunkListener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.IFightSystem; +import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; @@ -61,20 +60,15 @@ public class TechHider extends StateDependent { public TechHider(){ super(ENABLED, FightState.Schem); - Set hiddenBlockIds = getHiddenBlockIds(); - int obfuscateWith = getObfuscateWith(); - obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith.toUpperCase()); - chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8), - new VersionedCallable<>(() -> TechHider_12.chunkHider(hiddenBlockIds, obfuscateWith), 12), - new VersionedCallable<>(() -> TechHider_14.chunkHider(hiddenBlockIds, obfuscateWith), 14)); + chunkHider = VersionDependent.getVersionImpl(TechHider.class.getName()); if(Config.mode == ArenaMode.EVENT) threadMultiplier = 4; else threadMultiplier = 1; - Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); + Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), packetCache::clear, 1, 1); if(Core.getVersion() > 8){ protocolManager.addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) { @@ -104,15 +98,13 @@ public class TechHider extends StateDependent { protocolManager.addPacketListener(blockHider); protocolManager.addPacketListener(multiBlockHider); protocolManager.addPacketListener(blockActionHider); + protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(threadMultiplier * 4); if(Core.getVersion() > 8) { protocolManager.addPacketListener(updateBlockEntity); } if(Core.getVersion() > 12) { protocolManager.addPacketListener(blockBreakHider); } - if(chunkHider != null) { - protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(threadMultiplier * 4); - } } @Override @@ -120,18 +112,16 @@ public class TechHider extends StateDependent { protocolManager.removePacketListener(blockHider); protocolManager.removePacketListener(multiBlockHider); protocolManager.removePacketListener(blockActionHider); + protocolManager.getAsynchronousManager().unregisterAsyncHandler(chunkHider); if(Core.getVersion() > 8) { protocolManager.removePacketListener(updateBlockEntity); } if(Core.getVersion() > 12) { protocolManager.removePacketListener(blockBreakHider); } - if(chunkHider != null) { - protocolManager.getAsynchronousManager().unregisterAsyncHandler(chunkHider); - } } - private final PacketAdapter multiBlockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { + private final PacketAdapter multiBlockHider = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -168,7 +158,7 @@ public class TechHider extends StateDependent { } }; - private final PacketAdapter blockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { + private final PacketAdapter blockHider = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -196,7 +186,7 @@ public class TechHider extends StateDependent { } }; - private final PacketAdapter blockActionHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { + private final PacketAdapter blockActionHider = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -210,7 +200,7 @@ public class TechHider extends StateDependent { } }; - private final PacketAdapter blockBreakHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_BREAK) { + private final PacketAdapter blockBreakHider = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_BREAK) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -257,20 +247,6 @@ public class TechHider extends StateDependent { } }; - public static Set getHiddenBlockIds(){ - return VersionedCallable.call( - new VersionedCallable<>(TechHider_8::getHiddenBlockIds, 8), - new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), - new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); - } - - public static int getObfuscateWith(){ - return VersionedCallable.call( - new VersionedCallable<>(TechHider_8::getObfuscateWith, 8), - new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), - new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); - } - public static List prepareChunkReload(Player p, boolean hide){ if(!ENABLED) return Collections.emptyList(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java new file mode 100644 index 0000000..cc7ad07 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -0,0 +1,43 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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.utils; + +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.transform.AffineTransform; +import de.steamwar.fightsystem.VersionDependent; +import de.steamwar.sql.Schematic; +import org.bukkit.DyeColor; + +import java.io.IOException; + +public class WorldeditWrapper { + private WorldeditWrapper() {} + + public static final IWorldeditWrapper impl = VersionDependent.getVersionImpl(WorldeditWrapper.class.getName()); + + public interface IWorldeditWrapper { + void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; + void pasteSchematic(Clipboard clipboard, Region region, boolean rotate); + void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT); + Clipboard loadChar(String charName) throws IOException; + void saveSchem(Schematic schem, Region region, int minY); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java similarity index 98% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index dfc9f6d..659e3a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -22,7 +22,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java similarity index 100% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java similarity index 95% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index d548f8c..2510815 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -23,9 +23,9 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.listener.WaterRemover; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.utils.FlatteningWrapper; import org.bukkit.Bukkit; import org.bukkit.World; @@ -69,7 +69,7 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi private void check() { water = 0; team.getExtendRegion().forEach((x, y, z) -> { - if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z))) + if (FlatteningWrapper.impl.isWater(WORLD.getBlockAt(x, y, z))) water++; }); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java similarity index 95% rename from FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 604cc99..eb52f04 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2021 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 @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ package de.steamwar.fightsystem.winconditions; diff --git a/FightSystem_Main/src/plugin.yml b/FightSystem_Core/src/plugin.yml similarity index 100% rename from FightSystem_Main/src/plugin.yml rename to FightSystem_Core/src/plugin.yml diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 3083862..2cd94da 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -1,4 +1,23 @@ + + @@ -18,16 +37,6 @@ 1.0 - src - - - src - - **/*.java - **/*.kt - - - org.apache.maven.plugins @@ -47,20 +56,6 @@ - - steamwar - Spigot - 1.15 - system - ${main.basedir}/lib/Spigot-1.15.jar - - - steamwar - WorldEdit - 1.0 - system - ${main.basedir}/lib/WorldEdit-1.12.jar - steamwar FightSystem_8 @@ -99,7 +94,7 @@ steamwar - FightSystem_API + FightSystem_Core 1.0 compile diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java deleted file mode 100644 index c572101..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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.listener; - -import de.steamwar.core.VersionedRunnable; -import de.steamwar.fightsystem.fight.Fight; -import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.entity.Player; - -public class BasicListener { - private BasicListener(){} - - public static boolean notFighting(Player p){ - return Fight.getFightPlayer(p) == null; - } - - public static void toActionbar(Player player, BaseComponent... components){ - VersionedRunnable.call(new VersionedRunnable(() -> BasicListener_8.toActionbar(player, components), 8), - new VersionedRunnable(() -> BasicListener_9.toActionbar(player, components), 9)); - } - - public static void toChat(Player player, BaseComponent... components){ - VersionedRunnable.call(new VersionedRunnable(() -> BasicListener_8.toChat(player, components), 8), - new VersionedRunnable(() -> BasicListener_9.toChat(player, components), 9)); - } - - public static void setAttackSpeed(Player player){ - VersionedRunnable.call(new VersionedRunnable(() -> BasicListener_9.setAttackSpeed(player), 9)); - } -} diff --git a/pom.xml b/pom.xml index 455d1b6..da93e94 100644 --- a/pom.xml +++ b/pom.xml @@ -26,17 +26,37 @@ 1.8 + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + false + + + + src + + + src + + **/*.java + **/*.kt + + + - FightSystem_API FightSystem_8 FightSystem_9 FightSystem_10 FightSystem_12 FightSystem_14 FightSystem_15 + FightSystem_Core FightSystem_Main From 765a9e4f6ca3b15d6fc8edba088ebb9197a75ec1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Aug 2021 11:19:56 +0200 Subject: [PATCH 20/33] Reduce overhead and add a World of Colors! Signed-off-by: Lixfel --- .../fightsystem/fight/FightTeam12.java | 31 ------------------ .../WorldOfColorWrapper12.java} | 10 ++++-- .../fightsystem/listener/ArrowPickup8.java | 25 --------------- .../listener/DenyWorldInteraction8.java | 25 --------------- .../fightsystem/utils/BountifulWrapper8.java | 11 +++++++ .../WorldOfColorWrapper8.java} | 11 +++++-- .../fightsystem/listener/ArrowPickup9.java | 32 ------------------- .../listener/DenyWorldInteraction9.java | 32 ------------------- .../fightsystem/utils/BountifulWrapper9.java | 24 ++++++++++++++ .../steamwar/fightsystem/fight/FightTeam.java | 14 ++------ .../fightsystem/listener/ArrowPickup.java | 4 +-- .../fightsystem/listener/ArrowStopper.java | 6 ++-- .../listener/DenyWorldInteraction.java | 4 +-- .../fightsystem/utils/BountifulWrapper.java | 4 +++ .../utils/WorldOfColorWrapper.java | 24 ++++++++------ 15 files changed, 78 insertions(+), 179 deletions(-) delete mode 100644 FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java rename FightSystem_12/src/de/steamwar/fightsystem/{listener/ArrowStopper12.java => utils/WorldOfColorWrapper12.java} (75%) delete mode 100644 FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java delete mode 100644 FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java rename FightSystem_8/src/de/steamwar/fightsystem/{listener/ArrowStopper8.java => utils/WorldOfColorWrapper8.java} (73%) delete mode 100644 FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java delete mode 100644 FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java rename FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java => FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java (61%) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java deleted file mode 100644 index 7f24260..0000000 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - 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.fight; - -import org.bukkit.ChatColor; -import org.bukkit.scoreboard.Team; - -public class FightTeam12 implements FightTeam.IFightTeam { - - @Override - public void setTeamColor(Team team, ChatColor color){ - team.setColor(color); - } -} diff --git a/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java similarity index 75% rename from FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java rename to FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java index 08b42cc..1c3e416 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java @@ -17,11 +17,17 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.utils; +import org.bukkit.ChatColor; import org.bukkit.entity.Arrow; +import org.bukkit.scoreboard.Team; -public class ArrowStopper12 implements ArrowStopper.IArrowStopper { +public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorWrapper { + @Override + public void setTeamColor(Team team, ChatColor color) { + team.setColor(color); + } @Override public boolean isInBlock(Arrow e) { diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java deleted file mode 100644 index f5a9c7e..0000000 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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.listener; - -import org.bukkit.event.Listener; - -public class ArrowPickup8 implements Listener { -} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java deleted file mode 100644 index db0b29c..0000000 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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.listener; - -import org.bukkit.event.Listener; - -public class DenyWorldInteraction8 implements Listener { -} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java index 6d9c805..b09a3df 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -26,6 +26,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutChat; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import org.bukkit.scoreboard.Team; public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { @@ -55,4 +56,14 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { public void setNametagVisibility(Team team) { //nothing to do } + + @Override + public Listener newDenyArrowPickupListener() { + return new Listener() {}; + } + + @Override + public Listener newDenyHandSwapListener() { + return new Listener() {}; + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java similarity index 73% rename from FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java index 1c1c96c..79be18a 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java @@ -17,11 +17,18 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.utils; +import org.bukkit.ChatColor; import org.bukkit.entity.Arrow; +import org.bukkit.scoreboard.Team; + +public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWrapper { + @Override + public void setTeamColor(Team team, ChatColor color) { + team.setPrefix("§" + color.getChar()); + } -public class ArrowStopper8 implements ArrowStopper.IArrowStopper { @Override public boolean isInBlock(Arrow e) { return false; diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java deleted file mode 100644 index 28ce13b..0000000 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - 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.listener; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerPickupArrowEvent; - -public class ArrowPickup9 implements Listener { - - @EventHandler - public void onArrowPickup(PlayerPickupArrowEvent e){ - e.setCancelled(true); - } -} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java deleted file mode 100644 index c5c6733..0000000 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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.listener; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; - -public class DenyWorldInteraction9 implements Listener { - - @EventHandler - public void onSwapItems(PlayerSwapHandItemsEvent event) { - event.setCancelled(true); - } -} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index ba721de..5bc1d10 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -26,6 +26,10 @@ import org.bukkit.Material; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupArrowEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.scoreboard.Team; public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @@ -55,4 +59,24 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { public void setNametagVisibility(Team team) { team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); } + + @Override + public Listener newDenyArrowPickupListener() { + return new Listener() { + @EventHandler + public void onArrowPickup(PlayerPickupArrowEvent e){ + e.setCancelled(true); + } + }; + } + + @Override + public Listener newDenyHandSwapListener() { + return new Listener() { + @EventHandler + public void onSwapItems(PlayerSwapHandItemsEvent event) { + event.setCancelled(true); + } + }; + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index fab2aea..37a705c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -24,17 +24,13 @@ import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.utils.BountifulWrapper; -import de.steamwar.fightsystem.utils.ItemBuilder; -import de.steamwar.fightsystem.utils.Region; -import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.fightsystem.utils.*; import de.steamwar.inventory.SWItem; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; @@ -50,8 +46,6 @@ import java.util.*; public class FightTeam { - private static final IFightTeam impl = VersionDependent.getVersionImpl(FightTeam.class.getName()); - private UUID designatedLeader; private FightPlayer leader; private final Map players = new HashMap<>(); @@ -89,7 +83,7 @@ public class FightTeam { else team = FightScoreboard.getBukkit().getTeam(name); assert team != null; - impl.setTeamColor(team, color); + WorldOfColorWrapper.impl.setTeamColor(team, color); BountifulWrapper.impl.setNametagVisibility(team); //noinspection deprecation team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); @@ -406,10 +400,6 @@ public class FightTeam { return color; } - public interface IFightTeam { - void setTeamColor(Team team, ChatColor color); - } - private class KitLoader extends StateDependent { private KitLoader() { super(ArenaMode.AntiReplay, FightState.Ingame); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java index ccf9acd..6839a3f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java @@ -20,13 +20,13 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.BountifulWrapper; public class ArrowPickup { public ArrowPickup() { - new StateDependentListener(ArenaMode.All, FightState.All, VersionDependent.getVersionImpl(ArrowPickup.class.getName())); + new StateDependentListener(ArenaMode.All, FightState.All, BountifulWrapper.impl.newDenyArrowPickupListener()); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 47fcecf..1e286e9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -20,9 +20,9 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.utils.WorldOfColorWrapper; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -37,8 +37,6 @@ public class ArrowStopper { private static final Vector NULL_VECTOR = new Vector(0, 0, 0); private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; - private static final IArrowStopper impl = VersionDependent.getVersionImpl(ArrowStopper.class.getName()); - public ArrowStopper() { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } @@ -93,7 +91,7 @@ public class ArrowStopper { boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ(); boolean otherSide = teamFrom == overMid; return otherSide || - impl.isInBlock(entity) || + WorldOfColorWrapper.impl.isInBlock(entity) || entity.getVelocity().equals(NULL_VECTOR); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java index 998f8cb..579d303 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java @@ -20,9 +20,9 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.BountifulWrapper; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -41,7 +41,7 @@ public class DenyWorldInteraction implements Listener { new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this); new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this); - Listener listener = VersionDependent.getVersionImpl(DenyWorldInteraction.class.getName()); + Listener listener = BountifulWrapper.impl.newDenyHandSwapListener(); new StateDependentListener(ArenaMode.Test, FightState.PreRunning, listener); new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, listener); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index e6705b8..f205977 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -23,6 +23,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import de.steamwar.fightsystem.VersionDependent; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import org.bukkit.scoreboard.Team; public class BountifulWrapper { @@ -39,5 +40,8 @@ public class BountifulWrapper { void setAttackSpeed(Player player); void setNametagVisibility(Team team); + + Listener newDenyArrowPickupListener(); + Listener newDenyHandSwapListener(); } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java similarity index 61% rename from FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java index de213b8..f1a3bce 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,18 +15,22 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; +import de.steamwar.fightsystem.VersionDependent; import org.bukkit.ChatColor; +import org.bukkit.entity.Arrow; import org.bukkit.scoreboard.Team; -public class FightTeam8 implements FightTeam.IFightTeam { +public class WorldOfColorWrapper { + private WorldOfColorWrapper() {} - @Override - public void setTeamColor(Team team, ChatColor color){ - team.setPrefix("§" + color.getChar()); + public static final IWorldOfColorWrapper impl = VersionDependent.getVersionImpl(WorldOfColorWrapper.class.getName()); + + public interface IWorldOfColorWrapper { + void setTeamColor(Team team, ChatColor color); + boolean isInBlock(Arrow e); } - } From f61c6cbf6d60b573b24171cdf67bd9b2447061da Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Aug 2021 12:09:34 +0200 Subject: [PATCH 21/33] Full 1.8 compilation support Signed-off-by: Lixfel --- .../utils/WorldOfColorWrapper12.java | 8 +++ .../fightsystem/utils/BountifulWrapper8.java | 20 ++++++++ .../utils/WorldOfColorWrapper8.java | 7 +++ .../fightsystem/utils/BountifulWrapper9.java | 31 ++++++++++++ .../de/steamwar/fightsystem/FightSystem.java | 15 ++++-- .../fightsystem/commands/WinCommand.java | 7 ++- .../fightsystem/countdown/Countdown.java | 2 +- .../countdown/TimeOverCountdown.java | 5 +- .../fightsystem/event/HellsBells.java | 4 +- .../fightsystem/fight/FightSchematic.java | 2 +- .../steamwar/fightsystem/fight/FightTeam.java | 2 +- .../fightsystem/fight/FreezeWorld.java | 12 ++--- .../fightsystem/listener/IngameDeath.java | 7 ++- .../fightsystem/listener/Recording.java | 49 +++++++------------ .../fightsystem/record/PacketProcessor.java | 13 ++--- .../fightsystem/utils/BountifulWrapper.java | 6 +++ .../fightsystem/utils/FightStatistics.java | 4 +- .../utils/WorldOfColorWrapper.java | 4 ++ .../EventTeamOffWincondition.java | 5 +- .../RankedPlayerLeftWincondition.java | 3 +- .../winconditions/WinconditionAllDead.java | 3 +- .../WinconditionCaptainDead.java | 3 +- .../WinconditionHeartRatioTimeout.java | 7 ++- .../WinconditionPercentSystem.java | 3 +- .../WinconditionPercentTimeout.java | 7 ++- .../winconditions/WinconditionPoints.java | 9 ++-- .../WinconditionPumpkinTechKO.java | 2 +- .../WinconditionRelativePercent.java | 2 +- .../winconditions/WinconditionTimeTechKO.java | 2 +- .../winconditions/WinconditionTimeout.java | 3 +- .../WinconditionWaterTechKO.java | 2 +- 31 files changed, 153 insertions(+), 96 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java index 1c3e416..deef5e6 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java @@ -20,6 +20,9 @@ package de.steamwar.fightsystem.utils; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.entity.Arrow; import org.bukkit.scoreboard.Team; @@ -33,4 +36,9 @@ public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorW public boolean isInBlock(Arrow e) { return e.isInBlock(); } + + @Override + public void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch) { + location.getWorld().playSound(location, sound, SoundCategory.valueOf(soundCategory), volume, pitch); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java index b09a3df..50ff9ea 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -20,10 +20,15 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.wrappers.EnumWrappers; +import de.steamwar.fightsystem.listener.Recording; +import de.steamwar.fightsystem.record.GlobalRecorder; import net.md_5.bungee.api.chat.BaseComponent; import net.minecraft.server.v1_8_R3.ChatComponentText; import net.minecraft.server.v1_8_R3.PacketPlayOutChat; +import org.bukkit.Effect; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -66,4 +71,19 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { public Listener newDenyHandSwapListener() { return new Listener() {}; } + + @Override + public void recordHandItems(Player player) { + GlobalRecorder.getInstance().item(player, Recording.disarmNull(player.getInventory().getItemInHand()), "MAINHAND"); + } + + @Override + public Listener newHandSwapRecorder() { + return new Listener() {}; + } + + @Override + public void spawnParticle(World world, String particleName, double x, double y, double z) { + world.playEffect(new Location(world, x, y, z), Effect.valueOf(particleName), 1); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java index 79be18a..dfe0228 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java @@ -20,6 +20,8 @@ package de.steamwar.fightsystem.utils; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.entity.Arrow; import org.bukkit.scoreboard.Team; @@ -33,4 +35,9 @@ public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWr public boolean isInBlock(Arrow e) { return false; } + + @Override + public void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch) { + location.getWorld().playSound(location, sound, volume, pitch); + } } diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 5bc1d10..12312f9 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -20,13 +20,18 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.wrappers.EnumWrappers; +import de.steamwar.fightsystem.listener.Recording; +import de.steamwar.fightsystem.record.GlobalRecorder; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerPickupArrowEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent; @@ -79,4 +84,30 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { } }; } + + @Override + public void recordHandItems(Player player) { + GlobalRecorder.getInstance().item(player, Recording.disarmNull(player.getInventory().getItemInMainHand()), "MAINHAND"); + GlobalRecorder.getInstance().item(player, Recording.disarmNull(player.getInventory().getItemInOffHand()), "OFFHAND"); + } + + @Override + public Listener newHandSwapRecorder() { + return new Listener() { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onItemSwap(PlayerSwapHandItemsEvent e){ + if(Recording.isNotSent(e.getPlayer())) + return; + + Player player = e.getPlayer(); + GlobalRecorder.getInstance().item(player, Recording.disarmNull(e.getMainHandItem()), "MAINHAND"); + GlobalRecorder.getInstance().item(player, Recording.disarmNull(e.getOffHandItem()), "OFFHAND"); + } + }; + } + + @Override + public void spawnParticle(World world, String particleName, double x, double y, double z) { + world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 2927bda..e578353 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -129,8 +129,8 @@ public class FightSystem extends JavaPlugin { new LiveRecorder(); new FileRecorder(); - new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!")); - new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!")); + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreRunning, () -> FightSystem.broadcast("§aDer Kampf beginnt!")); + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Running, () -> FightSystem.broadcast("§aArena freigegeben!")); new OneShotStateDependent(ArenaMode.AntiTest, FightState.Running, FightStatistics::start); try { @@ -187,9 +187,9 @@ public class FightSystem extends JavaPlugin { public static void setSpectateState(FightTeam winFightTeam, String windescription) { if(!PacketProcessor.isReplaying()){ if(winFightTeam != null) { - Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); + FightSystem.broadcast("§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); } else { - Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); + FightSystem.broadcast("§aKein Team hat gewonnen!"); } } @@ -231,11 +231,16 @@ public class FightSystem extends JavaPlugin { public static void shutdown(String reason){ if(reason != null) - Bukkit.broadcastMessage(reason); + FightSystem.broadcast(reason); //Staggered kick to prevent lobby overloading kickNext(); } + public static void broadcast(String message) { + Bukkit.broadcastMessage(PREFIX + message); + GlobalRecorder.getInstance().systemChat(PREFIX + message); + } + private static void kickNext(){ if(Bukkit.getOnlinePlayers().isEmpty()){ Bukkit.shutdown(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java index 90aafa6..d2a18ea 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java @@ -5,7 +5,6 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -35,13 +34,13 @@ public class WinCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase(Fight.getBlueTeam().getName())){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Kampfleiter hat den Kampf entschieden!"); + FightSystem.broadcast("§cDer Kampfleiter hat den Kampf entschieden!"); FightSystem.setSpectateState(Fight.getBlueTeam(), "Referee"); }else if(args[0].equalsIgnoreCase(Fight.getRedTeam().getName())){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Kampfleiter hat den Kampf entschieden!"); + FightSystem.broadcast("§cDer Kampfleiter hat den Kampf entschieden!"); FightSystem.setSpectateState(Fight.getRedTeam(), "Referee"); }else if(args[0].equalsIgnoreCase("tie")){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Kampfleiter hat den Kampf entschieden!"); + FightSystem.broadcast("§cDer Kampfleiter hat den Kampf entschieden!"); FightSystem.setSpectateState(null, "Referee"); } return false; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java index f847bb9..565bd04 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -86,7 +86,7 @@ public abstract class Countdown { countdown.show(); } - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aBeide Teams waren damit einverstanden, zum nächsten Event zu beschleunigen!"); + FightSystem.broadcast("§aBeide Teams waren damit einverstanden, zum nächsten Event zu beschleunigen!"); } private void broadcast(String message){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index a45e12c..30659cb 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -19,10 +19,9 @@ package de.steamwar.fightsystem.countdown; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.utils.SWSound; -import org.bukkit.Bukkit; public class TimeOverCountdown extends Countdown { @@ -40,7 +39,7 @@ public class TimeOverCountdown extends Countdown { @Override public void countdownFinished() { - Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!"); + FightSystem.broadcast("§aZeit abgelaufen!"); timeOver.run(); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java index 72a7b40..a19a3ae 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java @@ -63,10 +63,10 @@ public class HellsBells { public void startCountdown() { if (current == State.PRE) { - Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); + FightSystem.broadcast(startMessages.get(random.nextInt(startMessages.size()))); current = current.getNext(); } else if (current != State.LAST && currentDrops >= current.SWITCH_AFTER) { - Bukkit.broadcastMessage(FightSystem.PREFIX + (stateSwapMessages.get(random.nextInt(stateSwapMessages.size())))); + FightSystem.broadcast(stateSwapMessages.get(random.nextInt(stateSwapMessages.size()))); currentDrops = 0; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index a9a1bcb..474b9ef 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -128,7 +128,7 @@ public class FightSchematic extends StateDependent { replaceTeamColor(clipboard); WorldeditWrapper.impl.pasteSchematic(clipboard, region, rotate); } catch (WorldEditException e) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); + FightSystem.broadcast("§cFehler beim Pasten der Schematic"); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); throw new SecurityException("Could not paste schematic", e); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 37a705c..3bd0840 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -245,7 +245,7 @@ public class FightTeam { this.leader = null; if(!players.isEmpty()) { setLeader(players.values().iterator().next()); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); + FightSystem.broadcast("§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); }else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){ Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java index f3aa5d3..b94fc72 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FreezeWorld.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.utils.BountifulWrapper; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,15 +29,19 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.*; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; public class FreezeWorld implements Listener { + + private final Listener denyHandSwap = BountifulWrapper.impl.newDenyHandSwapListener(); + public FreezeWorld(){ Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); + Bukkit.getPluginManager().registerEvents(denyHandSwap, FightSystem.getPlugin()); } public void disable(){ HandlerList.unregisterAll(this); + HandlerList.unregisterAll(denyHandSwap); } @EventHandler @@ -79,11 +84,6 @@ public class FreezeWorld implements Listener { e.setCancelled(true); } - @EventHandler - public void handlePlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) { - event.setCancelled(true); - } - @EventHandler(priority = EventPriority.LOW) public void handlePlayerInteract(PlayerInteractEvent event) { event.setCancelled(true); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java index 89b3b3c..154ed42 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java @@ -21,14 +21,13 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.utils.SWSound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -52,7 +51,7 @@ public class IngameDeath implements Listener { if(team == null) return; - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §cist gestorben!"); + FightSystem.broadcast("§cDer Spieler " + team.getPrefix() + player.getName() + " §cist gestorben!"); Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F); team.getFightPlayer(player).setOut(); } @@ -68,7 +67,7 @@ public class IngameDeath implements Listener { FightPlayer fightPlayer = team.getFightPlayer(player); if(fightPlayer.isLiving()) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); + FightSystem.broadcast("§cDer Spieler " + team.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); team.getFightPlayer(player).setOut(); GlobalRecorder.getInstance().entityDespawns(player); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 86d4377..94d8182 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -38,7 +38,10 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.SWSound; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -50,7 +53,6 @@ import org.bukkit.event.entity.*; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.*; -import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.inventory.ItemStack; import java.util.Random; @@ -83,8 +85,20 @@ public class Recording implements Listener { } }; + public static ItemStack disarmNull(ItemStack stack){ + if(stack == null) + return new ItemStack(Material.AIR); + return stack; + } + + public static boolean isNotSent(Player p){ + FightPlayer fp = Fight.getFightPlayer(p); + return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; + } + public Recording() { new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.All, BountifulWrapper.impl.newHandSwapRecorder()); new StateDependent(ArenaMode.AntiReplay, FightState.Ingame){ @Override public void enable() { @@ -143,11 +157,6 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entityDespawns(e.getEntity()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBroadcast(BroadcastMessageEvent e){ - GlobalRecorder.getInstance().systemChat(e.getMessage()); - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPhysics(BlockPhysicsEvent e){ if(FlatteningWrapper.impl.doRecord(e)) @@ -213,7 +222,7 @@ public class Recording implements Listener { Location loc = e.getLocation(); GlobalRecorder.getInstance().entityDespawns(e.getEntity()); - GlobalRecorder.getInstance().particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_HUGE.name()); + GlobalRecorder.getInstance().particle(loc.getX(), loc.getY(), loc.getZ(), "EXPLOSION_HUGE"); GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), SWSound.ENTITY_GENERIC_EXPLODE, EnumWrappers.SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); } @@ -225,16 +234,6 @@ public class Recording implements Listener { GlobalRecorder.getInstance().item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND"); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onItemSwap(PlayerSwapHandItemsEvent e){ - if(isNotSent(e.getPlayer())) - return; - - Player player = e.getPlayer(); - GlobalRecorder.getInstance().item(player, disarmNull(e.getMainHandItem()), "MAINHAND"); - GlobalRecorder.getInstance().item(player, disarmNull(e.getOffHandItem()), "OFFHAND"); - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onProjectileSpawn(ProjectileLaunchEvent e){ if(e.getEntityType() == EntityType.FIREBALL) @@ -277,8 +276,7 @@ public class Recording implements Listener { continue; Player player = fp.getPlayer(); - GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getItemInMainHand()), "MAINHAND"); - GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getItemInOffHand()), "OFFHAND"); + BountifulWrapper.impl.recordHandItems(player); GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getHelmet()), "HEAD"); GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getChestplate()), "CHEST"); GlobalRecorder.getInstance().item(player, disarmNull(player.getInventory().getLeggings()), "LEGS"); @@ -286,12 +284,6 @@ public class Recording implements Listener { } } - private ItemStack disarmNull(ItemStack stack){ - if(stack == null) - return new ItemStack(Material.AIR); - return stack; - } - private void despawnTeam(FightTeam team){ for(FightPlayer player : team.getPlayers()){ if(player.isLiving()) @@ -303,9 +295,4 @@ public class Recording implements Listener { for(TNTPrimed tnt : Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)) GlobalRecorder.getInstance().entityDespawns(tnt); } - - private boolean isNotSent(Player p){ - FightPlayer fp = Fight.getFightPlayer(p); - return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; - } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 1caa6c0..c8d0845 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -21,7 +21,6 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; -import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -34,12 +33,16 @@ import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.BlockIdWrapper; import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.fightsystem.utils.WorldOfColorWrapper; import de.steamwar.sql.Schematic; import de.steamwar.sql.Team; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitTask; @@ -296,10 +299,9 @@ public class PacketProcessor { double x = source.readDouble(); double y = source.readDouble(); double z = source.readDouble(); - String particleName = source.readUTF(); - execSync(() -> world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1)); + execSync(() -> BountifulWrapper.impl.spawnParticle(world, particleName, x, y, z)); } private void sound() throws IOException { @@ -314,9 +316,8 @@ public class PacketProcessor { float pitch = source.readFloat(); Sound sound = Sound.valueOf(soundName); - SoundCategory sCategory = SoundCategory.valueOf(soundCategory); - execSync(() -> world.playSound(new Location(world, x, y, z), sound, sCategory, volume, pitch)); + execSync(() -> WorldOfColorWrapper.impl.playSound(new Location(world, x, y, z), sound, soundCategory, volume, pitch)); } private void soundAtPlayer() throws IOException { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index f205977..261c83f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.wrappers.EnumWrappers; import de.steamwar.fightsystem.VersionDependent; import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.scoreboard.Team; @@ -43,5 +44,10 @@ public class BountifulWrapper { Listener newDenyArrowPickupListener(); Listener newDenyHandSwapListener(); + + void recordHandItems(Player player); + Listener newHandSwapRecorder(); + + void spawnParticle(World world, String particleName, double x, double y, double z); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 3075e68..9c9eacf 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -115,8 +115,8 @@ public class FightStatistics { int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)); Elo.setElo(blueLeader, gameMode, newBlueElo); Elo.setElo(redLeader, gameMode, newRedElo); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + SteamwarUser.get(blueLeader).getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + SteamwarUser.get(redLeader).getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo); + FightSystem.broadcast("§7ELO von " + Fight.getBlueTeam().getPrefix() + SteamwarUser.get(blueLeader).getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); + FightSystem.broadcast("§7ELO von " + Fight.getRedTeam().getPrefix() + SteamwarUser.get(redLeader).getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java index f1a3bce..6d17a26 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java @@ -21,6 +21,8 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.VersionDependent; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.entity.Arrow; import org.bukkit.scoreboard.Team; @@ -32,5 +34,7 @@ public class WorldOfColorWrapper { public interface IWorldOfColorWrapper { void setTeamColor(Team team, ChatColor color); boolean isInBlock(Arrow e); + + void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index 1366fbf..fc8e9c9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import org.bukkit.Bukkit; public class EventTeamOffWincondition extends Wincondition{ @@ -35,7 +34,7 @@ public class EventTeamOffWincondition extends Wincondition{ @Override public void enable() { if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cBeide Teams sind offline!"); + FightSystem.broadcast("§cBeide Teams sind offline!"); win(null); }else{ teamOff(Fight.getBlueTeam()); @@ -52,7 +51,7 @@ public class EventTeamOffWincondition extends Wincondition{ private void teamOff(FightTeam team){ if(team.allPlayersOut()){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDas Team " + team.getColoredName() + " §cist offline!"); + FightSystem.broadcast("§cDas Team " + team.getColoredName() + " §cist offline!"); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java index 34c5fc2..56f849f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -46,7 +45,7 @@ public class RankedPlayerLeftWincondition extends Wincondition implements Listen return; if(team.isPlayerLeader(player)) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + team.getColoredName() + " §chat den Kampf verlassen!"); + FightSystem.broadcast("§cDer Leader von " + team.getColoredName() + " §chat den Kampf verlassen!"); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index 263c2b6..572d1ee 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -24,7 +24,6 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -54,7 +53,7 @@ public class WinconditionAllDead extends Wincondition implements Listener { return; if(team.allPlayersOut()) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + team.getColoredName() + message); + FightSystem.broadcast("§cDer letzte Spieler aus " + team.getColoredName() + message); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index b1e406b..9a1bd7d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -24,7 +24,6 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -54,7 +53,7 @@ public class WinconditionCaptainDead extends Wincondition implements Listener { return; if(team.isPlayerLeader(player)) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + team.getColoredName() + message); + FightSystem.broadcast("§cDer Leader von " + team.getColoredName() + message); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java index 73608ea..3e71579 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; -import org.bukkit.Bukkit; public class WinconditionHeartRatioTimeout extends Wincondition { @@ -41,13 +40,13 @@ public class WinconditionHeartRatioTimeout extends Wincondition { double redHeartRatio = Fight.getRedTeam().getHeartRatio(); if(blueHeartRatio > redHeartRatio) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen, und Team " + Fight.getBlueTeam().getColoredName() + " §chatte mehr verbleibende Leben!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen, und Team " + Fight.getBlueTeam().getColoredName() + " §chatte mehr verbleibende Leben!"); win(Fight.getBlueTeam()); }else if(blueHeartRatio < redHeartRatio){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen, und Team " + Fight.getRedTeam().getColoredName() + " §chatte mehr verbleibende Leben!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen, und Team " + Fight.getRedTeam().getColoredName() + " §chatte mehr verbleibende Leben!"); win(Fight.getRedTeam()); }else{ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!"); win(null); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 4b4dd1d..7a2f730 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -93,7 +92,7 @@ public class WinconditionPercentSystem extends Wincondition implements Listener, destroyedBlocks += event.blockList().size(); percent = (double)destroyedBlocks * 100 / volume; if(percent >= Config.PercentWin) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!"); + FightSystem.broadcast("§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!"); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java index c8f343b..be67855 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; -import org.bukkit.Bukkit; public class WinconditionPercentTimeout extends Wincondition { @@ -41,13 +40,13 @@ public class WinconditionPercentTimeout extends Wincondition { double redPercent = Wincondition.percentWincondition.getPercent(Fight.getRedTeam()); if(bluePercent > redPercent) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen, und Team " + Fight.getRedTeam().getColoredName() + " §chat weniger Schaden erlitten!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen, und Team " + Fight.getRedTeam().getColoredName() + " §chat weniger Schaden erlitten!"); win(Fight.getRedTeam()); }else if(bluePercent < redPercent){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen, und Team " + Fight.getBlueTeam().getColoredName() + " §chat weniger Schaden erlitten!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen, und Team " + Fight.getBlueTeam().getColoredName() + " §chat weniger Schaden erlitten!"); win(Fight.getBlueTeam()); }else{ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden erlitten!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden erlitten!"); win(null); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 421188e..52ac282 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -28,7 +28,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentCountdown; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -71,13 +70,13 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond int bluePoints = teamMap.get(Fight.getBlueTeam()).getPoints(); if(bluePoints < redPoints) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDas Team " + Fight.getRedTeam().getColoredName() + " §chat mehr Punkte!"); + FightSystem.broadcast("§cDas Team " + Fight.getRedTeam().getColoredName() + " §chat mehr Punkte!"); win(Fight.getRedTeam()); }else if(bluePoints > redPoints){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDas Team " + Fight.getBlueTeam().getColoredName() + " §chat mehr Punkte!"); + FightSystem.broadcast("§cDas Team " + Fight.getBlueTeam().getColoredName() + " §chat mehr Punkte!"); win(Fight.getBlueTeam()); }else{ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cBeide Teams haben gleich viele Punkte!"); + FightSystem.broadcast("§cBeide Teams haben gleich viele Punkte!"); win(null); } } @@ -100,7 +99,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond TeamPoints enemy = teamMap.get(Fight.getOpposite(team)); if(team.isPlayerLeader(player)) { enemy.points += 500; - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + team.getColoredName() + message); + FightSystem.broadcast("§cDer Leader von " + team.getColoredName() + message); timeOver(); }else if(team.getPlayers().size() <= 5) enemy.points += 300; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 54c3447..4fda590 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -77,7 +77,7 @@ public class WinconditionPumpkinTechKO extends Wincondition implements Printable }); if(pumpkins == 0) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDas Team " + team.getColoredName() + " §cist Tech K.O.!"); + FightSystem.broadcast("§cDas Team " + team.getColoredName() + " §cist Tech K.O.!"); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index db34dec..fd2b511 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -99,7 +99,7 @@ public class WinconditionRelativePercent extends Wincondition implements Printab return; if(getPercent() >= Config.PercentWin){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!"); + FightSystem.broadcast("§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!"); FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent"); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index 659e3a4..3a61db5 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -121,7 +121,7 @@ public class WinconditionTimeTechKO extends Wincondition { @Override public void countdownFinished() { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu lange nicht geschossen!"); + FightSystem.broadcast("§cTeam " + team.getColoredName() + " §chat zu lange nicht geschossen!"); win(Fight.getOpposite(team)); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index a14fd79..e6d8a3f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -24,7 +24,6 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; -import org.bukkit.Bukkit; public class WinconditionTimeout extends Wincondition { @@ -36,7 +35,7 @@ public class WinconditionTimeout extends Wincondition { } protected void timeOver() { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDie Zeit ist abgelaufen!"); + FightSystem.broadcast("§cDie Zeit ist abgelaufen!"); win(null); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 2510815..f6f2c5b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -74,7 +74,7 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi }); if(water == 0){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §cwurde Tech K.O. gesetzt!"); + FightSystem.broadcast("§cTeam " + team.getColoredName() + " §cwurde Tech K.O. gesetzt!"); win(Fight.getOpposite(team)); } } From 1c428cdacc13fcc5baa639140f269578e500d916 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Aug 2021 12:12:54 +0200 Subject: [PATCH 22/33] Remove ITechHider Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider12.java | 16 +-- .../fightsystem/utils/TechHider14.java | 20 ++-- .../fightsystem/utils/ITechHider.java | 101 ------------------ .../steamwar/fightsystem/utils/TechHider.java | 80 ++++++++++++-- 4 files changed, 92 insertions(+), 125 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java index 3f4ec39..f554505 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider12.java @@ -37,7 +37,7 @@ import java.util.List; import java.util.Set; import java.util.logging.Level; -import static de.steamwar.fightsystem.utils.ITechHider.bypass; +import static de.steamwar.fightsystem.utils.TechHider.bypass; public class TechHider12 extends PacketAdapter { @@ -85,28 +85,28 @@ public class TechHider12 extends PacketAdapter { buffer.writeByte(bitsPerBlock); if(bitsPerBlock != 13){ - int paletteLength = ITechHider.readVarInt(data, i); - int paletteLengthLength = ITechHider.readVarIntLength(data, i); + int paletteLength = TechHider.readVarInt(data, i); + int paletteLengthLength = TechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int entry = ITechHider.readVarInt(data, i); - i += ITechHider.readVarIntLength(data, i); + int entry = TechHider.readVarInt(data, i); + i += TechHider.readVarIntLength(data, i); if(hiddenBlockIds.contains(entry)){ entry = obfuscateWith; changed = true; } - buffer.writeBytes(ITechHider.writeVarInt(entry)); + buffer.writeBytes(TechHider.writeVarInt(entry)); } }else{ buffer.writeByte(data[++i]); //Empty palette Bukkit.getLogger().log(Level.SEVERE, "Full chunk occured"); } - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + int dataArrayLength = TechHider.readVarInt(data, i); + int dataArrayLengthLength = TechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); i += dataArrayLengthLength; i += dataArrayLength * 8; diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java index 8f6cff3..78100f1 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java @@ -37,7 +37,7 @@ import java.nio.LongBuffer; import java.util.List; import java.util.Set; -import static de.steamwar.fightsystem.utils.ITechHider.bypass; +import static de.steamwar.fightsystem.utils.TechHider.bypass; public class TechHider14 extends PacketAdapter { @@ -97,16 +97,16 @@ public class TechHider14 extends PacketAdapter { buffer.writeByte(bitsPerBlock); if(bitsPerBlock < 9){ - int paletteLength = ITechHider.readVarInt(data, i); - int paletteLengthLength = ITechHider.readVarIntLength(data, i); + int paletteLength = TechHider.readVarInt(data, i); + int paletteLengthLength = TechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int blockId = ITechHider.readVarInt(data, i); - int actPaletteLength = ITechHider.readVarIntLength(data, i); + int blockId = TechHider.readVarInt(data, i); + int actPaletteLength = TechHider.readVarIntLength(data, i); if(hiddenBlockIds.contains(blockId)){ - buffer.writeBytes(ITechHider.writeVarInt(obfuscateWith)); + buffer.writeBytes(TechHider.writeVarInt(obfuscateWith)); changed = true; }else{ buffer.writeBytes(data, i, actPaletteLength); @@ -115,15 +115,15 @@ public class TechHider14 extends PacketAdapter { } //We modify only the chunk palette for performance reasons - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + int dataArrayLength = TechHider.readVarInt(data, i); + int dataArrayLengthLength = TechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); i += dataArrayLengthLength; i += dataArrayLength * 8; }else{ //Full Chunk/no palette, so the chunk has to be crawled through - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + int dataArrayLength = TechHider.readVarInt(data, i); + int dataArrayLengthLength = TechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLengthLength); i += dataArrayLengthLength; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java deleted file mode 100644 index c772ec2..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ITechHider.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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.utils; - -import com.google.common.primitives.Bytes; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -public class ITechHider { - private ITechHider (){} - - static boolean bypass(Player p, int chunkX, int chunkZ){ - if(p == FightSystem.getEventLeiter()) - return true; - - FightTeam ft = Fight.getPlayerTeam(p); - if(ft == null){ - return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); - }else if(ft.isBlue()){ - return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); - }else{ - return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); - } - } - - public static int posToChunk(int c){ - int chunk = c / 16; - if(c<0) - chunk--; - return chunk; - } - - static int readVarInt(byte[] array, int startPos) { - int numRead = 0; - int result = 0; - byte read; - do { - read = array[startPos + numRead]; - int value = (read & 0b01111111); - result |= (value << (7 * numRead)); - - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return result; - } - - static int readVarIntLength(byte[] array, int startPos) { - int numRead = 0; - byte read; - do { - read = array[startPos + numRead]; - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return numRead; - } - - static byte[] writeVarInt(int value) { - List buffer = new ArrayList<>(5); - 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; - } - buffer.add(temp); - } while (value != 0); - return Bytes.toArray(buffer); - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java index 6414551..f0b0f5c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -30,12 +30,15 @@ import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.ChunkCoordIntPair; import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; import com.comphenix.protocol.wrappers.WrappedBlockData; +import com.google.common.primitives.Bytes; import de.steamwar.core.Core; import de.steamwar.core.events.ChunkListener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.VersionDependent; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; @@ -45,8 +48,6 @@ import org.bukkit.entity.Player; import java.util.*; -import static de.steamwar.fightsystem.utils.ITechHider.bypass; - public class TechHider extends StateDependent { public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; @@ -165,7 +166,7 @@ public class TechHider extends StateDependent { BlockPosition pos = packet.getBlockPositionModifier().read(0); Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ()))) return; PacketContainer cached = packetCache.get(packet); @@ -193,7 +194,7 @@ public class TechHider extends StateDependent { BlockPosition pos = packet.getBlockPositionModifier().read(0); Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ()))) return; e.setCancelled(true); @@ -207,7 +208,7 @@ public class TechHider extends StateDependent { BlockPosition pos = packet.getBlockPositionModifier().read(0); Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ()))) return; @@ -236,7 +237,7 @@ public class TechHider extends StateDependent { BlockPosition pos = packet.getBlockPositionModifier().read(0); Player p = event.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ()))) return; // 9 == Set sign text @@ -269,6 +270,73 @@ public class TechHider extends StateDependent { }, 40); } + static boolean bypass(Player p, int chunkX, int chunkZ){ + if(p == FightSystem.getEventLeiter()) + return true; + + FightTeam ft = Fight.getPlayerTeam(p); + if(ft == null){ + return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); + }else if(ft.isBlue()){ + return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); + }else{ + return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); + } + } + + private static int posToChunk(int c){ + int chunk = c / 16; + if(c<0) + chunk--; + return chunk; + } + + static int readVarInt(byte[] array, int startPos) { + int numRead = 0; + int result = 0; + byte read; + do { + read = array[startPos + numRead]; + int value = (read & 0b01111111); + result |= (value << (7 * numRead)); + + numRead++; + if (numRead > 5) { + break; + } + } while ((read & 0b10000000) != 0); + + return result; + } + + static int readVarIntLength(byte[] array, int startPos) { + int numRead = 0; + byte read; + do { + read = array[startPos + numRead]; + numRead++; + if (numRead > 5) { + break; + } + } while ((read & 0b10000000) != 0); + + return numRead; + } + + static byte[] writeVarInt(int value) { + List buffer = new ArrayList<>(5); + 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; + } + buffer.add(temp); + } while (value != 0); + return Bytes.toArray(buffer); + } + public static class ChunkPos{ final int x; final int z; From eae23123c8d61a269687e34d3f144d0ba989d822 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Aug 2021 17:01:45 +0200 Subject: [PATCH 23/33] Worldedit refactoring Signed-off-by: Lixfel --- .../fightsystem/utils/WorldeditWrapper12.java | 38 +----- .../fightsystem/utils/WorldeditWrapper14.java | 108 ++++++++---------- .../fightsystem/utils/WorldeditWrapper8.java | 107 ++++++++--------- .../de/steamwar/fightsystem/FightSystem.java | 6 +- .../de/steamwar/fightsystem/fight/Fight.java | 4 + .../fightsystem/fight/FightSchematic.java | 103 +++++++---------- .../steamwar/fightsystem/fight/FightTeam.java | 6 +- .../fightsystem/listener/PrepareSchem.java | 13 +-- .../fightsystem/utils/WorldeditWrapper.java | 5 +- 9 files changed, 151 insertions(+), 239 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java index 25be503..7dd977b 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldeditWrapper12.java @@ -19,44 +19,14 @@ package de.steamwar.fightsystem.utils; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import org.bukkit.DyeColor; import org.bukkit.Material; +@SuppressWarnings("deprecation") public class WorldeditWrapper12 extends WorldeditWrapper8 { - @SuppressWarnings("deprecation") - private static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData(); - - @SuppressWarnings("deprecation") - private static final BaseBlock CONCRETE = new BaseBlock(Material.CONCRETE.getId(), COLOR_TO_REPLACE); - @SuppressWarnings("deprecation") - private static final BaseBlock CONCRETE_POWDER = new BaseBlock(Material.CONCRETE_POWDER.getId(), COLOR_TO_REPLACE); - - @SuppressWarnings("deprecation") - @Override - public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { - super.replaceTeamColor(clipboard, c); - - Vector minimum = clipboard.getRegion().getMinimumPoint(); - BaseBlock concrete = new BaseBlock(CONCRETE.getId(), c.getWoolData()); - BaseBlock concretePowder = new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData()); - - for(int x = 0; x < clipboard.getDimensions().getX(); x++){ - for(int y = 0; y < clipboard.getDimensions().getY(); y++){ - for(int z = 0; z < clipboard.getDimensions().getZ(); z++){ - Vector pos = minimum.add(x, y, z); - BaseBlock block = clipboard.getBlock(pos); - if(block.equals(CONCRETE)){ - clipboard.setBlock(pos, concrete); - }else if(block.equals(CONCRETE_POWDER)){ - clipboard.setBlock(pos, concretePowder); - } - } - } - } + static { + colorBlocks.add(new BaseBlock(Material.CONCRETE.getId(), COLOR_TO_REPLACE)); + colorBlocks.add(new BaseBlock(Material.CONCRETE_POWDER.getId(), COLOR_TO_REPLACE)); } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index aa19d25..6b2ae67 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -23,6 +23,7 @@ import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -43,55 +44,44 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.DyeColor; +import org.bukkit.Location; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.zip.GZIPInputStream; public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { - private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); - private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); - private static final BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(); - private static final BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(); - private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(); - private static final BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(); - private static final BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(); + private static final Map colorBlocks = new HashMap<>(); + + static { + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(), "_wool"); + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(), "_terracotta"); + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(), "_stained_glass"); + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(), "_stained_glass_pane"); + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(), "_concrete"); + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(), "_concrete_powder"); + colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(), "_carpet"); + } @Override public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); - BaseBlock wool = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock(); - BaseBlock clay = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock(); - BaseBlock glass = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock(); - BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock(); - BaseBlock carpet = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock(); - BaseBlock concrete = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_concrete")).getDefaultState().toBaseBlock(); - BaseBlock concretePowder = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_concrete_powder")).getDefaultState().toBaseBlock(); + Map replaceMap = new HashMap<>(); + colorBlocks.forEach((base, postfix) -> replaceMap.put(base, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + postfix)).getDefaultState().toBaseBlock())); for(int x = 0; x < clipboard.getDimensions().getX(); x++){ for(int y = 0; y < clipboard.getDimensions().getY(); y++){ for(int z = 0; z < clipboard.getDimensions().getZ(); z++){ BlockVector3 pos = minimum.add(x, y, z); - BaseBlock block = clipboard.getFullBlock(pos); - if(block.equals(WOOL)){ - clipboard.setBlock(pos, wool); - }else if(block.equals(CLAY)){ - clipboard.setBlock(pos, clay); - }else if(block.equals(GLASS)){ - clipboard.setBlock(pos, glass); - }else if(block.equals(GLASS_PANE)){ - clipboard.setBlock(pos, glassPane); - }else if(block.equals(CARPET)){ - clipboard.setBlock(pos, carpet); - }else if(block.equals(CONCRETE)){ - clipboard.setBlock(pos, concrete); - }else if(block.equals(CONCRETE_POWDER)){ - clipboard.setBlock(pos, concretePowder); - } + BaseBlock replacement = replaceMap.get(clipboard.getFullBlock(pos)); + if(replacement != null) + clipboard.setBlock(pos, replacement); } } } @@ -99,22 +89,18 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { @Override public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { - BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); - - World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); BlockVector3 dimensions = clipboard.getDimensions(); - BlockVector3 v; - BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - AffineTransform aT = new AffineTransform(); + BlockVector3 v = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); if(rotate){ - aT = aT.rotateY(180); - v = paste.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); + v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(1, 0, 1); }else{ - v = paste.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset); + v = v.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2); } + v = v.subtract(aT.apply(clipboardOffset(clipboard).toVector3()).toBlockPoint()); if(Config.WaterDepth != 0){ - BlockVector3 it = clipboard.getMinimumPoint(); + BlockVector3 it = clipboard.getMinimumPoint().add(0, 0, 1); int depth = 0; while(!clipboard.getBlock(it).getBlockType().getMaterial().isAir()){ depth++; @@ -123,24 +109,24 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { v = v.add(0, Config.WaterDepth - depth, 0); } - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); - ClipboardHolder ch = new ClipboardHolder(clipboard); - ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e).to(v).build()); - e.flushSession(); + pasteClipboard(Bukkit.getWorlds().get(0), clipboard, aT, v, false); } @Override - public void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT) { - BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); - BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); - v = aT.apply(v.toVector3()).toBlockPoint(); - v = v.add(x, y, z); + public void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT) { + BlockVector3 v = aT.apply(BlockVector3.at(xOffset, 0, 0).subtract(clipboardOffset(character)).toVector3()).toBlockPoint(); + pasteClipboard(pos.getWorld(), character, aT, v.add(BukkitAdapter.asBlockVector(pos)), true); + } - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1); - ClipboardHolder ch = new ClipboardHolder(character); + private BlockVector3 clipboardOffset(Clipboard clipboard) { + return clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); + } + + private void pasteClipboard(org.bukkit.World world, Clipboard clipboard, AffineTransform aT, BlockVector3 pos, boolean ignoreAir) { + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1); + ClipboardHolder ch = new ClipboardHolder(clipboard); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build()); + Operations.completeBlindly(ch.createPaste(e).to(pos).ignoreAirBlocks(ignoreAir).build()); e.flushSession(); } @@ -150,21 +136,17 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { } @Override - public void saveSchem(Schematic schem, Region region, int minY) { + public void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); BlockVector3 min = BlockVector3.at(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ())); BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); - ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min); + ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy( + WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1), cuboidRegion, clipboard, min + ); forwardExtentCopy.setCopyingEntities(false); - - try{ - Operations.complete(forwardExtentCopy); - }catch(WorldEditException e){ - throw new IllegalStateException(e); - } + Operations.complete(forwardExtentCopy); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { @@ -172,7 +154,7 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { writer.write(clipboard); writer.close(); } catch (IOException e) { - throw new IllegalStateException(e); + throw new SecurityException(e); } schem.saveFromBytes(outputStream.toByteArray(), true); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index d12b387..f3c17e3 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -42,56 +42,46 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.DyeColor; +import org.bukkit.Location; import org.bukkit.Material; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.zip.GZIPInputStream; +@SuppressWarnings("deprecation") public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { - @SuppressWarnings("deprecation") - private static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData(); + protected static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData(); + protected static final Set colorBlocks = new HashSet<>(); - @SuppressWarnings("deprecation") - private static final BaseBlock WOOL = new BaseBlock(Material.WOOL.getId(), COLOR_TO_REPLACE); - @SuppressWarnings("deprecation") - private static final BaseBlock GLASS = new BaseBlock(Material.STAINED_GLASS.getId(), COLOR_TO_REPLACE); - @SuppressWarnings("deprecation") - private static final BaseBlock CLAY = new BaseBlock(Material.CLAY.getId(), COLOR_TO_REPLACE); - @SuppressWarnings("deprecation") - private static final BaseBlock GLASS_PANE = new BaseBlock(Material.STAINED_GLASS_PANE.getId(), COLOR_TO_REPLACE); - @SuppressWarnings("deprecation") - private static final BaseBlock CARPET = new BaseBlock(Material.CARPET.getId(), COLOR_TO_REPLACE); + static { + colorBlocks.add(new BaseBlock(Material.WOOL.getId(), COLOR_TO_REPLACE)); + colorBlocks.add(new BaseBlock(Material.STAINED_GLASS.getId(), COLOR_TO_REPLACE)); + colorBlocks.add(new BaseBlock(Material.CLAY.getId(), COLOR_TO_REPLACE)); + colorBlocks.add(new BaseBlock(Material.STAINED_GLASS_PANE.getId(), COLOR_TO_REPLACE)); + colorBlocks.add(new BaseBlock(Material.CARPET.getId(), COLOR_TO_REPLACE)); + } - @SuppressWarnings("deprecation") @Override public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException { Vector minimum = clipboard.getRegion().getMinimumPoint(); - BaseBlock wool = new BaseBlock(WOOL.getId(), c.getWoolData()); - BaseBlock clay = new BaseBlock(CLAY.getId(), c.getWoolData()); - BaseBlock glass = new BaseBlock(GLASS.getId(), c.getWoolData()); - BaseBlock glassPane = new BaseBlock(GLASS_PANE.getId(), c.getWoolData()); - BaseBlock carpet = new BaseBlock(CARPET.getId(), c.getWoolData()); + Map replaceMap = new HashMap<>(); + colorBlocks.forEach(base -> replaceMap.put(base, new BaseBlock(base.getId(), c.getWoolData()))); for(int x = 0; x < clipboard.getDimensions().getX(); x++){ for(int y = 0; y < clipboard.getDimensions().getY(); y++){ for(int z = 0; z < clipboard.getDimensions().getZ(); z++){ Vector pos = minimum.add(x, y, z); - BaseBlock block = clipboard.getBlock(pos); - if(block.equals(WOOL)){ - clipboard.setBlock(pos, wool); - }else if(block.equals(CLAY)){ - clipboard.setBlock(pos, clay); - }else if(block.equals(GLASS)){ - clipboard.setBlock(pos, glass); - }else if(block.equals(GLASS_PANE)){ - clipboard.setBlock(pos, glassPane); - }else if(block.equals(CARPET)){ - clipboard.setBlock(pos, carpet); - } + BaseBlock replacement = replaceMap.get(clipboard.getBlock(pos)); + if(replacement != null) + clipboard.setBlock(pos, replacement); } } } @@ -99,47 +89,45 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { @Override public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { - World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); Vector dimensions = clipboard.getDimensions(); Vector v = new Vector(region.centerX(), region.getMinY(), region.centerZ()); - Vector offset = clipboard.getMinimumPoint().subtract(clipboard.getOrigin()); - AffineTransform aT = new AffineTransform(); if(rotate){ - aT = aT.rotateY(180); - v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); + v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(1, 0, 1); }else{ - v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); + v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2); } + v = v.subtract(aT.apply(clipboardOffset(clipboard)).toBlockPoint()); if(Config.WaterDepth != 0){ - Vector it = clipboard.getMinimumPoint(); + Vector it = clipboard.getMinimumPoint().add(0, 0, 1); int depth = 0; - while(!clipboard.getBlock(it).isAir()){ + while(!clipboard.getBlock(it).isAir()) { depth++; - it = it.setY(it.getY()+1); + it = it.add(0, 1, 0); } v = v.add(0, Config.WaterDepth - depth, 0); } - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); - ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); - ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); - e.flushQueue(); + pasteClipboard(Bukkit.getWorlds().get(0), clipboard, aT, v, false); } @Override - public void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT) { - World w = new BukkitWorld(Bukkit.getWorlds().get(0)); - Vector offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); - Vector v = Vector.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); - v = aT.apply(v).toBlockPoint(); - v = v.add(x, y, z); + public void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT) { + Vector v = aT.apply(new Vector(xOffset, 0, 0).subtract(clipboardOffset(character))).toBlockPoint(); + pasteClipboard(pos.getWorld(), character, aT, v.add(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), true); + } + private Vector clipboardOffset(Clipboard clipboard) { + return clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); + } + + private void pasteClipboard(org.bukkit.World world, Clipboard clipboard, AffineTransform aT, Vector pos, boolean ignoreAir) { + World w = new BukkitWorld(world); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); - ClipboardHolder ch = new ClipboardHolder(character, w.getWorldData()); + ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); + Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(pos).ignoreAirBlocks(ignoreAir).build()); e.flushQueue(); } @@ -149,19 +137,16 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { } @Override - public void saveSchem(Schematic schem, Region region, int minY) { + public void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector min = new Vector(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ())); BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); - ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min); - try{ - Operations.complete(forwardExtentCopy); - }catch(WorldEditException e){ - throw new IllegalStateException(e); - } + ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy( + WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1), cuboidRegion, clipboard, min + ); + Operations.complete(forwardExtentCopy); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { @@ -169,7 +154,7 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { writer.write(clipboard, w.getWorldData()); writer.close(); } catch (IOException e) { - throw new IllegalStateException(e); + throw new SecurityException(e); } schem.saveFromBytes(outputStream.toByteArray(), false); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index e578353..12c713d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -145,11 +145,7 @@ public class FightSystem extends JavaPlugin { }else if(Config.mode == ArenaMode.CHECK){ Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); }else if(Config.mode == ArenaMode.PREPARE) { - if(Config.BlueRotate){ - Fight.getRedTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); - }else{ - Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); - } + Fight.getUnrotated().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); }else if(Config.mode == ArenaMode.REPLAY) { FightWorld.forceLoad(); FileSource.startReplay(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 7ea0ee2..4033521 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -88,6 +88,10 @@ public class Fight { return blueTeam; } + public static FightTeam getUnrotated() { + return Config.BlueRotate ? Fight.getRedTeam() : Fight.getBlueTeam(); + } + public static void playSound(Sound sound, float volume, float pitch) { GlobalRecorder.getInstance().soundAtPlayer(sound.name(), volume, pitch); //volume: max. 100, pitch: max. 2 diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 474b9ef..7c81d40 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -32,15 +32,11 @@ import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; import de.steamwar.sql.Schematic; -import org.bukkit.Bukkit; -import org.bukkit.DyeColor; -import org.bukkit.Material; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.event.HandlerList; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.logging.Level; @@ -62,7 +58,7 @@ public class FightSchematic extends StateDependent { register(); } - public boolean hasSchematic(){ + public boolean hasSchematic() { return clipboard != null; } @@ -75,7 +71,7 @@ public class FightSchematic extends StateDependent { try { clipboard = schem.load(); } catch (IOException e) { - team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!"); + team.broadcast(FightSystem.PREFIX + "§cSchematic konnte nicht geladen werden!"); Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getSchemName()); } } @@ -137,60 +133,6 @@ public class FightSchematic extends StateDependent { Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } - private Clipboard loadTextSchem(String schemName) throws IOException { - return WorldeditWrapper.impl.loadChar(schemName); - } - - public void pasteTeamName(){ - List characters = new ArrayList<>(); - for(char c : team.getName().toCharArray()){ - try { - characters.add(loadTextSchem(c == '/' ? "slash" : String.valueOf(c))); - } catch (IOException e) { - Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", c); - try { - characters.add(loadTextSchem("")); - }catch (IOException ex) { - throw new SecurityException("Could not load text", ex); - } - } - } - - //Calc character sizes - int[] lengthes = new int[characters.size()]; - for(int i = 0; i < lengthes.length; i++) - lengthes[i] = characters.get(i).getDimensions().getBlockX(); - - //Calc character offsets - int[] offsets = new int[lengthes.length]; - int previousOffset = 0; - for(int i = 0; i < offsets.length; i++){ - offsets[i] = previousOffset; - previousOffset += lengthes[i] + 1; // 1 is the distance between characters - } - - int length = lengthes.length == 0 ? 0 : lengthes[lengthes.length - 1] + offsets[offsets.length - 1]; - - int z = team.getSchemRegion().centerZ(); - AffineTransform aT = new AffineTransform(); - - if(rotate){ - aT = aT.rotateY(180); - z += team.getSchemRegion().getSizeZ() / 2; - }else{ - z -= team.getSchemRegion().getSizeZ() / 2; - } - - for(int i = 0; i < characters.size(); i++){ - try { - replaceTeamColor(characters.get(i)); - } catch (WorldEditException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e); - } - WorldeditWrapper.impl.pasteChar(characters.get(i), offsets[i], length, team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), z, aT); - } - } - @Override public void disable() { if(!Config.ReplaceObsidianBedrock) @@ -207,6 +149,45 @@ public class FightSchematic extends StateDependent { HandlerList.unregisterAll(freezer); } + public void pasteTeamName(){ + char[] chars = team.getName().toCharArray(); + Clipboard[] characters = new Clipboard[chars.length]; + + int length = 0; + int[] offsets = new int[chars.length]; + + for(int i = 0; i < chars.length; i++){ + Clipboard character; + try { + character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i])); + } catch (IOException e) { + Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", chars[i]); + try { + character = WorldeditWrapper.impl.loadChar(""); + }catch (IOException ex) { + throw new SecurityException("Could not load text", ex); + } + } + + try { + replaceTeamColor(character); + } catch (WorldEditException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e); + } + + characters[i] = character; + offsets[i] = length; + length += character.getDimensions().getBlockX() + 1; // 1 is the distance between characters + } + + length -= 1; + AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); + Location base = new Location(Bukkit.getWorlds().get(0), team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), team.getSchemRegion().centerZ() + (rotate ? 1 : -1) * team.getSchemRegion().getSizeZ() / 2); + for(int i = 0; i < characters.length; i++){ + WorldeditWrapper.impl.pasteChar(characters[i], base, offsets[i] - length/2, aT); + } + } + private void replaceSync(Material target, Material replacement){ World world = Bukkit.getWorlds().get(0); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 3bd0840..0f80fe0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -305,7 +305,7 @@ public class FightTeam { private void testPasteAction(){ if(Config.test()) this.schematic.enable(); - else if(Fight.getOpposite(this).hasSchematic()){ + else if(Fight.getOpposite(this).schematic.hasSchematic()){ FightSystem.setPostSchemState(); } } @@ -319,10 +319,6 @@ public class FightTeam { broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); } - public boolean hasSchematic(){ - return schematic.hasSchematic(); - } - public void setReady(boolean ready) { Player l = leader.getPlayer(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index e1a39ad..f20057f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.listener; +import com.sk89q.worldedit.WorldEditException; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -45,8 +46,8 @@ public class PrepareSchem implements Listener { public void disable() { super.disable(); World world = Bukkit.getWorlds().get(0); - Region region = Config.BlueRotate ? Fight.getRedTeam().getExtendRegion() : Fight.getBlueTeam().getExtendRegion(); - int minY = Config.BlueRotate ? Fight.getRedTeam().getSchemRegion().getMinY() : Fight.getBlueTeam().getSchemRegion().getMinY(); + Region region = Fight.getUnrotated().getExtendRegion(); + int minY = Fight.getUnrotated().getSchemRegion().getMinY(); Schematic schem; try{ @@ -69,7 +70,7 @@ public class PrepareSchem implements Listener { try{ WorldeditWrapper.impl.saveSchem(schem, region, minY); - }catch(IllegalStateException e){ + }catch(WorldEditException e){ FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen."); throw new SecurityException("Could not save schem", e); } @@ -86,11 +87,7 @@ public class PrepareSchem implements Listener { FightTeam team = Fight.getPlayerTeam(player); if (team == null) { - if(Config.BlueRotate){ - Fight.getRedTeam().addMember(player); - }else{ - Fight.getBlueTeam().addMember(player); - } + Fight.getUnrotated().addMember(player); } if(FightState.getFightState() == FightState.PRE_LEADER_SETUP) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index cc7ad07..4d1585a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import de.steamwar.fightsystem.VersionDependent; import de.steamwar.sql.Schematic; import org.bukkit.DyeColor; +import org.bukkit.Location; import java.io.IOException; @@ -36,8 +37,8 @@ public class WorldeditWrapper { public interface IWorldeditWrapper { void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; void pasteSchematic(Clipboard clipboard, Region region, boolean rotate); - void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT); + void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT); Clipboard loadChar(String charName) throws IOException; - void saveSchem(Schematic schem, Region region, int minY); + void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException; } } From 453dea774e35e2a79609c605aa95f1293f8ea65e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Sep 2021 16:50:41 +0200 Subject: [PATCH 24/33] Unify WE offset calculation Signed-off-by: Lixfel --- .../fightsystem/utils/WorldeditWrapper14.java | 47 +++++-------------- .../fightsystem/utils/WorldeditWrapper8.java | 46 +++++------------- .../fightsystem/fight/FightSchematic.java | 16 +++++-- .../steamwar/fightsystem/record/Recorder.java | 32 +++++++------ .../fightsystem/utils/WorldeditWrapper.java | 5 +- 5 files changed, 59 insertions(+), 87 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 6b2ae67..8f1c317 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -39,12 +39,12 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; +import org.bukkit.util.Vector; import java.io.ByteArrayOutputStream; import java.io.File; @@ -88,45 +88,24 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { } @Override - public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { - AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); - BlockVector3 dimensions = clipboard.getDimensions(); - BlockVector3 v = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); - if(rotate){ - v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(1, 0, 1); - }else{ - v = v.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2); + public int getWaterDepth(Clipboard clipboard) { + BlockVector3 it = clipboard.getMinimumPoint().add(0, 0, 1); + int depth = 0; + while(!clipboard.getBlock(it).getBlockType().getMaterial().isAir()){ + depth++; + it = it.add(0, 1, 0); } - v = v.subtract(aT.apply(clipboardOffset(clipboard).toVector3()).toBlockPoint()); - - if(Config.WaterDepth != 0){ - BlockVector3 it = clipboard.getMinimumPoint().add(0, 0, 1); - int depth = 0; - while(!clipboard.getBlock(it).getBlockType().getMaterial().isAir()){ - depth++; - it = it.add(0, 1, 0); - } - v = v.add(0, Config.WaterDepth - depth, 0); - } - - pasteClipboard(Bukkit.getWorlds().get(0), clipboard, aT, v, false); + return depth; } @Override - public void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT) { - BlockVector3 v = aT.apply(BlockVector3.at(xOffset, 0, 0).subtract(clipboardOffset(character)).toVector3()).toBlockPoint(); - pasteClipboard(pos.getWorld(), character, aT, v.add(BukkitAdapter.asBlockVector(pos)), true); - } - - private BlockVector3 clipboardOffset(Clipboard clipboard) { - return clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - } - - private void pasteClipboard(org.bukkit.World world, Clipboard clipboard, AffineTransform aT, BlockVector3 pos, boolean ignoreAir) { - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1); + public void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT) { + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(position.getWorld()), -1); ClipboardHolder ch = new ClipboardHolder(clipboard); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e).to(pos).ignoreAirBlocks(ignoreAir).build()); + Operations.completeBlindly(ch.createPaste(e).to(BukkitAdapter.asBlockVector(position).add( + aT.apply(BlockVector3.at(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint()).toVector3()).toBlockPoint() + )).build()); e.flushSession(); } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index f3c17e3..ad3ea1e 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -37,7 +37,6 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -88,46 +87,25 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { } @Override - public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) { - AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); - Vector dimensions = clipboard.getDimensions(); - Vector v = new Vector(region.centerX(), region.getMinY(), region.centerZ()); - if(rotate){ - v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(1, 0, 1); - }else{ - v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2); + public int getWaterDepth(Clipboard clipboard) { + Vector it = clipboard.getMinimumPoint().add(0, 0, 1); + int depth = 0; + while(!clipboard.getBlock(it).isAir()) { + depth++; + it = it.add(0, 1, 0); } - v = v.subtract(aT.apply(clipboardOffset(clipboard)).toBlockPoint()); - - if(Config.WaterDepth != 0){ - Vector it = clipboard.getMinimumPoint().add(0, 0, 1); - int depth = 0; - while(!clipboard.getBlock(it).isAir()) { - depth++; - it = it.add(0, 1, 0); - } - v = v.add(0, Config.WaterDepth - depth, 0); - } - - pasteClipboard(Bukkit.getWorlds().get(0), clipboard, aT, v, false); + return depth; } @Override - public void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT) { - Vector v = aT.apply(new Vector(xOffset, 0, 0).subtract(clipboardOffset(character))).toBlockPoint(); - pasteClipboard(pos.getWorld(), character, aT, v.add(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), true); - } - - private Vector clipboardOffset(Clipboard clipboard) { - return clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - } - - private void pasteClipboard(org.bukkit.World world, Clipboard clipboard, AffineTransform aT, Vector pos, boolean ignoreAir) { - World w = new BukkitWorld(world); + public void pasteClipboard(Clipboard clipboard, Location position, org.bukkit.util.Vector offset, AffineTransform aT) { + World w = new BukkitWorld(position.getWorld()); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(pos).ignoreAirBlocks(ignoreAir).build()); + Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(new Vector(position.getBlockX(), position.getBlockY(), position.getBlockZ()).add( + aT.apply(new Vector(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint())).toBlockPoint() + )).build()); e.flushQueue(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7c81d40..64cdf2e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -35,6 +35,7 @@ import de.steamwar.sql.Schematic; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.event.HandlerList; +import org.bukkit.util.Vector; import java.io.IOException; import java.util.List; @@ -122,7 +123,16 @@ public class FightSchematic extends StateDependent { try { replaceTeamColor(clipboard); - WorldeditWrapper.impl.pasteSchematic(clipboard, region, rotate); + WorldeditWrapper.impl.pasteClipboard( + clipboard, + new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()), + new Vector( + -clipboard.getDimensions().getBlockX()/2, + Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, + -clipboard.getDimensions().getBlockZ()/2 + ), + new AffineTransform().rotateY(rotate ? 180 : 0) + ); } catch (WorldEditException e) { FightSystem.broadcast("§cFehler beim Pasten der Schematic"); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); @@ -182,9 +192,9 @@ public class FightSchematic extends StateDependent { length -= 1; AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); - Location base = new Location(Bukkit.getWorlds().get(0), team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), team.getSchemRegion().centerZ() + (rotate ? 1 : -1) * team.getSchemRegion().getSizeZ() / 2); + Location base = new Location(Bukkit.getWorlds().get(0), region.centerX(), team.getExtendRegion().getMaxY(), region.centerZ()); for(int i = 0; i < characters.length; i++){ - WorldeditWrapper.impl.pasteChar(characters[i], base, offsets[i] - length/2, aT); + WorldeditWrapper.impl.pasteClipboard(characters[i], base, new Vector(offsets[i] - length/2, 0, region.getSizeZ()/2), aT); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 4e6525a..c98e21d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -38,10 +38,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.util.logging.Level; public interface Recorder { @@ -249,16 +246,23 @@ public interface Recorder { } default void schem(int embedId, int noEmbedId, int schemId){ - try { - if(schemId == 0) - throw new IOException(); - - write(embedId, schemId, Schematic.getSchemFromDB(schemId).schemData()); - } catch (IOException e) { - if(schemId != 0) - Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); + if(schemId == 0) { write(noEmbedId, schemId); + return; } + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + try{ + copy(Schematic.getSchemFromDB(schemId).schemData(), buffer); + }catch (EOFException e) { + Bukkit.getLogger().log(Level.INFO, "EOFException ignored"); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not embed schematic", e); + disable(); + return; + } + + write(embedId, schemId, buffer.toByteArray()); } default void scoreboardTitle(String title){ @@ -292,8 +296,8 @@ public interface Recorder { stream.writeDouble((Double)o); else if(o instanceof String) stream.writeUTF((String)o); - else if(o instanceof InputStream) - copy((InputStream) o, stream); + else if(o instanceof byte[]) + stream.write((byte[])o); else throw new SecurityException("Undefined write for: " + o.getClass().getName()); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index 4d1585a..0edf2e9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.VersionDependent; import de.steamwar.sql.Schematic; import org.bukkit.DyeColor; import org.bukkit.Location; +import org.bukkit.util.Vector; import java.io.IOException; @@ -36,8 +37,8 @@ public class WorldeditWrapper { public interface IWorldeditWrapper { void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; - void pasteSchematic(Clipboard clipboard, Region region, boolean rotate); - void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT); + int getWaterDepth(Clipboard clipboard); + void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT); Clipboard loadChar(String charName) throws IOException; void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException; } From 5826f7e8b199e4eb3e55210f0eaa3e0a3d4b941e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Sep 2021 17:27:00 +0200 Subject: [PATCH 25/33] Fix dimensions Signed-off-by: Lixfel --- .../fightsystem/utils/WorldeditWrapper14.java | 6 +++ .../fightsystem/utils/WorldeditWrapper8.java | 6 +++ .../fightsystem/fight/FightSchematic.java | 46 +++++++++---------- .../fightsystem/utils/WorldeditWrapper.java | 1 + 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 8f1c317..bb5b450 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -109,6 +109,12 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { e.flushSession(); } + @Override + public Vector getDimensions(Clipboard clipboard) { + BlockVector3 dims = clipboard.getDimensions(); + return new Vector(dims.getX(), dims.getY(), dims.getZ()); + } + @Override public Clipboard loadChar(String charName) throws IOException { return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schem"))))).read(); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index ad3ea1e..0969655 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -109,6 +109,12 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { e.flushQueue(); } + @Override + public org.bukkit.util.Vector getDimensions(Clipboard clipboard) { + Vector dims = clipboard.getDimensions(); + return new org.bukkit.util.Vector(dims.getBlockX(), dims.getBlockY(), dims.getBlockZ()); + } + @Override public Clipboard loadChar(String charName) throws IOException { return new SchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schematic"))))).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData()); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 64cdf2e..c7f465c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -114,30 +114,30 @@ public class FightSchematic extends StateDependent { Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); } - private void replaceTeamColor(Clipboard clipboard) throws WorldEditException { - WorldeditWrapper.impl.replaceTeamColor(clipboard, ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK); + private void replaceTeamColor(Clipboard clipboard) { + try { + WorldeditWrapper.impl.replaceTeamColor(clipboard, ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK); + } catch (WorldEditException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not recolor schematic", e); + } } private void paste(){ FreezeWorld freezer = new FreezeWorld(); - try { - replaceTeamColor(clipboard); - WorldeditWrapper.impl.pasteClipboard( - clipboard, - new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()), - new Vector( - -clipboard.getDimensions().getBlockX()/2, - Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, - -clipboard.getDimensions().getBlockZ()/2 - ), - new AffineTransform().rotateY(rotate ? 180 : 0) - ); - } catch (WorldEditException e) { - FightSystem.broadcast("§cFehler beim Pasten der Schematic"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); - throw new SecurityException("Could not paste schematic", e); - } + replaceTeamColor(clipboard); + + Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); + WorldeditWrapper.impl.pasteClipboard( + clipboard, + new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()), + new Vector( + -dims.getBlockX()/2, + Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, + -dims.getBlockZ()/2 + ), + new AffineTransform().rotateY(rotate ? 180 : 0) + ); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); @@ -179,15 +179,11 @@ public class FightSchematic extends StateDependent { } } - try { - replaceTeamColor(character); - } catch (WorldEditException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e); - } + replaceTeamColor(character); characters[i] = character; offsets[i] = length; - length += character.getDimensions().getBlockX() + 1; // 1 is the distance between characters + length += WorldeditWrapper.impl.getDimensions(character).getBlockX() + 1; // 1 is the distance between characters } length -= 1; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index 0edf2e9..d96df0a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -39,6 +39,7 @@ public class WorldeditWrapper { void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; int getWaterDepth(Clipboard clipboard); void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT); + Vector getDimensions(Clipboard clipboard); Clipboard loadChar(String charName) throws IOException; void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException; } From 0556b9de9a42aabf49fa08f3f470f994b7676a57 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Sep 2021 11:23:10 +0200 Subject: [PATCH 26/33] Fix one off offsets with doubles + aligned pasting Signed-off-by: Lixfel --- .../fightsystem/utils/WorldeditWrapper14.java | 7 ++++--- .../fightsystem/utils/WorldeditWrapper8.java | 6 +++--- .../src/de/steamwar/fightsystem/Config.java | 13 +++++++------ .../steamwar/fightsystem/fight/FightSchematic.java | 4 ++-- .../src/de/steamwar/fightsystem/utils/Region.java | 12 ++++++++---- .../fightsystem/winconditions/Winconditions.java | 4 ++++ 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index bb5b450..a91d4eb 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; @@ -103,9 +104,9 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(position.getWorld()), -1); ClipboardHolder ch = new ClipboardHolder(clipboard); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e).to(BukkitAdapter.asBlockVector(position).add( - aT.apply(BlockVector3.at(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint()).toVector3()).toBlockPoint() - )).build()); + Operations.completeBlindly(ch.createPaste(e).to(BukkitAdapter.asVector(position).add( + aT.apply(Vector3.at(offset.getX(), offset.getY(), offset.getZ()).add(clipboard.getOrigin().toVector3()).subtract(clipboard.getMinimumPoint().toVector3())) + ).toBlockPoint()).build()); e.flushSession(); } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 0969655..2264f2b 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -103,9 +103,9 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(new Vector(position.getBlockX(), position.getBlockY(), position.getBlockZ()).add( - aT.apply(new Vector(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint())).toBlockPoint() - )).build()); + Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(new Vector(position.getX(), position.getY(), position.getZ()).add( + aT.apply(new Vector(offset.getX(), offset.getY(), offset.getZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint())) + ).toBlockPoint()).build()); e.flushQueue(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index ac9b04d..8f09b06 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -61,9 +61,9 @@ public class Config { public static final Location TeamRedSpawn; public static final Location SpecSpawn; - private static final int BlueToRedX; + public static final int BlueToRedX; private static final int BlueToRedY; - private static final int BlueToRedZ; + public static final int BlueToRedZ; public static final int PreperationArea; public static final int WaterDepth; @@ -132,14 +132,15 @@ public class Config { public static final int ReplayID; static{ - if(!new File(FightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) { + String configFile = System.getProperty("config", "config.yml"); + if(!new File(FightSystem.getPlugin().getDataFolder(), configFile).exists()) { FightSystem.getPlugin().saveDefaultConfig(); Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); Bukkit.shutdown(); } - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(FightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml"))); + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(FightSystem.getPlugin().getDataFolder(), configFile)); - File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), config.getString("Arenaconfig", "config.yml")); + File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!"); Bukkit.shutdown(); @@ -173,7 +174,7 @@ public class Config { GroundWalkable = config.getBoolean("Arena.GroundWalkable"); RanksEnabled = config.getBoolean("Schematic.RanksEnabled"); - SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); + SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.SchematicType"))); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly"); boolean rotate = config.getBoolean("Schematic.Rotate"); PasteAligned = config.getBoolean("Schematic.PasteAligned"); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index c7f465c..4132169 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -132,9 +132,9 @@ public class FightSchematic extends StateDependent { clipboard, new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()), new Vector( - -dims.getBlockX()/2, + -(Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX() : dims.getBlockX())/2.0, Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, - -dims.getBlockZ()/2 + -(Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ() : dims.getBlockZ())/2.0 ), new AffineTransform().rotateY(rotate ? 180 : 0) ); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 809b530..ac6d9a3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -71,6 +71,10 @@ public class Region { return maxZ; } + public int getSizeX() { + return maxX - minX; + } + public int getSizeZ() { return maxZ - minZ; } @@ -120,12 +124,12 @@ public class Region { return (maxX - minX) * (maxY - minY) * (maxZ - minZ); } - public int centerX() { - return (maxX - minX) / 2 + minX; + public double centerX() { + return (maxX - minX) / 2.0 + minX; } - public int centerZ() { - return (maxZ - minZ) / 2 + minZ; + public double centerZ() { + return (maxZ - minZ) / 2.0 + minZ; } public boolean in2dRegion(Location location){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index eb52f04..ed55771 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -23,13 +23,17 @@ public enum Winconditions { TIMEOUT, HEART_RATIO_TIMEOUT, PERCENT_TIMEOUT, + ALL_DEAD, CAPTAIN_DEAD, + PERCENT_SYSTEM, RELATIVE_PERCENT, POINTS, + TIME_TECH_KO, WATER_TECH_KO, PUMPKIN_TECH_KO, + HELLS_BELLS } From fe19c1656dc0228eefa77bb32d9f217a93de2dd1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Sep 2021 17:30:18 +0200 Subject: [PATCH 27/33] TODO: Test if offsets vanished Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java | 2 +- .../src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index a91d4eb..5d3b1e3 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -106,7 +106,7 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e).to(BukkitAdapter.asVector(position).add( aT.apply(Vector3.at(offset.getX(), offset.getY(), offset.getZ()).add(clipboard.getOrigin().toVector3()).subtract(clipboard.getMinimumPoint().toVector3())) - ).toBlockPoint()).build()); + ).round().toBlockPoint()).build()); e.flushSession(); } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 2264f2b..356d51a 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -105,7 +105,7 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(new Vector(position.getX(), position.getY(), position.getZ()).add( aT.apply(new Vector(offset.getX(), offset.getY(), offset.getZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint())) - ).toBlockPoint()).build()); + ).round().toBlockPoint()).build()); e.flushQueue(); } From fe90f31c4ac235c3b2aa59ea25e210ed5344b562 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Sep 2021 17:32:49 +0200 Subject: [PATCH 28/33] Possible 1.8 world reset fix Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java index 89aedc7..3eb750e 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java @@ -39,6 +39,7 @@ public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapp public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle(); Chunk chunk = w.getChunkAt(x, z); + ((CraftWorld) backup).getHandle().chunkProviderServer.forceChunkLoad = true; Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); From d3cff066f5c42a15a6be97bd14b4a293424046f1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Sep 2021 23:09:50 +0200 Subject: [PATCH 29/33] Correct rotating? Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 4132169..892728c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -136,7 +136,7 @@ public class FightSchematic extends StateDependent { Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, -(Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ() : dims.getBlockZ())/2.0 ), - new AffineTransform().rotateY(rotate ? 180 : 0) + new AffineTransform().rotateY(rotate ? 180 : 0).translate(rotate ? 0.5 : 0, 0, rotate ? 0.5 : 0) ); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); From 79658bf3aa762d5042e77ab0e4ebc6a51f539a74 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Sep 2021 18:31:58 +0200 Subject: [PATCH 30/33] Real spectator mode in own teamarea Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/Fight.java | 24 ++++--- .../fightsystem/listener/TeamArea.java | 70 ++++++++++++------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 4033521..591e631 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -123,16 +123,7 @@ public class Fight { Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { if(!player.isOnline()) return; - PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); - gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); - List playerInfoActions = new ArrayList<>(); - playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(player.getDisplayName()))); - gm1packet.getPlayerInfoDataLists().write(0, playerInfoActions); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); - } + pseudoSpectator(player, true); }, 2); }else if(gameMode == GameMode.SURVIVAL) { for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { @@ -144,6 +135,19 @@ public class Fight { } } + public static void pseudoSpectator(Player player, boolean enable) { + PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); + List playerInfoActions = new ArrayList<>(); + playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, enable ? EnumWrappers.NativeGameMode.CREATIVE : EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName()))); + gm1packet.getPlayerInfoDataLists().write(0, playerInfoActions); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + } + } + public static int getMaxRank(){ /* MaxRank of 0 is Pubonly*/ if(Config.OnlyPublicSchematics){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java index db88f9f..6a06a8e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -26,15 +26,18 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.Region; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import java.util.HashSet; +import java.util.Set; import java.util.logging.Level; public class TeamArea implements Listener { @@ -42,6 +45,8 @@ public class TeamArea implements Listener { private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams"; private static final String DENY_ENTERN = "§cDu darfst nicht entern"; + private static final Set realSpectator = new HashSet<>(); + public TeamArea() { new StateDependentListener(ArenaMode.AntiTest, FightState.All, this); } @@ -52,37 +57,48 @@ public class TeamArea implements Listener { if(player == FightSystem.getEventLeiter()) return; - Location to = event.getTo(); - assert to != null; - FightTeam team = Fight.getPlayerTeam(player); + checkInTeamRegion(event, Fight.getBlueTeam(), player, team); + checkInTeamRegion(event, Fight.getRedTeam(), player, team); + } - if(Config.BlueExtendRegion.playerInRegion(to)){ - if(team == null) - reset(event, DENY_TEAM); - else if(team == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player))) - reset(event, DENY_ENTERN); - else - return; // Is allowed in area - checkInInnerArea(event.getPlayer(), to, Fight.getBlueTeam()); - }else if(Config.RedExtendRegion.playerInRegion(to)){ - if(team == null) - reset(event, DENY_TEAM); - else if(team == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player))) - reset(event, DENY_ENTERN); - else - return; // Is allowed in area - checkInInnerArea(event.getPlayer(), to, Fight.getRedTeam()); - }else{ - if(team != null && player.getGameMode() != GameMode.SPECTATOR && !team.canPlayerEntern(player) && !team.getExtendRegion().in2dRegion(to)) - reset(event, DENY_ENTERN); + @EventHandler + public void playerQuit(PlayerQuitEvent e) { + realSpectator.remove(e.getPlayer()); + } + + private void checkInTeamRegion(PlayerMoveEvent event, FightTeam team, Player player, FightTeam playerTeam) { + boolean spectator = player.getGameMode() == GameMode.SPECTATOR; + if(!spectator && playerTeam != null && playerTeam.canPlayerEntern(player)) + return; // Player can entern + + Region region = team.getExtendRegion(); + boolean inRegion = region.playerInRegion(event.getTo()); + if(team == playerTeam) { + if(spectator) { + realSpectator(inRegion, player); + } else if (!playerTeam.canPlayerEntern(player) && !inRegion) { + reset(event, DENY_ENTERN); // Leaving prior to entern + } + return; // Always allowed in own region + } + + if(inRegion) { + reset(event, DENY_TEAM); // Not allowed in region + if(team.getSchemRegion().playerInRegion(event.getTo()) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension + player.kickPlayer(null); + Bukkit.getLogger().log(Level.INFO, player.getName() + " ist in einen Teambereich eingedrungen."); + } } } - private void checkInInnerArea(Player player, Location to, FightTeam team){ - if(team.getSchemRegion().playerInRegion(to) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension - player.kickPlayer(null); - Bukkit.getLogger().log(Level.INFO, player.getName() + " ist in einen Teambereich eingedrungen."); + private void realSpectator(boolean inRegion, Player player) { + if(inRegion && !realSpectator.contains(player)) { + Fight.pseudoSpectator(player, false); + realSpectator.add(player); + }else if(!inRegion && realSpectator.contains(player)) { + Fight.pseudoSpectator(player, true); + realSpectator.remove(player); } } From 05d121fe63ad102c7ddabc78f07918096baba287 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Sep 2021 22:27:28 +0200 Subject: [PATCH 31/33] Fix rotation Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java | 2 +- .../src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java | 2 +- .../src/de/steamwar/fightsystem/fight/FightSchematic.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 5d3b1e3..a91d4eb 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -106,7 +106,7 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e).to(BukkitAdapter.asVector(position).add( aT.apply(Vector3.at(offset.getX(), offset.getY(), offset.getZ()).add(clipboard.getOrigin().toVector3()).subtract(clipboard.getMinimumPoint().toVector3())) - ).round().toBlockPoint()).build()); + ).toBlockPoint()).build()); e.flushSession(); } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 356d51a..2264f2b 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -105,7 +105,7 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(new Vector(position.getX(), position.getY(), position.getZ()).add( aT.apply(new Vector(offset.getX(), offset.getY(), offset.getZ()).add(clipboard.getOrigin()).subtract(clipboard.getMinimumPoint())) - ).round().toBlockPoint()).build()); + ).toBlockPoint()).build()); e.flushQueue(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 892728c..159317d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -135,8 +135,8 @@ public class FightSchematic extends StateDependent { -(Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX() : dims.getBlockX())/2.0, Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, -(Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ() : dims.getBlockZ())/2.0 - ), - new AffineTransform().rotateY(rotate ? 180 : 0).translate(rotate ? 0.5 : 0, 0, rotate ? 0.5 : 0) + ).add(new Vector(rotate ? 1 : 0, 0, rotate ? 1 : 0)), + new AffineTransform().rotateY(rotate ? 180 : 0) ); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); From 194adf89700b93d8739b7cec36aab91b83f24fbb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 16 Sep 2021 17:58:31 +0200 Subject: [PATCH 32/33] Fix laggy schemselect Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/Fight.java | 19 +------------------ .../steamwar/fightsystem/fight/FightTeam.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 4033521..c2e2965 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -30,7 +30,6 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -159,22 +158,6 @@ public class Fight { return 1000; } - if(Config.RanksEnabled) - return Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader())); - else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() || - Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty()) - return 0; - else - return 1; - } - - private static int schemRank(FightPlayer fightPlayer){ - int rank = 1; - List schematics = Schematic.getSchemsOfType(fightPlayer.getPlayer().getUniqueId(), Config.SchematicType); - for(Schematic schem : schematics){ - if(schem.getRank() > rank) - rank = schem.getRank(); - } - return rank; + return Math.min(redTeam.getSchemRank(), blueTeam.getSchemRank()); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 0f80fe0..be1f4b5 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -48,6 +48,8 @@ public class FightTeam { private UUID designatedLeader; private FightPlayer leader; + private int schemRank; + private final Map players = new HashMap<>(); private final Set invited = new HashSet<>(); @@ -69,6 +71,7 @@ public class FightTeam { this.spawn = spawn; this.schemRegion = schemRegion; this.extendRegion = extendRegion; + this.schemRank = 0; this.ready = false; this.skip = false; this.blue = blue; @@ -112,6 +115,10 @@ public class FightTeam { return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); } + public int getSchemRank() { + return schemRank; + } + public void teleportToSpawn(){ players.forEach((player, fp) -> player.teleport(spawn)); } @@ -258,6 +265,12 @@ public class FightTeam { if(ready) setReady(false); + Optional maxRank = Schematic.getSchemsOfType(leader.getPlayer().getUniqueId(), Config.SchematicType).stream().map(Schematic::getRank).max(Integer::compare); + if(Config.RanksEnabled) + schemRank = maxRank.orElse(1); + else + schemRank = maxRank.isPresent() ? 1 : 0; + if(!Config.PersonalKits) leader.setKit(Kit.getKitByName(Config.LeaderDefault)); From 9c2a854a14ec4df58741c2070cb0e466350f2087 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 27 Sep 2021 17:01:18 +0200 Subject: [PATCH 33/33] SteamWarCI Signed-off-by: Lixfel --- steamwarci.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 steamwarci.yml diff --git a/steamwarci.yml b/steamwarci.yml new file mode 100644 index 0000000..a48cedd --- /dev/null +++ b/steamwarci.yml @@ -0,0 +1,6 @@ +build: + - "ln -s /home/gitea/lib" + - "mvn package -B" + +artifacts: + "/binarys/fightsystem.jar": "FightSystem_Main/target/fightsystem.jar"