From e431b1323cb444b3e36b4292b80aaa39cd47379b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 7 Dec 2020 23:38:14 +0100 Subject: [PATCH] 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()); } }