Simplify RegionSystem
Dieser Commit ist enthalten in:
Ursprung
edb25635d4
Commit
828fb025aa
@ -45,18 +45,10 @@ public class CommandFire extends RegionToggleCommand {
|
||||
return region.isFire();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean toggleGlobal() {
|
||||
Region.NoRegion.fire = !Region.NoRegion.fire;
|
||||
return Region.NoRegion.fire;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFireDamage(BlockBurnEvent e) {
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFire()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.fire) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -64,8 +56,6 @@ public class CommandFire extends RegionToggleCommand {
|
||||
public void onFireSpread(BlockSpreadEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFire()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.fire) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -48,18 +48,10 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
return region.isFreeze();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean toggleGlobal() {
|
||||
Region.NoRegion.freeze = !Region.NoRegion.freeze;
|
||||
return Region.NoRegion.freeze;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent e) {
|
||||
Region.getRegion(e.getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -74,14 +66,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
e.setBuildable(false);
|
||||
e.getBlock().setType(Material.TNT, false);
|
||||
}
|
||||
}, () -> {
|
||||
if (!Region.NoRegion.freeze) {
|
||||
return;
|
||||
}
|
||||
if (e.getMaterial() == Material.TNT) {
|
||||
e.setBuildable(false);
|
||||
e.getBlock().setType(Material.TNT, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -89,8 +73,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -98,8 +80,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onPhysicsEvent(BlockPhysicsEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -107,8 +87,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onPistonExtend(BlockPistonExtendEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -116,8 +94,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onPistonRetract(BlockPistonRetractEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -125,8 +101,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onBlockGrow(BlockGrowEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -134,8 +108,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onRedstoneEvent(BlockRedstoneEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent());
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setNewCurrent(e.getOldCurrent());
|
||||
});
|
||||
}
|
||||
|
||||
@ -143,8 +115,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onBlockDispense(BlockDispenseEvent e){
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -152,8 +122,6 @@ public class CommandFreeze extends RegionToggleCommand {
|
||||
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
|
||||
Region.getRegion(e.getDestination().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
}, () -> {
|
||||
if (Region.NoRegion.freeze) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -42,11 +42,7 @@ public class CommandInfo implements CommandExecutor {
|
||||
|
||||
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region == null) {
|
||||
sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS"));
|
||||
} else {
|
||||
sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS"));
|
||||
}
|
||||
|
||||
List<BauweltMember> members = BauweltMember.getMembers(BauSystem.getOwnerID());
|
||||
StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: ");
|
||||
|
@ -111,33 +111,10 @@ public class CommandTNT implements CommandExecutor, Listener {
|
||||
}
|
||||
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region == null) {
|
||||
tntGlobalToggle(requestedMode, requestedMessage);
|
||||
return false;
|
||||
}
|
||||
tntToggle(region, requestedMode, requestedMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
private void tntGlobalToggle(TNTMode requestedMode, String requestedMessage) {
|
||||
if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) {
|
||||
Region.NoRegion.tnt = requestedMode;
|
||||
RegionToggleCommand.actionBar(requestedMessage);
|
||||
return;
|
||||
}
|
||||
switch (Region.NoRegion.tnt) {
|
||||
case ON:
|
||||
case ONLY_TB:
|
||||
Region.NoRegion.tnt = TNTMode.OFF;
|
||||
RegionToggleCommand.actionBar(getDisableMessage());
|
||||
break;
|
||||
case OFF:
|
||||
Region.NoRegion.tnt = TNTMode.ON;
|
||||
RegionToggleCommand.actionBar(getEnableMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) {
|
||||
if (requestedMode != null && region.hasTestblock()) {
|
||||
region.setTntMode(requestedMode);
|
||||
@ -166,9 +143,6 @@ public class CommandTNT implements CommandExecutor, Listener {
|
||||
public void onExplode(EntityExplodeEvent event) {
|
||||
event.blockList().removeIf(block -> {
|
||||
Region region = Region.getRegion(block.getLocation());
|
||||
if (region == null) {
|
||||
return Region.NoRegion.tnt == TNTMode.OFF;
|
||||
}
|
||||
if (region.getTntMode() == TNTMode.OFF) return true;
|
||||
if (region.getTntMode() == TNTMode.ON) return false;
|
||||
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
|
||||
|
@ -52,14 +52,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
|
||||
}
|
||||
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region == null) {
|
||||
if (toggleGlobal()) {
|
||||
actionBar(getEnableMessage());
|
||||
} else {
|
||||
actionBar(getDisableMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (toggle(region)) {
|
||||
actionBar(region, getEnableMessage());
|
||||
} else {
|
||||
@ -69,11 +61,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
|
||||
}
|
||||
|
||||
public static void actionBar(Region region, String s) {
|
||||
if (Region.GlobalRegion.isGlobalRegion(region)) {
|
||||
Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
|
||||
}
|
||||
|
||||
public static void actionBar(String s) {
|
||||
Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
|
||||
}
|
||||
|
||||
abstract String getNoPermMessage();
|
||||
@ -84,6 +76,5 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
|
||||
* {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()}
|
||||
*/
|
||||
abstract boolean toggle(Region region);
|
||||
abstract boolean toggleGlobal();
|
||||
|
||||
}
|
||||
|
@ -60,15 +60,9 @@ public class BauScoreboard implements Listener {
|
||||
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||
strings.add("§2");
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (region != null) {
|
||||
strings.add("§eTNT§8: " + region.getTntMode().getName());
|
||||
strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus"));
|
||||
strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can"));
|
||||
} else {
|
||||
strings.add("§eTNT§8: " + Region.NoRegion.tnt.getName());
|
||||
strings.add("§eFreeze§8: " + (Region.NoRegion.freeze ? "§aan" : "§caus"));
|
||||
strings.add("§eFire§8: " + (Region.NoRegion.fire ? "§aaus" : "§can"));
|
||||
}
|
||||
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
||||
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
||||
|
||||
|
@ -41,13 +41,6 @@ public class Region {
|
||||
private static final List<Region> regions = new ArrayList<>();
|
||||
private static boolean buildArea = false;
|
||||
|
||||
public static class NoRegion {
|
||||
private NoRegion() {}
|
||||
public static TNTMode tnt = TNTMode.OFF;
|
||||
public static boolean fire = false;
|
||||
public static boolean freeze = false;
|
||||
}
|
||||
|
||||
static{
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
try {
|
||||
@ -77,10 +70,10 @@ public class Region {
|
||||
for (Region region : regions) {
|
||||
if (region.inRegion(location)) return region;
|
||||
}
|
||||
return null;
|
||||
return GlobalRegion.getInstance();
|
||||
}
|
||||
|
||||
public static void getRegion(Location location, Consumer<Region> regionConsumer, Runnable noRegion) {
|
||||
public static void getRegion(Location location, Consumer<Region> regionConsumer) {
|
||||
boolean b = true;
|
||||
for (Region region : regions) {
|
||||
if (region.inRegion(location)) {
|
||||
@ -88,7 +81,7 @@ public class Region {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
if (b) noRegion.run();
|
||||
if (b) regionConsumer.accept(GlobalRegion.getInstance());
|
||||
}
|
||||
|
||||
private final String name;
|
||||
@ -114,6 +107,16 @@ public class Region {
|
||||
regions.add(this);
|
||||
}
|
||||
|
||||
public Region(String name) {
|
||||
this.name = name;
|
||||
this.minX = 0;
|
||||
this.minY = 0;
|
||||
this.minZ = 0;
|
||||
this.prototype = null;
|
||||
this.optionsLinkedWith = null;
|
||||
tntMode = TNTMode.OFF;
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Consumer<Region> regionConsumer) {
|
||||
if (optionsLinkedWith == null) {
|
||||
return;
|
||||
@ -194,6 +197,64 @@ public class Region {
|
||||
prototype.protect(this, schem);
|
||||
}
|
||||
|
||||
public static class GlobalRegion extends Region {
|
||||
|
||||
private static final GlobalRegion GLOBAL_REGION = new GlobalRegion();
|
||||
|
||||
public static GlobalRegion getInstance() {
|
||||
return GLOBAL_REGION;
|
||||
}
|
||||
|
||||
public static boolean isGlobalRegion(Region region) {
|
||||
return region == GLOBAL_REGION;
|
||||
}
|
||||
|
||||
public GlobalRegion() {
|
||||
super("Global");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inRegion(Location l) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBuildRegion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inBuildRegion(Location l) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastreset() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTestblock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasProtection() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void protect(Schematic schem) throws IOException, NoClipboardException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Prototype{
|
||||
private static final Map<String, Prototype> prototypes = new HashMap<>();
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren