Introduce edit-sign flag (#4236)

This commit is contained in:
Hannes Greule 2023-11-26 13:36:01 +01:00 committed by GitHub
parent cdb44d4884
commit 31ae62b62c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 1 deletions

View File

@ -37,6 +37,7 @@ import com.plotsquared.bukkit.listener.EntityEventListener;
import com.plotsquared.bukkit.listener.EntitySpawnListener; import com.plotsquared.bukkit.listener.EntitySpawnListener;
import com.plotsquared.bukkit.listener.PaperListener; import com.plotsquared.bukkit.listener.PaperListener;
import com.plotsquared.bukkit.listener.PlayerEventListener; import com.plotsquared.bukkit.listener.PlayerEventListener;
import com.plotsquared.bukkit.listener.PlayerEventListener1201;
import com.plotsquared.bukkit.listener.ProjectileEventListener; import com.plotsquared.bukkit.listener.ProjectileEventListener;
import com.plotsquared.bukkit.listener.ServerListener; import com.plotsquared.bukkit.listener.ServerListener;
import com.plotsquared.bukkit.listener.SingleWorldListener; import com.plotsquared.bukkit.listener.SingleWorldListener;
@ -359,6 +360,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
if (Settings.Enabled_Components.EVENTS) { if (Settings.Enabled_Components.EVENTS) {
getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener.class), this); getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener.class), this);
if ((serverVersion()[1] == 20 && serverVersion()[2] >= 1) || serverVersion()[1] > 20) {
getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener1201.class), this);
}
getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener.class), this); getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener.class), this);
if (serverVersion()[1] >= 17) { if (serverVersion()[1] >= 17) {
getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener117.class), this); getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener117.class), this);

View File

@ -0,0 +1,63 @@
/*
* 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.bukkit.listener;
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.EditSignFlag;
import com.plotsquared.core.util.PlotFlagUtil;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerSignOpenEvent;
/**
* For events since 1.20.1
* @since TODO
*/
public class PlayerEventListener1201 implements Listener {
@EventHandler(ignoreCancelled = true)
@SuppressWarnings({"removal", "UnstableApiUsage"}) // thanks Paper, thanks Spigot
public void onPlayerSignOpenEvent(PlayerSignOpenEvent event) {
Sign sign = event.getSign();
Location location = BukkitUtil.adapt(sign.getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) {
event.setCancelled(true);
}
return;
}
if (plot.isAdded(event.getPlayer().getUniqueId())) {
return; // allow for added players
}
if (!plot.getFlag(EditSignFlag.class)) {
plot.debug(event.getPlayer().getName() + " could not edit the sign because of edit-sign = false");
event.setCancelled(true);
}
}
}

View File

@ -42,6 +42,7 @@ import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag;
import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag; import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag;
import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag; import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag;
import com.plotsquared.core.plot.flag.implementations.EditSignFlag;
import com.plotsquared.core.plot.flag.implementations.EntityCapFlag; import com.plotsquared.core.plot.flag.implementations.EntityCapFlag;
import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag; import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag;
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag; import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
@ -153,6 +154,7 @@ public final class GlobalFlagContainer extends FlagContainer {
this.addFlag(DeviceInteractFlag.DEVICE_INTERACT_FALSE); this.addFlag(DeviceInteractFlag.DEVICE_INTERACT_FALSE);
this.addFlag(DisablePhysicsFlag.DISABLE_PHYSICS_FALSE); this.addFlag(DisablePhysicsFlag.DISABLE_PHYSICS_FALSE);
this.addFlag(DropProtectionFlag.DROP_PROTECTION_FALSE); this.addFlag(DropProtectionFlag.DROP_PROTECTION_FALSE);
this.addFlag(EditSignFlag.EDIT_SIGN_FALSE);
this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE); this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE);
this.addFlag(ExplosionFlag.EXPLOSION_FALSE); this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
this.addFlag(ForcefieldFlag.FORCEFIELD_FALSE); this.addFlag(ForcefieldFlag.FORCEFIELD_FALSE);

View File

@ -0,0 +1,41 @@
/*
* 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 EditSignFlag extends BooleanFlag<EditSignFlag> {
public static final EditSignFlag EDIT_SIGN_TRUE = new EditSignFlag(true);
public static final EditSignFlag EDIT_SIGN_FALSE = new EditSignFlag(false);
private EditSignFlag(final boolean value) {
super(value, TranslatableCaption.of("flags.flag_description_edit_sign"));
}
@Override
protected EditSignFlag flagOf(@NonNull final Boolean value) {
return value ? EDIT_SIGN_TRUE : EDIT_SIGN_FALSE;
}
}

View File

@ -63,6 +63,7 @@ import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.Rating; import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag; import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag;
import com.plotsquared.core.plot.flag.implementations.EditSignFlag;
import com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag; import com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag;
import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag; import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag;
import com.plotsquared.core.plot.flag.implementations.PlaceFlag; import com.plotsquared.core.plot.flag.implementations.PlaceFlag;
@ -74,6 +75,7 @@ import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -392,6 +394,12 @@ public class EventDispatcher {
if (player.hasPermission(Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) { if (player.hasPermission(Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) {
return true; return true;
} }
// we check for the EditSignFlag in the PlayerSignOpenEvent again, but we must not cancel the interact event
// or send a message if the flag is true
if (BlockCategories.ALL_SIGNS != null && BlockCategories.ALL_SIGNS.contains(blockType)
&& plot.getFlag(EditSignFlag.class)) {
return true;
}
if (notifyPerms) { if (notifyPerms) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("commandconfig.flag_tutorial_usage"), TranslatableCaption.of("commandconfig.flag_tutorial_usage"),

View File

@ -555,6 +555,7 @@
"flags.flag_description_device_interact": "<gray>Set to `true` to allow devices to be interacted with in the plot.</gray>", "flags.flag_description_device_interact": "<gray>Set to `true` to allow devices to be interacted with in the plot.</gray>",
"flags.flag_description_disable_physics": "<gray>Set to `true` to disable block physics in the plot.</gray>", "flags.flag_description_disable_physics": "<gray>Set to `true` to disable block physics in the plot.</gray>",
"flags.flag_description_drop_protection": "<gray>Set to `true` to prevent dropped items from being picked up by non-members of the plot.</gray>", "flags.flag_description_drop_protection": "<gray>Set to `true` to prevent dropped items from being picked up by non-members of the plot.</gray>",
"flags.flag_description_edit_sign": "<gray>Set to `true` to allow editing signs in the plot.</gray>",
"flags.flag_description_feed": "<gray>Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).</gray>", "flags.flag_description_feed": "<gray>Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).</gray>",
"flags.flag_description_forcefield": "<gray>Set to `true` to enable member forcefield in the plot.</gray>", "flags.flag_description_forcefield": "<gray>Set to `true` to enable member forcefield in the plot.</gray>",
"flags.flag_description_grass_grow": "<gray>Set to `false` to prevent grass from growing within the plot.</gray>", "flags.flag_description_grass_grow": "<gray>Set to `false` to prevent grass from growing within the plot.</gray>",

View File

@ -1,8 +1,8 @@
import com.diffplug.gradle.spotless.SpotlessPlugin import com.diffplug.gradle.spotless.SpotlessPlugin
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import groovy.json.JsonSlurper import groovy.json.JsonSlurper
import java.net.URI
import xyz.jpenilla.runpaper.task.RunServer import xyz.jpenilla.runpaper.task.RunServer
import java.net.URI
plugins { plugins {
java java