mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-09-12 05:08:48 +00:00
Stop the error on shutdown if GM failed to load at startup.
GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. Startup errors will now lock out ALL commands other than '/manload'
This commit is contained in:
parent
f02691863b
commit
cdae0898c7
|
@ -170,3 +170,6 @@ v 2.0:
|
||||||
- Fix a concurrent modification error when removing all attachments.
|
- Fix a concurrent modification error when removing all attachments.
|
||||||
- Better handling of errors in user and group yml's.
|
- Better handling of errors in user and group yml's.
|
||||||
- Added missing confirmation message on '/manload'.
|
- Added missing confirmation message on '/manload'.
|
||||||
|
- Stop the error on shutdown if GM failed to load at startup.
|
||||||
|
- GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log.
|
||||||
|
- Startup errors will now lock out ALL commands other than '/manload'
|
|
@ -14,6 +14,7 @@ import org.anjocaido.groupmanager.data.Group;
|
||||||
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
|
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
|
||||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -60,6 +61,9 @@ public class GroupManager extends JavaPlugin {
|
||||||
private Map<CommandSender, String> selectedWorlds = new HashMap<CommandSender, String>();
|
private Map<CommandSender, String> selectedWorlds = new HashMap<CommandSender, String>();
|
||||||
private WorldsHolder worldsHolder;
|
private WorldsHolder worldsHolder;
|
||||||
private boolean validateOnlinePlayer = true;
|
private boolean validateOnlinePlayer = true;
|
||||||
|
|
||||||
|
private String lastError = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the validateOnlinePlayer
|
* @return the validateOnlinePlayer
|
||||||
*/
|
*/
|
||||||
|
@ -108,8 +112,10 @@ public class GroupManager extends JavaPlugin {
|
||||||
WorldEvents = null;
|
WorldEvents = null;
|
||||||
|
|
||||||
// Remove all attachments before clearing
|
// Remove all attachments before clearing
|
||||||
|
if (BukkitPermissions != null) {
|
||||||
BukkitPermissions.removeAllAttachments();
|
BukkitPermissions.removeAllAttachments();
|
||||||
BukkitPermissions = null;
|
BukkitPermissions = null;
|
||||||
|
}
|
||||||
|
|
||||||
// EXAMPLE: Custom code, here we just output some info so we can check that
|
// EXAMPLE: Custom code, here we just output some info so we can check that
|
||||||
// all is well
|
// all is well
|
||||||
|
@ -118,8 +124,12 @@ public class GroupManager extends JavaPlugin {
|
||||||
GroupManager.logger.removeHandler(ch);
|
GroupManager.logger.removeHandler(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
//@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
lastError = "";
|
||||||
|
|
||||||
GroupManager.logger.setUseParentHandlers(false);
|
GroupManager.logger.setUseParentHandlers(false);
|
||||||
ch = new GMLoggerHandler();
|
ch = new GMLoggerHandler();
|
||||||
GroupManager.logger.addHandler(ch);
|
GroupManager.logger.addHandler(ch);
|
||||||
|
@ -165,6 +175,57 @@ public class GroupManager extends JavaPlugin {
|
||||||
|
|
||||||
// Register as a service
|
// Register as a service
|
||||||
this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest);
|
this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Store the error and write to the log.
|
||||||
|
*/
|
||||||
|
saveErrorLog(ex);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Throw an error so Bukkit knows about it.
|
||||||
|
*/
|
||||||
|
throw new IllegalArgumentException(ex.getMessage(),ex);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an error.log
|
||||||
|
*
|
||||||
|
* @param ex
|
||||||
|
*/
|
||||||
|
private void saveErrorLog(Exception ex) {
|
||||||
|
|
||||||
|
if (!getDataFolder().exists()) {
|
||||||
|
getDataFolder().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
lastError = ex.getMessage();
|
||||||
|
|
||||||
|
GroupManager.logger.severe("===================================================");
|
||||||
|
GroupManager.logger.severe("= ERROR REPORT START =");
|
||||||
|
GroupManager.logger.severe("===================================================");
|
||||||
|
GroupManager.logger.severe("=== PLEASE COPY AND PASTE THE ERROR.LOG FROM THE ==");
|
||||||
|
GroupManager.logger.severe("= GROUPMANAGER FOLDER TO AN ESSENTIALS DEVELOPER =");
|
||||||
|
GroupManager.logger.severe("===================================================");
|
||||||
|
GroupManager.logger.severe(lastError);
|
||||||
|
GroupManager.logger.severe("===================================================");
|
||||||
|
GroupManager.logger.severe("= ERROR REPORT ENDED =");
|
||||||
|
GroupManager.logger.severe("===================================================");
|
||||||
|
|
||||||
|
// Append this error to the error log.
|
||||||
|
try {
|
||||||
|
String error = "=============================== GM ERROR LOG ===============================\n\n";
|
||||||
|
error += Tasks.getStackTraceAsString(ex);
|
||||||
|
error += "\n============================================================================\n";
|
||||||
|
|
||||||
|
Tasks.appendStringToFile(error, (getDataFolder() + System.getProperty("file.separator") + "ERROR.LOG"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Failed to write file.
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLoaded() {
|
public static boolean isLoaded() {
|
||||||
|
@ -301,9 +362,16 @@ public class GroupManager extends JavaPlugin {
|
||||||
User senderUser = null;
|
User senderUser = null;
|
||||||
boolean isOpOverride = config.isOpOverride();
|
boolean isOpOverride = config.isOpOverride();
|
||||||
|
|
||||||
|
|
||||||
// DETERMINING PLAYER INFORMATION
|
// DETERMINING PLAYER INFORMATION
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
senderPlayer = (Player) sender;
|
senderPlayer = (Player) sender;
|
||||||
|
|
||||||
|
if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
|
senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
|
||||||
senderGroup = senderUser.getGroup();
|
senderGroup = senderUser.getGroup();
|
||||||
isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op")));
|
isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op")));
|
||||||
|
@ -313,6 +381,12 @@ public class GroupManager extends JavaPlugin {
|
||||||
playerCanDo = true;
|
playerCanDo = true;
|
||||||
}
|
}
|
||||||
} else if (sender instanceof ConsoleCommandSender) {
|
} else if (sender instanceof ConsoleCommandSender) {
|
||||||
|
|
||||||
|
if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
isConsole = true;
|
isConsole = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1560,10 +1634,17 @@ public class GroupManager extends JavaPlugin {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case manload:
|
case manload:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to reload a specific world
|
* Attempt to reload a specific world
|
||||||
*/
|
*/
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
|
||||||
|
if (!lastError.isEmpty()) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auxString = "";
|
auxString = "";
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
auxString += args[i];
|
auxString += args[i];
|
||||||
|
@ -1588,6 +1669,11 @@ public class GroupManager extends JavaPlugin {
|
||||||
/**
|
/**
|
||||||
* Reload all settings and data as no world was specified.
|
* Reload all settings and data as no world was specified.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the last error as we are attempting a fresh load.
|
||||||
|
*/
|
||||||
|
lastError = "";
|
||||||
onDisable();
|
onDisable();
|
||||||
onEnable();
|
onEnable();
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,17 @@
|
||||||
*/
|
*/
|
||||||
package org.anjocaido.groupmanager.utils;
|
package org.anjocaido.groupmanager.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -17,12 +22,26 @@ import java.util.List;
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
import org.anjocaido.groupmanager.data.Group;
|
import org.anjocaido.groupmanager.data.Group;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author gabrielcouto
|
* @author gabrielcouto
|
||||||
*/
|
*/
|
||||||
public abstract class Tasks {
|
public abstract class Tasks {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the exception stack trace as a string.
|
||||||
|
*
|
||||||
|
* @param exception
|
||||||
|
* @return stack trace as a string
|
||||||
|
*/
|
||||||
|
public static String getStackTraceAsString(Exception exception) {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
exception.printStackTrace(pw);
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static void copy(InputStream src, File dst) throws IOException {
|
public static void copy(InputStream src, File dst) throws IOException {
|
||||||
InputStream in = src;
|
InputStream in = src;
|
||||||
OutputStream out = new FileOutputStream(dst);
|
OutputStream out = new FileOutputStream(dst);
|
||||||
|
@ -45,6 +64,28 @@ public abstract class Tasks {
|
||||||
copy(in, dst);
|
copy(in, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string to a file
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param file
|
||||||
|
*/
|
||||||
|
public static void appendStringToFile(String data, String file) throws IOException {
|
||||||
|
|
||||||
|
FileWriter outStream = new FileWriter("." + System.getProperty("file.separator") + file, true);
|
||||||
|
|
||||||
|
BufferedWriter out = new BufferedWriter(outStream);
|
||||||
|
|
||||||
|
data.replaceAll("\n", System.getProperty("line.separator"));
|
||||||
|
|
||||||
|
out.append(new SimpleDateFormat("yyyy-MM-dd HH-mm").format(System.currentTimeMillis()));
|
||||||
|
out.append(System.getProperty("line.separator"));
|
||||||
|
out.append(data);
|
||||||
|
out.append(System.getProperty("line.separator"));
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
public static void removeOldFiles(GroupManager gm, File folder) {
|
public static void removeOldFiles(GroupManager gm, File folder) {
|
||||||
if (folder.isDirectory()) {
|
if (folder.isDirectory()) {
|
||||||
long oldTime = System.currentTimeMillis() - (((long)gm.getGMConfig().getBackupDuration()*60*60)*1000);
|
long oldTime = System.currentTimeMillis() - (((long)gm.getGMConfig().getBackupDuration()*60*60)*1000);
|
||||||
|
|
Loading…
Reference in a new issue