Cleans up message logging quite a bit

Adds methods to Stargate for easier logging and less redundancy
Loads the language loader in two parts to make it available while loading
Adds a translated string to the reload-message
Uses String.format to make long messages more readable
Makes it possible to get strings directly from the backup language to make debugging easier
This commit is contained in:
Kristian Knarvik 2021-10-26 15:05:05 +02:00
parent eaf7596014
commit 1c906528f2
22 changed files with 154 additions and 118 deletions

View File

@ -120,12 +120,49 @@ public class Stargate extends JavaPlugin {
*/
public static void debug(String route, String message) {
if (Stargate.stargateConfig.isDebuggingEnabled()) {
logger.info("[stargate::" + route + "] " + message);
logger.info("[Stargate::" + route + "] " + message);
} else {
logger.log(Level.FINEST, "[stargate::" + route + "] " + message);
logger.log(Level.FINEST, "[Stargate::" + route + "] " + message);
}
}
/**
* Logs an info message to the console
*
* @param message <p>The message to log</p>
*/
public static void logInfo(String message) {
logger.info(Stargate.getBackupString("prefix") + message);
}
/**
* Logs a severe error message to the console
*
* @param message <p>The message to log</p>
*/
public static void logSevere(String message) {
log(Level.SEVERE, message);
}
/**
* Logs a warning message to the console
*
* @param message <p>The message to log</p>
*/
public static void logWarning(String message) {
log(Level.WARNING, message);
}
/**
* Logs a message to the console
*
* @param severity <p>The severity of the event triggering the message</p>
* @param message <p>The message to log</p>
*/
private static void log(Level severity, String message) {
logger.log(severity, Stargate.getBackupString("prefix") + message);
}
/**
* Gets the folder for saving created portals
*
@ -169,6 +206,18 @@ public class Stargate extends JavaPlugin {
return stargateConfig.getLanguageLoader().getString(name);
}
/**
* Gets a backup string given its string key
*
* <p>The name/key is the string before the equals sign in the language files</p>
*
* @param name <p>The name/key of the string to get</p>
* @return <p>The full string in the backup language (English)</p>
*/
public static String getBackupString(String name) {
return stargateConfig.getLanguageLoader().getBackupString(name);
}
/**
* Replaces a list of variables in a string in the order they are given
*

View File

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

View File

@ -25,30 +25,27 @@ public final class LanguageLoader {
/**
* Instantiates a new language loader
*
* <p>This will only load the backup language. Set the chosen language and reload afterwards.</p>
*
* @param languageFolder <p>The folder containing the language files</p>
* @param chosenLanguage <p>The chosen plugin language</p>
*/
public LanguageLoader(String languageFolder, String chosenLanguage) {
this.chosenLanguage = chosenLanguage;
public LanguageLoader(String languageFolder) {
this.languageFolder = languageFolder;
File tmp = new File(languageFolder, chosenLanguage + ".txt");
if (!tmp.exists()) {
if (tmp.getParentFile().mkdirs() && Stargate.getStargateConfig().isDebuggingEnabled()) {
Stargate.getConsoleLogger().info("[stargate] Created language folder");
File testFile = new File(languageFolder, "en.txt");
if (!testFile.exists()) {
if (testFile.getParentFile().mkdirs()) {
Stargate.debug("LanguageLoader", "Created language folder");
}
}
updateLanguage(chosenLanguage);
loadedStringTranslations = load(chosenLanguage);
//Load english as backup language in case the chosen language is missing newly added text strings
InputStream inputStream = FileHelper.getInputStreamForInternalFile("/lang/en.txt");
if (inputStream != null) {
loadedBackupStrings = load("en", inputStream);
} else {
loadedBackupStrings = null;
Stargate.getConsoleLogger().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");
}
}
@ -56,7 +53,7 @@ public final class LanguageLoader {
* Reloads languages from the files on disk
*/
public void reload() {
// This extracts/updates the language as needed
//Extracts/Updates the language as needed
updateLanguage(chosenLanguage);
loadedStringTranslations = load(chosenLanguage);
}
@ -72,7 +69,21 @@ public final class LanguageLoader {
if (loadedStringTranslations != null) {
value = loadedStringTranslations.get(name);
}
if (value == null && loadedBackupStrings != null) {
if (value == null) {
value = getBackupString(name);
}
return value;
}
/**
* Gets the string to display given its name/key
*
* @param name <p>The name/key of the string to display</p>
* @return <p>The string in the backup language (English)</p>
*/
public String getBackupString(String name) {
String value = null;
if (loadedBackupStrings != null) {
value = loadedBackupStrings.get(name);
}
if (value == null) {
@ -96,17 +107,13 @@ public final class LanguageLoader {
* @param language <p>The language to update</p>
*/
private void updateLanguage(String language) {
// Load the current language file
Map<String, String> currentLanguageValues = load(language);
InputStream inputStream = getClass().getResourceAsStream("/lang/" + language + ".txt");
if (inputStream == null) {
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.getStargateConfig().isDebuggingEnabled()) {
Stargate.getConsoleLogger().info("[stargate] Unable to load /lang/" + language + ".txt");
}
Stargate.logInfo(String.format("The language %s is not available. Falling back to english, You can add a " +
"custom language by creating a new text file in the lang directory.", language));
Stargate.debug("LanguageLoader::updateLanguage", String.format("Unable to load /lang/%s.txt", language));
return;
}
@ -134,7 +141,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.getConsoleLogger().info("[stargate] Language (" + language + ") has been loaded");
Stargate.logInfo(String.format("Language (%s) has been loaded", language));
return;
}
@ -155,8 +162,7 @@ public final class LanguageLoader {
//Update the file itself
if (updateNecessary) {
updateLanguageFile(language, newLanguageValues, currentLanguageValues);
Stargate.getConsoleLogger().info("[stargate] Your language file (" + language +
".txt) has been updated");
Stargate.logInfo(String.format("Your language file (%s.txt) has been updated", language));
}
}
}
@ -218,7 +224,7 @@ public final class LanguageLoader {
strings = FileHelper.readKeyValuePairs(bufferedReader);
} catch (Exception e) {
if (Stargate.getStargateConfig().isDebuggingEnabled()) {
Stargate.getConsoleLogger().info("[stargate] Unable to load language " + lang);
Stargate.getConsoleLogger().info("[Stargate] Unable to load language " + lang);
}
return null;
}
@ -229,15 +235,17 @@ public final class LanguageLoader {
* Prints debug output to the console for checking loaded language strings/translations
*/
public void debug() {
Set<String> keys = loadedStringTranslations.keySet();
for (String key : keys) {
Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", key + " => " +
loadedStringTranslations.get(key));
if (loadedStringTranslations != null) {
Set<String> keys = loadedStringTranslations.keySet();
for (String key : keys) {
Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", key + " => " +
loadedStringTranslations.get(key));
}
}
if (loadedBackupStrings == null) {
return;
}
keys = loadedBackupStrings.keySet();
Set<String> keys = loadedBackupStrings.keySet();
for (String key : keys) {
Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " +
loadedBackupStrings.get(key));

View File

@ -32,11 +32,10 @@ public final class StargateConfig {
private StargateGateConfig stargateGateConfig;
private MessageSender messageSender;
public LanguageLoader languageLoader;
public final LanguageLoader languageLoader;
private EconomyConfig economyConfig;
private final Logger logger;
private final String languageFolder;
private final String dataFolderPath;
private String gateFolder;
private String portalFolder;
@ -56,7 +55,7 @@ public final class StargateConfig {
dataFolderPath = Stargate.stargate.getDataFolder().getPath().replaceAll("\\\\", "/");
portalFolder = dataFolderPath + "/portals/";
gateFolder = dataFolderPath + "/gates/";
languageFolder = dataFolderPath + "/lang/";
languageLoader = new LanguageLoader(dataFolderPath + "/lang/");
this.loadConfig();
@ -70,8 +69,10 @@ public final class StargateConfig {
* Finish the config setup by loading languages, gates and portals, and loading economy if vault is loaded
*/
public void finishSetup() {
//Load the translated strings before they're used by loadGates
languageLoader = new LanguageLoader(languageFolder, languageName);
//Set the chosen language and reload the language loader
languageLoader.setChosenLanguage(languageName);
languageLoader.reload();
messageSender = new MessageSender(languageLoader);
if (debuggingEnabled) {
languageLoader.debug();
@ -132,7 +133,7 @@ public final class StargateConfig {
startStopBungeeListener(stargateGateConfig.enableBungee());
}
messageSender.sendErrorMessage(sender, "stargate reloaded");
messageSender.sendErrorMessage(sender, languageLoader.getString("reloaded"));
}
/**
@ -309,7 +310,7 @@ public final class StargateConfig {
*/
public void loadGates() {
GateHandler.loadGates(gateFolder);
logger.info(Stargate.getString("prefix") + "Loaded " + GateHandler.getGateCount() + " gate layouts");
Stargate.logInfo(String.format("Loaded %s gate layouts", GateHandler.getGateCount()));
}
/**
@ -358,8 +359,7 @@ public final class StargateConfig {
EconomyConfig economyConfig = getEconomyConfig();
if (economyConfig.setupEconomy(Stargate.getPluginManager()) && economyConfig.getEconomy() != null) {
String vaultVersion = economyConfig.getVault().getDescription().getVersion();
logger.info(Stargate.getString("prefix") + Stargate.replaceVars(
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
Stargate.logInfo(Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
}

View File

@ -4,8 +4,6 @@ import net.knarcraft.stargate.Stargate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import static net.knarcraft.stargate.Stargate.getString;
/**
* The Stargate gate config keeps track of all global config values related to gates
*/
@ -181,8 +179,7 @@ public final class StargateGateConfig {
} catch (IllegalArgumentException | NullPointerException ignored) {
}
}
Stargate.getConsoleLogger().warning(getString("prefix") +
"You have specified an invalid color in your config.yml. Defaulting to BLACK");
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK");
this.signColor = ChatColor.BLACK;
}

View File

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

View File

@ -34,8 +34,7 @@ public class PluginEventListener implements Listener {
public void onPluginEnable(PluginEnableEvent ignored) {
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
String vaultVersion = Stargate.getEconomyConfig().getVault().getDescription().getVersion();
stargate.getLogger().info(Stargate.getString("prefix") +
Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
Stargate.logInfo(Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
}
@ -47,7 +46,7 @@ public class PluginEventListener implements Listener {
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) {
stargate.getLogger().info(Stargate.getString("prefix") + "Vault plugin lost.");
Stargate.logInfo("Vault plugin lost.");
}
}
}

View File

@ -60,16 +60,15 @@ public class VehicleEventListener implements Listener {
*/
private static void teleportVehicle(List<Entity> passengers, Portal entrancePortal, Vehicle vehicle) {
String route = "VehicleEventListener::teleportVehicle";
String prefix = Stargate.getString("prefix");
if (!passengers.isEmpty() && passengers.get(0) instanceof Player) {
Stargate.debug(route, prefix + "Found passenger vehicle");
Stargate.debug(route, "Found passenger vehicle");
teleportPlayerAndVehicle(entrancePortal, vehicle, passengers);
} else {
Stargate.debug(route, prefix + "Found empty vehicle");
Stargate.debug(route, "Found empty vehicle");
Portal destinationPortal = entrancePortal.getPortalActivator().getDestination();
if (destinationPortal == null) {
Stargate.debug(route, prefix + "Unable to find portal destination");
Stargate.debug(route, "Unable to find portal destination");
return;
}
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " +

View File

@ -10,7 +10,6 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
/**
* A gate describes the physical structure of a stargate
@ -268,7 +267,7 @@ public class Gate {
bufferedWriter.close();
} catch (IOException ex) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
Stargate.logSevere(String.format("Could not save Gate %s - %s", filename, ex.getMessage()));
}
}

View File

@ -15,7 +15,6 @@ import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.logging.Level;
import static net.knarcraft.stargate.utility.GateReader.generateLayoutMatrix;
import static net.knarcraft.stargate.utility.GateReader.readGateConfig;
@ -105,8 +104,8 @@ public class GateHandler {
private static Gate loadGate(File file) {
try (Scanner scanner = new Scanner(file)) {
return loadGate(file.getName(), file.getParent(), scanner);
} catch (Exception ex) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage());
} catch (Exception exception) {
Stargate.logSevere(String.format("Could not load Gate %s - %s", file.getName(), exception.getMessage()));
return null;
}
}
@ -190,14 +189,13 @@ public class GateHandler {
*/
private static boolean validateGate(Gate gate, String fileName) {
if (gate.getLayout().getControls().length != 2) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName +
" - Gates must have exactly 2 control points.");
Stargate.logSevere(String.format("Could not load Gate %s - Gates must have exactly 2 control points.",
fileName));
return false;
}
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName +
" - Gate button must be a type of button.");
Stargate.logSevere(String.format("Could not load Gate %s - Gate button must be a type of button.", fileName));
return false;
}
return true;

View File

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

View File

@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
/**
* The portal registry keeps track of all registered portals and all their lookup blocks
@ -268,8 +267,8 @@ public class PortalRegistry {
if (!allPortalNetworks.get(networkName).contains(portalName)) {
allPortalNetworks.get(networkName).add(portalName);
} else {
Stargate.getConsoleLogger().log(Level.SEVERE, "Portal " + portal + " was registered twice. Check " +
"your portal database for duplicates.");
Stargate.logSevere(String.format("Portal %s was registered twice. Check your portal database for " +
"duplicates.", portal));
}
}

View File

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

View File

@ -18,7 +18,6 @@ import org.bukkit.scheduler.BukkitScheduler;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/**
* The portal teleporter takes care of common teleportation logic
@ -80,8 +79,8 @@ public abstract class Teleporter {
}
}
} else {
Stargate.getConsoleLogger().log(Level.WARNING, Stargate.getString("prefix") +
"Missing destination point in .gate file " + portal.getGate().getFilename());
Stargate.logWarning(String.format("Missing destination point in .gate file %s",
portal.getGate().getFilename()));
}
return adjustExitLocation(traveller, exitLocation);
@ -180,8 +179,7 @@ public abstract class Teleporter {
exitLocation.setPitch(traveller.getPitch());
return exitLocation;
} else {
Stargate.getConsoleLogger().log(Level.WARNING, Stargate.getString("prefix") +
"Unable to generate exit location");
Stargate.logWarning("Unable to generate exit location");
}
return traveller;
}

View File

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

View File

@ -80,8 +80,7 @@ public final class BungeeHelper {
//Send the plugin message
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
} catch (IOException ex) {
Stargate.getConsoleLogger().severe(Stargate.getString("prefix") + "Error sending BungeeCord " +
"teleport packet");
Stargate.logSevere("Error sending BungeeCord teleport packet");
ex.printStackTrace();
return false;
}
@ -107,8 +106,7 @@ public final class BungeeHelper {
//Send the plugin message
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
} catch (IOException ex) {
Stargate.getConsoleLogger().severe(Stargate.getString("prefix") +
"Error sending BungeeCord connect packet");
Stargate.logSevere("Error sending BungeeCord connect packet");
ex.printStackTrace();
return false;
}
@ -122,7 +120,6 @@ public final class BungeeHelper {
* @return <p>The message contained in the byte array, or null on failure</p>
*/
public static String readPluginMessage(byte[] message) {
// Get data from message
byte[] data;
try {
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(message));
@ -139,8 +136,7 @@ public final class BungeeHelper {
//Read the message to the prepared array
dataInputStream.readFully(data);
} catch (IOException ex) {
Stargate.getConsoleLogger().severe(Stargate.getString("prefix") +
"Error receiving BungeeCord message");
Stargate.logSevere("Error receiving BungeeCord message");
ex.printStackTrace();
return null;
}
@ -166,8 +162,7 @@ public final class BungeeHelper {
Portal destinationPortal = PortalHandler.getBungeePortal(destination);
//If teleporting to an invalid portal, let the server decide where the player arrives
if (destinationPortal == null) {
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Bungee gate " +
destination + " does not exist");
Stargate.logInfo(String.format("Bungee portal %s does not exist", destination));
return;
}
new PlayerTeleporter(destinationPortal, player).teleport(destinationPortal, null);

View File

@ -28,9 +28,13 @@ public final class EconomyHelper {
boolean success;
//Try to charge the player. Paying the portal owner is only possible if a UUID is available
if (entrancePortal.getGate().getToOwner()) {
UUID ownerUUID = entrancePortal.getOwner().getUUID();
success = ownerUUID != null && Stargate.getEconomyConfig().chargePlayerIfNecessary(player, ownerUUID, cost);
UUID ownerUUID = entrancePortal.getOwner().getUUID();
if (ownerUUID == null) {
Stargate.logWarning(String.format("The owner of the portal %s does not have a UUID and payment to owner " +
"was therefore not possible. Make the owner re-create the portal to fix this.", entrancePortal));
}
if (entrancePortal.getGate().getToOwner() && ownerUUID != null) {
success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, ownerUUID, cost);
} else {
success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost);
}

View File

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

View File

@ -19,7 +19,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.logging.Level;
/**
* Helper class for saving and loading portal save files
@ -54,8 +53,7 @@ public final class PortalFileHelper {
bufferedWriter.close();
} catch (Exception e) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Exception while writing stargates to " +
saveFileLocation + ": " + e);
Stargate.logSevere(String.format("Exception while writing stargates to %s: %s", saveFileLocation, e));
}
}
@ -133,8 +131,7 @@ public final class PortalFileHelper {
if (database.exists()) {
return loadPortals(world, database);
} else {
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "{" + world.getName() +
"} No stargates for world ");
Stargate.logInfo(String.format("{%s} No stargates for world ", world.getName()));
}
return false;
}
@ -160,8 +157,8 @@ public final class PortalFileHelper {
doPostLoadTasks(world);
return true;
} catch (Exception e) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Exception while reading stargates from " +
database.getName() + ": " + lineIndex);
Stargate.logSevere(String.format("Exception while reading stargates from %s: %d", database.getName(),
lineIndex));
e.printStackTrace();
}
return false;
@ -185,7 +182,7 @@ public final class PortalFileHelper {
//Check if the min. required portal data is present
String[] portalData = line.split(":");
if (portalData.length < 8) {
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Invalid line - " + lineIndex);
Stargate.logInfo(String.format("Invalid line - %s", lineIndex));
return;
}
@ -208,8 +205,8 @@ public final class PortalFileHelper {
int openCount = PortalHandler.openAlwaysOpenPortals();
//Print info about loaded stargates so that admins can see if all stargates loaded
Stargate.getConsoleLogger().info(String.format("%s{%s} Loaded %d stargates with %d set as always-on",
Stargate.getString("prefix"), world.getName(), portalCount, openCount));
Stargate.logInfo(String.format("{%s} Loaded %d stargates with %d set as always-on", 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
for (Portal portal : PortalRegistry.getAllPortals()) {
@ -272,8 +269,7 @@ public final class PortalFileHelper {
sign.setLine(3, ChatColor.DARK_RED + Stargate.getString("signInvalidGate"));
sign.update();
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Gate layout on line " + lineIndex +
" does not exist [" + gateName + "]");
Stargate.logInfo(String.format("Gate layout on line %d does not exist [%s]", lineIndex, gateName));
}
}

View File

@ -5,6 +5,7 @@ invalidMsg=Invalid Destination
blockMsg=Destination Blocked
destEmpty=Destination List Empty
denyMsg=Access Denied
reloaded=Stargate Reloaded
ecoDeduct=Deducted %cost%
ecoRefund=Refunded %cost%

View File

@ -6,6 +6,7 @@ invalidMsg=Ugyldig Destinasjon
blockMsg=Destinasjon Blokkert
destEmpty=Destinasjonslisten Er Tom
denyMsg=Tilgang Avslått
reloaded=Stjerneport Ble Lastet Inn På Nytt
ecoDeduct=Fratrekk %cost%
ecoRefund=Refundert %cost%

View File

@ -1,11 +1,12 @@
author=EpicKnarvik97
prefix=[Stjerneport]
prefix=[Stjerneport]
teleportMsg=Teleporterte
destroyMsg=Port Øydelagd
invalidMsg=Ugyldig Destinasjon
blockMsg=Destinasjon Blokkert
destEmpty=Destinasjonslista Er Tom
denyMsg=Tilgang Avslått
reloaded=Stjerneport Vart Lasta Inn På Nytt
ecoDeduct=Fråtrekk %cost%
ecoRefund=Refundert %cost%