From d4f61da61ff18021a2a874d2e3a530ab685e28d6 Mon Sep 17 00:00:00 2001 From: needkg Date: Tue, 2 Jul 2024 23:34:24 -0300 Subject: [PATCH] update --- DayNightPvP.iml | 13 -- pom.xml | 6 +- .../callvdois/daynightpvp/DayNightPvP.java | 90 ++++++------ .../DamageListener.java} | 46 +++--- .../DeathListener.java} | 22 +-- .../JoinListener.java} | 14 +- .../Listeners/ListenersHandler.java | 45 ++++++ ...ommandManager.java => CommandHandler.java} | 7 +- .../daynightpvp/commands/DnpCommand.java | 55 ------- .../daynightpvp/commands/DnpTabCompleter.java | 17 --- .../commands/SubCommandHandler.java | 8 + .../daynightpvp/commands/dnp/DnpCommand.java | 52 +++++++ .../commands/dnp/reload/DnpReloadCommand.java | 23 +++ .../daynightpvp/config/FilesManager.java | 101 ------------- .../daynightpvp/events/EventsManager.java | 53 ------- .../daynightpvp/events/InventoryEvent.java | 139 ------------------ .../ConfigFile.java} | 82 ++++++----- .../LangManager.java => files/LangFile.java} | 54 +++++-- ...nager.java => GriefPreventionHandler.java} | 9 +- .../daynightpvp/gui/LanguageGui.java | 55 ------- .../callvdois/daynightpvp/gui/MainGui.java | 45 ------ .../callvdois/daynightpvp/gui/WorldGui.java | 116 --------------- .../callvdois/daynightpvp/gui/WorldsGui.java | 124 ---------------- .../daynightpvp/metrics/MetricsHandler.java | 12 ++ .../daynightpvp/metrics/MetricsManager.java | 11 -- ...erManager.java => PlaceholderHandler.java} | 2 +- .../placeholder/PvpStatusPlaceholder.java | 30 ++-- .../daynightpvp/runnables/AutomaticPvp.java | 134 +++++++++++++++++ .../runnables/CustomTimeDuration.java | 37 +++++ .../runnables/RunnableHandler.java | 48 ++++++ .../service/DayNightDurationService.java | 33 ----- .../daynightpvp/service/ServiceManager.java | 43 ------ .../service/TimeCheckerService.java | 91 ------------ .../daynightpvp/services/PluginServices.java | 37 +++++ .../UpdateServices.java} | 20 +-- .../daynightpvp/utils/ConsoleUtils.java | 4 +- .../daynightpvp/utils/ItemUtils.java | 109 -------------- .../daynightpvp/utils/PlayerUtils.java | 20 +-- .../daynightpvp/utils/PluginUtils.java | 2 +- .../daynightpvp/utils/SearchUtils.java | 11 +- .../daynightpvp/utils/WorldUtils.java | 14 +- .../daynightpvp/vault/LoseMoneyOnDeath.java | 23 +-- ...nDayFlag.java => AllowDaytimePvpFlag.java} | 6 +- ...orldGuardManager.java => FlagHandler.java} | 4 +- src/main/resources/plugin.yml | 27 +++- 45 files changed, 662 insertions(+), 1232 deletions(-) delete mode 100644 DayNightPvP.iml rename src/main/java/org/callvdois/daynightpvp/{events/DamageEvent.java => Listeners/DamageListener.java} (61%) rename src/main/java/org/callvdois/daynightpvp/{events/DeathEvent.java => Listeners/DeathListener.java} (74%) rename src/main/java/org/callvdois/daynightpvp/{events/JoinEvent.java => Listeners/JoinListener.java} (54%) create mode 100644 src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java rename src/main/java/org/callvdois/daynightpvp/commands/{CommandManager.java => CommandHandler.java} (70%) delete mode 100644 src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/commands/DnpTabCompleter.java create mode 100644 src/main/java/org/callvdois/daynightpvp/commands/SubCommandHandler.java create mode 100644 src/main/java/org/callvdois/daynightpvp/commands/dnp/DnpCommand.java create mode 100644 src/main/java/org/callvdois/daynightpvp/commands/dnp/reload/DnpReloadCommand.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/config/FilesManager.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/events/EventsManager.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/events/InventoryEvent.java rename src/main/java/org/callvdois/daynightpvp/{config/ConfigManager.java => files/ConfigFile.java} (78%) rename src/main/java/org/callvdois/daynightpvp/{config/LangManager.java => files/LangFile.java} (77%) rename src/main/java/org/callvdois/daynightpvp/griefprevention/{GriefManager.java => GriefPreventionHandler.java} (54%) delete mode 100644 src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/gui/MainGui.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/gui/WorldGui.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/gui/WorldsGui.java create mode 100644 src/main/java/org/callvdois/daynightpvp/metrics/MetricsHandler.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/metrics/MetricsManager.java rename src/main/java/org/callvdois/daynightpvp/placeholder/{PlaceholderManager.java => PlaceholderHandler.java} (92%) create mode 100644 src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java create mode 100644 src/main/java/org/callvdois/daynightpvp/runnables/CustomTimeDuration.java create mode 100644 src/main/java/org/callvdois/daynightpvp/runnables/RunnableHandler.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/service/DayNightDurationService.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/service/ServiceManager.java delete mode 100644 src/main/java/org/callvdois/daynightpvp/service/TimeCheckerService.java create mode 100644 src/main/java/org/callvdois/daynightpvp/services/PluginServices.java rename src/main/java/org/callvdois/daynightpvp/{service/UpdateChecker.java => services/UpdateServices.java} (74%) delete mode 100644 src/main/java/org/callvdois/daynightpvp/utils/ItemUtils.java rename src/main/java/org/callvdois/daynightpvp/worldguard/{AllowPvpOnDayFlag.java => AllowDaytimePvpFlag.java} (91%) rename src/main/java/org/callvdois/daynightpvp/worldguard/{WorldGuardManager.java => FlagHandler.java} (71%) diff --git a/DayNightPvP.iml b/DayNightPvP.iml deleted file mode 100644 index a589521..0000000 --- a/DayNightPvP.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - SPIGOT - - 1 - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f7e4f1..fa440f9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ jar UTF-8 - 17 + 1.8 ${project.name} ${project.groupId}.daynightpvp.DayNightPvP @@ -38,8 +38,8 @@ maven-compiler-plugin 3.13.0 - ${java.version} - ${java.version} + 16 + 16 diff --git a/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java b/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java index 2dd4fa0..a7efee0 100644 --- a/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java +++ b/src/main/java/org/callvdois/daynightpvp/DayNightPvP.java @@ -2,15 +2,16 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -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.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.utils.ConsoleUtils; import org.callvdois.daynightpvp.utils.PluginUtils; -import org.callvdois.daynightpvp.worldguard.WorldGuardManager; +import org.callvdois.daynightpvp.worldguard.FlagHandler; import java.util.ArrayList; import java.util.List; @@ -23,24 +24,30 @@ public class DayNightPvP extends JavaPlugin { public static boolean placeHolderIsPresent; public static List serviceTasks = new ArrayList<>(); private static DayNightPvP instance; - 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; + 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; public DayNightPvP() { instance = this; - filesManager = new FilesManager(); - commandManager = new CommandManager(); - eventsManager = new EventsManager(); - placeholderManager = new PlaceholderManager(); - worldGuardManager = new WorldGuardManager(); - serviceManager = new ServiceManager(); - metricsManager = new MetricsManager(); + 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(); } @@ -50,49 +57,42 @@ public static DayNightPvP getInstance() { @Override public void onLoad() { - load(); - } - - @Override - public void onEnable() { - enable(); - } - - private void load() { - verifyCompatibilityPlugins(); if (worldGuardIsPresent) { - worldGuardManager.register(); + flagHandler.register(); } } - private void enable() { - ConsoleUtils.startMessage(); + @Override + public void onEnable() { + consoleUtils.sendStartupMessage(); - filesManager.createFiles(); + metricsHandler.start(); - commandManager.register(); + configFile.createFile(); + langFile.createFile(); - eventsManager.register(); + commandHandler.register(); - placeholderManager.register(); + listenersHandler.register(); - serviceManager.startServices(); + placeholderHandler.register(); - metricsManager.register(); + runnableHandler.startAllRunnables(); } + 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() { - serviceManager.stopServices(); + runnableHandler.stopAllRunnables(); } } \ No newline at end of file diff --git a/src/main/java/org/callvdois/daynightpvp/events/DamageEvent.java b/src/main/java/org/callvdois/daynightpvp/Listeners/DamageListener.java similarity index 61% rename from src/main/java/org/callvdois/daynightpvp/events/DamageEvent.java rename to src/main/java/org/callvdois/daynightpvp/Listeners/DamageListener.java index a24fdc9..cc8ef1f 100644 --- a/src/main/java/org/callvdois/daynightpvp/events/DamageEvent.java +++ b/src/main/java/org/callvdois/daynightpvp/Listeners/DamageListener.java @@ -1,4 +1,4 @@ -package org.callvdois.daynightpvp.events; +package org.callvdois.daynightpvp.Listeners; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -10,22 +10,24 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.callvdois.daynightpvp.DayNightPvP; -import org.callvdois.daynightpvp.config.ConfigManager; -import org.callvdois.daynightpvp.config.LangManager; -import org.callvdois.daynightpvp.griefprevention.GriefManager; +import org.callvdois.daynightpvp.files.ConfigFile; +import org.callvdois.daynightpvp.files.LangFile; +import org.callvdois.daynightpvp.griefprevention.GriefPreventionHandler; import org.callvdois.daynightpvp.utils.WorldUtils; -import org.callvdois.daynightpvp.worldguard.AllowPvpOnDayFlag; +import org.callvdois.daynightpvp.worldguard.AllowDaytimePvpFlag; -public class DamageEvent implements Listener { +public class DamageListener implements Listener { - private final GriefManager griefManager; - private final ConfigManager configManager; - private final LangManager langManager; + private final GriefPreventionHandler griefPreventionHandler; + private final ConfigFile configFile; + private final LangFile langFile; + private final WorldUtils worldUtils; - public DamageEvent() { - griefManager = new GriefManager(); - configManager = new ConfigManager(); - langManager = new LangManager(); + public DamageListener() { + griefPreventionHandler = new GriefPreventionHandler(); + configFile = new ConfigFile(); + langFile = new LangFile(); + worldUtils = new WorldUtils(); } @EventHandler @@ -36,8 +38,8 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (checkHooks(damagedPlayer, damager)) { event.setCancelled(true); - if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) { - damager.sendMessage(langManager.getNotifyPvpDisabled()); + if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) { + damager.sendMessage(langFile.getNotifyPvpDisabled()); } } } @@ -50,8 +52,8 @@ public void onProjectileHitEvent(ProjectileHitEvent event) { if (checkHooks(damagedPlayer, damager)) { event.setCancelled(true); - if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) { - damager.sendMessage(langManager.getNotifyPvpDisabled()); + if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) { + damager.sendMessage(langFile.getNotifyPvpDisabled()); } } @@ -68,8 +70,8 @@ public void onPotionSplash(PotionSplashEvent event) { if (event.getAffectedEntities().contains(damagedPlayer) && damagedPlayer != damager) { if (checkHooks(damagedPlayer, damager)) { event.setIntensity(damagedPlayer, 0.0); - if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) { - damager.sendMessage(langManager.getNotifyPvpDisabled()); + if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) { + damager.sendMessage(langFile.getNotifyPvpDisabled()); } } } @@ -91,13 +93,13 @@ private boolean checkHooks(Player damagedPlayer, Player damager) { if (damager.hasPermission("dnp.bypasspvp")) { return false; } - if (DayNightPvP.worldGuardIsPresent && AllowPvpOnDayFlag.checkState(damagedPlayer) && AllowPvpOnDayFlag.checkState(damager)) { + if (DayNightPvP.worldGuardIsPresent && AllowDaytimePvpFlag.checkStateOnPosition(damagedPlayer) && AllowDaytimePvpFlag.checkStateOnPosition(damager)) { return false; } - if (DayNightPvP.griefIsPresent && !configManager.getGriefPreventionPvpInLandEnabled() && griefManager.verify(damagedPlayer, damager)) { + if (DayNightPvP.griefIsPresent && !configFile.getGriefPreventionPvpInLandEnabled() && griefPreventionHandler.verify(damagedPlayer, damager)) { return true; } - return WorldUtils.checkPlayerIsInWorld(damagedPlayer); + return worldUtils.checkPlayerIsInWorld(damagedPlayer); } } diff --git a/src/main/java/org/callvdois/daynightpvp/events/DeathEvent.java b/src/main/java/org/callvdois/daynightpvp/Listeners/DeathListener.java similarity index 74% rename from src/main/java/org/callvdois/daynightpvp/events/DeathEvent.java rename to src/main/java/org/callvdois/daynightpvp/Listeners/DeathListener.java index ffa0e32..5626dab 100644 --- a/src/main/java/org/callvdois/daynightpvp/events/DeathEvent.java +++ b/src/main/java/org/callvdois/daynightpvp/Listeners/DeathListener.java @@ -1,4 +1,4 @@ -package org.callvdois.daynightpvp.events; +package org.callvdois.daynightpvp.Listeners; import org.bukkit.Bukkit; import org.bukkit.World; @@ -8,18 +8,20 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.permissions.PermissionAttachmentInfo; import org.callvdois.daynightpvp.DayNightPvP; -import org.callvdois.daynightpvp.config.ConfigManager; +import org.callvdois.daynightpvp.files.ConfigFile; import org.callvdois.daynightpvp.utils.SearchUtils; import org.callvdois.daynightpvp.vault.LoseMoneyOnDeath; import java.util.List; -public class DeathEvent implements Listener { +public class DeathListener implements Listener { - private final ConfigManager configManager; + private final ConfigFile configFile; + private final SearchUtils searchUtils; - public DeathEvent() { - configManager = new ConfigManager(); + public DeathListener() { + configFile = new ConfigFile(); + searchUtils = new SearchUtils(); } @EventHandler @@ -27,11 +29,11 @@ public void onPlayerDeath(PlayerDeathEvent event) { Player killed = event.getEntity(); Player killer = event.getEntity().getKiller(); World world = event.getEntity().getWorld(); - List worldList = configManager.getDayNightPvpWorlds(); + List worldList = configFile.getDayNightPvpWorlds(); - if (configManager.getPvpKeepInventoryWhenKilledByPlayer()) { + if (configFile.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); @@ -40,7 +42,7 @@ public void onPlayerDeath(PlayerDeathEvent event) { } Bukkit.getScheduler().runTaskAsynchronously(DayNightPvP.getInstance(), () -> { - if (configManager.getVaultLoseMoneyOnDeathEnabled() && DayNightPvP.vaultIsPresent) { + if (configFile.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/JoinEvent.java b/src/main/java/org/callvdois/daynightpvp/Listeners/JoinListener.java similarity index 54% rename from src/main/java/org/callvdois/daynightpvp/events/JoinEvent.java rename to src/main/java/org/callvdois/daynightpvp/Listeners/JoinListener.java index ba296e6..d25cd10 100644 --- a/src/main/java/org/callvdois/daynightpvp/events/JoinEvent.java +++ b/src/main/java/org/callvdois/daynightpvp/Listeners/JoinListener.java @@ -1,23 +1,23 @@ -package org.callvdois.daynightpvp.events; +package org.callvdois.daynightpvp.Listeners; 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.service.UpdateChecker; +import org.callvdois.daynightpvp.services.UpdateServices; -public class JoinEvent implements Listener { - private final UpdateChecker updateChecker; +public class JoinListener implements Listener { + private final UpdateServices updateServices; - public JoinEvent() { - updateChecker = new UpdateChecker(); + public JoinListener() { + updateServices = new UpdateServices(); } @EventHandler public void onJoin(PlayerJoinEvent event) { if (event.getPlayer().hasPermission("dnp.admin")) { - Bukkit.getServer().getScheduler().runTaskLater(DayNightPvP.getInstance(), () -> updateChecker.checkUpdate(event), 100); + Bukkit.getServer().getScheduler().runTaskLater(DayNightPvP.getInstance(), () -> updateServices.checkUpdate(event), 100); } } diff --git a/src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java b/src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java new file mode 100644 index 0000000..ab761c8 --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/Listeners/ListenersHandler.java @@ -0,0 +1,45 @@ +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/CommandManager.java b/src/main/java/org/callvdois/daynightpvp/commands/CommandHandler.java similarity index 70% rename from src/main/java/org/callvdois/daynightpvp/commands/CommandManager.java rename to src/main/java/org/callvdois/daynightpvp/commands/CommandHandler.java index 419d994..59a5701 100644 --- a/src/main/java/org/callvdois/daynightpvp/commands/CommandManager.java +++ b/src/main/java/org/callvdois/daynightpvp/commands/CommandHandler.java @@ -1,11 +1,12 @@ package org.callvdois.daynightpvp.commands; import org.callvdois.daynightpvp.DayNightPvP; +import org.callvdois.daynightpvp.commands.dnp.DnpCommand; -public class CommandManager { - public void register() { +public class CommandHandler { + public void register() { DayNightPvP.getInstance().getCommand("daynightpvp").setExecutor(new DnpCommand()); - DayNightPvP.getInstance().getCommand("daynightpvp").setTabCompleter(new DnpTabCompleter()); + DayNightPvP.getInstance().getCommand("daynightpvp").setTabCompleter(new DnpCommand()); } } diff --git a/src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java b/src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java deleted file mode 100644 index 910b8ae..0000000 --- a/src/main/java/org/callvdois/daynightpvp/commands/DnpCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index fb01944..0000000 --- a/src/main/java/org/callvdois/daynightpvp/commands/DnpTabCompleter.java +++ /dev/null @@ -1,17 +0,0 @@ -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 new file mode 100644 index 0000000..1adb65e --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/commands/SubCommandHandler.java @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000..60f7a45 --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/commands/dnp/DnpCommand.java @@ -0,0 +1,52 @@ +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 new file mode 100644 index 0000000..39e4078 --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/commands/dnp/reload/DnpReloadCommand.java @@ -0,0 +1,23 @@ +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/config/FilesManager.java b/src/main/java/org/callvdois/daynightpvp/config/FilesManager.java deleted file mode 100644 index d070cdd..0000000 --- a/src/main/java/org/callvdois/daynightpvp/config/FilesManager.java +++ /dev/null @@ -1,101 +0,0 @@ -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/events/EventsManager.java b/src/main/java/org/callvdois/daynightpvp/events/EventsManager.java deleted file mode 100644 index 3388cd2..0000000 --- a/src/main/java/org/callvdois/daynightpvp/events/EventsManager.java +++ /dev/null @@ -1,53 +0,0 @@ -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 deleted file mode 100644 index e180af5..0000000 --- a/src/main/java/org/callvdois/daynightpvp/events/InventoryEvent.java +++ /dev/null @@ -1,139 +0,0 @@ -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/config/ConfigManager.java b/src/main/java/org/callvdois/daynightpvp/files/ConfigFile.java similarity index 78% rename from src/main/java/org/callvdois/daynightpvp/config/ConfigManager.java rename to src/main/java/org/callvdois/daynightpvp/files/ConfigFile.java index 01d9a8d..0fa653a 100644 --- a/src/main/java/org/callvdois/daynightpvp/config/ConfigManager.java +++ b/src/main/java/org/callvdois/daynightpvp/files/ConfigFile.java @@ -1,10 +1,11 @@ -package org.callvdois.daynightpvp.config; +package org.callvdois.daynightpvp.files; 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; @@ -12,49 +13,56 @@ import java.util.ArrayList; import java.util.List; -public class ConfigManager { +public class ConfigFile { - public static File file; - public static FileConfiguration fileConfiguration; + 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 void setValue(String path, Object value) { - fileConfiguration.set(path, value); + fileContent.set(path, value); saveConfig(); } public void saveConfig() { try { - fileConfiguration.save(file); + fileContent.save(fileLocation); } catch (Exception e) { - ConsoleUtils.warning("Error saving configuration file, resetting..."); - resetFile("config.yml"); + consoleUtils.sendWarningMessage("Error saving configuration file, resetting..."); + resetFile(); } } - 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 void resetFile() { + DayNightPvP.getInstance().saveResource("config.yml", true); } public int getInt(String path, Integer defaultValue) { - String configValue = fileConfiguration.getString(path); + String configValue = fileContent.getString(path); if (configValue == null) { - resetFile("config.yml"); + resetFile(); return defaultValue; } @@ -68,10 +76,10 @@ public int getInt(String path, Integer defaultValue) { public Difficulty getDifficulty(String path, Difficulty defaultValue) { - String configValue = fileConfiguration.getString(path); + String configValue = fileContent.getString(path); if (configValue == null) { - resetFile("config.yml"); + resetFile(); return defaultValue; } @@ -85,10 +93,10 @@ public Difficulty getDifficulty(String path, Difficulty defaultValue) { public Sound getSound(String path, Sound defaultValue) { - String configValue = fileConfiguration.getString(path); + String configValue = fileContent.getString(path); if (configValue == null) { - resetFile("config.yml"); + resetFile(); return defaultValue; } @@ -101,10 +109,10 @@ public Sound getSound(String path, Sound defaultValue) { } public String getString(String path, String defaultValue) { - String configValue = fileConfiguration.getString(path); + String configValue = fileContent.getString(path); if (configValue == null) { - resetFile("config.yml"); + resetFile(); return defaultValue; } @@ -112,10 +120,10 @@ public String getString(String path, String defaultValue) { } public boolean getBoolean(String path, Boolean defaultValue) { - String configValue = fileConfiguration.getString(path); + String configValue = fileContent.getString(path); if (configValue == null) { - resetFile("config.yml"); + resetFile(); return defaultValue; } @@ -129,12 +137,12 @@ public boolean getBoolean(String path, Boolean defaultValue) { public List getWorldList(String path, List defaultValue) { - List configValue = fileConfiguration.getStringList(path); + List configValue = fileContent.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("config.yml"); + resetFile(); for (String worldName : defaultValue) { if (Bukkit.getWorld(worldName) != null) { @@ -155,7 +163,7 @@ public List getWorldList(String path, List defaultValue) { } public int getVersion() { - return fileConfiguration.getInt("version"); + return fileContent.getInt("version"); } public boolean getUpdateChecker() { diff --git a/src/main/java/org/callvdois/daynightpvp/config/LangManager.java b/src/main/java/org/callvdois/daynightpvp/files/LangFile.java similarity index 77% rename from src/main/java/org/callvdois/daynightpvp/config/LangManager.java rename to src/main/java/org/callvdois/daynightpvp/files/LangFile.java index b177f20..21bc813 100644 --- a/src/main/java/org/callvdois/daynightpvp/config/LangManager.java +++ b/src/main/java/org/callvdois/daynightpvp/files/LangFile.java @@ -1,25 +1,57 @@ -package org.callvdois.daynightpvp.config; +package org.callvdois.daynightpvp.files; 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; -public class LangManager { +import java.io.File; - public static FileConfiguration fileConfiguration; - private final ConfigManager configManager; +public class LangFile { - public LangManager() { - configManager = new 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 void getLanguageFileSelected() { - String pathLangFile = "lang/" + configManager.getLanguage() + ".yml"; - fileConfiguration = FilesManager.loadConfigFile(DayNightPvP.getInstance(), pathLangFile); + private void loadFileContent() { + fileContent = YamlConfiguration.loadConfiguration(fileLocation); } private String formatMessage(String path) { - String text = fileConfiguration.getString(path); + String text = fileContent.getString(path); if (text != null) { return ChatColor.translateAlternateColorCodes('&', text); } @@ -28,7 +60,7 @@ private String formatMessage(String path) { // Version public int getVersion() { - return fileConfiguration.getInt("version"); + return fileContent.getInt("version"); } // Estados diff --git a/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefManager.java b/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefPreventionHandler.java similarity index 54% rename from src/main/java/org/callvdois/daynightpvp/griefprevention/GriefManager.java rename to src/main/java/org/callvdois/daynightpvp/griefprevention/GriefPreventionHandler.java index 6f4ab37..e1fd317 100644 --- a/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefManager.java +++ b/src/main/java/org/callvdois/daynightpvp/griefprevention/GriefPreventionHandler.java @@ -3,14 +3,11 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention; import org.bukkit.entity.Player; -public class GriefManager { +public class GriefPreventionHandler { public boolean verify(Player damagedPlayer, Player damager) { - if (GriefPrevention.instance.dataStore.getClaimAt(damagedPlayer.getLocation(), true, null) != null || - GriefPrevention.instance.dataStore.getClaimAt(damager.getLocation(), true, null) != null) { - return true; - } - return false; + return GriefPrevention.instance.dataStore.getClaimAt(damagedPlayer.getLocation(), true, null) != null || + GriefPrevention.instance.dataStore.getClaimAt(damager.getLocation(), true, null) != null; } } diff --git a/src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java b/src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java deleted file mode 100644 index 759af24..0000000 --- a/src/main/java/org/callvdois/daynightpvp/gui/LanguageGui.java +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index f6b4257..0000000 --- a/src/main/java/org/callvdois/daynightpvp/gui/MainGui.java +++ /dev/null @@ -1,45 +0,0 @@ -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 deleted file mode 100644 index ba84c04..0000000 --- a/src/main/java/org/callvdois/daynightpvp/gui/WorldGui.java +++ /dev/null @@ -1,116 +0,0 @@ -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 deleted file mode 100644 index 1373dc6..0000000 --- a/src/main/java/org/callvdois/daynightpvp/gui/WorldsGui.java +++ /dev/null @@ -1,124 +0,0 @@ -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 new file mode 100644 index 0000000..a604bb7 --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/metrics/MetricsHandler.java @@ -0,0 +1,12 @@ +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 deleted file mode 100644 index dcec4a4..0000000 --- a/src/main/java/org/callvdois/daynightpvp/metrics/MetricsManager.java +++ /dev/null @@ -1,11 +0,0 @@ -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/PlaceholderManager.java b/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderHandler.java similarity index 92% rename from src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderManager.java rename to src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderHandler.java index 212c679..c237d70 100644 --- a/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderManager.java +++ b/src/main/java/org/callvdois/daynightpvp/placeholder/PlaceholderHandler.java @@ -2,7 +2,7 @@ import org.callvdois.daynightpvp.DayNightPvP; -public class PlaceholderManager { +public class PlaceholderHandler { 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 f49976d..e50e304 100644 --- a/src/main/java/org/callvdois/daynightpvp/placeholder/PvpStatusPlaceholder.java +++ b/src/main/java/org/callvdois/daynightpvp/placeholder/PvpStatusPlaceholder.java @@ -5,19 +5,21 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.callvdois.daynightpvp.DayNightPvP; -import org.callvdois.daynightpvp.config.ConfigManager; -import org.callvdois.daynightpvp.config.LangManager; +import org.callvdois.daynightpvp.files.ConfigFile; +import org.callvdois.daynightpvp.files.LangFile; import org.callvdois.daynightpvp.utils.SearchUtils; import org.jetbrains.annotations.NotNull; public class PvpStatusPlaceholder extends PlaceholderExpansion { - private final LangManager langManager; - private final ConfigManager configManager; + private final LangFile langFile; + private final ConfigFile configFile; + private final SearchUtils searchUtils; public PvpStatusPlaceholder() { - langManager = new LangManager(); - configManager = new ConfigManager(); + langFile = new LangFile(); + configFile = new ConfigFile(); + searchUtils = new SearchUtils(); } @@ -48,13 +50,13 @@ public String onPlaceholderRequest(Player player, String params) { boolean pvpStatus; World world = player.getWorld(); - if (SearchUtils.worldExistsInWorldList(configManager.getDayNightPvpWorlds(), world.getName())) { + if (searchUtils.worldExistsInWorldList(configFile.getDayNightPvpWorlds(), world.getName())) { long time = world.getTime(); - pvpStatus = time >= configManager.getDayNightPvpDayEnd(); + pvpStatus = time >= configFile.getDayNightPvpDayEnd(); } else { - return langManager.getFeedbackError(); + return langFile.getFeedbackError(); } - return pvpStatus ? langManager.getPlaceholderPvpEnabled() : langManager.getPlaceholderPvpDisabled(); + return pvpStatus ? langFile.getPlaceholderPvpEnabled() : langFile.getPlaceholderPvpDisabled(); } if (params.startsWith("pvpstatus_")) { @@ -62,14 +64,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(configManager.getDayNightPvpWorlds(), world.getName())) { + if (searchUtils.worldExistsInWorldList(configFile.getDayNightPvpWorlds(), world.getName())) { long time = world.getTime(); - pvpStatus = time >= configManager.getDayNightPvpDayEnd(); - return pvpStatus ? langManager.getPlaceholderPvpEnabled() : langManager.getPlaceholderPvpDisabled(); + pvpStatus = time >= configFile.getDayNightPvpDayEnd(); + return pvpStatus ? langFile.getPlaceholderPvpEnabled() : langFile.getPlaceholderPvpDisabled(); } } } - return langManager.getFeedbackError(); + return langFile.getFeedbackError(); } } diff --git a/src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java b/src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java new file mode 100644 index 0000000..899dd7e --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/runnables/AutomaticPvp.java @@ -0,0 +1,134 @@ +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 new file mode 100644 index 0000000..af91bd7 --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/runnables/CustomTimeDuration.java @@ -0,0 +1,37 @@ +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 new file mode 100644 index 0000000..cb4191c --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/runnables/RunnableHandler.java @@ -0,0 +1,48 @@ +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 deleted file mode 100644 index f43ade7..0000000 --- a/src/main/java/org/callvdois/daynightpvp/service/DayNightDurationService.java +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 1c21351..0000000 --- a/src/main/java/org/callvdois/daynightpvp/service/ServiceManager.java +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index 4de31df..0000000 --- a/src/main/java/org/callvdois/daynightpvp/service/TimeCheckerService.java +++ /dev/null @@ -1,91 +0,0 @@ -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/PluginServices.java b/src/main/java/org/callvdois/daynightpvp/services/PluginServices.java new file mode 100644 index 0000000..4956d95 --- /dev/null +++ b/src/main/java/org/callvdois/daynightpvp/services/PluginServices.java @@ -0,0 +1,37 @@ +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/service/UpdateChecker.java b/src/main/java/org/callvdois/daynightpvp/services/UpdateServices.java similarity index 74% rename from src/main/java/org/callvdois/daynightpvp/service/UpdateChecker.java rename to src/main/java/org/callvdois/daynightpvp/services/UpdateServices.java index b2738f2..cb7b735 100644 --- a/src/main/java/org/callvdois/daynightpvp/service/UpdateChecker.java +++ b/src/main/java/org/callvdois/daynightpvp/services/UpdateServices.java @@ -1,10 +1,10 @@ -package org.callvdois.daynightpvp.service; +package org.callvdois.daynightpvp.services; 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.config.LangManager; +import org.callvdois.daynightpvp.files.LangFile; import java.io.BufferedReader; import java.io.IOException; @@ -12,12 +12,12 @@ import java.net.HttpURLConnection; import java.net.URL; -public class UpdateChecker { +public class UpdateServices { - private final LangManager langManager; + private final LangFile langFile; - public UpdateChecker() { - langManager = new LangManager(); + public UpdateServices() { + langFile = new LangFile(); } public void checkUpdate(PlayerJoinEvent event) { @@ -28,12 +28,12 @@ public void checkUpdate(PlayerJoinEvent event) { if (!currentVersion.equals(latestVersion)) { - TextComponent link = new TextComponent(langManager.getActionUpdateFoundClick()); + TextComponent link = new TextComponent(langFile.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(langManager.getFeedbackUpdateFound()); - event.getPlayer().sendMessage(langManager.getFeedbackUpdateFoundCurrentVersion().replace("{0}", currentVersion)); - event.getPlayer().sendMessage(langManager.getFeedbackUpdateFoundNewVersion().replace("{0}", latestVersion)); + event.getPlayer().sendMessage(langFile.getFeedbackUpdateFound()); + event.getPlayer().sendMessage(langFile.getFeedbackUpdateFoundCurrentVersion().replace("{0}", currentVersion)); + event.getPlayer().sendMessage(langFile.getFeedbackUpdateFoundNewVersion().replace("{0}", latestVersion)); event.getPlayer().spigot().sendMessage(link); } } catch (IOException ex) { diff --git a/src/main/java/org/callvdois/daynightpvp/utils/ConsoleUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/ConsoleUtils.java index 7986381..f870e13 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 static void warning(String message) { + public void sendWarningMessage(String message) { Bukkit.getLogger().warning(message); } - public static void startMessage() { + public void sendStartupMessage() { 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 deleted file mode 100644 index e439913..0000000 --- a/src/main/java/org/callvdois/daynightpvp/utils/ItemUtils.java +++ /dev/null @@ -1,109 +0,0 @@ -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 f333ec6..dab8b70 100644 --- a/src/main/java/org/callvdois/daynightpvp/utils/PlayerUtils.java +++ b/src/main/java/org/callvdois/daynightpvp/utils/PlayerUtils.java @@ -3,39 +3,31 @@ import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.entity.Player; -import org.callvdois.daynightpvp.config.ConfigManager; +import org.callvdois.daynightpvp.files.ConfigFile; public class PlayerUtils { - private final ConfigManager configManager; + private final ConfigFile configFile; public PlayerUtils() { - configManager = new ConfigManager(); + configFile = new ConfigFile(); } - public static void sendMessageToAllPlayers(World world, String message) { + public void sendMessageToAllPlayers(World world, String message) { for (Player player : world.getPlayers()) { player.sendMessage(message); } } - public static void sendMessageToPlayer(Player player, String message) { - player.sendMessage(message); - } - - public static void playSoundToAllPlayers(World world, Sound sound) { + public 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, configManager.getNotifyPlayersTitleFadeIn(), configManager.getNotifyPlayersTitleStay(), configManager.getNotifyPlayersTitleFadeOut()); + player.sendTitle(title, subTitle, configFile.getNotifyPlayersTitleFadeIn(), configFile.getNotifyPlayersTitleStay(), configFile.getNotifyPlayersTitleFadeOut()); } } } diff --git a/src/main/java/org/callvdois/daynightpvp/utils/PluginUtils.java b/src/main/java/org/callvdois/daynightpvp/utils/PluginUtils.java index 0d65168..5048913 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 static boolean isPluginInstalled(String pluginName) { + public 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 c7c2c58..290e4ea 100644 --- a/src/main/java/org/callvdois/daynightpvp/utils/SearchUtils.java +++ b/src/main/java/org/callvdois/daynightpvp/utils/SearchUtils.java @@ -7,16 +7,7 @@ public class SearchUtils { - 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) { + public 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 7773f5d..235c06e 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.service.TimeCheckerService; +import org.callvdois.daynightpvp.runnables.AutomaticPvp; public class WorldUtils { - public static void setTime(String worldName, int time) { - World world = Bukkit.getWorld(worldName); - assert world != null; - world.setTime(time); + public SearchUtils searchUtils; + + public WorldUtils() { + searchUtils = new SearchUtils(); } - public static boolean checkPlayerIsInWorld(Player player) { + public boolean checkPlayerIsInWorld(Player player) { String worldName = player.getWorld().getName(); - return SearchUtils.worldExistsInWorldList(TimeCheckerService.worldsPvpOff, worldName); + return searchUtils.worldExistsInWorldList(AutomaticPvp.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 fcf57ae..8acb07d 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.config.ConfigManager; -import org.callvdois.daynightpvp.config.LangManager; +import org.callvdois.daynightpvp.files.ConfigFile; +import org.callvdois.daynightpvp.files.LangFile; import org.callvdois.daynightpvp.utils.SearchUtils; import java.util.List; @@ -13,10 +13,11 @@ public class LoseMoneyOnDeath { public static void loseMoneyOnDeath(Player killed, Player killer, World world, List worldList, String percentage) { - ConfigManager configManager = new ConfigManager(); - LangManager langManager = new LangManager(); - boolean onlyNight = configManager.getVaultLoseMoneyOnDeathOnlyAtNight(); - boolean onlyConfiguredWorlds = configManager.getVaultLoseMoneyOnDeathOnlyInConfiguredWorlds(); + ConfigFile configFile = new ConfigFile(); + LangFile langFile = new LangFile(); + SearchUtils searchUtils = new SearchUtils(); + boolean onlyNight = configFile.getVaultLoseMoneyOnDeathOnlyAtNight(); + boolean onlyConfiguredWorlds = configFile.getVaultLoseMoneyOnDeathOnlyInConfiguredWorlds(); Economy economy = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider(); if (killed != null && !percentage.isEmpty() && percentage.matches("[1-9][0-9]?|100")) { @@ -29,7 +30,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 @@ -41,7 +42,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 @@ -55,10 +56,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(langManager.getFeedbackLoseMoney().replace("{0}", killerName).replace("{1}", money)); - if (configManager.getVaultLoseMoneyOnDeathKillerRewardMoney()) { + killed.sendMessage(langFile.getFeedbackLoseMoney().replace("{0}", killerName).replace("{1}", money)); + if (configFile.getVaultLoseMoneyOnDeathKillerRewardMoney()) { economy.depositPlayer(killer, amountRounded); - killer.sendMessage(langManager.getFeedbackWinMoney().replace("{0}", killedName).replace("{1}", money)); + killer.sendMessage(langFile.getFeedbackWinMoney().replace("{0}", killedName).replace("{1}", money)); } } } diff --git a/src/main/java/org/callvdois/daynightpvp/worldguard/AllowPvpOnDayFlag.java b/src/main/java/org/callvdois/daynightpvp/worldguard/AllowDaytimePvpFlag.java similarity index 91% rename from src/main/java/org/callvdois/daynightpvp/worldguard/AllowPvpOnDayFlag.java rename to src/main/java/org/callvdois/daynightpvp/worldguard/AllowDaytimePvpFlag.java index 69e2982..000afe8 100644 --- a/src/main/java/org/callvdois/daynightpvp/worldguard/AllowPvpOnDayFlag.java +++ b/src/main/java/org/callvdois/daynightpvp/worldguard/AllowDaytimePvpFlag.java @@ -12,11 +12,11 @@ import com.sk89q.worldguard.protection.regions.RegionQuery; import org.bukkit.entity.Player; -public class AllowPvpOnDayFlag { +public class AllowDaytimePvpFlag { - public static StateFlag allowPvpOnDay; + private static StateFlag allowPvpOnDay; - public static boolean checkState(Player player) { + public static boolean checkStateOnPosition(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/WorldGuardManager.java b/src/main/java/org/callvdois/daynightpvp/worldguard/FlagHandler.java similarity index 71% rename from src/main/java/org/callvdois/daynightpvp/worldguard/WorldGuardManager.java rename to src/main/java/org/callvdois/daynightpvp/worldguard/FlagHandler.java index a3cca96..ab806c9 100644 --- a/src/main/java/org/callvdois/daynightpvp/worldguard/WorldGuardManager.java +++ b/src/main/java/org/callvdois/daynightpvp/worldguard/FlagHandler.java @@ -2,11 +2,11 @@ import org.callvdois.daynightpvp.DayNightPvP; -public class WorldGuardManager { +public class FlagHandler { public void register() { if (DayNightPvP.worldGuardIsPresent) { - AllowPvpOnDayFlag.register(); + AllowDaytimePvpFlag.register(); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8a761f8..fe0fa70 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,16 +1,27 @@ -name: DayNightPvP +name: '${name}' version: '${project.version}' author: 'needkg' main: org.callvdois.daynightpvp.DayNightPvP api-version: '1.16' -softdepend: [ PlaceholderAPI, GriefPrevention, Vault, WorldGuard ] -load: STARTUP +softdepend: [PlaceholderAPI, GriefPrevention, Vault, WorldGuard] +load: POSTWORLD + commands: - dnp: + daynightpvp: description: "Open the gui." - aliases: [ daynightpvp ] + usage: "/dnp" + aliases: [ dnp ] permission: dnp.admin - dnp reload: + daynightpvp reload: description: "Reload the plugin" - aliases: [ daynightpvp reload ] - permission: dnp.admin \ No newline at end of file + 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