Updated to b602

Minor Changes - Removed Static from some variables etc.
Added Custom seed to Worlds.
This commit is contained in:
Rigby 2011-04-01 01:38:17 +01:00
parent 85b219282e
commit a9103d1ba9
7 changed files with 104 additions and 130 deletions

View File

@ -53,7 +53,7 @@ public class MVEntityListener extends EntityListener {
Entity defender = event.getEntity();
World w = defender.getWorld();
if (!(MultiverseCore.configWorlds.getBoolean("worlds." + w.getName() + ".enablehealth", true))) {
if (!(plugin.configWorlds.getBoolean("worlds." + w.getName() + ".enablehealth", true))) {
event.setCancelled(true);
return;
}
@ -153,7 +153,7 @@ public class MVEntityListener extends EntityListener {
int count = 0;
for (Entity entity : entities) {
if (entity instanceof Ghast) {
if (count >= MultiverseCore.configMV.getInt("ghastlimit", 50)) {
if (count >= plugin.configMV.getInt("ghastlimit", 50)) {
event.setCancelled(true);
return;
}

View File

@ -3,10 +3,12 @@ package com.onarandombox.MultiverseCore;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class MVPlayerListener extends PlayerListener {
@ -16,7 +18,8 @@ public class MVPlayerListener extends PlayerListener {
this.plugin = plugin;
}
public void onPlayerTeleport(PlayerMoveEvent event) {
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
// MultiVerseCore.debugMsg(event.getPlayer().getName() + " just tried to Teleport");
// event.setCancelled(true);
// Entity entity = event.getPlayer().;
@ -50,11 +53,13 @@ public class MVPlayerListener extends PlayerListener {
}
public void onPlayerJoin(PlayerEvent event) {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
}
public void onPlayerQuit(PlayerEvent event) {
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
}
}

View File

@ -1,5 +1,9 @@
package com.onarandombox.MultiverseCore;
import java.util.logging.Level;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.PluginEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
@ -18,14 +22,14 @@ public class MVPluginListener extends ServerListener {
/**
* Keep an eye out for Plugins which we can utilize.
*/
public void onPluginEnabled(PluginEvent event) {
public void onPluginEnable(PluginEnableEvent event) {
/**
* Check to see if Permissions was just enabled, we only wan't to perform the following if GroupManager is not found.
*/
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
MultiverseCore.Permissions = ((Permissions) plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler();
// MultiverseCore.log.info(MultiverseCore.logPrefix + "- Found Permissions");
plugin.log(Level.INFO, "- Attached to Permissions");
}
/**
@ -37,7 +41,6 @@ public class MVPluginListener extends ServerListener {
if (iConomy != null) {
if (iConomy.isEnabled()) {
MultiverseCore.iConomy = (iConomy) iConomy;
// MultiverseCore.log.info(MultiverseCore.logPrefix + "- Found iConomy");
}
}
}
@ -46,13 +49,12 @@ public class MVPluginListener extends ServerListener {
/**
* We'll check if any of the plugins we rely on decide to Disable themselves.
*/
public void onPluginDisabled(PluginEvent event) {
public void onPluginDisable(PluginDisableEvent event) {
/**
* Check to see if Permissions just disabled.
*/
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
MultiverseCore.Permissions = null;
// MultiverseCore.log.info(MultiverseCore.logPrefix + "- Permissions has been Disabled");
}
/**
@ -60,7 +62,6 @@ public class MVPluginListener extends ServerListener {
*/
if (MultiverseCore.getiConomy() != null) {
MultiverseCore.iConomy = null;
// MultiverseCore.log.info(MultiverseCore.logPrefix + "- iConom has been Disabled");
}
}

View File

@ -15,7 +15,8 @@ public class MVWorld {
public World world; // The World Instance.
public Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL
public Long seed;
public String name; // The Worlds Name, EG its folder name.
public String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes.
@ -36,13 +37,14 @@ public class MVWorld {
public Double compression; // How stretched/compressed distances are
public MVWorld(World world, Configuration config, MultiverseCore instance) {
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed) {
this.config = config;
this.plugin = instance;
this.world = world;
this.name = world.getName();
this.environment = world.getEnvironment();
this.seed = seed;
this.alias = config.getString("worlds." + this.name + ".alias", "");
this.pvp = config.getBoolean("worlds." + this.name + ".pvp", true);

View File

@ -9,7 +9,6 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.Command;
@ -18,7 +17,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
@ -44,29 +42,23 @@ import com.onarandombox.utils.UpdateChecker;
public class MultiverseCore extends JavaPlugin {
// Setup our Map for our Commands using the CommandHandler.
private Map<String, MVCommandHandler> commands = new HashMap<String, MVCommandHandler>();
// Variable to state whether we are displaying Debug Messages or not.
public static boolean debug = true;
// Setup a variable to hold our DataFolder which will house everything to do with Multiverse
public static final File dataFolder = new File("plugins" + File.separator + "Multiverse");
// Useless stuff to keep us going.
private static final Logger log = Logger.getLogger("Minecraft");
private static DebugLog debugLog;
public static final String logPrefix = "[MultiVerse-Core] ";
public static Plugin instance;
public static Server server;
public static PluginDescriptionFile description;
// Debug Mode
private boolean debug;
// Setup a variable to hold our DataFolder which will house everything to do with MultiVerse
// Using this instead of getDataFolder(), allows all modules to use the same direectory.
public static final File dataFolder = new File("plugins" + File.separator + "Multiverse");
// Setup our Map for our Commands using the CommandHandler.
private Map<String, MVCommandHandler> commands = new HashMap<String, MVCommandHandler>();
// Messaging
private Messaging messaging = new Messaging();
// MultiVerse Permissions Handler
// Multiverse Permissions Handler
public MVPermissions ph = new MVPermissions(this);
// Permissions Handler
@ -77,8 +69,8 @@ public class MultiverseCore extends JavaPlugin {
public static boolean useiConomy = false;
// Configurations
public static Configuration configMV = null;
public static Configuration configWorlds = null;
public Configuration configMV = null;
public Configuration configWorlds = null;
// Setup the block/player/entity listener.
private MVPlayerListener playerListener = new MVPlayerListener(this);;
@ -100,16 +92,10 @@ public class MultiverseCore extends JavaPlugin {
debugLog = new DebugLog("Multiverse", dataFolder + File.separator + "debug.log");
}
/**
* What happens when the plugin gets around to being enabled...
*/
@Override
public void onEnable() {
// Create the Plugin Data folder.
dataFolder.mkdir();
// Output a little snippet to show it's enabled.
log.info(logPrefix + "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
log(Level.INFO, "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
// Setup & Load our Configuration files.
loadConfigs();
@ -138,20 +124,19 @@ public class MultiverseCore extends JavaPlugin {
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Highest, this); // Low so it acts above any other.
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Highest, this); // Cancel Teleports if needed.
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this); // To create the Player Session
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); // To remove Player Sessions
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); // To prevent Blocks being destroyed.
// pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); // To prevent Blocks being placed.
// pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning.
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
// pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, pluginListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginListener, Priority.Monitor, this); // Monitor for Permissions Plugin etc.
// pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); // To prevent Blocks being destroyed.
// pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); // To prevent Blocks being placed.
// pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
// pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
}
/**
@ -163,7 +148,7 @@ public class MultiverseCore extends JavaPlugin {
if (MultiverseCore.Permissions == null) {
if (p != null && p.isEnabled()) {
MultiverseCore.Permissions = ((Permissions) p).getHandler();
MultiverseCore.log.info(logPrefix + "- Attached to Permissions");
log(Level.INFO, "- Attached to Permissions");
}
}
}
@ -187,7 +172,7 @@ public class MultiverseCore extends JavaPlugin {
public void loadConfigs() {
// Call the defaultConfiguration class to create the config files if they don't already exist.
new DefaultConfiguration(dataFolder, "config.yml");
new DefaultConfiguration(dataFolder, "worlds.yml", "worlds:");
new DefaultConfiguration(dataFolder, "worlds.yml");
// Now grab the Configuration Files.
configMV = new Configuration(new File(dataFolder, "config.yml"));
@ -196,20 +181,20 @@ public class MultiverseCore extends JavaPlugin {
// Now attempt to Load the configurations.
try {
configMV.load();
log.info(logPrefix + "- MultiVerse Config -- Loaded");
log(Level.INFO, "- Multiverse Config -- Loaded");
} catch (Exception e) {
log.info(MultiverseCore.logPrefix + "- Failed to load config.yml");
log(Level.INFO, "- Failed to load config.yml");
}
try {
configWorlds.load();
log.info(logPrefix + "- World Config -- Loaded");
log(Level.INFO, "- World Config -- Loaded");
} catch (Exception e) {
log.info(MultiverseCore.logPrefix + "- Failed to load worlds.yml");
log(Level.INFO, "- Failed to load worlds.yml");
}
// Setup the Debug option, we'll default to false because this option will not be in the default config.
MultiverseCore.debug = configMV.getBoolean("debug", false);
this.debug = configMV.getBoolean("debug", false);
}
/**
@ -261,33 +246,69 @@ public class MultiverseCore extends JavaPlugin {
public void loadWorlds() {
// Basic Counter to count how many Worlds we are loading.
int count = 0;
List<String> worldKeys = MultiverseCore.configWorlds.getKeys("worlds"); // Grab all the Worlds from the Config.
// Grab all the Worlds from the Config.
List<String> worldKeys = configWorlds.getKeys("worlds");
if (worldKeys != null) {
// Check that the list actually contains any data.
if (worldKeys != null && worldKeys.size() > 0) {
for (String worldKey : worldKeys) {
// If this World already exists within the HashMap then we don't need to process it.
// Check if the World is already loaded within the Plugin.
if (worlds.containsKey(worldKey)) {
continue;
}
String wEnvironment = MultiverseCore.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
// Grab the initial values from the config file.
String environment = configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
String seedString = configWorlds.getString("worlds." + worldKey + ".seed", null);
Long seed = null;
// Work out the Environment
Environment env;
if (wEnvironment.equalsIgnoreCase("NETHER")) // Check if the selected Environment is NETHER, otherwise we just default to NORMAL.
if (environment.equalsIgnoreCase("NETHER")) { // Check if the selected Environment is NETHER, otherwise we just default to NORMAL.
env = Environment.NETHER;
else
} else {
env = Environment.NORMAL;
log.info(logPrefix + "Loading World & Settings - '" + worldKey + "' - " + wEnvironment); // Output to the Log that wea re loading a world, specify the name and environment type.
World world = getServer().createWorld(worldKey, env);
worlds.put(worldKey, new MVWorld(world, MultiverseCore.configWorlds, this)); // Place the World into the HashMap.
count++; // Increment the World Count.
}
// Output to the Log that wea re loading a world, specify the name and environment type.
log(Level.INFO, "Loading World & Settings - '" + worldKey + "' - " + environment);
// If a seed was given we need to parse it to a Long Format.
if (seedString.length() > 0) {
try {
seed = Long.parseLong(seedString);
} catch (NumberFormatException numberformatexception) {
seed = (long) seedString.hashCode();
}
}
// If we don't have a seed then add a standard World, else add the world with the Seed.
if (seed == null) {
addWorld(worldKey, env, null);
} else {
addWorld(worldKey, env, seed);
}
// Increment the World Count.
count++;
}
}
log.info(logPrefix + count + " - World(s) loaded.");
// Simple Output to the Console to show how many Worlds were loaded.
log(Level.INFO, count + " - World(s) loaded.");
}
/**
* Add a new World to the Multiverse Setup.
* @param name World Name
* @param environment Environment Type
*/
public void addWorld(String name, Environment environment, Long seed) {
if (seed != null) {
World world = getServer().createWorld(name, environment, seed);
worlds.put(name, new MVWorld(world, configWorlds, this, seed)); // Place the World into the HashMap.
} else {
World world = getServer().createWorld(name, environment);
worlds.put(name, new MVWorld(world, configWorlds, this, null)); // Place the World into the HashMap.
}
}
public void addWorld(String name, Environment environment) {
addWorld(name, environment, null);
}
/**
@ -296,7 +317,7 @@ public class MultiverseCore extends JavaPlugin {
@Override
public void onDisable() {
MultiverseCore.Permissions = null;
log.info(logPrefix + "- Disabled");
log(Level.INFO, "- Disabled");
}
/**
@ -308,7 +329,7 @@ public class MultiverseCore extends JavaPlugin {
if (playerSessions.containsKey(player.getName())) {
return playerSessions.get(player.getName());
} else {
playerSessions.put(player.getName(), new MVPlayerSession(player, MultiverseCore.configMV, this));
playerSessions.put(player.getName(), new MVPlayerSession(player, configMV, this));
return playerSessions.get(player.getName());
}
}
@ -373,7 +394,7 @@ public class MultiverseCore extends JavaPlugin {
* @param msg
*/
public void debugLog(Level level, String msg) {
if (MultiverseCore.debug) {
if (this.debug) {
log.log(level, "[Debug] " + msg);
}
debugLog.log(level, "[Debug] " + msg);

View File

@ -17,7 +17,7 @@ public class MVSpawn extends MVCommandHandler {
// TODO: Permissions
if (sender instanceof Player) {
Player p = (Player) sender;
p.teleportTo(p.getWorld().getSpawnLocation());
p.teleport(p.getWorld().getSpawnLocation());
} else {
sender.sendMessage("Must be used in game.");
}

View File

@ -1,14 +1,8 @@
package com.onarandombox.MultiverseCore.configuration;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* https://github.com/Nijikokun/iConomy3/blob/master/com/nijiko/coelho/iConomy/iConomy.java
@ -17,10 +11,6 @@ import java.io.InputStreamReader;
public class DefaultConfiguration {
public DefaultConfiguration(File folder, String name) {
new DefaultConfiguration(folder, name, null);
}
public DefaultConfiguration(File folder, String name, String contains) {
File actual = new File(folder, name);
if (!actual.exists()) {
@ -55,52 +45,7 @@ public class DefaultConfiguration {
}
}
}
} else {
if (contains == null) {
return;
}
boolean found = false;
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(actual);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
if (strLine.equals(contains)) {
found = true;
break;
}
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: Could not verify the contents of " + actual.toString());
System.err.println("Error: " + e.getMessage());
return;
}
if (!found) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(actual, true));
out.newLine();
out.write(contains);
out.close();
} catch (Exception e) {
System.err.println("Error: Could not write default node to " + actual.toString());
System.err.println("Error: " + e.getMessage());
return;
}
}
}
}
}