From a15317e21dae98850b39a4b3f122dfd0fbc5ac28 Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Tue, 3 Jul 2012 15:48:57 -0400 Subject: [PATCH] Removed many instances of String.format in favor of higher performance inline concatenation. We should prune many more of these as well. --- .../MultiverseCore/MultiverseCore.java | 5 +- .../listeners/MVPlayerListener.java | 75 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 90b70ee3..cb079ff8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -753,8 +753,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { } else if (level == Level.FINEST && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 3) { staticDebugLog(Level.INFO, msg); } else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) { - LOGGER.log(level, String.format("%s %s", LOG_TAG, msg)); - debugLog.log(level, String.format("%s %s", LOG_TAG, msg)); + String message = LOG_TAG + " " + msg; + LOGGER.log(level, message); + debugLog.log(level, message); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 51f70553..89945930 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -128,8 +128,8 @@ public class MVPlayerListener implements Listener { if (!p.hasPlayedBefore()) { this.plugin.log(Level.FINER, "Player joined for the FIRST time!"); if (plugin.getMVConfig().getFirstSpawnOverride()) { - this.plugin.log(Level.FINE, String.format("Moving NEW player to(firstspawnoverride): %s", - worldManager.getFirstSpawnWorld().getSpawnLocation())); + this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): " + + worldManager.getFirstSpawnWorld().getSpawnLocation()); this.sendPlayerToDefaultWorld(p); } return; @@ -170,9 +170,8 @@ public class MVPlayerListener implements Listener { */ @EventHandler(priority = EventPriority.HIGHEST) public void playerTeleport(PlayerTeleportEvent event) { - this.plugin.log(Level.FINER, String.format( - "Got teleport event for player '%s' with cause '%s'", - event.getPlayer().getName(), event.getCause())); + this.plugin.log(Level.FINER, "Got teleport event for player '" + + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'"); if (event.isCancelled()) { return; } @@ -187,16 +186,15 @@ public class MVPlayerListener implements Listener { teleporter = this.plugin.getServer().getPlayer(teleporterName); } } - this.plugin.log(Level.FINER, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'", - teleporter, teleporterName, teleportee.getName())); + this.plugin.log(Level.FINER, "Inferred sender '" + teleporter + "' from name '" + + teleporterName + "', fetched from name '" + teleportee.getName() + "'"); MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); if (fromWorld == null || toWorld == null) return; if (event.getFrom().getWorld().equals(event.getTo().getWorld())) { // The player is Teleporting to the same world. - this.plugin.log(Level.FINER, String.format("Player '%s' is teleporting to the same world.", - teleportee.getName())); + this.plugin.log(Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world."); this.stateSuccess(teleportee.getName(), toWorld.getAlias()); return; } @@ -204,33 +202,31 @@ public class MVPlayerListener implements Listener { // Charge the teleporter event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true)); if (event.isCancelled() && teleporter != null) { - this.plugin.log(Level.FINE, String.format( - "Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.", - teleportee.getName(), toWorld.getAlias(), teleporter.getName())); - + this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + + "' was DENIED ACCESS to '" + toWorld.getAlias() + + "' because '" + teleporter.getName() + + "' don't have the FUNDS required to enter it."); return; } if (plugin.getMVConfig().getEnforceAccess()) { event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee)); if (event.isCancelled() && teleporter != null) { - this.plugin.log(Level.FINE, String.format( - "Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s", - teleportee.getName(), toWorld.getAlias(), teleporter.getName(), - event.getTo().getWorld().getName())); + this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + + "' was DENIED ACCESS to '" + toWorld.getAlias() + + "' because '" + teleporter.getName() + + "' don't have: multiverse.access." + event.getTo().getWorld().getName()); } else { this.stateSuccess(teleportee.getName(), toWorld.getAlias()); } } else { - this.plugin.log(Level.FINE, String.format( - "Player '%s' was allowed to go to '%s' because enforceaccess is off.", - teleportee.getName(), toWorld.getAlias())); + this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + + "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off."); } } private void stateSuccess(String playerName, String worldName) { - this.plugin.log(Level.FINE, String.format( - "MV-Core is allowing Player '%s' to go to '%s'.", - playerName, worldName)); + this.plugin.log(Level.FINE, "MV-Core is allowing Player '" + playerName + + "' to go to '" + worldName + "'."); } /** @@ -281,19 +277,22 @@ public class MVPlayerListener implements Listener { } event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true)); if (event.isCancelled()) { - this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have the FUNDS required to enter.", - event.getPlayer().getName(), event.getTo().getWorld().getName())); + this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + + "' because they don't have the FUNDS required to enter."); return; } if (plugin.getMVConfig().getEnforceAccess()) { event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer())); if (event.isCancelled()) { - this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have: multiverse.access.%s", - event.getPlayer().getName(), event.getTo().getWorld().getName(), event.getTo().getWorld().getName())); + this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + + "' because they don't have: multiverse.access." + event.getTo().getWorld().getName()); } } else { - this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.", - event.getPlayer().getName(), event.getTo().getWorld().getName())); + this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + + "' was allowed to go to '" + event.getTo().getWorld().getName() + + "' because enforceaccess is off."); } } @@ -314,8 +313,8 @@ public class MVPlayerListener implements Listener { if (mvWorld != null) { this.handleGameMode(player, mvWorld); } else { - this.plugin.log(Level.FINER, String.format( - "Not handling gamemode for world '%s' not managed by Multiverse.", world.getName())); + this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName() + + "' not managed by Multiverse."); } } @@ -333,21 +332,21 @@ public class MVPlayerListener implements Listener { public void run() { // Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled. if (player.getWorld() == world.getCBWorld()) { - MultiverseCore.staticLog(Level.FINE, String.format( - "Handling gamemode for player: %s, Changing to %s", - player.getName(), world.getGameMode().toString())); + MultiverseCore.staticLog(Level.FINE, "Handling gamemode for player: " + + player.getName() + ", Changing to " + world.getGameMode().toString()); MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld()); MultiverseCore.staticLog(Level.FINEST, "To World: " + world); player.setGameMode(world.getGameMode()); } else { - MultiverseCore.staticLog(Level.FINE, - String.format("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'", - player.getName(), player.getWorld().getName(), world.getName())); + MultiverseCore.staticLog(Level.FINE, "The gamemode was NOT changed for player '" + + player.getName() + "' because he is now in world '" + + player.getWorld().getName() + "' instead of world '" + + world.getName() +"'"); } } }, 1L); } else { - this.plugin.log(Level.FINE, String.format("Player: %s is IMMUNE to gamemode changes!", player.getName())); + this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!"); } } }