Move Listeners

This commit is contained in:
Eric Stokes 2011-07-29 18:09:48 -06:00
parent 48f9226d27
commit f07be132f8
7 changed files with 81 additions and 10 deletions

View File

@ -53,6 +53,9 @@ import com.onarandombox.MultiverseCore.commands.WhoCommand;
import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration; import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration;
import com.onarandombox.MultiverseCore.configuration.MVConfigMigrator; import com.onarandombox.MultiverseCore.configuration.MVConfigMigrator;
import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator; import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.utils.DebugLog; import com.onarandombox.utils.DebugLog;
import com.onarandombox.utils.DestinationFactory; import com.onarandombox.utils.DestinationFactory;
import com.onarandombox.utils.ExactDestination; import com.onarandombox.utils.ExactDestination;

View File

@ -13,6 +13,9 @@ public class DefaultConfiguration {
public DefaultConfiguration(File folder, String name, MVConfigMigrator migrator) { public DefaultConfiguration(File folder, String name, MVConfigMigrator migrator) {
File actual = new File(folder, name); File actual = new File(folder, name);
if(actual.exists() && migrator.createdDefaults.contains(name)) {
actual.delete();
}
// If defaults have been created, and we're being called again, we should try to migrate // If defaults have been created, and we're being called again, we should try to migrate
if (!actual.exists() && !migrator.migrate(name, folder)) { if (!actual.exists() && !migrator.migrate(name, folder)) {
@ -28,8 +31,8 @@ public class DefaultConfiguration {
while ((length = input.read(buf)) > 0) { while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length); output.write(buf, 0, length);
} }
migrator.createdDefaults.add(name);
// MultiverseCore.log.info(MultiverseCore.logPrefix + "Default config file written: " + name);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {

View File

@ -12,7 +12,7 @@ import org.bukkit.util.config.Configuration;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
public abstract class MVConfigMigrator { public abstract class MVConfigMigrator {
public List<String> createdDefaults = new ArrayList<String>();
public abstract boolean migrate(String name, File folder); public abstract boolean migrate(String name, File folder);
protected final void migrateListItem(Configuration newConfig, Configuration oldConfig, String key, String oldProperty, String newProperty) { protected final void migrateListItem(Configuration newConfig, Configuration oldConfig, String key, String oldProperty, String newProperty) {
@ -27,15 +27,11 @@ public abstract class MVConfigMigrator {
protected final File detectMultiverseFolders(File folder, MultiverseCore core) { protected final File detectMultiverseFolders(File folder, MultiverseCore core) {
File oldFolder = null; File oldFolder = null;
core.log(Level.INFO, "Starting Multiverse Configuration Migrator(MVCM)!");
// They still have MV 1 installed! Good! // They still have MV 1 installed! Good!
if (core.getServer().getPluginManager().getPlugin("MultiVerse") != null) { if (core.getServer().getPluginManager().getPlugin("MultiVerse") != null) {
core.log(Level.INFO, "Found MultiVerse 1. Starting Config Migration..."); core.log(Level.INFO, "Found MultiVerse 1. Starting Config Migration...");
Plugin plugin = core.getServer().getPluginManager().getPlugin("MultiVerse"); Plugin plugin = core.getServer().getPluginManager().getPlugin("MultiVerse");
// We found MV1, but it's enabled, get the data folder, then disable it!
if (!core.getServer().getPluginManager().isPluginEnabled("MultiVerse")) {
core.getServer().getPluginManager().disablePlugin(plugin);
}
oldFolder = plugin.getDataFolder(); oldFolder = plugin.getDataFolder();
} else { } else {
// They didn't have MV 1 enabled... let's try and find the folder... // They didn't have MV 1 enabled... let's try and find the folder...

View File

@ -1,10 +1,12 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import com.onarandombox.MultiverseCore.MultiverseCore;
//import org.bukkit.event.block.BlockRightClickEvent; //import org.bukkit.event.block.BlockRightClickEvent;
public class MVBlockListener extends BlockListener { public class MVBlockListener extends BlockListener {

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore.listeners;
import java.util.List; import java.util.List;
@ -19,6 +19,9 @@ import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
//import org.bukkit.event.entity.ExplosionPrimedEvent; //import org.bukkit.event.entity.ExplosionPrimedEvent;
public class MVEntityListener extends EntityListener { public class MVEntityListener extends EntityListener {

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -11,6 +11,9 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import com.fernferret.allpay.GenericBank; import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.MVTeleport;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
public class MVPlayerListener extends PlayerListener { public class MVPlayerListener extends PlayerListener {

View File

@ -0,0 +1,61 @@
package com.onarandombox.MultiverseCore.listeners;
import java.util.Arrays;
import java.util.logging.Level;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import com.fernferret.allpay.AllPay;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class MVPluginListener extends ServerListener {
MultiverseCore plugin;
public MVPluginListener(MultiverseCore plugin) {
this.plugin = plugin;
}
/**
* Keep an eye out for Plugins which we can utilize.
*/
@Override
public void onPluginEnable(PluginEnableEvent event) {
/**
* Check to see if Permissions was just enabled
*/
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
this.plugin.ph.setPermissions(((Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler());
this.plugin.log(Level.INFO, "- Attached to Permissions");
}
// Let AllPay handle all econ plugin loadings, only go for econ plugins we support
if (Arrays.asList(AllPay.validEconPlugins).contains(event.getPlugin().getDescription().getName())) {
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
}
if (event.getPlugin().getDescription().getName().equals("MultiVerse")) {
if (event.getPlugin().isEnabled()) {
this.plugin.getServer().getPluginManager().disablePlugin(event.getPlugin());
this.plugin.log(Level.WARNING, "I just disabled the old version of Multiverse for you. You should remove the JAR now, your configs have been migrated.");
}
}
}
/**
* We'll check if any of the plugins we rely on decide to Disable themselves.
*/
@Override
public void onPluginDisable(PluginDisableEvent event) {
/**
* Check to see if Permissions just disabled.
*/
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
this.plugin.log(Level.INFO, "Permissions disabled");
this.plugin.ph.setPermissions(null);
}
// TODO: Disable econ when it disables.
}
}