Adding Better Tracking
Dieser Commit ist enthalten in:
Ursprung
664350d286
Commit
81ac127bbf
@ -26,6 +26,6 @@ public class ArrowStopper_12 {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static int blockToId(Block block){
|
||||
return block.getTypeId() << 4 + block.getData();
|
||||
return block.getTypeId();
|
||||
}
|
||||
}
|
||||
|
@ -25,18 +25,24 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
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;
|
||||
|
||||
public class ArrowStopper implements StateDependent {
|
||||
|
||||
private BukkitTask task;
|
||||
private static final HashMap<Entity, Location> LAST_LOCATION = new HashMap<>();
|
||||
|
||||
public static void init() {
|
||||
if(Config.ArrowTechhiderCollision == -1)
|
||||
@ -51,8 +57,16 @@ public class ArrowStopper implements StateDependent {
|
||||
for (Entity entity : arrows) {
|
||||
if(entity.getTicksLived() > Config.ArrowTechhiderCollision)
|
||||
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();
|
||||
}
|
||||
LAST_LOCATION.remove(entity);
|
||||
LAST_LOCATION.put(entity, entity.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +83,7 @@ public class ArrowStopper implements StateDependent {
|
||||
@Override
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
LAST_LOCATION.clear();
|
||||
}
|
||||
|
||||
private static int blockToId(Block block){
|
||||
@ -83,4 +98,19 @@ public class ArrowStopper implements StateDependent {
|
||||
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 {}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren