The core update.

This commit is contained in:
Brianna 2019-10-19 13:29:46 -04:00
parent b54280abf0
commit 855926936c
67 changed files with 593 additions and 2781 deletions

20
pom.xml
View File

@ -32,7 +32,7 @@
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet> <artifactSet>
<includes> <includes>
<include>com.songoda:songodaupdater</include> <include>com.songoda:SongodaCore</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -45,6 +45,12 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<relocations>
<relocation>
<pattern>com.songoda.core</pattern>
<shadedPattern>${project.groupId}.ultimatemoderation.core</shadedPattern>
</relocation>
</relocations>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@ -61,17 +67,13 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.14</version> <version>1.14.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>songodaupdater</artifactId> <artifactId>SongodaCore</artifactId>
<version>1</version> <version>LATEST</version>
</dependency> <scope>compile</scope>
<dependency>
<groupId>net.milkbowl</groupId>
<artifactId>vault</artifactId>
<version>1.7.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,6 +1,13 @@
package com.songoda.ultimatemoderation; package com.songoda.ultimatemoderation;
import com.songoda.ultimatemoderation.command.CommandManager; import com.songoda.core.SongodaCore;
import com.songoda.core.SongodaPlugin;
import com.songoda.core.commands.CommandManager;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.configuration.Config;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatemoderation.commands.*;
import com.songoda.ultimatemoderation.listeners.*; import com.songoda.ultimatemoderation.listeners.*;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote; import com.songoda.ultimatemoderation.punish.PunishmentNote;
@ -9,10 +16,10 @@ import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import com.songoda.ultimatemoderation.punish.player.PunishmentManager; import com.songoda.ultimatemoderation.punish.player.PunishmentManager;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.punish.template.TemplateManager; import com.songoda.ultimatemoderation.punish.template.TemplateManager;
import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.staffchat.StaffChatManager; import com.songoda.ultimatemoderation.staffchat.StaffChatManager;
import com.songoda.ultimatemoderation.storage.Storage; import com.songoda.ultimatemoderation.storage.Storage;
import com.songoda.ultimatemoderation.storage.StorageRow; import com.songoda.ultimatemoderation.storage.StorageRow;
import com.songoda.ultimatemoderation.storage.types.StorageMysql;
import com.songoda.ultimatemoderation.storage.types.StorageYaml; import com.songoda.ultimatemoderation.storage.types.StorageYaml;
import com.songoda.ultimatemoderation.tasks.SlowModeTask; import com.songoda.ultimatemoderation.tasks.SlowModeTask;
import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.Ticket;
@ -20,71 +27,80 @@ import com.songoda.ultimatemoderation.tickets.TicketManager;
import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.tickets.TicketStatus;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.Metrics;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import com.songoda.ultimatemoderation.utils.locale.Locale;
import com.songoda.ultimatemoderation.utils.settings.Setting;
import com.songoda.ultimatemoderation.utils.settings.SettingsManager;
import com.songoda.ultimatemoderation.utils.updateModules.LocaleModule;
import com.songoda.update.Plugin;
import com.songoda.update.SongodaUpdate;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class UltimateModeration extends JavaPlugin { public class UltimateModeration extends SongodaPlugin {
private static CommandSender console = Bukkit.getConsoleSender();
private static UltimateModeration INSTANCE; private static UltimateModeration INSTANCE;
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); private final GuiManager guiManager = new GuiManager(this);
private TicketManager ticketManager; private TicketManager ticketManager;
private TemplateManager templateManager; private TemplateManager templateManager;
private SettingsManager settingsManager;
private CommandManager commandManager; private CommandManager commandManager;
private PunishmentManager punishmentManager; private PunishmentManager punishmentManager;
private StaffChatManager staffChatManager; private StaffChatManager staffChatManager;
private Locale locale;
private Storage storage; private Storage storage;
private Permission perms = null;
public static UltimateModeration getInstance() { public static UltimateModeration getInstance() {
return INSTANCE; return INSTANCE;
} }
@Override @Override
public void onEnable() { public void onPluginLoad() {
INSTANCE = this; INSTANCE = this;
}
console.sendMessage(Methods.formatText("&a=============================")); @Override
console.sendMessage(Methods.formatText("&7UltimateModeration " + this.getDescription().getVersion() + " by &5Songoda <3!")); public void onPluginDisable() {
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); storage.doSave();
this.storage.closeConnection();
}
this.settingsManager = new SettingsManager(this); @Override
this.settingsManager.setupConfig(); public void onPluginEnable() {
// Run Songoda Updater
SongodaCore.registerPlugin(this, 29, CompatibleMaterial.DIAMOND_CHESTPLATE);
// Setup language // Setup Config
String langMode = Setting.LANGUGE_MODE.getString(); Settings.setupConfig();
locale = new Locale(this, "en_US"); this.setLocale(Settings.LANGUGE_MODE.getString(), false);
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
//Running Songoda Updater // Register commands
Plugin plugin = new Plugin(this, 29); this.commandManager = new CommandManager(this);
plugin.addModule(new LocaleModule()); this.commandManager.addCommand(new CommandUltimateModeration(this))
SongodaUpdate.load(plugin); .addSubCommands(
new CommandReload(this),
new CommandSettings(this, guiManager),
new CommandHelp(this)
);
this.commandManager.addCommand(new CommandBan(this));
this.commandManager.addCommand(new CommandClearChat(this));
this.commandManager.addCommand(new CommandCommandSpy(this));
this.commandManager.addCommand(new CommandFreeze(this));
this.commandManager.addCommand(new CommandInvSee(this));
this.commandManager.addCommand(new CommandKick(this));
this.commandManager.addCommand(new CommandMute(this));
this.commandManager.addCommand(new CommandRandomPlayer(this));
this.commandManager.addCommand(new CommandRevive(this));
this.commandManager.addCommand(new CommandRunTemplate(this));
this.commandManager.addCommand(new CommandSlowMode(this));
this.commandManager.addCommand(new CommandSpy(this));
this.commandManager.addCommand(new CommandStaffChat(this));
this.commandManager.addCommand(new CommandTicket(this));
this.commandManager.addCommand(new CommandToggleChat(this));
this.commandManager.addCommand(new CommandUnBan(this));
this.commandManager.addCommand(new CommandUnMute(this));
this.commandManager.addCommand(new CommandVanish(this));
this.commandManager.addCommand(new CommandViewEnderChest(this));
this.commandManager.addCommand(new CommandWarn(this));
// Setup Managers // Setup Managers
this.ticketManager = new TicketManager(); this.ticketManager = new TicketManager();
this.templateManager = new TemplateManager(); this.templateManager = new TemplateManager();
this.commandManager = new CommandManager(this);
this.punishmentManager = new PunishmentManager(); this.punishmentManager = new PunishmentManager();
this.staffChatManager = new StaffChatManager(); this.staffChatManager = new StaffChatManager();
@ -93,6 +109,7 @@ public class UltimateModeration extends JavaPlugin {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, this::loadFromFile, 1L); Bukkit.getScheduler().scheduleSyncDelayedTask(this, this::loadFromFile, 1L);
// Register Listeners // Register Listeners
guiManager.init();
AbstractGUI.initializeListeners(this); AbstractGUI.initializeListeners(this);
Bukkit.getPluginManager().registerEvents(new CommandListener(this), this); Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
Bukkit.getPluginManager().registerEvents(new DeathListener(this), this); Bukkit.getPluginManager().registerEvents(new DeathListener(this), this);
@ -103,40 +120,18 @@ public class UltimateModeration extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new LoginListener(this), this); Bukkit.getPluginManager().registerEvents(new LoginListener(this), this);
Bukkit.getPluginManager().registerEvents(new MobTargetLister(), this); Bukkit.getPluginManager().registerEvents(new MobTargetLister(), this);
if (isServerVersionAtLeast(ServerVersion.V1_13)) Bukkit.getPluginManager().registerEvents(new SpyingDismountListener(), this); if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
Bukkit.getPluginManager().registerEvents(new SpyingDismountListener(), this);
// Start tasks // Start tasks
SlowModeTask.startTask(this); SlowModeTask.startTask(this);
// Starting Metrics int timeout = Settings.AUTOSAVE.getInt() * 60 * 20;
new Metrics(this);
if (getServer().getPluginManager().getPlugin("Vault") != null) {
setupPermissions();
console.sendMessage("Hooked Vault.");
}
int timeout = Setting.AUTOSAVE.getInt() * 60 * 20;
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> storage.doSave(), timeout, timeout); Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> storage.doSave(), timeout, timeout);
console.sendMessage(Methods.formatText("&a============================="));
}
@Override
public void onDisable() {
storage.doSave();
this.storage.closeConnection();
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7UltimateModeration " + this.getDescription().getVersion() + " by &5Songoda <3!"));
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Methods.formatText("&a============================="));
} }
private void checkStorage() { private void checkStorage() {
if (getConfig().getBoolean("Database.Activate Mysql Support")) { this.storage = new StorageYaml(this);
this.storage = new StorageMysql(this);
} else {
this.storage = new StorageYaml(this);
}
} }
private void loadFromFile() { private void loadFromFile() {
@ -201,8 +196,8 @@ public class UltimateModeration extends JavaPlugin {
int id = row.get("ticketid").asInt(); int id = row.get("ticketid").asInt();
TicketResponse ticketResponse = new TicketResponse( TicketResponse ticketResponse = new TicketResponse(
UUID.fromString(row.get("author").asString()), UUID.fromString(row.get("author").asString()),
row.get("message").asString(), row.get("message").asString(),
row.get("posted").asLong()); row.get("posted").asLong());
ticketResponse.setTicketId(id); ticketResponse.setTicketId(id);
ticketManager.getTicket(id).addResponse(ticketResponse); ticketManager.getTicket(id).addResponse(ticketResponse);
@ -211,45 +206,21 @@ public class UltimateModeration extends JavaPlugin {
storage.doSave(); storage.doSave();
} }
private boolean setupPermissions() { @Override
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class); public void onConfigReload() {
perms = rsp.getProvider(); this.setLocale(getConfig().getString("System.Language Mode"), true);
return perms != null;
}
public ServerVersion getServerVersion() {
return serverVersion;
}
public boolean isServerVersion(ServerVersion version) {
return serverVersion == version;
}
public boolean isServerVersion(ServerVersion... versions) {
return ArrayUtils.contains(versions, serverVersion);
}
public boolean isServerVersionAtLeast(ServerVersion version) {
return serverVersion.ordinal() >= version.ordinal();
}
public void reload() {
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
this.locale.reloadMessages(); this.locale.reloadMessages();
this.settingsManager.reloadConfig(); }
@Override
public List<Config> getExtraConfig() {
return null;
} }
public CommandManager getCommandManager() { public CommandManager getCommandManager() {
return commandManager; return commandManager;
} }
public SettingsManager getSettingsManager() {
return settingsManager;
}
public Locale getLocale() {
return locale;
}
public TemplateManager getTemplateManager() { public TemplateManager getTemplateManager() {
return templateManager; return templateManager;
} }
@ -265,8 +236,4 @@ public class UltimateModeration extends JavaPlugin {
public StaffChatManager getStaffChatManager() { public StaffChatManager getStaffChatManager() {
return staffChatManager; return staffChatManager;
} }
public Permission getPerms() {
return perms;
}
} }

View File

@ -1,71 +0,0 @@
package com.songoda.ultimatemoderation.command;
import com.songoda.ultimatemoderation.UltimateModeration;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class AbstractCommand {
private final boolean noConsole;
private AbstractCommand parent = null;
private boolean hasArgs = false;
private String command;
private List<String> subCommand = new ArrayList<>();
protected AbstractCommand(AbstractCommand parent, boolean noConsole, String... command) {
if (parent != null) {
this.subCommand = Arrays.asList(command);
} else {
this.command = Arrays.asList(command).get(0);
}
this.parent = parent;
this.noConsole = noConsole;
}
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
this.command = Arrays.asList(command).get(0);
this.hasArgs = hasArgs;
this.noConsole = noConsole;
}
public AbstractCommand getParent() {
return parent;
}
public String getCommand() {
return command;
}
public List<String> getSubCommand() {
return subCommand;
}
public void addSubCommand(String command) {
subCommand.add(command);
}
protected abstract ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args);
protected abstract List<String> onTab(UltimateModeration instance, CommandSender sender, String... args);
public abstract String getPermissionNode();
public abstract String getSyntax();
public abstract String getDescription();
public boolean hasArgs() {
return hasArgs;
}
public boolean isNoConsole() {
return noConsole;
}
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
}

View File

