Makes the stargate logger private

This commit is contained in:
Kristian Knarvik 2021-10-23 14:25:46 +02:00
parent 7cc8685e26
commit deba2e5c2c
14 changed files with 60 additions and 41 deletions

View File

@ -64,7 +64,7 @@ public class Stargate extends JavaPlugin {
private static final int activeTime = 10; private static final int activeTime = 10;
private static final int openTime = 10; private static final int openTime = 10;
public static Logger logger; private static Logger logger;
public static Server server; public static Server server;
public static Stargate stargate; public static Stargate stargate;
public static LanguageLoader languageLoader; public static LanguageLoader languageLoader;
@ -172,6 +172,15 @@ public class Stargate extends JavaPlugin {
return activeTime; return activeTime;
} }
/**
* Gets the logger used for logging to the console
*
* @return <p>The logger</p>
*/
public static Logger getConsoleLogger() {
return logger;
}
/** /**
* Sends a debug message * Sends a debug message
* *

View File

@ -242,10 +242,12 @@ public final class EconomyConfig {
this.vault = vault; this.vault = vault;
return true; return true;
} else { } else {
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("ecoLoadError")); Stargate.getConsoleLogger().info(Stargate.getString("prefix") +
Stargate.getString("ecoLoadError"));
} }
} else { } else {
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("vaultLoadError")); Stargate.getConsoleLogger().info(Stargate.getString("prefix") +
Stargate.getString("vaultLoadError"));
} }
economyEnabled = false; economyEnabled = false;
return false; return false;

View File

@ -35,7 +35,7 @@ public final class LanguageLoader {
File tmp = new File(languageFolder, chosenLanguage + ".txt"); File tmp = new File(languageFolder, chosenLanguage + ".txt");
if (!tmp.exists()) { if (!tmp.exists()) {
if (tmp.getParentFile().mkdirs() && Stargate.debuggingEnabled) { if (tmp.getParentFile().mkdirs() && Stargate.debuggingEnabled) {
Stargate.logger.info("[stargate] Created language folder"); Stargate.getConsoleLogger().info("[stargate] Created language folder");
} }
} }
updateLanguage(chosenLanguage); updateLanguage(chosenLanguage);
@ -47,7 +47,8 @@ public final class LanguageLoader {
loadedBackupStrings = load("en", inputStream); loadedBackupStrings = load("en", inputStream);
} else { } else {
loadedBackupStrings = null; loadedBackupStrings = null;
Stargate.logger.severe("[stargate] Error loading backup language. There may be missing text in-game"); Stargate.getConsoleLogger().severe("[stargate] Error loading backup language. There may be missing " +
"text in-game");
} }
} }
@ -101,10 +102,10 @@ public final class LanguageLoader {
InputStream inputStream = getClass().getResourceAsStream("/lang/" + language + ".txt"); InputStream inputStream = getClass().getResourceAsStream("/lang/" + language + ".txt");
if (inputStream == null) { if (inputStream == null) {
Stargate.logger.info("[stargate] The language " + language + " is not available. Falling back to " + Stargate.getConsoleLogger().info("[stargate] The language " + language + " is not available. Falling " +
"english, You can add a custom language by creating a new text file in the lang directory."); "back to english, You can add a custom language by creating a new text file in the lang directory.");
if (Stargate.debuggingEnabled) { if (Stargate.debuggingEnabled) {
Stargate.logger.info("[stargate] Unable to load /lang/" + language + ".txt"); Stargate.getConsoleLogger().info("[stargate] Unable to load /lang/" + language + ".txt");
} }
return; return;
} }
@ -133,7 +134,7 @@ public final class LanguageLoader {
//If currentLanguageValues is null; the chosen language has not been used before //If currentLanguageValues is null; the chosen language has not been used before
if (currentLanguageValues == null) { if (currentLanguageValues == null) {
updateLanguageFile(language, internalLanguageValues, null); updateLanguageFile(language, internalLanguageValues, null);
Stargate.logger.info("[stargate] Language (" + language + ") has been loaded"); Stargate.getConsoleLogger().info("[stargate] Language (" + language + ") has been loaded");
return; return;
} }
@ -154,7 +155,8 @@ public final class LanguageLoader {
//Update the file itself //Update the file itself
if (updateNecessary) { if (updateNecessary) {
updateLanguageFile(language, newLanguageValues, currentLanguageValues); updateLanguageFile(language, newLanguageValues, currentLanguageValues);
Stargate.logger.info("[stargate] Your language file (" + language + ".txt) has been updated"); Stargate.getConsoleLogger().info("[stargate] Your language file (" + language +
".txt) has been updated");
} }
} }
} }
@ -216,7 +218,7 @@ public final class LanguageLoader {
strings = FileHelper.readKeyValuePairs(bufferedReader); strings = FileHelper.readKeyValuePairs(bufferedReader);
} catch (Exception e) { } catch (Exception e) {
if (Stargate.debuggingEnabled) { if (Stargate.debuggingEnabled) {
Stargate.logger.info("[stargate] Unable to load language " + lang); Stargate.getConsoleLogger().info("[stargate] Unable to load language " + lang);
} }
return null; return null;
} }

View File

@ -161,7 +161,7 @@ public final class StargateGateConfig {
} catch (IllegalArgumentException | NullPointerException ignored) { } catch (IllegalArgumentException | NullPointerException ignored) {
} }
} }
Stargate.logger.warning(getString("prefix") + Stargate.getConsoleLogger().warning(getString("prefix") +
"You have specified an invalid color in your config.yml. Defaulting to BLACK"); "You have specified an invalid color in your config.yml. Defaulting to BLACK");
this.signColor = ChatColor.BLACK; this.signColor = ChatColor.BLACK;
} }

View File

@ -115,7 +115,8 @@ public class BlockEventListener implements Listener {
if (!PermissionHelper.canDestroyPortal(player, portal)) { if (!PermissionHelper.canDestroyPortal(player, portal)) {
denyMessage = Stargate.getString("denyMsg"); denyMessage = Stargate.getString("denyMsg");
deny = true; deny = true;
Stargate.logger.info(Stargate.getString("prefix") + player.getName() + " tried to destroy gate"); Stargate.getConsoleLogger().info(Stargate.getString("prefix") + player.getName() +
" tried to destroy gate");
} }
int cost = Stargate.getEconomyConfig().getDestroyCost(player, portal.getGate()); int cost = Stargate.getEconomyConfig().getDestroyCost(player, portal.getGate());

View File

@ -268,7 +268,7 @@ public class Gate {
bufferedWriter.close(); bufferedWriter.close();
} catch (IOException ex) { } catch (IOException ex) {
Stargate.logger.log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage()); Stargate.getConsoleLogger().log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
} }
} }

View File

@ -106,7 +106,7 @@ public class GateHandler {
try (Scanner scanner = new Scanner(file)) { try (Scanner scanner = new Scanner(file)) {
return loadGate(file.getName(), file.getParent(), scanner); return loadGate(file.getName(), file.getParent(), scanner);
} catch (Exception ex) { } catch (Exception ex) {
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage()); Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage());
return null; return null;
} }
} }
@ -190,13 +190,13 @@ public class GateHandler {
*/ */
private static boolean validateGate(Gate gate, String fileName) { private static boolean validateGate(Gate gate, String fileName) {
if (gate.getLayout().getControls().length != 2) { if (gate.getLayout().getControls().length != 2) {
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName +
" - Gates must have exactly 2 control points."); " - Gates must have exactly 2 control points.");
return false; return false;
} }
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) { if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName +
" - Gate button must be a type of button."); " - Gate button must be a type of button.");
return false; return false;
} }

