Add per-component logging
This commit is contained in:
parent
1139f832b6
commit
58fcd4c145
6 changed files with 22 additions and 14 deletions
|
@ -71,14 +71,14 @@ public class MemberComponent extends Component<MainPlugin> implements Listener {
|
|||
try {
|
||||
if (permission.playerAddGroup(null, player, memberGroup().get())) {
|
||||
player.sendMessage("§bYou are a member now!");
|
||||
MainPlugin.Instance.getLogger().info("Added " + player.getName() + " as a member.");
|
||||
log("Added " + player.getName() + " as a member.");
|
||||
return true;
|
||||
} else {
|
||||
MainPlugin.Instance.getLogger().warning("Failed to assign the member role! Please make sure the member group exists or disable the component if it's unused.");
|
||||
logWarn("Failed to assign the member role! Please make sure the member group exists or disable the component if it's unused.");
|
||||
return false;
|
||||
}
|
||||
} catch (UnsupportedOperationException e) {
|
||||
MainPlugin.Instance.getLogger().warning("Failed to assign the member role! Groups are not supported by the permissions implementation.");
|
||||
logWarn("Failed to assign the member role! Groups are not supported by the permissions implementation.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,11 +59,10 @@ public class RandomTP extends ICommand2MC
|
|||
{
|
||||
world = Bukkit.getWorld("World");
|
||||
border = world.getWorldBorder();
|
||||
Logger logger = component.getPlugin().getLogger();
|
||||
logger.info("Getting new location");
|
||||
component.log("Getting new location");
|
||||
if(border.getSize() > 100000)
|
||||
logger.warning("World border is wide, it may take a minute...");
|
||||
logger.info("Success: "+newLocation());
|
||||
component.logWarn("World border is wide, it may take a minute...");
|
||||
component.log("Success: "+newLocation());
|
||||
}
|
||||
|
||||
/*================================================================================================*/
|
||||
|
|
|
@ -30,21 +30,22 @@ public class TownyComponent extends Component<MainPlugin> {
|
|||
* @param newName The player's new name
|
||||
*/
|
||||
public static void renameInTowny(String oldName, String newName) {
|
||||
if (!ComponentManager.isEnabled(TownyComponent.class))
|
||||
var component = ComponentManager.getIfEnabled(TownyComponent.class);
|
||||
if (component == null)
|
||||
return;
|
||||
Bukkit.getLogger().info("Renaming " + oldName + " in Towny to " + newName);
|
||||
component.log("Renaming " + oldName + " in Towny to " + newName);
|
||||
TownyUniverse tu = TownyUniverse.getInstance();
|
||||
try {
|
||||
Resident resident = tu.getDataSource().getResident(oldName);
|
||||
if (resident == null) {
|
||||
Bukkit.getLogger().warning("Resident not found - couldn't rename in Towny.");
|
||||
component.logWarn("Resident not found - couldn't rename in Towny.");
|
||||
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
|
||||
} else if (tu.getDataSource().hasResident(newName)) {
|
||||
Bukkit.getLogger().warning("Target resident name is already in use.");
|
||||
component.logWarn("Target resident name is already in use.");
|
||||
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
|
||||
} else {
|
||||
tu.getDataSource().renamePlayer(resident, newName); //Fixed in Towny 0.91.1.2
|
||||
Bukkit.getLogger().info("Renaming done.");
|
||||
component.log("Renaming done.");
|
||||
}
|
||||
} catch (AlreadyRegisteredException e) {
|
||||
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e);
|
||||
|
|
|
@ -38,7 +38,7 @@ public class VotifierComponent extends Component<MainPlugin> {
|
|||
@SuppressWarnings("deprecation")
|
||||
public void onVotifierEvent(VotifierEvent event) {
|
||||
Vote vote = event.getVote();
|
||||
getPlugin().getLogger().info("Vote: " + vote);
|
||||
log("Vote: " + vote);
|
||||
org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote.getUsername());
|
||||
Player p = Bukkit.getPlayer(vote.getUsername());
|
||||
/*if (op != null) {
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.HashMap;
|
|||
*
|
||||
* @author dumptruckman & Articdive
|
||||
*/
|
||||
public class CommentedConfiguration extends YamlConfiguration { //TODO: Remove FileMgmt dependency
|
||||
public class CommentedConfiguration extends YamlConfiguration {
|
||||
private HashMap<String, String> comments;
|
||||
private File file;
|
||||
|
||||
|
|
|
@ -175,6 +175,14 @@ public abstract class Component<TP extends JavaPlugin> {
|
|||
return Collections.unmodifiableMap(components);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
plugin.getLogger().info("[" + getClassName() + "] " + message);
|
||||
}
|
||||
|
||||
public void logWarn(String message) {
|
||||
plugin.getLogger().warning("[" + getClassName() + "] " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the module, when called by the JavaPlugin class.
|
||||
* This gets fired when the plugin is enabled. Use {@link #enable()} to register commands and such.
|
||||
|
|
Loading…
Reference in a new issue