Makes some 1.20 changes
All checks were successful
EpicKnarvik97/PlaceholderSigns/pipeline/head This commit looks good
KnarCraft/PlaceholderSigns/pipeline/head This commit looks good

Updates spigot version
Updates depreciated sign code
Adds a new permission for editing waxed signs
This commit is contained in:
Kristian Knarvik 2023-06-23 20:22:15 +02:00
parent 837eac46b7
commit 82032dbbbc
5 changed files with 36 additions and 16 deletions

View File

@ -24,7 +24,9 @@ won't be changed unless the player passes all world protection checks.
## Permissions ## Permissions
| Permission | Description | | Permission | Description |
|------------------------------|---------------------------------------------------------------------------------------------------------------| |------------------------------------|---------------------------------------------------------------------------------------------------------------|
| placeholdersigns.* | Gives all permissions. | | placeholdersigns.* | Gives all permissions. |
| placeholdersigns.edit | Allows the use of the /editSign command. | | placeholdersigns.edit | Allows unrestricted use of the /editSign command. |
| placeholdersigns.edit.use | Allows use of the /editSign command. |
| placeholdersigns.edit.bypass-waxed | Allows use of the /editSign command on a waxed sign. |
| placeholdersigns.placeholder | Allows a player to make signs containing placeholders. Without this, placeholders are treated as normal text. | | placeholdersigns.placeholder | Allows a player to make signs containing placeholders. Without this, placeholders are treated as normal text. |

View File

@ -62,7 +62,7 @@
<url>https://oss.sonatype.org/content/groups/public/</url> <url>https://oss.sonatype.org/content/groups/public/</url>
</repository> </repository>
<repository> <repository>
<id>placeholderapi</id> <id>placeholder-api</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url> <url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository> </repository>
</repositories> </repositories>
@ -82,7 +82,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version> <version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -12,6 +12,7 @@ import net.knarcraft.placeholdersigns.util.ColorHelper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -130,10 +131,10 @@ public final class PlaceholderSigns extends JavaPlugin {
// Update placeholders // Update placeholders
Map<Integer, String> placeholders = placeholderSign.placeholders(); Map<Integer, String> placeholders = placeholderSign.placeholders();
String[] lines = sign.getLines(); String[] lines = sign.getSide(Side.FRONT).getLines();
boolean updateRequired = false; boolean updateRequired = false;
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
String oldText = sign.getLine(i); String oldText = sign.getSide(Side.FRONT).getLine(i);
// The new text of the sign is either the same, or the original placeholder // The new text of the sign is either the same, or the original placeholder
String newText; String newText;
@ -148,7 +149,7 @@ public final class PlaceholderSigns extends JavaPlugin {
// Only change the line if the text has changed // Only change the line if the text has changed
if (!newText.equals(oldText)) { if (!newText.equals(oldText)) {
sign.setLine(i, newText); sign.getSide(Side.FRONT).setLine(i, newText);
updateRequired = true; updateRequired = true;
} }
} }

View File

@ -3,8 +3,11 @@ package net.knarcraft.placeholdersigns.listener;
import net.knarcraft.placeholdersigns.PlaceholderSigns; import net.knarcraft.placeholdersigns.PlaceholderSigns;
import net.knarcraft.placeholdersigns.container.LineChangeRequest; import net.knarcraft.placeholdersigns.container.LineChangeRequest;
import net.knarcraft.placeholdersigns.util.ColorHelper; import net.knarcraft.placeholdersigns.util.ColorHelper;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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;
@ -24,18 +27,23 @@ public class SignClickListener implements Listener {
return; return;
} }
Player player = event.getPlayer();
if (sign.isWaxed() && !player.hasPermission("placeholdersigns.edit.bypass-waxed")) {
player.sendMessage(ChatColor.RED + "You do not have the necessary permissions to edit a waxed sign.");
return;
}
// Check if the player has run the /editSign command // Check if the player has run the /editSign command
LineChangeRequest request = PlaceholderSigns.getInstance().getChangeRequest(event.getPlayer()); LineChangeRequest request = PlaceholderSigns.getInstance().getChangeRequest(player);
if (request == null) { if (request == null) {
return; return;
} }
String[] lines = sign.getLines(); String[] lines = sign.getSide(Side.FRONT).getLines();
lines[request.line()] = request.text(); lines[request.line()] = request.text();
// Run the sign change event to allow protection plugins to cancel, and allow the sign text listener to trigger // Run the sign change event to allow protection plugins to cancel, and allow the sign text listener to trigger
SignChangeEvent changeEvent = new SignChangeEvent(event.getClickedBlock(), event.getPlayer(), lines); SignChangeEvent changeEvent = new SignChangeEvent(event.getClickedBlock(), player, lines, Side.FRONT);
Bukkit.getPluginManager().callEvent(changeEvent); Bukkit.getPluginManager().callEvent(changeEvent);
if (changeEvent.isCancelled()) { if (changeEvent.isCancelled()) {
return; return;
@ -44,11 +52,11 @@ public class SignClickListener implements Listener {
// Update the sign with the new text // Update the sign with the new text
String[] finalLines = changeEvent.getLines(); String[] finalLines = changeEvent.getLines();
for (int i = 0; i < finalLines.length; i++) { for (int i = 0; i < finalLines.length; i++) {
sign.setLine(i, ColorHelper.translateAllColorCodes(finalLines[i])); sign.getSide(Side.FRONT).setLine(i, ColorHelper.translateAllColorCodes(finalLines[i]));
} }
sign.update(); sign.update();
event.getPlayer().sendMessage("The sign line was successfully changed."); player.sendMessage("The sign line was successfully changed.");
} }
} }

View File

@ -1,7 +1,7 @@
name: PlaceholderSigns name: PlaceholderSigns
version: '${project.version}' version: '${project.version}'
main: net.knarcraft.placeholdersigns.PlaceholderSigns main: net.knarcraft.placeholdersigns.PlaceholderSigns
api-version: 1.19 api-version: '1.20'
depend: depend:
- PlaceholderAPI - PlaceholderAPI
@ -18,8 +18,17 @@ permissions:
- placeholdersigns.placeholder - placeholdersigns.placeholder
default: op default: op
placeholdersigns.edit: placeholdersigns.edit:
description: Allows a player to use the /editSign command without restriction
default: false
children:
- placeholdersigns.edit.use
- placeholdersigns.edit.bypass-waxed
placeholdersigns.edit.use:
description: Allows a player to use the /editSign command description: Allows a player to use the /editSign command
default: false default: false
placeholdersigns.edit.bypass-waxed:
description: Allows a player to use the /editSign command on a waxed sign
default: false
placeholdersigns.placeholder: placeholdersigns.placeholder:
description: Allows a player to make signs containing placeholders description: Allows a player to make signs containing placeholders
default: false default: false