View File

@ -88,7 +88,7 @@ public class PortalHandler {
} }
//Check if this player can access the dest world //Check if this player can access the dest world
if (PermissionHelper.cannotAccessWorld(player, portal.getWorld().getName())) { if (PermissionHelper.cannotAccessWorld(player, portal.getWorld().getName())) {
Stargate.logger.info("cannot access world"); Stargate.getConsoleLogger().info("cannot access world");
continue; continue;
} }
//Visible to this player. //Visible to this player.
@ -439,14 +439,14 @@ public class PortalHandler {
} }
} }
PortalRegistry.unregisterPortal(portal, false); PortalRegistry.unregisterPortal(portal, false);
Stargate.logger.info(Stargate.getString("prefix") + "Destroying stargate at " + portal); Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Destroying stargate at " + portal);
} }
/** /**
* Closes all portals * Closes all portals
*/ */
public static void closeAllPortals() { public static void closeAllPortals() {
Stargate.logger.info("Closing all stargates."); Stargate.getConsoleLogger().info("Closing all stargates.");
for (Portal portal : PortalRegistry.getAllPortals()) { for (Portal portal : PortalRegistry.getAllPortals()) {
if (portal != null) { if (portal != null) {
portal.getPortalOpener().closePortal(true); portal.getPortalOpener().closePortal(true);

View File

@ -30,7 +30,8 @@ public class PortalSignDrawer {
Block signBlock = portal.getSignLocation().getBlock(); Block signBlock = portal.getSignLocation().getBlock();
BlockState state = signBlock.getState(); BlockState state = signBlock.getState();
if (!(state instanceof Sign sign)) { if (!(state instanceof Sign sign)) {
Stargate.logger.warning(Stargate.getString("prefix") + "Sign block is not a Sign object"); Stargate.getConsoleLogger().warning(Stargate.getString("prefix") +
"Sign block is not a Sign object");
Stargate.debug("Portal::drawSign", "Block: " + signBlock.getType() + " @ " + Stargate.debug("Portal::drawSign", "Block: " + signBlock.getType() + " @ " +
signBlock.getLocation()); signBlock.getLocation());
return; return;

View File

@ -80,7 +80,7 @@ public abstract class Teleporter {
} }
} }
} else { } else {
Stargate.logger.log(Level.WARNING, Stargate.getString("prefix") + Stargate.getConsoleLogger().log(Level.WARNING, Stargate.getString("prefix") +
"Missing destination point in .gate file " + portal.getGate().getFilename()); "Missing destination point in .gate file " + portal.getGate().getFilename());
} }
@ -180,7 +180,7 @@ public abstract class Teleporter {
exitLocation.setPitch(traveller.getPitch()); exitLocation.setPitch(traveller.getPitch());
return exitLocation; return exitLocation;
} else { } else {
Stargate.logger.log(Level.WARNING, Stargate.getString("prefix") + Stargate.getConsoleLogger().log(Level.WARNING, Stargate.getString("prefix") +
"Unable to generate exit location"); "Unable to generate exit location");
} }
return traveller; return traveller;

View File

@ -138,7 +138,7 @@ public class VehicleTeleporter extends Teleporter {
Vector newVelocity) { Vector newVelocity) {
World vehicleWorld = exit.getWorld(); World vehicleWorld = exit.getWorld();
if (vehicleWorld == null) { if (vehicleWorld == null) {
Stargate.logger.warning(Stargate.getString("prefix") + Stargate.getConsoleLogger().warning(Stargate.getString("prefix") +
"Unable to get the world to teleport the vehicle to"); "Unable to get the world to teleport the vehicle to");
return; return;
} }

View File

@ -66,7 +66,7 @@ public final class BungeeHelper {
dataOutputStream.writeBytes(message); dataOutputStream.writeBytes(message);
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray()); player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
} catch (IOException ex) { } catch (IOException ex) {
Stargate.logger.severe(Stargate.getString("prefix") + "Error sending BungeeCord teleport packet"); Stargate.getConsoleLogger().severe(Stargate.getString("prefix") + "Error sending BungeeCord teleport packet");
ex.printStackTrace(); ex.printStackTrace();
return false; return false;
} }
@ -90,7 +90,8 @@ public final class BungeeHelper {
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray()); player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
byteArrayOutputStream.reset(); byteArrayOutputStream.reset();
} catch (IOException ex) { } catch (IOException ex) {
Stargate.logger.severe(Stargate.getString("prefix") + "Error sending BungeeCord connect packet"); Stargate.getConsoleLogger().severe(Stargate.getString("prefix") +
"Error sending BungeeCord connect packet");
ex.printStackTrace(); ex.printStackTrace();
return false; return false;
} }
@ -117,7 +118,8 @@ public final class BungeeHelper {
data = new byte[dataLength]; data = new byte[dataLength];
dataInputStream.readFully(data); dataInputStream.readFully(data);
} catch (IOException ex) { } catch (IOException ex) {
Stargate.logger.severe(Stargate.getString("prefix") + "Error receiving BungeeCord message"); Stargate.getConsoleLogger().severe(Stargate.getString("prefix") +
"Error receiving BungeeCord message");
ex.printStackTrace(); ex.printStackTrace();
return null; return null;
} }
@ -145,7 +147,8 @@ public final class BungeeHelper {
Portal destinationPortal = PortalHandler.getBungeePortal(destination); Portal destinationPortal = PortalHandler.getBungeePortal(destination);
// Specified an invalid gate. For now, we'll just let them connect at their current location // Specified an invalid gate. For now, we'll just let them connect at their current location
if (destinationPortal == null) { if (destinationPortal == null) {
Stargate.logger.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist"); Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Bungee gate " +
destination + " does not exist");
return; return;
} }
new PlayerTeleporter(destinationPortal, player).teleport(destinationPortal, null); new PlayerTeleporter(destinationPortal, player).teleport(destinationPortal, null);

