SteamWar/BauSystem2.0
Archiviert
12
0

Optimize FreezeListener

Dieser Commit ist enthalten in:
yoyosource 2021-05-01 17:33:26 +02:00
Ursprung 9e8372a318
Commit 2a0dbaa049
5 geänderte Dateien mit 41 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -21,7 +21,7 @@ public class FreezeListener implements Listener {
@EventHandler @EventHandler
public void onEntitySpawn(EntitySpawnEvent e) { public void onEntitySpawn(EntitySpawnEvent e) {
if (Region.getRegion(e.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.INACTIVE) { if (Region.getRegion(e.getLocation()).get(Flag.FREEZE) == FreezeMode.INACTIVE) {
return; return;
} }
e.setCancelled(true); e.setCancelled(true);
@ -35,7 +35,8 @@ public class FreezeListener implements Listener {
@EventHandler @EventHandler
public void onBlockCanBuild(BlockCanBuildEvent e) { public void onBlockCanBuild(BlockCanBuildEvent e) {
if (!e.isBuildable()) return; if (!e.isBuildable()) return;
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.INACTIVE) return; if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.INACTIVE)
return;
if (e.getMaterial() == Material.TNT) { if (e.getMaterial() == Material.TNT) {
e.setBuildable(false); e.setBuildable(false);
e.getBlock().setType(Material.TNT, false); e.getBlock().setType(Material.TNT, false);
@ -44,42 +45,58 @@ public class FreezeListener implements Listener {
@EventHandler @EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent e) { public void onEntityChangeBlock(EntityChangeBlockEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onPhysicsEvent(BlockPhysicsEvent e){ public void onPhysicsEvent(BlockPhysicsEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onPistonExtend(BlockPistonExtendEvent e){ public void onPistonExtend(BlockPistonExtendEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onPistonRetract(BlockPistonRetractEvent e){ public void onPistonRetract(BlockPistonRetractEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onBlockGrow(BlockGrowEvent e){ public void onBlockGrow(BlockGrowEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e) { public void onRedstoneEvent(BlockRedstoneEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setNewCurrent(e.getOldCurrent()); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setNewCurrent(e.getOldCurrent());
}
} }
@EventHandler @EventHandler
public void onBlockDispense(BlockDispenseEvent e) { public void onBlockDispense(BlockDispenseEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e){ public void onInventoryMoveEvent(InventoryMoveItemEvent e) {
if (Region.getRegion(e.getDestination().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true); if (Region.getRegion(e.getDestination().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
}
} }
} }

Datei anzeigen

@ -46,7 +46,7 @@ public class RamUsage implements Listener {
long presumableFreeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory; long presumableFreeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory;
double percentageFree = presumableFreeMemory / (double) Runtime.getRuntime().maxMemory(); double percentageFree = presumableFreeMemory / (double) Runtime.getRuntime().maxMemory();
bossBar.setProgress(1 - percentageFree); bossBar.setProgress(1 - percentageFree);
}, 1, 1); }, 20, 20);
} }
@EventHandler @EventHandler

Datei anzeigen

@ -59,9 +59,8 @@ public class FlagStorage {
return flags.put(flagType, value) != value; return flags.put(flagType, value) != value;
} }
@SuppressWarnings("unchecked") public Flag.Value<?> get(final Flag flagType) {
public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(final Flag flagType) { return flags.get(flagType);
return (Flag.Value<T>) flags.get(flagType);
} }
private void readKeys() { private void readKeys() {

Datei anzeigen

@ -51,8 +51,12 @@ public class Region {
private static final List<Region> REGION_LIST = new ArrayList<>(); private static final List<Region> REGION_LIST = new ArrayList<>();
public static Region getRegion(Location location) { public static Region getRegion(Location location) {
String s = Thread.currentThread().getStackTrace()[2].toString();
if (!s.contains("sidebar")) {
System.out.println(s +" " + location);
}
for (Region region : REGION_LIST) { for (Region region : REGION_LIST) {
if (region.inRegion(location, RegionType.NORMAL, RegionExtensionType.NORMAL)) { if (region.inRegion(location, region.minPoint, region.maxPoint)) {
return region; return region;
} }
} }
@ -276,7 +280,7 @@ public class Region {
setLinkedRegion(region -> region.flagStorage.set(flagType, value)); setLinkedRegion(region -> region.flagStorage.set(flagType, value));
} }
public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag flagType) { public Flag.Value<?> get(Flag flagType) {
return flagStorage.get(flagType); return flagStorage.get(flagType);
} }

Datei anzeigen

@ -28,7 +28,6 @@ import yapion.hierarchy.output.FileOutput;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONType;
import yapion.parser.YAPIONParser; import yapion.parser.YAPIONParser;
import yapion.serializing.YAPIONDeserializer;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;