diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/WaterDestroyCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/WaterDestroyCommand.java new file mode 100644 index 00000000..2b64a5ae --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/WaterDestroyCommand.java @@ -0,0 +1,64 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.region; + +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.WaterDestroyMode; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class WaterDestroyCommand extends SWCommand { + public WaterDestroyCommand() { + super("waterblock", "waterdestroy", "wb"); + } + + private String getEnableMessage(){ + return "REGION_WATER_ENABLED"; + } + + private String getDisableMessage(){ + return "REGION_WATER_DISABLED"; + } + + @Register(description = "REGION_WATER_HELP") + public void toggleCommand(@Validator Player p) { + Region region = Region.getRegion(p.getLocation()); + + if (toggle(region)) { + RegionUtils.actionBar(region, getEnableMessage()); + } else { + RegionUtils.actionBar(region, getDisableMessage()); + } + } + + private boolean toggle(Region region) { + if (region.getRegionData().get(Flag.WATER_DESTROY).isWithDefault(WaterDestroyMode.DENY)) { + region.getRegionData().set(Flag.WATER_DESTROY, WaterDestroyMode.ALLOW); + return false; + } else { + region.getRegionData().set(Flag.WATER_DESTROY, WaterDestroyMode.DENY); + return true; + } + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/WaterDestroyListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/WaterDestroyListener.java new file mode 100644 index 00000000..4e4ba725 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/WaterDestroyListener.java @@ -0,0 +1,57 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.region; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.WaterDestroyMode; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFromToEvent; + +@Linked +public class WaterDestroyListener implements Listener, ScoreboardElement { + + @EventHandler + public void onBlockFromTo(BlockFromToEvent event) { + if (event.getBlock().getType() == Material.WATER && event.getToBlock().getType() != Material.AIR && Region.getRegion(event.getBlock().getLocation()).getRegionData().get(Flag.WATER_DESTROY).isWithDefault(WaterDestroyMode.DENY)) event.setCancelled(true); + } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 5; + } + + @Override + public String get(Region region, Player p) { + if (region.getRegionData().get(Flag.WATER_DESTROY).isWithDefault(WaterDestroyMode.ALLOW)) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.WATER_DESTROY.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.getRegionData().get(Flag.WATER_DESTROY).getWithDefault().getChatValue(), p); + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index f2213470..5bd32444 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -43,6 +43,7 @@ public final class Flag & Flag.Value> implements EnumDispla public static final Flag NO_GRAVITY = new Flag<>("NO_GRAVITY", "FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE); public static final Flag TESTBLOCK = new Flag<>("TESTBLOCK", "FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE); public static final Flag CHANGED = new Flag<>("CHANGED", "FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE); + public static final Flag WATER_DESTROY = new Flag<>("WATER_DESTROY", "FLAG_WATER_DESTROY", WaterDestroyMode.class, WaterDestroyMode.ALLOW); private String name; private int ordinal; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/WaterDestroyMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/WaterDestroyMode.java new file mode 100644 index 00000000..1917ebea --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/WaterDestroyMode.java @@ -0,0 +1,56 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.region.flags; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum WaterDestroyMode implements Flag.Value { + + ALLOW("FLAG_WATER_DESTROY_ALLOW"), + DENY("FLAG_WATER_DESTROY_DENY"); + + private static WaterDestroyMode[] values; + private final String chatValue; + + @Override + public WaterDestroyMode[] getValues() { + if (WaterDestroyMode.values == null) { + WaterDestroyMode.values = WaterDestroyMode.values(); + } + return WaterDestroyMode.values; + } + + @Override + public WaterDestroyMode getValue() { + return this; + } + + @Override + public WaterDestroyMode getValueOf(final String name) { + try { + return WaterDestroyMode.valueOf(name.toUpperCase()); + } catch (IllegalArgumentException e) { + return ALLOW; + } + } +} \ No newline at end of file diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegionData.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegionData.java index 4da87bd9..b42b15e7 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegionData.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegionData.java @@ -34,7 +34,7 @@ public class FixedRegionData extends RegionData { @Override public @NonNull & Flag.Value> RegionFlagPolicy has(@NonNull Flag flag) { - if (flag.oneOf(Flag.COLOR, Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.PROTECT, Flag.NO_GRAVITY, Flag.CHANGED)) { + if (flag.oneOf(Flag.COLOR, Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.PROTECT, Flag.NO_GRAVITY, Flag.CHANGED, Flag.WATER_DESTROY)) { return RegionFlagPolicy.WRITABLE; } if (flag.oneOf(Flag.ITEMS) && Core.getVersion() >= 20) {