Compare commits
13
Commits
v1.0
...
development
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a330c82bde | ||
|
|
748a9b8279 | ||
|
|
c85416ff08 | ||
|
|
55ce1ac0e0 | ||
|
|
b3e2700cd4 | ||
|
|
ea0da4ff07 | ||
|
|
a9a07f3406 | ||
|
|
38ef4279e6 | ||
|
|
2c152c78d9 | ||
|
|
1c320feddc | ||
|
|
aadbaa848d | ||
|
|
0ad76d3abe | ||
|
|
35934ea25e |
No files matched your search
@@ -3,16 +3,18 @@
|
||||
# SudoSigns
|
||||
A Spigot plugin used to run commands by interacting with a sign. Some inspiration for commands has been taken from [Nokorbis' Command Signs](https://www.spigotmc.org/resources/command-signs.10512/), but all the code is my own, and I have also implemented a convenient inventory-based GUI.
|
||||
This allows you to perform actions on SudoSigns such as:
|
||||
* Renaming the SudoSign
|
||||
* Editing the sign's text
|
||||
* Adding permissions that a player must have to run the sign's commands
|
||||
* Adding either player or console commands to a sign
|
||||
* Adding messages which are shown to the player
|
||||
* Use colour codes (`&`) on the sign for coloured text
|
||||
* Adding delays to commands/messages
|
||||
* (Vault Economy) Setting the price of running a sign
|
||||
|
||||
For in-depth details on the command, permissions and features of this plugin, visit the [Wiki](https://github.com/MylesMor/SudoSigns/wiki)!
|
||||
|
||||
## Installation
|
||||
1. Download the Spigot plugin [HERE](https://spigot.com/LINK).
|
||||
1. Download the Spigot plugin [HERE](https://www.spigotmc.org/resources/sudosigns-commands-messages-on-signs.80758/).
|
||||
2. Place the JAR file inside your `./plugins` directory.
|
||||
3. Reload or restart the server.
|
||||
|
||||
@@ -29,4 +31,4 @@ In your issue report, please include as much information as possible including:
|
||||
|
||||
## Upcoming Features
|
||||
These features will be available in future updates!
|
||||
* Edit the sign's text from the GUI menu.
|
||||
* None currently planned, send me suggestions!
|
||||
@@ -12,23 +12,42 @@
|
||||
<groupId>dev.mylesmor.sudosigns</groupId>
|
||||
<artifactId>SudoSigns</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<version>1.1.1</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<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>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<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>
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.mylesmor.sudosigns;
|
||||
|
||||
import dev.mylesmor.sudosigns.commands.Commands;
|
||||
import dev.mylesmor.sudosigns.commands.SudoSignsTabCompleter;
|
||||
import dev.mylesmor.sudosigns.config.ConfigManager;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
@@ -8,9 +9,12 @@ import dev.mylesmor.sudosigns.listeners.ChatListener;
|
||||
import dev.mylesmor.sudosigns.listeners.InventoryListener;
|
||||
import dev.mylesmor.sudosigns.listeners.PlayerListener;
|
||||
import dev.mylesmor.sudosigns.listeners.SignListener;
|
||||
import dev.mylesmor.sudosigns.util.UpdateChecker;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
@@ -24,6 +28,8 @@ import java.util.function.BiConsumer;
|
||||
public class SudoSigns extends JavaPlugin {
|
||||
|
||||
public static Map<String, SudoSign> signs = new HashMap<>();
|
||||
public static ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
|
||||
public static Map<UUID, SudoUser> users = new HashMap<>();
|
||||
|
||||
public static ConfigManager config;
|
||||
@@ -32,9 +38,21 @@ 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.");
|
||||
} else {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] There is a new update available (" + version + ")! Please update for all the latest features, bug fixes and improvements! https://www.spigotmc.org/resources/sudosigns-commands-messages-on-signs.80758/");
|
||||
}
|
||||
});
|
||||
String version = getServer().getVersion().split("MC: ")[1];
|
||||
SudoSigns.version = version.substring(0, version.length()-1);
|
||||
getServer().getPluginManager().registerEvents(new SignListener(), this);
|
||||
@@ -43,13 +61,40 @@ public class SudoSigns extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
sudoSignsPlugin = this;
|
||||
config = new ConfigManager();
|
||||
config.loadModules();
|
||||
this.getCommand("sudosigns").setExecutor(new Commands());
|
||||
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...");
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] No compatible economy plugin found, sign prices disabled...");
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
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() { }
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class Commands implements CommandExecutor {
|
||||
} else {
|
||||
command.accept(p, null);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid command!" + ChatColor.GRAY + " Type " + ChatColor.LIGHT_PURPLE + "/ss help " + ChatColor.GRAY + "for a list of commands.", null);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Help {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss reload" + ChatColor.GRAY + " - Reloads the configuration file (signs.yml).");
|
||||
}
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss purge [name]" + ChatColor.GRAY + " - Removes a specified invalid entry from the config (leave name black to purge all invalid entries).");
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss purge [name]" + ChatColor.GRAY + " - Removes a specified invalid entry from the config (leave name blank to purge all invalid entries).");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
|
||||
@@ -20,9 +20,10 @@ public class List {
|
||||
public static void list(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
if (SudoSigns.signs.size() == 0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "No SudoSigns were found!", null);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "No SudoSigns were found!", null);
|
||||
return;
|
||||
}
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Listing all SudoSigns...", null);
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
String message = Util.getSelectString(p, entry.getKey());
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
|
||||
@@ -44,12 +44,15 @@ public class Near {
|
||||
boolean found = false;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
Location signLoc = entry.getValue().getSign().getLocation();
|
||||
if (signLoc.distance(p.getLocation()) <= r) {
|
||||
if (!found) Util.sudoSignsMessage(p, ChatColor.GRAY, "Displaying SudoSigns within a radius of %NAME% block(s):", Integer.toString(r));
|
||||
found = true;
|
||||
String message = Util.getSelectString(p, entry.getKey());
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
}
|
||||
try {
|
||||
if (signLoc.distance(p.getLocation()) <= r) {
|
||||
if (!found)
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Displaying SudoSigns within a radius of %NAME% block(s):", Integer.toString(r));
|
||||
found = true;
|
||||
String message = Util.getSelectString(p, entry.getKey());
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (!found) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "No SudoSigns found within a radius of %NAME% block(s).", Integer.toString(r));
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Reload {
|
||||
public static void reload(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Reloading config...", null);
|
||||
|
||||
SudoSigns.signs.clear();
|
||||
if (SudoSigns.config.loadCustomConfig()) {
|
||||
ArrayList<String> invalidSigns = SudoSigns.config.loadSigns();
|
||||
if (invalidSigns != null) {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Run {
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
SudoSign sign = SudoSigns.signs.get(name);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Executing " + ChatColor.LIGHT_PURPLE + sign.getMessages().size() + ChatColor.GRAY + " messages and " + ChatColor.LIGHT_PURPLE + (sign.getPlayerCommands().size() + sign.getConsoleCommands().size()) + ChatColor.GRAY + " commands...", null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Executing " + ChatColor.LIGHT_PURPLE + sign.getMessages().size() + ChatColor.GRAY + " message(s) and " + ChatColor.LIGHT_PURPLE + (sign.getPlayerCommands().size() + sign.getConsoleCommands().size()) + ChatColor.GRAY + " command(s)...", null);
|
||||
SudoSigns.signs.get(name).executeCommands(p);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", name);
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class SudoSignsTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
Player p = (Player) commandSender;
|
||||
if (args.length == 1) {
|
||||
ArrayList<String> commands = new ArrayList<>();
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
commands.add("help");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
commands.add("reload");
|
||||
}
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
commands.add("create");
|
||||
}
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
commands.add("list");
|
||||
}
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
commands.add("near");
|
||||
}
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
commands.add("delete");
|
||||
}
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
commands.add("view");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
commands.add("run");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
commands.add("reload");
|
||||
}
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
commands.add("tp");
|
||||
}
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
commands.add("copy");
|
||||
}
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
commands.add("select");
|
||||
}
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
commands.add("purge");
|
||||
}
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
commands.add("fix");
|
||||
}
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
commands.add("edit");
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
switch (args[0]) {
|
||||
case "create":
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
suggestions.add("<sign-name>");
|
||||
}
|
||||
return suggestions;
|
||||
case "delete":
|
||||
case "view":
|
||||
case "run":
|
||||
case "tp":
|
||||
case "copy":
|
||||
case "select":
|
||||
case "edit":
|
||||
if (p.hasPermission(Permissions.SELECT) || p.hasPermission(Permissions.VIEW)
|
||||
|| p.hasPermission(Permissions.RUN) || p.hasPermission(Permissions.TP)
|
||||
|| p.hasPermission(Permissions.COPY) || p.hasPermission(Permissions.SELECT)
|
||||
|| p.hasPermission(Permissions.EDIT)) {
|
||||
for (SudoSign s : SudoSigns.signs.values()) {
|
||||
suggestions.add(s.getName());
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
case "fix":
|
||||
case "purge":
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
suggestions.addAll(SudoSigns.invalidSigns);
|
||||
}
|
||||
return suggestions;
|
||||
case "near":
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
suggestions.add("2");
|
||||
suggestions.add("5");
|
||||
suggestions.add("10");
|
||||
suggestions.add("25");
|
||||
suggestions.add("50");
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
}
|
||||
if (args.length == 3) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
switch (args[0]) {
|
||||
case "copy":
|
||||
suggestions.add("<new-sign-name>");
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,12 @@ public class View {
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY,"Location: " + ChatColor.LIGHT_PURPLE + locString, null);
|
||||
}
|
||||
if (sign.getPrice() == 1.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Price: " + ChatColor.LIGHT_PURPLE + SudoSigns.econ.currencyNameSingular() + sign.getPrice(), null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Price: " + ChatColor.LIGHT_PURPLE + SudoSigns.econ.currencyNamePlural() + sign.getPrice(), null);
|
||||
}
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Price: " + ChatColor.LIGHT_PURPLE + sign.getMessages().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Messages: " + ChatColor.LIGHT_PURPLE + sign.getMessages().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Permissions: " + ChatColor.LIGHT_PURPLE + sign.getPermissions().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY,"Player Commands: " + ChatColor.LIGHT_PURPLE + sign.getPlayerCommands().size(), null);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
CommandConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void addCommandToConfig(SudoSign s, SignCommand cmd, PlayerInput type) {
|
||||
if (signConfig.isConfigurationSection("signs." + s.getName())) {
|
||||
HashMap<String, Double> map;
|
||||
switch (type) {
|
||||
case PLAYER_COMMAND:
|
||||
List<Map<?, ?>> pCmds = signConfig.getMapList("signs." + s.getName() + ".player-commands");
|
||||
map = new HashMap<>();
|
||||
map.put(cmd.getCommand(), cmd.getDelay());
|
||||
pCmds.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", pCmds);
|
||||
break;
|
||||
case CONSOLE_COMMAND:
|
||||
List<Map<?, ?>> cCmds = signConfig.getMapList("signs." + s.getName() + ".console-commands");
|
||||
map = new HashMap<>();
|
||||
map.put(cmd.getCommand(), cmd.getDelay());
|
||||
cCmds.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", cCmds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a command from a sign in the config.
|
||||
* @param s The SudoSign object to edit.
|
||||
* @param s The .
|
||||
* @param s The SudoSign object to edit.
|
||||
*/
|
||||
public void deleteCommandFromConfig(SudoSign s, SignCommand cmd, PlayerInput type, double oldDelay) {
|
||||
if (type.equals(PlayerInput.PLAYER_COMMAND)) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".player-commands");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> cmds : map.entrySet()) {
|
||||
if (cmds.getKey().equals(cmd.getCommand()) && (Double) cmds.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", mapList);
|
||||
} else if (type.equals(PlayerInput.CONSOLE_COMMAND)) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".console-commands");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> cmds : map.entrySet()) {
|
||||
if (cmds.getKey().equals(cmd.getCommand()) && (Double) cmds.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", mapList);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,9 @@ package dev.mylesmor.sudosigns.config;
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -30,19 +25,75 @@ public class ConfigManager {
|
||||
private FileConfiguration signConfig;
|
||||
private File signConfigFile;
|
||||
private InvalidEntriesManager invalidEntriesManager;
|
||||
private SignConfig signConfigManager;
|
||||
private MessageConfig messageConfig;
|
||||
private CommandConfig commandConfig;
|
||||
private PermissionConfig permissionConfig;
|
||||
|
||||
|
||||
public ConfigManager() {
|
||||
createCustomConfig();
|
||||
loadCustomConfig();
|
||||
loadModules();
|
||||
}
|
||||
|
||||
public void loadModules() {
|
||||
invalidEntriesManager = new InvalidEntriesManager(this, signConfig);
|
||||
loadSigns();
|
||||
signConfigManager = new SignConfig(this);
|
||||
signConfigManager.loadSigns();
|
||||
messageConfig = new MessageConfig(this);
|
||||
commandConfig = new CommandConfig(this);
|
||||
permissionConfig = new PermissionConfig(this);
|
||||
}
|
||||
|
||||
public InvalidEntriesManager getInvalidEntriesManager() {
|
||||
return invalidEntriesManager;
|
||||
}
|
||||
|
||||
public FileConfiguration getSignConfig() { return signConfig; }
|
||||
|
||||
public ArrayList<String> loadSigns() {
|
||||
return signConfigManager.loadSigns();
|
||||
}
|
||||
|
||||
public void saveSign(SudoSign s, boolean singular, Player p) {
|
||||
signConfigManager.saveToFile(s, singular, p);
|
||||
}
|
||||
|
||||
public void deleteSign(String name) {
|
||||
signConfigManager.deleteSign(name);
|
||||
}
|
||||
|
||||
public void editSignText(String name, int lineNumber, String message) {
|
||||
signConfigManager.editText(name, lineNumber, message);
|
||||
}
|
||||
|
||||
public void addMessage(SudoSign s, SignMessage sm) {
|
||||
messageConfig.addMessageToConfig(s, sm);
|
||||
}
|
||||
|
||||
public void deleteMessage(SudoSign s, SignMessage sm, double delay) {
|
||||
messageConfig.deleteMessageFromConfig(s, sm, delay);
|
||||
}
|
||||
|
||||
public void addCommand(SudoSign s, SignCommand sm, PlayerInput type) {
|
||||
commandConfig.addCommandToConfig(s, sm, type);
|
||||
}
|
||||
|
||||
public void deleteCommand(SudoSign s, SignCommand sm, PlayerInput type, double oldDelay) {
|
||||
commandConfig.deleteCommandFromConfig(s, sm, type, oldDelay);
|
||||
}
|
||||
|
||||
public void setPrice(String name, double price) {
|
||||
signConfigManager.setPrice(name, price);
|
||||
}
|
||||
|
||||
public void addPermission(SudoSign s, String permission) {
|
||||
permissionConfig.addPermissionToConfig(s, permission);
|
||||
}
|
||||
|
||||
public void deletePermission(SudoSign s, String permission) {
|
||||
permissionConfig.deletePermissionFromConfig(s, permission);
|
||||
}
|
||||
|
||||
private void createCustomConfig() {
|
||||
if (!SudoSigns.sudoSignsPlugin.getDataFolder().exists()) {
|
||||
@@ -60,9 +111,12 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
public boolean loadCustomConfig() {
|
||||
signConfig = new YamlConfiguration();
|
||||
createCustomConfig();
|
||||
try {
|
||||
signConfig.load(signConfigFile);
|
||||
signConfig = YamlConfiguration.loadConfiguration(signConfigFile);
|
||||
if (signConfigManager != null) {
|
||||
signConfigManager.setSignConfig(signConfig);
|
||||
}
|
||||
if (!signConfig.isConfigurationSection("signs")) {
|
||||
signConfig.createSection("signs");
|
||||
save();
|
||||
@@ -70,7 +124,13 @@ public class ConfigManager {
|
||||
if (invalidEntriesManager != null) {
|
||||
invalidEntriesManager.setConfig(signConfig);
|
||||
}
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
if (!signConfig.contains("version")) {
|
||||
signConfig.createSection("version");
|
||||
signConfig.set("version", "1.1.0");
|
||||
save();
|
||||
fixConfig();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to initialise signs.yml!");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@@ -78,211 +138,72 @@ public class ConfigManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the signs from the config.
|
||||
* @return True if successful, false if not
|
||||
*/
|
||||
public ArrayList<String> loadSigns() {
|
||||
Map<String, SudoSign> tempSigns = new HashMap<>();
|
||||
public void fixConfig() {
|
||||
Set<String> signSection = signConfig.getConfigurationSection("signs").getKeys(false);
|
||||
String name;
|
||||
ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
String name = null;
|
||||
for (String key : signSection) {
|
||||
signConfig.set("signs." + key + ".op-commands", null);
|
||||
signConfig.set("signs." + key + ".price", 0.0);
|
||||
name = key;
|
||||
try {
|
||||
ConfigurationSection locSec = signConfig.getConfigurationSection("signs." + key + ".location");
|
||||
String world = locSec.getString("world");
|
||||
double x = locSec.getDouble("x");
|
||||
double y = locSec.getDouble("y");
|
||||
double z = locSec.getDouble("z");
|
||||
World w = Bukkit.getServer().getWorld(world);
|
||||
if (w != null) {
|
||||
Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
if (loc.getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) loc.getBlock().getState();
|
||||
SudoSign ss = new SudoSign(key);
|
||||
ss.setSign(sign);
|
||||
List<String> pCommands = signConfig.getStringList("signs." + key + ".player-commands");
|
||||
List<String> opCommands = signConfig.getStringList("signs." + key + ".op-commands");
|
||||
List<String> cCommands = signConfig.getStringList("signs." + key + ".console-commands");
|
||||
List<String> permissions = signConfig.getStringList("signs." + key + ".permissions");
|
||||
List<String> messages = signConfig.getStringList("signs." + key + ".messages");
|
||||
for (String cmd : pCommands) {
|
||||
ss.addPlayerCommand(new SignCommand(cmd, PlayerInput.PLAYER_COMMAND), false);
|
||||
}
|
||||
for (String cmd : opCommands) {
|
||||
ss.addPlayerCommand(new SignCommand(cmd, PlayerInput.PLAYER_COMMAND), true);
|
||||
}
|
||||
for (String cmd : cCommands) {
|
||||
ss.addConsoleCommand(new SignCommand(cmd, PlayerInput.CONSOLE_COMMAND));
|
||||
}
|
||||
for (String perm : permissions) {
|
||||
ss.addPermission(perm);
|
||||
}
|
||||
for (String message : messages) {
|
||||
ss.addMessage(message);
|
||||
}
|
||||
tempSigns.put(name, ss);
|
||||
} else {
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The block at the provided location is not a sign. Skipping...");
|
||||
}
|
||||
} else {
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The world name for this sign is invalid. Skipping...");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
List<String> pCommands = signConfig.getStringList("signs." + key + ".player-commands");
|
||||
List<String> cCommands = signConfig.getStringList("signs." + key + ".console-commands");
|
||||
List<String> messages = signConfig.getStringList("signs." + key + ".messages");
|
||||
if (pCommands.size() == 0 && cCommands.size() == 0 && messages.size() == 0) {
|
||||
save();
|
||||
continue;
|
||||
}
|
||||
if (pCommands.size() != 0) {
|
||||
try {
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : pCommands) {
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
signConfig.set("signs." + name + ".player-commands", mapList);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
signConfig.set("signs." + key + ".op-commands", null);
|
||||
if (cCommands.size() != 0) {
|
||||
try {
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : cCommands) {
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
signConfig.set("signs." + name + ".console-commands", mapList);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (messages.size() != 0) {
|
||||
try {
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : messages) {
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
signConfig.set("signs." + name + ".messages", mapList);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
save();
|
||||
}
|
||||
invalidEntriesManager.setInvalidEntries(invalidSigns);
|
||||
SudoSigns.signs = tempSigns;
|
||||
return invalidSigns;
|
||||
}
|
||||
|
||||
void save() {
|
||||
public void save() {
|
||||
try {
|
||||
signConfig.save(signConfigFile);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to save to signs.yml!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void addPermissionToConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.add(perm);
|
||||
signConfig.set(path, perms);
|
||||
save();
|
||||
}
|
||||
|
||||
public void deletePermissionFromConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.remove(perm);
|
||||
signConfig.set(path, perms);
|
||||
save();
|
||||
}
|
||||
|
||||
public void addMessageToConfig(SudoSign s, String message) {
|
||||
String path = "signs." + s.getName() + ".messages";
|
||||
List<String> messages = signConfig.getStringList(path);
|
||||
messages.add(message);
|
||||
signConfig.set(path, messages);
|
||||
save();
|
||||
}
|
||||
|
||||
public void deleteMessageFromConfig(SudoSign s, String message) {
|
||||
String path = "signs." + s.getName() + ".messages";
|
||||
List<String> messages = signConfig.getStringList(path);
|
||||
messages.remove(message);
|
||||
signConfig.set(path, messages);
|
||||
save();
|
||||
}
|
||||
|
||||
public void addCommandToConfig(SudoSign s, SignCommand cmd, PlayerInput type) {
|
||||
if (signConfig.isConfigurationSection("signs." + s.getName())) {
|
||||
switch (type) {
|
||||
case PLAYER_COMMAND:
|
||||
List<String> pCmds = signConfig.getStringList("signs." + s.getName() + ".player-commands");
|
||||
pCmds.add(cmd.getCommand());
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", pCmds);
|
||||
break;
|
||||
case PLAYER_COMMAND_WITH_PERMISSIONS:
|
||||
List<String> opCmds = signConfig.getStringList("signs." + s.getName() + ".op-commands");
|
||||
opCmds.add(cmd.getCommand());
|
||||
signConfig.set("signs." + s.getName() + ".op-commands", opCmds);
|
||||
break;
|
||||
case CONSOLE_COMMAND:
|
||||
List<String> cCmds = signConfig.getStringList("signs." + s.getName() + ".console-commands");
|
||||
cCmds.add(cmd.getCommand());
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", cCmds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void deleteCommandFromConfig(SudoSign s, SignCommand cmd, PlayerInput type) {
|
||||
if (signConfig.isConfigurationSection("signs." + s.getName())) {
|
||||
if (type.equals(PlayerInput.PLAYER_COMMAND)) {
|
||||
if (signConfig.isList("signs." + s.getName() + ".player-commands")) {
|
||||
List<String> cmds = signConfig.getStringList("signs." + s.getName() + ".player-commands");
|
||||
cmds.remove(cmd.getCommand());
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", cmds);
|
||||
}
|
||||
} else if (type.equals(PlayerInput.CONSOLE_COMMAND)) {
|
||||
if (signConfig.isList("signs." + s.getName() + ".console-commands")) {
|
||||
List<String> cmds = signConfig.getStringList("signs." + s.getName() + ".console-commands");
|
||||
cmds.remove(cmd.getCommand());
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", cmds);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void deleteSign(String name) {
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
signConfig.set("signs." + name + "", null);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void saveToFile(SudoSign s, Boolean singular, Player p) {
|
||||
if (singular) {
|
||||
saveSign(s, p);
|
||||
} else {
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
saveSign(entry.getValue(), p);
|
||||
}
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void saveSign(SudoSign s, Player p) {
|
||||
String name = s.getName();
|
||||
try {
|
||||
if (!signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
signConfig.createSection("signs." + name + "");
|
||||
signConfig.createSection("signs." + name + ".text");
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
lines.addAll(s.getText());
|
||||
signConfig.set("signs." + name + ".text", lines);
|
||||
ConfigurationSection locSec = signConfig.createSection("signs." + name + ".location");
|
||||
String world = s.getSign().getWorld().getName();
|
||||
double x = s.getSign().getLocation().getX();
|
||||
double y = s.getSign().getLocation().getY();
|
||||
double z = s.getSign().getLocation().getZ();
|
||||
signConfig.set("signs." + name + ".blocktype", s.getSign().getType().toString());
|
||||
locSec.set("world", world);
|
||||
locSec.set("x", x);
|
||||
locSec.set("y", y);
|
||||
locSec.set("z", z);
|
||||
if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof org.bukkit.block.data.type.Sign) {
|
||||
org.bukkit.block.data.type.Sign facing = (org.bukkit.block.data.type.Sign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
locSec.set("rotation", facing.getRotation().toString());
|
||||
} else if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof org.bukkit.block.data.type.WallSign) {
|
||||
org.bukkit.block.data.type.WallSign facing = (org.bukkit.block.data.type.WallSign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
locSec.set("rotation", facing.getFacing().toString());
|
||||
}
|
||||
signConfig.createSection("signs." + name + ".permissions");
|
||||
signConfig.createSection("signs." + name + ".messages");
|
||||
signConfig.createSection("signs." + name + ".player-commands");
|
||||
signConfig.createSection("signs." + name + ".console-commands");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (p != null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Failed to save sign %NAME% to the config!", name);
|
||||
}
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to save " + name + " to signs.yml!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,16 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InvalidEntriesManager {
|
||||
/**
|
||||
* The class for managing invalid sign entries in the config.
|
||||
* @author MylesMor
|
||||
* @author https://mylesmor.dev
|
||||
*/
|
||||
|
||||
ArrayList<String> invalidEntries = new ArrayList<>();
|
||||
ConfigManager configManager;
|
||||
@@ -28,6 +31,11 @@ public class InvalidEntriesManager {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to a fix an invalid entry by placing a sign in the correct position.
|
||||
* @param s The sign's name.
|
||||
* @return True if sign successfully fixed, otherwise False.
|
||||
*/
|
||||
private boolean fixEntry(String s) {
|
||||
try {
|
||||
ConfigurationSection locSec = config.getConfigurationSection("signs." + s + ".location");
|
||||
@@ -56,7 +64,6 @@ public class InvalidEntriesManager {
|
||||
b.setBlockData(facing);
|
||||
}
|
||||
Sign newSign = (Sign) b.getState();
|
||||
Bukkit.getLogger().warning(w.getBlockAt(loc).getBlockData().toString());
|
||||
List<String> lines = getSignText(s);
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
@@ -84,7 +91,11 @@ public class InvalidEntriesManager {
|
||||
invalidEntries.add(entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the invalid sign's text from the config.
|
||||
* @param name Name of the sign.
|
||||
* @return The sign's message or null if not found.
|
||||
*/
|
||||
public List<String> getSignText(String name) {
|
||||
List<String> signSec = config.getStringList("signs." + name + ".text");
|
||||
for (String item : signSec) {
|
||||
@@ -96,7 +107,12 @@ public class InvalidEntriesManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a sign's entry in the config.
|
||||
* @param name Name of the sign.
|
||||
* @param all True if all invalid entries should be purged, or False for just one.
|
||||
* @return The sign's message or null if not found.
|
||||
*/
|
||||
public boolean purgeInvalidEntry(String name, boolean all) {
|
||||
if (all) {
|
||||
for (String s : invalidEntries) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessageConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
MessageConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void addMessageToConfig(SudoSign s, SignMessage sm) {
|
||||
HashMap<String, Double> map;
|
||||
List<Map<?, ?>> messages = signConfig.getMapList("signs." + s.getName() + ".messages");
|
||||
map = new HashMap<>();
|
||||
map.put(sm.getMessage(), sm.getDelay());
|
||||
messages.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".messages", messages);
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public void deleteMessageFromConfig(SudoSign s, SignMessage sm, double oldDelay) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".messages");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> messages : map.entrySet()) {
|
||||
String key = (String) messages.getKey();
|
||||
if (key.equals(sm.getMessage()) && (Double) messages.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".messages", mapList);
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
PermissionConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void addPermissionToConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.add(perm);
|
||||
signConfig.set(path, perms);
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public void deletePermissionFromConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.remove(perm);
|
||||
signConfig.set(path, perms);
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SignConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
SignConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void setSignConfig(FileConfiguration signConfig) {
|
||||
this.signConfig = signConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the signs from the config.
|
||||
* @return True if successful, false if not
|
||||
*/
|
||||
public ArrayList<String> loadSigns() {
|
||||
Map<String, SudoSign> tempSigns = new HashMap<>();
|
||||
Set<String> signSection = signConfig.getConfigurationSection("signs").getKeys(false);
|
||||
String name;
|
||||
ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
for (String key : signSection) {
|
||||
name = key;
|
||||
try {
|
||||
ConfigurationSection locSec = signConfig.getConfigurationSection("signs." + key + ".location");
|
||||
String world = locSec.getString("world");
|
||||
double x = locSec.getDouble("x");
|
||||
double y = locSec.getDouble("y");
|
||||
double z = locSec.getDouble("z");
|
||||
World w = Bukkit.getServer().getWorld(world);
|
||||
if (w != null) {
|
||||
Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
if (loc.getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) loc.getBlock().getState();
|
||||
SudoSign ss = new SudoSign(key);
|
||||
ss.setSign(sign);
|
||||
List<Map<?, ?>> pCommands = signConfig.getMapList("signs." + key + ".player-commands");
|
||||
List<Map<?, ?>> cCommands = signConfig.getMapList("signs." + key + ".console-commands");
|
||||
List<String> permissions = signConfig.getStringList("signs." + key + ".permissions");
|
||||
List<Map<?, ?>> messages = signConfig.getMapList("signs." + key + ".messages");
|
||||
try {
|
||||
ss.setPrice((Double) signConfig.get("signs." + key + ".price"));
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().info("Invalid price for sign " + name + "! Default to 0.");
|
||||
ss.setPrice(0.0);
|
||||
}
|
||||
int number = 0;
|
||||
for (Map<?, ?> sc : pCommands) {
|
||||
for (Map.Entry<?, ?> cmd : sc.entrySet()) {
|
||||
ss.addPlayerCommand(new SignCommand(number++, (String) cmd.getKey(), (Double) cmd.getValue(), PlayerInput.PLAYER_COMMAND));
|
||||
}
|
||||
}
|
||||
for (Map<?, ?> sc : cCommands) {
|
||||
for (Map.Entry<?, ?> cmd : sc.entrySet()) {
|
||||
ss.addConsoleCommand(new SignCommand(number++, (String) cmd.getKey(), (Double) cmd.getValue(), PlayerInput.CONSOLE_COMMAND));
|
||||
}
|
||||
}
|
||||
for (String perm : permissions) {
|
||||
ss.addPermission(perm);
|
||||
}
|
||||
number = 0;
|
||||
for (Map<?, ?> sc : messages) {
|
||||
for (Map.Entry<?, ?> message : sc.entrySet()) {
|
||||
ss.addMessage(new SignMessage(number++, (String) message.getKey(), (Double) message.getValue(), PlayerInput.MESSAGE));
|
||||
}
|
||||
}
|
||||
tempSigns.put(name, ss);
|
||||
} else {
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The block at the provided location is not a sign. Skipping...");
|
||||
}
|
||||
} else {
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The world name for this sign is invalid. Skipping...");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
configManager.getInvalidEntriesManager().setInvalidEntries(invalidSigns);
|
||||
SudoSigns.signs = tempSigns;
|
||||
SudoSigns.invalidSigns = invalidSigns;
|
||||
return invalidSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a sign from the config.
|
||||
* @param name The name of the sign.
|
||||
*/
|
||||
public void deleteSign(String name) {
|
||||
if (signConfig.isSet("signs." + name)) {
|
||||
signConfig.set("signs." + name, null);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the SudoSigns to config.
|
||||
* @param s The SudoSign object.
|
||||
* @param singular True to save a singular sign, False to save all.
|
||||
* @param p The player who has edited the sign.
|
||||
*/
|
||||
public void saveToFile(SudoSign s, boolean singular, Player p) {
|
||||
if (singular) {
|
||||
saveSign(s, p);
|
||||
} else {
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
saveSign(entry.getValue(), p);
|
||||
}
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a SudoSign in the config.
|
||||
* @param s The SudoSign object.
|
||||
* @param p The player who has edited the sign.
|
||||
*/
|
||||
public void saveSign(SudoSign s, Player p) {
|
||||
String name = s.getName();
|
||||
try {
|
||||
if (!signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
signConfig.createSection("signs." + name + "");
|
||||
signConfig.createSection("signs." + name + ".text");
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
lines.addAll(s.getText());
|
||||
signConfig.set("signs." + name + ".text", lines);
|
||||
signConfig.set("signs." + name + ".price", 0.0);
|
||||
ConfigurationSection locSec = signConfig.createSection("signs." + name + ".location");
|
||||
String world = s.getSign().getWorld().getName();
|
||||
double x = s.getSign().getLocation().getX();
|
||||
double y = s.getSign().getLocation().getY();
|
||||
double z = s.getSign().getLocation().getZ();
|
||||
signConfig.set("signs." + name + ".blocktype", s.getSign().getType().toString());
|
||||
locSec.set("world", world);
|
||||
locSec.set("x", x);
|
||||
locSec.set("y", y);
|
||||
locSec.set("z", z);
|
||||
if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof org.bukkit.block.data.type.Sign) {
|
||||
org.bukkit.block.data.type.Sign facing = (org.bukkit.block.data.type.Sign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
locSec.set("rotation", facing.getRotation().toString());
|
||||
} else if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof org.bukkit.block.data.type.WallSign) {
|
||||
org.bukkit.block.data.type.WallSign facing = (org.bukkit.block.data.type.WallSign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
locSec.set("rotation", facing.getFacing().toString());
|
||||
}
|
||||
signConfig.createSection("signs." + name + ".permissions");
|
||||
signConfig.createSection("signs." + name + ".messages");
|
||||
signConfig.createSection("signs." + name + ".player-commands");
|
||||
signConfig.createSection("signs." + name + ".console-commands");
|
||||
configManager.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (p != null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Failed to save sign %NAME% to the config!", name);
|
||||
}
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to save " + name + " to signs.yml!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void editText(String name, int lineNumber, String newText) {
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
List<String> text = signConfig.getStringList("signs." + name + ".text");
|
||||
Bukkit.getLogger().info(Integer.toString(text.size()));
|
||||
text.set(lineNumber-1, newText);
|
||||
signConfig.set("signs." + name + ".text", text);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public void setPrice(String name, double price) {
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
signConfig.set("signs." + name + ".price", price);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,13 @@ package dev.mylesmor.sudosigns.data;
|
||||
*/
|
||||
public enum PlayerInput {
|
||||
PLAYER_COMMAND,
|
||||
PLAYER_COMMAND_WITH_PERMISSIONS,
|
||||
CONSOLE_COMMAND,
|
||||
RENAME,
|
||||
PERMISSION,
|
||||
MESSAGE,
|
||||
COMMAND_DELAY,
|
||||
MESSAGE_DELAY,
|
||||
EDIT_TEXT_NUMBER,
|
||||
EDIT_TEXT,
|
||||
SET_PRICE,
|
||||
}
|
||||
@@ -11,10 +11,14 @@ public class SignCommand {
|
||||
|
||||
private String command;
|
||||
private PlayerInput type;
|
||||
private int number;
|
||||
private double delay;
|
||||
|
||||
public SignCommand(String cmd, PlayerInput type) {
|
||||
public SignCommand(int number, String cmd, double delay, PlayerInput type) {
|
||||
this.number = number;
|
||||
command = cmd;
|
||||
this.type = type;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
@@ -25,5 +29,14 @@ public class SignCommand {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getNumber() { return number; }
|
||||
|
||||
public double getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dev.mylesmor.sudosigns.data;
|
||||
|
||||
public class SignMessage {
|
||||
|
||||
private String message;
|
||||
private PlayerInput type;
|
||||
private int number;
|
||||
private double delay;
|
||||
|
||||
public SignMessage(int number, String message, double delay, PlayerInput type) {
|
||||
this.number = number;
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public PlayerInput getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getNumber() { return number; }
|
||||
|
||||
public double getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
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;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -19,11 +23,12 @@ import java.util.Map;
|
||||
*/
|
||||
public class SudoSign {
|
||||
|
||||
private HashMap<SignCommand, Boolean> playerCommands = new HashMap<>();
|
||||
private ArrayList<SignCommand> playerCommands = new ArrayList<>();
|
||||
private ArrayList<SignCommand> consoleCommands = new ArrayList<>();
|
||||
private ArrayList<String> permissions = new ArrayList<>();
|
||||
private ArrayList<String> messages = new ArrayList<>();
|
||||
private ArrayList<SignMessage> messages = new ArrayList<>();
|
||||
private ArrayList<String> text = new ArrayList<>();
|
||||
private double price = 0;
|
||||
private String worldName;
|
||||
private double x;
|
||||
private double y;
|
||||
@@ -46,9 +51,8 @@ public class SudoSign {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addPlayerCommand(SignCommand sc, boolean permissions) {
|
||||
playerCommands.put(sc, permissions);
|
||||
|
||||
public void addPlayerCommand(SignCommand sc) {
|
||||
playerCommands.add(sc);
|
||||
}
|
||||
|
||||
public List<String> getText() {
|
||||
@@ -62,12 +66,18 @@ public class SudoSign {
|
||||
String line = lines[i];
|
||||
text.add(line.replaceAll("§", "&"));
|
||||
line = ChatColor.translateAlternateColorCodes('&', line);
|
||||
//line = ChatColor.translateAlternateColorCodes('§', line);
|
||||
sign.setLine(i, line);
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
|
||||
public void editLine(int lineNumber, String message) {
|
||||
Sign sign = getSign();
|
||||
String line = ChatColor.translateAlternateColorCodes('&', message);
|
||||
sign.setLine(lineNumber, line);
|
||||
sign.update();
|
||||
}
|
||||
|
||||
public void addConsoleCommand(SignCommand sc) {
|
||||
consoleCommands.add(sc);
|
||||
}
|
||||
@@ -92,11 +102,11 @@ public class SudoSign {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void addMessage(String s) {
|
||||
public void addMessage(SignMessage s) {
|
||||
messages.add(s);
|
||||
}
|
||||
|
||||
public void removeMessage(String s) {
|
||||
public void removeMessage(SignMessage s) {
|
||||
messages.remove(s);
|
||||
}
|
||||
|
||||
@@ -105,14 +115,15 @@ public class SudoSign {
|
||||
this.playerCommands = s.getPlayerCommands();
|
||||
this.consoleCommands = s.getConsoleCommands();
|
||||
this.messages = s.getMessages();
|
||||
this.price = s.getPrice();
|
||||
}
|
||||
|
||||
public ArrayList<String> getMessages() { return messages; }
|
||||
public ArrayList<SignMessage> getMessages() { return messages; }
|
||||
|
||||
public void setMessages(ArrayList<String> messages) { this.messages = messages; }
|
||||
public void setMessages(ArrayList<SignMessage> messages) { this.messages = messages; }
|
||||
|
||||
|
||||
public void setPlayerCommands(HashMap<SignCommand, Boolean> playerCommands) {
|
||||
public void setPlayerCommands(ArrayList<SignCommand> playerCommands) {
|
||||
this.playerCommands = playerCommands;
|
||||
}
|
||||
|
||||
@@ -124,7 +135,7 @@ public class SudoSign {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public HashMap<SignCommand, Boolean> getPlayerCommands() {
|
||||
public ArrayList<SignCommand> getPlayerCommands() {
|
||||
return playerCommands;
|
||||
}
|
||||
|
||||
@@ -132,6 +143,14 @@ public class SudoSign {
|
||||
return consoleCommands;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all of the commands attached to the sign, if the player has the required permissions.
|
||||
* @param p The player who is running the sign.
|
||||
@@ -144,27 +163,63 @@ public class SudoSign {
|
||||
}
|
||||
}
|
||||
if (hasPermission) {
|
||||
for (String s : messages) {
|
||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', s).replaceAll("(?i)%PLAYER%", p.getName()));
|
||||
}
|
||||
for (Map.Entry<SignCommand, Boolean> entry : playerCommands.entrySet()) {
|
||||
String cmd = entry.getKey().getCommand().replaceAll("(?i)%PLAYER%", p.getName());
|
||||
if (entry.getValue()) {
|
||||
try {
|
||||
p.setOp(true);
|
||||
p.performCommand(cmd);
|
||||
p.setOp(false);
|
||||
} catch (Exception ignored) { }
|
||||
finally {
|
||||
p.setOp(false);
|
||||
if (SudoSigns.econ != null) {
|
||||
EconomyResponse r = SudoSigns.econ.withdrawPlayer(p, price);
|
||||
if (!r.transactionSuccess()) {
|
||||
if (price == 1.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have enough money to run this sign! This sign costs " + ChatColor.GOLD + SudoSigns.econ.currencyNameSingular() + price + ChatColor.RED + ".", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have enough money to run this sign! This sign costs " + ChatColor.GOLD + SudoSigns.econ.currencyNamePlural() + price + ChatColor.RED + ".", null);
|
||||
}
|
||||
} else {
|
||||
p.performCommand(cmd);
|
||||
return;
|
||||
}
|
||||
if (price == 1.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, ChatColor.GOLD + SudoSigns.econ.currencyNameSingular() + price + ChatColor.GREEN + " has been withdrawn from your balance.", null);
|
||||
} else if (price != 0.0) {
|
||||
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('&', finalMessageString));
|
||||
}
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sm.getDelay()/50));
|
||||
}
|
||||
// Queue Sign player commands
|
||||
for (SignCommand sc : playerCommands) {
|
||||
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(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());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
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(), finalCommandString);
|
||||
}
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay()/50));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "You don't have permission to do this!");
|
||||
@@ -185,4 +240,46 @@ public class SudoSign {
|
||||
Bukkit.getLogger().warning("Failed to locate sign " + name + "!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getNextCommandNumber() {
|
||||
int number = 0;
|
||||
for (SignCommand c: consoleCommands) {
|
||||
number = Math.max(c.getNumber(), number);
|
||||
}
|
||||
for(SignCommand sc: playerCommands) {
|
||||
number = Math.max(sc.getNumber(), number);
|
||||
}
|
||||
return number+1;
|
||||
}
|
||||
|
||||
public int getNextMessageNumber() {
|
||||
int number = 0;
|
||||
for (SignMessage m : messages) {
|
||||
number = Math.max(m.getNumber(), number);
|
||||
}
|
||||
return number+1;
|
||||
}
|
||||
|
||||
public SignMessage getSignMessageByNumber(int number) {
|
||||
for (SignMessage sm: messages) {
|
||||
if (sm.getNumber() == number) {
|
||||
return sm;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SignCommand getSignCommandByNumber(int number) {
|
||||
for (SignCommand c: consoleCommands) {
|
||||
if (c.getNumber() == number) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
for(SignCommand sc: playerCommands) {
|
||||
if (sc.getNumber() == number) {
|
||||
return sc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ public class SudoUser {
|
||||
public void addTextInput(PlayerInput type) {
|
||||
this.textInput = true;
|
||||
this.inputType = type;
|
||||
|
||||
}
|
||||
|
||||
public void removeTextInput() {
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ChatListener implements Listener {
|
||||
if (user != null) {
|
||||
if (user.isTextInput() && user.isEditing()) {
|
||||
e.setCancelled(true);
|
||||
if (user.getInputType() == PlayerInput.CONSOLE_COMMAND || user.getInputType() == PlayerInput.PLAYER_COMMAND || user.getInputType() == PlayerInput.PLAYER_COMMAND_WITH_PERMISSIONS) {
|
||||
if (user.getInputType() == PlayerInput.CONSOLE_COMMAND || user.getInputType() == PlayerInput.PLAYER_COMMAND) {
|
||||
user.getEditor().getCommandsMenu().addCommand(e.getMessage().substring(1), user.getInputType());
|
||||
user.removeTextInput();
|
||||
} else {
|
||||
@@ -48,7 +48,7 @@ public class ChatListener implements Listener {
|
||||
if (user.isTextInput() && user.isEditing()) {
|
||||
SignEditor editor = user.getEditor();
|
||||
switch (user.getInputType()) {
|
||||
case PLAYER_COMMAND: case CONSOLE_COMMAND: case PLAYER_COMMAND_WITH_PERMISSIONS:
|
||||
case PLAYER_COMMAND: case CONSOLE_COMMAND:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToCommands);
|
||||
return;
|
||||
@@ -77,6 +77,92 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
handle(e, true, null, editor, user, edit -> editor.getMessagesMenu().addMessage(ChatColor.stripColor(e.getMessage())), editor::goToMessages);
|
||||
break;
|
||||
case COMMAND_DELAY:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToCommands);
|
||||
return;
|
||||
}
|
||||
double delay = 0;
|
||||
try {
|
||||
delay = Double.parseDouble(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number!", "");
|
||||
return;
|
||||
}
|
||||
double finalDelay = delay;
|
||||
handle(e, true, null, editor, user, edit -> editor.getCommandOptionsMenu().setDelay(finalDelay), editor::goToCommands);
|
||||
break;
|
||||
case MESSAGE_DELAY:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
double messageDelay = 0;
|
||||
try {
|
||||
messageDelay = Double.parseDouble(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number!", "");
|
||||
return;
|
||||
}
|
||||
double finalMessageDelay = messageDelay;
|
||||
handle(e, true, null, editor, user, edit -> editor.getMessageOptionsMenu().setDelay(finalMessageDelay), editor::goToMessages);
|
||||
break;
|
||||
case EDIT_TEXT_NUMBER:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
int lineNumber = 0;
|
||||
try {
|
||||
lineNumber = Integer.parseInt(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number between 1-4!", "");
|
||||
return;
|
||||
}
|
||||
if (lineNumber < 1 || lineNumber > 4) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number between 1-4!", "");
|
||||
return;
|
||||
}
|
||||
final int finalLineNumber = lineNumber;
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setLineNumber(finalLineNumber), null);
|
||||
break;
|
||||
case EDIT_TEXT:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
if (e.getMessage().length() > 15) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "The message can't be greater than 15 characters!", "");
|
||||
return;
|
||||
}
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setText(e.getMessage()), editor::goToMain);
|
||||
break;
|
||||
case SET_PRICE:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
double price;
|
||||
try {
|
||||
price = Double.parseDouble(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number!", "");
|
||||
return;
|
||||
}
|
||||
if (price < 0) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter 0 or a positive number!", "");
|
||||
return;
|
||||
}
|
||||
double finalPrice = price;
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setPrice(finalPrice), editor::goToMain);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -88,6 +174,8 @@ public class ChatListener implements Listener {
|
||||
if (message != null) Util.sudoSignsMessage(e.getPlayer(), ChatColor.RED, message, null);
|
||||
if (eventConsumer != null) Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, () -> eventConsumer.accept(editor));
|
||||
user.removeTextInput();
|
||||
Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, finalAction);
|
||||
if (finalAction != null) {
|
||||
Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, finalAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,16 @@ 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;
|
||||
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;
|
||||
|
||||
@@ -42,10 +46,10 @@ public class InventoryListener implements Listener {
|
||||
checkForMainMenuClicks(editor, m);
|
||||
break;
|
||||
case COMMANDS:
|
||||
checkForCommandsClicks(p, editor, m, itemName);
|
||||
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);
|
||||
@@ -54,11 +58,15 @@ public class InventoryListener implements Listener {
|
||||
choosePermissionType(editor, m);
|
||||
break;
|
||||
case MESSAGES:
|
||||
if (e.getCurrentItem().getItemMeta().getLore() != null) {
|
||||
checkForMessagesClicks(p, editor, m, e.getCurrentItem().getItemMeta().getLore().get(0).replace("§", "&"));
|
||||
} else {
|
||||
checkForMessagesClicks(p, editor, m, null);
|
||||
}
|
||||
checkForMessagesClicks(p, editor, m, e.getCurrentItem());
|
||||
break;
|
||||
case COMMAND_OPTIONS:
|
||||
checkForCommandOptionClicks(p, editor, m, itemName);
|
||||
break;
|
||||
case MESSAGE_OPTIONS:
|
||||
checkForMessageOptionClicks(p, editor, m, itemName);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,11 +105,11 @@ public class InventoryListener implements Listener {
|
||||
}
|
||||
}
|
||||
switch (m) {
|
||||
case BOOK:
|
||||
case NAME_TAG:
|
||||
editor.prepareRename();
|
||||
break;
|
||||
case OAK_SIGN:
|
||||
editor.editSignText();
|
||||
case WRITABLE_BOOK:
|
||||
editor.editSignNumber();
|
||||
break;
|
||||
case BARRIER:
|
||||
editor.goToPermissions();
|
||||
@@ -111,27 +119,54 @@ public class InventoryListener implements Listener {
|
||||
break;
|
||||
case BIRCH_SIGN:
|
||||
editor.goToMessages();
|
||||
break;
|
||||
case GOLD_NUGGET:
|
||||
editor.getMainMenu().prepareSetPrice();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Commands menu.
|
||||
* Checks for GUI clicks in the Command Options 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 clicked item.
|
||||
*/
|
||||
public void checkForCommandsClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
public void checkForCommandsClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case WRITABLE_BOOK:
|
||||
editor.getCommandsMenu().prepareCommand();
|
||||
break;
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
editor.getCommandsMenu().deleteCommand(ChatColor.stripColor(itemName));
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
editor.goToCommandOptionsMenu(item);
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Command Options 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.
|
||||
*/
|
||||
public void checkForCommandOptionClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CLOCK:
|
||||
editor.getCommandOptionsMenu().addDelay();
|
||||
break;
|
||||
case BARRIER:
|
||||
if (p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
editor.getCommandOptionsMenu().deleteCommand();
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,18 +176,41 @@ public class InventoryListener implements Listener {
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param itemName The name of the item clicked.
|
||||
*/
|
||||
public void checkForMessagesClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
public void checkForMessageOptionClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CLOCK:
|
||||
editor.getMessageOptionsMenu().addDelay();
|
||||
break;
|
||||
case BARRIER:
|
||||
if (p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
editor.getMessageOptionsMenu().deleteMessage();
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMessages();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Commands menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param item The ItemStack of the clicked item.
|
||||
*/
|
||||
public void checkForMessagesClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case WRITABLE_BOOK:
|
||||
editor.getMessagesMenu().prepareMessage();
|
||||
break;
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
editor.getMessagesMenu().deleteMessage(itemName.substring(4));
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
|
||||
editor.goToMessageOptionsMenu(item);
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,14 +224,12 @@ public class InventoryListener implements Listener {
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToPermissions();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseCommandType(SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CHAIN_COMMAND_BLOCK:
|
||||
editor.getCommandsMenu().chooseCommandType(PlayerInput.PLAYER_COMMAND_WITH_PERMISSIONS);
|
||||
break;
|
||||
case PLAYER_HEAD:
|
||||
editor.getCommandsMenu().chooseCommandType(PlayerInput.PLAYER_COMMAND);
|
||||
break;
|
||||
@@ -193,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:
|
||||
|
||||
@@ -109,7 +109,7 @@ public class SignListener implements Listener {
|
||||
SignEditor editor = new SignEditor(p, SudoSigns.signs.get(user.getPassThru()), user);
|
||||
user.setEditor(editor);
|
||||
}
|
||||
SudoSigns.config.saveToFile(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
SudoSigns.config.saveSign(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign wasn't clicked! Cancelling...", null);
|
||||
user.setCreate(false);
|
||||
@@ -130,7 +130,7 @@ public class SignListener implements Listener {
|
||||
}
|
||||
SudoSigns.signs.get(user.getPassThru()).setSign(newSign);
|
||||
SudoSigns.signs.get(user.getPassThru()).addLines();
|
||||
SudoSigns.config.saveToFile(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
SudoSigns.config.saveSign(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Sign has been copied to sign %NAME% successfully!", user.getPassThru());
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign wasn't clicked! Cancelling...", null);
|
||||
@@ -250,6 +250,8 @@ public class SignListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// The following events all attempt to prevent a SudoSign being broken
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent e) {
|
||||
ArrayList<Block> blocksToRemove = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
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.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CommandOptionsMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private SignCommand sc;
|
||||
private Player p;
|
||||
private SignEditor editor;
|
||||
|
||||
CommandOptionsMenu(SudoUser su, Player p, SudoSign sign, ItemStack item, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
this.editor = editor;
|
||||
this.sc = findSignCommand(item);
|
||||
if (this.sc == null) {
|
||||
editor.goToCommands();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void goToCommandOptionsMenu() {
|
||||
createCommandOptionsMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
private SignCommand findSignCommand(ItemStack item) {
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "command-number");
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(key, PersistentDataType.INTEGER)) {
|
||||
int foundValue = container.get(key, PersistentDataType.INTEGER);
|
||||
return sign.getSignCommandByNumber(foundValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void createCommandOptionsMenu() {
|
||||
menu = Bukkit.createInventory(p, 45, "Command options: /" + sc.getCommand());
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack clock = new ItemStack(Material.CLOCK);
|
||||
ItemMeta clockMeta = clock.getItemMeta();
|
||||
lore.add(ChatColor.YELLOW + "Change the delay after which the command executes");
|
||||
clockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Change Delay");
|
||||
clockMeta.setLore(lore);
|
||||
clock.setItemMeta(clockMeta);
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.RED + "Delete Command");
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS) && p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
menu.setItem(20, clock);
|
||||
menu.setItem(24, barrier);
|
||||
} else {
|
||||
menu.setItem(22, clock);
|
||||
}
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
public void addDelay() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the delay in seconds. To cancel, type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.COMMAND_DELAY);
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
double oldDelay = sc.getDelay();
|
||||
sc.setDelay(delay * 1000);
|
||||
SudoSigns.config.deleteCommand(sign, sc, sc.getType(), oldDelay);
|
||||
SudoSigns.config.addCommand(sign, sc, sc.getType());
|
||||
}
|
||||
|
||||
public void deleteCommand() {
|
||||
if (sc.getType() == PlayerInput.CONSOLE_COMMAND) {
|
||||
SudoSigns.config.deleteCommand(sign, sc, PlayerInput.CONSOLE_COMMAND, sc.getDelay());
|
||||
sign.deleteConsoleCommand(sc);
|
||||
} else if (sc.getType() == PlayerInput.PLAYER_COMMAND) {
|
||||
SudoSigns.config.deleteCommand(sign, sc, PlayerInput.PLAYER_COMMAND, sc.getDelay());
|
||||
sign.deletePlayerCommand(sc);
|
||||
}
|
||||
editor.goToCommands();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.data.*;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
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.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -39,8 +39,6 @@ public class CommandsMenu {
|
||||
public void goToCommandsMenu() {
|
||||
createCommandsMenu();
|
||||
p.openInventory(menu);
|
||||
editor.setCurrentPage(PAGE);
|
||||
|
||||
}
|
||||
|
||||
private void createCommandsMenu() {
|
||||
@@ -72,24 +70,28 @@ public class CommandsMenu {
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "command-number");
|
||||
|
||||
ArrayList<SignCommand> orderedSignCommands = sign.getPlayerCommands();
|
||||
orderedSignCommands.sort(Comparator.comparing(SignCommand::getDelay));
|
||||
|
||||
// Populates spaces with commands.
|
||||
int i = 1;
|
||||
for (Map.Entry<SignCommand, Boolean> entry : sign.getPlayerCommands().entrySet()) {
|
||||
SignCommand sc = entry.getKey();
|
||||
for (SignCommand sc : orderedSignCommands) {
|
||||
if (i > 26) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
if (entry.getValue()) {
|
||||
lore.add(ChatColor.YELLOW + "Player Command with Permissions (player is granted OP for this command only).");
|
||||
} else {
|
||||
lore.add(ChatColor.YELLOW + "Player Command");
|
||||
}
|
||||
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
|
||||
if (p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
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.RED + "Click to delete!");
|
||||
lore.add(ChatColor.GREEN + "Click for options!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sc.getNumber());
|
||||
bookMeta.setLore(lore);
|
||||
lore.clear();
|
||||
book.setItemMeta(bookMeta);
|
||||
@@ -97,16 +99,26 @@ public class CommandsMenu {
|
||||
menu.setItem(i, book);
|
||||
i++;
|
||||
}
|
||||
|
||||
orderedSignCommands = sign.getConsoleCommands();
|
||||
orderedSignCommands.sort(Comparator.comparing(SignCommand::getDelay));
|
||||
|
||||
i = 19;
|
||||
for (SignCommand sc : sign.getConsoleCommands()) {
|
||||
for (SignCommand sc : orderedSignCommands) {
|
||||
if (i > 35) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
|
||||
if (p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
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.RED + "Click to delete!");
|
||||
lore.add(ChatColor.GREEN + "Click for options!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sc.getNumber());
|
||||
bookMeta.setLore(lore);
|
||||
lore.clear();
|
||||
book.setItemMeta(bookMeta);
|
||||
@@ -141,26 +153,14 @@ public class CommandsMenu {
|
||||
headMeta.setLore(lore);
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
ItemStack chainCmdBlock = new ItemStack(Material.CHAIN_COMMAND_BLOCK);
|
||||
ItemMeta chainCmdBlockItemMeta = chainCmdBlock.getItemMeta();
|
||||
lore.clear();
|
||||
lore.add(ChatColor.YELLOW + "The player is granted operator for this command only.");
|
||||
lore.add("");
|
||||
lore.add(ChatColor.RED + "THIS IS DISCOURAGED FOR SECURITY REASONS");
|
||||
lore.add(ChatColor.RED + "ONLY USE IF CONSOLE COMMAND CANNOT BE USED.");
|
||||
chainCmdBlockItemMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Player Command with Permissions");
|
||||
chainCmdBlockItemMeta.setLore(lore);
|
||||
chainCmdBlock.setItemMeta(chainCmdBlockItemMeta);
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Console Command");
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.CONSOLE_COMMAND)) {
|
||||
choiceInv.setItem(20, head);
|
||||
choiceInv.setItem(22, chainCmdBlock);
|
||||
choiceInv.setItem(24, cmdBlock);
|
||||
choiceInv.setItem(21, head);
|
||||
choiceInv.setItem(23, cmdBlock);
|
||||
} else {
|
||||
choiceInv.setItem(22, head);
|
||||
}
|
||||
@@ -170,58 +170,32 @@ public class CommandsMenu {
|
||||
p.openInventory(choiceInv);
|
||||
}
|
||||
|
||||
public void deleteCommand(String cmd) {
|
||||
SignCommand found = null;
|
||||
for (SignCommand c : sign.getConsoleCommands()) {
|
||||
if (c.getCommand().equals(cmd)) {
|
||||
found = c;
|
||||
SudoSigns.config.deleteCommandFromConfig(sign, c, PlayerInput.CONSOLE_COMMAND);
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
sign.deleteConsoleCommand(found);
|
||||
}
|
||||
found = null;
|
||||
for (Map.Entry<SignCommand, Boolean> entry : sign.getPlayerCommands().entrySet()) {
|
||||
SignCommand command = entry.getKey();
|
||||
if (command.getCommand().equals(cmd.replace("/", ""))) {
|
||||
found = command;
|
||||
if (entry.getValue()) {
|
||||
SudoSigns.config.deleteCommandFromConfig(sign, command, PlayerInput.PLAYER_COMMAND_WITH_PERMISSIONS);
|
||||
} else {
|
||||
SudoSigns.config.deleteCommandFromConfig(sign, command, PlayerInput.PLAYER_COMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
sign.deletePlayerCommand(found);
|
||||
}
|
||||
goToCommandsMenu();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void addCommand(String cmd, PlayerInput type) {
|
||||
SignCommand command = new SignCommand(cmd, type);
|
||||
SignCommand command = new SignCommand(sign.getNextCommandNumber(), cmd, 0, type);
|
||||
switch (type) {
|
||||
case CONSOLE_COMMAND:
|
||||
sign.addConsoleCommand(command);
|
||||
break;
|
||||
case PLAYER_COMMAND:
|
||||
sign.addPlayerCommand(command, false);
|
||||
break;
|
||||
case PLAYER_COMMAND_WITH_PERMISSIONS:
|
||||
sign.addPlayerCommand(command, true);
|
||||
sign.addPlayerCommand(command);
|
||||
break;
|
||||
}
|
||||
SudoSigns.config.addCommandToConfig(sign, command, type);
|
||||
SudoSigns.config.addCommand(sign, command, type);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Command added successfully!", null);
|
||||
goToCommandsMenu();
|
||||
editor.goToCommands();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,4 +7,6 @@ public enum GUIPage {
|
||||
CHOOSE_PERMISSION,
|
||||
CHOOSE_COMMAND,
|
||||
MESSAGES,
|
||||
COMMAND_OPTIONS,
|
||||
MESSAGE_OPTIONS
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -22,6 +25,7 @@ public class MainMenu {
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private Player p;
|
||||
private int lineNumber = 0;
|
||||
|
||||
public MainMenu(Player p, SudoSign sign, SignEditor editor) {
|
||||
this.sign = sign;
|
||||
@@ -32,8 +36,6 @@ public class MainMenu {
|
||||
public void goToMainMenu() {
|
||||
createMainMenu();
|
||||
p.openInventory(menu);
|
||||
editor.setCurrentPage(PAGE);
|
||||
|
||||
}
|
||||
|
||||
private void createMainMenu() {
|
||||
@@ -43,9 +45,17 @@ public class MainMenu {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
if (p.hasPermission(Permissions.RENAME)) {
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemStack nametag = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta ntMeta = nametag.getItemMeta();
|
||||
ntMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Rename Sign");
|
||||
nametag.setItemMeta(ntMeta);
|
||||
items.add(nametag);
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.EDIT_TEXT)) {
|
||||
ItemStack book = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Rename Sign");
|
||||
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Edit Sign Text");
|
||||
book.setItemMeta(bookMeta);
|
||||
items.add(book);
|
||||
}
|
||||
@@ -53,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");
|
||||
@@ -70,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);
|
||||
}
|
||||
@@ -83,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.");
|
||||
@@ -92,7 +102,47 @@ public class MainMenu {
|
||||
items.add(signBlock);
|
||||
}
|
||||
|
||||
if (SudoSigns.econ != null) {
|
||||
if (p.hasPermission(Permissions.VIEW_PRICE)) {
|
||||
if (SudoSigns.econ != null) {
|
||||
ItemStack goldNugget = new ItemStack(Material.GOLD_NUGGET);
|
||||
ItemMeta goldNuggetItemMeta = goldNugget.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.YELLOW + "Set the price to use this sign.");
|
||||
lore.add(ChatColor.YELLOW + "");
|
||||
if (sign.getPrice() == 1.0) {
|
||||
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Price: " + ChatColor.GRAY + SudoSigns.econ.currencyNameSingular() + ChatColor.RED + sign.getPrice());
|
||||
} else {
|
||||
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 + ChatColor.BOLD + "Price");
|
||||
goldNugget.setItemMeta(goldNuggetItemMeta);
|
||||
items.add(goldNugget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (items.size()) {
|
||||
case 6:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
menu.setItem(31, items.get(4));
|
||||
menu.setItem(33, items.get(5));
|
||||
case 5:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
menu.setItem(31, items.get(4));
|
||||
case 4:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
@@ -113,4 +163,32 @@ public class MainMenu {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void prepareSetPrice() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the price to use the sign! Type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + " to cancel.");
|
||||
SudoSigns.users.get(p.getUniqueId()).addTextInput(PlayerInput.SET_PRICE);
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
sign.setPrice(price);
|
||||
SudoSigns.config.setPrice(sign.getName(), price);
|
||||
if (sign.getPrice() == 1.0) {
|
||||
p.sendMessage(Util.prefix + ChatColor.GREEN + " The price of " + ChatColor.GRAY + sign.getName() + " has been set to: " + ChatColor.GOLD + SudoSigns.econ.currencyNameSingular() + price + ChatColor.GREEN + ".");
|
||||
} else {
|
||||
p.sendMessage(Util.prefix + ChatColor.GREEN + " The price of " + ChatColor.GRAY + sign.getName() + " has been set to: " + ChatColor.GOLD + SudoSigns.econ.currencyNamePlural() + price + ChatColor.GREEN + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public void setLineNumber(int lineNumber) {
|
||||
this.lineNumber = lineNumber;
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the new text (maximum 15 characters), using " + ChatColor.GOLD + "& " + ChatColor.GRAY + "for colour codes. Type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + " to cancel.");
|
||||
SudoSigns.users.get(p.getUniqueId()).addTextInput(PlayerInput.EDIT_TEXT);
|
||||
}
|
||||
|
||||
public void setText(String message) {
|
||||
p.sendMessage(Util.prefix + ChatColor.GREEN + " Line " + lineNumber + " has been set to: " + ChatColor.translateAlternateColorCodes('&', message));
|
||||
sign.editLine(lineNumber-1, message);
|
||||
SudoSigns.config.editSignText(sign.getName(), lineNumber, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.*;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
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.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageOptionsMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private SignMessage sm;
|
||||
private Player p;
|
||||
private SignEditor editor;
|
||||
|
||||
MessageOptionsMenu(SudoUser su, Player p, SudoSign sign, ItemStack item, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
this.editor = editor;
|
||||
this.sm = findSignMessage(item);
|
||||
if (this.sm == null) {
|
||||
editor.goToMessages();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void goToMessageOptionsMenu() {
|
||||
createMessageOptionsMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
private SignMessage findSignMessage(ItemStack item) {
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "message-number");
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(key, PersistentDataType.INTEGER)) {
|
||||
int foundValue = container.get(key, PersistentDataType.INTEGER);
|
||||
return sign.getSignMessageByNumber(foundValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void createMessageOptionsMenu() {
|
||||
menu = Bukkit.createInventory(p, 45, "Message options");
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack clock = new ItemStack(Material.CLOCK);
|
||||
ItemMeta clockMeta = clock.getItemMeta();
|
||||
lore.add(ChatColor.YELLOW + "Change the delay after which the message is sent");
|
||||
clockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Change Delay");
|
||||
clockMeta.setLore(lore);
|
||||
clock.setItemMeta(clockMeta);
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.RED + "Delete Message");
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS) && p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
menu.setItem(20, clock);
|
||||
menu.setItem(24, barrier);
|
||||
} else {
|
||||
menu.setItem(22, clock);
|
||||
}
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
public void addDelay() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the delay in seconds. To cancel, type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.MESSAGE_DELAY);
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
double oldDelay = sm.getDelay();
|
||||
sm.setDelay(delay * 1000);
|
||||
SudoSigns.config.deleteMessage(sign, sm, oldDelay);
|
||||
SudoSigns.config.addMessage(sign, sm);
|
||||
}
|
||||
|
||||
public void deleteMessage() {
|
||||
sign.removeMessage(sm);
|
||||
SudoSigns.config.deleteMessage(sign, sm, sm.getDelay());
|
||||
// if (message.equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', m))) {
|
||||
editor.goToMessages();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.data.*;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
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.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessagesMenu {
|
||||
|
||||
@@ -38,7 +39,6 @@ public class MessagesMenu {
|
||||
public void goToMessagesMenu() {
|
||||
createMessagesMenu();
|
||||
p.openInventory(menu);
|
||||
editor.setCurrentPage(PAGE);
|
||||
}
|
||||
|
||||
private void createMessagesMenu() {
|
||||
@@ -70,18 +70,28 @@ public class MessagesMenu {
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "message-number");
|
||||
|
||||
ArrayList<SignMessage> orderedSignMessages = sign.getMessages();
|
||||
orderedSignMessages.sort(Comparator.comparing(SignMessage::getDelay));
|
||||
|
||||
int i = 1;
|
||||
for (String message : sign.getMessages()) {
|
||||
for (SignMessage sm : orderedSignMessages) {
|
||||
if (i > 35) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
if (p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
bookMeta.setDisplayName(ChatColor.RED + "Click to delete!");
|
||||
} else {
|
||||
bookMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Message:");
|
||||
}
|
||||
lore.clear();
|
||||
lore.add("" + ChatColor.RESET + ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', 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 + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sm.getDelay() / 1000) + "s");
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GREEN + "Click for options!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sm.getNumber());
|
||||
bookMeta.setLore(lore);
|
||||
book.setItemMeta(bookMeta);
|
||||
if (i == 9 || i == 18 || i == 27) i++;
|
||||
@@ -97,26 +107,22 @@ public class MessagesMenu {
|
||||
}
|
||||
|
||||
public void addMessage(String message) {
|
||||
SudoSigns.config.addMessageToConfig(sign, message);
|
||||
sign.addMessage(message);
|
||||
SignMessage signMessage = new SignMessage(sign.getNextMessageNumber(), message, 0, PlayerInput.MESSAGE);
|
||||
SudoSigns.config.addMessage(sign, signMessage);
|
||||
sign.addMessage(signMessage);
|
||||
}
|
||||
|
||||
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 + ".");
|
||||
su.addTextInput(PlayerInput.MESSAGE);
|
||||
}
|
||||
|
||||
public void deleteMessage(String message) {
|
||||
String found = null;
|
||||
for (String m : sign.getMessages()) {
|
||||
if (message.equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', m))) {
|
||||
found = m;
|
||||
}
|
||||
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.");
|
||||
}
|
||||
sign.removeMessage(found);
|
||||
SudoSigns.config.deleteMessageFromConfig(sign, found);
|
||||
goToMessagesMenu();
|
||||
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;
|
||||
@@ -46,6 +48,7 @@ public class PermissionsMenu {
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
@@ -64,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);
|
||||
@@ -127,10 +134,10 @@ public class PermissionsMenu {
|
||||
if (provided) {
|
||||
if (perm == null) {
|
||||
sign.addPermission("sudosigns.sign." + sign.getName());
|
||||
SudoSigns.config.addPermissionToConfig(sign, "sudosigns.sign." + sign.getName());
|
||||
SudoSigns.config.addPermission(sign, "sudosigns.sign." + sign.getName());
|
||||
goToPermissionsMenu();
|
||||
} else {
|
||||
SudoSigns.config.addPermissionToConfig(sign, perm);
|
||||
SudoSigns.config.addPermission(sign, perm);
|
||||
sign.addPermission(perm);
|
||||
}
|
||||
} else {
|
||||
@@ -142,7 +149,7 @@ public class PermissionsMenu {
|
||||
|
||||
public void deletePermission(String perm) {
|
||||
sign.removePermission(perm);
|
||||
SudoSigns.config.deletePermissionFromConfig(sign, perm);
|
||||
SudoSigns.config.deletePermission(sign, perm);
|
||||
goToPermissionsMenu();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@ public class SignEditor {
|
||||
private MainMenu mainMenu;
|
||||
private PermissionsMenu permMenu;
|
||||
private CommandsMenu commandsMenu;
|
||||
private CommandOptionsMenu commandOptionsMenu;
|
||||
private MessageOptionsMenu messageOptionsMenu;
|
||||
private MessagesMenu messagesMenu;
|
||||
private GUIPage currentPage;
|
||||
private boolean edited = false;
|
||||
|
||||
public SignEditor(Player p, SudoSign s, SudoUser su) {
|
||||
this.su = su;
|
||||
@@ -45,29 +48,44 @@ public class SignEditor {
|
||||
|
||||
public void setCurrentPage(GUIPage page) {
|
||||
currentPage = page;
|
||||
|
||||
}
|
||||
|
||||
public void goToMain() {
|
||||
if (mainMenu == null) mainMenu = new MainMenu(p, sign, this);
|
||||
setCurrentPage(GUIPage.MAIN);
|
||||
mainMenu.goToMainMenu();
|
||||
}
|
||||
|
||||
public void goToPermissions() {
|
||||
if (permMenu == null) permMenu = new PermissionsMenu(su, p, sign, this);
|
||||
setCurrentPage(GUIPage.PERMISSIONS);
|
||||
permMenu.goToPermissionsMenu();
|
||||
}
|
||||
|
||||
public void goToCommands() {
|
||||
if (commandsMenu == null) commandsMenu = new CommandsMenu(su, p, sign, this);
|
||||
setCurrentPage(GUIPage.COMMANDS);
|
||||
commandsMenu.goToCommandsMenu();
|
||||
}
|
||||
|
||||
public void goToMessages() {
|
||||
if (messagesMenu == null) messagesMenu = new MessagesMenu(su, p, sign, this);
|
||||
setCurrentPage(GUIPage.MESSAGES);
|
||||
messagesMenu.goToMessagesMenu();
|
||||
}
|
||||
|
||||
public void goToCommandOptionsMenu(ItemStack item) {
|
||||
commandOptionsMenu = new CommandOptionsMenu(su, p, sign, item, this);
|
||||
setCurrentPage(GUIPage.COMMAND_OPTIONS);
|
||||
commandOptionsMenu.goToCommandOptionsMenu();
|
||||
}
|
||||
|
||||
public void goToMessageOptionsMenu(ItemStack item) {
|
||||
messageOptionsMenu = new MessageOptionsMenu(su, p, sign, item, this);
|
||||
setCurrentPage(GUIPage.MESSAGE_OPTIONS);
|
||||
messageOptionsMenu.goToMessageOptionsMenu();
|
||||
}
|
||||
|
||||
public MainMenu getMainMenu() {
|
||||
return mainMenu;
|
||||
}
|
||||
@@ -80,17 +98,29 @@ public class SignEditor {
|
||||
return commandsMenu;
|
||||
}
|
||||
|
||||
public CommandOptionsMenu getCommandOptionsMenu() {
|
||||
return commandOptionsMenu;
|
||||
}
|
||||
|
||||
public MessagesMenu getMessagesMenu() {
|
||||
return messagesMenu;
|
||||
}
|
||||
|
||||
public MessageOptionsMenu getMessageOptionsMenu() {
|
||||
return messageOptionsMenu;
|
||||
}
|
||||
|
||||
|
||||
public void endEditor() {
|
||||
//TODO: Find out whether they actually edited the sign
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Changes saved to sign %NAME%.", sign.getName());
|
||||
}
|
||||
|
||||
|
||||
public void editSignText() {
|
||||
//TODO: Add editing of sign text.
|
||||
public void editSignNumber() {
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the line you'd like to edit (1-4) or type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.EDIT_TEXT_NUMBER);
|
||||
p.closeInventory();
|
||||
}
|
||||
|
||||
public void prepareRename() {
|
||||
@@ -114,7 +144,7 @@ public class SignEditor {
|
||||
SudoSigns.signs.remove(found.getKey());
|
||||
SudoSigns.signs.put(s, sign);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Sign successfully renamed to %NAME%.", s);
|
||||
SudoSigns.config.saveToFile(found.getValue(), true, p);
|
||||
SudoSigns.config.saveSign(found.getValue(), true, p);
|
||||
SudoSigns.config.deleteSign(found.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,16 @@ public final class Permissions {
|
||||
public static final String ADD_COMMAND = "sudosigns.command.add";
|
||||
public static final String DELETE_COMMAND = "sudosigns.command.delete";
|
||||
public static final String CONSOLE_COMMAND = "sudosigns.command.console";
|
||||
public static final String COMMAND_OPTIONS = "sudosigns.command.options";
|
||||
public static final String VIEW_PERMISSION = "sudosigns.permission.view";
|
||||
public static final String ADD_PERMISSION = "sudosigns.permission.add";
|
||||
public static final String DELETE_PERMISSION = "sudosigns.permission.delete";
|
||||
public static final String VIEW_MESSAGE = "sudosigns.message.view";
|
||||
public static final String ADD_MESSAGE = "sudosigns.message.add";
|
||||
public static final String DELETE_MESSAGE = "sudosigns.message.delete";
|
||||
public static final String MESSAGE_OPTIONS = "sudosigns.message.options";
|
||||
public static final String EDIT_TEXT = "sudosigns.text.edit";
|
||||
public static final String VIEW_PRICE = "sudosigns.price.view";
|
||||
public static final String SET_PRICE = "sudosigns.price.set";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dev.mylesmor.sudosigns.util;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(final Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
this.plugin.getLogger().info("Unable to look for updates: " + exception.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
name: SudoSigns
|
||||
version: 1.0
|
||||
version: 1.1.1
|
||||
author: MylesMor
|
||||
main: dev.mylesmor.sudosigns.SudoSigns
|
||||
softdepend: [Multiverse-Core, Vault, PlaceholderAPI]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
sudosigns:
|
||||
|
||||
Reference in new issue
Block a user