SteamWar/FightSystem
Archiviert
13
1

Rework Arrow Tracking

Dieser Commit ist enthalten in:
Chaoscaot 2020-11-28 12:05:27 +01:00
Ursprung 8c93f446df
Commit 5366011bd7

Datei anzeigen

@ -34,10 +34,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;
import java.util.*;
public class ArrowStopper implements StateDependent {
@ -55,20 +52,22 @@ public class ArrowStopper implements StateDependent {
if(arrows.isEmpty())
return;
for (Entity entity : arrows) {
if(entity.getTicksLived() > Config.ArrowTechhiderCollision)
if(entity.getTicksLived() > Config.ArrowTechhiderCollision){
LAST_LOCATION.remove(entity);
continue;
if(((AbstractArrow) entity).isInBlock())
}
if(((AbstractArrow) entity).isInBlock()) {
LAST_LOCATION.remove(entity);
continue;
}
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()) * 1.414213562);
try {
checkBlock(entity.getFacing().getOppositeFace(), entity.getLocation().getBlock(), LAST_LOCATION.get(entity).getBlock(), distance, entity.getLocation().getBlockY() - LAST_LOCATION.get(entity).getBlockY());
} catch (TechHiddenBlock techHiddenBlock) {
entity.remove();
}
Location last = LAST_LOCATION.get(entity);
LAST_LOCATION.remove(entity);
LAST_LOCATION.put(entity, entity.getLocation());
if(checkBlocks(entity.getLocation().getBlock(), last.getBlock()))
entity.remove();
else
LAST_LOCATION.put(entity, entity.getLocation());
}
}
@ -101,22 +100,39 @@ public class ArrowStopper implements StateDependent {
}
}
private void checkBlock(BlockFace face, Block block, Block start, 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();
private boolean checkBlocks(Block start, Block end) {
Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(start.getLocation(), Material.LIME_STAINED_GLASS.createBlockData()));
Block cursor = start;
if(lastdown != 0) {
boolean negativ = lastdown < 0;
BlockFace toFace = negativ?BlockFace.UP:BlockFace.DOWN;
checkBlock(face, block.getRelative(toFace), start, i - 1, lastdown + (negativ?1:-1));
return;
while (cursor.getY() != end.getY()) {
boolean negativ = cursor.getY() - end.getY() < 0;
BlockFace face = negativ?BlockFace.UP:BlockFace.DOWN;
if(checkBlock(cursor))
return true;
cursor = cursor.getRelative(face);
}
if(i != 0) {
checkBlock(face, block.getRelative(face), start, i - 1, lastdown);
while (cursor.getX() != end.getX()) {
boolean negativ = cursor.getX() - end.getX() < 0;
BlockFace face = negativ?BlockFace.EAST:BlockFace.WEST;
if(checkBlock(cursor))
return true;
cursor = cursor.getRelative(face);
}
while (cursor.getZ() != end.getZ()) {
boolean negativ = cursor.getZ() - end.getZ() < 0;
BlockFace face = negativ?BlockFace.SOUTH:BlockFace.NORTH;
if(checkBlock(cursor))
return true;
cursor = cursor.getRelative(face);
}
return false;
}
private class TechHiddenBlock extends Throwable {}
private boolean checkBlock(Block block) {
Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData()));
return Config.HiddenBlocks.contains(blockToId(block));
}
}