SteamWar/FightSystem
Archiviert
13
1

Arrows Stopping in Techhider Blocks #208

Manuell gemergt
Lixfel hat 17 Commits von arrow-in-techhider nach master 2021-01-02 09:20:42 +01:00 zusammengeführt
3 geänderte Dateien mit 38 neuen und 22 gelöschten Zeilen
Nur Änderungen aus Commit 030bfbc6a1 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -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){

Datei anzeigen

@ -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);
}
}