|
|
|
@ -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<Entity, Location> LAST_LOCATION = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
public static void init() {
|
|
|
|
|
if(Config.ArrowTechhiderCollision == -1)
|
|
|
|
|
if(Config.ArrowTechhiderCollision == 0)
|
|
|
|
|
return;
|
|
|
|
|
FightSystem.registerStateDependent(new ArrowStopper());
|
|
|
|
|
}
|
|
|
|
@ -50,21 +55,29 @@ public class ArrowStopper implements StateDependent {
|
|
|
|
|
Collection<Entity> 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<Entity, Location> 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<FightState> enabled() {
|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|