View File

@ -55,7 +55,7 @@ public final class GateReader {
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + " - " + ex.getMessage()); Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName + " - " + ex.getMessage());
return -1; return -1;
} finally { } finally {
if (scanner != null) { if (scanner != null) {
@ -90,8 +90,8 @@ public final class GateReader {
for (Character symbol : line.toCharArray()) { for (Character symbol : line.toCharArray()) {
//Refuse read gate designs with unknown characters //Refuse read gate designs with unknown characters
if (symbol.equals('?') || (!characterMaterialMap.containsKey(symbol))) { if (symbol.equals('?') || (!characterMaterialMap.containsKey(symbol))) {
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + " - Unknown symbol '" + Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName +
symbol + "' in diagram"); " - Unknown symbol '" + symbol + "' in diagram");
return -1; return -1;
} }
//Add the read character to the row //Add the read character to the row
@ -148,7 +148,7 @@ public final class GateReader {
try { try {
return Integer.parseInt(config.get(key)); return Integer.parseInt(config.get(key));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
Stargate.logger.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", Stargate.getConsoleLogger().log(Level.WARNING, String.format("%s reading %s: %s is not numeric",
ex.getClass().getName(), fileName, key)); ex.getClass().getName(), fileName, key));
} }
} }
@ -172,8 +172,8 @@ public final class GateReader {
if (material != null) { if (material != null) {
return material; return material;
} else { } else {
Stargate.logger.log(Level.WARNING, String.format("Error reading %s: %s is not a material", fileName, Stargate.getConsoleLogger().log(Level.WARNING, String.format("Error reading %s: %s is not a material",
key)); fileName, key));
} }
} }
return defaultMaterial; return defaultMaterial;

