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
2 geänderte Dateien mit 32 neuen und 2 gelöschten Zeilen
Nur Änderungen aus Commit 81ac127bbf werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -26,6 +26,6 @@ public class ArrowStopper_12 {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
static int blockToId(Block block){ static int blockToId(Block block){
return block.getTypeId() << 4 + block.getData(); return block.getTypeId();
} }
} }

Datei anzeigen

@ -25,18 +25,24 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
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.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set; import java.util.Set;
public class ArrowStopper implements StateDependent { public class ArrowStopper implements StateDependent {
private BukkitTask task; private BukkitTask task;
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 == -1)
@ -51,8 +57,16 @@ public class ArrowStopper implements StateDependent {
for (Entity entity : arrows) { for (Entity entity : arrows) {
if(entity.getTicksLived() > Config.ArrowTechhiderCollision) if(entity.getTicksLived() > Config.ArrowTechhiderCollision)
continue; 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(); entity.remove();
}
LAST_LOCATION.remove(entity);
LAST_LOCATION.put(entity, entity.getLocation());
} }
} }
@ -69,6 +83,7 @@ public class ArrowStopper implements StateDependent {
@Override @Override
public void disable() { public void disable() {
task.cancel(); task.cancel();
LAST_LOCATION.clear();
} }
private static int blockToId(Block block){ private static int blockToId(Block block){
@ -83,4 +98,19 @@ public class ArrowStopper implements StateDependent {
return ArrowStopper_15.blockToId(block); 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 {}
} }