mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-12 11:21:34 +01:00
Now using Bukkit's tagged logging
This commit is contained in:
parent
57ed91cd28
commit
c14d25f860
@ -41,10 +41,6 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public abstract class Blacklist {
|
public abstract class Blacklist {
|
||||||
/**
|
|
||||||
* Logger.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of entries by block ID.
|
* List of entries by block ID.
|
||||||
@ -67,8 +63,11 @@ public abstract class Blacklist {
|
|||||||
|
|
||||||
private boolean useAsWhitelist;
|
private boolean useAsWhitelist;
|
||||||
|
|
||||||
public Blacklist(Boolean useAsWhitelist) {
|
private final Logger logger;
|
||||||
|
|
||||||
|
public Blacklist(Boolean useAsWhitelist, Logger logger) {
|
||||||
this.useAsWhitelist = useAsWhitelist;
|
this.useAsWhitelist = useAsWhitelist;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,7 +177,7 @@ public void load(File file) throws IOException {
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
id = getItemID(item.trim());
|
id = getItemID(item.trim());
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
|
logger.log(Level.WARNING, "Unknown block name: "
|
||||||
+ item);
|
+ item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,17 +37,15 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
|
public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
|
||||||
/**
|
|
||||||
* Logger.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
|
|
||||||
private String worldName;
|
private String worldName;
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
public ConsoleLoggerHandler(String worldName)
|
public ConsoleLoggerHandler(String worldName, Logger logger) {
|
||||||
{
|
this.worldName = worldName;
|
||||||
this.worldName = worldName;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,55 +57,55 @@ public void logEvent(BlacklistEvent event, String comment) {
|
|||||||
// Block break
|
// Block break
|
||||||
if (event instanceof BlockBreakBlacklistEvent) {
|
if (event instanceof BlockBreakBlacklistEvent) {
|
||||||
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
|
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to break " + getFriendlyItemName(evt.getType())
|
+ " tried to break " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Block place
|
// Block place
|
||||||
} else if (event instanceof BlockPlaceBlacklistEvent) {
|
} else if (event instanceof BlockPlaceBlacklistEvent) {
|
||||||
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
|
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to place " + getFriendlyItemName(evt.getType())
|
+ " tried to place " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Block interact
|
// Block interact
|
||||||
} else if (event instanceof BlockInteractBlacklistEvent) {
|
} else if (event instanceof BlockInteractBlacklistEvent) {
|
||||||
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
|
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to interact with " + getFriendlyItemName(evt.getType())
|
+ " tried to interact with " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Destroy with
|
// Destroy with
|
||||||
} else if (event instanceof DestroyWithBlacklistEvent) {
|
} else if (event instanceof DestroyWithBlacklistEvent) {
|
||||||
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
|
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to destroy with " + getFriendlyItemName(evt.getType())
|
+ " tried to destroy with " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Acquire
|
// Acquire
|
||||||
} else if (event instanceof ItemAcquireBlacklistEvent) {
|
} else if (event instanceof ItemAcquireBlacklistEvent) {
|
||||||
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
|
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to acquire " + getFriendlyItemName(evt.getType())
|
+ " tried to acquire " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Drop
|
// Drop
|
||||||
} else if (event instanceof ItemDropBlacklistEvent) {
|
} else if (event instanceof ItemDropBlacklistEvent) {
|
||||||
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
|
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to drop " + getFriendlyItemName(evt.getType())
|
+ " tried to drop " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Use
|
// Use
|
||||||
} else if (event instanceof ItemUseBlacklistEvent) {
|
} else if (event instanceof ItemUseBlacklistEvent) {
|
||||||
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
|
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " tried to use " + getFriendlyItemName(evt.getType())
|
+ " tried to use " + getFriendlyItemName(evt.getType())
|
||||||
+ (comment != null ? " (" + comment + ")" : ""));
|
+ (comment != null ? " (" + comment + ")" : ""));
|
||||||
|
|
||||||
// Unknown
|
// Unknown
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
|
logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName()
|
||||||
+ " caught unknown event: " + event.getClass().getCanonicalName());
|
+ " caught unknown event: " + event.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,35 +42,33 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||||
/**
|
|
||||||
* Logger.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DSN.
|
* DSN.
|
||||||
*/
|
*/
|
||||||
private String dsn;
|
private final String dsn;
|
||||||
/**
|
/**
|
||||||
* Username.
|
* Username.
|
||||||
*/
|
*/
|
||||||
private String user;
|
private final String user;
|
||||||
/**
|
/**
|
||||||
* Password.
|
* Password.
|
||||||
*/
|
*/
|
||||||
private String pass;
|
private final String pass;
|
||||||
/**
|
/**
|
||||||
* Table.
|
* Table.
|
||||||
*/
|
*/
|
||||||
private String table;
|
private final String table;
|
||||||
/**
|
/**
|
||||||
* World name.
|
* World name.
|
||||||
*/
|
*/
|
||||||
private String worldName;
|
private final String worldName;
|
||||||
/**
|
/**
|
||||||
* Database connection.
|
* Database connection.
|
||||||
*/
|
*/
|
||||||
private Connection conn;
|
private Connection conn;
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
@ -81,12 +79,13 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
|||||||
* @param table
|
* @param table
|
||||||
* @param worldName
|
* @param worldName
|
||||||
*/
|
*/
|
||||||
public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName) {
|
public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName, Logger logger) {
|
||||||
this.dsn = dsn;
|
this.dsn = dsn;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.pass = pass;
|
this.pass = pass;
|
||||||
this.table = table;
|
this.table = table;
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,10 +105,8 @@ private Connection getConnection() throws SQLException {
|
|||||||
* Log an event to the database.
|
* Log an event to the database.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* @param name
|
* @param player
|
||||||
* @param x
|
* @param pos
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @param item
|
* @param item
|
||||||
* @param comment
|
* @param comment
|
||||||
*/
|
*/
|
||||||
|
@ -52,10 +52,6 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class FileLoggerHandler implements BlacklistLoggerHandler {
|
public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||||
/**
|
|
||||||
* Logger.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
/**
|
/**
|
||||||
* Regex for patterns in the path.
|
* Regex for patterns in the path.
|
||||||
*/
|
*/
|
||||||
@ -83,6 +79,8 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
|||||||
*/
|
*/
|
||||||
private TreeMap<String,FileLoggerWriter> writers =
|
private TreeMap<String,FileLoggerWriter> writers =
|
||||||
new TreeMap<String,FileLoggerWriter>();
|
new TreeMap<String,FileLoggerWriter>();
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
@ -90,9 +88,10 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
|
|||||||
* @param pathPattern
|
* @param pathPattern
|
||||||
* @param worldName
|
* @param worldName
|
||||||
*/
|
*/
|
||||||
public FileLoggerHandler(String pathPattern, String worldName) {
|
public FileLoggerHandler(String pathPattern, String worldName, Logger logger) {
|
||||||
this.pathPattern = pathPattern;
|
this.pathPattern = pathPattern;
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,13 +101,14 @@ public FileLoggerHandler(String pathPattern, String worldName) {
|
|||||||
* @param cacheSize
|
* @param cacheSize
|
||||||
* @param worldName
|
* @param worldName
|
||||||
*/
|
*/
|
||||||
public FileLoggerHandler(String pathPattern, int cacheSize, String worldName) {
|
public FileLoggerHandler(String pathPattern, int cacheSize, String worldName, Logger logger) {
|
||||||
if (cacheSize < 1) {
|
if (cacheSize < 1) {
|
||||||
throw new IllegalArgumentException("Cache size cannot be less than 1");
|
throw new IllegalArgumentException("Cache size cannot be less than 1");
|
||||||
}
|
}
|
||||||
this.pathPattern = pathPattern;
|
this.pathPattern = pathPattern;
|
||||||
this.cacheSize = cacheSize;
|
this.cacheSize = cacheSize;
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,7 +25,7 @@ public class BukkitBlacklist extends Blacklist {
|
|||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
|
||||||
super(useAsWhitelist);
|
super(useAsWhitelist, plugin.getLogger());
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public void load() {
|
|||||||
try {
|
try {
|
||||||
config.load();
|
config.load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
WorldGuardPlugin.logger.severe("Error reading configuration for global config: ");
|
plugin.getLogger().severe("Error reading configuration for global config: ");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ public void load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!config.save()) {
|
if (!config.save()) {
|
||||||
WorldGuardPlugin.logger.severe("Error saving configuration!");
|
plugin.getLogger().severe("Error saving configuration!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,10 +40,6 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class LegacyWorldGuardMigration {
|
public class LegacyWorldGuardMigration {
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
protected static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Port over the blacklist.
|
* Port over the blacklist.
|
||||||
@ -59,7 +55,7 @@ public static void migrateBlacklist(WorldGuardPlugin plugin) {
|
|||||||
File newFile = new File(plugin.getDataFolder(), newPath);
|
File newFile = new File(plugin.getDataFolder(), newPath);
|
||||||
|
|
||||||
if (!newFile.exists() && oldFile.exists()) {
|
if (!newFile.exists() && oldFile.exists()) {
|
||||||
logger.warning("WorldGuard: WorldGuard will now update your blacklist "
|
plugin.getLogger().warning("WorldGuard will now update your blacklist "
|
||||||
+ "from an older version of WorldGuard.");
|
+ "from an older version of WorldGuard.");
|
||||||
|
|
||||||
// Need to make root directories
|
// Need to make root directories
|
||||||
@ -69,9 +65,9 @@ public static void migrateBlacklist(WorldGuardPlugin plugin) {
|
|||||||
oldFile.renameTo(new File(plugin.getDataFolder(),
|
oldFile.renameTo(new File(plugin.getDataFolder(),
|
||||||
"blacklist.txt.old"));
|
"blacklist.txt.old"));
|
||||||
} else {
|
} else {
|
||||||
logger.warning("WorldGuard: blacklist.txt has been converted " +
|
plugin.getLogger().warning("blacklist.txt has been converted " +
|
||||||
"for the main world at " + newPath + "");
|
"for the main world at " + newPath + "");
|
||||||
logger.warning("WorldGuard: Your other worlds currently have no " +
|
plugin.getLogger().warning("Your other worlds currently have no " +
|
||||||
"blacklist defined!");
|
"blacklist defined!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +84,7 @@ public static void migrateRegions(WorldGuardPlugin plugin) {
|
|||||||
File oldDatabase = new File(plugin.getDataFolder(), "regions.txt");
|
File oldDatabase = new File(plugin.getDataFolder(), "regions.txt");
|
||||||
if (!oldDatabase.exists()) return;
|
if (!oldDatabase.exists()) return;
|
||||||
|
|
||||||
logger.info("WorldGuard: The regions database has changed in 5.x. "
|
plugin.getLogger().info("The regions database has changed in 5.x. "
|
||||||
+ "Your old regions database will be converted to the new format "
|
+ "Your old regions database will be converted to the new format "
|
||||||
+ "and set as your primary world's database.");
|
+ "and set as your primary world's database.");
|
||||||
|
|
||||||
@ -96,7 +92,7 @@ public static void migrateRegions(WorldGuardPlugin plugin) {
|
|||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
|
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
|
||||||
|
|
||||||
// First load up the old database using the CSV loader
|
// First load up the old database using the CSV loader
|
||||||
CSVDatabase db = new CSVDatabase(oldDatabase);
|
CSVDatabase db = new CSVDatabase(oldDatabase, plugin.getLogger());
|
||||||
db.load();
|
db.load();
|
||||||
|
|
||||||
// Then save the new database
|
// Then save the new database
|
||||||
@ -105,9 +101,9 @@ public static void migrateRegions(WorldGuardPlugin plugin) {
|
|||||||
|
|
||||||
oldDatabase.renameTo(new File(plugin.getDataFolder(), "regions.txt.old"));
|
oldDatabase.renameTo(new File(plugin.getDataFolder(), "regions.txt.old"));
|
||||||
|
|
||||||
logger.info("WorldGuard: Regions database converted!");
|
plugin.getLogger().info("Regions database converted!");
|
||||||
} catch (ProtectionDatabaseException e) {
|
} catch (ProtectionDatabaseException e) {
|
||||||
logger.warning("WorldGuard: Failed to load regions: "
|
plugin.getLogger().warning("Failed to load regions: "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,6 @@ public class WorldConfiguration {
|
|||||||
"# Remove the {} and add your own entries.\r\n" +
|
"# Remove the {} and add your own entries.\r\n" +
|
||||||
"#\r\n";
|
"#\r\n";
|
||||||
|
|
||||||
private static final Logger logger = Logger
|
|
||||||
.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
private String worldName;
|
private String worldName;
|
||||||
@ -177,7 +174,7 @@ public WorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLProcess
|
|||||||
config = new YAMLProcessor(this.configFile, true, YAMLFormat.EXTENDED);
|
config = new YAMLProcessor(this.configFile, true, YAMLFormat.EXTENDED);
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
|
|
||||||
logger.info("WorldGuard: Loaded configuration for world '" + worldName + '"');
|
plugin.getLogger().info("Loaded configuration for world '" + worldName + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getBoolean(String node, boolean def) {
|
private boolean getBoolean(String node, boolean def) {
|
||||||
@ -279,7 +276,7 @@ private void loadConfiguration() {
|
|||||||
try {
|
try {
|
||||||
config.load();
|
config.load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
WorldGuardPlugin.logger.severe("Error reading configuration for world " + worldName + ": ");
|
plugin.getLogger().severe("Error reading configuration for world " + worldName + ": ");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +381,7 @@ private void loadConfiguration() {
|
|||||||
CreatureType creature = CreatureType.fromName(creatureName);
|
CreatureType creature = CreatureType.fromName(creatureName);
|
||||||
|
|
||||||
if (creature == null) {
|
if (creature == null) {
|
||||||
logger.warning("WorldGuard: Unknown mob type '" + creatureName + "'");
|
plugin.getLogger().warning("Unknown mob type '" + creatureName + "'");
|
||||||
} else {
|
} else {
|
||||||
blockCreatureSpawn.add(creature);
|
blockCreatureSpawn.add(creature);
|
||||||
}
|
}
|
||||||
@ -424,52 +421,52 @@ private void loadConfiguration() {
|
|||||||
this.blacklist = null;
|
this.blacklist = null;
|
||||||
} else {
|
} else {
|
||||||
this.blacklist = blist;
|
this.blacklist = blist;
|
||||||
logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
|
plugin.getLogger().log(Level.INFO, "Blacklist loaded.");
|
||||||
|
|
||||||
BlacklistLogger blacklistLogger = blist.getLogger();
|
BlacklistLogger blacklistLogger = blist.getLogger();
|
||||||
|
|
||||||
if (logDatabase) {
|
if (logDatabase) {
|
||||||
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table, worldName));
|
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table, worldName, plugin.getLogger()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logConsole) {
|
if (logConsole) {
|
||||||
blacklistLogger.addHandler(new ConsoleLoggerHandler(worldName));
|
blacklistLogger.addHandler(new ConsoleLoggerHandler(worldName, plugin.getLogger()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logFile) {
|
if (logFile) {
|
||||||
FileLoggerHandler handler =
|
FileLoggerHandler handler =
|
||||||
new FileLoggerHandler(logFilePattern, logFileCacheSize, worldName);
|
new FileLoggerHandler(logFilePattern, logFileCacheSize, worldName, plugin.getLogger());
|
||||||
blacklistLogger.addHandler(handler);
|
blacklistLogger.addHandler(handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logger.log(Level.WARNING, "WorldGuard blacklist does not exist.");
|
plugin.getLogger().log(Level.WARNING, "WorldGuard blacklist does not exist.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.log(Level.WARNING, "Could not load WorldGuard blacklist: "
|
plugin.getLogger().log(Level.WARNING, "Could not load WorldGuard blacklist: "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print an overview of settings
|
// Print an overview of settings
|
||||||
if (getBoolean("summary-on-start", true)) {
|
if (getBoolean("summary-on-start", true)) {
|
||||||
logger.log(Level.INFO, blockTNTExplosions
|
plugin.getLogger().log(Level.INFO, blockTNTExplosions
|
||||||
? "WorldGuard: (" + worldName + ") TNT ignition is blocked."
|
? "(" + worldName + ") TNT ignition is blocked."
|
||||||
: "WorldGuard: (" + worldName + ") TNT ignition is PERMITTED.");
|
: "(" + worldName + ") TNT ignition is PERMITTED.");
|
||||||
logger.log(Level.INFO, blockLighter
|
plugin.getLogger().log(Level.INFO, blockLighter
|
||||||
? "WorldGuard: (" + worldName + ") Lighters are blocked."
|
? "(" + worldName + ") Lighters are blocked."
|
||||||
: "WorldGuard: (" + worldName + ") Lighters are PERMITTED.");
|
: "(" + worldName + ") Lighters are PERMITTED.");
|
||||||
logger.log(Level.INFO, preventLavaFire
|
plugin.getLogger().log(Level.INFO, preventLavaFire
|
||||||
? "WorldGuard: (" + worldName + ") Lava fire is blocked."
|
? "(" + worldName + ") Lava fire is blocked."
|
||||||
: "WorldGuard: (" + worldName + ") Lava fire is PERMITTED.");
|
: "(" + worldName + ") Lava fire is PERMITTED.");
|
||||||
|
|
||||||
if (disableFireSpread) {
|
if (disableFireSpread) {
|
||||||
logger.log(Level.INFO, "WorldGuard: (" + worldName + ") All fire spread is disabled.");
|
plugin.getLogger().log(Level.INFO, "(" + worldName + ") All fire spread is disabled.");
|
||||||
} else {
|
} else {
|
||||||
if (disableFireSpreadBlocks.size() > 0) {
|
if (disableFireSpreadBlocks.size() > 0) {
|
||||||
logger.log(Level.INFO, "WorldGuard: (" + worldName
|
plugin.getLogger().log(Level.INFO, "(" + worldName
|
||||||
+ ") Fire spread is limited to "
|
+ ") Fire spread is limited to "
|
||||||
+ disableFireSpreadBlocks.size() + " block types.");
|
+ disableFireSpreadBlocks.size() + " block types.");
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.INFO, "WorldGuard: (" + worldName
|
plugin.getLogger().log(Level.INFO, "(" + worldName
|
||||||
+ ") Fire spread is UNRESTRICTED.");
|
+ ") Fire spread is UNRESTRICTED.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,6 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldGuardBlockListener implements Listener {
|
public class WorldGuardBlockListener implements Listener {
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
|
@ -79,11 +79,6 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldGuardEntityListener implements Listener {
|
public class WorldGuardEntityListener implements Listener {
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
|
@ -75,11 +75,6 @@
|
|||||||
*/
|
*/
|
||||||
public class WorldGuardPlayerListener implements Listener {
|
public class WorldGuardPlayerListener implements Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,7 +247,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (removed > 10) {
|
if (removed > 10) {
|
||||||
logger.info("WG Halt-Act: " + removed + " entities (>10) auto-removed from "
|
plugin.getLogger().info("Halt-Act: " + removed + " entities (>10) auto-removed from "
|
||||||
+ player.getWorld().toString());
|
+ player.getWorld().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
|
import com.sk89q.bukkit.util.CommandsManagerRegistration;
|
||||||
import com.sk89q.minecraft.util.commands.*;
|
import com.sk89q.minecraft.util.commands.*;
|
||||||
import com.sk89q.wepif.PermissionsResolverManager;
|
import com.sk89q.wepif.PermissionsResolverManager;
|
||||||
import com.sk89q.worldguard.util.CommandRegistration;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -62,10 +62,6 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldGuardPlugin extends JavaPlugin {
|
public class WorldGuardPlugin extends JavaPlugin {
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for commands. This automatically handles nested commands,
|
* Manager for commands. This automatically handles nested commands,
|
||||||
@ -116,7 +112,7 @@ public void onEnable() {
|
|||||||
commands.setInjector(new SimpleInjector(this));
|
commands.setInjector(new SimpleInjector(this));
|
||||||
|
|
||||||
// Register command classes
|
// Register command classes
|
||||||
final CommandRegistration reg = new CommandRegistration(this, commands);
|
final CommandsManagerRegistration reg = new CommandsManagerRegistration(this, commands);
|
||||||
reg.register(ToggleCommands.class);
|
reg.register(ToggleCommands.class);
|
||||||
reg.register(ProtectionCommands.class);
|
reg.register(ProtectionCommands.class);
|
||||||
|
|
||||||
@ -185,8 +181,6 @@ public void run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("WorldGuard " + this.getDescription().getVersion() + " enabled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,8 +190,6 @@ public void onDisable() {
|
|||||||
globalRegionManager.unload();
|
globalRegionManager.unload();
|
||||||
configuration.unload();
|
configuration.unload();
|
||||||
this.getServer().getScheduler().cancelTasks(this);
|
this.getServer().getScheduler().cancelTasks(this);
|
||||||
|
|
||||||
logger.info("WorldGuard " + getDescription().getVersion() + " disabled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -693,7 +685,7 @@ public void createDefaultConfiguration(File actual,
|
|||||||
if (copy == null) throw new FileNotFoundException();
|
if (copy == null) throw new FileNotFoundException();
|
||||||
input = file.getInputStream(copy);
|
input = file.getInputStream(copy);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.severe(getDescription().getName() + ": Unable to read default configuration: " + defaultName);
|
getLogger().severe("Unable to read default configuration: " + defaultName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
@ -707,7 +699,7 @@ public void createDefaultConfiguration(File actual,
|
|||||||
output.write(buf, 0, length);
|
output.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("WorldGuard: Default configuration file written: "
|
getLogger().info("Default configuration file written: "
|
||||||
+ actual.getAbsolutePath());
|
+ actual.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -28,12 +28,6 @@
|
|||||||
|
|
||||||
public class WorldGuardVehicleListener implements Listener {
|
public class WorldGuardVehicleListener implements Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,12 +36,6 @@
|
|||||||
|
|
||||||
public class WorldGuardWeatherListener implements Listener {
|
public class WorldGuardWeatherListener implements Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin.
|
* Plugin.
|
||||||
*/
|
*/
|
||||||
|
@ -16,11 +16,6 @@
|
|||||||
|
|
||||||
public class WorldGuardWorldListener implements Listener {
|
public class WorldGuardWorldListener implements Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger for messages.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private WorldGuardPlugin plugin;
|
private WorldGuardPlugin plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +52,7 @@ public void onChunkLoad(ChunkLoadEvent event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (removed > 50) {
|
if (removed > 50) {
|
||||||
logger.info("WG Halt-Act: " + removed + " entities (>50) auto-removed from "
|
plugin.getLogger().info("Halt-Act: " + removed + " entities (>50) auto-removed from "
|
||||||
+ event.getChunk().toString());
|
+ event.getChunk().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,6 @@
|
|||||||
*/
|
*/
|
||||||
public class GlobalRegionManager {
|
public class GlobalRegionManager {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the plugin.
|
* Reference to the plugin.
|
||||||
*/
|
*/
|
||||||
@ -141,12 +139,12 @@ public RegionManager load(World world) {
|
|||||||
try {
|
try {
|
||||||
if (!config.useSqlDatabase) {
|
if (!config.useSqlDatabase) {
|
||||||
file = getPath(name);
|
file = getPath(name);
|
||||||
database = new YAMLDatabase(file);
|
database = new YAMLDatabase(file, plugin.getLogger());
|
||||||
|
|
||||||
// Store the last modification date so we can track changes
|
// Store the last modification date so we can track changes
|
||||||
lastModified.put(name, file.lastModified());
|
lastModified.put(name, file.lastModified());
|
||||||
} else {
|
} else {
|
||||||
database = new MySQLDatabase(config, name);
|
database = new MySQLDatabase(config, name, plugin.getLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a manager
|
// Create a manager
|
||||||
@ -155,22 +153,22 @@ public RegionManager load(World world) {
|
|||||||
managers.put(name, manager);
|
managers.put(name, manager);
|
||||||
manager.load();
|
manager.load();
|
||||||
|
|
||||||
logger.info("WorldGuard: " + manager.getRegions().size()
|
plugin.getLogger().info(manager.getRegions().size()
|
||||||
+ " regions loaded for '" + name + "'");
|
+ " regions loaded for '" + name + "'");
|
||||||
|
|
||||||
return manager;
|
return manager;
|
||||||
} catch (ProtectionDatabaseException e) {
|
} catch (ProtectionDatabaseException e) {
|
||||||
String logStr = "WorldGuard: Failed to load regions from ";
|
String logStr = "Failed to load regions from ";
|
||||||
if (config.useSqlDatabase) {
|
if (config.useSqlDatabase) {
|
||||||
logStr += "SQL Database <" + config.sqlDsn + "> ";
|
logStr += "SQL Database <" + config.sqlDsn + "> ";
|
||||||
} else {
|
} else {
|
||||||
logStr += "file \"" + file + "\" ";
|
logStr += "file \"" + file + "\" ";
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(logStr + " : " + e.getMessage());
|
plugin.getLogger().info(logStr + " : " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("WorldGuard: Error loading regions for world \""
|
plugin.getLogger().info("Error loading regions for world \""
|
||||||
+ name + "\": " + e.toString() + "\n\t" + e.getMessage());
|
+ name + "\": " + e.toString() + "\n\t" + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -48,12 +48,12 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class CSVDatabase extends AbstractProtectionDatabase {
|
public class CSVDatabase extends AbstractProtectionDatabase {
|
||||||
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* References the CSV file.
|
* References the CSV file.
|
||||||
*/
|
*/
|
||||||
private File file;
|
private final File file;
|
||||||
/**
|
/**
|
||||||
* Holds the list of regions.
|
* Holds the list of regions.
|
||||||
*/
|
*/
|
||||||
@ -65,8 +65,9 @@ public class CSVDatabase extends AbstractProtectionDatabase {
|
|||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
public CSVDatabase(File file) {
|
public CSVDatabase(File file, Logger logger) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,8 +48,7 @@
|
|||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||||
|
|
||||||
public class MySQLDatabase extends AbstractProtectionDatabase {
|
public class MySQLDatabase extends AbstractProtectionDatabase {
|
||||||
|
private final Logger logger;
|
||||||
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private Map<String, ProtectedRegion> regions;
|
private Map<String, ProtectedRegion> regions;
|
||||||
|
|
||||||
@ -58,15 +57,16 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
|
|||||||
private Map<String, ProtectedRegion> globalRegions;
|
private Map<String, ProtectedRegion> globalRegions;
|
||||||
private Map<ProtectedRegion, String> parentSets;
|
private Map<ProtectedRegion, String> parentSets;
|
||||||
|
|
||||||
private ConfigurationManager config;
|
private final ConfigurationManager config;
|
||||||
|
|
||||||
private Connection conn;
|
private Connection conn;
|
||||||
private String world;
|
private String world;
|
||||||
private int worldDbId = -1; // The database will never have an id of -1;
|
private int worldDbId = -1; // The database will never have an id of -1;
|
||||||
|
|
||||||
public MySQLDatabase(ConfigurationManager config, String world) throws ProtectionDatabaseException {
|
public MySQLDatabase(ConfigurationManager config, String world, Logger logger) throws ProtectionDatabaseException {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connect();
|
connect();
|
||||||
@ -264,6 +264,7 @@ private void loadGlobal() {
|
|||||||
Throwable t = ex.getCause();
|
Throwable t = ex.getCause();
|
||||||
while (t != null) {
|
while (t != null) {
|
||||||
logger.warning("\t\tCause: " + t.getMessage());
|
logger.warning("\t\tCause: " + t.getMessage());
|
||||||
|
t = t.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +337,7 @@ private void loadCuboid() {
|
|||||||
Throwable t = ex.getCause();
|
Throwable t = ex.getCause();
|
||||||
while (t != null) {
|
while (t != null) {
|
||||||
logger.warning("\t\tCause: " + t.getMessage());
|
logger.warning("\t\tCause: " + t.getMessage());
|
||||||
|
t = t.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,6 +411,7 @@ private void loadPoly2d() {
|
|||||||
Throwable t = ex.getCause();
|
Throwable t = ex.getCause();
|
||||||
while (t != null) {
|
while (t != null) {
|
||||||
logger.warning("\t\tCause: " + t.getMessage());
|
logger.warning("\t\tCause: " + t.getMessage());
|
||||||
|
t = t.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@
|
|||||||
|
|
||||||
public class YAMLDatabase extends AbstractProtectionDatabase {
|
public class YAMLDatabase extends AbstractProtectionDatabase {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
|
||||||
|
|
||||||
private YAMLProcessor config;
|
private YAMLProcessor config;
|
||||||
private Map<String, ProtectedRegion> regions;
|
private Map<String, ProtectedRegion> regions;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
public YAMLDatabase(File file) throws ProtectionDatabaseException, FileNotFoundException {
|
public YAMLDatabase(File file, Logger logger) throws ProtectionDatabaseException, FileNotFoundException {
|
||||||
|
this.logger = logger;
|
||||||
if (!file.exists()) { // shouldn't be necessary, but check anyways
|
if (!file.exists()) { // shouldn't be necessary, but check anyways
|
||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
@ -72,7 +72,7 @@ protected Set<String> getWorldsFromOld() {
|
|||||||
protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException {
|
protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException {
|
||||||
ProtectionDatabase oldDatabase;
|
ProtectionDatabase oldDatabase;
|
||||||
try {
|
try {
|
||||||
oldDatabase = new MySQLDatabase(plugin.getGlobalStateManager(), world);
|
oldDatabase = new MySQLDatabase(plugin.getGlobalStateManager(), world, plugin.getLogger());
|
||||||
oldDatabase.load();
|
oldDatabase.load();
|
||||||
} catch (ProtectionDatabaseException e) {
|
} catch (ProtectionDatabaseException e) {
|
||||||
throw new MigrationException((Exception) e);
|
throw new MigrationException((Exception) e);
|
||||||
@ -87,7 +87,7 @@ protected ProtectionDatabase getNewWorldStorage(String world) throws MigrationEx
|
|||||||
File file = new File(plugin.getDataFolder(),
|
File file = new File(plugin.getDataFolder(),
|
||||||
"worlds" + File.separator + world + File.separator + "regions.yml");
|
"worlds" + File.separator + world + File.separator + "regions.yml");
|
||||||
|
|
||||||
return new YAMLDatabase(file);
|
return new YAMLDatabase(file, plugin.getLogger());
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new MigrationException((Exception) e);
|
throw new MigrationException((Exception) e);
|
||||||
} catch (ProtectionDatabaseException e) {
|
} catch (ProtectionDatabaseException e) {
|
||||||
|
@ -63,7 +63,7 @@ protected Set<String> getWorldsFromOld() {
|
|||||||
protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException {
|
protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) throws MigrationException {
|
||||||
ProtectionDatabase oldDatabase;
|
ProtectionDatabase oldDatabase;
|
||||||
try {
|
try {
|
||||||
oldDatabase = new YAMLDatabase(this.regionYamlFiles.get(world));
|
oldDatabase = new YAMLDatabase(this.regionYamlFiles.get(world), plugin.getLogger());
|
||||||
oldDatabase.load();
|
oldDatabase.load();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new MigrationException((Exception) e);
|
throw new MigrationException((Exception) e);
|
||||||
@ -77,7 +77,7 @@ protected Map<String, ProtectedRegion> getRegionsForWorldFromOld(String world) t
|
|||||||
@Override
|
@Override
|
||||||
protected ProtectionDatabase getNewWorldStorage(String world) throws MigrationException {
|
protected ProtectionDatabase getNewWorldStorage(String world) throws MigrationException {
|
||||||
try {
|
try {
|
||||||
return new MySQLDatabase(plugin.getGlobalStateManager(), world);
|
return new MySQLDatabase(plugin.getGlobalStateManager(), world, plugin.getLogger());
|
||||||
} catch (ProtectionDatabaseException e) {
|
} catch (ProtectionDatabaseException e) {
|
||||||
throw new MigrationException((Exception) e);
|
throw new MigrationException((Exception) e);
|
||||||
}
|
}
|
||||||
|
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* WorldGuard
|
|
||||||
* Copyright (C) 2011 sk89q <http://www.sk89q.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sk89q.worldguard.util;
|
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A helper class for dynamic command registration, including support for fallback methods.
|
|
||||||
*/
|
|
||||||
public class CommandRegistration {
|
|
||||||
private final Plugin plugin;
|
|
||||||
private final CommandsManager<?> commands;
|
|
||||||
private CommandMap fallbackCommands;
|
|
||||||
|
|
||||||
public CommandRegistration(Plugin plugin, CommandsManager<?> commands) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.commands = commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean register(Class<?> clazz) {
|
|
||||||
List<Command> registered = commands.registerAndReturn(clazz);
|
|
||||||
CommandMap commandMap = getCommandMap();
|
|
||||||
if (registered == null || commandMap == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (Command command : registered) {
|
|
||||||
commandMap.register(plugin.getDescription().getName(), new DynamicPluginCommand(command, plugin));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandMap getCommandMap() {
|
|
||||||
CommandMap commandMap = ReflectionUtil.getField(plugin.getServer().getPluginManager(), "commandMap");
|
|
||||||
if (commandMap == null) {
|
|
||||||
if (fallbackCommands != null) {
|
|
||||||
commandMap = fallbackCommands;
|
|
||||||
} else {
|
|
||||||
Bukkit.getServer().getLogger().warning(plugin.getDescription().getName() +
|
|
||||||
": Could not retrieve server CommandMap! Please report to http://redmine.sk89q.com");
|
|
||||||
fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return commandMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean unregisterCommands() {
|
|
||||||
CommandMap commandMap = getCommandMap();
|
|
||||||
List<String> toRemove = new ArrayList<String>();
|
|
||||||
Map<String, org.bukkit.command.Command> knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
|
|
||||||
Set<String> aliases = ReflectionUtil.getField(commandMap, "aliases");
|
|
||||||
if (knownCommands == null || aliases == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (Iterator<org.bukkit.command.Command> i = knownCommands.values().iterator(); i.hasNext();) {
|
|
||||||
org.bukkit.command.Command cmd = i.next();
|
|
||||||
if (cmd instanceof DynamicPluginCommand && ((DynamicPluginCommand) cmd).getPlugin().equals(plugin)) {
|
|
||||||
i.remove();
|
|
||||||
for (String alias : cmd.getAliases()) {
|
|
||||||
org.bukkit.command.Command aliasCmd = knownCommands.get(alias);
|
|
||||||
if (cmd.equals(aliasCmd)) {
|
|
||||||
aliases.remove(alias);
|
|
||||||
toRemove.add(alias);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String string : toRemove) {
|
|
||||||
knownCommands.remove(string);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DynamicPluginCommand extends org.bukkit.command.Command {
|
|
||||||
|
|
||||||
protected final Plugin plugin;
|
|
||||||
|
|
||||||
public DynamicPluginCommand(Command command, Plugin plugin) {
|
|
||||||
super(command.aliases()[0], command.desc(), command.usage(), Arrays.asList(command.aliases()));
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
|
||||||
return plugin.onCommand(sender, this, label, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FallbackRegistrationListener implements Listener {
|
|
||||||
|
|
||||||
private final CommandMap commandRegistration;
|
|
||||||
|
|
||||||
public FallbackRegistrationListener(CommandMap commandRegistration) {
|
|
||||||
this.commandRegistration = commandRegistration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (commandRegistration.dispatch(event.getPlayer(), event.getMessage())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user