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 openTime = 10;
public static Logger logger;
private static Logger logger;
public static Server server;
public static Stargate stargate;
public static LanguageLoader languageLoader;
@ -172,6 +172,15 @@ public class Stargate extends JavaPlugin {
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
*

View File

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

View File

@ -35,7 +35,7 @@ public final class LanguageLoader {
File tmp = new File(languageFolder, chosenLanguage + ".txt");
if (!tmp.exists()) {
if (tmp.getParentFile().mkdirs() && Stargate.debuggingEnabled) {
Stargate.logger.info("[stargate] Created language folder");
Stargate.getConsoleLogger().info("[stargate] Created language folder");
}
}
updateLanguage(chosenLanguage);
@ -47,7 +47,8 @@ public final class LanguageLoader {
loadedBackupStrings = load("en", inputStream);
} else {
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");
if (inputStream == null) {
Stargate.logger.info("[stargate] The language " + language + " is not available. Falling back to " +
"english, You can add a custom language by creating a new text file in the lang directory.");
Stargate.getConsoleLogger().info("[stargate] The language " + language + " is not available. Falling " +
"back to english, You can add a custom language by creating a new text file in the lang directory.");
if (Stargate.debuggingEnabled) {
Stargate.logger.info("[stargate] Unable to load /lang/" + language + ".txt");
Stargate.getConsoleLogger().info("[stargate] Unable to load /lang/" + language + ".txt");
}
return;
}
@ -133,7 +134,7 @@ public final class LanguageLoader {
//If currentLanguageValues is null; the chosen language has not been used before
if (currentLanguageValues == null) {
updateLanguageFile(language, internalLanguageValues, null);
Stargate.logger.info("[stargate] Language (" + language + ") has been loaded");
Stargate.getConsoleLogger().info("[stargate] Language (" + language + ") has been loaded");
return;
}
@ -154,7 +155,8 @@ public final class LanguageLoader {
//Update the file itself
if (updateNecessary) {
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);
} catch (Exception e) {
if (Stargate.debuggingEnabled) {
Stargate.logger.info("[stargate] Unable to load language " + lang);
Stargate.getConsoleLogger().info("[stargate] Unable to load language " + lang);
}
return null;
}

View File

@ -161,7 +161,7 @@ public final class StargateGateConfig {
} 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");
this.signColor = ChatColor.BLACK;
}

View File

@ -115,7 +115,8 @@ public class BlockEventListener implements Listener {
if (!PermissionHelper.canDestroyPortal(player, portal)) {
denyMessage = Stargate.getString("denyMsg");
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());

View File

@ -268,7 +268,7 @@ public class Gate {
bufferedWriter.close();
} 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)) {
return loadGate(file.getName(), file.getParent(), scanner);
} 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;
}
}
@ -190,13 +190,13 @@ public class GateHandler {
*/
private static boolean validateGate(Gate gate, String fileName) {
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.");
return false;
}
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.");
return false;
}

View File

@ -88,7 +88,7 @@ public class PortalHandler {
}
//Check if this player can access the dest world
if (PermissionHelper.cannotAccessWorld(player, portal.getWorld().getName())) {
Stargate.logger.info("cannot access world");
Stargate.getConsoleLogger().info("cannot access world");
continue;
}
//Visible to this player.
@ -439,14 +439,14 @@ public class PortalHandler {
}
}
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
*/
public static void closeAllPortals() {
Stargate.logger.info("Closing all stargates.");
Stargate.getConsoleLogger().info("Closing all stargates.");
for (Portal portal : PortalRegistry.getAllPortals()) {
if (portal != null) {
portal.getPortalOpener().closePortal(true);

View File

@ -30,7 +30,8 @@ public class PortalSignDrawer {
Block signBlock = portal.getSignLocation().getBlock();
BlockState state = signBlock.getState();
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() + " @ " +
signBlock.getLocation());
return;

View File

@ -80,7 +80,7 @@ public abstract class Teleporter {
}
}
} 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());
}
@ -180,7 +180,7 @@ public abstract class Teleporter {
exitLocation.setPitch(traveller.getPitch());
return exitLocation;
} else {
Stargate.logger.log(Level.WARNING, Stargate.getString("prefix") +
Stargate.getConsoleLogger().log(Level.WARNING, Stargate.getString("prefix") +
"Unable to generate exit location");
}
return traveller;

View File

@ -138,7 +138,7 @@ public class VehicleTeleporter extends Teleporter {
Vector newVelocity) {
World vehicleWorld = exit.getWorld();
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");
return;
}

View File

@ -66,7 +66,7 @@ public final class BungeeHelper {
dataOutputStream.writeBytes(message);
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
} 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();
return false;
}
@ -90,7 +90,8 @@ public final class BungeeHelper {
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
byteArrayOutputStream.reset();
} 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();
return false;
}
@ -117,7 +118,8 @@ public final class BungeeHelper {
data = new byte[dataLength];
dataInputStream.readFully(data);
} 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();
return null;
}
@ -145,7 +147,8 @@ public final class BungeeHelper {
Portal destinationPortal = PortalHandler.getBungeePortal(destination);
// Specified an invalid gate. For now, we'll just let them connect at their current location
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;
}
new PlayerTeleporter(destinationPortal, player).teleport(destinationPortal, null);

View File

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

View File

@ -53,7 +53,8 @@ public final class PortalFileHelper {
bufferedWriter.close();
} 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()) {
return loadPortals(world, database);
} else {
Stargate.logger.info(Stargate.getString("prefix") + "{" + world.getName() +
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "{" + world.getName() +
"} No stargates for world ");
}
return false;
@ -158,8 +159,8 @@ public final class PortalFileHelper {
doPostLoadTasks(world);
return true;
} catch (Exception e) {
Stargate.logger.log(Level.SEVERE, "Exception while reading stargates from " + database.getName() +
": " + lineIndex);
Stargate.getConsoleLogger().log(Level.SEVERE, "Exception while reading stargates from " +
database.getName() + ": " + lineIndex);
e.printStackTrace();
}
return false;
@ -183,7 +184,7 @@ public final class PortalFileHelper {
//Check if the min. required portal data is present
String[] portalData = line.split(":");
if (portalData.length < 8) {
Stargate.logger.info(Stargate.getString("prefix") + "Invalid line - " + lineIndex);
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Invalid line - " + lineIndex);
return;
}
@ -206,7 +207,7 @@ public final class PortalFileHelper {
int openCount = PortalHandler.openAlwaysOpenPortals();
//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));
//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"));
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 + "]");
}