performance & ram optimizations
This commit is contained in:
parent
bd5b8be487
commit
bb5a90b390
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea/
|
@ -7,12 +7,13 @@ import net.mindoverflow.hubthat.listeners.PlayerChatListener;
|
||||
import net.mindoverflow.hubthat.listeners.PlayerJoinListener;
|
||||
import net.mindoverflow.hubthat.listeners.PlayerMoveListener;
|
||||
import net.mindoverflow.hubthat.listeners.PlayerRespawnListener;
|
||||
import net.mindoverflow.hubthat.utils.ConfigEntries;
|
||||
import net.mindoverflow.hubthat.utils.Debugger;
|
||||
import net.mindoverflow.hubthat.utils.TeleportUtils;
|
||||
import net.mindoverflow.hubthat.utils.files.FileUtils;
|
||||
import net.mindoverflow.hubthat.utils.files.OldConfigConversion;
|
||||
import net.mindoverflow.hubthat.utils.statistics.Metrics;
|
||||
import net.mindoverflow.hubthat.utils.statistics.UpdateChecker;
|
||||
import net.mindoverflow.hubthat.utils.*;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -23,12 +24,15 @@ import java.util.logging.Logger;
|
||||
public class HubThat extends JavaPlugin
|
||||
{
|
||||
// Instantiate a Debugger for this class.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
// Initializing needed variables.
|
||||
public static Logger logger;
|
||||
private PluginManager pluginManager;
|
||||
public UpdateChecker updateChecker;
|
||||
private static HubThat instance;
|
||||
|
||||
public HubThat() { instance = this; }
|
||||
|
||||
// Method called when the plugin is being loaded.
|
||||
@Override
|
||||
@ -49,24 +53,21 @@ public class HubThat extends JavaPlugin
|
||||
FileUtils fileUtilsInstance = new FileUtils(this);
|
||||
HubThatCommand hubThatCommandInstance = new HubThatCommand(this);
|
||||
HubCommand hubCommandInstance = new HubCommand(this);
|
||||
SetHubCommand setHubCommandInstance = new SetHubCommand(this);
|
||||
SpawnCommand spawnCommandInstance = new SpawnCommand(this);
|
||||
SetSpawnCommand setSpawnCommandInstance = new SetSpawnCommand(this);
|
||||
WorldListCommand worldListCommandInstance = new WorldListCommand(this);
|
||||
WorldTpCommand worldTpCommandInstance = new WorldTpCommand(this);
|
||||
UpdateChecker updateCheckerInstance = new UpdateChecker(this);
|
||||
|
||||
|
||||
// We need to instantiate Utils classes because they need to access plugin data and server.
|
||||
PermissionUtils permissionUtilsInstance = new PermissionUtils(this);
|
||||
TeleportUtils teleportUtilsInstance = new TeleportUtils(this);
|
||||
MessageUtils messageUtilsInstance = new MessageUtils(this);
|
||||
UpdateChecker updateCheckerInstance = new UpdateChecker(this);
|
||||
updateChecker = new UpdateChecker(this);
|
||||
debugger.sendDebugMessage(Level.INFO, "Done instantiating classes!");
|
||||
|
||||
// Register Listeners
|
||||
debugger.sendDebugMessage(Level.INFO, "Registering listeners...");
|
||||
pluginManager.registerEvents(new PlayerJoinListener(this), this);
|
||||
pluginManager.registerEvents(new PlayerMoveListener(this), this);
|
||||
pluginManager.registerEvents(new PlayerMoveListener(), this);
|
||||
pluginManager.registerEvents(new PlayerChatListener(this), this);
|
||||
pluginManager.registerEvents(new PlayerRespawnListener(this), this);
|
||||
|
||||
@ -82,7 +83,7 @@ public class HubThat extends JavaPlugin
|
||||
|
||||
getCommand("hub").setExecutor(hubCommandInstance);
|
||||
|
||||
getCommand("sethub").setExecutor(setHubCommandInstance);
|
||||
getCommand("sethub").setExecutor(new SetHubCommand());
|
||||
|
||||
getCommand("spawn").setExecutor(spawnCommandInstance);
|
||||
getCommand("spawn").setTabCompleter(new SpawnCompleter());
|
||||
@ -111,37 +112,6 @@ public class HubThat extends JavaPlugin
|
||||
FileUtils.reloadYamls();
|
||||
debugger.sendDebugMessage(Level.INFO, "Done!");
|
||||
|
||||
// Check for updates, if they are enabled.
|
||||
if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntries.UPDATE_CHECKER_ENABLED.path))
|
||||
{
|
||||
debugger.sendDebugMessage(Level.INFO, "Update checking is enabled.");
|
||||
// Start the update checking delayed job. It will handle checking updates, storing variables and telling the console.
|
||||
debugger.sendDebugMessage(Level.INFO, "Running task (via Main).");
|
||||
//UpdateChecker.runTimer();
|
||||
// Check if the links are valid.
|
||||
/*debugger.sendDebugMessage(Level.INFO, "Checking if links are valid via Main.");
|
||||
if(updateCheckerInstance.linksValid())
|
||||
{
|
||||
debugger.sendDebugMessage(Level.INFO, "Links are valid.");
|
||||
// Check if the update is needed (if newest version is different from current version).
|
||||
// We need to surround it with try/catch because it may throw a IOException,
|
||||
try
|
||||
{
|
||||
debugger.sendDebugMessage(Level.INFO, "Checking updates are needed via Main.");
|
||||
updateCheckerInstance.checkUpdates();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // If the links are not valid... (eg: server/internet is offline)
|
||||
// Log it to the console.
|
||||
logger.log(Level.SEVERE, "There's a problem with the updates server.");
|
||||
logger.log(Level.SEVERE, "Please check if there are any updates manually.");
|
||||
}*/
|
||||
}
|
||||
|
||||
debugger.sendDebugMessage(Level.INFO,"Setting up Metrics...");
|
||||
setupMetrics();
|
||||
debugger.sendDebugMessage(Level.INFO,"Done setting up Metrics!");
|
||||
@ -181,4 +151,8 @@ public class HubThat extends JavaPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public static HubThat getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -17,10 +17,10 @@ public class HubCommand implements CommandExecutor
|
||||
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private static Debugger debugger = new Debugger(HubCommand.class.getName());
|
||||
private static final Debugger debugger = new Debugger(HubCommand.class.getName());
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private static HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
public HubCommand(HubThat givenPlugin) { plugin = givenPlugin; }
|
||||
|
@ -5,11 +5,9 @@ import net.mindoverflow.hubthat.commands.hubthatcommands.HelpCommand;
|
||||
import net.mindoverflow.hubthat.commands.hubthatcommands.ReloadCommand;
|
||||
import net.mindoverflow.hubthat.utils.Debugger;
|
||||
import net.mindoverflow.hubthat.utils.MessageUtils;
|
||||
import net.mindoverflow.hubthat.utils.LocalizedMessages;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -17,10 +15,10 @@ public class HubThatCommand implements CommandExecutor
|
||||
{
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
public HubThatCommand(HubThat givenPlugin)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.mindoverflow.hubthat.commands;
|
||||
|
||||
import net.mindoverflow.hubthat.HubThat;
|
||||
import net.mindoverflow.hubthat.utils.*;
|
||||
import net.mindoverflow.hubthat.utils.files.FileUtils;
|
||||
import org.bukkit.Location;
|
||||
@ -16,15 +15,7 @@ public class SetHubCommand implements CommandExecutor
|
||||
{
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private HubThat plugin;
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
public SetHubCommand(HubThat givenPlugin) { plugin = givenPlugin; }
|
||||
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args)
|
||||
|
@ -18,11 +18,11 @@ public class SetSpawnCommand implements CommandExecutor
|
||||
{
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
|
@ -17,11 +17,11 @@ public class SpawnCommand implements CommandExecutor
|
||||
{
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private static Debugger debugger = new Debugger(SpawnCommand.class.getName());
|
||||
private static final Debugger debugger = new Debugger(SpawnCommand.class.getName());
|
||||
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private static HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
public SpawnCommand(HubThat givenPlugin) { plugin = givenPlugin; }
|
||||
|
@ -15,11 +15,11 @@ public class WorldListCommand implements CommandExecutor
|
||||
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
public WorldListCommand(HubThat givenPlugin) { plugin = givenPlugin; }
|
||||
|
@ -16,11 +16,11 @@ public class WorldTpCommand implements CommandExecutor
|
||||
{
|
||||
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
|
||||
// Initialize the plugin variable so we can access all of the plugin's data.
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
|
||||
// Constructor to actually give "plugin" a value.
|
||||
public WorldTpCommand(HubThat givenPlugin) { plugin = givenPlugin; }
|
||||
|
@ -1,9 +1,10 @@
|
||||
package net.mindoverflow.hubthat.commands.hubthatcommands;
|
||||
|
||||
import net.mindoverflow.hubthat.utils.*;
|
||||
import org.bukkit.Location;
|
||||
import net.mindoverflow.hubthat.utils.LocalizedMessages;
|
||||
import net.mindoverflow.hubthat.utils.MessageUtils;
|
||||
import net.mindoverflow.hubthat.utils.PermissionUtils;
|
||||
import net.mindoverflow.hubthat.utils.Permissions;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class HelpCommand
|
||||
|
@ -9,7 +9,7 @@ import java.util.logging.Level;
|
||||
|
||||
public class ReloadCommand
|
||||
{
|
||||
private static Debugger debugger = new Debugger(ReloadCommand.class.getName());
|
||||
private static final Debugger debugger = new Debugger(ReloadCommand.class.getName());
|
||||
|
||||
|
||||
public static void reloadCommand(CommandSender commandSender, HubThat plugin)
|
||||
|
@ -13,9 +13,9 @@ public class PlayerChatListener implements Listener
|
||||
{
|
||||
|
||||
// Instantiate a Debugger for this class.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
public PlayerChatListener(HubThat givenPlugin)
|
||||
{
|
||||
plugin = givenPlugin;
|
||||
|
@ -2,7 +2,9 @@ package net.mindoverflow.hubthat.listeners;
|
||||
|
||||
import net.mindoverflow.hubthat.HubThat;
|
||||
import net.mindoverflow.hubthat.commands.HubCommand;
|
||||
import net.mindoverflow.hubthat.utils.*;
|
||||
import net.mindoverflow.hubthat.utils.ConfigEntries;
|
||||
import net.mindoverflow.hubthat.utils.Debugger;
|
||||
import net.mindoverflow.hubthat.utils.MessageUtils;
|
||||
import net.mindoverflow.hubthat.utils.files.FileUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -16,9 +18,9 @@ import java.util.logging.Level;
|
||||
public class PlayerJoinListener implements Listener
|
||||
{
|
||||
// Instantiate a Debugger for this class.
|
||||
private Debugger debugger = new Debugger(getClass().getName());
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
public PlayerJoinListener(HubThat givenPlugin)
|
||||
{
|
||||
plugin = givenPlugin;
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.mindoverflow.hubthat.listeners;
|
||||
|
||||
import net.mindoverflow.hubthat.HubThat;
|
||||
import net.mindoverflow.hubthat.utils.*;
|
||||
import net.mindoverflow.hubthat.utils.CommonValues;
|
||||
import net.mindoverflow.hubthat.utils.ConfigEntries;
|
||||
import net.mindoverflow.hubthat.utils.LocalizedMessages;
|
||||
import net.mindoverflow.hubthat.utils.MessageUtils;
|
||||
import net.mindoverflow.hubthat.utils.files.FileUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -10,13 +12,6 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
public class PlayerMoveListener implements Listener
|
||||
{
|
||||
|
||||
private HubThat plugin;
|
||||
|
||||
public PlayerMoveListener(HubThat givenPlugin)
|
||||
{
|
||||
plugin = givenPlugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
public class PlayerRespawnListener implements Listener
|
||||
{
|
||||
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
public PlayerRespawnListener(HubThat givenPlugin)
|
||||
{
|
||||
plugin = givenPlugin;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.mindoverflow.hubthat.utils;
|
||||
|
||||
|
||||
import net.mindoverflow.hubthat.HubThat;
|
||||
import net.mindoverflow.hubthat.utils.files.FileUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -12,14 +11,8 @@ import java.util.logging.Level;
|
||||
public class MessageUtils
|
||||
{
|
||||
// Initialize the Debugger instance.
|
||||
private static Debugger debugger = new Debugger(MessageUtils.class.getName());
|
||||
private static final Debugger debugger = new Debugger(MessageUtils.class.getName());
|
||||
|
||||
|
||||
private static HubThat plugin;
|
||||
public MessageUtils(HubThat plugin)
|
||||
{
|
||||
MessageUtils.plugin = plugin;
|
||||
}
|
||||
// Method to automatically load and send a localized message to the CommandSender.
|
||||
public static void sendLocalizedMessage(CommandSender sender, LocalizedMessages messageEnum)
|
||||
{
|
||||
|
@ -1,18 +1,10 @@
|
||||
package net.mindoverflow.hubthat.utils;
|
||||
|
||||
import net.mindoverflow.hubthat.HubThat;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class PermissionUtils
|
||||
{
|
||||
|
||||
// Initialize the Debugger instance.
|
||||
private static Debugger debugger = new Debugger(PermissionUtils.class.getName());
|
||||
|
||||
|
||||
private static HubThat plugin;
|
||||
public PermissionUtils(HubThat givenPlugin) { plugin = givenPlugin; }
|
||||
|
||||
// Method to get the permission string from the Permissions enum.
|
||||
public static boolean playerHasPermission(CommandSender user, Permissions permission)
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ public class TeleportUtils
|
||||
plugin = givenPlugin;
|
||||
}
|
||||
// Initialize the debugger so I can debug the plugin.
|
||||
private static Debugger debugger = new Debugger(TeleportUtils.class.getName());
|
||||
private static final Debugger debugger = new Debugger(TeleportUtils.class.getName());
|
||||
|
||||
// Method to teleport a player, given the location coordinates, the world name and the player's name.
|
||||
public static void teleportPlayer(double x, double y, double z, double yaw, double pitch, String worldName, String playerName)
|
||||
|
@ -16,7 +16,7 @@ public class FileUtils
|
||||
{
|
||||
|
||||
// Instantiate a Debugger for this class.
|
||||
private static Debugger debugger = new Debugger(FileUtils.class.getName());
|
||||
private static final Debugger debugger = new Debugger(FileUtils.class.getName());
|
||||
|
||||
// Necessary variables.
|
||||
private static HubThat plugin;
|
||||
|
@ -1,29 +1,8 @@
|
||||
package net.mindoverflow.hubthat.utils.statistics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,9 +10,16 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
|
@ -24,9 +24,7 @@ public class UpdateChecker implements Runnable
|
||||
|
||||
public static BukkitTask task;
|
||||
|
||||
Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
|
||||
private final Debugger debugger = new Debugger(getClass().getName());
|
||||
|
||||
public String newVersion, updateLink;
|
||||
public ArrayList<String> updateText = new ArrayList<>(), warningMessage = new ArrayList<>();
|
||||
@ -35,7 +33,7 @@ public class UpdateChecker implements Runnable
|
||||
public Boolean isServerUnreachable = true;
|
||||
public String errorCode;
|
||||
|
||||
private HubThat plugin;
|
||||
private final HubThat plugin;
|
||||
public UpdateChecker(HubThat givenPlugin)
|
||||
{
|
||||
plugin = givenPlugin;
|
||||
|
Loading…
Reference in New Issue
Block a user