Skip to content

Commit

Permalink
Merge pull request #197 from benwoo1110/logging
Browse files Browse the repository at this point in the history
Move all logging to use static Logging class.
  • Loading branch information
nicegamer7 authored Dec 14, 2020
2 parents 2d2f2c4 + 0f34bb8 commit 7d19a53
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ private void initMVNPConfig() {
this.MVNPConfiguration.load(configFile);
}
catch (IOException e) {
this.log(Level.SEVERE, "Could not load " + NETHER_PORTALS_CONFIG);
Logging.severe("Could not load " + NETHER_PORTALS_CONFIG);
}
catch (InvalidConfigurationException e) {
this.log(Level.SEVERE, NETHER_PORTALS_CONFIG + " contained INVALID YAML. Please look at the file.");
Logging.severe(NETHER_PORTALS_CONFIG + " contained INVALID YAML. Please look at the file.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onarandombox.MultiverseNetherPortals.listeners;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
Expand Down Expand Up @@ -75,7 +76,7 @@ public MVNPEntityListener(MultiverseNetherPortals plugin) {
*/
protected boolean shootPlayer(Player p, Block block, PortalType type) {
if (!plugin.isUsingBounceBack()) {
this.plugin.log(Level.FINEST, "Bounceback is disabled. The player is free to walk into the portal!");
Logging.finest("Bounceback is disabled. The player is free to walk into the portal!");
return false;
}

Expand Down Expand Up @@ -121,7 +122,7 @@ protected boolean shootPlayer(Player p, Block block, PortalType type) {
debugMessage.append(" entered an Unsupported Portal Type (").append(type).append(").");
}

this.plugin.log(Level.FINER, debugMessage.toString());
Logging.finer(debugMessage.toString());
return playerBounced;
}

Expand Down Expand Up @@ -213,10 +214,10 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) {
eventRecord.removeFromRecord(type, p.getUniqueId());
}

this.plugin.log(Level.FINEST, "Someone requested that this player be bounced back!");
Logging.finest("Someone requested that this player be bounced back!");
}
if (playerTouchedPortalEvent.isCancelled()) {
this.plugin.log(Level.FINEST, "Someone cancelled the enter Event for NetherPortals!");
Logging.finest("Someone cancelled the enter Event for NetherPortals!");
return;
}

Expand Down Expand Up @@ -264,15 +265,15 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) {

if (fromWorld.getCBWorld().equals(toWorld.getCBWorld())) {
// The player is Portaling to the same world.
this.plugin.log(Level.FINER, "Player '" + p.getName() + "' is portaling to the same world.");
Logging.finer("Player '" + p.getName() + "' is portaling to the same world.");
return;
}
if (!pt.playerHasMoneyToEnter(fromWorld, toWorld, p, p, false)) {
if (this.shootPlayer(p, eventLocation.getBlock(), type)) {
eventRecord.removeFromRecord(type, p.getUniqueId());
}

this.plugin.log(Level.FINE, "Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getCBWorld().getName() +
Logging.fine("Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getCBWorld().getName() +
"' because they don't have the FUNDS required to enter.");
return;
}
Expand All @@ -283,18 +284,18 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) {
eventRecord.removeFromRecord(type, p.getUniqueId());
}

this.plugin.log(Level.FINE, "Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getCBWorld().getName() +
Logging.fine("Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getCBWorld().getName() +
"' because they don't have: multiverse.access." + toWorld.getCBWorld().getName());
}
} else {
this.plugin.log(Level.FINE, "Player '" + p.getName() + "' was allowed to go to '" + toWorld.getCBWorld().getName() + "' because enforceaccess is off.");
Logging.fine("Player '" + p.getName() + "' was allowed to go to '" + toWorld.getCBWorld().getName() + "' because enforceaccess is off.");
}
}

@EventHandler
public void onEntityPortal(EntityPortalEvent event) {
if (event.isCancelled()) {
this.plugin.log(Level.FINEST, "EntityPortalEvent was cancelled! NOT teleporting!");
Logging.finest("EntityPortalEvent was cancelled! NOT teleporting!");
return;
}

Expand Down Expand Up @@ -327,7 +328,7 @@ public void onEntityPortal(EntityPortalEvent event) {
Class.forName("org.bukkit.TravelAgent");
event.useTravelAgent(true);
} catch (ClassNotFoundException ignore) {
plugin.log(Level.FINE, "TravelAgent not available for EntityPortalEvent for " + e.getName());
Logging.fine("TravelAgent not available for EntityPortalEvent for " + e.getName());
}
}

