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) { public static void debug(String route, String message) {
if (Stargate.stargateConfig.isDebuggingEnabled()) { if (Stargate.stargateConfig.isDebuggingEnabled()) {
logger.info("[stargate::" + route + "] " + message); logger.info("[Stargate::" + route + "] " + message);
} else { } 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 * Gets the folder for saving created portals
* *
@ -169,6 +206,18 @@ public class Stargate extends JavaPlugin {
return stargateConfig.getLanguageLoader().getString(name); 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 * 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; this.vault = vault;
return true; return true;
} else { } else {
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + Stargate.logInfo(Stargate.getString("ecoLoadError"));
Stargate.getString("ecoLoadError"));
} }
} else { } else {
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + Stargate.logInfo(Stargate.getString("vaultLoadError"));
Stargate.getString("vaultLoadError"));
} }
economyEnabled = false; economyEnabled = false;
return false; return false;

View File

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

View File

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

View File

@ -4,8 +4,6 @@ import net.knarcraft.stargate.Stargate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration; 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 * 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) { } catch (IllegalArgumentException | NullPointerException ignored) {
} }
} }
Stargate.getConsoleLogger().warning(getString("prefix") + Stargate.logWarning("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,8 +115,7 @@ 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.getConsoleLogger().info(Stargate.getString("prefix") + player.getName() + Stargate.logInfo(String.format("%s tried to destroy gate", player.getName()));
" tried to destroy gate");
} }
int cost = Stargate.getEconomyConfig().getDestroyCost(player, portal.getGate()); int cost = Stargate.getEconomyConfig().getDestroyCost(player, portal.getGate());

View File

@ -34,8 +34,7 @@ public class PluginEventListener implements Listener {
public void onPluginEnable(PluginEnableEvent ignored) { public void onPluginEnable(PluginEnableEvent ignored) {
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) { if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
String vaultVersion = Stargate.getEconomyConfig().getVault().getDescription().getVersion(); String vaultVersion = Stargate.getEconomyConfig().getVault().getDescription().getVersion();
stargate.getLogger().info(Stargate.getString("prefix") + Stargate.logInfo(Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
} }
} }
@ -47,7 +46,7 @@ public class PluginEventListener implements Listener {
@EventHandler @EventHandler
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) { 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) { private static void teleportVehicle(List<Entity> passengers, Portal entrancePortal, Vehicle vehicle) {
String route = "VehicleEventListener::teleportVehicle"; String route = "VehicleEventListener::teleportVehicle";
String prefix = Stargate.getString("prefix");
if (!passengers.isEmpty() && passengers.get(0) instanceof Player) { 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); teleportPlayerAndVehicle(entrancePortal, vehicle, passengers);
} else { } else {
Stargate.debug(route, prefix + "Found empty vehicle"); Stargate.debug(route, "Found empty vehicle");
Portal destinationPortal = entrancePortal.getPortalActivator().getDestination(); Portal destinationPortal = entrancePortal.getPortalActivator().getDestination();
if (destinationPortal == null) { if (destinationPortal == null) {
Stargate.debug(route, prefix + "Unable to find portal destination"); Stargate.debug(route, "Unable to find portal destination");
return; return;
} }
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " +

View File

@ -10,7 +10,6 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
/** /**
* A gate describes the physical structure of a stargate * A gate describes the physical structure of a stargate
@ -268,7 +267,7 @@ public class Gate {
bufferedWriter.close(); bufferedWriter.close();
} catch (IOException ex) { } 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.Map;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import static net.knarcraft.stargate.utility.GateReader.generateLayoutMatrix; import static net.knarcraft.stargate.utility.GateReader.generateLayoutMatrix;
import static net.knarcraft.stargate.utility.GateReader.readGateConfig; import static net.knarcraft.stargate.utility.GateReader.readGateConfig;
@ -105,8 +104,8 @@ public class GateHandler {
private static Gate loadGate(File file) { private static Gate loadGate(File file) {
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 exception) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage()); Stargate.logSevere(String.format("Could not load Gate %s - %s", file.getName(), exception.getMessage()));
return null; return null;
} }
} }
@ -190,14 +189,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.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName + Stargate.logSevere(String.format("Could not load Gate %s - Gates must have exactly 2 control points.",
" - Gates must have exactly 2 control points."); fileName));
return false; return false;
} }
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) { if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
Stargate.getConsoleLogger().log(Level.SEVERE, "Could not load Gate " + fileName + Stargate.logSevere(String.format("Could not load Gate %s - Gate button must be a type of button.", fileName));
" - Gate button must be a type of button.");
return false; return false;
} }
return true; return true;

View File

@ -88,7 +88,6 @@ 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.getConsoleLogger().info("cannot access world");
continue; continue;
} }
//Visible to this player. //Visible to this player.
@ -439,14 +438,14 @@ public class PortalHandler {
} }
} }
PortalRegistry.unregisterPortal(portal, false); 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 * Closes all portals
*/ */
public static void closeAllPortals() { public static void closeAllPortals() {
Stargate.getConsoleLogger().info("Closing all stargates."); Stargate.logInfo("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

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

View File

@ -30,10 +30,9 @@ 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.getConsoleLogger().warning(Stargate.getString("prefix") + Stargate.logWarning("Sign block is not a Sign object");
"Sign block is not a Sign object"); Stargate.debug("Portal::drawSign", String.format("Block: %s @ %s", signBlock.getType(),
Stargate.debug("Portal::drawSign", "Block: " + signBlock.getType() + " @ " + signBlock.getLocation()));
signBlock.getLocation());
return; return;
} }

View File

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

View File

@ -138,8 +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.getConsoleLogger().warning(Stargate.getString("prefix") + Stargate.logWarning("Unable to get the world to teleport the vehicle to");
"Unable to get the world to teleport the vehicle to");
return; return;
} }
//Spawn a new vehicle //Spawn a new vehicle

View File

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

View File

@ -28,9 +28,13 @@ public final class EconomyHelper {
boolean success; boolean success;
//Try to charge the player. Paying the portal owner is only possible if a UUID is available //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(); UUID ownerUUID = entrancePortal.getOwner().getUUID();
success = ownerUUID != null && Stargate.getEconomyConfig().chargePlayerIfNecessary(player, ownerUUID, cost); 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 { } else {
success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost); success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@ invalidMsg=Ugyldig Destinasjon
blockMsg=Destinasjon Blokkert blockMsg=Destinasjon Blokkert
destEmpty=Destinasjonslista Er Tom destEmpty=Destinasjonslista Er Tom
denyMsg=Tilgang Avslått denyMsg=Tilgang Avslått
reloaded=Stjerneport Vart Lasta Inn På Nytt
ecoDeduct=Fråtrekk %cost% ecoDeduct=Fråtrekk %cost%
ecoRefund=Refundert %cost% ecoRefund=Refundert %cost%