From 664350d286ad168c1611c12a7852ceafdaddbdd2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 27 Nov 2020 16:22:15 +0100 Subject: [PATCH 01/16] Add Arrows Stopping in Techhider Blocks --- .../fightsystem/utils/ArrowStopper_12.java | 31 +++++++ .../fightsystem/utils/ArrowStopper_15.java | 31 +++++++ .../src/de/steamwar/fightsystem/Config.java | 2 + .../de/steamwar/fightsystem/FightSystem.java | 6 +- .../fightsystem/utils/ArrowStopper.java | 86 +++++++++++++++++++ 5 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java create mode 100644 FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java new file mode 100644 index 0000000..e4855ee --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.utils; + +import org.bukkit.block.Block; + +public class ArrowStopper_12 { + private ArrowStopper_12(){} + + @SuppressWarnings("deprecation") + static int blockToId(Block block){ + return block.getTypeId() << 4 + block.getData(); + } +} diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java new file mode 100644 index 0000000..00aba0a --- /dev/null +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.utils; + +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; + +public class ArrowStopper_15 { + private ArrowStopper_15(){} + + static int blockToId(Block block){ + return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); + } +} diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 524da67..86e1db2 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -80,6 +80,7 @@ public class Config { public static final int ArenaMaxX; public static final int ArenaMaxZ; public static final boolean GroundWalkable; + public static final int ArrowTechhiderCollision; //schematic parameter public static final boolean RanksEnabled; @@ -188,6 +189,7 @@ public class Config { double teamBlueSpawnOffsetX = worldconfig.getDouble("Arena.SpawnOffset.x"); double teamBlueSpawnOffsetY = worldconfig.getDouble("Arena.SpawnOffset.y"); double teamBlueSpawnOffsetZ = worldconfig.getDouble("Arena.SpawnOffset.z"); + ArrowTechhiderCollision = config.getInt("Times.ArrowTechhiderCollision"); RanksEnabled = config.getBoolean("Schematic.RanksEnabled"); SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 9ddb221..b180f56 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -32,10 +32,7 @@ import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.record.Recorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.utils.EnterHandler; -import de.steamwar.fightsystem.utils.FightScoreboard; -import de.steamwar.fightsystem.utils.FightStatistics; -import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import de.steamwar.sql.Schematic; @@ -72,6 +69,7 @@ public class FightSystem extends JavaPlugin { TechHider.init(); FightScoreboard.init(); RecordSystem.init(); + ArrowStopper.init(); try { CommandRemover.removeAll("gamemode"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java new file mode 100644 index 0000000..9fcc647 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -0,0 +1,86 @@ +/* + 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.core.Core; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.entity.AbstractArrow; +import org.bukkit.entity.Entity; +import org.bukkit.scheduler.BukkitTask; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.Set; + +public class ArrowStopper implements StateDependent { + + private BukkitTask task; + + public static void init() { + if(Config.ArrowTechhiderCollision == -1) + return; + FightSystem.registerStateDependent(new ArrowStopper()); + } + + private void run() { + Collection arrows = Bukkit.getWorlds().get(0).getEntitiesByClasses(AbstractArrow.class); + if(arrows.isEmpty()) + return; + for (Entity entity : arrows) { + if(entity.getTicksLived() > Config.ArrowTechhiderCollision) + continue; + if(Config.HiddenBlocks.contains(blockToId(entity.getLocation().getBlock()))) + entity.remove(); + } + } + + @Override + public Set enabled() { + return EnumSet.of(FightState.RUNNING); + } + + @Override + public void enable() { + task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 0); + } + + @Override + public void disable() { + task.cancel(); + } + + private static int blockToId(Block block){ + switch(Core.getVersion()){ + case 8: + case 9: + case 10: + case 12: + return ArrowStopper_12.blockToId(block); + case 15: + default: + return ArrowStopper_15.blockToId(block); + } + } +} -- 2.39.2 From 81ac127bbf4cc8f0056b38af25e436161fca1e86 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 27 Nov 2020 19:55:26 +0100 Subject: [PATCH 02/16] Adding Better Tracking --- .../fightsystem/utils/ArrowStopper_12.java | 2 +- .../fightsystem/utils/ArrowStopper.java | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java index e4855ee..f4bf992 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java @@ -26,6 +26,6 @@ public class ArrowStopper_12 { @SuppressWarnings("deprecation") static int blockToId(Block block){ - return block.getTypeId() << 4 + block.getData(); + return block.getTypeId(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index 9fcc647..f838eaf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -25,18 +25,24 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import java.util.Collection; import java.util.EnumSet; +import java.util.HashMap; import java.util.Set; public class ArrowStopper implements StateDependent { private BukkitTask task; + private static final HashMap LAST_LOCATION = new HashMap<>(); public static void init() { if(Config.ArrowTechhiderCollision == -1) @@ -51,8 +57,16 @@ public class ArrowStopper implements StateDependent { for (Entity entity : arrows) { if(entity.getTicksLived() > Config.ArrowTechhiderCollision) continue; - if(Config.HiddenBlocks.contains(blockToId(entity.getLocation().getBlock()))) + if(!LAST_LOCATION.containsKey(entity)) + LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation()); + int distance = (int) Math.ceil(entity.getLocation().toVector().distance(LAST_LOCATION.get(entity).toVector())); + try { + checkBlock(entity.getFacing().getOppositeFace(), entity.getLocation().getBlock(), distance, entity.getLocation().getBlockY() - LAST_LOCATION.get(entity).getBlockY()); + } catch (TechHiddenBlock techHiddenBlock) { entity.remove(); + } + LAST_LOCATION.remove(entity); + LAST_LOCATION.put(entity, entity.getLocation()); } } @@ -69,6 +83,7 @@ public class ArrowStopper implements StateDependent { @Override public void disable() { task.cancel(); + LAST_LOCATION.clear(); } private static int blockToId(Block block){ @@ -83,4 +98,19 @@ public class ArrowStopper implements StateDependent { return ArrowStopper_15.blockToId(block); } } + + private void checkBlock(BlockFace face, Block block, int i, int lastdown) throws TechHiddenBlock { + Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData())); + if(Config.HiddenBlocks.contains(blockToId(block))) + throw new TechHiddenBlock(); + if(lastdown != 0) { + boolean negativ = lastdown < 0; + BlockFace toFace = negativ?BlockFace.UP:BlockFace.DOWN; + checkBlock(face, block.getRelative(toFace), i, lastdown + (negativ?1:-1)); + } + if(i != 0 && Math.abs(lastdown) < i) + checkBlock(face, block.getRelative(face), i - 1, lastdown); + } + + private class TechHiddenBlock extends Throwable {} } -- 2.39.2 From afa2217ce31ed0dd349a4668c97f2bd5c289bf96 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 27 Nov 2020 21:07:51 +0100 Subject: [PATCH 03/16] Adding Better Tracking --- .../de/steamwar/fightsystem/utils/ArrowStopper.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index f838eaf..ac26912 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -57,9 +57,11 @@ public class ArrowStopper implements StateDependent { for (Entity entity : arrows) { if(entity.getTicksLived() > Config.ArrowTechhiderCollision) continue; + if(((AbstractArrow) entity).isInBlock()) + continue; if(!LAST_LOCATION.containsKey(entity)) LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation()); - int distance = (int) Math.ceil(entity.getLocation().toVector().distance(LAST_LOCATION.get(entity).toVector())); + int distance = (int) Math.ceil(entity.getLocation().toVector().distance(LAST_LOCATION.get(entity).toVector()) * 1.414213562); try { checkBlock(entity.getFacing().getOppositeFace(), entity.getLocation().getBlock(), distance, entity.getLocation().getBlockY() - LAST_LOCATION.get(entity).getBlockY()); } catch (TechHiddenBlock techHiddenBlock) { @@ -103,13 +105,13 @@ public class ArrowStopper implements StateDependent { Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData())); if(Config.HiddenBlocks.contains(blockToId(block))) throw new TechHiddenBlock(); + if(i != Math.abs(lastdown)) + checkBlock(face, block.getRelative(face), i - 1, lastdown); if(lastdown != 0) { boolean negativ = lastdown < 0; BlockFace toFace = negativ?BlockFace.UP:BlockFace.DOWN; - checkBlock(face, block.getRelative(toFace), i, lastdown + (negativ?1:-1)); + checkBlock(face, block.getRelative(toFace), i - 1, lastdown + (negativ?1:-1)); } - if(i != 0 && Math.abs(lastdown) < i) - checkBlock(face, block.getRelative(face), i - 1, lastdown); } private class TechHiddenBlock extends Throwable {} -- 2.39.2 From 8c93f446df7c3bdcab8165d2884a4eb61ac2b8cc Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 27 Nov 2020 21:31:39 +0100 Subject: [PATCH 04/16] Adding Better Tracking --- .../steamwar/fightsystem/utils/ArrowStopper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index ac26912..6d5069d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -63,7 +63,7 @@ public class ArrowStopper implements StateDependent { LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation()); int distance = (int) Math.ceil(entity.getLocation().toVector().distance(LAST_LOCATION.get(entity).toVector()) * 1.414213562); try { - checkBlock(entity.getFacing().getOppositeFace(), entity.getLocation().getBlock(), distance, entity.getLocation().getBlockY() - LAST_LOCATION.get(entity).getBlockY()); + checkBlock(entity.getFacing().getOppositeFace(), entity.getLocation().getBlock(), LAST_LOCATION.get(entity).getBlock(), distance, entity.getLocation().getBlockY() - LAST_LOCATION.get(entity).getBlockY()); } catch (TechHiddenBlock techHiddenBlock) { entity.remove(); } @@ -101,16 +101,20 @@ public class ArrowStopper implements StateDependent { } } - private void checkBlock(BlockFace face, Block block, int i, int lastdown) throws TechHiddenBlock { + private void checkBlock(BlockFace face, Block block, Block start, int i, int lastdown) throws TechHiddenBlock { Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData())); if(Config.HiddenBlocks.contains(blockToId(block))) throw new TechHiddenBlock(); - if(i != Math.abs(lastdown)) - checkBlock(face, block.getRelative(face), i - 1, lastdown); + if(lastdown != 0) { boolean negativ = lastdown < 0; BlockFace toFace = negativ?BlockFace.UP:BlockFace.DOWN; - checkBlock(face, block.getRelative(toFace), i - 1, lastdown + (negativ?1:-1)); + checkBlock(face, block.getRelative(toFace), start, i - 1, lastdown + (negativ?1:-1)); + return; + } + + if(i != 0) { + checkBlock(face, block.getRelative(face), start, i - 1, lastdown); } } -- 2.39.2 From 5366011bd7194c1043f9cd0b81318d64386982d2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 28 Nov 2020 12:05:27 +0100 Subject: [PATCH 05/16] Rework Arrow Tracking --- .../fightsystem/utils/ArrowStopper.java | 66 ++++++++++++------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index 6d5069d..d6ad3d5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -34,10 +34,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; -import java.util.Collection; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Set; +import java.util.*; public class ArrowStopper implements StateDependent { @@ -55,20 +52,22 @@ public class ArrowStopper implements StateDependent { if(arrows.isEmpty()) return; for (Entity entity : arrows) { - if(entity.getTicksLived() > Config.ArrowTechhiderCollision) + if(entity.getTicksLived() > Config.ArrowTechhiderCollision){ + LAST_LOCATION.remove(entity); continue; - if(((AbstractArrow) entity).isInBlock()) + } + if(((AbstractArrow) entity).isInBlock()) { + LAST_LOCATION.remove(entity); continue; + } if(!LAST_LOCATION.containsKey(entity)) LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation()); - int distance = (int) Math.ceil(entity.getLocation().toVector().distance(LAST_LOCATION.get(entity).toVector()) * 1.414213562); - try { - checkBlock(entity.getFacing().getOppositeFace(), entity.getLocation().getBlock(), LAST_LOCATION.get(entity).getBlock(), distance, entity.getLocation().getBlockY() - LAST_LOCATION.get(entity).getBlockY()); - } catch (TechHiddenBlock techHiddenBlock) { - entity.remove(); - } + Location last = LAST_LOCATION.get(entity); LAST_LOCATION.remove(entity); - LAST_LOCATION.put(entity, entity.getLocation()); + if(checkBlocks(entity.getLocation().getBlock(), last.getBlock())) + entity.remove(); + else + LAST_LOCATION.put(entity, entity.getLocation()); } } @@ -101,22 +100,39 @@ public class ArrowStopper implements StateDependent { } } - private void checkBlock(BlockFace face, Block block, Block start, int i, int lastdown) throws TechHiddenBlock { - Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData())); - if(Config.HiddenBlocks.contains(blockToId(block))) - throw new TechHiddenBlock(); + private boolean checkBlocks(Block start, Block end) { + Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(start.getLocation(), Material.LIME_STAINED_GLASS.createBlockData())); + Block cursor = start; - if(lastdown != 0) { - boolean negativ = lastdown < 0; - BlockFace toFace = negativ?BlockFace.UP:BlockFace.DOWN; - checkBlock(face, block.getRelative(toFace), start, i - 1, lastdown + (negativ?1:-1)); - return; + while (cursor.getY() != end.getY()) { + boolean negativ = cursor.getY() - end.getY() < 0; + BlockFace face = negativ?BlockFace.UP:BlockFace.DOWN; + if(checkBlock(cursor)) + return true; + cursor = cursor.getRelative(face); } - if(i != 0) { - checkBlock(face, block.getRelative(face), start, i - 1, lastdown); + while (cursor.getX() != end.getX()) { + boolean negativ = cursor.getX() - end.getX() < 0; + BlockFace face = negativ?BlockFace.EAST:BlockFace.WEST; + if(checkBlock(cursor)) + return true; + cursor = cursor.getRelative(face); } + + while (cursor.getZ() != end.getZ()) { + boolean negativ = cursor.getZ() - end.getZ() < 0; + BlockFace face = negativ?BlockFace.SOUTH:BlockFace.NORTH; + if(checkBlock(cursor)) + return true; + cursor = cursor.getRelative(face); + } + + return false; } - private class TechHiddenBlock extends Throwable {} + private boolean checkBlock(Block block) { + Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData())); + return Config.HiddenBlocks.contains(blockToId(block)); + } } -- 2.39.2 From 9984fc017943ec90ec86dae8b94c797f49f3e905 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 28 Nov 2020 12:07:41 +0100 Subject: [PATCH 06/16] Remove Debug Message --- .../src/de/steamwar/fightsystem/utils/ArrowStopper.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index d6ad3d5..b640fcb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -101,7 +101,6 @@ public class ArrowStopper implements StateDependent { } private boolean checkBlocks(Block start, Block end) { - Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(start.getLocation(), Material.LIME_STAINED_GLASS.createBlockData())); Block cursor = start; while (cursor.getY() != end.getY()) { @@ -132,7 +131,6 @@ public class ArrowStopper implements StateDependent { } private boolean checkBlock(Block block) { - Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData())); return Config.HiddenBlocks.contains(blockToId(block)); } } -- 2.39.2 From 5eedf7bf503cebc8ac75ba0aff733978848e21cd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 28 Nov 2020 13:11:43 +0100 Subject: [PATCH 07/16] Improving Array --- .../de/steamwar/fightsystem/utils/ArrowStopper.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index b640fcb..920ebae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -26,7 +26,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.AbstractArrow; @@ -52,18 +51,14 @@ public class ArrowStopper implements StateDependent { if(arrows.isEmpty()) return; for (Entity entity : arrows) { - if(entity.getTicksLived() > Config.ArrowTechhiderCollision){ - LAST_LOCATION.remove(entity); - continue; - } - if(((AbstractArrow) entity).isInBlock()) { + if(entity.getTicksLived() > Config.ArrowTechhiderCollision || + ((AbstractArrow) entity).isInBlock()){ LAST_LOCATION.remove(entity); continue; } if(!LAST_LOCATION.containsKey(entity)) LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation()); - Location last = LAST_LOCATION.get(entity); - LAST_LOCATION.remove(entity); + Location last = LAST_LOCATION.remove(entity); if(checkBlocks(entity.getLocation().getBlock(), last.getBlock())) entity.remove(); else @@ -78,7 +73,7 @@ public class ArrowStopper implements StateDependent { @Override public void enable() { - task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 0); + task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); } @Override -- 2.39.2 From 030bfbc6a160acd598b819c8b67e0ae9994dea21 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 30 Nov 2020 20:05:07 +0100 Subject: [PATCH 08/16] Improving --- .../fightsystem/utils/ArrowStopper_14.java | 8 ++-- .../fightsystem/utils/ArrowStopper_8.java | 4 +- .../fightsystem/utils/ArrowStopper.java | 48 ++++++++++++------- 3 files changed, 38 insertions(+), 22 deletions(-) rename FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java => FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java (83%) rename FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java => FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java (93%) diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java similarity index 83% rename from FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java rename to FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java index 00aba0a..6a16357 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/ArrowStopper_15.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java @@ -20,12 +20,12 @@ package de.steamwar.fightsystem.utils; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; +import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; -public class ArrowStopper_15 { - private ArrowStopper_15(){} +public class ArrowStopper_14 { + private ArrowStopper_14(){} static int blockToId(Block block){ - return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); + return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java similarity index 93% rename from FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java index f4bf992..01a4972 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/ArrowStopper_12.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java @@ -21,8 +21,8 @@ package de.steamwar.fightsystem.utils; import org.bukkit.block.Block; -public class ArrowStopper_12 { - private ArrowStopper_12(){} +public class ArrowStopper_8 { + private ArrowStopper_8(){} @SuppressWarnings("deprecation") static int blockToId(Block block){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java index 920ebae..f4e33b3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java @@ -31,17 +31,22 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.player.PlayerPickupArrowEvent; import org.bukkit.scheduler.BukkitTask; import java.util.*; -public class ArrowStopper implements StateDependent { +public class ArrowStopper implements StateDependent, Listener { private BukkitTask task; private static final HashMap LAST_LOCATION = new HashMap<>(); public static void init() { - if(Config.ArrowTechhiderCollision == -1) + if(Config.ArrowTechhiderCollision == 0) return; FightSystem.registerStateDependent(new ArrowStopper()); } @@ -50,22 +55,30 @@ public class ArrowStopper implements StateDependent { Collection arrows = Bukkit.getWorlds().get(0).getEntitiesByClasses(AbstractArrow.class); if(arrows.isEmpty()) return; - for (Entity entity : arrows) { - if(entity.getTicksLived() > Config.ArrowTechhiderCollision || - ((AbstractArrow) entity).isInBlock()){ - LAST_LOCATION.remove(entity); - continue; + for (Map.Entry e : LAST_LOCATION.entrySet()) { + if(checkBlocks(e.getKey().getLocation().getBlock(), e.getValue().getBlock())) + e.getKey().remove(); + else { + if(e.getKey().getTicksLived() <= Config.ArrowTechhiderCollision || + !((AbstractArrow) e.getKey()).isInBlock()) { + LAST_LOCATION.put(e.getKey(), e.getKey().getLocation()); + } } - if(!LAST_LOCATION.containsKey(entity)) - LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation()); - Location last = LAST_LOCATION.remove(entity); - if(checkBlocks(entity.getLocation().getBlock(), last.getBlock())) - entity.remove(); - else - LAST_LOCATION.put(entity, entity.getLocation()); } } + @EventHandler() + public void onEntityShootBow(EntityShootBowEvent event) { + if(!(event.getEntity() instanceof Player)) + return; + LAST_LOCATION.put(event.getProjectile(), event.getEntity().getEyeLocation()); + } + + @EventHandler + public void onPlayerPickupArrow(PlayerPickupArrowEvent event) { + LAST_LOCATION.remove(event.getArrow()); + } + @Override public Set enabled() { return EnumSet.of(FightState.RUNNING); @@ -73,6 +86,7 @@ public class ArrowStopper implements StateDependent { @Override public void enable() { + Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); } @@ -80,6 +94,7 @@ public class ArrowStopper implements StateDependent { public void disable() { task.cancel(); LAST_LOCATION.clear(); + HandlerList.unregisterAll(this); } private static int blockToId(Block block){ @@ -88,10 +103,11 @@ public class ArrowStopper implements StateDependent { case 9: case 10: case 12: - return ArrowStopper_12.blockToId(block); + return ArrowStopper_8.blockToId(block); + case 14: case 15: default: - return ArrowStopper_15.blockToId(block); + return ArrowStopper_14.blockToId(block); } } -- 2.39.2 From e431b1323cb444b3e36b4292b80aaa39cd47379b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 7 Dec 2020 23:38:14 +0100 Subject: [PATCH 09/16] Fixing --- .../fightsystem/utils/ArrowStopper_14.java | 31 --------- .../fightsystem/utils/ArrowStopper_8.java | 31 --------- .../{utils => listener}/ArrowStopper.java | 63 ++++++------------- 3 files changed, 19 insertions(+), 106 deletions(-) delete mode 100644 FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java delete mode 100644 FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java rename FightSystem_Main/src/de/steamwar/fightsystem/{utils => listener}/ArrowStopper.java (65%) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.java deleted file mode 100644 index 6a16357..0000000 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/ArrowStopper_14.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.utils; - -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; - -public class ArrowStopper_14 { - private ArrowStopper_14(){} - - static int blockToId(Block block){ - return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); - } -} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.java deleted file mode 100644 index 01a4972..0000000 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/ArrowStopper_8.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.utils; - -import org.bukkit.block.Block; - -public class ArrowStopper_8 { - private ArrowStopper_8(){} - - @SuppressWarnings("deprecation") - static int blockToId(Block block){ - return block.getTypeId(); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java similarity index 65% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index f4e33b3..6982fa3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -17,34 +17,33 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityShootBowEvent; -import org.bukkit.event.player.PlayerPickupArrowEvent; import org.bukkit.scheduler.BukkitTask; import java.util.*; -public class ArrowStopper implements StateDependent, Listener { +public class ArrowStopper extends BasicListener { private BukkitTask task; private static final HashMap LAST_LOCATION = new HashMap<>(); + ArrowStopper() { + super(EnumSet.of(FightState.RUNNING)); + } + public static void init() { if(Config.ArrowTechhiderCollision == 0) return; @@ -52,16 +51,18 @@ public class ArrowStopper implements StateDependent, Listener { } private void run() { - Collection arrows = Bukkit.getWorlds().get(0).getEntitiesByClasses(AbstractArrow.class); - if(arrows.isEmpty()) - return; for (Map.Entry e : LAST_LOCATION.entrySet()) { - if(checkBlocks(e.getKey().getLocation().getBlock(), e.getValue().getBlock())) - e.getKey().remove(); + Entity entity = e.getKey(); + if(checkBlocks(entity.getLocation().getBlock(), e.getValue().getBlock())){ + entity.remove(); + LAST_LOCATION.remove(entity); + } else { - if(e.getKey().getTicksLived() <= Config.ArrowTechhiderCollision || - !((AbstractArrow) e.getKey()).isInBlock()) { - LAST_LOCATION.put(e.getKey(), e.getKey().getLocation()); + if(entity.getTicksLived() > Config.ArrowTechhiderCollision || + ((AbstractArrow) entity).isInBlock() || entity.getLocation().equals(e.getValue())) { + LAST_LOCATION.remove(entity); + }else { + LAST_LOCATION.replace(e.getKey(), e.getKey().getLocation()); } } } @@ -69,46 +70,20 @@ public class ArrowStopper implements StateDependent, Listener { @EventHandler() public void onEntityShootBow(EntityShootBowEvent event) { - if(!(event.getEntity() instanceof Player)) - return; LAST_LOCATION.put(event.getProjectile(), event.getEntity().getEyeLocation()); } - @EventHandler - public void onPlayerPickupArrow(PlayerPickupArrowEvent event) { - LAST_LOCATION.remove(event.getArrow()); - } - - @Override - public Set enabled() { - return EnumSet.of(FightState.RUNNING); - } - @Override public void enable() { - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); + super.enable(); task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); } @Override public void disable() { + super.disable(); task.cancel(); LAST_LOCATION.clear(); - HandlerList.unregisterAll(this); - } - - private static int blockToId(Block block){ - switch(Core.getVersion()){ - case 8: - case 9: - case 10: - case 12: - return ArrowStopper_8.blockToId(block); - case 14: - case 15: - default: - return ArrowStopper_14.blockToId(block); - } } private boolean checkBlocks(Block start, Block end) { @@ -142,6 +117,6 @@ public class ArrowStopper implements StateDependent, Listener { } private boolean checkBlock(Block block) { - return Config.HiddenBlocks.contains(blockToId(block)); + return Config.HiddenBlockTags.contains(block.getType().name()); } } -- 2.39.2 From 94b248d875e45fc53d4adac0964e4da48f6fa669 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 8 Dec 2020 16:01:42 +0100 Subject: [PATCH 10/16] Fixing --- .../src/de/steamwar/fightsystem/listener/ArrowStopper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 6982fa3..8f61a9b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; @@ -51,7 +50,9 @@ public class ArrowStopper extends BasicListener { } private void run() { - for (Map.Entry e : LAST_LOCATION.entrySet()) { + Iterator> iterator = LAST_LOCATION.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry e = iterator.next(); Entity entity = e.getKey(); if(checkBlocks(entity.getLocation().getBlock(), e.getValue().getBlock())){ entity.remove(); -- 2.39.2 From 250c429a516926de57e2518ca992d5e5b3a65c36 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 21 Dec 2020 12:59:09 +0100 Subject: [PATCH 11/16] Performance Changes --- .../fightsystem/listener/ArrowStopper.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 8f61a9b..46581b4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -56,12 +56,10 @@ public class ArrowStopper extends BasicListener { Entity entity = e.getKey(); if(checkBlocks(entity.getLocation().getBlock(), e.getValue().getBlock())){ entity.remove(); - LAST_LOCATION.remove(entity); - } - else { - if(entity.getTicksLived() > Config.ArrowTechhiderCollision || - ((AbstractArrow) entity).isInBlock() || entity.getLocation().equals(e.getValue())) { - LAST_LOCATION.remove(entity); + iterator.remove(); + } else { + if(isValidEntity(entity, e)) { + iterator.remove(); }else { LAST_LOCATION.replace(e.getKey(), e.getKey().getLocation()); } @@ -77,7 +75,7 @@ public class ArrowStopper extends BasicListener { @Override public void enable() { super.enable(); - task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1); } @Override @@ -120,4 +118,10 @@ public class ArrowStopper extends BasicListener { private boolean checkBlock(Block block) { return Config.HiddenBlockTags.contains(block.getType().name()); } + + private boolean isValidEntity(Entity entity, Map.Entry entry) { + return entity.getTicksLived() > Config.ArrowTechhiderCollision || + ((AbstractArrow) entity).isInBlock() || + entity.getLocation().equals(entry.getValue()); + } } -- 2.39.2 From dea991d7d7d1fcd6af74fb97936c131c2e23dfab Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 13:41:17 +0100 Subject: [PATCH 12/16] Fixing --- .../src/de/steamwar/fightsystem/FightSystem.java | 2 +- .../de/steamwar/fightsystem/listener/ArrowStopper.java | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index b180f56..93f333b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -69,7 +69,6 @@ public class FightSystem extends JavaPlugin { TechHider.init(); FightScoreboard.init(); RecordSystem.init(); - ArrowStopper.init(); try { CommandRemover.removeAll("gamemode"); @@ -101,6 +100,7 @@ public class FightSystem extends JavaPlugin { new GameplayListener(); new PersonalKitCreator(); new ScoreboardListener(); + new ArrowStopper(); if(Core.getVersion() > 8) new VersionDependentListener(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 46581b4..cd3c11d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -39,14 +39,8 @@ public class ArrowStopper extends BasicListener { private BukkitTask task; private static final HashMap LAST_LOCATION = new HashMap<>(); - ArrowStopper() { - super(EnumSet.of(FightState.RUNNING)); - } - - public static void init() { - if(Config.ArrowTechhiderCollision == 0) - return; - FightSystem.registerStateDependent(new ArrowStopper()); + public ArrowStopper() { + super(Config.ArrowTechhiderCollision != 0 ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class)); } private void run() { -- 2.39.2 From 36d27f52c6fe76b398f8caa16f5dec0ff8188b23 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 16:44:57 +0100 Subject: [PATCH 13/16] Improving Performance --- .../src/de/steamwar/fightsystem/Config.java | 2 - .../fightsystem/listener/ArrowStopper.java | 51 +++++++++---------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 86e1db2..524da67 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -80,7 +80,6 @@ public class Config { public static final int ArenaMaxX; public static final int ArenaMaxZ; public static final boolean GroundWalkable; - public static final int ArrowTechhiderCollision; //schematic parameter public static final boolean RanksEnabled; @@ -189,7 +188,6 @@ public class Config { double teamBlueSpawnOffsetX = worldconfig.getDouble("Arena.SpawnOffset.x"); double teamBlueSpawnOffsetY = worldconfig.getDouble("Arena.SpawnOffset.y"); double teamBlueSpawnOffsetZ = worldconfig.getDouble("Arena.SpawnOffset.z"); - ArrowTechhiderCollision = config.getInt("Times.ArrowTechhiderCollision"); RanksEnabled = config.getBoolean("Schematic.RanksEnabled"); SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index cd3c11d..7c0bbd9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -24,48 +24,43 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.entity.AbstractArrow; -import org.bukkit.entity.Entity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; import java.util.*; public class ArrowStopper extends BasicListener { private BukkitTask task; - private static final HashMap LAST_LOCATION = new HashMap<>(); + private static final Vector NULL_VECTOR = new Vector(0, 0, 0); public ArrowStopper() { - super(Config.ArrowTechhiderCollision != 0 ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class)); + super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class)); } private void run() { - Iterator> iterator = LAST_LOCATION.entrySet().iterator(); + Iterator iterator = Bukkit.getWorlds().get(0).getEntitiesByClass(Arrow.class).iterator(); while (iterator.hasNext()) { - Map.Entry e = iterator.next(); - Entity entity = e.getKey(); - if(checkBlocks(entity.getLocation().getBlock(), e.getValue().getBlock())){ - entity.remove(); + Arrow arrow = iterator.next(); + if(isValidEntity(arrow)) + continue; + + Location prevLocation = arrow.getLocation().toVector().subtract(arrow.getVelocity()).toLocation(arrow.getWorld()); + if(arrow.getTicksLived() == 0) + prevLocation = ((Player) arrow.getShooter()).getEyeLocation(); + if(checkBlocks(arrow.getLocation().getBlock(), prevLocation.getBlock())) { + arrow.remove(); iterator.remove(); - } else { - if(isValidEntity(entity, e)) { - iterator.remove(); - }else { - LAST_LOCATION.replace(e.getKey(), e.getKey().getLocation()); - } } } } - @EventHandler() - public void onEntityShootBow(EntityShootBowEvent event) { - LAST_LOCATION.put(event.getProjectile(), event.getEntity().getEyeLocation()); - } - @Override public void enable() { super.enable(); @@ -76,7 +71,6 @@ public class ArrowStopper extends BasicListener { public void disable() { super.disable(); task.cancel(); - LAST_LOCATION.clear(); } private boolean checkBlocks(Block start, Block end) { @@ -113,9 +107,12 @@ public class ArrowStopper extends BasicListener { return Config.HiddenBlockTags.contains(block.getType().name()); } - private boolean isValidEntity(Entity entity, Map.Entry entry) { - return entity.getTicksLived() > Config.ArrowTechhiderCollision || - ((AbstractArrow) entity).isInBlock() || - entity.getLocation().equals(entry.getValue()); + private boolean isValidEntity(Arrow entity) { + boolean teamFrom = entity.getVelocity().getZ() > 0; + boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ(); + boolean otherSide = teamFrom == overMid; + return otherSide || + entity.isInBlock() || + entity.getVelocity().equals(NULL_VECTOR); } } -- 2.39.2 From 6d9a8683dbe6c6f4937985571f3883671d787832 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 16:45:14 +0100 Subject: [PATCH 14/16] Removing Imports --- .../src/de/steamwar/fightsystem/listener/ArrowStopper.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 7c0bbd9..b44b38e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -24,10 +24,8 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; -- 2.39.2 From 7b055a37be47b751466b737db2c13e1d49413bad Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 30 Dec 2020 17:11:02 +0100 Subject: [PATCH 15/16] Improve Tracking --- .../fightsystem/listener/ArrowStopper.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index b44b38e..8a9ac68 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -37,7 +37,7 @@ public class ArrowStopper extends BasicListener { private BukkitTask task; 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}; public ArrowStopper() { super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class)); } @@ -74,28 +74,20 @@ public class ArrowStopper extends BasicListener { private boolean checkBlocks(Block start, Block end) { Block cursor = start; - while (cursor.getY() != end.getY()) { - boolean negativ = cursor.getY() - end.getY() < 0; - BlockFace face = negativ?BlockFace.UP:BlockFace.DOWN; + while (!cursor.getLocation().equals(end.getLocation())) { + BlockFace nearest = BlockFace.SELF; + double nearestDistance = cursor.getLocation().distance(end.getLocation()); + for (BlockFace face : BLOCK_FACES) { + Block relative = cursor.getRelative(face); + double distance = relative.getLocation().distance(end.getLocation()); + if(distance < nearestDistance) { + nearestDistance = distance; + nearest = face; + } + } + cursor = cursor.getRelative(nearest); if(checkBlock(cursor)) return true; - cursor = cursor.getRelative(face); - } - - while (cursor.getX() != end.getX()) { - boolean negativ = cursor.getX() - end.getX() < 0; - BlockFace face = negativ?BlockFace.EAST:BlockFace.WEST; - if(checkBlock(cursor)) - return true; - cursor = cursor.getRelative(face); - } - - while (cursor.getZ() != end.getZ()) { - boolean negativ = cursor.getZ() - end.getZ() < 0; - BlockFace face = negativ?BlockFace.SOUTH:BlockFace.NORTH; - if(checkBlock(cursor)) - return true; - cursor = cursor.getRelative(face); } return false; -- 2.39.2 From 47e256d31c68f697bcbb93192150cbeaef1ab4f5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 2 Jan 2021 09:20:19 +0100 Subject: [PATCH 16/16] Improvements Signed-off-by: Lixfel --- .../fightsystem/listener/ArrowStopper.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 8a9ac68..7dcfc68 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -28,10 +28,11 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; +import org.bukkit.projectiles.ProjectileSource; import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Vector; -import java.util.*; +import java.util.EnumSet; public class ArrowStopper extends BasicListener { @@ -43,18 +44,20 @@ public class ArrowStopper extends BasicListener { } private void run() { - Iterator iterator = Bukkit.getWorlds().get(0).getEntitiesByClass(Arrow.class).iterator(); - while (iterator.hasNext()) { - Arrow arrow = iterator.next(); - if(isValidEntity(arrow)) + for (Arrow arrow : Bukkit.getWorlds().get(0).getEntitiesByClass(Arrow.class)) { + if (invalidEntity(arrow)) continue; Location prevLocation = arrow.getLocation().toVector().subtract(arrow.getVelocity()).toLocation(arrow.getWorld()); - if(arrow.getTicksLived() == 0) - prevLocation = ((Player) arrow.getShooter()).getEyeLocation(); - if(checkBlocks(arrow.getLocation().getBlock(), prevLocation.getBlock())) { + if (arrow.getTicksLived() == 0){ + ProjectileSource projSource = arrow.getShooter(); + if(projSource instanceof Player) + prevLocation = ((Player) arrow.getShooter()).getEyeLocation(); + else + continue; + } + if (checkBlocks(arrow.getLocation().getBlock(), prevLocation.getBlock())) { arrow.remove(); - iterator.remove(); } } } @@ -97,7 +100,7 @@ public class ArrowStopper extends BasicListener { return Config.HiddenBlockTags.contains(block.getType().name()); } - private boolean isValidEntity(Arrow entity) { + private boolean invalidEntity(Arrow entity) { boolean teamFrom = entity.getVelocity().getZ() > 0; boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ(); boolean otherSide = teamFrom == overMid; -- 2.39.2