Expand All @@ -347,12 +348,12 @@ public void onEntityPortal(EntityPortalEvent event) {

if (!event.isCancelled()) {
if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
this.plugin.log(Level.FINE, "Entity '" + e.getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
Logging.fine("Entity '" + e.getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
try {
Class.forName("org.bukkit.TravelAgent");
event.getPortalTravelAgent().setCanCreatePortal(false);
} catch (ClassNotFoundException ignore) {
plugin.log(Level.FINE, "TravelAgent not available for EntityPortalEvent for " + e.getName() + ". There may be a portal created at spawn.");
Logging.fine("TravelAgent not available for EntityPortalEvent for " + e.getName() + ". There may be a portal created at spawn.");
}

event.setTo(toWorld.getSpawnLocation());
Expand All @@ -362,7 +363,7 @@ public void onEntityPortal(EntityPortalEvent event) {
event.getPortalTravelAgent().setCanCreatePortal(true);
event.setTo(event.getPortalTravelAgent().findOrCreate(event.getTo()));
} catch (ClassNotFoundException ignore) {
plugin.log(Level.FINE, "TravelAgent not available for EntityPortalEvent for " + e.getName() + ". Their destination may not be correct.");
Logging.fine("TravelAgent not available for EntityPortalEvent for " + e.getName() + ". Their destination may not be correct.");
event.setTo(event.getTo());
}
} else if (toWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.logging.Level;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.PermissionTools;
Expand Down Expand Up @@ -39,7 +40,7 @@ public MVNPPlayerListener(MultiverseNetherPortals plugin) {
@EventHandler
public void onPlayerPortal(PlayerPortalEvent event) {
if (event.isCancelled()) {
this.plugin.log(Level.FINEST, "PlayerPortalEvent was cancelled! NOT teleporting!");
Logging.finest("PlayerPortalEvent was cancelled! NOT teleporting!");
return;
}

Expand All @@ -62,7 +63,7 @@ public void onPlayerPortal(PlayerPortalEvent event) {
Class.forName("org.bukkit.TravelAgent");
event.useTravelAgent(true);
} catch (ClassNotFoundException ignore) {
plugin.log(Level.FINE, "TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
}
}

Expand Down Expand Up @@ -105,12 +106,12 @@ public void onPlayerPortal(PlayerPortalEvent event) {

if (!event.isCancelled()) {
if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
Logging.fine("Player '" + event.getPlayer().getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
try {
Class.forName("org.bukkit.TravelAgent");
event.getPortalTravelAgent().setCanCreatePortal(false);
} catch (ClassNotFoundException ignore) {
plugin.log(Level.FINE, "TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". There may be a portal created at spawn.");
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". There may be a portal created at spawn.");
}
if (toWorld.getBedRespawn()
&& event.getPlayer().getBedSpawnLocation() != null
Expand All @@ -125,7 +126,7 @@ public void onPlayerPortal(PlayerPortalEvent event) {
event.getPortalTravelAgent().setCanCreatePortal(true);
event.setTo(event.getPortalTravelAgent().findOrCreate(event.getTo()));
} catch (ClassNotFoundException ignore) {
plugin.log(Level.FINE, "TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". Their destination may not be correct.");
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". Their destination may not be correct.");
event.setTo(event.getTo());
}
} else if (toWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onarandombox.MultiverseNetherPortals.utils;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals;
Expand All @@ -22,14 +23,14 @@ public Location findNewTeleportLocation(Location fromLocation, String worldStrin
MultiverseWorld tpTo = this.worldManager.getMVWorld(worldString);

if (tpTo == null) {
this.plugin.log(Level.FINE, "Can't find world " + worldString);
Logging.fine("Can't find world " + worldString);
} else if (e instanceof Player && !this.plugin.getCore().getMVPerms().canEnterWorld((Player) e, tpTo)) {
this.plugin.log(Level.WARNING, "Player " + e.getName() + " can't enter world " + worldString);
Logging.warning("Player " + e.getName() + " can't enter world " + worldString);
} else if (!this.worldManager.isMVWorld(fromLocation.getWorld().getName())) {
this.plugin.log(Level.WARNING, "World " + fromLocation.getWorld().getName() + " is not a Multiverse world");
Logging.warning("World " + fromLocation.getWorld().getName() + " is not a Multiverse world");
} else {
String entityType = (e instanceof Player) ? " player " : " entity ";
this.plugin.log(Level.FINE, "Finding new teleport location for" + entityType + e.getName() + " to world " + worldString);
Logging.fine("Finding new teleport location for" + entityType + e.getName() + " to world " + worldString);

// Set the output location to the same XYZ coords but different world
MultiverseWorld tpFrom = this.worldManager.getMVWorld(fromLocation.getWorld().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package com.onarandombox.MultiverseNetherPortals.utils;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals;
import org.bukkit.PortalType;

import java.util.logging.Level;

public class MVNameChecker {
private MultiverseNetherPortals plugin;
private MultiverseNetherPortals plugin;

public MVNameChecker(MultiverseNetherPortals plugin) {
this.plugin = plugin;
}
/**
* Returns true if the world meets the naming criteria for a nether world. It is NOT checked against the actual worlds here!
*
* @param world The world name to check
* @return True if the world has the correct
*/
public boolean isValidNetherName(String world) {
try {
if (world.matches("^" + this.plugin.getNetherPrefix() + ".+" + this.plugin.getNetherSuffix() + "$")) {
return true;
}
} catch (IndexOutOfBoundsException e) {
}
return false;
}
public MVNameChecker(MultiverseNetherPortals plugin) {
this.plugin = plugin;
}
/**
* Returns true if the world meets the naming criteria for a nether world. It is NOT checked against the actual worlds here!
*
* @param world The world name to check
* @return True if the world has the correct
*/
public boolean isValidNetherName(String world) {
try {
if (world.matches("^" + this.plugin.getNetherPrefix() + ".+" + this.plugin.getNetherSuffix() + "$")) {
return true;
}
} catch (IndexOutOfBoundsException e) {
}
return false;
}

/**
* Returns true if the world meets the naming criteria for an end world. It is NOT checked against the actual worlds here!
Expand All @@ -42,44 +41,44 @@ public boolean isValidEndName(String world) {
}
return false;
}
/**
* Takes a given normal name and adds the nether prefix and suffix onto it!
*
* @param normalName
* @return
*/
public String getNetherName(String normalName) {

/**
* Takes a given normal name and adds the nether prefix and suffix onto it!
*
* @param normalName
* @return
*/
public String getNetherName(String normalName) {
final String netherName = this.plugin.getNetherPrefix() + normalName + this.plugin.getNetherSuffix();
if (plugin.getCore().getMVWorldManager().isMVWorld(netherName)) {
this.plugin.log(Level.FINEST, "Selected nether world '" + netherName + "' for normal '" + normalName + "'");
Logging.finest("Selected nether world '" + netherName + "' for normal '" + normalName + "'");
}
return netherName;
}
/**
* Takes a given normal name and adds the end prefix and suffix onto it!
*
* @param normalName
* @return
*/
public String getEndName(String normalName) {
return netherName;
}

/**
* Takes a given normal name and adds the end prefix and suffix onto it!
*
* @param normalName
* @return
*/
public String getEndName(String normalName) {
final String endName = this.plugin.getEndPrefix() + normalName + this.plugin.getEndSuffix();
if (plugin.getCore().getMVWorldManager().isMVWorld(endName)) {
this.plugin.log(Level.FINEST, "Selected end world '" + endName + "' for normal '" + normalName + "'");
Logging.finest("Selected end world '" + endName + "' for normal '" + normalName + "'");
}
return endName;
}
/**
* Takes a given normal name chops the suffix and prefix off!
*
* @return
*/
public String getNormalName(String netherName, PortalType type) {
// Start by copying the nether name, we're going to transform it into a normal name!
String normalName = netherName;
// Chop off the prefix
return endName;
}

/**
* Takes a given normal name chops the suffix and prefix off!
*
* @return
*/
public String getNormalName(String netherName, PortalType type) {
// Start by copying the nether name, we're going to transform it into a normal name!
String normalName = netherName;
// Chop off the prefix
if (type == PortalType.NETHER) {
if (this.plugin.getNetherPrefix().length() > 0) {
String[] split = normalName.split(this.plugin.getNetherPrefix());
Expand All @@ -102,9 +101,9 @@ public String getNormalName(String netherName, PortalType type) {
}
}
if (!normalName.equals(netherName) && plugin.getCore().getMVWorldManager().isMVWorld(normalName)) {
this.plugin.log(Level.FINEST, "Selected normal world '" + normalName + "' for " + type + " '" + netherName + "'");
Logging.finest("Selected normal world '" + normalName + "' for " + type + " '" + netherName + "'");
}
// All we're left with is the normal world. Don't worry if it exists, the method below will handle that!
return normalName;
}
return normalName;
}
}

0 comments on commit 7d19a53

Please sign in to comment.