View File

@ -53,7 +53,8 @@ public final class PortalFileHelper {
bufferedWriter.close(); bufferedWriter.close();
} catch (Exception e) { } catch (Exception e) {
Stargate.logger.log(Level.SEVERE, "Exception while writing stargates to " + saveFileLocation + ": " + e); Stargate.getConsoleLogger().log(Level.SEVERE, "Exception while writing stargates to " +
saveFileLocation + ": " + e);
} }
} }
@ -131,7 +132,7 @@ public final class PortalFileHelper {
if (database.exists()) { if (database.exists()) {
return loadPortals(world, database); return loadPortals(world, database);
} else { } else {
Stargate.logger.info(Stargate.getString("prefix") + "{" + world.getName() + Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "{" + world.getName() +
"} No stargates for world "); "} No stargates for world ");
} }
return false; return false;
@ -158,8 +159,8 @@ public final class PortalFileHelper {
doPostLoadTasks(world); doPostLoadTasks(world);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
Stargate.logger.log(Level.SEVERE, "Exception while reading stargates from " + database.getName() + Stargate.getConsoleLogger().log(Level.SEVERE, "Exception while reading stargates from " +
": " + lineIndex); database.getName() + ": " + lineIndex);
e.printStackTrace(); e.printStackTrace();
} }
return false; return false;
@ -183,7 +184,7 @@ public final class PortalFileHelper {
//Check if the min. required portal data is present //Check if the min. required portal data is present
String[] portalData = line.split(":"); String[] portalData = line.split(":");
if (portalData.length < 8) { if (portalData.length < 8) {
Stargate.logger.info(Stargate.getString("prefix") + "Invalid line - " + lineIndex); Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Invalid line - " + lineIndex);
return; return;
} }
@ -206,7 +207,7 @@ public final class PortalFileHelper {
int openCount = PortalHandler.openAlwaysOpenPortals(); int openCount = PortalHandler.openAlwaysOpenPortals();
//Print info about loaded stargates so that admins can see if all stargates loaded //Print info about loaded stargates so that admins can see if all stargates loaded
Stargate.logger.info(String.format("%s{%s} Loaded %d stargates with %d set as always-on", Stargate.getConsoleLogger().info(String.format("%s{%s} Loaded %d stargates with %d set as always-on",
Stargate.getString("prefix"), world.getName(), portalCount, openCount)); Stargate.getString("prefix"), world.getName(), portalCount, openCount));
//Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since //Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since
@ -270,7 +271,7 @@ public final class PortalFileHelper {
Stargate.setLine(sign, 3, Stargate.getString("signInvalidGate")); Stargate.setLine(sign, 3, Stargate.getString("signInvalidGate"));
sign.update(); sign.update();
Stargate.logger.info(Stargate.getString("prefix") + "Gate layout on line " + lineIndex + Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Gate layout on line " + lineIndex +
" does not exist [" + gateName + "]"); " does not exist [" + gateName + "]");
} }