@ -1,127 +0,0 @@
package com.songoda.ultimatemoderation.command;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.*;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CommandManager implements CommandExecutor {
private UltimateModeration instance;
private TabManager tabManager;
private List<AbstractCommand> commands = new ArrayList<>();
public CommandManager(UltimateModeration instance) {
this.instance = instance;
this.tabManager = new TabManager(this);
instance.getCommand("UltimateModeration").setExecutor(this);
instance.getCommand("ClearChat").setExecutor(this);
instance.getCommand("ToggleChat").setExecutor(this);
instance.getCommand("RandomPlayer").setExecutor(this);
instance.getCommand("Vanish").setExecutor(this);
instance.getCommand("ViewEnderChest").setExecutor(this);
instance.getCommand("InvSee").setExecutor(this);
instance.getCommand("Freeze").setExecutor(this);
instance.getCommand("Revive").setExecutor(this);
instance.getCommand("Spy").setExecutor(this);
instance.getCommand("CommandSpy").setExecutor(this);
instance.getCommand("Ban").setExecutor(this);
instance.getCommand("UnBan").setExecutor(this);
instance.getCommand("Kick").setExecutor(this);
instance.getCommand("Mute").setExecutor(this);
instance.getCommand("UnMute").setExecutor(this);
instance.getCommand("Warn").setExecutor(this);
instance.getCommand("RunTemplate").setExecutor(this);
instance.getCommand("Ticket").setExecutor(this);
instance.getCommand("StaffChat").setExecutor(this);
instance.getCommand("SlowMode").setExecutor(this);
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
addCommand(new CommandClearChat());
addCommand(new CommandToggleChat());
addCommand(new CommandRandomPlayer());
addCommand(new CommandVanish());
addCommand(new CommandViewEnderChest());
addCommand(new CommandInvSee());
addCommand(new CommandFreeze());
addCommand(new CommandRevive());
addCommand(new CommandSpy());
addCommand(new CommandCommandSpy());
addCommand(new CommandBan());
addCommand(new CommandUnBan());
addCommand(new CommandKick());
addCommand(new CommandMute());
addCommand(new CommandUnMute());
addCommand(new CommandWarn());
addCommand(new CommandRunTemplate());
addCommand(new CommandTicket());
addCommand(new CommandStaffChat());
addCommand(new CommandSlowMode());
addCommand(new CommandSettings(commandUltimateModeration));
addCommand(new CommandHelp(commandUltimateModeration));
addCommand(new CommandReload(commandUltimateModeration));
for (AbstractCommand abstractCommand : commands) {
if (abstractCommand.getParent() != null) continue;
instance.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager);
}
}
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
commands.add(abstractCommand);
return abstractCommand;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
for (AbstractCommand abstractCommand : commands) {
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
if (strings.length == 0 || abstractCommand.hasArgs()) {
processRequirements(abstractCommand, commandSender, strings);
return true;
}
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
String cmd = strings[0];
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
for (String cmds : abstractCommand.getSubCommand()) {
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
processRequirements(abstractCommand, commandSender, strings);
return true;
}
}
}
}
instance.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
return true;
}
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
if (!(sender instanceof Player) && command.isNoConsole()) {
sender.sendMessage("You must be a player to use this command.");
return;
}
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
instance.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
instance.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
}
return;
}
instance.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
}
public List<AbstractCommand> getCommands() {
return Collections.unmodifiableList(commands);
}
}

View File

@ -1,63 +0,0 @@
package com.songoda.ultimatemoderation.command;
import com.songoda.ultimatemoderation.UltimateModeration;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
public class TabManager implements TabCompleter {
private final CommandManager commandManager;
TabManager(CommandManager commandManager) {
this.commandManager = commandManager;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] strings) {
for (AbstractCommand abstractCommand : commandManager.getCommands()) {
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName()) && !abstractCommand.hasArgs()) {
if (strings.length == 1) {
List<String> subs = new ArrayList<>();
for (AbstractCommand ac : commandManager.getCommands()) {
if (ac.getSubCommand() == null) continue;
subs.addAll(ac.getSubCommand());
}
subs.removeIf(s -> !s.toLowerCase().startsWith(strings[0].toLowerCase()));
return subs;
}
} else if (strings.length != 0
&& abstractCommand.getCommand() != null
&& abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
String cmd = strings[0];
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
if (abstractCommand.hasArgs()) {
return onCommand(abstractCommand, strings, sender);
} else {
for (String cmds : abstractCommand.getSubCommand()) {
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
return onCommand(abstractCommand, strings, sender);
}
}
}
}
}
return null;
}
private List<String> onCommand(AbstractCommand abstractCommand, String[] strings, CommandSender sender) {
List<String> list = abstractCommand.onTab(UltimateModeration.getInstance(), sender, strings);
String str = strings[strings.length - 1];
if (list != null && str != null && str.length() >= 1) {
try {
list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase()));
} catch (UnsupportedOperationException ignored) {
}
}
return list;
}
}

View File

@ -1,42 +0,0 @@
package com.songoda.ultimatemoderation.command.commands;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandSettings extends AbstractCommand {
public CommandSettings(AbstractCommand parent) {
super(parent, true, "settings");
}
@Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
Player player = (Player) sender;
instance.getSettingsManager().openSettingsManager(player);
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
return null;
}
@Override
public String getPermissionNode() {
return "um.admin";
}
@Override
public String getSyntax() {
return "/um settings";
}
@Override
public String getDescription() {
return "Edit UltimateModeration Settings.";
}
}

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.Punishment; import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
@ -17,12 +17,15 @@ import java.util.List;
public class CommandBan extends AbstractCommand { public class CommandBan extends AbstractCommand {
public CommandBan() { private UltimateModeration instance;
super(false, true, "Ban");
public CommandBan(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "Ban");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 1) if (args.length < 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -50,8 +53,7 @@ public class CommandBan extends AbstractCommand {
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
if (instance.getPerms() != null && sender instanceof Player if (sender instanceof Player && player.getPlayer().hasPermission("um.ban.exempt")) {
&& instance.getPerms().playerHas(Bukkit.getWorlds().get(0).getName(), player, "um.ban.exempt")) {
instance.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender); instance.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
@ -74,7 +76,7 @@ public class CommandBan extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,25 +1,26 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandClearChat extends AbstractCommand { public class CommandClearChat extends AbstractCommand {
public CommandClearChat() { private UltimateModeration instance;
super(true, true, "ClearChat");
public CommandClearChat(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "ClearChat");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 0 && !args[0].equalsIgnoreCase("force")) if (args.length != 0 && !args[0].equalsIgnoreCase("force"))
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -42,7 +43,7 @@ public class CommandClearChat extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
return Collections.singletonList("force"); return Collections.singletonList("force");
} }

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,10 +11,12 @@ import java.util.UUID;
public class CommandCommandSpy extends AbstractCommand { public class CommandCommandSpy extends AbstractCommand {
private UltimateModeration instance;
private static List<UUID> inSpy = new ArrayList<>(); private static List<UUID> inSpy = new ArrayList<>();
public CommandCommandSpy() { public CommandCommandSpy(UltimateModeration instance) {
super(true, false, "CommandSpy"); super(CommandType.CONSOLE_OK, "CommandSpy");
this.instance = instance;
} }
public static boolean isSpying(Player player) { public static boolean isSpying(Player player) {
@ -22,7 +24,7 @@ public class CommandCommandSpy extends AbstractCommand {
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = ((Player) sender); Player player = ((Player) sender);
if (inSpy.contains(player.getUniqueId())) { if (inSpy.contains(player.getUniqueId())) {
@ -36,7 +38,7 @@ public class CommandCommandSpy extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,23 +1,27 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class CommandFreeze extends AbstractCommand { public class CommandFreeze extends AbstractCommand {
private UltimateModeration instance;
private static List<UUID> frozen = new ArrayList<>(); private static List<UUID> frozen = new ArrayList<>();
public CommandFreeze() { public CommandFreeze(UltimateModeration instance) {
super(true, true, "Freeze"); super(CommandType.CONSOLE_OK, "Freeze");
this.instance = instance;
} }
public static void freeze(OfflinePlayer player, Player sender) { public static void freeze(OfflinePlayer player, CommandSender sender) {
UltimateModeration instance = UltimateModeration.getInstance(); UltimateModeration instance = UltimateModeration.getInstance();
if (frozen.contains(player.getUniqueId())) { if (frozen.contains(player.getUniqueId())) {
frozen.remove(player.getUniqueId()); frozen.remove(player.getUniqueId());
@ -37,7 +41,7 @@ public class CommandFreeze extends AbstractCommand {
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -53,13 +57,13 @@ public class CommandFreeze extends AbstractCommand {
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
freeze(player, (Player) sender); freeze(player, sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -9,12 +9,15 @@ import java.util.List;
public class CommandHelp extends AbstractCommand { public class CommandHelp extends AbstractCommand {
public CommandHelp(AbstractCommand parent) { private UltimateModeration instance;
super(parent, false, "help");
public CommandHelp(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "help");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage(""); sender.sendMessage("");
instance.getLocale().getMessage("&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda") instance.getLocale().getMessage("&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda")
.sendPrefixedMessage(sender); .sendPrefixedMessage(sender);
@ -22,7 +25,7 @@ public class CommandHelp extends AbstractCommand {
sender.sendMessage(Methods.formatText("&7Welcome to UltimateModeration! To get started try using the /um command to access the moderation panel.")); sender.sendMessage(Methods.formatText("&7Welcome to UltimateModeration! To get started try using the /um command to access the moderation panel."));
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage(Methods.formatText("&6Commands:")); sender.sendMessage(Methods.formatText("&6Commands:"));
for (AbstractCommand command : instance.getCommandManager().getCommands()) { for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
} }
@ -33,7 +36,7 @@ public class CommandHelp extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,24 +1,25 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandInvSee extends AbstractCommand { public class CommandInvSee extends AbstractCommand {
public CommandInvSee() { private UltimateModeration instance;
super(true, true, "InvSee");
public CommandInvSee(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "InvSee");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -39,7 +40,7 @@ public class CommandInvSee extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,28 +1,29 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.Punishment; import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandKick extends AbstractCommand { public class CommandKick extends AbstractCommand {
public CommandKick() { private UltimateModeration instance;
super(false, true, "Kick");
public CommandKick(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "Kick");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 1) if (args.length < 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -55,7 +56,7 @@ public class CommandKick extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.Punishment; import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
@ -17,12 +17,15 @@ import java.util.List;
public class CommandMute extends AbstractCommand { public class CommandMute extends AbstractCommand {
public CommandMute() { private UltimateModeration instance;
super(false, true, "Mute");
public CommandMute(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "Mute");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 1) if (args.length < 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -68,7 +71,7 @@ public class CommandMute extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,8 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -13,12 +12,15 @@ import java.util.List;
public class CommandRandomPlayer extends AbstractCommand { public class CommandRandomPlayer extends AbstractCommand {
public CommandRandomPlayer() { private UltimateModeration instance;
super(true, false, "RandomPlayer");
public CommandRandomPlayer(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "RandomPlayer");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers()); List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
Collections.shuffle(players); Collections.shuffle(players);
players.remove(sender); players.remove(sender);
@ -33,7 +35,7 @@ public class CommandRandomPlayer extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,27 +1,29 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
public class CommandReload extends AbstractCommand { public class CommandReload extends AbstractCommand {
public CommandReload(AbstractCommand parent) { private UltimateModeration instance;
super(parent, false, "reload");
public CommandReload(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "reload");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
instance.reload(); instance.reloadConfig();
instance.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); instance.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,24 +1,28 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.listeners.DeathListener; import com.songoda.ultimatemoderation.listeners.DeathListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class CommandRevive extends AbstractCommand { public class CommandRevive extends AbstractCommand {
public CommandRevive() { private UltimateModeration instance;
super(true, true, "Revive");
public CommandRevive(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "Revive");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -38,7 +42,7 @@ public class CommandRevive extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,29 +1,27 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandRunTemplate extends AbstractCommand { public class CommandRunTemplate extends AbstractCommand {
public CommandRunTemplate() { private UltimateModeration instance;
super(false, true, "RunTemplate");
public CommandRunTemplate(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "RunTemplate");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2) if (args.length < 2)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -54,7 +52,7 @@ public class CommandRunTemplate extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -0,0 +1,49 @@
package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.configuration.editor.PluginConfigGui;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatemoderation.UltimateModeration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandSettings extends AbstractCommand {
final UltimateModeration instance;
final GuiManager guiManager;
public CommandSettings(UltimateModeration instance, GuiManager manager) {
super(CommandType.PLAYER_ONLY, "settings");
this.instance = instance;
this.guiManager = manager;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
guiManager.showGUI((Player) sender, new PluginConfigGui(instance));
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}
@Override
public String getPermissionNode() {
return "um.admin";
}
@Override
public String getSyntax() {
return "/um settings";
}
@Override
public String getDescription() {
return "Edit UltimateModeration Settings.";
}
}

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.listeners.ChatListener; import com.songoda.ultimatemoderation.listeners.ChatListener;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -13,12 +13,15 @@ import java.util.List;
public class CommandSlowMode extends AbstractCommand { public class CommandSlowMode extends AbstractCommand {
public CommandSlowMode() { private UltimateModeration instance;
super(true, true, "Slowmode");
public CommandSlowMode(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "Slowmode");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length == 0) { if (args.length == 0) {
ChatListener.setSlowModeOverride(0); ChatListener.setSlowModeOverride(0);
instance.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender); instance.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender);
@ -38,7 +41,7 @@ public class CommandSlowMode extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -13,16 +13,19 @@ import java.util.*;
public class CommandSpy extends AbstractCommand { public class CommandSpy extends AbstractCommand {
private UltimateModeration instance;
private static Map<UUID, Spy> spying = new HashMap<>(); private static Map<UUID, Spy> spying = new HashMap<>();
public CommandSpy() { public CommandSpy(UltimateModeration instance) {
super(true, true, "Spy"); super(CommandType.PLAYER_ONLY, "Spy");
this.instance = instance;
} }
public static void spy(OfflinePlayer oPlayer, Player senderP) { public static void spy(OfflinePlayer oPlayer, Player senderP) {
UltimateModeration instance = UltimateModeration.getInstance(); UltimateModeration instance = UltimateModeration.getInstance();
if (!UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) { if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
instance.getLocale().newMessage("This feature is not compatible with this version of spigot.").sendPrefixedMessage(senderP); instance.getLocale().newMessage("This feature is not compatible with this version of spigot.").sendPrefixedMessage(senderP);
return; return;
} }
@ -53,14 +56,14 @@ public class CommandSpy extends AbstractCommand {
instance.getLocale().getMessage("command.spy.success") instance.getLocale().getMessage("command.spy.success")
.processPlaceholder("player", player.getName()).sendPrefixedMessage(senderP); .processPlaceholder("player", player.getName()).sendPrefixedMessage(senderP);
} }
public static boolean isSpying(OfflinePlayer player) { public static boolean isSpying(OfflinePlayer player) {
return spying.containsKey(player.getUniqueId()); return spying.containsKey(player.getUniqueId());
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length > 1) if (args.length > 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -96,7 +99,7 @@ public class CommandSpy extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,8 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.staffchat.StaffChannel; import com.songoda.ultimatemoderation.staffchat.StaffChannel;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,17 +11,20 @@ import java.util.List;
public class CommandStaffChat extends AbstractCommand { public class CommandStaffChat extends AbstractCommand {
public CommandStaffChat() { private UltimateModeration instance;
super(true, true, "StaffChat");
public CommandStaffChat(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "StaffChat");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
String channelName = args[0]; String channelName = args[0];
Player player = (Player)sender; Player player = (Player) sender;
if (channelName.trim().equalsIgnoreCase("leave")) { if (channelName.trim().equalsIgnoreCase("leave")) {
for (StaffChannel channel : instance.getStaffChatManager().getChats().values()) { for (StaffChannel channel : instance.getStaffChatManager().getChats().values()) {
@ -41,7 +43,7 @@ public class CommandStaffChat extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return new ArrayList<>(instance.getStaffChatManager().getChats().keySet()); return new ArrayList<>(instance.getStaffChatManager().getChats().keySet());
} }

View File

@ -1,27 +1,24 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.gui.GUITicketManager; import com.songoda.ultimatemoderation.gui.GUITicketManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID;
public class CommandTicket extends AbstractCommand { public class CommandTicket extends AbstractCommand {
public CommandTicket() { private UltimateModeration instance;
super(true, false, "Ticket");
public CommandTicket(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "Ticket");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
Player senderP = ((Player) sender); Player senderP = ((Player) sender);
new GUITicketManager(instance, senderP, senderP); new GUITicketManager(instance, senderP, senderP);
@ -29,7 +26,7 @@ public class CommandTicket extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,10 +1,9 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.locale.Message;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.listeners.ChatListener; import com.songoda.ultimatemoderation.listeners.ChatListener;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.locale.Message;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -13,17 +12,19 @@ import java.util.List;
public class CommandToggleChat extends AbstractCommand { public class CommandToggleChat extends AbstractCommand {
private UltimateModeration instance;
/* /*
* Chat is enabled by default ;) * Chat is enabled by default ;)
*/ */
private boolean toggled = true; private boolean toggled = true;
public CommandToggleChat() { public CommandToggleChat(UltimateModeration instance) {
super(false, false, "togglechat"); super(CommandType.PLAYER_ONLY, "togglechat");
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
toggled = !toggled; toggled = !toggled;
Message message = toggled ? instance.getLocale().getMessage("command.togglechat.toggledOn") Message message = toggled ? instance.getLocale().getMessage("command.togglechat.toggledOn")
@ -48,7 +49,7 @@ public class CommandToggleChat extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.gui.GUIPlayers; import com.songoda.ultimatemoderation.gui.GUIPlayers;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -10,18 +10,21 @@ import java.util.List;
public class CommandUltimateModeration extends AbstractCommand { public class CommandUltimateModeration extends AbstractCommand {
public CommandUltimateModeration() { private UltimateModeration instance;
super(true, false, "UltimateModeration");
public CommandUltimateModeration(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "UltimateModeration");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
new GUIPlayers(instance, (Player) sender); new GUIPlayers(instance, (Player) sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return null; return null;
} }

View File

@ -1,8 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -11,18 +10,19 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandUnBan extends AbstractCommand { public class CommandUnBan extends AbstractCommand {
public CommandUnBan() { private UltimateModeration instance;
super(false, true, "UnBan");
public CommandUnBan(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "UnBan");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -49,7 +49,7 @@ public class CommandUnBan extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -10,18 +10,19 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandUnMute extends AbstractCommand { public class CommandUnMute extends AbstractCommand {
public CommandUnMute() { private UltimateModeration instance;
super(false, true, "UnMute");
public CommandUnMute(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "UnMute");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -48,7 +49,7 @@ public class CommandUnMute extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,10 +1,9 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand; import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.settings.Setting;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -20,10 +19,13 @@ import java.util.UUID;
public class CommandVanish extends AbstractCommand { public class CommandVanish extends AbstractCommand {
private UltimateModeration instance;
private static List<UUID> inVanish = new ArrayList<>(); private static List<UUID> inVanish = new ArrayList<>();
public CommandVanish() { public CommandVanish(UltimateModeration instance) {
super(true, false, "Vanish"); super(CommandType.PLAYER_ONLY, "Vanish");
this.instance = instance;
} }
public static void registerVanishedPlayers(Player player) { public static void registerVanishedPlayers(Player player) {
@ -45,22 +47,22 @@ public class CommandVanish extends AbstractCommand {
if (inVanish.contains(uuid)) { if (inVanish.contains(uuid)) {
inVanish.remove(uuid); inVanish.remove(uuid);
if (instance.isServerVersionAtLeast(ServerVersion.V1_9)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
player.setInvulnerable(false); player.setInvulnerable(false);
player.setCanPickupItems(true); player.setCanPickupItems(true);
instance.getLocale().getMessage("command.vanish.toggledOff").sendPrefixedMessage(player); instance.getLocale().getMessage("command.vanish.toggledOff").sendPrefixedMessage(player);
} else { } else {
inVanish.add(uuid); inVanish.add(uuid);
player.setCanPickupItems(false); player.setCanPickupItems(false);
if (instance.isServerVersionAtLeast(ServerVersion.V1_9)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
player.setInvulnerable(true); player.setInvulnerable(true);
instance.getLocale().getMessage("command.vanish.toggledOn").sendPrefixedMessage(player); instance.getLocale().getMessage("command.vanish.toggledOn").sendPrefixedMessage(player);
} }
if (Setting.VANISH_EFFECTS.getBoolean()) { if (Settings.VANISH_EFFECTS.getBoolean()) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf(Setting.VANISH_SOUND.getString()), 1L, 1L); player.getWorld().playSound(player.getLocation(), Sound.valueOf(Settings.VANISH_SOUND.getString()), 1L, 1L);
if (Setting.VANISH_BATS.getBoolean()) { if (Settings.VANISH_BATS.getBoolean()) {
List<Entity> entities = new ArrayList<>(); List<Entity> entities = new ArrayList<>();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
entities.add(player.getWorld().spawnEntity(player.getLocation().add(0, 1, 0), EntityType.BAT)); entities.add(player.getWorld().spawnEntity(player.getLocation().add(0, 1, 0), EntityType.BAT));
@ -75,8 +77,8 @@ public class CommandVanish extends AbstractCommand {
float xx = (float) (0 + (Math.random() * 1)); float xx = (float) (0 + (Math.random() * 1));
float yy = (float) (0 + (Math.random() * 2)); float yy = (float) (0 + (Math.random() * 2));
float zz = (float) (0 + (Math.random() * 1)); float zz = (float) (0 + (Math.random() * 1));
if (instance.isServerVersionAtLeast(ServerVersion.V1_12)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12))
player.getWorld().spawnParticle(Particle.valueOf(Setting.VANISH_PARTICLE.getString()), player.getLocation().add(0, 1, 0), 35, xx, yy, zz, 0); player.getWorld().spawnParticle(Particle.valueOf(Settings.VANISH_PARTICLE.getString()), player.getLocation().add(0, 1, 0), 35, xx, yy, zz, 0);
} }
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
@ -97,14 +99,14 @@ public class CommandVanish extends AbstractCommand {
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = ((Player) sender); Player player = ((Player) sender);
vanish(player); vanish(player);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,12 +11,15 @@ import java.util.List;
public class CommandViewEnderChest extends AbstractCommand { public class CommandViewEnderChest extends AbstractCommand {
public CommandViewEnderChest() { private UltimateModeration instance;
super(true, true, "ViewEnderChest");
public CommandViewEnderChest(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "ViewEnderChest");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -38,7 +41,7 @@ public class CommandViewEnderChest extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.command.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.punish.Punishment; import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
@ -17,12 +17,15 @@ import java.util.List;
public class CommandWarn extends AbstractCommand { public class CommandWarn extends AbstractCommand {
public CommandWarn() { private UltimateModeration instance;
super(false, true, "Warn");
public CommandWarn(UltimateModeration instance) {
super(CommandType.CONSOLE_OK, "Warn");
this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 1) if (args.length < 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -50,8 +53,7 @@ public class CommandWarn extends AbstractCommand {
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
if (instance.getPerms() != null && sender instanceof Player if (sender instanceof Player && player.getPlayer().hasPermission("um.warning.exempt")) {
&& instance.getPerms().playerHas(Bukkit.getWorlds().get(0).getName(), player, "um.warning.exempt")) {
instance.getLocale().newMessage("You cannot warn that player.").sendPrefixedMessage(sender); instance.getLocale().newMessage("You cannot warn that player.").sendPrefixedMessage(sender);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
@ -63,7 +65,7 @@ public class CommandWarn extends AbstractCommand {
} }
@Override @Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) { if (args.length == 1) {
List<String> players = new ArrayList<>(); List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,16 +1,15 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze; import com.songoda.ultimatemoderation.commands.CommandFreeze;
import com.songoda.ultimatemoderation.command.commands.CommandRevive; import com.songoda.ultimatemoderation.commands.CommandRevive;
import com.songoda.ultimatemoderation.command.commands.CommandSpy; import com.songoda.ultimatemoderation.commands.CommandSpy;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class GUIModerate extends AbstractGUI { public class GUIModerate extends AbstractGUI {
@ -35,15 +34,15 @@ public class GUIModerate extends AbstractGUI {
@Override @Override
protected void constructGUI() { protected void constructGUI() {
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, CompatibleMaterial.OAK_DOOR.getMaterial(), plugin.getLocale().getMessage("gui.general.back").getMessage());
? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage());
if (freeze) createButton(10, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.BLUE_ICE : Material.valueOf("PACKED_ICE"), "&6&lFreeze", "&7Stop this player from moving.", "", "&7Currently:&6 " + (CommandFreeze.isFrozen(toModerate) ? "Frozen" : "Unfrozen")); if (freeze)
createButton(10, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.BLUE_ICE : Material.valueOf("PACKED_ICE"), "&6&lFreeze", "&7Stop this player from moving.", "", "&7Currently:&6 " + (CommandFreeze.isFrozen(toModerate) ? "Frozen" : "Unfrozen"));
if (spy) createButton(12, Material.SADDLE, "&6&lSpy", "&7Spy on this player"); if (spy) createButton(12, Material.SADDLE, "&6&lSpy", "&7Spy on this player");
if (invsee) createButton(14, Material.CHEST, "&c&lInventory", "&7Access this players Inventory."); if (invsee) createButton(14, Material.CHEST, "&c&lInventory", "&7Access this players Inventory.");
if (enderview) createButton(16, Material.ENDER_CHEST, "&a&lEnderchest", "&7Access this players Enderchest"); if (enderview) createButton(16, Material.ENDER_CHEST, "&a&lEnderchest", "&7Access this players Enderchest");
if (revive) createButton(28, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPLASH_POTION : Material.valueOf("POTION"), "&c&lRevive", "&7Revive this player."); if (revive)
createButton(28, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPLASH_POTION : Material.valueOf("POTION"), "&c&lRevive", "&7Revive this player.");
} }
@Override @Override

View File

@ -1,17 +1,15 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentNote; import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.utils.AbstractChatConfirm; import com.songoda.ultimatemoderation.utils.AbstractChatConfirm;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -47,7 +45,7 @@ public class GUINotesManager extends AbstractGUI {
registerClickables(); registerClickables();
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(9 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
int numNotes = plugin.getPunishmentManager().getPlayer(toModerate).getNotes().size(); int numNotes = plugin.getPunishmentManager().getPlayer(toModerate).getNotes().size();
int maxPage = (int) Math.floor(numNotes / 36.0); int maxPage = (int) Math.floor(numNotes / 36.0);
@ -58,7 +56,7 @@ public class GUINotesManager extends AbstractGUI {
if (page != 0) { if (page != 0) {
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage());
registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { registerClickable(1, ((player1, inventory1, cursor, slot, type) -> {
page --; page--;
constructGUI(); constructGUI();
})); }));
} }
@ -66,12 +64,12 @@ public class GUINotesManager extends AbstractGUI {
if (page != maxPage) { if (page != maxPage) {
createButton(3, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); createButton(3, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage());
registerClickable(3, ((player1, inventory1, cursor, slot, type) -> { registerClickable(3, ((player1, inventory1, cursor, slot, type) -> {
page ++; page++;
constructGUI(); constructGUI();
})); }));
} }
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.OAK_DOOR ? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage());
@ -89,7 +87,7 @@ public class GUINotesManager extends AbstractGUI {
continue; continue;
if (noteStr.charAt(n) == ' ') { if (noteStr.charAt(n) == ' ') {
lore.add("&6" +noteStr.substring(lastIndex, n).trim()); lore.add("&6" + noteStr.substring(lastIndex, n).trim());
lastIndex = n; lastIndex = n;
} }
} }

View File

@ -1,7 +1,8 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -33,9 +34,9 @@ public class GUIPlayer extends AbstractGUI {
@Override @Override
protected void constructGUI() { protected void constructGUI() {
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); ItemStack head = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
SkullMeta meta = ((SkullMeta) head.getItemMeta()); SkullMeta meta = ((SkullMeta) head.getItemMeta());
if (plugin.isServerVersionAtLeast(ServerVersion.V1_13)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
meta.setOwningPlayer(toModerate); meta.setOwningPlayer(toModerate);
else else
meta.setOwner(toModerate.getName()); meta.setOwner(toModerate.getName());
@ -44,16 +45,15 @@ public class GUIPlayer extends AbstractGUI {
createButton(13, head, "&7&l" + toModerate.getName(), createButton(13, head, "&7&l" + toModerate.getName(),
player.isOnline() ? "&a" + plugin.getLocale().getMessage("gui.players.online.online") : "&c" + plugin.getLocale().getMessage("gui.players.online.offline")); player.isOnline() ? "&a" + plugin.getLocale().getMessage("gui.players.online.online") : "&c" + plugin.getLocale().getMessage("gui.players.online.offline"));
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, CompatibleMaterial.OAK_DOOR.getMaterial(), plugin.getLocale().getMessage("gui.general.back").getMessage());
? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage());
if (punish) createButton(38, Material.ANVIL, plugin.getLocale().getMessage("gui.player.punish").getMessage()); if (punish) createButton(38, Material.ANVIL, plugin.getLocale().getMessage("gui.player.punish").getMessage());
if (tickets) createButton(30, Material.CHEST, plugin.getLocale().getMessage("gui.player.tickets").getMessage()); if (tickets) createButton(30, Material.CHEST, plugin.getLocale().getMessage("gui.player.tickets").getMessage());
if (player.isOnline() && punishments) if (player.isOnline() && punishments)
createButton(32, Material.DIAMOND_SWORD, plugin.getLocale().getMessage("gui.player.punishments").getMessage()); createButton(32, Material.DIAMOND_SWORD, plugin.getLocale().getMessage("gui.player.punishments").getMessage());
if (notes) createButton(42, Material.MAP, plugin.getLocale().getMessage("gui.player.notes").getMessage()); if (notes) createButton(42, Material.MAP, plugin.getLocale().getMessage("gui.player.notes").getMessage());
if (moderate) createButton(40, Material.DIAMOND_CHESTPLATE, plugin.getLocale().getMessage("gui.player.moderate").getMessage()); if (moderate)
createButton(40, Material.DIAMOND_CHESTPLATE, plugin.getLocale().getMessage("gui.player.moderate").getMessage());
} }
@Override @Override

View File

@ -1,10 +1,10 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.tickets.TicketStatus;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -66,7 +66,7 @@ public class GUIPlayers extends AbstractGUI {
if (page != 0) { if (page != 0) {
createButton(46, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); createButton(46, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage());
registerClickable(46, ((player1, inventory1, cursor, slot, type) -> { registerClickable(46, ((player1, inventory1, cursor, slot, type) -> {
page --; page--;
constructGUI(); constructGUI();
})); }));
} }
@ -74,7 +74,7 @@ public class GUIPlayers extends AbstractGUI {
if (maxPage != page) { if (maxPage != page) {
createButton(48, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); createButton(48, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage());
registerClickable(48, ((player1, inventory1, cursor, slot, type) -> { registerClickable(48, ((player1, inventory1, cursor, slot, type) -> {
page ++; page++;
constructGUI(); constructGUI();
})); }));
} }
@ -84,9 +84,9 @@ public class GUIPlayers extends AbstractGUI {
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl); PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl);
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); ItemStack head = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
SkullMeta meta = ((SkullMeta) head.getItemMeta()); SkullMeta meta = ((SkullMeta) head.getItemMeta());
if (plugin.isServerVersionAtLeast(ServerVersion.V1_13)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
meta.setOwningPlayer(pl); meta.setOwningPlayer(pl);
else else
meta.setOwner(pl.getName()); meta.setOwner(pl.getName());
@ -127,7 +127,7 @@ public class GUIPlayers extends AbstractGUI {
} }
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(36 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(36 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
createButton(46, Material.ENDER_PEARL, plugin.getLocale().getMessage("gui.players.search").getMessage()); createButton(46, Material.ENDER_PEARL, plugin.getLocale().getMessage("gui.players.search").getMessage());
createButton(47, Material.HOPPER, "&6" + currentOnline.getTranslation()); createButton(47, Material.HOPPER, "&6" + currentOnline.getTranslation());
@ -167,18 +167,18 @@ public class GUIPlayers extends AbstractGUI {
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> { AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
List<UUID> players = new ArrayList<>(plugin.getPunishmentManager().getPunishments().keySet()); List<UUID> players = new ArrayList<>(plugin.getPunishmentManager().getPunishments().keySet());
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if (players.contains(player.getUniqueId())) continue; if (players.contains(player.getUniqueId())) continue;
players.add(player.getUniqueId()); players.add(player.getUniqueId());
} }
List<UUID> found = players.stream().filter(uuid -> Bukkit.getOfflinePlayer(uuid).getName().equalsIgnoreCase(event.getName())).collect(Collectors.toList()); List<UUID> found = players.stream().filter(uuid -> Bukkit.getOfflinePlayer(uuid).getName().equalsIgnoreCase(event.getName())).collect(Collectors.toList());
if (found.size() == 1) { if (found.size() == 1) {
new GUIPlayer(plugin, Bukkit.getOfflinePlayer(found.get(0)), player); new GUIPlayer(plugin, Bukkit.getOfflinePlayer(found.get(0)), player);
} else { } else {
plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(player); plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(player);
} }
}); });

View File

@ -1,11 +1,11 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.Punishment; import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -58,9 +58,9 @@ public class GUIPunish extends AbstractGUI {
inventory.clear(); inventory.clear();
if (toModerate != null) { if (toModerate != null) {
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); ItemStack head = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
SkullMeta meta = ((SkullMeta) head.getItemMeta()); SkullMeta meta = ((SkullMeta) head.getItemMeta());
if (plugin.isServerVersionAtLeast(ServerVersion.V1_13)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
meta.setOwningPlayer(toModerate); meta.setOwningPlayer(toModerate);
else else
meta.setOwner(toModerate.getName()); meta.setOwner(toModerate.getName());
@ -72,7 +72,7 @@ public class GUIPunish extends AbstractGUI {
if (player.hasPermission("um." + type.toString().toLowerCase())) if (player.hasPermission("um." + type.toString().toLowerCase()))
createButton(22, Material.EMERALD_BLOCK, plugin.getLocale().getMessage("gui.punish.submit").getMessage()); createButton(22, Material.EMERALD_BLOCK, plugin.getLocale().getMessage("gui.punish.submit").getMessage());
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.OAK_DOOR ? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage());
@ -107,9 +107,9 @@ public class GUIPunish extends AbstractGUI {
} }
if (type != PunishmentType.KICK) { if (type != PunishmentType.KICK) {
createButton(32, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(32, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.CLOCK ? Material.CLOCK
: Material.valueOf("WATCH"), : Material.valueOf("WATCH"),
plugin.getLocale().getMessage("gui.punish.type.duration").getMessage(), plugin.getLocale().getMessage("gui.punish.type.duration").getMessage(),
plugin.getLocale().getMessage("gui.punish.type.duration.leftclick").getMessage(), plugin.getLocale().getMessage("gui.punish.type.duration.leftclick").getMessage(),
plugin.getLocale().getMessage("gui.punish.type.duration.rightclick").getMessage(), plugin.getLocale().getMessage("gui.punish.type.duration.rightclick").getMessage(),
@ -133,7 +133,7 @@ public class GUIPunish extends AbstractGUI {
return; return;
} }
Material material = plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"); Material material = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL");
String name = plugin.getLocale().getMessage("gui.punish.template.create").getMessage(); String name = plugin.getLocale().getMessage("gui.punish.template.create").getMessage();
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
lore.add(plugin.getLocale().getMessage("gui.punish.template.create2").getMessage()); lore.add(plugin.getLocale().getMessage("gui.punish.template.create2").getMessage());
@ -147,7 +147,7 @@ public class GUIPunish extends AbstractGUI {
lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick").getMessage()); lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick").getMessage());
} }
if (plugin.isServerVersionAtLeast(ServerVersion.V1_13) && inventory.getItem(4) != null && inventory.getItem(4).getType() == Material.WHITE_WOOL) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) && inventory.getItem(4) != null && inventory.getItem(4).getType() == Material.WHITE_WOOL)
material = Material.YELLOW_WOOL; material = Material.YELLOW_WOOL;
createButton(4, material, name, lore); createButton(4, material, name, lore);

View File

@ -1,22 +1,20 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.Punishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.omg.PortableInterceptor.ACTIVE;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class GUIPunishments extends AbstractGUI { public class GUIPunishments extends AbstractGUI {
@ -77,7 +75,7 @@ public class GUIPunishments extends AbstractGUI {
if (page != 0) { if (page != 0) {
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage());
registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { registerClickable(1, ((player1, inventory1, cursor, slot, type) -> {
page --; page--;
constructGUI(); constructGUI();
})); }));
} }
@ -85,12 +83,12 @@ public class GUIPunishments extends AbstractGUI {
if (page != maxPage) { if (page != maxPage) {
createButton(6, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); createButton(6, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage());
registerClickable(6, ((player1, inventory1, cursor, slot, type) -> { registerClickable(6, ((player1, inventory1, cursor, slot, type) -> {
page ++; page++;
constructGUI(); constructGUI();
})); }));
} }
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.OAK_DOOR ? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage());
@ -98,7 +96,7 @@ public class GUIPunishments extends AbstractGUI {
createButton(4, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())); createButton(4, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name()));
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(9 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
int currentSlot = 18; int currentSlot = 18;
for (PunishmentHolder punishmentHolder : punishments) { for (PunishmentHolder punishmentHolder : punishments) {

View File

@ -1,18 +1,16 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -46,7 +44,7 @@ public class GUITemplateManager extends AbstractGUI {
if (page != 0) { if (page != 0) {
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage());
registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { registerClickable(1, ((player1, inventory1, cursor, slot, type) -> {
page --; page--;
constructGUI(); constructGUI();
})); }));
} }
@ -54,23 +52,23 @@ public class GUITemplateManager extends AbstractGUI {
if (page != maxPage) { if (page != maxPage) {
createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage());
registerClickable(5, ((player1, inventory1, cursor, slot, type) -> { registerClickable(5, ((player1, inventory1, cursor, slot, type) -> {
page ++; page++;
constructGUI(); constructGUI();
})); }));
} }
createButton(3 ,Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())); createButton(3, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name()));
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.OAK_DOOR ? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), : Material.valueOf("WOOD_DOOR"),
plugin.getLocale().getMessage("gui.general.back").getMessage()); plugin.getLocale().getMessage("gui.general.back").getMessage());
if (player.hasPermission("um.templates.create")) if (player.hasPermission("um.templates.create"))
createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.templatemanager.create").getMessage()); createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.templatemanager.create").getMessage());
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(9 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
if (punishmentType != PunishmentType.ALL) if (punishmentType != PunishmentType.ALL)
templates.removeIf(template -> template.getPunishmentType() != punishmentType); templates.removeIf(template -> template.getPunishmentType() != punishmentType);
@ -84,7 +82,8 @@ public class GUITemplateManager extends AbstractGUI {
if (type == ClickType.LEFT) { if (type == ClickType.LEFT) {
if (player.hasPermission("um.templates.edit")) new GUIPunish(plugin, null, template, player); if (player.hasPermission("um.templates.edit")) new GUIPunish(plugin, null, template, player);
} else if (type == ClickType.RIGHT) { } else if (type == ClickType.RIGHT) {
if (player.hasPermission("um.templates.destroy")) plugin.getTemplateManager().removeTemplate(template.getUUID()); if (player.hasPermission("um.templates.destroy"))
plugin.getTemplateManager().removeTemplate(template.getUUID());
constructGUI(); constructGUI();
} }
})); }));

View File

@ -1,10 +1,9 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,13 +26,11 @@ public class GUITemplateSelector extends AbstractGUI {
@Override @Override
protected void constructGUI() { protected void constructGUI() {
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, CompatibleMaterial.OAK_DOOR.getMaterial(),
? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"),
plugin.getLocale().getMessage("gui.general.back").getMessage()); plugin.getLocale().getMessage("gui.general.back").getMessage());
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(9 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values()); ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values());
for (int i = 0; i < templates.size(); i++) { for (int i = 0; i < templates.size(); i++) {

View File

@ -1,19 +1,17 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.tickets.TicketStatus;
import com.songoda.ultimatemoderation.utils.AbstractChatConfirm; import com.songoda.ultimatemoderation.utils.AbstractChatConfirm;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -55,7 +53,7 @@ public class GUITicket extends AbstractGUI {
if (page != 0) { if (page != 0) {
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage());
registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { registerClickable(1, ((player1, inventory1, cursor, slot, type) -> {
page --; page--;
constructGUI(); constructGUI();
})); }));
} }
@ -63,7 +61,7 @@ public class GUITicket extends AbstractGUI {
if (page != maxPage) { if (page != maxPage) {
createButton(3, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); createButton(3, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage());
registerClickable(3, ((player1, inventory1, cursor, slot, type) -> { registerClickable(3, ((player1, inventory1, cursor, slot, type) -> {
page ++; page++;
constructGUI(); constructGUI();
})); }));
} }
@ -71,19 +69,20 @@ public class GUITicket extends AbstractGUI {
if (player.hasPermission("um.tickets.openclose")) if (player.hasPermission("um.tickets.openclose"))
createButton(5, Material.REDSTONE, "&6" + ticket.getStatus().getStatus()); createButton(5, Material.REDSTONE, "&6" + ticket.getStatus().getStatus());
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.OAK_DOOR ? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"), : Material.valueOf("WOOD_DOOR"),
plugin.getLocale().getMessage("gui.general.back").getMessage()); plugin.getLocale().getMessage("gui.general.back").getMessage());
if (player.hasPermission("um.ticket.clicktotele") && ticket.getLocation() != null) if (player.hasPermission("um.ticket.clicktotele") && ticket.getLocation() != null)
createButton(7, Material.REDSTONE, createButton(7, Material.REDSTONE,
plugin.getLocale().getMessage("gui.ticket.clicktotele").getMessage()); plugin.getLocale().getMessage("gui.ticket.clicktotele").getMessage());
if (player.hasPermission("um.tickets.respond")) createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.respond").getMessage()); if (player.hasPermission("um.tickets.respond"))
createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.respond").getMessage());
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(9 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
for (int i = 0; i < responses.size(); i++) { for (int i = 0; i < responses.size(); i++) {
TicketResponse ticketResponse = responses.get(i); TicketResponse ticketResponse = responses.get(i);
@ -97,7 +96,7 @@ public class GUITicket extends AbstractGUI {
continue; continue;
if (subjectStr.charAt(n) == ' ') { if (subjectStr.charAt(n) == ' ') {
lore.add("&6" +subjectStr.substring(lastIndex, n).trim()); lore.add("&6" + subjectStr.substring(lastIndex, n).trim());
lastIndex = n; lastIndex = n;
} }
} }
@ -134,8 +133,8 @@ public class GUITicket extends AbstractGUI {
if (player.hasPermission("um.tickets.openclose")) { if (player.hasPermission("um.tickets.openclose")) {
registerClickable(5, ((player1, inventory1, cursor, slot, type) -> { registerClickable(5, ((player1, inventory1, cursor, slot, type) -> {
ticket.setStatus(ticket.getStatus() == TicketStatus.OPEN ? TicketStatus.CLOSED : TicketStatus.OPEN); ticket.setStatus(ticket.getStatus() == TicketStatus.OPEN ? TicketStatus.CLOSED : TicketStatus.OPEN);
constructGUI(); constructGUI();
})); }));
} }

View File

@ -1,13 +1,11 @@
package com.songoda.ultimatemoderation.gui; package com.songoda.ultimatemoderation.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.tickets.TicketStatus;
import com.songoda.ultimatemoderation.utils.AbstractChatConfirm;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -58,7 +56,7 @@ public class GUITicketManager extends AbstractGUI {
if (page != 0) { if (page != 0) {
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage());
registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { registerClickable(1, ((player1, inventory1, cursor, slot, type) -> {
page --; page--;
constructGUI(); constructGUI();
})); }));
} }
@ -66,24 +64,22 @@ public class GUITicketManager extends AbstractGUI {
if (maxPage >= 36) { if (maxPage >= 36) {
createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage());
registerClickable(5, ((player1, inventory1, cursor, slot, type) -> { registerClickable(5, ((player1, inventory1, cursor, slot, type) -> {
page ++; page++;
constructGUI(); constructGUI();
})); }));
} }
createButton(3 ,Material.DIAMOND_SWORD, Methods.formatText("&6" + status.getStatus())); createButton(3, Material.DIAMOND_SWORD, Methods.formatText("&6" + status.getStatus()));
if (toModerate != null && player.hasPermission("um.tickets.create")) if (toModerate != null && player.hasPermission("um.tickets.create"))
createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.tickets.create").getMessage()); createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.tickets.create").getMessage());
if (player.hasPermission("um.ticket")) if (player.hasPermission("um.ticket"))
createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) createButton(8, CompatibleMaterial.OAK_DOOR.getMaterial(),
? Material.OAK_DOOR
: Material.valueOf("WOOD_DOOR"),
plugin.getLocale().getMessage("gui.general.back").getMessage()); plugin.getLocale().getMessage("gui.general.back").getMessage());
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(9 + i, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1");
for (int i = 0; i < tickets.size(); i++) { for (int i = 0; i < tickets.size(); i++) {
Ticket ticket = tickets.get(i); Ticket ticket = tickets.get(i);
@ -97,7 +93,7 @@ public class GUITicketManager extends AbstractGUI {
continue; continue;
if (subjectStr.charAt(n) == ' ') { if (subjectStr.charAt(n) == ' ') {
lore.add("&6" +subjectStr.substring(lastIndex, n).trim()); lore.add("&6" + subjectStr.substring(lastIndex, n).trim());
lastIndex = n; lastIndex = n;
} }
} }

View File

@ -5,7 +5,7 @@ import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.utils.AbstractChatConfirm; import com.songoda.ultimatemoderation.utils.AbstractChatConfirm;
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
import com.songoda.ultimatemoderation.utils.settings.Setting; import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -34,7 +34,7 @@ public class GUITicketType extends AbstractGUI {
resetClickables(); resetClickables();
registerClickables(); registerClickables();
List<String> types = Setting.TICKET_TYPES.getStringList(); List<String> types = Settings.TICKET_TYPES.getStringList();
for (int i = 0; i < types.size(); i ++) { for (int i = 0; i < types.size(); i ++) {
createButton(i, Material.PAPER, types.get(i)); createButton(i, Material.PAPER, types.get(i));

View File

@ -5,10 +5,9 @@ import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.staffchat.StaffChannel; import com.songoda.ultimatemoderation.staffchat.StaffChannel;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.settings.Setting; import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
@ -40,7 +39,7 @@ public class ChatListener implements Listener {
public void onChat(AsyncPlayerChatEvent event) { public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
long slowmode = slowModeOverride == 0 ? Methods.parseTime(Setting.SLOW_MODE.getString()) : slowModeOverride; long slowmode = slowModeOverride == 0 ? Methods.parseTime(Settings.SLOW_MODE.getString()) : slowModeOverride;
if (!player.hasPermission("um.slowmode.bypass") && slowmode != 0) { if (!player.hasPermission("um.slowmode.bypass") && slowmode != 0) {
List<Log> chats = chatLog.stream().filter(log -> log.player == player.getUniqueId()).collect(Collectors.toList()); List<Log> chats = chatLog.stream().filter(log -> log.player == player.getUniqueId()).collect(Collectors.toList());

View File

@ -1,11 +1,10 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandCommandSpy; import com.songoda.ultimatemoderation.commands.CommandCommandSpy;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.utils.settings.Setting; import com.songoda.ultimatemoderation.settings.Settings;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -30,13 +29,13 @@ public class CommandListener implements Listener {
List<AppliedPunishment> appliedPunishments = instance.getPunishmentManager().getPlayer(player).getActivePunishments(PunishmentType.MUTE); List<AppliedPunishment> appliedPunishments = instance.getPunishmentManager().getPlayer(player).getActivePunishments(PunishmentType.MUTE);
if (!appliedPunishments.isEmpty()) { if (!appliedPunishments.isEmpty()) {
if (Setting.MUTE_DISABLED_COMMANDS.getStringList().stream() if (Settings.MUTE_DISABLED_COMMANDS.getStringList().stream()
.anyMatch(s -> command.toUpperCase().startsWith("/" + s.toUpperCase()))) .anyMatch(s -> command.toUpperCase().startsWith("/" + s.toUpperCase())))
event.setCancelled(true); event.setCancelled(true);
} }
List<String> blockedCommands = Setting.BLOCKED_COMMANDS.getStringList(); List<String> blockedCommands = Settings.BLOCKED_COMMANDS.getStringList();
for (String cmd : blockedCommands) { for (String cmd : blockedCommands) {
if (command.toUpperCase().startsWith("/" + cmd.toUpperCase()) if (command.toUpperCase().startsWith("/" + cmd.toUpperCase())

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze; import com.songoda.ultimatemoderation.commands.CommandFreeze;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze; import com.songoda.ultimatemoderation.commands.CommandFreeze;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandVanish; import com.songoda.ultimatemoderation.commands.CommandVanish;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;

View File

@ -1,6 +1,6 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.command.commands.CommandVanish; import com.songoda.ultimatemoderation.commands.CommandVanish;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;

View File

@ -1,7 +1,7 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze; import com.songoda.ultimatemoderation.commands.CommandFreeze;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatemoderation.listeners; package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandSpy; import com.songoda.ultimatemoderation.commands.CommandSpy;
import com.songoda.ultimatemoderation.command.commands.CommandVanish; import com.songoda.ultimatemoderation.commands.CommandVanish;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -0,0 +1,75 @@
package com.songoda.ultimatemoderation.settings;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigSetting;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.ultimatemoderation.UltimateModeration;
import java.util.Arrays;
import java.util.stream.Collectors;
public class Settings {
static final Config config = UltimateModeration.getInstance().getCoreConfig();
public static final ConfigSetting VANISH_EFFECTS = new ConfigSetting(config, "Main.Enable Vanish Effects", true,
"Show particles and play sound when going in and out of vanish.");
public static final ConfigSetting VANISH_SOUND = new ConfigSetting(config, "Main.Vanish Sound", "ENTITY_GENERIC_EXPLODE",
"Sound to be played when going into vanish.");
public static final ConfigSetting VANISH_BATS = new ConfigSetting(config, "Main.Release Bats On Vanish", true,
"Shows bats when entering vanish.");
public static final ConfigSetting VANISH_PARTICLE = new ConfigSetting(config, "Main.Vanish Particle", "EXPLOSION_NORMAL",
"Show particles when entering vanish.");
public static final ConfigSetting SLOW_MODE = new ConfigSetting(config, "Main.SLOW_MODE", "0s",
"Limits how often a player can send a chat message by the corresponding amount.");
public static final ConfigSetting BLOCKED_COMMANDS = new ConfigSetting(config, "Main.Blocked Commands", Arrays.asList("Fly", "Op", "Plugins", "Pl"),
"Prevents players from running the specified commands.");
public static final ConfigSetting AUTOSAVE = new ConfigSetting(config, "Main.Auto Save Interval In Seconds", 15,
"The amount of time in between saving to file.",
"This is purely a safety function to prevent against unplanned crashes or",
"restarts. With that said it is advised to keep this enabled.",
"If however you enjoy living on the edge, feel free to turn it off.");
public static final ConfigSetting STAFFCHAT_COLOR_CODE = new ConfigSetting(config, "Main.Staff Chat Color Code", 'b',
"Color of messages sent in staff chat.");
public static final ConfigSetting TICKET_TYPES = new ConfigSetting(config, "Main.Ticket Types", Arrays.asList("Grief", "Player Report", "Bug Report", "Suggestion", "Other"),
"Types of tickets players can open.");
public static final ConfigSetting MUTE_DISABLED_COMMANDS = new ConfigSetting(config, "Main.Mute Disabled Commands", Arrays.asList("minecraft:me", "minecraft:tell"),
"Commands disabled when a player is muted.");
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", "GRAY_STAINED_GLASS_PANE");
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", "BLUE_STAINED_GLASS_PANE");
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", "LIGHT_BLUE_STAINED_GLASS_PANE");
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
public static void setupConfig() {
config.load();
config.setAutoremove(true).setAutosave(true);
// convert glass pane settings
int color;
if ((color = GLASS_TYPE_1.getInt(-1)) != -1) {
config.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
}
if ((color = GLASS_TYPE_2.getInt(-1)) != -1) {
config.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
}
if ((color = GLASS_TYPE_3.getInt(-1)) != -1) {
config.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
}
config.saveChanges();
}
}

View File

@ -1,8 +1,9 @@
package com.songoda.ultimatemoderation.staffchat; package com.songoda.ultimatemoderation.staffchat;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.settings.Setting; import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -13,7 +14,7 @@ import java.util.UUID;
public class StaffChannel { public class StaffChannel {
private final String channelName; private final String channelName;
private char chatChar = Setting.STAFFCHAT_COLOR_CODE.getChar(); private char chatChar = Settings.STAFFCHAT_COLOR_CODE.getChar();
private final List<UUID> members = new ArrayList<>(); private final List<UUID> members = new ArrayList<>();
private final List<String> chatLog = new ArrayList<>(); private final List<String> chatLog = new ArrayList<>();

View File

@ -1,5 +1,6 @@
package com.songoda.ultimatemoderation.storage; package com.songoda.ultimatemoderation.storage;
import com.songoda.core.configuration.Config;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote; import com.songoda.ultimatemoderation.punish.PunishmentNote;
@ -7,24 +8,19 @@ import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.tickets.TicketStatus;
import com.songoda.ultimatemoderation.utils.ConfigWrapper;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import java.util.List; import java.util.List;
import java.util.UUID;
public abstract class Storage { public abstract class Storage {
protected final UltimateModeration instance; protected final UltimateModeration plugin;
protected final ConfigWrapper dataFile; protected final Config dataFile;
public Storage(UltimateModeration instance) { public Storage(UltimateModeration plugin) {
this.instance = instance; this.plugin = plugin;
this.dataFile = new ConfigWrapper(instance, "", "data.yml"); this.dataFile = new Config(plugin, "data.yml");
this.dataFile.createNewFile(null, "UltimateModeration Data File"); this.dataFile.load();
this.dataFile.getConfig().options().copyDefaults(true);
this.dataFile.saveConfig();
} }
public abstract boolean containsGroup(String group); public abstract boolean containsGroup(String group);

View File

@ -1,195 +0,0 @@
package com.songoda.ultimatemoderation.storage.types;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.storage.Storage;
import com.songoda.ultimatemoderation.storage.StorageItem;
import com.songoda.ultimatemoderation.storage.StorageRow;
import com.songoda.ultimatemoderation.utils.MySQLDatabase;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StorageMysql extends Storage {
private static Map<String, StorageItem[]> toSave = new HashMap<>();
private static Map<String, StorageItem[]> lastSave = new HashMap<>();
private MySQLDatabase database;
public StorageMysql(UltimateModeration instance) {
super(instance);
this.database = new MySQLDatabase(instance);
}
@Override
public boolean containsGroup(String group) {
try {
DatabaseMetaData dbm = database.getConnection().getMetaData();
ResultSet rs = dbm.getTables(null, null, instance.getConfig().getString("Database.Prefix") + group, null);
if (rs.next()) {
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
@Override
public List<StorageRow> getRowsByGroup(String group) {
List<StorageRow> rows = new ArrayList<>();
try {
ResultSet set = database.getConnection().createStatement().executeQuery(String.format("SELECT * FROM `" + instance.getConfig().getString("Database.Prefix") + "%s`", group));
while (set.next()) {
Map<String, StorageItem> items = new HashMap<>();
String key = set.getString(1);
for (int i = 2; i <= set.getMetaData().getColumnCount(); i++) {
if (set.getObject(i) == null || set.getObject(i) == "") continue;
StorageItem item = new StorageItem(set.getObject(i));
items.put(set.getMetaData().getColumnName(i), item);
}
StorageRow row = new StorageRow(key, items);
rows.add(row);
}
} catch (SQLException e) {
e.printStackTrace();
}
return rows;
}
@Override
public void prepareSaveItem(String group, StorageItem... items) {
toSave.put(group + "]" + items[0].asObject().toString(), items);
}
@Override
public void doSave() {
this.updateData(instance);
if (toSave.isEmpty()) return;
Map<String, StorageItem[]> nextSave = new HashMap<>(toSave);
if (lastSave.isEmpty())
lastSave.putAll(toSave);
this.makeBackup();
this.save();
toSave.clear();
lastSave.clear();
lastSave.putAll(nextSave);
}
@Override
public void save() {
try {
Statement stmt = database.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
last:
for (Map.Entry<String, StorageItem[]> last : lastSave.entrySet()) {
String lastKey = last.getKey().split("]")[0];
String lastValue = last.getValue()[0].asObject().toString();
for (Map.Entry<String, StorageItem[]> to : toSave.entrySet()) {
String toKey = to.getKey().split("]")[0];
if (!toKey.equals(lastKey)
|| !to.getValue()[0].asObject().equals(lastValue)
|| to.getValue().length != last.getValue().length)
continue;
toSave.remove(toKey);
for (int i = 0; i < to.getValue().length - 1; i ++) {
if (to.getValue()[i].asObject() != null
&& !to.getValue()[i].asObject().toString()
.equals(last.getValue()[i].asObject().toString())) {
//Update
StorageItem[] items = to.getValue();
StringBuilder sql = new StringBuilder(String.format("UPDATE `" + instance.getConfig().getString("Database.Prefix") + "%s`", toKey));
sql.append(" SET");
for (StorageItem item : items) {
if (item == null || item.asObject() == null) continue;
String key = item.getKey().split("]")[0];
sql.append(String.format("`%s` = '%s', ", key, item.asObject().toString()));
}
sql = new StringBuilder(sql.substring(0, sql.length() - 2));
sql.append(String.format(" WHERE `%s`='%s'", last.getValue()[0].getKey(), last.getValue()[0].asObject().toString()));
stmt.addBatch(sql.toString());
continue last;
}
}
// Already up to date.
continue last;
}
//Was not found delete.
StringBuilder sql = new StringBuilder(String.format("DELETE FROM `" + instance.getConfig().getString("Database.Prefix") + "%s`", lastKey));
sql.append(String.format(" WHERE `%s`='%s'", last.getValue()[0].getKey(), last.getValue()[0].asObject().toString()));
stmt.addBatch(sql.toString());
}
for (Map.Entry<String, StorageItem[]> to : toSave.entrySet()) {
String toKey = to.getKey().split("]")[0];
//Add
StorageItem[] items = to.getValue();
StringBuilder sql = new StringBuilder(String.format("INSERT INTO `" + instance.getConfig().getString("Database.Prefix") + "%s`", toKey));
sql.append(" (");
for (StorageItem item : items) {
if (item == null || item.asObject() == null) continue;
String key = item.getKey().split("]")[0];
sql.append(String.format("`%s`, ", key));
}
sql = new StringBuilder(sql.substring(0, sql.length() - 2));
sql.append(") VALUES (");
for (StorageItem item : items) {
if (item == null || item.asObject() == null) continue;
sql.append(String.format("'%s', ", item.asObject().toString()));
}
sql = new StringBuilder(sql.substring(0, sql.length() - 2));
sql.append(");");
stmt.addBatch(sql.toString());
}
stmt.executeBatch();
toSave.clear();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void makeBackup() {
}
@Override
public void closeConnection() {
try {
database.getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View File

@ -12,30 +12,30 @@ import java.util.*;
public class StorageYaml extends Storage { public class StorageYaml extends Storage {
private static final Map<String, Object> toSave = new HashMap<>(); private final Map<String, Object> toSave = new HashMap<>();
private static final Map<String, Object> lastSave = new HashMap<>(); private Map<String, Object> lastSave = null;
public StorageYaml(UltimateModeration instance) { public StorageYaml(UltimateModeration plugin) {
super(instance); super(plugin);
} }
@Override @Override
public boolean containsGroup(String group) { public boolean containsGroup(String group) {
return dataFile.getConfig().contains("data." + group); return dataFile.contains("data." + group);
} }
@Override @Override
public List<StorageRow> getRowsByGroup(String group) { public List<StorageRow> getRowsByGroup(String group) {
List<StorageRow> rows = new ArrayList<>(); List<StorageRow> rows = new ArrayList<>();
ConfigurationSection currentSection = dataFile.getConfig().getConfigurationSection("data." + group); ConfigurationSection currentSection = dataFile.getConfigurationSection("data." + group);
for (String key : currentSection.getKeys(false)) { for (String key : currentSection.getKeys(false)) {
Map<String, StorageItem> items = new HashMap<>(); Map<String, StorageItem> items = new HashMap<>();
ConfigurationSection currentSection2 = dataFile.getConfig().getConfigurationSection("data." + group + "." + key); ConfigurationSection currentSection2 = dataFile.getConfigurationSection("data." + group + "." + key);
for (String key2 : currentSection2.getKeys(false)) { for (String key2 : currentSection2.getKeys(false)) {
String path = "data." + group + "." + key + "." + key2; String path = "data." + group + "." + key + "." + key2;
items.put(key2, new StorageItem(dataFile.getConfig().get(path) instanceof MemorySection items.put(key2, new StorageItem(dataFile.get(path) instanceof MemorySection
? convertToInLineList(path) : dataFile.getConfig().get(path))); ? convertToInLineList(path) : dataFile.get(path)));
} }
if (items.isEmpty()) continue; if (items.isEmpty()) continue;
StorageRow row = new StorageRow(key, items); StorageRow row = new StorageRow(key, items);
@ -46,8 +46,8 @@ public class StorageYaml extends Storage {
private String convertToInLineList(String path) { private String convertToInLineList(String path) {
StringBuilder converted = new StringBuilder(); StringBuilder converted = new StringBuilder();
for (String key : dataFile.getConfig().getConfigurationSection(path).getKeys(false)) { for (String key : dataFile.getConfigurationSection(path).getKeys(false)) {
converted.append(key).append(":").append(dataFile.getConfig().getInt(path + "." + key)).append(";"); converted.append(key).append(":").append(dataFile.getInt(path + "." + key)).append(";");
} }
return converted.toString(); return converted.toString();
} }
@ -56,21 +56,20 @@ public class StorageYaml extends Storage {
public void prepareSaveItem(String group, StorageItem... items) { public void prepareSaveItem(String group, StorageItem... items) {
for (StorageItem item : items) { for (StorageItem item : items) {
if (item == null || item.asObject() == null) continue; if (item == null || item.asObject() == null) continue;
toSave.put("data." + group + "." + items[0].asObject()+ "." + item.getKey(), item.asObject()); toSave.put("data." + group + "." + items[0].asString() + "." + item.getKey(), item.asObject());
} }
} }
@Override @Override
public void doSave() { public void doSave() {
dataFile.getConfig().set("data", null); this.updateData(plugin);
if (lastSave == null)
lastSave = new HashMap<>(toSave);
this.updateData(instance);
if (toSave.isEmpty()) return; if (toSave.isEmpty()) return;
Map<String, Object> nextSave = new HashMap<>(toSave); Map<String, Object> nextSave = new HashMap<>(toSave);
if (lastSave.isEmpty())
lastSave.putAll(toSave);
this.makeBackup(); this.makeBackup();
this.save(); this.save();
@ -86,19 +85,19 @@ public class StorageYaml extends Storage {
if (toSave.containsKey(entry.getKey())) { if (toSave.containsKey(entry.getKey())) {
Object newValue = toSave.get(entry.getKey()); Object newValue = toSave.get(entry.getKey());
if (!entry.getValue().equals(newValue)) { if (!entry.getValue().equals(newValue)) {
dataFile.getConfig().set(entry.getKey(), entry.getValue()); dataFile.set(entry.getKey(), newValue);
} }
toSave.remove(newValue); toSave.remove(entry.getKey());
} else { } else {
dataFile.getConfig().set(entry.getKey(), null); dataFile.set(entry.getKey(), null);
} }
} }
for (Map.Entry<String, Object> entry : toSave.entrySet()) { for (Map.Entry<String, Object> entry : toSave.entrySet()) {
dataFile.getConfig().set(entry.getKey(), entry.getValue()); dataFile.set(entry.getKey(), entry.getValue());
} }
dataFile.saveConfig(); dataFile.save();
} catch (NullPointerException e) { } catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -106,15 +105,16 @@ public class StorageYaml extends Storage {
@Override @Override
public void makeBackup() { public void makeBackup() {
File data = new File(instance.getDataFolder(), "data.yml"); File data = new File(plugin.getDataFolder(), "data.yml");
File dataClone = new File(instance.getDataFolder(), "data-backup-" + System.currentTimeMillis() + ".yml"); File dataClone = new File(plugin.getDataFolder(), "data-backup-" + System.currentTimeMillis() + ".yml");
try { try {
copyFile(data, dataClone); if (data.exists())
copyFile(data, dataClone);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
Deque<File> backups = new ArrayDeque<>(); Deque<File> backups = new ArrayDeque<>();
for (File file : Objects.requireNonNull(instance.getDataFolder().listFiles())) { for (File file : Objects.requireNonNull(plugin.getDataFolder().listFiles())) {
if (file.getName().toLowerCase().contains("data-backup")) { if (file.getName().toLowerCase().contains("data-backup")) {
backups.add(file); backups.add(file);
} }
@ -126,10 +126,9 @@ public class StorageYaml extends Storage {
@Override @Override
public void closeConnection() { public void closeConnection() {
dataFile.saveConfig(); dataFile.save();
} }
private static void copyFile(File source, File dest) throws IOException { private static void copyFile(File source, File dest) throws IOException {
InputStream is = null; InputStream is = null;
OutputStream os = null; OutputStream os = null;

View File

@ -1,10 +1,10 @@
package com.songoda.ultimatemoderation.tasks; package com.songoda.ultimatemoderation.tasks;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.listeners.ChatListener; import com.songoda.ultimatemoderation.listeners.ChatListener;
import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import com.songoda.ultimatemoderation.utils.settings.Setting;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -34,7 +34,7 @@ public class SlowModeTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
long slowmode = ChatListener.getSlowModeOverride() == 0 ? Methods.parseTime(Setting.SLOW_MODE.getString()) : ChatListener.getSlowModeOverride(); long slowmode = ChatListener.getSlowModeOverride() == 0 ? Methods.parseTime(Settings.SLOW_MODE.getString()) : ChatListener.getSlowModeOverride();
if (slowmode == 0) return; if (slowmode == 0) return;
@ -48,11 +48,11 @@ public class SlowModeTask extends BukkitRunnable {
ChatListener.Log last = chats.get(chats.size() - 1); ChatListener.Log last = chats.get(chats.size() - 1);
if ((System.currentTimeMillis() - last.getSent()) < (slowmode + 1000)) { if ((System.currentTimeMillis() - last.getSent()) < (slowmode + 1000)) {
int remaining = (int)((slowmode / 1000) - (System.currentTimeMillis() - last.getSent()) / 1000); int remaining = (int) ((slowmode / 1000) - (System.currentTimeMillis() - last.getSent()) / 1000);
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9)) if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0 player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0
? plugin.getLocale().getMessage("event.slowmode.done").getMessage() ? plugin.getLocale().getMessage("event.slowmode.done").getMessage()
: plugin.getLocale().getMessage("event.slowmode.wait").processPlaceholder("delay", remaining).getMessage())); : plugin.getLocale().getMessage("event.slowmode.wait").processPlaceholder("delay", remaining).getMessage()));
} }
}); });

View File

@ -1,67 +0,0 @@
package com.songoda.ultimatemoderation.utils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
/**
* ConfigWrapper made by @clip
*/
public class ConfigWrapper {
private final JavaPlugin plugin;
private final String folderName, fileName;
private FileConfiguration config;
private File configFile;
public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) {
this.plugin = instance;
this.folderName = folderName;
this.fileName = fileName;
}
public void createNewFile(final String message, final String header) {
reloadConfig();
saveConfig();
loadConfig(header);
if (message != null) {
plugin.getLogger().info(message);
}
}
public FileConfiguration getConfig() {
if (config == null) {
reloadConfig();
}
return config;
}
public void loadConfig(final String header) {
config.options().header(header);
config.options().copyDefaults(true);
saveConfig();
}
public void reloadConfig() {
if (configFile == null) {
configFile = new File(plugin.getDataFolder() + folderName, fileName);
}
config = YamlConfiguration.loadConfiguration(configFile);
}
public void saveConfig() {
if (config == null || configFile == null) {
return;
}
try {
getConfig().save(configFile);
} catch (final IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}

View File

@ -1,5 +1,6 @@
package com.songoda.ultimatemoderation.utils; package com.songoda.ultimatemoderation.utils;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -33,11 +34,11 @@ public class Methods {
int randomNum = 1 + (int) (Math.random() * 6); int randomNum = 1 + (int) (Math.random() * 6);
ItemStack glass; ItemStack glass;
if (rainbow) { if (rainbow) {
glass = new ItemStack(UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? glass = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
} else { } else {
glass = new ItemStack(UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? glass = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
} }
ItemMeta glassmeta = glass.getItemMeta(); ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName("§l"); glassmeta.setDisplayName("§l");
@ -62,7 +63,7 @@ public class Methods {
public static String formatTitle(String text) { public static String formatTitle(String text) {
if (text == null || text.equals("")) if (text == null || text.equals(""))
return ""; return "";
if (!UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) { if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
if (text.length() > 31) if (text.length() > 31)
text = text.substring(0, 29) + "..."; text = text.substring(0, 29) + "...";
} }
@ -150,7 +151,7 @@ public class Methods {
* @return The serialized data. * @return The serialized data.
*/ */
public static String serializeLocation(Location location) { public static String serializeLocation(Location location) {
if (location == null || location.getWorld() == null) if (location == null || location.getWorld() == null)
return ""; return "";
String w = location.getWorld().getName(); String w = location.getWorld().getName();
double x = location.getX(); double x = location.getX();

View File

@ -1,695 +0,0 @@
package com.songoda.ultimatemoderation.utils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}
// The version of this bStats class
public static final int B_STATS_VERSION = 1;
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final Plugin plugin;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
*/
public Metrics(Plugin plugin) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) { }
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) { }
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
// We are the first!
startSubmitting();
}
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Adds a custom chart.
*
* @param chart The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
}
/**
* Starts the Scheduler which submits our data every 30 minutes.
*/
private void startSubmitting() {
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JSONObject getPluginData() {
JSONObject data = new JSONObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.put("pluginName", pluginName); // Append the name of the plugin
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
JSONArray customCharts = new JSONArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JSONObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.put("customCharts", customCharts);
return data;
}
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JSONObject getServerData() {
// Minecraft specific data
int playerAmount;
try {
// Around MC 1.8 the return type was changed to a collection from an array,
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = Bukkit.getVersion();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JSONObject data = new JSONObject();
data.put("serverUUID", serverUUID);
data.put("playerAmount", playerAmount);
data.put("onlineMode", onlineMode);
data.put("bukkitVersion", bukkitVersion);
data.put("javaVersion", javaVersion);
data.put("osName", osName);
data.put("osArch", osArch);
data.put("osVersion", osVersion);
data.put("coreCount", coreCount);
return data;
}
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JSONObject data = getServerData();
JSONArray pluginData = new JSONArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
}
} catch (NoSuchFieldException ignored) { }
}
data.put("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(new Runnable() {
@Override
public void run() {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}
}).start();
}
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data.toString());
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.write(compressedData);
outputStream.flush();
outputStream.close();
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
bufferedReader.close();
if (logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
}
}
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
gzip.write(str.getBytes(StandardCharsets.UTF_8));
gzip.close();
return outputStream.toByteArray();
}
/**
* Represents a custom chart.
*/
public static abstract class CustomChart {
// The id of the chart
final String chartId;
/**
* Class constructor.
*
* @param chartId The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
}
private JSONObject getRequestJsonObject() {
JSONObject chart = new JSONObject();
chart.put("chartId", chartId);
try {
JSONObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.put("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JSONObject getChartData() throws Exception;
}
/**
* Represents a custom simple pie.
*/
public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
data.put("value", value);
return data;
}
}
/**
* Represents a custom advanced pie.
*/
public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.put(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.put("values", values);
return data;
}
}
/**
* Represents a custom drilldown pie.
*/
public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
this.callable = callable;
}
@Override
public JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JSONObject value = new JSONObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.put(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.put(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.put("values", values);
return data;
}
}
/**
* Represents a custom single line chart.
*/
public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
int value = callable.call();
if (value == 0) {
// Null = skip the chart
return null;
}
data.put("value", value);
return data;
}
}
/**
* Represents a custom multi line chart.
*/
public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.put(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.put("values", values);
return data;
}
}
/**
* Represents a custom simple bar chart.
*/
public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
JSONArray categoryValues = new JSONArray();
categoryValues.add(entry.getValue());
values.put(entry.getKey(), categoryValues);
}
data.put("values", values);
return data;
}
}
/**
* Represents a custom advanced bar chart.
*/
public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JSONObject getChartData() throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JSONArray categoryValues = new JSONArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(categoryValue);
}
values.put(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.put("values", values);
return data;
}
}
}

View File

@ -1,89 +0,0 @@
package com.songoda.ultimatemoderation.utils;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.storage.StorageItem;
import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
public class MySQLDatabase {
private final UltimateModeration instance;
private Connection connection;
public MySQLDatabase(UltimateModeration instance) {
this.instance = instance;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://" + instance.getConfig().getString("Database.IP") + ":" + instance.getConfig().getString("Database.Port") + "/" + instance.getConfig().getString("Database.Database Name") + "?autoReconnect=true&useSSL=false";
this.connection = DriverManager.getConnection(url, instance.getConfig().getString("Database.Username"), instance.getConfig().getString("Database.Password"));
createTables();
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Database connection failed.");
}
}
private void createTables() {
try {
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "templates` (\n" +
"\t`uuid` TEXT NULL,\n" +
"\t`type` TEXT NULL,\n" +
"\t`duration` BIGINT NULL,\n" +
"\t`reason` TEXT NULL,\n" +
"\t`name` TEXT NULL,\n" +
"\t`creator` TEXT NULL\n" +
")");
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "punishments` (\n" +
"\t`uuid` TEXT NULL,\n" +
"\t`type` TEXT NULL,\n" +
"\t`duration` BIGINT NULL,\n" +
"\t`reason` TEXT NULL,\n" +
"\t`victim` TEXT NULL,\n" +
"\t`punisher` TEXT NULL,\n" +
"\t`expiration` BIGINT NULL\n" +
")");
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "notes` (\n" +
"\t`uuid` TEXT NULL,\n" +
"\t`note` TEXT NULL,\n" +
"\t`author` TEXT NULL,\n" +
"\t`subject` TEXT NULL,\n" +
"\t`creation` BIGINT NULL\n" +
")");
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "tickets` (\n" +
"\t`id` INT NULL,\n" +
"\t`player` TEXT NULL,\n" +
"\t`subject` TEXT NULL,\n" +
"\t`status` TEXT NULL\n" +
")");
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS `" + instance.getConfig().getString("Database.Prefix") + "ticketresponses` (\n" +
"\t`posted` BIGINT NULL,\n" +
"\t`ticketid` INT NULL,\n" +
"\t`author` TEXT NULL,\n" +
"\t`message` TEXT NULL\n" +
")");
} catch (SQLException e) {
e.printStackTrace();
}
}
public Connection getConnection() {
return connection;
}
}

View File

@ -1,27 +0,0 @@
package com.songoda.ultimatemoderation.utils;
public enum ServerVersion {
UNKNOWN("unknown_server_version"),
V1_7("org.bukkit.craftbukkit.v1_7"),
V1_8("org.bukkit.craftbukkit.v1_8"),
V1_9("org.bukkit.craftbukkit.v1_9"),
V1_10("org.bukkit.craftbukkit.v1_10"),
V1_11("org.bukkit.craftbukkit.v1_11"),
V1_12("org.bukkit.craftbukkit.v1_12"),
V1_13("org.bukkit.craftbukkit.v1_13"),
V1_14("org.bukkit.craftbukkit.v1_14");
private final String packagePrefix;
private ServerVersion(String packagePrefix) {
this.packagePrefix = packagePrefix;
}
public static ServerVersion fromPackageName(String packageName) {
for (ServerVersion version : values())
if (packageName.startsWith(version.packagePrefix)) return version;
return ServerVersion.UNKNOWN;
}
}

View File

@ -1,7 +1,6 @@
package com.songoda.ultimatemoderation.utils.gui; package com.songoda.ultimatemoderation.utils.gui;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@ -18,7 +17,7 @@ public class Range {
this.max = max; this.max = max;
this.clickType = clickType; this.clickType = clickType;
this.bottom = bottom; this.bottom = bottom;
if (UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK;
} }
public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) { public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {

View File

@ -1,311 +0,0 @@
package com.songoda.ultimatemoderation.utils.locale;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Assists in the utilization of localization files.
* Created to be used by the Songoda Team.
*
* @author Brianna O'Keefe - Songoda
*/
public class Locale {
private static final List<Locale> LOCALES = new ArrayList<>();
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\"");
private static final String FILE_EXTENSION = ".lang";
private static JavaPlugin plugin;
private static File localeFolder;
private final Map<String, String> nodes = new HashMap<>();
private static String defaultLocale;
private File file;
private String name;
/**
* Instantiate the Locale class for future use
*
* @param name the name of the instantiated language
*/
private Locale(String name) {
if (plugin == null)
return;
this.name = name;
String fileName = name + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (!this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale \"" + fileName + "\"");
}
/**
* Initialize the class to load all existing language files and update them.
* This must be called before any other methods in this class as otherwise
* the methods will fail to invoke
*
* @param plugin the plugin instance
* @param defaultLocale the default language
*/
public Locale(JavaPlugin plugin, String defaultLocale) {
Locale.plugin = plugin;
Locale.localeFolder = new File(plugin.getDataFolder(), "locales/");
if (!localeFolder.exists()) localeFolder.mkdirs();
//Save the default locale file.
Locale.defaultLocale = defaultLocale;
saveLocale(defaultLocale);
for (File file : localeFolder.listFiles()) {
String fileName = file.getName();
if (!fileName.endsWith(FILE_EXTENSION)) continue;
String name = fileName.substring(0, fileName.lastIndexOf('.'));
if (name.split("_").length != 2) continue;
if (localeLoaded(name)) continue;
LOCALES.add(new Locale(name));
}
}
/**
* Save a locale file from the InputStream, to the locale folder
*
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveLocale(String fileName) {
return saveLocale(plugin.getResource(defaultLocale + FILE_EXTENSION), fileName);
}
/**
* Save a locale file from the InputStream, to the locale folder
*
* @param in file to save
* @param fileName the name of the file to save
* @return true if the operation was successful, false otherwise
*/
public static boolean saveLocale(InputStream in, String fileName) {
if (!localeFolder.exists()) localeFolder.mkdirs();
if (!fileName.endsWith(FILE_EXTENSION))
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
File destinationFile = new File(localeFolder, fileName);
if (destinationFile.exists())
return compareFiles(in, destinationFile);
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
copy(in, outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
if (fileName.split("_").length != 2) return false;
LOCALES.add(new Locale(fileName));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream in, File existingFile) {
InputStream defaultFile =
in == null ? plugin.getResource((defaultLocale != null ? defaultLocale : "en_US") + FILE_EXTENSION) : in;
boolean changed = false;
List<String> defaultLines, existingLines;
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
defaultLines = defaultReader.lines().collect(Collectors.toList());
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
for (String defaultValue : defaultLines) {
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
String key = defaultValue.split("\\s*=")[0];
if (!existingLines.contains(key)) {
if (!changed) {
writer.newLine();
writer.newLine();
// Leave a note alerting the user of the newly added messages.
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + ".");
// If changes were found outside of the default file leave a note explaining that.
if (in == null) {
writer.newLine();
writer.write("# These translations were found untranslated, join");
writer.newLine();
writer.write("# our translation Discord https://discord.gg/f7fpZEf");
writer.newLine();
writer.write("# to request an official update!");
}
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
if (in != null && !changed) compareFiles(null, existingFile);
} catch (IOException e) {
return false;
}
return changed;
}
/**
* Check whether a locale exists and is registered or not
*
* @param name the whole language tag (i.e. "en_US")
* @return true if it exists
*/
public static boolean localeLoaded(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equals(name)) return true;
return false;
}
/**
* Get a locale by its entire proper name (i.e. "en_US")
*
* @param name the full name of the locale
* @return locale of the specified name
*/
public static Locale getLocale(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* Clear the previous message cache and load new messages directly from file
*
* @return reload messages from file
*/
public boolean reloadMessages() {
if (!this.file.exists()) {
plugin.getLogger().warning("Could not find file for locale \"" + this.name + "\"");
return false;
}
this.nodes.clear(); // Clear previous data (if any)
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
if (line.trim().isEmpty() || line.startsWith("#") /* Comment */) continue;
Matcher matcher = NODE_PATTERN.matcher(line);
if (!matcher.find()) {
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
continue;
}
nodes.put(matcher.group(1), matcher.group(2));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* Supply the Message object with the plugins prefix.
*
* @param message message to be applied
* @return applied message
*/
private Message supplyPrefix(Message message) {
return message.setPrefix(this.nodes.getOrDefault("general.nametag.prefix", "[Plugin]"));
}
/**
* Create a new unsaved Message
*
* @param message the message to create
* @return the created message
*/
public Message newMessage(String message) {
return supplyPrefix(new Message(message));
}
/**
* Get a message set for a specific node.
*
* @param node the node to get
* @return the message for the specified node
*/
public Message getMessage(String node) {
return this.getMessageOrDefault(node, node);
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @param defaultValue the default value given that a value for the node was not found
* @return the message for the specified node. Default if none found
*/
public Message getMessageOrDefault(String node, String defaultValue) {
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
}
/**
* Return the locale name (i.e. "en_US")
*
* @return the locale name
*/
public String getName() {
return name;
}
private static void copy(InputStream input, OutputStream output) {
int n;
byte[] buffer = new byte[1024 * 4];
try {
while ((n = input.read(buffer)) != -1) {
output.write(buffer, 0, n);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,115 +0,0 @@
package com.songoda.ultimatemoderation.utils.locale;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* The Message object. This holds the message to be sent
* as well as the plugins prefix so that they can both be
* easily manipulated then deployed
*/
public class Message {
private String prefix = null;
private String message;
/**
* create a new message
*
* @param message the message text
*/
public Message(String message) {
this.message = message;
}
/**
* Format and send the held message to a player
*
* @param player player to send the message to
*/
public void sendMessage(Player player) {
player.sendMessage(this.getMessage());
}
/**
* Format and send the held message with the
* appended plugin prefix to a player
*
* @param player player to send the message to
*/
public void sendPrefixedMessage(Player player) {
player.sendMessage(this.getPrefixedMessage());
}
/**
* Format and send the held message to a player
*
* @param sender command sender to send the message to
*/
public void sendMessage(CommandSender sender) {
sender.sendMessage(this.getMessage());
}
/**
* Format and send the held message with the
* appended plugin prefix to a command sender
*
* @param sender command sender to send the message to
*/
public void sendPrefixedMessage(CommandSender sender) {
sender.sendMessage(this.getPrefixedMessage());
}
/**
* Format the held message and append the plugins
* prefix
*
* @return the prefixed message
*/
public String getPrefixedMessage() {
return ChatColor.translateAlternateColorCodes('&',(prefix == null ? "" : this.prefix)
+ " " + this.message);
}
/**
* Get and format the held message
*
* @return the message
*/
public String getMessage() {
return ChatColor.translateAlternateColorCodes('&', this.message);
}
/**
* Get the held message
*
* @return the message
*/
public String getUnformattedMessage() {
return this.message;
}
/**
* Replace the provided placeholder with the
* provided object
*
* @param placeholder the placeholder to replace
* @param replacement the replacement object
* @return the modified Message
*/
public Message processPlaceholder(String placeholder, Object replacement) {
this.message = message.replace("%" + placeholder + "%", replacement.toString());
return this;
}
Message setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String toString() {
return this.message;
}
}

View File

@ -1,22 +0,0 @@
package com.songoda.ultimatemoderation.utils.settings;
public enum Category {
MAIN("General settings and options."),
INTERFACES("These settings allow you to alter the way interfaces look.",
"They are used in GUI's to make patterns, change them up then open up a",
"GUI to see how it works."),
DATABASE("Settings regarding the Database."),
SYSTEM("System related settings.");
private String[] comments;
Category(String... comments) {
this.comments = comments;
}
public String[] getComments() {
return comments;
}
}

View File

@ -1,134 +0,0 @@
package com.songoda.ultimatemoderation.utils.settings;
import com.songoda.ultimatemoderation.UltimateModeration;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum Setting {
VANISH_EFFECTS("Main.Enable Vanish Effects", true,
"Show particles and play sound when going in and out of vanish."),
VANISH_SOUND("Main.Vanish Sound", "ENTITY_GENERIC_EXPLODE",
"Sound to be played when going into vanish."),
VANISH_BATS("Main.Release Bats On Vanish", true,
"Shows bats when entering vanish."),
VANISH_PARTICLE("Main.Vanish Particle", "EXPLOSION_NORMAL",
"Show particles when entering vanish."),
SLOW_MODE("Main.SLOW_MODE", "0s",
"Limits how often a player can send a chat message by the corresponding amount."),
BLOCKED_COMMANDS("Main.Blocked Commands", Arrays.asList("Fly", "Op", "Plugins", "Pl"),
"Prevents players from running the specified commands."),
AUTOSAVE("Main.Auto Save Interval In Seconds", 15,
"The amount of time in between saving to file.",
"This is purely a safety function to prevent against unplanned crashes or",
"restarts. With that said it is advised to keep this enabled.",
"If however you enjoy living on the edge, feel free to turn it off."),
STAFFCHAT_COLOR_CODE("Main.Staff Chat Color Code", 'b',
"Color of messages sent in staff chat."),
TICKET_TYPES("Main.Ticket Types", Arrays.asList("Grief", "Player Report", "Bug Report", "Suggestion", "Other"),
"Types of tickets players can open."),
MUTE_DISABLED_COMMANDS("Main.Mute Disabled Commands", Arrays.asList("minecraft:me", "minecraft:tell"),
"Commands disabled when a player is muted."),
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
DATABASE_SUPPORT("Database.Activate Mysql Support", false,
"Should MySQL be used for data storage?"),
DATABASE_IP("Database.IP", "127.0.0.1",
"MySQL IP"),
DATABASE_PORT("Database.Port", 3306,
"MySQL Port"),
DATABASE_NAME("Database.Database Name", "UltimateModeration",
"The database you are inserting data into."),
DATABASE_PREFIX("Database.Prefix", "US-",
"The prefix for tables inserted into the database."),
DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE",
"MySQL Username"),
DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE",
"MySQL Password"),
LANGUGE_MODE("System.Language Mode", "en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
private String setting;
private Object option;
private String[] comments;
Setting(String setting, Object option, String... comments) {
this.setting = setting;
this.option = option;
this.comments = comments;
}
Setting(String setting, Object option) {
this.setting = setting;
this.option = option;
this.comments = null;
}
public static Setting getSetting(String setting) {
List<Setting> settings = Arrays.stream(values()).filter(setting1 -> setting1.setting.equals(setting)).collect(Collectors.toList());
if (settings.isEmpty()) return null;
return settings.get(0);
}
public String getSetting() {
return setting;
}
public Object getOption() {
return option;
}
public String[] getComments() {
return comments;
}
public List<String> getStringList() {
return UltimateModeration.getInstance().getConfig().getStringList(setting);
}
public boolean getBoolean() {
return UltimateModeration.getInstance().getConfig().getBoolean(setting);
}
public int getInt() {
return UltimateModeration.getInstance().getConfig().getInt(setting);
}
public long getLong() {
return UltimateModeration.getInstance().getConfig().getLong(setting);
}
public String getString() {
return UltimateModeration.getInstance().getConfig().getString(setting);
}
public char getChar() {
return UltimateModeration.getInstance().getConfig().getString(setting).charAt(0);
}
public double getDouble() {
return UltimateModeration.getInstance().getConfig().getDouble(setting);
}
}

View File

@ -1,311 +0,0 @@
package com.songoda.ultimatemoderation.utils.settings;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
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.InventoryType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.*;
import java.util.*;
/**
* Created by songoda on 6/4/2017.
*/
public class SettingsManager implements Listener {
private final UltimateModeration plugin;
private Map<Player, String> cat = new HashMap<>();
private Map<Player, String> current = new HashMap<>();
public SettingsManager(UltimateModeration plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (event.getView().getType() != InventoryType.CHEST) return;
ItemStack clickedItem = event.getCurrentItem();
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|| clickedItem == null || !clickedItem.hasItemMeta()
|| !clickedItem.getItemMeta().hasDisplayName()) {
return;
}
if (event.getView().getTitle().equals(plugin.getName() + " Settings Manager")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
this.cat.put((Player) event.getWhoClicked(), type);
this.openEditor((Player) event.getWhoClicked());
} else if (event.getView().getTitle().equals(plugin.getName() + " Settings Editor")) {
event.setCancelled(true);
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
Player player = (Player) event.getWhoClicked();
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
if (plugin.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
this.plugin.getConfig().set(key, !plugin.getConfig().getBoolean(key));
this.finishEditing(player);
} else {
this.editObject(player, key);
}
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!current.containsKey(player)) return;
String value = current.get(player);
FileConfiguration config = plugin.getConfig();
if (config.isLong(value)) {
config.set(value, Long.parseLong(event.getMessage()));
} else if (config.isInt(value)) {
config.set(value, Integer.parseInt(event.getMessage()));
} else if (config.isDouble(value)) {
config.set(value, Double.parseDouble(event.getMessage()));
} else if (config.isString(value)) {
config.set(value, event.getMessage());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateModeration.getInstance(), () ->
this.finishEditing(player), 0L);
event.setCancelled(true);
}
private void finishEditing(Player player) {
this.current.remove(player);
this.saveConfig();
this.openEditor(player);
}
private void editObject(Player player, String current) {
this.current.put(player, ChatColor.stripColor(current));
player.closeInventory();
player.sendMessage("");
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
if (plugin.getConfig().isInt(current) || plugin.getConfig().isDouble(current)) {
player.sendMessage(Methods.formatText("&cUse only numbers."));
}
player.sendMessage("");
}
public void openSettingsManager(Player player) {
Inventory inventory = Bukkit.createInventory(null, 27, plugin.getName() + " Settings Manager");
ItemStack glass = Methods.getGlass();
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, glass);
}
int slot = 10;
for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9));
ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(Methods.formatText("&f&l" + key));
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
private void openEditor(Player player) {
Inventory inventory = Bukkit.createInventory(null, 54, plugin.getName() + " Settings Editor");
FileConfiguration config = plugin.getConfig();
int slot = 0;
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
String fKey = cat.get(player) + "." + key;
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.formatText("&6" + key));
List<String> lore = new ArrayList<>();
if (config.isBoolean(fKey)) {
item.setType(Material.LEVER);
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
} else if (config.isString(fKey)) {
item.setType(Material.PAPER);
lore.add(Methods.formatText("&7" + config.getString(fKey)));
} else if (config.isInt(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getInt(fKey)));
} else if (config.isLong(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getLong(fKey)));
} else if (config.isDouble(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getDouble(fKey)));
}
Setting setting = Setting.getSetting(fKey);
if (setting != null && setting.getComments() != null) {
lore.add("");
String comment = String.join(" ", setting.getComments());
int lastIndex = 0;
for (int n = 0; n < comment.length(); n++) {
if (n - lastIndex < 30)
continue;
if (comment.charAt(n) == ' ') {
lore.add(Methods.formatText("&8" + comment.substring(lastIndex, n).trim()));
lastIndex = n;
}
}
if (lastIndex - comment.length() < 30)
lore.add(Methods.formatText("&8" + comment.substring(lastIndex).trim()));
}
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
slot++;
}
player.openInventory(inventory);
}
public void reloadConfig() {
plugin.reloadConfig();
this.setupConfig();
}
public void setupConfig() {
FileConfiguration config = plugin.getConfig();
for (Setting setting : Setting.values()) {
config.addDefault(setting.getSetting(), setting.getOption());
}
plugin.getConfig().options().copyDefaults(true);
saveConfig();
}
private void saveConfig() {
String dump = plugin.getConfig().saveToString();
StringBuilder config = new StringBuilder();
BufferedReader bufReader = new BufferedReader(new StringReader(dump));
try {
boolean first = true;
String line;
int currentTab = 0;
String category = "";
while ((line = bufReader.readLine()) != null) {
if (line.trim().startsWith("#")) continue;
int tabChange = line.length() - line.trim().length();
if (currentTab != tabChange) {
category = category.contains(".") && tabChange != 0 ? category.substring(0, category.indexOf(".")) : "";
currentTab = tabChange;
}
if (line.endsWith(":")) {
bufReader.mark(1000);
String found = bufReader.readLine();
bufReader.reset();
if (!found.trim().startsWith("-")) {
String newCategory = line.substring(0, line.length() - 1).trim();
if (category.equals(""))
category = newCategory;
else
category += "." + newCategory;
currentTab = tabChange + 2;
if (!first) {
config.append("\n\n");
} else {
first = false;
}
if (!category.contains("."))
config.append("#").append("\n");
try {
Category categoryObj = Category.valueOf(category.toUpperCase()
.replace(" ", "_")
.replace(".", "_"));
config.append(new String(new char[tabChange]).replace('\0', ' '));
for (String l : categoryObj.getComments())
config.append("# ").append(l).append("\n");
} catch (IllegalArgumentException e) {
config.append("# ").append(category).append("\n");
}
if (!category.contains("."))
config.append("#").append("\n");
config.append(line).append("\n");
continue;
}
}
if (line.trim().startsWith("-")) {
config.append(line).append("\n");
continue;
}
String key = category + "." + (line.split(":")[0].trim());
for (Setting setting : Setting.values()) {
if (!setting.getSetting().equals(key) || setting.getComments() == null) continue;
config.append(" ").append("\n");
for (String l : setting.getComments()) {
config.append(new String(new char[currentTab]).replace('\0', ' '));
config.append("# ").append(l).append("\n");
}
}
config.append(line).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (!plugin.getDataFolder().exists())
plugin.getDataFolder().mkdir();
BufferedWriter writer =
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + File.separator + "config.yml")));
writer.write(config.toString());
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,32 +0,0 @@
package com.songoda.ultimatemoderation.utils.updateModules;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.update.Module;
import com.songoda.update.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class LocaleModule implements Module {
@Override
public void run(Plugin plugin) {
JSONObject json = plugin.getJson();
try {
JSONArray files = (JSONArray) json.get("neededFiles");
for (Object o : files) {
JSONObject file = (JSONObject) o;
if (file.get("type").equals("locale")) {
InputStream in = new URL((String) file.get("link")).openStream();
UltimateModeration.getInstance().getLocale().saveLocale(in, (String) file.get("name"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}