SteamWar/BauSystem
Archiviert
13
0

Add other region to toggleable

Dieser Commit ist enthalten in:
jojo 2021-01-25 17:10:45 +01:00
Ursprung 4268647057
Commit 90d0063465
7 geänderte Dateien mit 84 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -42,10 +42,6 @@ public class CommandFire extends RegionToggleCommand {
String getDisableMessage(){ String getDisableMessage(){
return "§aFeuerschaden aktiviert"; return "§aFeuerschaden aktiviert";
} }
@Override
String getNoRegionMessage() {
return "§cDu befindest dich derzeit in keiner Region";
}
@Override @Override
boolean toggle(Region region) { boolean toggle(Region region) {
@ -53,10 +49,18 @@ public class CommandFire extends RegionToggleCommand {
return region.isFire(); return region.isFire();
} }
@Override
boolean toggleGlobal() {
Region.NoRegion.fire = !Region.NoRegion.fire;
return Region.NoRegion.fire;
}
@EventHandler @EventHandler
public void onFireDamage(BlockBurnEvent e) { public void onFireDamage(BlockBurnEvent e) {
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFire()) e.setCancelled(true); if (region.isFire()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.fire) e.setCancelled(true);
}); });
} }
@ -64,6 +68,8 @@ public class CommandFire extends RegionToggleCommand {
public void onFireSpread(BlockSpreadEvent e){ public void onFireSpread(BlockSpreadEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFire()) e.setCancelled(true); if (region.isFire()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.fire) e.setCancelled(true);
}); });
} }

Datei anzeigen

@ -21,11 +21,7 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Region;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.*; import org.bukkit.event.block.*;
@ -50,10 +46,6 @@ public class CommandFreeze extends RegionToggleCommand {
String getDisableMessage(){ String getDisableMessage(){
return "§aWelt aufgetaut"; return "§aWelt aufgetaut";
} }
@Override
String getNoRegionMessage() {
return "§cDu befindest dich derzeit in keiner Region";
}
@Override @Override
boolean toggle(Region region) { boolean toggle(Region region) {
@ -61,6 +53,12 @@ public class CommandFreeze extends RegionToggleCommand {
return region.isFreeze(); return region.isFreeze();
} }
@Override
boolean toggleGlobal() {
Region.NoRegion.freeze = !Region.NoRegion.freeze;
return Region.NoRegion.freeze;
}
@EventHandler @EventHandler
public void onEntitySpawn(EntitySpawnEvent e) { public void onEntitySpawn(EntitySpawnEvent e) {
Region.getRegion(e.getLocation(), region -> { Region.getRegion(e.getLocation(), region -> {
@ -70,6 +68,13 @@ public class CommandFreeze extends RegionToggleCommand {
if (e.getEntityType() == EntityType.FALLING_BLOCK) { if (e.getEntityType() == EntityType.FALLING_BLOCK) {
e.setCancelled(true); e.setCancelled(true);
} }
}, () -> {
if (!Region.NoRegion.freeze) {
return;
}
if (e.getEntityType() == EntityType.FALLING_BLOCK) {
e.setCancelled(true);
}
}); });
} }
@ -77,6 +82,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onPhysicsEvent(BlockPhysicsEvent e){ public void onPhysicsEvent(BlockPhysicsEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFreeze()) e.setCancelled(true); if (region.isFreeze()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.freeze) e.setCancelled(true);
}); });
} }
@ -84,6 +91,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onPistonExtend(BlockPistonExtendEvent e){ public void onPistonExtend(BlockPistonExtendEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFreeze()) e.setCancelled(true); if (region.isFreeze()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.freeze) e.setCancelled(true);
}); });
} }
@ -91,6 +100,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onPistonRetract(BlockPistonRetractEvent e){ public void onPistonRetract(BlockPistonRetractEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFreeze()) e.setCancelled(true); if (region.isFreeze()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.freeze) e.setCancelled(true);
}); });
} }
@ -98,6 +109,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onBlockGrow(BlockGrowEvent e){ public void onBlockGrow(BlockGrowEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFreeze()) e.setCancelled(true); if (region.isFreeze()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.freeze) e.setCancelled(true);
}); });
} }
@ -105,6 +118,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onRedstoneEvent(BlockRedstoneEvent e){ public void onRedstoneEvent(BlockRedstoneEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent());
}, () -> {
if (Region.NoRegion.freeze) e.setNewCurrent(e.getOldCurrent());
}); });
} }
@ -112,6 +127,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onBlockDispense(BlockDispenseEvent e){ public void onBlockDispense(BlockDispenseEvent e){
Region.getRegion(e.getBlock().getLocation(), region -> { Region.getRegion(e.getBlock().getLocation(), region -> {
if (region.isFreeze()) e.setCancelled(true); if (region.isFreeze()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.freeze) e.setCancelled(true);
}); });
} }
@ -119,6 +136,8 @@ public class CommandFreeze extends RegionToggleCommand {
public void onInventoryMoveEvent(InventoryMoveItemEvent e){ public void onInventoryMoveEvent(InventoryMoveItemEvent e){
Region.getRegion(e.getDestination().getLocation(), region -> { Region.getRegion(e.getDestination().getLocation(), region -> {
if (region.isFreeze()) e.setCancelled(true); if (region.isFreeze()) e.setCancelled(true);
}, () -> {
if (Region.NoRegion.freeze) e.setCancelled(true);
}); });
} }
} }

