mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-26 20:16:16 +01:00
Make methods in ChestCommands class static
This commit is contained in:
parent
cf8e5da6bf
commit
a86e3a6951
@ -45,6 +45,7 @@ import org.bstats.bukkit.MetricsLite;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -56,11 +57,11 @@ public class ChestCommands extends BaseJavaPlugin {
|
|||||||
|
|
||||||
public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN;
|
public static final String CHAT_PREFIX = ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "ChestCommands" + ChatColor.DARK_GREEN + "] " + ChatColor.GREEN;
|
||||||
|
|
||||||
private static ChestCommands instance;
|
private static Plugin pluginInstance;
|
||||||
private static Path dataFolderPath;
|
private static Path dataFolderPath;
|
||||||
|
|
||||||
private ConfigManager configManager;
|
private static ConfigManager configManager;
|
||||||
private MenuManager menuManager;
|
private static MenuManager menuManager;
|
||||||
private static Settings settings;
|
private static Settings settings;
|
||||||
private static Lang lang;
|
private static Lang lang;
|
||||||
private static CustomPlaceholders placeholders;
|
private static CustomPlaceholders placeholders;
|
||||||
@ -78,24 +79,24 @@ public class ChestCommands extends BaseJavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance != null || System.getProperty("ChestCommandsLoaded") != null) {
|
if (pluginInstance != null || System.getProperty("ChestCommandsLoaded") != null) {
|
||||||
Log.warning("Please do not use /reload or plugin reloaders. Use the command \"/cc reload\" instead.");
|
Log.warning("Please do not use /reload or plugin reloaders. Use the command \"/cc reload\" instead.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.setProperty("ChestCommandsLoaded", "true");
|
System.setProperty("ChestCommandsLoaded", "true");
|
||||||
|
|
||||||
instance = this;
|
pluginInstance = this;
|
||||||
dataFolderPath = getDataFolder().toPath();
|
dataFolderPath = getDataFolder().toPath();
|
||||||
Log.setLogger(getLogger());
|
Log.setLogger(getLogger());
|
||||||
BackendAPI.setImplementation(new DefaultBackendAPI());
|
|
||||||
|
|
||||||
configManager = new ConfigManager(getDataFolderPath());
|
configManager = new ConfigManager(getDataFolderPath());
|
||||||
menuManager = new MenuManager();
|
menuManager = new MenuManager();
|
||||||
settings = new Settings();
|
settings = new Settings();
|
||||||
lang = new Lang();
|
lang = new Lang();
|
||||||
placeholders = new CustomPlaceholders();
|
placeholders = new CustomPlaceholders();
|
||||||
|
|
||||||
|
BackendAPI.setImplementation(new DefaultBackendAPI());
|
||||||
|
|
||||||
VaultEconomyHook.INSTANCE.setup();
|
VaultEconomyHook.INSTANCE.setup();
|
||||||
BarAPIHook.INSTANCE.setup();
|
BarAPIHook.INSTANCE.setup();
|
||||||
PlaceholderAPIHook.INSTANCE.setup();
|
PlaceholderAPIHook.INSTANCE.setup();
|
||||||
@ -150,16 +151,12 @@ public class ChestCommands extends BaseJavaPlugin {
|
|||||||
Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L);
|
Bukkit.getScheduler().runTaskTimer(this, new TickingTask(), 1L, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path getDataFolderPath() {
|
|
||||||
return dataFolderPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
closeAllMenus();
|
closeAllMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorCollector load() {
|
public static ErrorCollector load() {
|
||||||
ErrorCollector errorCollector = new PrintableErrorCollector();
|
ErrorCollector errorCollector = new PrintableErrorCollector();
|
||||||
menuManager.clear();
|
menuManager.clear();
|
||||||
boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder());
|
boolean isFreshInstall = !Files.isDirectory(configManager.getRootDataFolder());
|
||||||
@ -210,11 +207,15 @@ public class ChestCommands extends BaseJavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ChestCommands getInstance() {
|
public static Plugin getPluginInstance() {
|
||||||
return instance;
|
return pluginInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuManager getMenuManager() {
|
public static Path getDataFolderPath() {
|
||||||
|
return dataFolderPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MenuManager getMenuManager() {
|
||||||
return menuManager;
|
return menuManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ public class DefaultBackendAPI extends BackendAPI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPluginMenu(String yamlFile) {
|
public boolean isPluginMenu(String yamlFile) {
|
||||||
return ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile) != null;
|
return ChestCommands.getMenuManager().getMenuByFileName(yamlFile) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean openPluginMenu(Player player, String yamlFile) {
|
public boolean openPluginMenu(Player player, String yamlFile) {
|
||||||
InternalIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(yamlFile);
|
InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(yamlFile);
|
||||||
|
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
menu.open(player);
|
menu.open(player);
|
||||||
|
@ -31,14 +31,14 @@ public class OpenMenuAction extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute0(final Player player) {
|
protected void execute0(final Player player) {
|
||||||
final InternalIconMenu menu = ChestCommands.getInstance().getMenuManager().getMenuByFileName(targetMenu.getValue(player));
|
final InternalIconMenu menu = ChestCommands.getMenuManager().getMenuByFileName(targetMenu.getValue(player));
|
||||||
|
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
/*
|
/*
|
||||||
* Delay the task, since this action is executed in ClickInventoryEvent
|
* Delay the task, since this action is executed in ClickInventoryEvent
|
||||||
* and opening another inventory in the same moment is not a good idea.
|
* and opening another inventory in the same moment is not a good idea.
|
||||||
*/
|
*/
|
||||||
Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> {
|
||||||
menu.openCheckingPermission(player);
|
menu.openCheckingPermission(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class CommandHandler extends CommandFramework {
|
|||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for free
|
// This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for free
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX);
|
sender.sendMessage(ChestCommands.CHAT_PREFIX);
|
||||||
sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getInstance().getDescription().getVersion());
|
sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getPluginInstance().getDescription().getVersion());
|
||||||
sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");
|
sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");
|
||||||
sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help");
|
sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/" + label + " help");
|
||||||
return;
|
return;
|
||||||
@ -83,7 +83,7 @@ public class CommandHandler extends CommandFramework {
|
|||||||
|
|
||||||
ChestCommands.closeAllMenus();
|
ChestCommands.closeAllMenus();
|
||||||
|
|
||||||
ErrorCollector errorCollector = ChestCommands.getInstance().load();
|
ErrorCollector errorCollector = ChestCommands.load();
|
||||||
|
|
||||||
if (!errorCollector.hasErrors()) {
|
if (!errorCollector.hasErrors()) {
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded.");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + "Plugin reloaded.");
|
||||||
|
@ -29,8 +29,8 @@ public enum BungeeCordHook implements PluginHook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getInstance(), "BungeeCord")) {
|
if (!Bukkit.getMessenger().isOutgoingChannelRegistered(ChestCommands.getPluginInstance(), "BungeeCord")) {
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getInstance(), "BungeeCord");
|
Bukkit.getMessenger().registerOutgoingPluginChannel(ChestCommands.getPluginInstance(), "BungeeCord");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public enum BungeeCordHook implements PluginHook {
|
|||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray());
|
player.sendPluginMessage(ChestCommands.getPluginInstance(), "BungeeCord", byteArrayOutputStream.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class InventoryListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only handle the click AFTER the event has finished
|
// Only handle the click AFTER the event has finished
|
||||||
Bukkit.getScheduler().runTask(ChestCommands.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> {
|
||||||
ClickResult result = slotClickHandler.onClick();
|
ClickResult result = slotClickHandler.onClick();
|
||||||
|
|
||||||
if (result == ClickResult.CLOSE) {
|
if (result == ClickResult.CLOSE) {
|
||||||
|
@ -77,12 +77,14 @@ public class SignListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onCreateMenuSign(SignChangeEvent event) {
|
public void onCreateMenuSign(SignChangeEvent event) {
|
||||||
if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(event.getPlayer())) {
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (isCreatingMenuSign(event.getLine(HEADER_LINE)) && canCreateMenuSign(player)) {
|
||||||
String menuFileName = event.getLine(FILENAME_LINE).trim();
|
String menuFileName = event.getLine(FILENAME_LINE).trim();
|
||||||
|
|
||||||
if (menuFileName.isEmpty()) {
|
if (menuFileName.isEmpty()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "You must write a menu name in the second line.");
|
player.sendMessage(ChatColor.RED + "You must write a menu name in the second line.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,12 +93,12 @@ public class SignListener implements Listener {
|
|||||||
InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName);
|
InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName);
|
||||||
if (iconMenu == null) {
|
if (iconMenu == null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found.");
|
player.sendMessage(ChatColor.RED + "Menu \"" + menuFileName + "\" was not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setLine(HEADER_LINE, VALID_SIGN_COLOR + event.getLine(HEADER_LINE));
|
event.setLine(HEADER_LINE, VALID_SIGN_COLOR + event.getLine(HEADER_LINE));
|
||||||
event.getPlayer().sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + ".");
|
player.sendMessage(ChatColor.GREEN + "Successfully created a sign for the menu " + menuFileName + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user