diff --git a/DayNightPvP.iml b/DayNightPvP.iml
new file mode 100644
index 0000000..a589521
--- /dev/null
+++ b/DayNightPvP.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ SPIGOT
+
+ 1
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index fa440f9..5f7e4f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
jar
UTF-8
- 1.8
+ 17
${project.name}
${project.groupId}.daynightpvp.DayNightPvP
@@ -38,8 +38,8 @@
maven-compiler-plugin
3.13.0
-
- 16
+
+ ${java.version}
diff --git a/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java b/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java
index a7efee0..2dd4fa0 100644
--- a/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java
+++ b/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java
@@ -2,16 +2,15 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
-import org.callvdois.daynightpvp.Listeners.ListenersHandler;
-import org.callvdois.daynightpvp.commands.CommandHandler;
-import org.callvdois.daynightpvp.files.ConfigFile;
-import org.callvdois.daynightpvp.files.LangFile;
-import org.callvdois.daynightpvp.metrics.MetricsHandler;
-import org.callvdois.daynightpvp.placeholder.PlaceholderHandler;
-import org.callvdois.daynightpvp.runnables.RunnableHandler;
+import org.callvdois.daynightpvp.commands.CommandManager;
+import org.callvdois.daynightpvp.config.FilesManager;
+import org.callvdois.daynightpvp.events.EventsManager;
+import org.callvdois.daynightpvp.metrics.MetricsManager;
+import org.callvdois.daynightpvp.placeholder.PlaceholderManager;
+import org.callvdois.daynightpvp.service.ServiceManager;
import org.callvdois.daynightpvp.utils.ConsoleUtils;
import org.callvdois.daynightpvp.utils.PluginUtils;
-import org.callvdois.daynightpvp.worldguard.FlagHandler;
+import org.callvdois.daynightpvp.worldguard.WorldGuardManager;
import java.util.ArrayList;
import java.util.List;
@@ -24,30 +23,24 @@ public class DayNightPvP extends JavaPlugin {
public static boolean placeHolderIsPresent;
public static List serviceTasks = new ArrayList<>();
private static DayNightPvP instance;
- private final ConsoleUtils consoleUtils;
- private final ConfigFile configFile;
- private final LangFile langFile;
- private final CommandHandler commandHandler;
- private final ListenersHandler listenersHandler;
- private final PlaceholderHandler placeholderHandler;
- private final FlagHandler flagHandler;
- private final RunnableHandler runnableHandler;
- private final MetricsHandler metricsHandler;
- private final PluginUtils pluginUtils;
+ private final FilesManager filesManager;
+ private final CommandManager commandManager;
+ private final EventsManager eventsManager;
+ private final PlaceholderManager placeholderManager;
+ private final WorldGuardManager worldGuardManager;
+ private final ServiceManager serviceManager;
+ private final MetricsManager metricsManager;
public DayNightPvP() {
instance = this;
- consoleUtils = new ConsoleUtils();
- configFile = new ConfigFile();
- langFile = new LangFile();
- commandHandler = new CommandHandler();
- listenersHandler = new ListenersHandler();
- placeholderHandler = new PlaceholderHandler();
- flagHandler = new FlagHandler();
- runnableHandler = new RunnableHandler();
- metricsHandler = new MetricsHandler();
- pluginUtils = new PluginUtils();
+ filesManager = new FilesManager();
+ commandManager = new CommandManager();
+ eventsManager = new EventsManager();
+ placeholderManager = new PlaceholderManager();
+ worldGuardManager = new WorldGuardManager();
+ serviceManager = new ServiceManager();
+ metricsManager = new MetricsManager();
}
@@ -57,42 +50,49 @@ public static DayNightPvP getInstance() {
@Override
public void onLoad() {
+ load();
+ }
+
+ @Override
+ public void onEnable() {
+ enable();
+ }
+
+ private void load() {
+
verifyCompatibilityPlugins();
if (worldGuardIsPresent) {
- flagHandler.register();
+ worldGuardManager.register();
}
}
- @Override
- public void onEnable() {
- consoleUtils.sendStartupMessage();
+ private void enable() {
+ ConsoleUtils.startMessage();
- metricsHandler.start();
+ filesManager.createFiles();
- configFile.createFile();
- langFile.createFile();
+ commandManager.register();
- commandHandler.register();
+ eventsManager.register();
- listenersHandler.register();
+ placeholderManager.register();
- placeholderHandler.register();
+ serviceManager.startServices();
- runnableHandler.startAllRunnables();
+ metricsManager.register();
}
-
private void verifyCompatibilityPlugins() {
- vaultIsPresent = pluginUtils.isPluginInstalled("Vault");
- worldGuardIsPresent = pluginUtils.isPluginInstalled("WorldGuard");
- griefIsPresent = pluginUtils.isPluginInstalled("GriefPrevention");
- placeHolderIsPresent = pluginUtils.isPluginInstalled("PlaceholderAPI");
+ vaultIsPresent = PluginUtils.isPluginInstalled("Vault");
+ worldGuardIsPresent = PluginUtils.isPluginInstalled("WorldGuard");
+ griefIsPresent = PluginUtils.isPluginInstalled("GriefPrevention");
+ placeHolderIsPresent = PluginUtils.isPluginInstalled("PlaceholderAPI");
}
@Override
public void onDisable() {
- runnableHandler.stopAllRunnables();
+ serviceManager.stopServices();
}
}
\ No newline at end of file
diff --git a/src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java b/src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java
deleted file mode 100644
index ab761c8..0000000
--- a/src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.callvdois.daynightpvp.Listeners;
-
-import org.bukkit.Bukkit;
-import org.bukkit.event.HandlerList;
-import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.files.ConfigFile;
-
-public class ListenersHandler {
-
- private final ConfigFile configFile;
-
- public ListenersHandler() {
- configFile = new ConfigFile();
- }
-
- public void register() {
- registerJoinListener();
- registerEntityListener();
- registerDeathListener();
- }
-
- public void unregisterAll() {
- HandlerList.unregisterAll(DayNightPvP.getInstance());
- }
-
- private void registerJoinListener() {
- if (configFile.getUpdateChecker()) {
- Bukkit.getPluginManager().registerEvents(new JoinListener(), DayNightPvP.getInstance());
- }
- }
-
- private void registerEntityListener() {
- Bukkit.getPluginManager().registerEvents(new DamageListener(), DayNightPvP.getInstance());
- }
-
- private void registerDeathListener() {
- boolean vaultLoseMoneyOnDeath = configFile.getVaultLoseMoneyOnDeathEnabled();
- boolean keepInventoryWhenKilledByPlayer = configFile.getPvpKeepInventoryWhenKilledByPlayer();
-
- if (vaultLoseMoneyOnDeath || keepInventoryWhenKilledByPlayer) {
- Bukkit.getPluginManager().registerEvents(new DeathListener(), DayNightPvP.getInstance());
- }
- }
-
-}
diff --git a/src/main/java/org/callvdois/daynightpvp/commands/CommandHandler.java b/src/main/java/org/callvdois/daynightpvp/commands/CommandManager.java
similarity index 70%
rename from src/main/java/org/callvdois/daynightpvp/commands/CommandHandler.java
rename to src/main/java/org/callvdois/daynightpvp/commands/CommandManager.java
index 59a5701..419d994 100644
--- a/src/main/java/org/callvdois/daynightpvp/commands/CommandHandler.java
+++ b/src/main/java/org/callvdois/daynightpvp/commands/CommandManager.java
@@ -1,12 +1,11 @@
package org.callvdois.daynightpvp.commands;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.commands.dnp.DnpCommand;
-
-public class CommandHandler {
+public class CommandManager {
public void register() {
+
DayNightPvP.getInstance().getCommand("daynightpvp").setExecutor(new DnpCommand());
- DayNightPvP.getInstance().getCommand("daynightpvp").setTabCompleter(new DnpCommand());
+ DayNightPvP.getInstance().getCommand("daynightpvp").setTabCompleter(new DnpTabCompleter());
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java b/src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java
new file mode 100644
index 0000000..910b8ae
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java
@@ -0,0 +1,55 @@
+package org.callvdois.daynightpvp.commands;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.FilesManager;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.gui.MainGui;
+import org.callvdois.daynightpvp.utils.PlayerUtils;
+import org.jetbrains.annotations.NotNull;
+
+public class DnpCommand implements CommandExecutor {
+
+ private final MainGui mainGui;
+ private final FilesManager filesManager;
+ private final LangManager langManager;
+
+ public DnpCommand() {
+ mainGui = new MainGui();
+ filesManager = new FilesManager();
+ langManager = new LangManager();
+ }
+
+ @Override
+ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
+ if (sender instanceof Player player) {
+ if (sender.hasPermission("dnp.admin")) {
+ if (args.length == 0) {
+ mainGui.open(player);
+ return true;
+ }
+ if (args.length == 1) {
+ if (args[0].equals("reload")) {
+ filesManager.reloadPlugin();
+ PlayerUtils.sendMessageToPlayer(player, langManager.getFeedbackReloadPlugin());
+ return true;
+ } else {
+ PlayerUtils.sendMessageToPlayer(player, langManager.getFeedbackNonExistentCommand());
+ return false;
+ }
+ }
+ return false;
+ } else {
+ PlayerUtils.sendMessageToPlayer(player, "§8[§e☀§8] §9DayNightPvP §8- §7v" + DayNightPvP.getInstance().getDescription().getVersion());
+ return false;
+ }
+ } else {
+ sender.sendMessage("This command can only be executed by players.");
+ return false;
+ }
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/commands/DnpTabCompleter.java b/src/main/java/org/callvdois/daynightpvp/commands/DnpTabCompleter.java
new file mode 100644
index 0000000..fb01944
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/commands/DnpTabCompleter.java
@@ -0,0 +1,17 @@
+package org.callvdois.daynightpvp.commands;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collections;
+import java.util.List;
+
+public class DnpTabCompleter implements TabCompleter {
+
+ @Override
+ public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
+ return Collections.emptyList();
+ }
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/commands/SubCommandHandler.java b/src/main/java/org/callvdois/daynightpvp/commands/SubCommandHandler.java
deleted file mode 100644
index 1adb65e..0000000
--- a/src/main/java/org/callvdois/daynightpvp/commands/SubCommandHandler.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.callvdois.daynightpvp.commands;
-
-import org.bukkit.command.CommandSender;
-
-public abstract class SubCommandHandler {
-
- public abstract void execute(CommandSender sender, String[] args);
-}
\ No newline at end of file
diff --git a/src/main/java/org/callvdois/daynightpvp/commands/dnp/DnpCommand.java b/src/main/java/org/callvdois/daynightpvp/commands/dnp/DnpCommand.java
deleted file mode 100644
index 60f7a45..0000000
--- a/src/main/java/org/callvdois/daynightpvp/commands/dnp/DnpCommand.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.callvdois.daynightpvp.commands.dnp;
-
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabCompleter;
-import org.callvdois.daynightpvp.commands.SubCommandHandler;
-import org.callvdois.daynightpvp.commands.dnp.reload.DnpReloadCommand;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class DnpCommand implements CommandExecutor, TabCompleter {
-
- private final Map subCommands = new HashMap<>();
-
- public DnpCommand() {
- registerSubCommands();
- }
-
- private void registerSubCommands() {
- subCommands.put("reload", new DnpReloadCommand());
- }
-
- @Override
- public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, String[] args) {
-
- if (args.length == 0) {
-
- sender.sendMessage("Mostra todos os comandos.");
- return false;
- }
-
- SubCommandHandler dnpSubCommand = subCommands.get(args[0]);
-
- if (dnpSubCommand == null) {
- sender.sendMessage("Subcomando não encontrado!");
- return false;
- }
-
- dnpSubCommand.execute(sender, args);
- return true;
- }
-
- @Override
- public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
- return Collections.emptyList();
- }
-}
diff --git a/src/main/java/org/callvdois/daynightpvp/commands/dnp/reload/DnpReloadCommand.java b/src/main/java/org/callvdois/daynightpvp/commands/dnp/reload/DnpReloadCommand.java
deleted file mode 100644
index 39e4078..0000000
--- a/src/main/java/org/callvdois/daynightpvp/commands/dnp/reload/DnpReloadCommand.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.callvdois.daynightpvp.commands.dnp.reload;
-
-import org.bukkit.command.CommandSender;
-import org.callvdois.daynightpvp.commands.SubCommandHandler;
-import org.callvdois.daynightpvp.files.LangFile;
-import org.callvdois.daynightpvp.services.PluginServices;
-
-public class DnpReloadCommand extends SubCommandHandler {
-
- private final LangFile langFile;
- private final PluginServices pluginServices;
-
- public DnpReloadCommand() {
- langFile = new LangFile();
- pluginServices = new PluginServices();
- }
-
- @Override
- public void execute(CommandSender sender, String[] args) {
- pluginServices.reloadPlugin();
- sender.sendMessage(langFile.getFeedbackReloadPlugin());
- }
-}
diff --git a/src/main/java/org/callvdois/daynightpvp/files/ConfigFile.java b/src/main/java/org/callvdois/daynightpvp/config/ConfigManager.java
similarity index 78%
rename from src/main/java/org/callvdois/daynightpvp/files/ConfigFile.java
rename to src/main/java/org/callvdois/daynightpvp/config/ConfigManager.java
index 0fa653a..01d9a8d 100644
--- a/src/main/java/org/callvdois/daynightpvp/files/ConfigFile.java
+++ b/src/main/java/org/callvdois/daynightpvp/config/ConfigManager.java
@@ -1,11 +1,10 @@
-package org.callvdois.daynightpvp.files;
+package org.callvdois.daynightpvp.config;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
import org.callvdois.daynightpvp.DayNightPvP;
import org.callvdois.daynightpvp.utils.ConsoleUtils;
@@ -13,56 +12,49 @@
import java.util.ArrayList;
import java.util.List;
-public class ConfigFile {
+public class ConfigManager {
- public static File fileLocation;
- public static FileConfiguration fileContent;
- private final ConsoleUtils consoleUtils;
-
- public ConfigFile() {
- consoleUtils = new ConsoleUtils();
- }
-
- public void createFile() {
- fileLocation = new File(DayNightPvP.getInstance().getDataFolder(), "config.yml");
- fileContent = YamlConfiguration.loadConfiguration(fileLocation);
- verifyFileVersion();
- }
-
- private void verifyFileVersion() {
- int lastestFileVersion = 16;
- if (lastestFileVersion != getVersion()) {
- resetFile();
- String fileOutdated = "[DayNightPvP] The \"config.yml\" file was an outdated version. it has been replaced by the new version.";
- consoleUtils.sendWarningMessage(fileOutdated);
- fileContent = YamlConfiguration.loadConfiguration(fileLocation);
- }
- }
+ public static File file;
+ public static FileConfiguration fileConfiguration;
public void setValue(String path, Object value) {
- fileContent.set(path, value);
+ fileConfiguration.set(path, value);
saveConfig();
}
public void saveConfig() {
try {
- fileContent.save(fileLocation);
+ fileConfiguration.save(file);
} catch (Exception e) {
- consoleUtils.sendWarningMessage("Error saving configuration file, resetting...");
- resetFile();
+ ConsoleUtils.warning("Error saving configuration file, resetting...");
+ resetFile("config.yml");
}
}
- public void resetFile() {
- DayNightPvP.getInstance().saveResource("config.yml", true);
+ public void resetFile(String fileName) {
+ DayNightPvP.getInstance().saveResource(fileName, true);
+ }
+
+ public void addWorld(String worldName) {
+ List worldList = getDayNightPvpWorlds();
+ worldList.add(Bukkit.getWorld(worldName));
+ fileConfiguration.set("daynightpvp.worlds", worldList);
+ saveConfig();
+ }
+
+ public void removeWorld(String worldName) {
+ List worldList = getDayNightPvpWorlds();
+ worldList.remove(Bukkit.getWorld(worldName));
+ fileConfiguration.set("daynightpvp.worlds", worldList);
+ saveConfig();
}
public int getInt(String path, Integer defaultValue) {
- String configValue = fileContent.getString(path);
+ String configValue = fileConfiguration.getString(path);
if (configValue == null) {
- resetFile();
+ resetFile("config.yml");
return defaultValue;
}
@@ -76,10 +68,10 @@ public int getInt(String path, Integer defaultValue) {
public Difficulty getDifficulty(String path, Difficulty defaultValue) {
- String configValue = fileContent.getString(path);
+ String configValue = fileConfiguration.getString(path);
if (configValue == null) {
- resetFile();
+ resetFile("config.yml");
return defaultValue;
}
@@ -93,10 +85,10 @@ public Difficulty getDifficulty(String path, Difficulty defaultValue) {
public Sound getSound(String path, Sound defaultValue) {
- String configValue = fileContent.getString(path);
+ String configValue = fileConfiguration.getString(path);
if (configValue == null) {
- resetFile();
+ resetFile("config.yml");
return defaultValue;
}
@@ -109,10 +101,10 @@ public Sound getSound(String path, Sound defaultValue) {
}
public String getString(String path, String defaultValue) {
- String configValue = fileContent.getString(path);
+ String configValue = fileConfiguration.getString(path);
if (configValue == null) {
- resetFile();
+ resetFile("config.yml");
return defaultValue;
}
@@ -120,10 +112,10 @@ public String getString(String path, String defaultValue) {
}
public boolean getBoolean(String path, Boolean defaultValue) {
- String configValue = fileContent.getString(path);
+ String configValue = fileConfiguration.getString(path);
if (configValue == null) {
- resetFile();
+ resetFile("config.yml");
return defaultValue;
}
@@ -137,12 +129,12 @@ public boolean getBoolean(String path, Boolean defaultValue) {
public List getWorldList(String path, List defaultValue) {
- List configValue = fileContent.getStringList(path);
+ List configValue = fileConfiguration.getStringList(path);
List worldList = new ArrayList<>();
// Se a lista de String estiver vazia, reseta a configuração e retorna o valor padrão.
if (configValue.isEmpty()) {
- resetFile();
+ resetFile("config.yml");
for (String worldName : defaultValue) {
if (Bukkit.getWorld(worldName) != null) {
@@ -163,7 +155,7 @@ public List getWorldList(String path, List defaultValue) {
}
public int getVersion() {
- return fileContent.getInt("version");
+ return fileConfiguration.getInt("version");
}
public boolean getUpdateChecker() {
diff --git a/src/main/java/org/callvdois/daynightpvp/config/FilesManager.java b/src/main/java/org/callvdois/daynightpvp/config/FilesManager.java
new file mode 100644
index 0000000..d070cdd
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/config/FilesManager.java
@@ -0,0 +1,101 @@
+package org.callvdois.daynightpvp.config;
+
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.events.EventsManager;
+import org.callvdois.daynightpvp.placeholder.PlaceholderManager;
+import org.callvdois.daynightpvp.service.ServiceManager;
+import org.callvdois.daynightpvp.utils.ConsoleUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class FilesManager {
+
+ public static List langFiles = new ArrayList<>();
+ private final int configVersion;
+ private final int langVersion;
+ private final String fileOutdated;
+ private final EventsManager eventsManager;
+ private final PlaceholderManager placeholderManager;
+ private final ConfigManager configManager;
+ private final LangManager langManager;
+ private final ServiceManager serviceManager;
+
+ public FilesManager() {
+ eventsManager = new EventsManager();
+ placeholderManager = new PlaceholderManager();
+ configManager = new ConfigManager();
+ langManager = new LangManager();
+ serviceManager = new ServiceManager();
+
+ fileOutdated = "[DayNightPvP] The {0} file was an outdated version. it has been replaced by the new version.";
+
+ configVersion = 16;
+ langVersion = 13;
+ langFiles = Arrays.asList("lang/en-US.yml", "lang/pt-BR.yml", "lang/es-ES.yml", "lang/ru-RU.yml");
+ }
+
+ public static FileConfiguration loadConfigFile(JavaPlugin plugin, String path) {
+ File file = new File(plugin.getDataFolder(), path);
+ if (!file.exists()) {
+ plugin.saveResource(path, false);
+ }
+ return YamlConfiguration.loadConfiguration(file);
+ }
+
+ public void verifyConfigVersion() {
+ if (!(configVersion == configManager.getVersion())) {
+ resetFile("config.yml");
+ ConsoleUtils.warning(fileOutdated.replace("{0}", "config.yml"));
+ ConfigManager.fileConfiguration = YamlConfiguration.loadConfiguration(ConfigManager.file);
+ }
+ }
+
+ public void verfiyLangsVersion() {
+ for (String fileName : langFiles) {
+ File langFile = new File(DayNightPvP.getInstance().getDataFolder(), fileName);
+
+ if (!(langVersion == langManager.getVersion())) {
+ resetFile("lang/" + langFile.getName());
+ ConsoleUtils.warning(fileOutdated.replace("{0}", "lang/" + langFile.getName()));
+ }
+ }
+ }
+
+ public void reloadPlugin() {
+ createFiles();
+ eventsManager.unregiser();
+ eventsManager.register();
+ placeholderManager.unregister();
+ placeholderManager.register();
+ serviceManager.stopServices();
+ serviceManager.startServices();
+ }
+
+ public void resetFile(String fileName) {
+ DayNightPvP.getInstance().saveResource(fileName, true);
+ }
+
+ public void createFiles() {
+ ConfigManager.file = new File(DayNightPvP.getInstance().getDataFolder(), "config.yml");
+ if (!ConfigManager.file.exists()) {
+ DayNightPvP.getInstance().saveResource("config.yml", false);
+ }
+ ConfigManager.fileConfiguration = YamlConfiguration.loadConfiguration(ConfigManager.file);
+ verifyConfigVersion();
+
+ for (String fileName : langFiles) {
+ if (!new File(DayNightPvP.getInstance().getDataFolder(), fileName).exists()) {
+ DayNightPvP.getInstance().saveResource(fileName, false);
+ }
+ }
+ langManager.getLanguageFileSelected();
+ verfiyLangsVersion();
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/files/LangFile.java b/src/main/java/org/callvdois/daynightpvp/config/LangManager.java
similarity index 77%
rename from src/main/java/org/callvdois/daynightpvp/files/LangFile.java
rename to src/main/java/org/callvdois/daynightpvp/config/LangManager.java
index 21bc813..b177f20 100644
--- a/src/main/java/org/callvdois/daynightpvp/files/LangFile.java
+++ b/src/main/java/org/callvdois/daynightpvp/config/LangManager.java
@@ -1,57 +1,25 @@
-package org.callvdois.daynightpvp.files;
+package org.callvdois.daynightpvp.config;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.utils.ConsoleUtils;
-import java.io.File;
+public class LangManager {
-public class LangFile {
+ public static FileConfiguration fileConfiguration;
+ private final ConfigManager configManager;
- private static File fileLocation;
- private static FileConfiguration fileContent;
- private final ConfigFile configFile;
- private final ConsoleUtils consoleUtils;
-
- public LangFile() {
- configFile = new ConfigFile();
- consoleUtils = new ConsoleUtils();
- }
-
- public void createFile() {
- String filePath = "lang/" + configFile.getLanguage() + ".yml";
- fileLocation = new File(DayNightPvP.getInstance().getDataFolder(), filePath);
-
- if (!fileLocation.exists()) {
- DayNightPvP.getInstance().saveResource(filePath, false);
- }
-
- loadFileContent();
- verifyFileVersion();
- }
-
- private void verifyFileVersion() {
- int latestFileVersion = 13;
- if (latestFileVersion != getVersion()) {
- resetFile();
- loadFileContent();
- String fileOutdated = "[DayNightPvP] The " + configFile.getLanguage() + ".yml file was an outdated version. It has been replaced by the new version.";
- consoleUtils.sendWarningMessage(fileOutdated);
- }
- }
-
- private void resetFile() {
- DayNightPvP.getInstance().saveResource("lang/" + configFile.getLanguage() + ".yml", true);
+ public LangManager() {
+ configManager = new ConfigManager();
}
- private void loadFileContent() {
- fileContent = YamlConfiguration.loadConfiguration(fileLocation);
+ public void getLanguageFileSelected() {
+ String pathLangFile = "lang/" + configManager.getLanguage() + ".yml";
+ fileConfiguration = FilesManager.loadConfigFile(DayNightPvP.getInstance(), pathLangFile);
}
private String formatMessage(String path) {
- String text = fileContent.getString(path);
+ String text = fileConfiguration.getString(path);
if (text != null) {
return ChatColor.translateAlternateColorCodes('&', text);
}
@@ -60,7 +28,7 @@ private String formatMessage(String path) {
// Version
public int getVersion() {
- return fileContent.getInt("version");
+ return fileConfiguration.getInt("version");
}
// Estados
diff --git a/src/main/java/org/callvdois/daynightpvp/Listeners/DamageListener.java b/src/main/java/org/callvdois/daynightpvp/events/DamageEvent.java
similarity index 61%
rename from src/main/java/org/callvdois/daynightpvp/Listeners/DamageListener.java
rename to src/main/java/org/callvdois/daynightpvp/events/DamageEvent.java
index cc8ef1f..a24fdc9 100644
--- a/src/main/java/org/callvdois/daynightpvp/Listeners/DamageListener.java
+++ b/src/main/java/org/callvdois/daynightpvp/events/DamageEvent.java
@@ -1,4 +1,4 @@
-package org.callvdois.daynightpvp.Listeners;
+package org.callvdois.daynightpvp.events;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -10,24 +10,22 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.files.ConfigFile;
-import org.callvdois.daynightpvp.files.LangFile;
-import org.callvdois.daynightpvp.griefprevention.GriefPreventionHandler;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.griefprevention.GriefManager;
import org.callvdois.daynightpvp.utils.WorldUtils;
-import org.callvdois.daynightpvp.worldguard.AllowDaytimePvpFlag;
+import org.callvdois.daynightpvp.worldguard.AllowPvpOnDayFlag;
-public class DamageListener implements Listener {
+public class DamageEvent implements Listener {
- private final GriefPreventionHandler griefPreventionHandler;
- private final ConfigFile configFile;
- private final LangFile langFile;
- private final WorldUtils worldUtils;
+ private final GriefManager griefManager;
+ private final ConfigManager configManager;
+ private final LangManager langManager;
- public DamageListener() {
- griefPreventionHandler = new GriefPreventionHandler();
- configFile = new ConfigFile();
- langFile = new LangFile();
- worldUtils = new WorldUtils();
+ public DamageEvent() {
+ griefManager = new GriefManager();
+ configManager = new ConfigManager();
+ langManager = new LangManager();
}
@EventHandler
@@ -38,8 +36,8 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (checkHooks(damagedPlayer, damager)) {
event.setCancelled(true);
- if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
- damager.sendMessage(langFile.getNotifyPvpDisabled());
+ if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
+ damager.sendMessage(langManager.getNotifyPvpDisabled());
}
}
}
@@ -52,8 +50,8 @@ public void onProjectileHitEvent(ProjectileHitEvent event) {
if (checkHooks(damagedPlayer, damager)) {
event.setCancelled(true);
- if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
- damager.sendMessage(langFile.getNotifyPvpDisabled());
+ if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
+ damager.sendMessage(langManager.getNotifyPvpDisabled());
}
}
@@ -70,8 +68,8 @@ public void onPotionSplash(PotionSplashEvent event) {
if (event.getAffectedEntities().contains(damagedPlayer) && damagedPlayer != damager) {
if (checkHooks(damagedPlayer, damager)) {
event.setIntensity(damagedPlayer, 0.0);
- if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
- damager.sendMessage(langFile.getNotifyPvpDisabled());
+ if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
+ damager.sendMessage(langManager.getNotifyPvpDisabled());
}
}
}
@@ -93,13 +91,13 @@ private boolean checkHooks(Player damagedPlayer, Player damager) {
if (damager.hasPermission("dnp.bypasspvp")) {
return false;
}
- if (DayNightPvP.worldGuardIsPresent && AllowDaytimePvpFlag.checkStateOnPosition(damagedPlayer) && AllowDaytimePvpFlag.checkStateOnPosition(damager)) {
+ if (DayNightPvP.worldGuardIsPresent && AllowPvpOnDayFlag.checkState(damagedPlayer) && AllowPvpOnDayFlag.checkState(damager)) {
return false;
}
- if (DayNightPvP.griefIsPresent && !configFile.getGriefPreventionPvpInLandEnabled() && griefPreventionHandler.verify(damagedPlayer, damager)) {
+ if (DayNightPvP.griefIsPresent && !configManager.getGriefPreventionPvpInLandEnabled() && griefManager.verify(damagedPlayer, damager)) {
return true;
}
- return worldUtils.checkPlayerIsInWorld(damagedPlayer);
+ return WorldUtils.checkPlayerIsInWorld(damagedPlayer);
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/Listeners/DeathListener.java b/src/main/java/org/callvdois/daynightpvp/events/DeathEvent.java
similarity index 74%
rename from src/main/java/org/callvdois/daynightpvp/Listeners/DeathListener.java
rename to src/main/java/org/callvdois/daynightpvp/events/DeathEvent.java
index 5626dab..ffa0e32 100644
--- a/src/main/java/org/callvdois/daynightpvp/Listeners/DeathListener.java
+++ b/src/main/java/org/callvdois/daynightpvp/events/DeathEvent.java
@@ -1,4 +1,4 @@
-package org.callvdois.daynightpvp.Listeners;
+package org.callvdois.daynightpvp.events;
import org.bukkit.Bukkit;
import org.bukkit.World;
@@ -8,20 +8,18 @@
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.files.ConfigFile;
+import org.callvdois.daynightpvp.config.ConfigManager;
import org.callvdois.daynightpvp.utils.SearchUtils;
import org.callvdois.daynightpvp.vault.LoseMoneyOnDeath;
import java.util.List;
-public class DeathListener implements Listener {
+public class DeathEvent implements Listener {
- private final ConfigFile configFile;
- private final SearchUtils searchUtils;
+ private final ConfigManager configManager;
- public DeathListener() {
- configFile = new ConfigFile();
- searchUtils = new SearchUtils();
+ public DeathEvent() {
+ configManager = new ConfigManager();
}
@EventHandler
@@ -29,11 +27,11 @@ public void onPlayerDeath(PlayerDeathEvent event) {
Player killed = event.getEntity();
Player killer = event.getEntity().getKiller();
World world = event.getEntity().getWorld();
- List worldList = configFile.getDayNightPvpWorlds();
+ List worldList = configManager.getDayNightPvpWorlds();
- if (configFile.getPvpKeepInventoryWhenKilledByPlayer()) {
+ if (configManager.getPvpKeepInventoryWhenKilledByPlayer()) {
if (killer != null) {
- if (searchUtils.worldExistsInWorldList(worldList, world.getName())) {
+ if (SearchUtils.worldExistsInWorldList(worldList, world.getName())) {
event.setKeepInventory(true);
event.getDrops().clear();
event.setKeepLevel(true);
@@ -42,7 +40,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
}
Bukkit.getScheduler().runTaskAsynchronously(DayNightPvP.getInstance(), () -> {
- if (configFile.getVaultLoseMoneyOnDeathEnabled() && DayNightPvP.vaultIsPresent) {
+ if (configManager.getVaultLoseMoneyOnDeathEnabled() && DayNightPvP.vaultIsPresent) {
if (killer != null) {
for (PermissionAttachmentInfo permission : event.getEntity().getEffectivePermissions()) {
if (permission.getPermission().startsWith("dnp.losemoney")) {
diff --git a/src/main/java/org/callvdois/daynightpvp/events/EventsManager.java b/src/main/java/org/callvdois/daynightpvp/events/EventsManager.java
new file mode 100644
index 0000000..3388cd2
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/events/EventsManager.java
@@ -0,0 +1,53 @@
+package org.callvdois.daynightpvp.events;
+
+import org.bukkit.Bukkit;
+import org.bukkit.event.HandlerList;
+import org.bukkit.plugin.PluginManager;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.ConfigManager;
+
+public class EventsManager {
+
+ private final PluginManager pluginManager;
+ private final ConfigManager configManager;
+
+ public EventsManager() {
+ pluginManager = Bukkit.getPluginManager();
+ configManager = new ConfigManager();
+ }
+
+ public void register() {
+ registerJoinEvent();
+ registerEntityEvent();
+ registerDeathEvent();
+ registerInventoryEvent();
+ }
+
+ public void unregiser() {
+ HandlerList.unregisterAll(DayNightPvP.getInstance());
+ }
+
+ private void registerInventoryEvent() {
+ pluginManager.registerEvents(new InventoryEvent(), DayNightPvP.getInstance());
+ }
+
+ private void registerJoinEvent() {
+ if (configManager.getUpdateChecker()) {
+ pluginManager.registerEvents(new JoinEvent(), DayNightPvP.getInstance());
+ }
+ }
+
+ private void registerEntityEvent() {
+ pluginManager.registerEvents(new DamageEvent(), DayNightPvP.getInstance());
+ }
+
+ private void registerDeathEvent() {
+ boolean vaultLoseMoneyOnDeath = configManager.getVaultLoseMoneyOnDeathEnabled();
+ boolean keepInventoryWhenKilledByPlayer = configManager.getPvpKeepInventoryWhenKilledByPlayer();
+
+ if (vaultLoseMoneyOnDeath || keepInventoryWhenKilledByPlayer) {
+ pluginManager.registerEvents(new DeathEvent(), DayNightPvP.getInstance());
+ }
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/events/InventoryEvent.java b/src/main/java/org/callvdois/daynightpvp/events/InventoryEvent.java
new file mode 100644
index 0000000..e180af5
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/events/InventoryEvent.java
@@ -0,0 +1,139 @@
+package org.callvdois.daynightpvp.events;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Sound;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.inventory.ItemStack;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.FilesManager;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.gui.LanguageGui;
+import org.callvdois.daynightpvp.gui.MainGui;
+import org.callvdois.daynightpvp.gui.WorldGui;
+import org.callvdois.daynightpvp.gui.WorldsGui;
+import org.callvdois.daynightpvp.utils.ItemUtils;
+import org.callvdois.daynightpvp.utils.PlayerUtils;
+import org.callvdois.daynightpvp.utils.SearchUtils;
+import org.callvdois.daynightpvp.utils.WorldUtils;
+
+import java.io.File;
+
+public class InventoryEvent implements Listener {
+
+ private final FilesManager filesManager;
+ private final LanguageGui languageGui;
+ private final MainGui mainGui;
+ private final WorldGui worldGui;
+ private final WorldsGui worldsGui;
+ private final ConfigManager configManager;
+ private final LangManager langManager;
+
+ public InventoryEvent() {
+ filesManager = new FilesManager();
+ languageGui = new LanguageGui();
+ mainGui = new MainGui();
+ worldGui = new WorldGui();
+ worldsGui = new WorldsGui();
+ configManager = new ConfigManager();
+ langManager = new LangManager();
+ }
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent event) {
+ ItemStack clickedItem = event.getCurrentItem();
+ String title = event.getView().getTitle();
+ if (title.equals(MainGui.inventoryTitle) || title.equals(WorldsGui.inventoryTitle) || title.equals(WorldGui.inventoryTitle)) {
+
+ if (clickedItem == null) {
+ return;
+ }
+
+ event.setCancelled(true);
+ String itemID = ItemUtils.getID(clickedItem);
+
+
+ Player player = (Player) event.getWhoClicked();
+ String worldName = event.getInventory().getItem(4).getItemMeta().getDisplayName();
+
+ switch (itemID) {
+ case "worldsButton":
+ worldsGui.open(player);
+ break;
+ case "reloadButton":
+ filesManager.reloadPlugin();
+ PlayerUtils.sendMessageToPlayer(player, langManager.getFeedbackReloadPlugin());
+ break;
+ case "languageButton":
+ languageGui.open(player);
+ break;
+ case "backButton":
+ mainGui.open(player);
+ break;
+ case "backToWorldsButton":
+ worldsGui.open(player);
+ break;
+ case "exitButton":
+ player.closeInventory();
+ break;
+ case "dayButton":
+ WorldUtils.setTime(worldName, 1000);
+ PlayerUtils.playSoundToPlayer(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP);
+ break;
+ case "nightButton":
+ WorldUtils.setTime(worldName, configManager.getDayNightPvpDayEnd());
+ PlayerUtils.playSoundToPlayer(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP);
+ break;
+ case "setAutomaticPvpOn":
+ configManager.addWorld(worldName);
+ filesManager.reloadPlugin();
+ PlayerUtils.playSoundToPlayer(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP);
+ break;
+ case "setAutomaticPvpOff":
+ configManager.removeWorld(worldName);
+ filesManager.reloadPlugin();
+ PlayerUtils.playSoundToPlayer(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP);
+ break;
+ }
+ if (SearchUtils.worldExistsInWorldList(Bukkit.getWorlds(), itemID)) {
+ World world = Bukkit.getWorld(itemID);
+ if (world != null) {
+ if (world.getEnvironment().equals(World.Environment.NORMAL)) {
+ worldGui.open(player, world);
+ }
+ }
+ }
+
+ File folder = new File(DayNightPvP.getInstance().getDataFolder() + "/lang");
+ File[] listOfFiles = folder.listFiles();
+ assert listOfFiles != null;
+ if (SearchUtils.fileExistsInFileList(listOfFiles, itemID)) {
+ PlayerUtils.playSoundToPlayer(player, Sound.BLOCK_NOTE_BLOCK_HAT);
+
+ configManager.setValue("language", itemID);
+ langManager.getLanguageFileSelected();
+
+ player.sendMessage(langManager.getFeedbackSelectLang().replace("{0}", itemID));
+
+ mainGui.open(player);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onInventoryClose(InventoryCloseEvent event) {
+ String title = event.getView().getTitle();
+ if (title.equals(WorldGui.inventoryTitle)) {
+ WorldGui.task.cancel();
+ }
+ if (title.equals(WorldsGui.inventoryTitle)) {
+ WorldsGui.task.cancel();
+ }
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/Listeners/JoinListener.java b/src/main/java/org/callvdois/daynightpvp/events/JoinEvent.java
similarity index 54%
rename from src/main/java/org/callvdois/daynightpvp/Listeners/JoinListener.java
rename to src/main/java/org/callvdois/daynightpvp/events/JoinEvent.java
index d25cd10..ba296e6 100644
--- a/src/main/java/org/callvdois/daynightpvp/Listeners/JoinListener.java
+++ b/src/main/java/org/callvdois/daynightpvp/events/JoinEvent.java
@@ -1,23 +1,23 @@
-package org.callvdois.daynightpvp.Listeners;
+package org.callvdois.daynightpvp.events;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.services.UpdateServices;
+import org.callvdois.daynightpvp.service.UpdateChecker;
-public class JoinListener implements Listener {
- private final UpdateServices updateServices;
+public class JoinEvent implements Listener {
+ private final UpdateChecker updateChecker;
- public JoinListener() {
- updateServices = new UpdateServices();
+ public JoinEvent() {
+ updateChecker = new UpdateChecker();
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (event.getPlayer().hasPermission("dnp.admin")) {
- Bukkit.getServer().getScheduler().runTaskLater(DayNightPvP.getInstance(), () -> updateServices.checkUpdate(event), 100);
+ Bukkit.getServer().getScheduler().runTaskLater(DayNightPvP.getInstance(), () -> updateChecker.checkUpdate(event), 100);
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefPreventionHandler.java b/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefManager.java
similarity index 54%
rename from src/main/java/org/callvdois/daynightpvp/griefprevention/GriefPreventionHandler.java
rename to src/main/java/org/callvdois/daynightpvp/griefprevention/GriefManager.java
index e1fd317..6f4ab37 100644
--- a/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefPreventionHandler.java
+++ b/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefManager.java
@@ -3,11 +3,14 @@
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.entity.Player;
-public class GriefPreventionHandler {
+public class GriefManager {
public boolean verify(Player damagedPlayer, Player damager) {
- return GriefPrevention.instance.dataStore.getClaimAt(damagedPlayer.getLocation(), true, null) != null ||
- GriefPrevention.instance.dataStore.getClaimAt(damager.getLocation(), true, null) != null;
+ if (GriefPrevention.instance.dataStore.getClaimAt(damagedPlayer.getLocation(), true, null) != null ||
+ GriefPrevention.instance.dataStore.getClaimAt(damager.getLocation(), true, null) != null) {
+ return true;
+ }
+ return false;
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java b/src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java
new file mode 100644
index 0000000..759af24
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java
@@ -0,0 +1,55 @@
+package org.callvdois.daynightpvp.gui;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.utils.ItemUtils;
+
+import java.io.File;
+
+public class LanguageGui {
+
+ private final LangManager langManager;
+
+ public LanguageGui() {
+ langManager = new LangManager();
+ }
+
+ public void open(Player player) {
+ Inventory inventory = Bukkit.createInventory(player, 18, MainGui.inventoryTitle);
+
+ File folder = new File(DayNightPvP.getInstance().getDataFolder() + "/lang");
+ File[] listOfFiles = folder.listFiles();
+ assert listOfFiles != null;
+ int position = 0;
+
+ for (File file : listOfFiles) {
+ String[] name = file.getName().split("\\.");
+ ItemStack item = ItemUtils.createItem(ChatColor.YELLOW + name[0], name[0], langManager.getGuiLanguageButtonDescription().replace("{0}", ChatColor.YELLOW + name[0]), Material.PAPER);
+ inventory.setItem(position, item);
+
+ position++;
+ }
+
+ ItemStack backButton = ItemUtils.createCustomHead(langManager.getGuiBackButton(), "backButton", langManager.getGuiBackButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmIwZjZlOGFmNDZhYzZmYWY4ODkxNDE5MWFiNjZmMjYxZDY3MjZhNzk5OWM2MzdjZjJlNDE1OWZlMWZjNDc3In19fQ==");
+ ItemStack exitButton = ItemUtils.createCustomHead(langManager.getGuiExitButton(), "exitButton", langManager.getGuiExitButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTkxOWQxNTk0YmY4MDlkYjdiNDRiMzc4MmJmOTBhNjlmNDQ5YTg3Y2U1ZDE4Y2I0MGViNjUzZmRlYzI3MjIifX19");
+ ItemStack separatorGlass = ItemUtils.createItem(ChatColor.RED + "###", "nothing", " ", Material.GRAY_STAINED_GLASS_PANE);
+
+ inventory.setItem(16, backButton);
+ inventory.setItem(17, exitButton);
+
+ for (int slot = 0; slot < inventory.getSize(); slot++) {
+ if (inventory.getItem(slot) == null) {
+ inventory.setItem(slot, separatorGlass);
+ }
+ }
+
+ player.openInventory(inventory);
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/gui/MainGui.java b/src/main/java/org/callvdois/daynightpvp/gui/MainGui.java
new file mode 100644
index 0000000..f6b4257
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/gui/MainGui.java
@@ -0,0 +1,45 @@
+package org.callvdois.daynightpvp.gui;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.utils.ItemUtils;
+
+public class MainGui {
+
+ public static String inventoryTitle;
+ private final LangManager langManager;
+
+ public MainGui() {
+ inventoryTitle = "§c§l» DayNightPvP";
+ langManager = new LangManager();
+ }
+
+ public void open(Player player) {
+
+ Inventory inventory = Bukkit.createInventory(player, 9, inventoryTitle);
+
+ ItemStack worldsButton = ItemUtils.createCustomHead(langManager.getGuiWorldsButton(), "worldsButton", langManager.getGuiWorldsButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDM4Y2YzZjhlNTRhZmMzYjNmOTFkMjBhNDlmMzI0ZGNhMTQ4NjAwN2ZlNTQ1Mzk5MDU1NTI0YzE3OTQxZjRkYyJ9fX0=");
+ ItemStack separatorGlass = ItemUtils.createItem(ChatColor.RED + "###", "nothing", " ", Material.GRAY_STAINED_GLASS_PANE);
+ ItemStack languageButton = ItemUtils.createItem(langManager.getGuiLanguagesButton(), "languageButton", langManager.getGuiLanguagesButtonDescription(), Material.PAPER);
+ ItemStack reloadButon = ItemUtils.createCustomHead(langManager.getGuiReloadButton(), "reloadButton", langManager.getGuiReloadButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjk3ZDZkN2JlOTg1ZDA2MjJhNDhlOTA2OThlOTA3M2Y3ZmY4ODEzMjkyODEyZWJkMTczMGRiYTBlMDFjZjE4ZiJ9fX0=");
+ ItemStack exitButton = ItemUtils.createCustomHead(langManager.getGuiExitButton(), "exitButton", langManager.getGuiExitButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTkxOWQxNTk0YmY4MDlkYjdiNDRiMzc4MmJmOTBhNjlmNDQ5YTg3Y2U1ZDE4Y2I0MGViNjUzZmRlYzI3MjIifX19");
+
+ inventory.setItem(0, worldsButton);
+ inventory.setItem(1, separatorGlass);
+ inventory.setItem(2, separatorGlass);
+ inventory.setItem(3, separatorGlass);
+ inventory.setItem(4, separatorGlass);
+ inventory.setItem(5, separatorGlass);
+ inventory.setItem(6, languageButton);
+ inventory.setItem(7, reloadButon);
+ inventory.setItem(8, exitButton);
+
+ player.openInventory(inventory);
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/gui/WorldGui.java b/src/main/java/org/callvdois/daynightpvp/gui/WorldGui.java
new file mode 100644
index 0000000..ba84c04
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/gui/WorldGui.java
@@ -0,0 +1,116 @@
+package org.callvdois.daynightpvp.gui;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.utils.ItemUtils;
+import org.callvdois.daynightpvp.utils.SearchUtils;
+
+import java.util.List;
+
+public class WorldGui {
+
+ public static BukkitTask task;
+ public static String inventoryTitle;
+ private final Inventory inventory;
+ private final LangManager langManager;
+ private final ConfigManager configManager;
+
+ public WorldGui() {
+ langManager = new LangManager();
+ configManager = new ConfigManager();
+ inventoryTitle = "§c§l» DayNightPvP (World)";
+ inventory = Bukkit.createInventory(null, 18, inventoryTitle);
+ }
+
+ public void open(Player player, World world) {
+
+ ItemStack backButton = ItemUtils.createCustomHead(langManager.getGuiBackButton(), "backToWorldsButton", langManager.getGuiBackButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmIwZjZlOGFmNDZhYzZmYWY4ODkxNDE5MWFiNjZmMjYxZDY3MjZhNzk5OWM2MzdjZjJlNDE1OWZlMWZjNDc3In19fQ==");
+ ItemStack exitButton = ItemUtils.createCustomHead(langManager.getGuiExitButton(), "exitButton", langManager.getGuiExitButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTkxOWQxNTk0YmY4MDlkYjdiNDRiMzc4MmJmOTBhNjlmNDQ5YTg3Y2U1ZDE4Y2I0MGViNjUzZmRlYzI3MjIifX19");
+ ItemStack dayButton = ItemUtils.createCustomHead(langManager.getGuiDayButton(), "dayButton", langManager.getGuiDayButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjg5MDQyMDgyYmI3YTc2MThiNzg0ZWU3NjA1YTEzNGM1ODgzNGUyMWUzNzRjODg4OTM3MTYxMDU3ZjZjNyJ9fX0=");
+ ItemStack nightButton = ItemUtils.createCustomHead(langManager.getGuiNightButton(), "nightButton", langManager.getGuiNightButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdkNjhiYjE0NGUxNTlmZmRiMGJiMmFiZGQ1ODNmZjM4OWFlNzEwNjgyY2E3N2U2NTM1MzkzYWUyMjEzN2EifX19");
+ ItemStack separatorGlass = ItemUtils.createItem(ChatColor.RED + "###", "nothing", " ", Material.GRAY_STAINED_GLASS_PANE);
+
+ if (world.getEnvironment() == World.Environment.NORMAL) {
+ inventory.setItem(3, dayButton);
+ inventory.setItem(5, nightButton);
+ }
+
+ inventory.setItem(9, backButton);
+ inventory.setItem(17, exitButton);
+
+ for (int slot = 0; slot < inventory.getSize(); slot++) {
+ if (inventory.getItem(slot) == null) {
+ inventory.setItem(slot, separatorGlass);
+ }
+ }
+
+ player.openInventory(inventory);
+ updateTask(world, inventory);
+ }
+
+ public void updateTask(World world, Inventory inventory) {
+
+ task = new BukkitRunnable() {
+ @Override
+ public void run() {
+ refreshGui(inventory, world);
+ }
+ }.runTaskTimer(DayNightPvP.getInstance(), 0L, 10L);
+ }
+
+ public String verifyTimeOnWorld(long time) {
+ if (time >= configManager.getDayNightPvpDayEnd()) {
+ return langManager.getGuiWorldButtonDescriptionNight();
+ } else {
+ return langManager.getGuiWorldButtonDescriptionDay();
+ }
+ }
+
+ public String verifyAutomaticPvpStatus(List list, String worldName) {
+ if (SearchUtils.worldExistsInWorldList(list, worldName)) {
+ return langManager.getStateEnabled();
+ } else {
+ return langManager.getStateDisabled();
+ }
+ }
+
+ public ItemStack defineAutomaticPvpPanel(String worldName) {
+ if (SearchUtils.worldExistsInWorldList(configManager.getDayNightPvpWorlds(), worldName)) {
+ return ItemUtils.createItem(langManager.getGuiDayNightPvpButton(), "setAutomaticPvpOff", langManager.getActionButtonClickToDisable(), Material.GREEN_STAINED_GLASS_PANE);
+ } else {
+ return ItemUtils.createItem(langManager.getGuiDayNightPvpButton(), "setAutomaticPvpOn", langManager.getActionButtonClickToEnable(), Material.RED_STAINED_GLASS_PANE);
+ }
+ }
+
+ public ItemStack defineWorldItem(World world, String automaticPvpStatus, String timeStatus) {
+ if (world.getEnvironment() == World.Environment.NORMAL) {
+ return ItemUtils.createCustomHead(world.getName(), world.getName(), langManager.getGuiWorldButtonDescriptionDayNightPvp().replace("{0}", automaticPvpStatus) + "|" + "§3§l» §7Status: §b" + timeStatus, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzIyODM5ZDVjN2ZjMDY3ODA2MmYxYzZjOGYyN2IzMzIwOTQzODRlM2JiNWM0YjVlYmQxNjc2YjI3OWIwNmJmIn19fQ==");
+ } else {
+ return ItemUtils.createCustomHead(world.getName(), world.getName(), langManager.getGuiWorldButtonDescriptionDayNightPvp().replace("{0}", langManager.getGuiWorldButtonDescriptionNotSupported()) + "|" + "§3§l» §7Status: §b" + timeStatus, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzIyODM5ZDVjN2ZjMDY3ODA2MmYxYzZjOGYyN2IzMzIwOTQzODRlM2JiNWM0YjVlYmQxNjc2YjI3OWIwNmJmIn19fQ==");
+ }
+ }
+
+ public void refreshGui(Inventory inventory, World world) {
+ String worldName = world.getName();
+ String automaticPvpStatus = verifyAutomaticPvpStatus(configManager.getDayNightPvpWorlds(), worldName);
+
+ String timeStatus = verifyTimeOnWorld(world.getTime());
+ ItemStack worldItem = defineWorldItem(world, automaticPvpStatus, timeStatus);
+
+ ItemStack automaticPvpPanel = defineAutomaticPvpPanel(worldName);
+
+ inventory.setItem(13, automaticPvpPanel);
+ inventory.setItem(4, worldItem);
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/gui/WorldsGui.java b/src/main/java/org/callvdois/daynightpvp/gui/WorldsGui.java
new file mode 100644
index 0000000..1373dc6
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/gui/WorldsGui.java
@@ -0,0 +1,124 @@
+package org.callvdois.daynightpvp.gui;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.utils.ItemUtils;
+import org.callvdois.daynightpvp.utils.SearchUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WorldsGui {
+
+ public static BukkitTask task;
+ public static String inventoryTitle;
+ private final LangManager langManager;
+ private final ConfigManager configManager;
+ private Inventory inventory;
+
+ public WorldsGui() {
+ inventoryTitle = "§c§l» DayNightPvP (Worlds)";
+ langManager = new LangManager();
+ configManager = new ConfigManager();
+ }
+
+ public void open(Player player) {
+ inventory = Bukkit.createInventory(player, 27, inventoryTitle);
+
+ ItemStack backButton = ItemUtils.createCustomHead(langManager.getGuiBackButton(), "backButton", langManager.getGuiBackButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmIwZjZlOGFmNDZhYzZmYWY4ODkxNDE5MWFiNjZmMjYxZDY3MjZhNzk5OWM2MzdjZjJlNDE1OWZlMWZjNDc3In19fQ==");
+ ItemStack exitButton = ItemUtils.createCustomHead(langManager.getGuiExitButton(), "exitButton", langManager.getGuiExitButtonDescription(), "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTkxOWQxNTk0YmY4MDlkYjdiNDRiMzc4MmJmOTBhNjlmNDQ5YTg3Y2U1ZDE4Y2I0MGViNjUzZmRlYzI3MjIifX19");
+
+ inventory.setItem(25, backButton);
+ inventory.setItem(26, exitButton);
+
+ player.openInventory(inventory);
+ updateTask();
+ }
+
+ public void updateTask() {
+ task = new BukkitRunnable() {
+ @Override
+ public void run() {
+ refreshGui(inventory);
+ }
+ }.runTaskTimer(DayNightPvP.getInstance(), 0L, 20L);
+ }
+
+ public String verifyAutomaticPvpStatus(List list, String worldName) {
+ if (SearchUtils.worldExistsInWorldList(list, worldName)) {
+ return langManager.getStateEnabled();
+ } else {
+ return langManager.getStateDisabled();
+ }
+ }
+
+ public String verifyTimeOnWorld(long time) {
+ if (time > configManager.getDayNightPvpDayEnd()) {
+ return langManager.getGuiWorldButtonDescriptionNight();
+ } else {
+ return langManager.getGuiWorldButtonDescriptionDay();
+ }
+ }
+
+ private ItemStack defineWorldItem(World world, String automaticPvpStatus, String timeStatus) {
+ List description = new ArrayList<>();
+ World.Environment worldEnvironment = world.getEnvironment();
+ if (worldEnvironment != World.Environment.NORMAL) {
+ description.add(langManager.getGuiWorldButtonDescriptionDayNightPvp().replace("{0}", langManager.getGuiWorldButtonDescriptionNotSupported()));
+ description.add(langManager.getGuiWorldButtonDescriptionType().replace("{0}", ChatColor.AQUA + worldEnvironment.toString().toLowerCase()));
+ String headUrl;
+ if (world.getEnvironment() == World.Environment.NETHER) {
+ headUrl = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzkzYmZjNDMxOTAwNzIzZjdmYTI4Nzg2NDk2MzgwMTdjZTYxNWQ4ZDhjYWI4ZDJmMDcwYTYxZWIxYWEwMGQwMiJ9fX0=";
+ } else {
+ headUrl = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTlmMjFmNWQ4ODMzMTZmZDY1YTkzNjZmMzJhMzMwMTMxODJlMzM4MWRlYzIxYzE3Yzc4MzU1ZDliZjRmMCJ9fX0=";
+ }
+ return ItemUtils.createCustomHeadExtendedDescription(world.getName(), world.getName(), description, headUrl);
+ } else {
+ description.add(langManager.getGuiWorldButtonDescriptionDayNightPvp().replace("{0}", automaticPvpStatus));
+ description.add(langManager.getGuiWorldButtonDescriptionTime().replace("{0}", timeStatus));
+ description.add(langManager.getGuiWorldButtonDescriptionType().replace("{0}", ChatColor.AQUA + worldEnvironment.toString().toLowerCase()));
+ description.add("");
+ description.add(langManager.getActionButtonClickToSeeSettings());
+ return ItemUtils.createCustomHeadExtendedDescription(world.getName(), world.getName(), description, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzIyODM5ZDVjN2ZjMDY3ODA2MmYxYzZjOGYyN2IzMzIwOTQzODRlM2JiNWM0YjVlYmQxNjc2YjI3OWIwNmJmIn19fQ==");
+ }
+ }
+
+ public void refreshGui(Inventory inventory) {
+
+ for (int i = 0; i <= 24; i++) {
+ inventory.clear(i);
+ }
+
+ List worldsInServer = Bukkit.getServer().getWorlds();
+ int position = 0;
+
+ for (World world : worldsInServer) {
+ String worldName = world.getName();
+ String automaticPvpStatus = verifyAutomaticPvpStatus(configManager.getDayNightPvpWorlds(), worldName);
+ String timeStatus = verifyTimeOnWorld(world.getTime());
+ ItemStack worldItem = defineWorldItem(world, automaticPvpStatus, timeStatus);
+
+ inventory.setItem(position, worldItem);
+ position++;
+ }
+
+ ItemStack separatorGlass = ItemUtils.createItem(ChatColor.RED + "###", "nothing", " ", Material.GRAY_STAINED_GLASS_PANE);
+
+ for (int slot = 0; slot < inventory.getSize(); slot++) {
+ if (inventory.getItem(slot) == null) {
+ inventory.setItem(slot, separatorGlass);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/metrics/MetricsHandler.java b/src/main/java/org/callvdois/daynightpvp/metrics/MetricsHandler.java
deleted file mode 100644
index a604bb7..0000000
--- a/src/main/java/org/callvdois/daynightpvp/metrics/MetricsHandler.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.callvdois.daynightpvp.metrics;
-
-import org.callvdois.daynightpvp.DayNightPvP;
-
-public class MetricsHandler {
-
- public void start() {
- int bStatsID = 19067;
- new Metrics(DayNightPvP.getInstance(), bStatsID);
- }
-
-}
diff --git a/src/main/java/org/callvdois/daynightpvp/metrics/MetricsManager.java b/src/main/java/org/callvdois/daynightpvp/metrics/MetricsManager.java
new file mode 100644
index 0000000..dcec4a4
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/metrics/MetricsManager.java
@@ -0,0 +1,11 @@
+package org.callvdois.daynightpvp.metrics;
+
+import org.callvdois.daynightpvp.DayNightPvP;
+
+public class MetricsManager {
+
+ public void register() {
+ new Metrics(DayNightPvP.getInstance(), 19067);
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderHandler.java b/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderManager.java
similarity index 92%
rename from src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderHandler.java
rename to src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderManager.java
index c237d70..212c679 100644
--- a/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderHandler.java
+++ b/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderManager.java
@@ -2,7 +2,7 @@
import org.callvdois.daynightpvp.DayNightPvP;
-public class PlaceholderHandler {
+public class PlaceholderManager {
public void register() {
if (DayNightPvP.placeHolderIsPresent) {
diff --git a/src/main/java/org/callvdois/daynightpvp/placeholder/PvpStatusPlaceholder.java b/src/main/java/org/callvdois/daynightpvp/placeholder/PvpStatusPlaceholder.java
index e50e304..f49976d 100644
--- a/src/main/java/org/callvdois/daynightpvp/placeholder/PvpStatusPlaceholder.java
+++ b/src/main/java/org/callvdois/daynightpvp/placeholder/PvpStatusPlaceholder.java
@@ -5,21 +5,19 @@
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.files.ConfigFile;
-import org.callvdois.daynightpvp.files.LangFile;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.LangManager;
import org.callvdois.daynightpvp.utils.SearchUtils;
import org.jetbrains.annotations.NotNull;
public class PvpStatusPlaceholder extends PlaceholderExpansion {
- private final LangFile langFile;
- private final ConfigFile configFile;
- private final SearchUtils searchUtils;
+ private final LangManager langManager;
+ private final ConfigManager configManager;
public PvpStatusPlaceholder() {
- langFile = new LangFile();
- configFile = new ConfigFile();
- searchUtils = new SearchUtils();
+ langManager = new LangManager();
+ configManager = new ConfigManager();
}
@@ -50,13 +48,13 @@ public String onPlaceholderRequest(Player player, String params) {
boolean pvpStatus;
World world = player.getWorld();
- if (searchUtils.worldExistsInWorldList(configFile.getDayNightPvpWorlds(), world.getName())) {
+ if (SearchUtils.worldExistsInWorldList(configManager.getDayNightPvpWorlds(), world.getName())) {
long time = world.getTime();
- pvpStatus = time >= configFile.getDayNightPvpDayEnd();
+ pvpStatus = time >= configManager.getDayNightPvpDayEnd();
} else {
- return langFile.getFeedbackError();
+ return langManager.getFeedbackError();
}
- return pvpStatus ? langFile.getPlaceholderPvpEnabled() : langFile.getPlaceholderPvpDisabled();
+ return pvpStatus ? langManager.getPlaceholderPvpEnabled() : langManager.getPlaceholderPvpDisabled();
}
if (params.startsWith("pvpstatus_")) {
@@ -64,14 +62,14 @@ public String onPlaceholderRequest(Player player, String params) {
String worldName = params.substring("pvpstatus_".length());
World world = Bukkit.getWorld(worldName);
if (world != null) {
- if (searchUtils.worldExistsInWorldList(configFile.getDayNightPvpWorlds(), world.getName())) {
+ if (SearchUtils.worldExistsInWorldList(configManager.getDayNightPvpWorlds(), world.getName())) {
long time = world.getTime();
- pvpStatus = time >= configFile.getDayNightPvpDayEnd();
- return pvpStatus ? langFile.getPlaceholderPvpEnabled() : langFile.getPlaceholderPvpDisabled();
+ pvpStatus = time >= configManager.getDayNightPvpDayEnd();
+ return pvpStatus ? langManager.getPlaceholderPvpEnabled() : langManager.getPlaceholderPvpDisabled();
}
}
}
- return langFile.getFeedbackError();
+ return langManager.getFeedbackError();
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java b/src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java
deleted file mode 100644
index 899dd7e..0000000
--- a/src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package org.callvdois.daynightpvp.runnables;
-
-import org.bukkit.Difficulty;
-import org.bukkit.Sound;
-import org.bukkit.World;
-import org.bukkit.scheduler.BukkitRunnable;
-import org.callvdois.daynightpvp.files.ConfigFile;
-import org.callvdois.daynightpvp.files.LangFile;
-import org.callvdois.daynightpvp.utils.PlayerUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class AutomaticPvp extends BukkitRunnable {
-
- public static List worldsPvpOff = new ArrayList<>();
- public static List worldsPvpOn = new ArrayList<>();
- private final PlayerUtils playerUtils;
- private final long dayEnd;
- private final boolean automaticDifficultyEnabled;
- private final boolean notifyPlayersChat;
- private final boolean notifyPlayersTitleEnabled;
- private final boolean notifyPlayersSoundEnabled;
- private final Difficulty automaticDifficultyDay;
- private final Difficulty automaticDifficultyNight;
- private final String notifyDayChat;
- private final String notifyDayTitle;
- private final String notifyDaySubtitle;
- private final String notifyNightChat;
- private final String notifyNightTitle;
- private final String notifyNightSubtitle;
- private final Sound notifyPlayersSoundDay;
- private final Sound notifyPlayersSoundNight;
- private final List worldList;
-
- public AutomaticPvp() {
- ConfigFile configFile = new ConfigFile();
- LangFile langFile = new LangFile();
- playerUtils = new PlayerUtils();
- dayEnd = configFile.getDayNightPvpDayEnd();
- automaticDifficultyEnabled = configFile.getDayNightPvpAutomaticDifficultyEnabled();
- notifyPlayersChat = configFile.getNotifyPlayersChatDayNightStarts();
- notifyPlayersTitleEnabled = configFile.getNotifyPlayersTitleEnabled();
- notifyPlayersSoundEnabled = configFile.getNotifyPlayersSoundEnabled();
- automaticDifficultyDay = configFile.getDayNightPvpAutomaticDifficultyDay();
- automaticDifficultyNight = configFile.getDayNightPvpAutomaticDifficultyNight();
- notifyDayChat = langFile.getNotifyDayChat();
- notifyDayTitle = langFile.getNotifyDayTitle();
- notifyDaySubtitle = langFile.getNotifyDaySubtitle();
- notifyNightChat = langFile.getNotifyNightChat();
- notifyNightTitle = langFile.getNotifyNightTitle();
- notifyNightSubtitle = langFile.getNotifyNightSubtitle();
- notifyPlayersSoundDay = configFile.getNotifyPlayersSoundDay();
- notifyPlayersSoundNight = configFile.getNotifyPlayersSoundNight();
- worldList = configFile.getDayNightPvpWorlds();
- }
-
- @Override
- public void run() {
- for (World world : worldList) {
- if (checkTime(world)) {
- handleNight(world);
- } else {
- handleDay(world);
- }
- }
- }
-
- private void handleNight(World world) {
- if (!worldsPvpOn.contains(world)) {
- worldsPvpOn.add(world);
- //ConsoleUtils.info("[DayNightPvP] It's night in \"" + world.getName() + "\"");
- }
- worldsPvpOff.remove(world);
- }
-
- private void handleDay(World world) {
- if (!worldsPvpOff.contains(world)) {
- worldsPvpOff.add(world);
- //ConsoleUtils.info("[DayNightPvP] It's day in \"" + world.getName() + "\"");
- }
- worldsPvpOn.remove(world);
- }
-
- public boolean checkTime(World world) {
- long currentWorldTime = world.getTime();
- boolean isNight = currentWorldTime >= dayEnd;
-
- if (isNight) {
- if (!worldsPvpOn.contains(world)) {
- handleNight(world);
- notifyNightActions(world);
- }
- } else {
- if (!worldsPvpOff.contains(world)) {
- handleDay(world);
- notifyDayActions(world);
- }
- }
-
- return isNight;
- }
-
- private void notifyNightActions(World world) {
- if (automaticDifficultyEnabled) {
- world.setDifficulty(automaticDifficultyNight);
- }
- if (notifyPlayersChat) {
- playerUtils.sendMessageToAllPlayers(world, notifyNightChat);
- }
- if (notifyPlayersTitleEnabled) {
- playerUtils.sendTitleToAllPlayers(world, notifyNightTitle, notifyNightSubtitle);
- }
- if (notifyPlayersSoundEnabled) {
- playerUtils.playSoundToAllPlayers(world, notifyPlayersSoundNight);
- }
- }
-
- private void notifyDayActions(World world) {
- if (automaticDifficultyEnabled) {
- world.setDifficulty(automaticDifficultyDay);
- }
- if (notifyPlayersChat) {
- playerUtils.sendMessageToAllPlayers(world, notifyDayChat);
- }
- if (notifyPlayersTitleEnabled) {
- playerUtils.sendTitleToAllPlayers(world, notifyDayTitle, notifyDaySubtitle);
- }
- if (notifyPlayersSoundEnabled) {
- playerUtils.playSoundToAllPlayers(world, notifyPlayersSoundDay);
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/callvdois/daynightpvp/runnables/CustomTimeDuration.java b/src/main/java/org/callvdois/daynightpvp/runnables/CustomTimeDuration.java
deleted file mode 100644
index af91bd7..0000000
--- a/src/main/java/org/callvdois/daynightpvp/runnables/CustomTimeDuration.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.callvdois.daynightpvp.runnables;
-
-import org.bukkit.World;
-import org.bukkit.scheduler.BukkitRunnable;
-import org.callvdois.daynightpvp.files.ConfigFile;
-
-import java.util.List;
-
-public class CustomTimeDuration extends BukkitRunnable {
-
- private final double dayTickIncrement;
- private final double nightTickIncrement;
- private final List worldList;
-
- public CustomTimeDuration() {
- ConfigFile configFile = new ConfigFile();
- long dayTicks = 12000;
- long nightTicks = 12000;
- dayTickIncrement = dayTicks / (configFile.getDayNightDurationDayDuration() * 20.0);
- nightTickIncrement = nightTicks / (configFile.getDayNightDurationNightDuration() * 20.0);
- worldList = configFile.getDayNightDurationWorlds();
- }
-
- @Override
- public void run() {
- for (World world : worldList) {
- long time = world.getTime();
- if (time < 12000) {
- world.setTime((long) (time + dayTickIncrement));
- } else {
- world.setTime((long) (time + nightTickIncrement));
- }
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/callvdois/daynightpvp/runnables/RunnableHandler.java b/src/main/java/org/callvdois/daynightpvp/runnables/RunnableHandler.java
deleted file mode 100644
index cb4191c..0000000
--- a/src/main/java/org/callvdois/daynightpvp/runnables/RunnableHandler.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.callvdois.daynightpvp.runnables;
-
-import org.bukkit.GameRule;
-import org.bukkit.World;
-import org.bukkit.scheduler.BukkitTask;
-import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.files.ConfigFile;
-
-public class RunnableHandler {
-
- private final ConfigFile configFile;
-
- public RunnableHandler() {
- configFile = new ConfigFile();
- }
-
- public void startAllRunnables() {
-
- if (configFile.getDayNightDurationEnabled()) {
- DayNightPvP.serviceTasks.add(new CustomTimeDuration().runTaskTimer(DayNightPvP.getInstance(), 0, 1));
- for (World world : configFile.getDayNightDurationWorlds()) {
- world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
- }
- }
-
- DayNightPvP.serviceTasks.add(new AutomaticPvp().runTaskTimer(DayNightPvP.getInstance(), 0, 20));
-
- }
-
- private void stopRunnable(BukkitTask task) {
- if (task != null && !task.isCancelled()) {
- task.cancel();
- }
- }
-
- public void stopAllRunnables() {
- for (BukkitTask task : DayNightPvP.serviceTasks) {
- stopRunnable(task);
- }
- DayNightPvP.serviceTasks.clear();
-
- for (World world : configFile.getDayNightDurationWorlds()) {
- world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true);
- }
-
- }
-
-}
diff --git a/src/main/java/org/callvdois/daynightpvp/service/DayNightDurationService.java b/src/main/java/org/callvdois/daynightpvp/service/DayNightDurationService.java
new file mode 100644
index 0000000..f43ade7
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/service/DayNightDurationService.java
@@ -0,0 +1,33 @@
+package org.callvdois.daynightpvp.service;
+
+import org.bukkit.World;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.callvdois.daynightpvp.config.ConfigManager;
+
+public class DayNightDurationService extends BukkitRunnable {
+
+ private final ConfigManager configManager;
+
+ public DayNightDurationService() {
+ configManager = new ConfigManager();
+ }
+
+ @Override
+ public void run() {
+ long dayTicks = 12000;
+ long nightTicks = 12000;
+ double dayTickIncrement = dayTicks / (configManager.getDayNightDurationDayDuration() * 20.0);
+ double nightTickIncrement = nightTicks / (configManager.getDayNightDurationNightDuration() * 20.0);
+
+ for (World world : configManager.getDayNightDurationWorlds()) {
+ long time = world.getTime();
+ if (time < 12000) {
+ world.setTime((long) (time + dayTickIncrement));
+ } else {
+ world.setTime((long) (time + nightTickIncrement));
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/callvdois/daynightpvp/service/ServiceManager.java b/src/main/java/org/callvdois/daynightpvp/service/ServiceManager.java
new file mode 100644
index 0000000..1c21351
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/service/ServiceManager.java
@@ -0,0 +1,43 @@
+package org.callvdois.daynightpvp.service;
+
+import org.bukkit.GameRule;
+import org.bukkit.World;
+import org.bukkit.scheduler.BukkitTask;
+import org.callvdois.daynightpvp.DayNightPvP;
+import org.callvdois.daynightpvp.config.ConfigManager;
+
+public class ServiceManager {
+
+ private final ConfigManager configManager;
+
+ public ServiceManager() {
+ configManager = new ConfigManager();
+ }
+
+ public void startServices() {
+ DayNightPvP.serviceTasks.add(new TimeCheckerService().runTaskTimer(DayNightPvP.getInstance(), 0, 20));
+ if (configManager.getDayNightDurationEnabled()) {
+ DayNightPvP.serviceTasks.add(new DayNightDurationService().runTaskTimer(DayNightPvP.getInstance(), 0, 1));
+ for (World world : configManager.getDayNightDurationWorlds()) {
+ world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
+ }
+ }
+ }
+
+ public void stopServices() {
+ for (BukkitTask task : DayNightPvP.serviceTasks) {
+ stopService(task);
+ }
+ DayNightPvP.serviceTasks.clear();
+ for (World world : configManager.getDayNightDurationWorlds()) {
+ world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true);
+ }
+ }
+
+ private void stopService(BukkitTask task) {
+ if (task != null && !task.isCancelled()) {
+ task.cancel();
+ }
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/service/TimeCheckerService.java b/src/main/java/org/callvdois/daynightpvp/service/TimeCheckerService.java
new file mode 100644
index 0000000..4de31df
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/service/TimeCheckerService.java
@@ -0,0 +1,91 @@
+package org.callvdois.daynightpvp.service;
+
+import org.bukkit.World;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.LangManager;
+import org.callvdois.daynightpvp.utils.PlayerUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TimeCheckerService extends BukkitRunnable {
+
+ public static List worldsPvpOff = new ArrayList<>();
+ public static List worldsPvpOn = new ArrayList<>();
+ private final ConfigManager configManager;
+ private final LangManager langManager;
+ private final PlayerUtils playerUtils;
+
+ public TimeCheckerService() {
+ configManager = new ConfigManager();
+ langManager = new LangManager();
+ playerUtils = new PlayerUtils();
+ }
+
+ @Override
+ public void run() {
+ List worldList = configManager.getDayNightPvpWorlds();
+ for (World world : worldList) {
+ if (checkTime(world)) {
+ handleNight(world);
+ } else {
+ handleDay(world);
+ }
+ }
+ }
+
+ private void handleNight(World world) {
+ if (!worldsPvpOn.contains(world)) {
+ worldsPvpOn.add(world);
+ //ConsoleUtils.info("[DayNightPvP] It's night in \"" + world.getName() + "\"");
+ }
+ worldsPvpOff.remove(world);
+ }
+
+ private void handleDay(World world) {
+ if (!worldsPvpOff.contains(world)) {
+ worldsPvpOff.add(world);
+ //ConsoleUtils.info("[DayNightPvP] It's day in \"" + world.getName() + "\"");
+ }
+ worldsPvpOn.remove(world);
+ }
+
+ public boolean checkTime(World world) {
+ long currentWorldTime = world.getTime();
+ if (currentWorldTime < configManager.getDayNightPvpDayEnd()) {
+ if (!worldsPvpOff.contains(world)) {
+ if (configManager.getDayNightPvpAutomaticDifficultyEnabled()) {
+ world.setDifficulty(configManager.getDayNightPvpAutomaticDifficultyDay());
+ }
+ if (configManager.getNotifyPlayersChatDayNightStarts()) {
+ PlayerUtils.sendMessageToAllPlayers(world, langManager.getNotifyDayChat());
+ }
+ if (configManager.getNotifyPlayersTitleEnabled()) {
+ playerUtils.sendTitleToAllPlayers(world, langManager.getNotifyDayTitle(), langManager.getNotifyDaySubtitle());
+ }
+ if (configManager.getNotifyPlayersSoundEnabled()) {
+ PlayerUtils.playSoundToAllPlayers(world, configManager.getNotifyPlayersSoundDay());
+ }
+ }
+ return false;
+ } else {
+ if (!worldsPvpOn.contains(world)) {
+ if (configManager.getDayNightPvpAutomaticDifficultyEnabled()) {
+ world.setDifficulty(configManager.getDayNightPvpAutomaticDifficultyNight());
+ }
+ if (configManager.getNotifyPlayersChatDayNightStarts()) {
+ PlayerUtils.sendMessageToAllPlayers(world, langManager.getNotifyNightChat());
+ }
+ if (configManager.getNotifyPlayersTitleEnabled()) {
+ playerUtils.sendTitleToAllPlayers(world, langManager.getNotifyNightTitle(), langManager.getNotifyNightSubtitle());
+ }
+ if (configManager.getNotifyPlayersSoundEnabled()) {
+ PlayerUtils.playSoundToAllPlayers(world, configManager.getNotifyPlayersSoundNight());
+ }
+ }
+ return true;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/callvdois/daynightpvp/services/UpdateServices.java b/src/main/java/org/callvdois/daynightpvp/service/UpdateChecker.java
similarity index 74%
rename from src/main/java/org/callvdois/daynightpvp/services/UpdateServices.java
rename to src/main/java/org/callvdois/daynightpvp/service/UpdateChecker.java
index cb7b735..b2738f2 100644
--- a/src/main/java/org/callvdois/daynightpvp/services/UpdateServices.java
+++ b/src/main/java/org/callvdois/daynightpvp/service/UpdateChecker.java
@@ -1,10 +1,10 @@
-package org.callvdois.daynightpvp.services;
+package org.callvdois.daynightpvp.service;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.callvdois.daynightpvp.DayNightPvP;
-import org.callvdois.daynightpvp.files.LangFile;
+import org.callvdois.daynightpvp.config.LangManager;
import java.io.BufferedReader;
import java.io.IOException;
@@ -12,12 +12,12 @@
import java.net.HttpURLConnection;
import java.net.URL;
-public class UpdateServices {
+public class UpdateChecker {
- private final LangFile langFile;
+ private final LangManager langManager;
- public UpdateServices() {
- langFile = new LangFile();
+ public UpdateChecker() {
+ langManager = new LangManager();
}
public void checkUpdate(PlayerJoinEvent event) {
@@ -28,12 +28,12 @@ public void checkUpdate(PlayerJoinEvent event) {
if (!currentVersion.equals(latestVersion)) {
- TextComponent link = new TextComponent(langFile.getActionUpdateFoundClick());
+ TextComponent link = new TextComponent(langManager.getActionUpdateFoundClick());
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/daynightpvp-dynamic-pvp-for-day-night.102250/updates"));
- event.getPlayer().sendMessage(langFile.getFeedbackUpdateFound());
- event.getPlayer().sendMessage(langFile.getFeedbackUpdateFoundCurrentVersion().replace("{0}", currentVersion));
- event.getPlayer().sendMessage(langFile.getFeedbackUpdateFoundNewVersion().replace("{0}", latestVersion));
+ event.getPlayer().sendMessage(langManager.getFeedbackUpdateFound());
+ event.getPlayer().sendMessage(langManager.getFeedbackUpdateFoundCurrentVersion().replace("{0}", currentVersion));
+ event.getPlayer().sendMessage(langManager.getFeedbackUpdateFoundNewVersion().replace("{0}", latestVersion));
event.getPlayer().spigot().sendMessage(link);
}
} catch (IOException ex) {
diff --git a/src/main/java/org/callvdois/daynightpvp/services/PluginServices.java b/src/main/java/org/callvdois/daynightpvp/services/PluginServices.java
deleted file mode 100644
index 4956d95..0000000
--- a/src/main/java/org/callvdois/daynightpvp/services/PluginServices.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.callvdois.daynightpvp.services;
-
-import org.callvdois.daynightpvp.Listeners.ListenersHandler;
-import org.callvdois.daynightpvp.files.ConfigFile;
-import org.callvdois.daynightpvp.files.LangFile;
-import org.callvdois.daynightpvp.placeholder.PlaceholderHandler;
-import org.callvdois.daynightpvp.runnables.RunnableHandler;
-
-
-public class PluginServices {
-
- private final ConfigFile configFile;
- private final LangFile langFile;
- private final ListenersHandler listenersHandler;
- private final PlaceholderHandler placeholderHandler;
- private final RunnableHandler runnableHandler;
-
- public PluginServices() {
- configFile = new ConfigFile();
- langFile = new LangFile();
- listenersHandler = new ListenersHandler();
- placeholderHandler = new PlaceholderHandler();
- runnableHandler = new RunnableHandler();
- }
-
- public void reloadPlugin() {
- configFile.createFile();
- langFile.createFile();
- listenersHandler.unregisterAll();
- listenersHandler.register();
- placeholderHandler.unregister();
- placeholderHandler.register();
- runnableHandler.stopAllRunnables();
- runnableHandler.startAllRunnables();
- }
-
-}
diff --git a/src/main/java/org/callvdois/daynightpvp/utils/ConsoleUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/ConsoleUtils.java
index f870e13..7986381 100644
--- a/src/main/java/org/callvdois/daynightpvp/utils/ConsoleUtils.java
+++ b/src/main/java/org/callvdois/daynightpvp/utils/ConsoleUtils.java
@@ -5,11 +5,11 @@
public class ConsoleUtils {
- public void sendWarningMessage(String message) {
+ public static void warning(String message) {
Bukkit.getLogger().warning(message);
}
- public void sendStartupMessage() {
+ public static void startMessage() {
Bukkit.getConsoleSender().sendMessage(" §9 _ _");
Bukkit.getConsoleSender().sendMessage(" §9| \\|\\||_)" + " §3DayNightPvP §8v" + DayNightPvP.getInstance().getDescription().getVersion());
Bukkit.getConsoleSender().sendMessage(" §9|_/| ||" + " §8by §3needkg");
diff --git a/src/main/java/org/callvdois/daynightpvp/utils/ItemUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/ItemUtils.java
new file mode 100644
index 0000000..e439913
--- /dev/null
+++ b/src/main/java/org/callvdois/daynightpvp/utils/ItemUtils.java
@@ -0,0 +1,109 @@
+package org.callvdois.daynightpvp.utils;
+
+import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.properties.Property;
+import org.bukkit.Material;
+import org.bukkit.NamespacedKey;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.persistence.PersistentDataType;
+import org.callvdois.daynightpvp.DayNightPvP;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public class ItemUtils {
+
+ private static final NamespacedKey customTagKey = new NamespacedKey(DayNightPvP.getInstance(), "id");
+
+ public static ItemStack createCustomHead(String name, String id, String description, String url) {
+ ItemStack item = getHead(url);
+ ItemStack itemWithId = setID(item, id);
+
+ ItemMeta itemMeta = itemWithId.getItemMeta();
+ itemMeta.setDisplayName(name);
+ List itemLore = new ArrayList<>();
+
+ String[] descriptionParts = description.split("\\|");
+ for (String part : descriptionParts) {
+ itemLore.add(part);
+ }
+
+ itemMeta.setLore(itemLore);
+ item.setItemMeta(itemMeta);
+ return item;
+ }
+
+ public static ItemStack createCustomHeadExtendedDescription(String name, String id, List description, String url) {
+ ItemStack item = getHead(url);
+ ItemStack itemWithId = setID(item, id);
+
+ ItemMeta itemMeta = itemWithId.getItemMeta();
+ itemMeta.setDisplayName(name);
+ List itemLore = new ArrayList<>();
+
+ for (String part : description) {
+ itemLore.add(part);
+ }
+
+ itemMeta.setLore(itemLore);
+ item.setItemMeta(itemMeta);
+ return item;
+ }
+
+ public static ItemStack createItem(String name, String id, String description, Material material) {
+ ItemStack item = new ItemStack(material);
+ ItemStack itemWithId = setID(item, id);
+ ItemMeta itemMeta = itemWithId.getItemMeta();
+ itemMeta.setDisplayName(name);
+ List itemLore = new ArrayList<>();
+
+ String[] descriptionParts = description.split("\\|");
+ for (String part : descriptionParts) {
+ itemLore.add(part);
+ }
+
+ itemMeta.setLore(itemLore);
+ item.setItemMeta(itemMeta);
+ return item;
+ }
+
+ private static ItemStack setID(ItemStack item, String value) {
+ ItemMeta meta = item.getItemMeta();
+
+ meta.getPersistentDataContainer().set(customTagKey, PersistentDataType.STRING, value);
+ item.setItemMeta(meta);
+ return item;
+ }
+
+ public static String getID(ItemStack item) {
+ ItemMeta meta = item.getItemMeta();
+ return meta.getPersistentDataContainer().get(customTagKey, PersistentDataType.STRING);
+ }
+
+ private static ItemStack getHead(String value) {
+ try {
+ if (value == null) return null;
+
+ ItemStack head = new ItemStack(Material.PLAYER_HEAD);
+ SkullMeta hMeta = (SkullMeta) head.getItemMeta();
+
+ GameProfile profile = new GameProfile(UUID.randomUUID(), "head");
+ profile.getProperties().put("textures", new Property("textures", value));
+ Method mtd = hMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
+ mtd.setAccessible(true);
+ mtd.invoke(hMeta, profile);
+
+ head.setItemMeta(hMeta);
+ return head;
+ } catch (Exception e) {
+ // ignore
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/callvdois/daynightpvp/utils/PlayerUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/PlayerUtils.java
index dab8b70..f333ec6 100644
--- a/src/main/java/org/callvdois/daynightpvp/utils/PlayerUtils.java
+++ b/src/main/java/org/callvdois/daynightpvp/utils/PlayerUtils.java
@@ -3,31 +3,39 @@
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
-import org.callvdois.daynightpvp.files.ConfigFile;
+import org.callvdois.daynightpvp.config.ConfigManager;
public class PlayerUtils {
- private final ConfigFile configFile;
+ private final ConfigManager configManager;
public PlayerUtils() {
- configFile = new ConfigFile();
+ configManager = new ConfigManager();
}
- public void sendMessageToAllPlayers(World world, String message) {
+ public static void sendMessageToAllPlayers(World world, String message) {
for (Player player : world.getPlayers()) {
player.sendMessage(message);
}
}
- public void playSoundToAllPlayers(World world, Sound sound) {
+ public static void sendMessageToPlayer(Player player, String message) {
+ player.sendMessage(message);
+ }
+
+ public static void playSoundToAllPlayers(World world, Sound sound) {
for (Player player : world.getPlayers()) {
player.playSound(player.getLocation(), sound, 1, 1);
}
}
+ public static void playSoundToPlayer(Player player, Sound sound) {
+ player.playSound(player.getLocation(), sound, 1, 1);
+ }
+
public void sendTitleToAllPlayers(World world, String title, String subTitle) {
for (Player player : world.getPlayers()) {
- player.sendTitle(title, subTitle, configFile.getNotifyPlayersTitleFadeIn(), configFile.getNotifyPlayersTitleStay(), configFile.getNotifyPlayersTitleFadeOut());
+ player.sendTitle(title, subTitle, configManager.getNotifyPlayersTitleFadeIn(), configManager.getNotifyPlayersTitleStay(), configManager.getNotifyPlayersTitleFadeOut());
}
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/utils/PluginUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/PluginUtils.java
index 5048913..0d65168 100644
--- a/src/main/java/org/callvdois/daynightpvp/utils/PluginUtils.java
+++ b/src/main/java/org/callvdois/daynightpvp/utils/PluginUtils.java
@@ -5,7 +5,7 @@
public class PluginUtils {
- public boolean isPluginInstalled(String pluginName) {
+ public static boolean isPluginInstalled(String pluginName) {
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
return plugin != null;
}
diff --git a/src/main/java/org/callvdois/daynightpvp/utils/SearchUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/SearchUtils.java
index 290e4ea..c7c2c58 100644
--- a/src/main/java/org/callvdois/daynightpvp/utils/SearchUtils.java
+++ b/src/main/java/org/callvdois/daynightpvp/utils/SearchUtils.java
@@ -7,7 +7,16 @@
public class SearchUtils {
- public boolean worldExistsInWorldList(List list, String worldName) {
+ public static boolean fileExistsInFileList(File[] files, String searchString) {
+ for (File file : files) {
+ if (file.getName().contains(searchString)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean worldExistsInWorldList(List list, String worldName) {
return list.stream().map(World::getName).anyMatch(name -> name.contains(worldName));
}
diff --git a/src/main/java/org/callvdois/daynightpvp/utils/WorldUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/WorldUtils.java
index 235c06e..7773f5d 100644
--- a/src/main/java/org/callvdois/daynightpvp/utils/WorldUtils.java
+++ b/src/main/java/org/callvdois/daynightpvp/utils/WorldUtils.java
@@ -3,19 +3,19 @@
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
-import org.callvdois.daynightpvp.runnables.AutomaticPvp;
+import org.callvdois.daynightpvp.service.TimeCheckerService;
public class WorldUtils {
- public SearchUtils searchUtils;
-
- public WorldUtils() {
- searchUtils = new SearchUtils();
+ public static void setTime(String worldName, int time) {
+ World world = Bukkit.getWorld(worldName);
+ assert world != null;
+ world.setTime(time);
}
- public boolean checkPlayerIsInWorld(Player player) {
+ public static boolean checkPlayerIsInWorld(Player player) {
String worldName = player.getWorld().getName();
- return searchUtils.worldExistsInWorldList(AutomaticPvp.worldsPvpOff, worldName);
+ return SearchUtils.worldExistsInWorldList(TimeCheckerService.worldsPvpOff, worldName);
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/vault/LoseMoneyOnDeath.java b/src/main/java/org/callvdois/daynightpvp/vault/LoseMoneyOnDeath.java
index 8acb07d..fcf57ae 100644
--- a/src/main/java/org/callvdois/daynightpvp/vault/LoseMoneyOnDeath.java
+++ b/src/main/java/org/callvdois/daynightpvp/vault/LoseMoneyOnDeath.java
@@ -4,8 +4,8 @@
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
-import org.callvdois.daynightpvp.files.ConfigFile;
-import org.callvdois.daynightpvp.files.LangFile;
+import org.callvdois.daynightpvp.config.ConfigManager;
+import org.callvdois.daynightpvp.config.LangManager;
import org.callvdois.daynightpvp.utils.SearchUtils;
import java.util.List;
@@ -13,11 +13,10 @@
public class LoseMoneyOnDeath {
public static void loseMoneyOnDeath(Player killed, Player killer, World world, List worldList, String percentage) {
- ConfigFile configFile = new ConfigFile();
- LangFile langFile = new LangFile();
- SearchUtils searchUtils = new SearchUtils();
- boolean onlyNight = configFile.getVaultLoseMoneyOnDeathOnlyAtNight();
- boolean onlyConfiguredWorlds = configFile.getVaultLoseMoneyOnDeathOnlyInConfiguredWorlds();
+ ConfigManager configManager = new ConfigManager();
+ LangManager langManager = new LangManager();
+ boolean onlyNight = configManager.getVaultLoseMoneyOnDeathOnlyAtNight();
+ boolean onlyConfiguredWorlds = configManager.getVaultLoseMoneyOnDeathOnlyInConfiguredWorlds();
Economy economy = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
if (killed != null && !percentage.isEmpty() && percentage.matches("[1-9][0-9]?|100")) {
@@ -30,7 +29,7 @@ public static void loseMoneyOnDeath(Player killed, Player killer, World world, L
if (onlyNight) {
if (world.getPVP()) {
if (onlyConfiguredWorlds) {
- if (searchUtils.worldExistsInWorldList(worldList, world.getName())) {
+ if (SearchUtils.worldExistsInWorldList(worldList, world.getName())) {
economy.withdrawPlayer(killed, amountRounded);
shouldWithdraw = true;
// noite e configurado
@@ -42,7 +41,7 @@ public static void loseMoneyOnDeath(Player killed, Player killer, World world, L
}
}
} else if (onlyConfiguredWorlds) {
- if (searchUtils.worldExistsInWorldList(worldList, world.getName())) {
+ if (SearchUtils.worldExistsInWorldList(worldList, world.getName())) {
shouldWithdraw = true;
economy.withdrawPlayer(killed, amountRounded);
// dia/noite e configurado
@@ -56,10 +55,10 @@ public static void loseMoneyOnDeath(Player killed, Player killer, World world, L
String money = Double.toString(amountRounded);
String killedName = killed.getName();
String killerName = killed.getName();
- killed.sendMessage(langFile.getFeedbackLoseMoney().replace("{0}", killerName).replace("{1}", money));
- if (configFile.getVaultLoseMoneyOnDeathKillerRewardMoney()) {
+ killed.sendMessage(langManager.getFeedbackLoseMoney().replace("{0}", killerName).replace("{1}", money));
+ if (configManager.getVaultLoseMoneyOnDeathKillerRewardMoney()) {
economy.depositPlayer(killer, amountRounded);
- killer.sendMessage(langFile.getFeedbackWinMoney().replace("{0}", killedName).replace("{1}", money));
+ killer.sendMessage(langManager.getFeedbackWinMoney().replace("{0}", killedName).replace("{1}", money));
}
}
}
diff --git a/src/main/java/org/callvdois/daynightpvp/worldguard/AllowDaytimePvpFlag.java b/src/main/java/org/callvdois/daynightpvp/worldguard/AllowPvpOnDayFlag.java
similarity index 91%
rename from src/main/java/org/callvdois/daynightpvp/worldguard/AllowDaytimePvpFlag.java
rename to src/main/java/org/callvdois/daynightpvp/worldguard/AllowPvpOnDayFlag.java
index 000afe8..69e2982 100644
--- a/src/main/java/org/callvdois/daynightpvp/worldguard/AllowDaytimePvpFlag.java
+++ b/src/main/java/org/callvdois/daynightpvp/worldguard/AllowPvpOnDayFlag.java
@@ -12,11 +12,11 @@
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.entity.Player;
-public class AllowDaytimePvpFlag {
+public class AllowPvpOnDayFlag {
- private static StateFlag allowPvpOnDay;
+ public static StateFlag allowPvpOnDay;
- public static boolean checkStateOnPosition(Player player) {
+ public static boolean checkState(Player player) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
Location loc = localPlayer.getLocation();
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
diff --git a/src/main/java/org/callvdois/daynightpvp/worldguard/FlagHandler.java b/src/main/java/org/callvdois/daynightpvp/worldguard/WorldGuardManager.java
similarity index 71%
rename from src/main/java/org/callvdois/daynightpvp/worldguard/FlagHandler.java
rename to src/main/java/org/callvdois/daynightpvp/worldguard/WorldGuardManager.java
index ab806c9..a3cca96 100644
--- a/src/main/java/org/callvdois/daynightpvp/worldguard/FlagHandler.java
+++ b/src/main/java/org/callvdois/daynightpvp/worldguard/WorldGuardManager.java
@@ -2,11 +2,11 @@
import org.callvdois.daynightpvp.DayNightPvP;
-public class FlagHandler {
+public class WorldGuardManager {
public void register() {
if (DayNightPvP.worldGuardIsPresent) {
- AllowDaytimePvpFlag.register();
+ AllowPvpOnDayFlag.register();
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index fe0fa70..8a761f8 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,27 +1,16 @@
-name: '${name}'
+name: DayNightPvP
version: '${project.version}'
author: 'needkg'
main: org.callvdois.daynightpvp.DayNightPvP
api-version: '1.16'
-softdepend: [PlaceholderAPI, GriefPrevention, Vault, WorldGuard]
-load: POSTWORLD
-
+softdepend: [ PlaceholderAPI, GriefPrevention, Vault, WorldGuard ]
+load: STARTUP
commands:
- daynightpvp:
+ dnp:
description: "Open the gui."
- usage: "/dnp"
- aliases: [ dnp ]
+ aliases: [ daynightpvp ]
permission: dnp.admin
- daynightpvp reload:
+ dnp reload:
description: "Reload the plugin"
- usage: "/dnp reload"
- aliases: [ dnp reload ]
- permission: dnp.admin
-
-permissions:
- dnp.admin:
- description: Ensures access to all DNP commands.
- default: op
- dnp.bypasspvp:
- description: Allows the user to engage in combat even during the day.
- default: op
\ No newline at end of file
+ aliases: [ daynightpvp reload ]
+ permission: dnp.admin
\ No newline at end of file