From 761ab51edc4100422d235c55028dba90189bad94 Mon Sep 17 00:00:00 2001 From: Brianna Date: Tue, 20 Aug 2019 13:05:41 -0400 Subject: [PATCH] Testing --- .../songoda/core/command/AbstractCommand.java | 8 ++++---- .../songoda/core/command/CommandManager.java | 16 ++++++++-------- .../com/songoda/core/command/TabManager.java | 6 +++--- .../core/command/commands/CommandDiag.java | 12 ++++++------ .../core/command/commands/CommandSongoda.java | 13 ++++++------- .../java/com/songoda/core/gui/GUIOverview.java | 12 ++++++------ .../core/library/economy/EconomyManager.java | 18 ++++++++++++++---- .../library/economy/economies/Economy.java | 4 +++- .../economy/economies/PlayerPointsEconomy.java | 7 ++++++- .../economy/economies/ReserveEconomy.java | 7 ++++++- .../economy/economies/VaultEconomy.java | 8 +++++++- .../songoda/core/library/locale/Locale.java | 2 +- .../songoda/core/library/locale/Message.java | 2 +- .../songoda/core/listeners/LoginListener.java | 10 +++++----- .../songoda/core/utils/gui/AbstractGUI.java | 11 ++++------- .../com/songoda/core/utils/gui/Clickable.java | 2 +- .../com/songoda/core/utils/gui/OnClose.java | 2 +- .../java/com/songoda/core/utils/gui/Range.java | 8 ++++---- 18 files changed, 86 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/songoda/core/command/AbstractCommand.java b/src/main/java/com/songoda/core/command/AbstractCommand.java index 2146b9ab..fb02b7b5 100644 --- a/src/main/java/com/songoda/core/command/AbstractCommand.java +++ b/src/main/java/com/songoda/core/command/AbstractCommand.java @@ -1,6 +1,6 @@ -package com.songoda.update.command; +package com.songoda.core.command; -import com.songoda.update.SongodaUpdate; +import com.songoda.core.SongodaCore; import org.bukkit.command.CommandSender; import java.util.ArrayList; @@ -49,9 +49,9 @@ public abstract class AbstractCommand { subCommand.add(command); } - protected abstract ReturnType runCommand(SongodaUpdate instance, CommandSender sender, String... args); + protected abstract ReturnType runCommand(SongodaCore instance, CommandSender sender, String... args); - protected abstract List onTab(SongodaUpdate instance, CommandSender sender, String... args); + protected abstract List onTab(SongodaCore instance, CommandSender sender, String... args); public abstract String getPermissionNode(); diff --git a/src/main/java/com/songoda/core/command/CommandManager.java b/src/main/java/com/songoda/core/command/CommandManager.java index 441b4c66..595e574c 100644 --- a/src/main/java/com/songoda/core/command/CommandManager.java +++ b/src/main/java/com/songoda/core/command/CommandManager.java @@ -1,9 +1,9 @@ -package com.songoda.update.command; +package com.songoda.core.command; -import com.songoda.update.SongodaUpdate; -import com.songoda.update.command.commands.CommandDiag; -import com.songoda.update.command.commands.CommandSongoda; -import com.songoda.update.utils.Methods; +import com.songoda.core.SongodaCore; +import com.songoda.core.command.commands.CommandDiag; +import com.songoda.core.command.commands.CommandSongoda; +import com.songoda.core.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.command.*; import org.bukkit.entity.Player; @@ -18,12 +18,12 @@ import java.util.Map; public class CommandManager implements CommandExecutor { - private SongodaUpdate instance; + private SongodaCore instance; private TabManager tabManager; private List commands = new ArrayList<>(); - public CommandManager(SongodaUpdate instance) { + public CommandManager(SongodaCore instance) { this.instance = instance; this.tabManager = new TabManager(this); @@ -97,7 +97,7 @@ public class CommandManager implements CommandExecutor { // Construct a new Command object Constructor constructorPluginCommand = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); constructorPluginCommand.setAccessible(true); - PluginCommand commandObject = constructorPluginCommand.newInstance(command, SongodaUpdate.getHijackedPlugin()); + PluginCommand commandObject = constructorPluginCommand.newInstance(command, SongodaCore.getHijackedPlugin()); commandObject.setExecutor(executor); // Set tab complete diff --git a/src/main/java/com/songoda/core/command/TabManager.java b/src/main/java/com/songoda/core/command/TabManager.java index b298386a..87e73a90 100644 --- a/src/main/java/com/songoda/core/command/TabManager.java +++ b/src/main/java/com/songoda/core/command/TabManager.java @@ -1,6 +1,6 @@ -package com.songoda.update.command; +package com.songoda.core.command; -import com.songoda.update.SongodaUpdate; +import com.songoda.core.SongodaCore; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -50,7 +50,7 @@ public class TabManager implements TabCompleter { private List onCommand(AbstractCommand abstractCommand, String[] strings, CommandSender sender) { - List list = abstractCommand.onTab(SongodaUpdate.getInstance(), sender, strings); + List list = abstractCommand.onTab(SongodaCore.getInstance(), sender, strings); String str = strings[strings.length - 1]; if (list != null && str != null && str.length() >= 1) { try { diff --git a/src/main/java/com/songoda/core/command/commands/CommandDiag.java b/src/main/java/com/songoda/core/command/commands/CommandDiag.java index 0b1309fc..cff481fb 100644 --- a/src/main/java/com/songoda/core/command/commands/CommandDiag.java +++ b/src/main/java/com/songoda/core/command/commands/CommandDiag.java @@ -1,8 +1,8 @@ -package com.songoda.update.command.commands; +package com.songoda.core.command.commands; -import com.songoda.update.Plugin; -import com.songoda.update.SongodaUpdate; -import com.songoda.update.command.AbstractCommand; +import com.songoda.core.Plugin; +import com.songoda.core.SongodaCore; +import com.songoda.core.command.AbstractCommand; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -36,7 +36,7 @@ public class CommandDiag extends AbstractCommand { } @Override - protected ReturnType runCommand(SongodaUpdate instance, CommandSender sender, String... args) { + protected ReturnType runCommand(SongodaCore instance, CommandSender sender, String... args) { sender.sendMessage(""); sender.sendMessage("Songoda Diagnostics Information"); @@ -64,7 +64,7 @@ public class CommandDiag extends AbstractCommand { } @Override - protected List onTab(SongodaUpdate instance, CommandSender sender, String... args) { + protected List onTab(SongodaCore instance, CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/core/command/commands/CommandSongoda.java b/src/main/java/com/songoda/core/command/commands/CommandSongoda.java index 81289ffa..afa55299 100644 --- a/src/main/java/com/songoda/core/command/commands/CommandSongoda.java +++ b/src/main/java/com/songoda/core/command/commands/CommandSongoda.java @@ -1,9 +1,8 @@ -package com.songoda.update.command.commands; +package com.songoda.core.command.commands; -import com.songoda.update.SongodaUpdate; -import com.songoda.update.command.AbstractCommand; -import com.songoda.update.gui.GUIOverview; -import org.bukkit.Bukkit; +import com.songoda.core.SongodaCore; +import com.songoda.core.command.AbstractCommand; +import com.songoda.core.gui.GUIOverview; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,13 +15,13 @@ public class CommandSongoda extends AbstractCommand { } @Override - protected ReturnType runCommand(SongodaUpdate instance, CommandSender sender, String... args) { + protected ReturnType runCommand(SongodaCore instance, CommandSender sender, String... args) { new GUIOverview(instance, (Player) sender); return ReturnType.SUCCESS; } @Override - protected List onTab(SongodaUpdate instance, CommandSender sender, String... args) { + protected List onTab(SongodaCore instance, CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/core/gui/GUIOverview.java b/src/main/java/com/songoda/core/gui/GUIOverview.java index 14aca399..81967554 100644 --- a/src/main/java/com/songoda/core/gui/GUIOverview.java +++ b/src/main/java/com/songoda/core/gui/GUIOverview.java @@ -1,8 +1,8 @@ -package com.songoda.update.gui; +package com.songoda.core.gui; -import com.songoda.update.Plugin; -import com.songoda.update.SongodaUpdate; -import com.songoda.update.utils.gui.AbstractGUI; +import com.songoda.core.Plugin; +import com.songoda.core.SongodaCore; +import com.songoda.core.utils.gui.AbstractGUI; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -10,9 +10,9 @@ import java.util.List; public class GUIOverview extends AbstractGUI { - private final SongodaUpdate update; + private final SongodaCore update; - public GUIOverview(SongodaUpdate update, Player player) { + public GUIOverview(SongodaCore update, Player player) { super(player); this.update = update; diff --git a/src/main/java/com/songoda/core/library/economy/EconomyManager.java b/src/main/java/com/songoda/core/library/economy/EconomyManager.java index 148601b4..abe1cfc6 100644 --- a/src/main/java/com/songoda/core/library/economy/EconomyManager.java +++ b/src/main/java/com/songoda/core/library/economy/EconomyManager.java @@ -7,12 +7,13 @@ import com.songoda.core.library.economy.economies.VaultEconomy; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; -import java.util.HashMap; -import java.util.Map; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; public class EconomyManager { - private static Map registeredEconomies = new HashMap(); + private static Set registeredEconomies = new HashSet<>(); public static void load() { if (!registeredEconomies.isEmpty()) return; @@ -20,10 +21,19 @@ public class EconomyManager { PluginManager pluginManager = Bukkit.getPluginManager(); if (pluginManager.isPluginEnabled("Vault")) - registeredEconomies.put(new VaultEconomy()); + registeredEconomies.add(new VaultEconomy()); if (pluginManager.isPluginEnabled("Reserve")) registeredEconomies.add(new ReserveEconomy()); if (pluginManager.isPluginEnabled("PlayerPoints")) registeredEconomies.add(new PlayerPointsEconomy()); } + + public static Economy getEconomy(String name) { + return registeredEconomies.stream().filter(economy -> economy.getName().equalsIgnoreCase(name.trim())) + .findFirst().orElse(null); + } + + public static Set getRegisteredEconomies() { + return Collections.unmodifiableSet(registeredEconomies); + } } diff --git a/src/main/java/com/songoda/core/library/economy/economies/Economy.java b/src/main/java/com/songoda/core/library/economy/economies/Economy.java index 9d5a9141..90bc5a86 100644 --- a/src/main/java/com/songoda/core/library/economy/economies/Economy.java +++ b/src/main/java/com/songoda/core/library/economy/economies/Economy.java @@ -1,9 +1,11 @@ -package com.songoda.ultimateclaims.economy; +package com.songoda.core.library.economy.economies; import org.bukkit.OfflinePlayer; public interface Economy { + String getName(); + boolean hasBalance(OfflinePlayer player, double cost); boolean withdrawBalance(OfflinePlayer player, double cost); diff --git a/src/main/java/com/songoda/core/library/economy/economies/PlayerPointsEconomy.java b/src/main/java/com/songoda/core/library/economy/economies/PlayerPointsEconomy.java index bc739556..538f5027 100644 --- a/src/main/java/com/songoda/core/library/economy/economies/PlayerPointsEconomy.java +++ b/src/main/java/com/songoda/core/library/economy/economies/PlayerPointsEconomy.java @@ -1,4 +1,4 @@ -package com.songoda.ultimateclaims.economy; +package com.songoda.core.library.economy.economies; import org.black_ixx.playerpoints.PlayerPoints; import org.bukkit.Bukkit; @@ -16,6 +16,11 @@ public class PlayerPointsEconomy implements Economy { return (int) Math.ceil(amount); } + @Override + public String getName() { + return "PlayerPoints"; + } + @Override public boolean hasBalance(OfflinePlayer player, double cost) { int amount = convertAmount(cost); diff --git a/src/main/java/com/songoda/core/library/economy/economies/ReserveEconomy.java b/src/main/java/com/songoda/core/library/economy/economies/ReserveEconomy.java index 5fecdf3e..56c34424 100644 --- a/src/main/java/com/songoda/core/library/economy/economies/ReserveEconomy.java +++ b/src/main/java/com/songoda/core/library/economy/economies/ReserveEconomy.java @@ -1,4 +1,4 @@ -package com.songoda.ultimateclaims.economy; +package com.songoda.core.library.economy.economies; import net.tnemc.core.Reserve; import net.tnemc.core.economy.EconomyAPI; @@ -15,6 +15,11 @@ public class ReserveEconomy implements Economy { economyAPI = Reserve.instance().economy(); } + @Override + public String getName() { + return "Reserve"; + } + @Override public boolean hasBalance(OfflinePlayer player, double cost) { return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost)); diff --git a/src/main/java/com/songoda/core/library/economy/economies/VaultEconomy.java b/src/main/java/com/songoda/core/library/economy/economies/VaultEconomy.java index dca7967c..14fbe64b 100644 --- a/src/main/java/com/songoda/core/library/economy/economies/VaultEconomy.java +++ b/src/main/java/com/songoda/core/library/economy/economies/VaultEconomy.java @@ -1,9 +1,10 @@ -package com.songoda.ultimateclaims.economy; +package com.songoda.core.library.economy.economies; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; public class VaultEconomy implements Economy { + private final net.milkbowl.vault.economy.Economy vault; public VaultEconomy() { @@ -11,6 +12,11 @@ public class VaultEconomy implements Economy { getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider(); } + @Override + public String getName() { + return "Vault"; + } + @Override public boolean hasBalance(OfflinePlayer player, double cost) { return vault.has(player, cost); diff --git a/src/main/java/com/songoda/core/library/locale/Locale.java b/src/main/java/com/songoda/core/library/locale/Locale.java index a12f68b0..e16ad0d2 100644 --- a/src/main/java/com/songoda/core/library/locale/Locale.java +++ b/src/main/java/com/songoda/core/library/locale/Locale.java @@ -1,4 +1,4 @@ -package com.songoda.ultimateclaims.utils.locale; +package com.songoda.core.library.locale; import org.bukkit.plugin.java.JavaPlugin; diff --git a/src/main/java/com/songoda/core/library/locale/Message.java b/src/main/java/com/songoda/core/library/locale/Message.java index 7ad2f6b2..4aef25ab 100644 --- a/src/main/java/com/songoda/core/library/locale/Message.java +++ b/src/main/java/com/songoda/core/library/locale/Message.java @@ -1,4 +1,4 @@ -package com.songoda.ultimateclaims.utils.locale; +package com.songoda.core.library.locale; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/songoda/core/listeners/LoginListener.java b/src/main/java/com/songoda/core/listeners/LoginListener.java index 1fe522c4..97dee07b 100644 --- a/src/main/java/com/songoda/core/listeners/LoginListener.java +++ b/src/main/java/com/songoda/core/listeners/LoginListener.java @@ -1,7 +1,7 @@ -package com.songoda.update.listeners; +package com.songoda.core.listeners; -import com.songoda.update.Plugin; -import com.songoda.update.SongodaUpdate; +import com.songoda.core.Plugin; +import com.songoda.core.SongodaCore; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -9,9 +9,9 @@ import org.bukkit.event.player.PlayerLoginEvent; public class LoginListener implements Listener { - private SongodaUpdate instance; + private SongodaCore instance; - public LoginListener(SongodaUpdate instance) { + public LoginListener(SongodaCore instance) { this.instance = instance; } diff --git a/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java index f0add34e..6ab4dc56 100644 --- a/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java +++ b/src/main/java/com/songoda/core/utils/gui/AbstractGUI.java @@ -1,10 +1,7 @@ -package com.songoda.update.utils.gui; +package com.songoda.core.utils.gui; -import com.songoda.update.SongodaUpdate; -import com.songoda.update.utils.Methods; -import com.songoda.update.utils.gui.Clickable; -import com.songoda.update.utils.gui.OnClose; -import com.songoda.update.utils.gui.Range; +import com.songoda.core.SongodaCore; +import com.songoda.core.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -125,7 +122,7 @@ public abstract class AbstractGUI implements Listener { registerOnCloses(); } constructGUI(); - initializeListeners(SongodaUpdate.getHijackedPlugin()); + initializeListeners(SongodaCore.getHijackedPlugin()); player.openInventory(inventory); } diff --git a/src/main/java/com/songoda/core/utils/gui/Clickable.java b/src/main/java/com/songoda/core/utils/gui/Clickable.java index f198fa72..fa169be8 100644 --- a/src/main/java/com/songoda/core/utils/gui/Clickable.java +++ b/src/main/java/com/songoda/core/utils/gui/Clickable.java @@ -1,4 +1,4 @@ -package com.songoda.update.utils.gui; +package com.songoda.core.utils.gui; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/src/main/java/com/songoda/core/utils/gui/OnClose.java b/src/main/java/com/songoda/core/utils/gui/OnClose.java index 0660d8e4..684ce9ce 100644 --- a/src/main/java/com/songoda/core/utils/gui/OnClose.java +++ b/src/main/java/com/songoda/core/utils/gui/OnClose.java @@ -1,4 +1,4 @@ -package com.songoda.update.utils.gui; +package com.songoda.core.utils.gui; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; diff --git a/src/main/java/com/songoda/core/utils/gui/Range.java b/src/main/java/com/songoda/core/utils/gui/Range.java index b440e231..6c58f97d 100644 --- a/src/main/java/com/songoda/core/utils/gui/Range.java +++ b/src/main/java/com/songoda/core/utils/gui/Range.java @@ -1,7 +1,7 @@ -package com.songoda.update.utils.gui; +package com.songoda.core.utils.gui; -import com.songoda.update.SongodaUpdate; -import com.songoda.update.utils.ServerVersion; +import com.songoda.core.SongodaCore; +import com.songoda.core.utils.ServerVersion; import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; @@ -18,7 +18,7 @@ public class Range { this.max = max; this.clickType = clickType; this.bottom = bottom; - if (SongodaUpdate.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; + if (SongodaCore.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; } public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {