From 635e18e7ed47029992ec59cf32429275d904c49c Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sat, 10 Jul 2021 15:50:38 +0200 Subject: [PATCH] Add `copper-oxide` flag --- .../listener/BlockEventListener117.java | 42 +++++++++++++++++ .../core/plot/flag/GlobalFlagContainer.java | 2 + .../flag/implementations/CopperOxideFlag.java | 46 +++++++++++++++++++ Core/src/main/resources/lang/messages_en.json | 1 + 4 files changed, 91 insertions(+) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CopperOxideFlag.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java index 1ef7ab09b..3787e8baa 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java @@ -31,6 +31,7 @@ import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.flag.implementations.CopperOxideFlag; import com.plotsquared.core.plot.flag.implementations.MiscInteractFlag; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -40,6 +41,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFertilizeEvent; +import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockReceiveGameEvent; import java.util.List; @@ -137,4 +139,44 @@ public class BlockEventListener117 implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockForm(BlockFormEvent event) { + Block block = event.getBlock(); + Location location = BukkitUtil.adapt(block.getLocation()); + if (location.isPlotRoad()) { + event.setCancelled(true); + return; + } + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getOwnedPlot(location); + if (plot == null) { + return; + } + switch (event.getNewState().getType()) { + case COPPER_BLOCK: + case EXPOSED_COPPER: + case WEATHERED_COPPER: + case OXIDIZED_COPPER: + case CUT_COPPER: + case EXPOSED_CUT_COPPER: + case WEATHERED_CUT_COPPER: + case OXIDIZED_CUT_COPPER: + case CUT_COPPER_STAIRS: + case EXPOSED_CUT_COPPER_STAIRS: + case WEATHERED_CUT_COPPER_STAIRS: + case OXIDIZED_CUT_COPPER_STAIRS: + case CUT_COPPER_SLAB: + case EXPOSED_CUT_COPPER_SLAB: + case WEATHERED_CUT_COPPER_SLAB: + case OXIDIZED_CUT_COPPER_SLAB: + if (!plot.getFlag(CopperOxideFlag.class)) { + plot.debug("Copper could not oxide because copper-oxide = false"); + event.setCancelled(true); + } + } + } + } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java index 4672fe28e..0fd188d54 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java @@ -35,6 +35,7 @@ import com.plotsquared.core.plot.flag.implementations.BlockIgnitionFlag; import com.plotsquared.core.plot.flag.implementations.BlockedCmdsFlag; import com.plotsquared.core.plot.flag.implementations.BreakFlag; import com.plotsquared.core.plot.flag.implementations.ChatFlag; +import com.plotsquared.core.plot.flag.implementations.CopperOxideFlag; import com.plotsquared.core.plot.flag.implementations.CoralDryFlag; import com.plotsquared.core.plot.flag.implementations.CropGrowFlag; import com.plotsquared.core.plot.flag.implementations.DenyExitFlag; @@ -193,6 +194,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(DenyPortalsFlag.DENY_PORTALS_FALSE); this.addFlag(LecternReadBookFlag.LECTERN_READ_BOOK_FALSE); this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE); + this.addFlag(CopperOxideFlag.COPPER_OXIDE_FALSE); // Enum Flags this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CopperOxideFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CopperOxideFlag.java new file mode 100644 index 000000000..4c9dd6128 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CopperOxideFlag.java @@ -0,0 +1,46 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2021 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.plot.flag.implementations; + +import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.plot.flag.types.BooleanFlag; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class CopperOxideFlag extends BooleanFlag { + + public static final CopperOxideFlag COPPER_OXIDE_TRUE = new CopperOxideFlag(true); + public static final CopperOxideFlag COPPER_OXIDE_FALSE = new CopperOxideFlag(false); + + private CopperOxideFlag(boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_copper_oxide")); + } + + @Override + protected CopperOxideFlag flagOf(@NonNull Boolean value) { + return value ? COPPER_OXIDE_TRUE : COPPER_OXIDE_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 5cc6251c0..4910dc8e6 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -575,6 +575,7 @@ "flags.flag_description_redstone": "Set to `false` to disable redstone in the plot.", "flags.flag_description_server_plot": "Set to `true` to turn the plot into a server plot. This is equivalent to setting the server as the plot owner.", "flags.flag_description_snow_form": "Set to `true` to allow snow to form within the plot.", + "flags.flag_description_copper_oxide": "Set to `true` to allow copper to oxide within the plot.", "flags.flag_description_snow_melt": "Set to `true` to allow snow to melt within the plot.", "flags.flag_description_soil_dry": "Set to `true` to allow soil to dry within the plot.", "flags.flag_description_coral_dry": "Set to `true` to allow coral blocks to dry within the plot.",