Datei anzeigen

@ -43,7 +43,7 @@ public class CommandInfo implements CommandExecutor {
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
Region region = Region.getRegion(player); Region region = Region.getRegion(player);
if (region == null) { if (region == null) {
sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); 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 { } else {
sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS"));
} }

Datei anzeigen

@ -23,8 +23,6 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -77,10 +75,6 @@ public class CommandTNT implements CommandExecutor, Listener {
return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; return "§cEine Explosion hätte Blöcke im Baubereich zerstört";
} }
private String getNoRegionMessage() {
return "§cDu befindest dich derzeit in keiner Region";
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (!(sender instanceof Player)) return false; if (!(sender instanceof Player)) return false;
@ -118,13 +112,37 @@ public class CommandTNT implements CommandExecutor, Listener {
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
if (region == null) { if (region == null) {
RegionToggleCommand.actionBar(player, getNoRegionMessage()); tntGlobalToggle(player, requestedMode, requestedMessage);
return false; return false;
} }
tntToggle(region, requestedMode, requestedMessage);
return false;
}
private void tntGlobalToggle(Player player, TNTMode requestedMode, String requestedMessage) {
if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) {
Region.NoRegion.tnt = requestedMode;
RegionToggleCommand.actionBar(player, requestedMessage);
return;
}
switch (Region.NoRegion.tnt) {
case ON:
case ONLY_TB:
Region.NoRegion.tnt = TNTMode.OFF;
RegionToggleCommand.actionBar(player, getDisableMessage());
break;
case OFF:
Region.NoRegion.tnt = TNTMode.ON;
RegionToggleCommand.actionBar(player, getEnableMessage());
break;
}
}
private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) {
if (requestedMode != null) { if (requestedMode != null) {
region.setTntMode(requestedMode); region.setTntMode(requestedMode);
RegionToggleCommand.actionBar(region, requestedMessage); RegionToggleCommand.actionBar(region, requestedMessage);
return false; return;
} }
switch (region.getTntMode()) { switch (region.getTntMode()) {
case ON: case ON:
@ -142,14 +160,15 @@ public class CommandTNT implements CommandExecutor, Listener {
} }
break; break;
} }
return false;
} }
@EventHandler @EventHandler
public void onExplode(EntityExplodeEvent event) { public void onExplode(EntityExplodeEvent event) {
event.blockList().removeIf(block -> { event.blockList().removeIf(block -> {
Region region = Region.getRegion(block.getLocation()); Region region = Region.getRegion(block.getLocation());
if (region == null) return false; if (region == null) {
return Region.NoRegion.tnt == TNTMode.OFF;
}
if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.OFF) return true;
if (region.getTntMode() == TNTMode.ON) return false; if (region.getTntMode() == TNTMode.ON) return false;
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {

Datei anzeigen

@ -27,7 +27,6 @@ import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_15_R1.BlockCactus;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -54,7 +53,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
Region region = Region.getRegion(player); Region region = Region.getRegion(player);
if (region == null) { if (region == null) {
actionBar(player, getNoRegionMessage()); if (toggleGlobal()) {
actionBar(player, getEnableMessage());
} else {
actionBar(player, getDisableMessage());
}
return false; return false;
} }
if (toggle(region)) { if (toggle(region)) {
@ -73,7 +76,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s));
} }
abstract String getNoRegionMessage();
abstract String getNoPermMessage(); abstract String getNoPermMessage();
abstract String getEnableMessage(); abstract String getEnableMessage();
abstract String getDisableMessage(); abstract String getDisableMessage();
@ -82,5 +84,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
* {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()}
*/ */
abstract boolean toggle(Region region); abstract boolean toggle(Region region);
abstract boolean toggleGlobal();
} }

Datei anzeigen

@ -64,6 +64,10 @@ public class BauScoreboard implements Listener {
strings.add("§eTNT§8: " + region.getTntMode().getName()); strings.add("§eTNT§8: " + region.getTntMode().getName());
strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus"));
strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); 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("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));

Datei anzeigen

@ -42,6 +42,13 @@ public class Region {
private static final List<Region> regions = new ArrayList<>(); private static final List<Region> regions = new ArrayList<>();
private static boolean buildArea = false; 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{ static{
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
try { try {
@ -78,10 +85,6 @@ public class Region {
return null; return null;
} }
public static void getRegion(Location location, Consumer<Region> regionConsumer) {
getRegion(location, regionConsumer, () -> {});
}
public static void getRegion(Location location, Consumer<Region> regionConsumer, Runnable noRegion) { public static void getRegion(Location location, Consumer<Region> regionConsumer, Runnable noRegion) {
boolean b = true; boolean b = true;
for (Region region : regions) { for (Region region : regions) {