Skip to content

Commit 31ae62b

Browse files
authored
Introduce edit-sign flag (#4236)
1 parent cdb44d4 commit 31ae62b

File tree

7 files changed

+120
-1
lines changed

7 files changed

+120
-1
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.plotsquared.bukkit.listener.EntitySpawnListener;
3838
import com.plotsquared.bukkit.listener.PaperListener;
3939
import com.plotsquared.bukkit.listener.PlayerEventListener;
40+
import com.plotsquared.bukkit.listener.PlayerEventListener1201;
4041
import com.plotsquared.bukkit.listener.ProjectileEventListener;
4142
import com.plotsquared.bukkit.listener.ServerListener;
4243
import com.plotsquared.bukkit.listener.SingleWorldListener;
@@ -359,6 +360,9 @@ public void onEnable() {
359360

360361
if (Settings.Enabled_Components.EVENTS) {
361362
getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener.class), this);
363+
if ((serverVersion()[1] == 20 && serverVersion()[2] >= 1) || serverVersion()[1] > 20) {
364+
getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener1201.class), this);
365+
}
362366
getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener.class), this);
363367
if (serverVersion()[1] >= 17) {
364368
getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener117.class), this);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package com.plotsquared.bukkit.listener;
20+
21+
import com.plotsquared.bukkit.util.BukkitUtil;
22+
import com.plotsquared.core.location.Location;
23+
import com.plotsquared.core.plot.Plot;
24+
import com.plotsquared.core.plot.PlotArea;
25+
import com.plotsquared.core.plot.flag.implementations.EditSignFlag;
26+
import com.plotsquared.core.util.PlotFlagUtil;
27+
import org.bukkit.block.Sign;
28+
import org.bukkit.event.EventHandler;
29+
import org.bukkit.event.Listener;
30+
import org.bukkit.event.player.PlayerSignOpenEvent;
31+
32+
/**
33+
* For events since 1.20.1
34+
* @since TODO
35+
*/
36+
public class PlayerEventListener1201 implements Listener {
37+
38+
@EventHandler(ignoreCancelled = true)
39+
@SuppressWarnings({"removal", "UnstableApiUsage"}) // thanks Paper, thanks Spigot
40+
public void onPlayerSignOpenEvent(PlayerSignOpenEvent event) {
41+
Sign sign = event.getSign();
42+
Location location = BukkitUtil.adapt(sign.getLocation());
43+
PlotArea area = location.getPlotArea();
44+
if (area == null) {
45+
return;
46+
}
47+
Plot plot = location.getOwnedPlot();
48+
if (plot == null) {
49+
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) {
50+
event.setCancelled(true);
51+
}
52+
return;
53+
}
54+
if (plot.isAdded(event.getPlayer().getUniqueId())) {
55+
return; // allow for added players
56+
}
57+
if (!plot.getFlag(EditSignFlag.class)) {
58+
plot.debug(event.getPlayer().getName() + " could not edit the sign because of edit-sign = false");
59+
event.setCancelled(true);
60+
}
61+
}
62+
63+
}

Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag;
4343
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
4444
import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag;
45+
import com.plotsquared.core.plot.flag.implementations.EditSignFlag;
4546
import com.plotsquared.core.plot.flag.implementations.EntityCapFlag;
4647
import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag;
4748
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
@@ -153,6 +154,7 @@ private GlobalFlagContainer() {
153154
this.addFlag(DeviceInteractFlag.DEVICE_INTERACT_FALSE);
154155
this.addFlag(DisablePhysicsFlag.DISABLE_PHYSICS_FALSE);
155156
this.addFlag(DropProtectionFlag.DROP_PROTECTION_FALSE);
157+
this.addFlag(EditSignFlag.EDIT_SIGN_FALSE);
156158
this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE);
157159
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
158160
this.addFlag(ForcefieldFlag.FORCEFIELD_FALSE);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package com.plotsquared.core.plot.flag.implementations;
20+
21+
import com.plotsquared.core.configuration.caption.TranslatableCaption;
22+
import com.plotsquared.core.plot.flag.types.BooleanFlag;
23+
import org.checkerframework.checker.nullness.qual.NonNull;
24+
25+
/**
26+
* @since TODO
27+
*/
28+
public class EditSignFlag extends BooleanFlag<EditSignFlag> {
29+
public static final EditSignFlag EDIT_SIGN_TRUE = new EditSignFlag(true);
30+
public static final EditSignFlag EDIT_SIGN_FALSE = new EditSignFlag(false);
31+
32+
private EditSignFlag(final boolean value) {
33+
super(value, TranslatableCaption.of("flags.flag_description_edit_sign"));
34+
}
35+
36+
@Override
37+
protected EditSignFlag flagOf(@NonNull final Boolean value) {
38+
return value ? EDIT_SIGN_TRUE : EDIT_SIGN_FALSE;
39+
}
40+
41+
}

Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.plotsquared.core.plot.Rating;
6464
import com.plotsquared.core.plot.flag.PlotFlag;
6565
import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag;
66+
import com.plotsquared.core.plot.flag.implementations.EditSignFlag;
6667
import com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag;
6768
import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag;
6869
import com.plotsquared.core.plot.flag.implementations.PlaceFlag;
@@ -74,6 +75,7 @@
7475
import com.sk89q.worldedit.WorldEdit;
7576
import com.sk89q.worldedit.entity.Entity;
7677
import com.sk89q.worldedit.function.pattern.Pattern;
78+
import com.sk89q.worldedit.world.block.BlockCategories;
7779
import com.sk89q.worldedit.world.block.BlockType;
7880
import com.sk89q.worldedit.world.block.BlockTypes;
7981
import net.kyori.adventure.text.Component;
@@ -392,6 +394,12 @@ public boolean checkPlayerBlockEvent(
392394
if (player.hasPermission(Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) {
393395
return true;
394396
}
397+
// we check for the EditSignFlag in the PlayerSignOpenEvent again, but we must not cancel the interact event
398+
// or send a message if the flag is true
399+
if (BlockCategories.ALL_SIGNS != null && BlockCategories.ALL_SIGNS.contains(blockType)
400+
&& plot.getFlag(EditSignFlag.class)) {
401+
return true;
402+
}
395403
if (notifyPerms) {
396404
player.sendMessage(
397405
TranslatableCaption.of("commandconfig.flag_tutorial_usage"),

Core/src/main/resources/lang/messages_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@
555555
"flags.flag_description_device_interact": "<gray>Set to `true` to allow devices to be interacted with in the plot.</gray>",
556556
"flags.flag_description_disable_physics": "<gray>Set to `true` to disable block physics in the plot.</gray>",
557557
"flags.flag_description_drop_protection": "<gray>Set to `true` to prevent dropped items from being picked up by non-members of the plot.</gray>",
558+
"flags.flag_description_edit_sign": "<gray>Set to `true` to allow editing signs in the plot.</gray>",
558559
"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>",
559560
"flags.flag_description_forcefield": "<gray>Set to `true` to enable member forcefield in the plot.</gray>",
560561
"flags.flag_description_grass_grow": "<gray>Set to `false` to prevent grass from growing within the plot.</gray>",

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import com.diffplug.gradle.spotless.SpotlessPlugin
22
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
33
import groovy.json.JsonSlurper
4-
import java.net.URI
54
import xyz.jpenilla.runpaper.task.RunServer
5+
import java.net.URI
66

77
plugins {
88
java

0 commit comments

Comments
 (0)