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(){
return "§aFeuerschaden aktiviert";
}
@Override
String getNoRegionMessage() {
return "§cDu befindest dich derzeit in keiner Region";
}
@Override
boolean toggle(Region region) {
@ -53,10 +49,18 @@ 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,6 +68,8 @@ 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);
});
}

Datei anzeigen

@ -21,11 +21,7 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
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.event.EventHandler;
import org.bukkit.event.block.*;
@ -50,10 +46,6 @@ public class CommandFreeze extends RegionToggleCommand {
String getDisableMessage(){
return "§aWelt aufgetaut";
}
@Override
String getNoRegionMessage() {
return "§cDu befindest dich derzeit in keiner Region";
}
@Override
boolean toggle(Region region) {
@ -61,6 +53,12 @@ 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 -> {
@ -70,6 +68,13 @@ public class CommandFreeze extends RegionToggleCommand {
if (e.getEntityType() == EntityType.FALLING_BLOCK) {
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){
Region.getRegion(e.getBlock().getLocation(), region -> {
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){
Region.getRegion(e.getBlock().getLocation(), region -> {
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){
Region.getRegion(e.getBlock().getLocation(), region -> {
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){
Region.getRegion(e.getBlock().getLocation(), region -> {
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){
Region.getRegion(e.getBlock().getLocation(), region -> {
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){
Region.getRegion(e.getBlock().getLocation(), region -> {
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){
Region.getRegion(e.getDestination().getLocation(), region -> {
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());
Region region = Region.getRegion(player);
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 {
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.world.Region;
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.command.Command;
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";
}
private String getNoRegionMessage() {
return "§cDu befindest dich derzeit in keiner Region";
}
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (!(sender instanceof Player)) return false;
@ -118,13 +112,37 @@ public class CommandTNT implements CommandExecutor, Listener {
Region region = Region.getRegion(player.getLocation());
if (region == null) {
RegionToggleCommand.actionBar(player, getNoRegionMessage());
tntGlobalToggle(player, requestedMode, requestedMessage);
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) {
region.setTntMode(requestedMode);
RegionToggleCommand.actionBar(region, requestedMessage);
return false;
return;
}
switch (region.getTntMode()) {
case ON:
@ -142,14 +160,15 @@ public class CommandTNT implements CommandExecutor, Listener {
}
break;
}
return false;
}
@EventHandler
public void onExplode(EntityExplodeEvent event) {
event.blockList().removeIf(block -> {
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.ON) return false;
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 net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_15_R1.BlockCactus;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -54,7 +53,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
Region region = Region.getRegion(player);
if (region == null) {
actionBar(player, getNoRegionMessage());
if (toggleGlobal()) {
actionBar(player, getEnableMessage());
} else {
actionBar(player, getDisableMessage());
}
return false;
}
if (toggle(region)) {
@ -73,7 +76,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s));
}
abstract String getNoRegionMessage();
abstract String getNoPermMessage();
abstract String getEnableMessage();
abstract String getDisableMessage();
@ -82,5 +84,6 @@ 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();
}

Datei anzeigen

@ -64,6 +64,10 @@ public class BauScoreboard implements Listener {
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"));

Datei anzeigen

@ -42,6 +42,13 @@ 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 {
@ -78,10 +85,6 @@ public class Region {
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) {
boolean b = true;
for (Region region : regions) {