SteamWar/FightSystem
Archiviert
13
1
Dieser Commit ist enthalten in:
Chaoscaot 2020-11-30 20:05:07 +01:00
Ursprung fff0380228
Commit 030bfbc6a1
3 geänderte Dateien mit 38 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -20,12 +20,12 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import org.bukkit.block.Block; 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 { public class ArrowStopper_14 {
private ArrowStopper_15(){} private ArrowStopper_14(){}
static int blockToId(Block block){ 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());
} }
} }

Datei anzeigen

@ -21,8 +21,8 @@ package de.steamwar.fightsystem.utils;
import org.bukkit.block.Block; import org.bukkit.block.Block;
public class ArrowStopper_12 { public class ArrowStopper_8 {
private ArrowStopper_12(){} private ArrowStopper_8(){}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
static int blockToId(Block block){ static int blockToId(Block block){

Datei anzeigen

@ -31,17 +31,22 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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 org.bukkit.scheduler.BukkitTask;
import java.util.*; import java.util.*;
public class ArrowStopper implements StateDependent { public class ArrowStopper implements StateDependent, Listener {
private BukkitTask task; private BukkitTask task;
private static final HashMap<Entity, Location> LAST_LOCATION = new HashMap<>(); private static final HashMap<Entity, Location> LAST_LOCATION = new HashMap<>();
public static void init() { public static void init() {
if(Config.ArrowTechhiderCollision == -1) if(Config.ArrowTechhiderCollision == 0)
return; return;
FightSystem.registerStateDependent(new ArrowStopper()); FightSystem.registerStateDependent(new ArrowStopper());
} }
@ -50,22 +55,30 @@ public class ArrowStopper implements StateDependent {
Collection<Entity> arrows = Bukkit.getWorlds().get(0).getEntitiesByClasses(AbstractArrow.class); Collection<Entity> arrows = Bukkit.getWorlds().get(0).getEntitiesByClasses(AbstractArrow.class);
if(arrows.isEmpty()) if(arrows.isEmpty())
return; return;
for (Entity entity : arrows) { for (Map.Entry<Entity, Location> e : LAST_LOCATION.entrySet()) {
if(entity.getTicksLived() > Config.ArrowTechhiderCollision || if(checkBlocks(e.getKey().getLocation().getBlock(), e.getValue().getBlock()))
((AbstractArrow) entity).isInBlock()){ e.getKey().remove();
LAST_LOCATION.remove(entity); else {
continue; 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 @Override
public Set<FightState> enabled() { public Set<FightState> enabled() {
return EnumSet.of(FightState.RUNNING); return EnumSet.of(FightState.RUNNING);
@ -73,6 +86,7 @@ public class ArrowStopper implements StateDependent {
@Override @Override
public void enable() { public void enable() {
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1); task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1);
} }
@ -80,6 +94,7 @@ public class ArrowStopper implements StateDependent {
public void disable() { public void disable() {
task.cancel(); task.cancel();
LAST_LOCATION.clear(); LAST_LOCATION.clear();
HandlerList.unregisterAll(this);
} }
private static int blockToId(Block block){ private static int blockToId(Block block){
@ -88,10 +103,11 @@ public class ArrowStopper implements StateDependent {
case 9: case 9:
case 10: case 10:
case 12: case 12:
return ArrowStopper_12.blockToId(block); return ArrowStopper_8.blockToId(block);
case 14:
case 15: case 15:
default: default:
return ArrowStopper_15.blockToId(block); return ArrowStopper_14.blockToId(block);
} }
} }