Rework Arrow Tracking
Dieser Commit ist enthalten in:
Ursprung
8c93f446df
Commit
5366011bd7
@ -34,10 +34,7 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ArrowStopper implements StateDependent {
|
public class ArrowStopper implements StateDependent {
|
||||||
|
|
||||||
@ -55,19 +52,21 @@ public class ArrowStopper implements StateDependent {
|
|||||||
if(arrows.isEmpty())
|
if(arrows.isEmpty())
|
||||||
return;
|
return;
|
||||||
for (Entity entity : arrows) {
|
for (Entity entity : arrows) {
|
||||||
if(entity.getTicksLived() > Config.ArrowTechhiderCollision)
|
if(entity.getTicksLived() > Config.ArrowTechhiderCollision){
|
||||||
|
LAST_LOCATION.remove(entity);
|
||||||
continue;
|
continue;
|
||||||
if(((AbstractArrow) entity).isInBlock())
|
}
|
||||||
|
if(((AbstractArrow) entity).isInBlock()) {
|
||||||
|
LAST_LOCATION.remove(entity);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if(!LAST_LOCATION.containsKey(entity))
|
if(!LAST_LOCATION.containsKey(entity))
|
||||||
LAST_LOCATION.put(entity, ((Player) ((AbstractArrow) entity).getShooter()).getEyeLocation());
|
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);
|
Location last = LAST_LOCATION.get(entity);
|
||||||
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();
|
|
||||||
}
|
|
||||||
LAST_LOCATION.remove(entity);
|
LAST_LOCATION.remove(entity);
|
||||||
|
if(checkBlocks(entity.getLocation().getBlock(), last.getBlock()))
|
||||||
|
entity.remove();
|
||||||
|
else
|
||||||
LAST_LOCATION.put(entity, entity.getLocation());
|
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 {
|
private boolean checkBlocks(Block start, Block end) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(start.getLocation(), Material.LIME_STAINED_GLASS.createBlockData()));
|
||||||
|
Block cursor = start;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 boolean checkBlock(Block block) {
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData()));
|
Bukkit.getOnlinePlayers().forEach(player -> player.sendBlockChange(block.getLocation(), Material.RED_STAINED_GLASS.createBlockData()));
|
||||||
if(Config.HiddenBlocks.contains(blockToId(block)))
|
return 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), start, i - 1, lastdown + (negativ?1:-1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i != 0) {
|
|
||||||
checkBlock(face, block.getRelative(face), start, i - 1, lastdown);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TechHiddenBlock extends Throwable {}
|
|
||||||
}
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren