Improving Performance
Dieser Commit ist enthalten in:
Ursprung
dea991d7d7
Commit
36d27f52c6
@ -80,7 +80,6 @@ public class Config {
|
||||
public static final int ArenaMaxX;
|
||||
public static final int ArenaMaxZ;
|
||||
public static final boolean GroundWalkable;
|
||||
public static final int ArrowTechhiderCollision;
|
||||
|
||||
//schematic parameter
|
||||
public static final boolean RanksEnabled;
|
||||
@ -189,7 +188,6 @@ public class Config {
|
||||
double teamBlueSpawnOffsetX = worldconfig.getDouble("Arena.SpawnOffset.x");
|
||||
double teamBlueSpawnOffsetY = worldconfig.getDouble("Arena.SpawnOffset.y");
|
||||
double teamBlueSpawnOffsetZ = worldconfig.getDouble("Arena.SpawnOffset.z");
|
||||
ArrowTechhiderCollision = config.getInt("Times.ArrowTechhiderCollision");
|
||||
|
||||
RanksEnabled = config.getBoolean("Schematic.RanksEnabled");
|
||||
SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType"));
|
||||
|
@ -24,46 +24,41 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
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.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ArrowStopper extends BasicListener {
|
||||
|
||||
private BukkitTask task;
|
||||
private static final HashMap<Entity, Location> LAST_LOCATION = new HashMap<>();
|
||||
private static final Vector NULL_VECTOR = new Vector(0, 0, 0);
|
||||
|
||||
public ArrowStopper() {
|
||||
super(Config.ArrowTechhiderCollision != 0 ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class));
|
||||
super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class));
|
||||
}
|
||||
|
||||
private void run() {
|
||||
Iterator<Map.Entry<Entity, Location>> iterator = LAST_LOCATION.entrySet().iterator();
|
||||
Iterator<Arrow> iterator = Bukkit.getWorlds().get(0).getEntitiesByClass(Arrow.class).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<Entity, Location> e = iterator.next();
|
||||
Entity entity = e.getKey();
|
||||
if(checkBlocks(entity.getLocation().getBlock(), e.getValue().getBlock())){
|
||||
entity.remove();
|
||||
iterator.remove();
|
||||
} else {
|
||||
if(isValidEntity(entity, e)) {
|
||||
iterator.remove();
|
||||
}else {
|
||||
LAST_LOCATION.replace(e.getKey(), e.getKey().getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Arrow arrow = iterator.next();
|
||||
if(isValidEntity(arrow))
|
||||
continue;
|
||||
|
||||
@EventHandler()
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
LAST_LOCATION.put(event.getProjectile(), event.getEntity().getEyeLocation());
|
||||
Location prevLocation = arrow.getLocation().toVector().subtract(arrow.getVelocity()).toLocation(arrow.getWorld());
|
||||
if(arrow.getTicksLived() == 0)
|
||||
prevLocation = ((Player) arrow.getShooter()).getEyeLocation();
|
||||
if(checkBlocks(arrow.getLocation().getBlock(), prevLocation.getBlock())) {
|
||||
arrow.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,7 +71,6 @@ public class ArrowStopper extends BasicListener {
|
||||
public void disable() {
|
||||
super.disable();
|
||||
task.cancel();
|
||||
LAST_LOCATION.clear();
|
||||
}
|
||||
|
||||
private boolean checkBlocks(Block start, Block end) {
|
||||
@ -113,9 +107,12 @@ public class ArrowStopper extends BasicListener {
|
||||
return Config.HiddenBlockTags.contains(block.getType().name());
|
||||
}
|
||||
|
||||
private boolean isValidEntity(Entity entity, Map.Entry<Entity, Location> entry) {
|
||||
return entity.getTicksLived() > Config.ArrowTechhiderCollision ||
|
||||
((AbstractArrow) entity).isInBlock() ||
|
||||
entity.getLocation().equals(entry.getValue());
|
||||
private boolean isValidEntity(Arrow entity) {
|
||||
boolean teamFrom = entity.getVelocity().getZ() > 0;
|
||||
boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ();
|
||||
boolean otherSide = teamFrom == overMid;
|
||||
return otherSide ||
|
||||
entity.isInBlock() ||
|
||||
entity.getVelocity().equals(NULL_VECTOR);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren