Introduce tile-drop flag (#4371)

* added tile-drops flag

* added tile-drops flag

* added tile-drop flag

* updated description

* relocated listener
This commit is contained in:
Nicolai 2024-03-26 17:38:55 +01:00 committed by GitHub
parent e46dbd826c
commit 82f868ae7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 76 additions and 0 deletions

View File

@ -19,6 +19,7 @@
package com.plotsquared.bukkit.listener; package com.plotsquared.bukkit.listener;
import com.destroystokyo.paper.event.block.BeaconEffectEvent; import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
import com.destroystokyo.paper.event.entity.EntityPathfindEvent; import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent; import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
@ -42,6 +43,7 @@ import com.plotsquared.core.plot.flag.implementations.BeaconEffectsFlag;
import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.FishingFlag; import com.plotsquared.core.plot.flag.implementations.FishingFlag;
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag; import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
import com.plotsquared.core.plot.flag.implementations.TileDropFlag;
import com.plotsquared.core.plot.flag.types.BooleanFlag; import com.plotsquared.core.plot.flag.types.BooleanFlag;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.PlotFlagUtil; import com.plotsquared.core.util.PlotFlagUtil;
@ -84,6 +86,19 @@ public class PaperListener implements Listener {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockDestroy(final BlockDestroyEvent event) {
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getPlot(location);
if (plot != null) {
event.setWillDrop(plot.getFlag(TileDropFlag.class));
}
}
@EventHandler @EventHandler
public void onEntityPathfind(EntityPathfindEvent event) { public void onEntityPathfind(EntityPathfindEvent event) {
if (!Settings.Paper_Components.ENTITY_PATHING) { if (!Settings.Paper_Components.ENTITY_PATHING) {

View File

@ -61,6 +61,7 @@ import com.plotsquared.core.plot.flag.implementations.MiscInteractFlag;
import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag; import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag;
import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag; import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag;
import com.plotsquared.core.plot.flag.implementations.TamedInteractFlag; import com.plotsquared.core.plot.flag.implementations.TamedInteractFlag;
import com.plotsquared.core.plot.flag.implementations.TileDropFlag;
import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag; import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag;
import com.plotsquared.core.plot.flag.implementations.VehicleBreakFlag; import com.plotsquared.core.plot.flag.implementations.VehicleBreakFlag;
import com.plotsquared.core.plot.flag.implementations.VehicleUseFlag; import com.plotsquared.core.plot.flag.implementations.VehicleUseFlag;
@ -107,6 +108,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityPlaceEvent; import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityPotionEffectEvent;
@ -236,6 +238,19 @@ public class PlayerEventListener implements Listener {
this.plotListener = plotListener; this.plotListener = plotListener;
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockBreak(final BlockBreakEvent event) {
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getPlot(location);
if (plot != null) {
event.setDropItems(plot.getFlag(TileDropFlag.class));
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerDyeSign(PlayerInteractEvent event) { public void onPlayerDyeSign(PlayerInteractEvent event) {
ItemStack itemStack = event.getItem(); ItemStack itemStack = event.getItem();

View File

@ -102,6 +102,7 @@ import com.plotsquared.core.plot.flag.implementations.SnowMeltFlag;
import com.plotsquared.core.plot.flag.implementations.SoilDryFlag; import com.plotsquared.core.plot.flag.implementations.SoilDryFlag;
import com.plotsquared.core.plot.flag.implementations.TamedAttackFlag; import com.plotsquared.core.plot.flag.implementations.TamedAttackFlag;
import com.plotsquared.core.plot.flag.implementations.TamedInteractFlag; import com.plotsquared.core.plot.flag.implementations.TamedInteractFlag;
import com.plotsquared.core.plot.flag.implementations.TileDropFlag;
import com.plotsquared.core.plot.flag.implementations.TimeFlag; import com.plotsquared.core.plot.flag.implementations.TimeFlag;
import com.plotsquared.core.plot.flag.implementations.TitlesFlag; import com.plotsquared.core.plot.flag.implementations.TitlesFlag;
import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag; import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag;
@ -198,6 +199,7 @@ public final class GlobalFlagContainer extends FlagContainer {
this.addFlag(SoilDryFlag.SOIL_DRY_FALSE); this.addFlag(SoilDryFlag.SOIL_DRY_FALSE);
this.addFlag(TamedAttackFlag.TAMED_ATTACK_FALSE); this.addFlag(TamedAttackFlag.TAMED_ATTACK_FALSE);
this.addFlag(TamedInteractFlag.TAMED_INTERACT_FALSE); this.addFlag(TamedInteractFlag.TAMED_INTERACT_FALSE);
this.addFlag(TileDropFlag.TILE_DROP_TRUE);
this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE); this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE);
this.addFlag(VehicleBreakFlag.VEHICLE_BREAK_FALSE); this.addFlag(VehicleBreakFlag.VEHICLE_BREAK_FALSE);
this.addFlag(VehiclePlaceFlag.VEHICLE_PLACE_FALSE); this.addFlag(VehiclePlaceFlag.VEHICLE_PLACE_FALSE);

View File

@ -0,0 +1,43 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/
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;
/**
* @since TODO
*/
public class TileDropFlag extends BooleanFlag<TileDropFlag> {
public static final TileDropFlag TILE_DROP_TRUE = new TileDropFlag(true);
public static final TileDropFlag TILE_DROP_FALSE = new TileDropFlag(false);
private TileDropFlag(boolean value) {
super(value, TranslatableCaption.of("flags.flag_description_tile_drop"));
}
@Override
protected TileDropFlag flagOf(@NonNull Boolean value) {
return value ? TILE_DROP_TRUE : TILE_DROP_FALSE;
}
}

View File

@ -606,6 +606,7 @@
"flags.flag_description_tamed_attack": "<gray>Set to `true` to allow guests to attack tamed animals in the plot.</gray>", "flags.flag_description_tamed_attack": "<gray>Set to `true` to allow guests to attack tamed animals in the plot.</gray>",
"flags.flag_description_tamed_interact": "<gray>Set to `true` to allow guests to interact with tamed animals in the plot.</gray>", "flags.flag_description_tamed_interact": "<gray>Set to `true` to allow guests to interact with tamed animals in the plot.</gray>",
"flags.flag_description_time": "<gray>Set the time in the plot to a fixed value.</gray>", "flags.flag_description_time": "<gray>Set the time in the plot to a fixed value.</gray>",
"flags.flag_description_tile_drop": "<gray>Set to `false` to prevent blocks from dropping items in the plot.</gray>",
"flags.flag_description_titles": "<gray>Set to `false` to disable plot titles. Can be set to: `none` (to inherit world settings), `true`, or `false`</gray>", "flags.flag_description_titles": "<gray>Set to `false` to disable plot titles. Can be set to: `none` (to inherit world settings), `true`, or `false`</gray>",
"flags.flag_description_title": "<gray>Set the pop-up title's title and subtitle. Format: /plot flag set title \"A title\" \"The subtitle\"</gray>", "flags.flag_description_title": "<gray>Set the pop-up title's title and subtitle. Format: /plot flag set title \"A title\" \"The subtitle\"</gray>",
"flags.flag_description_use": "<gray>Define a list of materials players should be able to interact with in the plot.</gray>", "flags.flag_description_use": "<gray>Define a list of materials players should be able to interact with in the plot.</gray>",