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:
2021-10-26 15:05:05 +02:00
parent eaf7596014
commit 1c906528f2
22 changed files with 154 additions and 118 deletions

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