1 Commits
Author SHA1 Message Date
MylesMor a330c82bde Add PAPI Support + GUI Improvements
- Add PlaceholderAPI support.
- Improve GUI and messaging (make Item Meta consistent and improve readability of chat messages).
- Fix issue with Player Commands not replacing %PLAYER% placeholder.
- Fix other minor bugs.
2021-03-04 01:42:58 +00:00
10 changed files with 116 additions and 42 deletions

No files matched your search

+11 -4
View File
@@ -12,7 +12,7 @@
<groupId>dev.mylesmor.sudosigns</groupId>
<artifactId>SudoSigns</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<version>1.1.1</version>
<repositories>
<repository>
@@ -23,6 +23,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
@@ -38,9 +42,12 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -39,11 +39,13 @@ public class SudoSigns extends JavaPlugin {
public static String version;
public static Economy econ = null;
public static boolean papi = false;
@Override
public void onEnable() {
setupEconomy();
setupPapi();
new UpdateChecker(this, 80758).getVersion(version -> {
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
Bukkit.getLogger().info("[SUDOSIGNS] SudoSigns is up-to-date.");
@@ -64,6 +66,10 @@ public class SudoSigns extends JavaPlugin {
this.getCommand("sudosigns").setTabCompleter(new SudoSignsTabCompleter());
}
/**
* Setup Vault economy if compatible plugins found.
* @return Vault Economy object or null.
*/
public boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
Bukkit.getLogger().warning("[SUDOSIGNS] Vault not found, sign prices disabled...");
@@ -78,9 +84,17 @@ public class SudoSigns extends JavaPlugin {
return true;
}
/**
* Allow PlaceholderAPI to be used if plugin found.
*/
public void setupPapi() {
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
Bukkit.getLogger().warning("[SUDOSIGNS] PlaceholderAPI found! Integration enabled.");
papi = true;
}
}
@Override
public void onDisable() {
}
public void onDisable() { }
}
@@ -2,6 +2,7 @@ package dev.mylesmor.sudosigns.data;
import dev.mylesmor.sudosigns.SudoSigns;
import dev.mylesmor.sudosigns.util.Util;
import me.clip.placeholderapi.PlaceholderAPI;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -178,28 +179,45 @@ public class SudoSign {
Util.sudoSignsMessage(p, ChatColor.GREEN, ChatColor.GOLD + SudoSigns.econ.currencyNamePlural() + price + ChatColor.GREEN + " has been withdrawn from your balance.", null);
}
}
// Queue Sign messages
for (SignMessage sm : messages) {
String messageString = sm.getMessage().replaceAll("(?i)%PLAYER%", p.getName());
if (SudoSigns.papi) {
messageString = PlaceholderAPI.setPlaceholders(p, messageString);
}
String finalMessageString = messageString;
new BukkitRunnable() {
@Override
public void run() {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', sm.getMessage()).replaceAll("(?i)%PLAYER%", p.getName()));
p.sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageString));
}
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sm.getDelay()/50));
}
// Queue Sign player commands
for (SignCommand sc : playerCommands) {
new BukkitRunnable() {
String commandString = sc.getCommand().replaceAll("(?i)%PLAYER%", p.getName());
if (SudoSigns.papi) {
commandString = PlaceholderAPI.setPlaceholders(p, commandString);
}
String finalCommandString = commandString;
new BukkitRunnable() {
@Override
public void run() {
p.performCommand(sc.getCommand());
p.performCommand(finalCommandString);
}
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay()/50));
}
// Queue Sign console commands
for (SignCommand sc : consoleCommands) {
String cmd = sc.getCommand().replaceAll("(?i)%PLAYER%", p.getName());
String commandString = sc.getCommand().replaceAll("(?i)%PLAYER%", p.getName());
if (SudoSigns.papi) {
commandString = PlaceholderAPI.setPlaceholders(p, commandString);
}
String finalCommandString = commandString;
new BukkitRunnable() {
@Override
public void run() {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommandString);
}
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay()/50));
}
@@ -8,6 +8,7 @@ import dev.mylesmor.sudosigns.util.Permissions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -15,6 +16,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.Objects;
@@ -46,7 +49,7 @@ public class InventoryListener implements Listener {
checkForCommandsClicks(p, editor, m, e.getCurrentItem());
break;
case PERMISSIONS:
checkForPermissionsClicks(p, editor, m, itemName);
checkForPermissionsClicks(p, editor, m, e.getCurrentItem());
break;
case CHOOSE_COMMAND:
chooseCommandType(editor, m, itemName);
@@ -246,13 +249,17 @@ public class InventoryListener implements Listener {
* Checks for GUI clicks in the Permissions menu.
* @param editor The SignEditor class of the particular user.
* @param m The material clicked on in the menu.
* @param itemName The name of the item clicked.
* @param item The ItemStack of the item clicked.
*/
public void checkForPermissionsClicks(Player p, SignEditor editor, Material m, String itemName) {
public void checkForPermissionsClicks(Player p, SignEditor editor, Material m, ItemStack item) {
switch (m) {
case BOOK:
if (p.hasPermission(Permissions.DELETE_PERMISSION)) {
editor.getPermMenu().deletePermission(ChatColor.stripColor(itemName));
ItemMeta itemMeta = item.getItemMeta();
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "permission");
if (itemMeta != null) {
editor.getPermMenu().deletePermission(itemMeta.getPersistentDataContainer().get(key, PersistentDataType.STRING));
}
}
break;
case WRITABLE_BOOK:
@@ -81,9 +81,12 @@ public class CommandsMenu {
if (i > 26) break;
ItemStack book = new ItemStack(Material.BOOK);
ItemMeta bookMeta = book.getItemMeta();
lore.add(ChatColor.YELLOW + "Player Command");
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
lore.add(ChatColor.GRAY + "Delay: " + ChatColor.RED + (sc.getDelay() / 1000) + "s");
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Player Command");
lore.add("");
lore.add("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
lore.add("");
lore.add("");
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sc.getDelay() / 1000) + "s");
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
lore.add("");
lore.add(ChatColor.GREEN + "Click for options!");
@@ -105,9 +108,12 @@ public class CommandsMenu {
if (i > 35) break;
ItemStack book = new ItemStack(Material.BOOK);
ItemMeta bookMeta = book.getItemMeta();
lore.add(ChatColor.YELLOW + "Console Command");
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
lore.add(ChatColor.GRAY + "Delay: " + ChatColor.RED + (sc.getDelay() / 1000) + "s");
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Console Command");
lore.add("");
lore.add("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
lore.add("");
lore.add("");
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sc.getDelay() / 1000) + "s");
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
lore.add("");
lore.add(ChatColor.GREEN + "Click for options!");
@@ -167,8 +173,13 @@ public class CommandsMenu {
public void chooseCommandType(PlayerInput type) {
p.closeInventory();
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the full command in chat with the beginning /. The phrase" + ChatColor.GOLD + " %PLAYER%" + ChatColor.GRAY +
" will be replaced with the player who clicked the sign. To cancel, type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
p.sendMessage(Util.prefix);
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "Please enter the full command in chat beginning with " + ChatColor.GOLD + "/" + ChatColor.GRAY + ".");
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + ChatColor.GOLD + "%PLAYER%" + ChatColor.GRAY + " will be replaced with the player's name.");
if (SudoSigns.papi) {
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "You can also use " + ChatColor.GOLD + "PlaceHolderAPI" + ChatColor.GRAY + " placeholders.");
}
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "To cancel type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
su.addTextInput(type);
}
@@ -47,7 +47,7 @@ public class MainMenu {
if (p.hasPermission(Permissions.RENAME)) {
ItemStack nametag = new ItemStack(Material.NAME_TAG);
ItemMeta ntMeta = nametag.getItemMeta();
ntMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Rename Sign");
ntMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Rename Sign");
nametag.setItemMeta(ntMeta);
items.add(nametag);
}
@@ -55,7 +55,7 @@ public class MainMenu {
if (p.hasPermission(Permissions.EDIT_TEXT)) {
ItemStack book = new ItemStack(Material.WRITABLE_BOOK);
ItemMeta bookMeta = book.getItemMeta();
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Edit Sign Text");
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Edit Sign Text");
book.setItemMeta(bookMeta);
items.add(book);
}
@@ -63,7 +63,7 @@ public class MainMenu {
if (p.hasPermission(Permissions.VIEW_PERMISSION)) {
ItemStack barrier = new ItemStack(Material.BARRIER);
ItemMeta barrierMeta = barrier.getItemMeta();
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Permissions");
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Permissions");
List<String> lore = new ArrayList<>();
lore.add(ChatColor.YELLOW + "Players must have all permissions");
lore.add(ChatColor.YELLOW + "listed in this section to be able");
@@ -80,7 +80,7 @@ public class MainMenu {
lore.add(ChatColor.YELLOW + "Commands listed here will be executed");
lore.add(ChatColor.YELLOW + "when a player uses the sign.");
cmdBlockMeta.setLore(lore);
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Commands");
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Commands");
cmdBlock.setItemMeta(cmdBlockMeta);
items.add(cmdBlock);
}
@@ -93,7 +93,7 @@ public class MainMenu {
signBlock = new ItemStack(Material.BIRCH_SIGN);
}
ItemMeta signMeta = signBlock.getItemMeta();
signMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Messages");
signMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Messages");
List<String> lore = new ArrayList<>();
lore.add(ChatColor.YELLOW + "Messages listed here will be shown");
lore.add(ChatColor.YELLOW + "to the player when they use the sign.");
@@ -108,19 +108,20 @@ public class MainMenu {
ItemStack goldNugget = new ItemStack(Material.GOLD_NUGGET);
ItemMeta goldNuggetItemMeta = goldNugget.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add(ChatColor.YELLOW + "The cost to use this sign.");
lore.add(ChatColor.YELLOW + "Set the price to use this sign.");
lore.add(ChatColor.YELLOW + "");
if (sign.getPrice() == 1.0) {
lore.add(ChatColor.GRAY + SudoSigns.econ.currencyNameSingular() + ChatColor.RED + sign.getPrice());
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Price: " + ChatColor.GRAY + SudoSigns.econ.currencyNameSingular() + ChatColor.RED + sign.getPrice());
} else {
lore.add(ChatColor.GRAY + SudoSigns.econ.currencyNamePlural() + ChatColor.RED + sign.getPrice());
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Price: " + ChatColor.GRAY + SudoSigns.econ.currencyNamePlural() + ChatColor.RED + sign.getPrice());
}
if (p.hasPermission(Permissions.SET_PRICE)) {
lore.add(ChatColor.YELLOW + "");
lore.add("");
lore.add(ChatColor.GREEN + "Click to edit!");
}
goldNuggetItemMeta.setLore(lore);
goldNuggetItemMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Price");
goldNuggetItemMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Price");
goldNugget.setItemMeta(goldNuggetItemMeta);
items.add(goldNugget);
}
@@ -81,11 +81,12 @@ public class MessagesMenu {
ItemStack book = new ItemStack(Material.BOOK);
ItemMeta bookMeta = book.getItemMeta();
lore.clear();
bookMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Message:");
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Message");
lore.add("");
lore.add("" + ChatColor.RESET + ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', sm.getMessage()));
lore.add("");
lore.add("");
lore.add(ChatColor.GRAY + "Delay: " + ChatColor.RED + (sm.getDelay() / 1000) + "s");
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sm.getDelay() / 1000) + "s");
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
lore.add("");
lore.add(ChatColor.GREEN + "Click for options!");
@@ -113,7 +114,14 @@ public class MessagesMenu {
public void prepareMessage() {
p.closeInventory();
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter in chat the message which will be shown. Use the " + ChatColor.GOLD + "& " + ChatColor.GRAY + "symbol for chat colour codes and the phrase" + ChatColor.GOLD + " %PLAYER% " + ChatColor.GRAY + "for the player who clicked the sign. To cancel type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
p.sendMessage(Util.prefix);
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "Please enter the message in chat.");
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "Use the " + ChatColor.GOLD + "& " + ChatColor.GRAY + "symbol for chat colour codes.");
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + ChatColor.GOLD + "%PLAYER%" + ChatColor.GRAY + " will be replaced with the player's name.");
if (SudoSigns.papi) {
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "You can also use " + ChatColor.GOLD + "PlaceHolderAPI" + ChatColor.GRAY + " placeholders.");
}
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "To cancel type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
su.addTextInput(PlayerInput.MESSAGE);
}
@@ -9,10 +9,12 @@ import dev.mylesmor.sudosigns.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
@@ -65,20 +67,24 @@ public class PermissionsMenu {
menu.setItem(40, bookQuill);
}
List<String> lore = new ArrayList<>();
lore.add(ChatColor.RED + "Click to delete!");
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "permission");
int i = 1;
for (String perm : sign.getPermissions()) {
if (i > 35) break;
ItemStack book = new ItemStack(Material.BOOK);
ItemMeta bookMeta = book.getItemMeta();
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GOLD + perm);
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Permission");
lore.add("");
lore.add("" + ChatColor.RESET + ChatColor.GOLD + perm);
if (p.hasPermission(Permissions.DELETE_PERMISSION)) {
lore.add("");
bookMeta.setLore(lore);
lore.add("");
lore.add("" + ChatColor.RED + ChatColor.BOLD + "Click to delete!");
}
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.STRING, perm);
bookMeta.setLore(lore);
book.setItemMeta(bookMeta);
if (i == 9 || i == 18 || i == 27) i++;
menu.setItem(i, book);
@@ -31,6 +31,7 @@ public class SignEditor {
private MessageOptionsMenu messageOptionsMenu;
private MessagesMenu messagesMenu;
private GUIPage currentPage;
private boolean edited = false;
public SignEditor(Player p, SudoSign s, SudoUser su) {
this.su = su;
@@ -111,6 +112,7 @@ public class SignEditor {
public void endEditor() {
//TODO: Find out whether they actually edited the sign
Util.sudoSignsMessage(p, ChatColor.GRAY, "Changes saved to sign %NAME%.", sign.getName());
}
+2 -2
View File
@@ -1,8 +1,8 @@
name: SudoSigns
version: 1.1.0
version: 1.1.1
author: MylesMor
main: dev.mylesmor.sudosigns.SudoSigns
softdepend: [Multiverse-Core, Vault]
softdepend: [Multiverse-Core, Vault, PlaceholderAPI]
api-version: 1.13
commands:
sudosigns: