Refactoring... Cleaning Up... Adding some Commands... Fixing up some

mistakes etc etc etc.
This commit is contained in:
Simon Rigby 2011-03-07 09:14:02 +00:00
parent bdf3d70bbf
commit 764b050baa
13 changed files with 260 additions and 65 deletions

View File

@ -63,8 +63,9 @@ public class MVEntityListener extends EntityListener {
}
if (defender instanceof Player && attacker instanceof Player){
Player player = (Player) attacker;
if (!(this.plugin.worlds.get(w.getName()).pvp)) {
this.plugin.playerSessions.get(((Player) attacker)).message(ChatColor.RED + "PVP is disabled in this World.");
this.plugin.getPlayerSession(player).message(ChatColor.RED + "PVP is disabled in this World.");
event.setCancelled(true);
return;
}

View File

@ -14,6 +14,11 @@ public class MVPlayerListener extends PlayerListener {
this.plugin = plugin;
}
public void onPlayerTeleport(PlayerMoveEvent event){
//MultiVerseCore.debugMsg(event.getPlayer().getName() + " just tried to Teleport");
//event.setCancelled(true);
}
public void onPlayerMove(PlayerMoveEvent event){
}

View File

@ -50,8 +50,6 @@ public class MVTeleport {
z = location.getZ() / (srcComp != 0 ? srcComp : 1) * trgComp + 0.5;
}
world.loadChunk(world.getChunkAt(new Location(world,x,y,z)));
if (y < 1 && world.getEnvironment() == Environment.NORMAL)
y = 1;
@ -77,7 +75,9 @@ public class MVTeleport {
if (aux == -1) return null;
MultiVerseCore.log.info("Target location (safe): " + x + ", " + aux + ", " + z);
world.loadChunk(world.getChunkAt(new Location(world,x,aux,z))); // Try load the destination to chunk first before teleporting.
return new Location(world, x, aux, z, location.getYaw(),location.getPitch());
}

View File

@ -9,7 +9,7 @@ import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.util.config.Configuration;
import com.onarandombox.utils.stringLocation;
import com.onarandombox.utils.LocationManipulation;
@SuppressWarnings("unused")
public class MVWorld {

View File

@ -31,7 +31,7 @@ import org.bukkit.event.Event.Priority;
//import com.nijiko.permissions.PermissionHandler;
import com.onarandombox.MultiVerseCore.commands.*;
import com.onarandombox.MultiVerseCore.configuration.defaultConfiguration;
import com.onarandombox.MultiVerseCore.configuration.DefaultConfiguration;
@SuppressWarnings("unused")
public class MultiVerseCore extends JavaPlugin {
@ -95,8 +95,8 @@ public class MultiVerseCore extends JavaPlugin {
}*/
// 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");
new DefaultConfiguration(dataFolder, "config.yml");
new DefaultConfiguration(dataFolder, "worlds.yml");
// Now grab the Configuration Files.
configMV = new Configuration(new File(dataFolder, "config.yml"));
@ -109,20 +109,21 @@ public class MultiVerseCore extends JavaPlugin {
// Setup all the Events the plugin needs to Monitor.
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Low, this); // Low so it acts above any other.
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.High, this); // To Add World Prefixing to Chat.
pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this); // Respawn Players at the right point.
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Normal, this); // Cancel Teleports if needed.
//pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.High, this); // To Add World Prefixing to Chat. -- Separate Plugin, maybe...
//pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this); // Respawn Players at the right point. -- No need to handle it anymore with setSpawnLocation()
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.
pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this);
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);
pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this);
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.Normal, this); // Monitor for Permissions Plugin etc.
@ -169,6 +170,7 @@ public class MultiVerseCore extends JavaPlugin {
commands.put("mvsetspawn", new MVSetSpawn(this));
commands.put("mvspawn", new MVSpawn(this));
commands.put("mvcoord", new MVCoord(this));
commands.put("mvwho", new MVWho(this));
}
/**
@ -248,7 +250,7 @@ public class MultiVerseCore extends JavaPlugin {
MVCommandHandler handler = commands.get(command.getName().toLowerCase());
if (handler != null) {
if (handler!=null) {
return handler.perform(sender, args);
} else {
return false;
@ -258,6 +260,9 @@ public class MultiVerseCore extends JavaPlugin {
/**
* Basic Debug Output function, if we've enabled debugging we'll output more information.
*/
public static void debugMsg(String msg){
debugMsg(msg,null);
}
public static void debugMsg(String msg, Player p){
if(debug){
log.info(msg);
@ -266,8 +271,4 @@ public class MultiVerseCore extends JavaPlugin {
}
}
}
public static void debugMsg(String msg){
debugMsg(msg,null);
}
}

View File

@ -1,12 +1,17 @@
package com.onarandombox.MultiVerseCore.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.onarandombox.MultiVerseCore.MVCommandHandler;
import com.onarandombox.MultiVerseCore.MultiVerseCore;
import com.onarandombox.utils.LocationManipulation;
public class MVCoord extends MVCommandHandler {
private LocationManipulation locMan = new LocationManipulation();
public MVCoord(MultiVerseCore plugin) {
super(plugin);
// TODO Auto-generated constructor stub
@ -14,8 +19,16 @@ public class MVCoord extends MVCommandHandler {
@Override
public boolean perform(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return false;
// TODO: Add Permissions
if(sender instanceof Player){
Player p = (Player) sender;
p.sendMessage(ChatColor.RED + "World: " + ChatColor.WHITE + p.getWorld().getName());
p.sendMessage(ChatColor.RED + "Compression: " + ChatColor.WHITE + plugin.worlds.get(p.getWorld().getName()).compression);
p.sendMessage(ChatColor.RED + "Coordinates: " + ChatColor.WHITE + locMan.strCoords(p.getLocation()));
p.sendMessage(ChatColor.RED + "Direction: " + ChatColor.WHITE + locMan.getDirection(p.getLocation()));
}
return true;
}
}

View File

@ -1,5 +1,10 @@
package com.onarandombox.MultiVerseCore.commands;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import com.onarandombox.MultiVerseCore.MVCommandHandler;
@ -13,7 +18,34 @@ public class MVCreate extends MVCommandHandler {
@Override
public boolean perform(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
if (args.length != 2) {
sender.sendMessage("Not enough parameters to create a new world");
sender.sendMessage(ChatColor.RED + "/mvcreate WORLDNAME ENVIRONMENT - Create a new World.");
sender.sendMessage(ChatColor.RED + "Example - /mvcreate hellworld nether");
return true;
}
if (new File(args[0].toString()).exists()) {
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
return true;
}
String name = args[0].toString();
String env = args[1].toString();
Environment environment = null;
if (env.equalsIgnoreCase("NETHER"))
environment = Environment.NETHER;
if (env.equalsIgnoreCase("NORMAL"))
environment = Environment.NORMAL;
if (environment == null) {
sender.sendMessage(ChatColor.RED
+ "Environment type does not exist!");
sender.sendMessage(ChatColor.RED
+ "Only Normal & Nether exist as Environments");
return false;
}
return false;
}

View File

@ -0,0 +1,63 @@
package com.onarandombox.MultiVerseCore.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.onarandombox.MultiVerseCore.MVCommandHandler;
import com.onarandombox.MultiVerseCore.MultiVerseCore;
public class MVWho extends MVCommandHandler {
public MVWho(MultiVerseCore plugin) {
super(plugin);
}
@Override
public boolean perform(CommandSender sender, String[] args) {
List<World> worlds = new ArrayList<World>();
if(args.length>1){
return false;
}
if(args.length>0){
World world = plugin.getServer().getWorld(args[0].toString());
if(world!=null){
worlds.add(world);
} else {
sender.sendMessage(ChatColor.RED + "World does not exist");
return true;
}
} else {
worlds = plugin.getServer().getWorlds();
}
for(World world : worlds){
ChatColor color = ChatColor.BLUE;
if(world.getEnvironment()==Environment.NETHER){
color = ChatColor.RED;
} else if(world.getEnvironment()==Environment.NORMAL){
color = ChatColor.GREEN;
}
List<Player> players = world.getPlayers();
String result = "";
if(players.size() <= 0){
result = "Empty";
} else {
for(Player player : players){
result += player.getName() + " ";
}
}
sender.sendMessage(color + world.getName() + ChatColor.WHITE + " - " + result);
}
return true;
}
}

View File

@ -10,9 +10,9 @@ import com.onarandombox.MultiVerseCore.MultiVerseCore;
* https://github.com/Nijikokun/iConomy3/blob/master/com/nijiko/coelho/iConomy/iConomy.java
* @author Nijikokun & Coelho
*/
public class defaultConfiguration {
public class DefaultConfiguration {
public defaultConfiguration(File folder, String name){
public DefaultConfiguration(File folder, String name){
File actual = new File(folder, name);
if (!actual.exists()) {

View File

@ -3,7 +3,7 @@ package com.onarandombox.utils;
import org.bukkit.Material;
import org.bukkit.World;
public class blockSafety {
public class BlockSafety {
/**
* This function checks whether the block at the given coordinates are above
* air or not.

View File

@ -0,0 +1,82 @@
package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.World;
public class LocationManipulation {
/**
* Convert a Location into a Colon separated string to allow us to store it in text.
* @param location
* @return
*/
public String locationToString(Location location) {
StringBuilder l = new StringBuilder();
l.append(location.getBlockX() + ":");
l.append(location.getBlockY() + ":");
l.append(location.getBlockZ() + ":");
l.append(location.getYaw() + ":");
l.append(location.getPitch());
return l.toString();
}
/**
* Convert a String to a Location.
* @param world
* @param xStr
* @param yStr
* @param zStr
* @param yawStr
* @param pitchStr
* @return
*/
public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr){
double x = Double.parseDouble(xStr);
double y = Double.parseDouble(yStr);
double z = Double.parseDouble(zStr);
float yaw = Float.valueOf(yawStr).floatValue();
float pitch = Float.valueOf(pitchStr).floatValue();
return new Location(world, x, y, z, yaw, pitch);
}
/**
* Convert a Location to XYZ Coordinates.
* @param l
* @return
*/
public String strCoords(Location l){
String result = "";
result += "X: " + l.getBlockX() + " ";
result += "Y: " + l.getBlockY() + " ";
result += "Z: " + l.getBlockZ() + " ";
return result;
}
/**
* Return the NESW Direction a Location is facing.
* @param location
* @return
*/
public String getDirection(Location location) {
int r = (int) Math.abs((location.getYaw() - 90) % 360);
String dir;
if (r < 23)
dir = "N";
else if (r < 68)
dir = "NE";
else if (r < 113)
dir = "E";
else if (r < 158)
dir = "SE";
else if (r < 203)
dir = "S";
else if (r < 248)
dir = "SW";
else if (r < 293)
dir = "W";
else if (r < 338)
dir = "NW";
else
dir = "N";
return dir;
}
}

View File

@ -1,28 +0,0 @@
package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.World;
public class stringLocation {
public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr){
double x = Double.parseDouble(xStr);
double y = Double.parseDouble(yStr);
double z = Double.parseDouble(zStr);
float yaw = Float.valueOf(yawStr).floatValue();
float pitch = Float.valueOf(pitchStr).floatValue();
return new Location(world, x, y, z, yaw, pitch);
}
public String locationToString(Location location) {
StringBuilder l = new StringBuilder();
l.append(location.getBlockX() + ":");
l.append(location.getBlockY() + ":");
l.append(location.getBlockZ() + ":");
l.append(location.getYaw() + ":");
l.append(location.getPitch());
return l.toString();
}
}

View File

@ -5,28 +5,54 @@ version: 0.1
commands:
mvcreate:
description: World create command
usage: /<command>
usage: |
/<command> <world> <environment>
/<command> creative normal -- Creates a world called 'creative' with a NORMAL environment.
/<command> hellworld nether -- Creates a world called 'hellworld' with a NETHER environment.
mvimport:
description: World import command
usage: /<command>
usage: |
/<command> <world> <environment>
/<command> creative normal -- Imports an existing world called 'creative' with a NORMAL environment.
/<command> hellworld nether -- Imports an existing world called 'hellworld' with a NETHER environment.
mvremove:
description: World delete command
usage: /<command>
usage: |
/<command> <world>
/<command> creative -- Removes the world 'creative' from the MultiVerse setup.
/<command> hellworld -- Removes the world 'hellworld' from the MultiVerse setup.
mvmodify:
description: Modify the settings of an existing world
usage: /<command>
usage: |
/<command> <world> <option>:<value>
/<command> creative pvp:false -- Turns off PVP in the 'creative' world.
mvtp:
description: Command to teleport between Worlds
usage: /<command>
usage: |
/<command> <world>[:spawn]
Example: /<command> creative - Teleports you to the relevant location in the 'creative' world.
Example: /<command> creative:spawn - Teleports you to the spawn of the 'creative' world.
mvlist:
description: Print list of loaded Worlds
usage: /<command>
usage: |
/<command> [environment]
Example: /<command> NETHER - Shows all NETHER Worlds.
Example: /<command> NORMAL - Shows all NORMAL Worlds.
mvsetspawn:
description: Set the spawn area for a particular World
usage: /<command>
description: Set the spawn area for a particular world
usage: /<command> -- Sets the spawn area of the current world to your location.
mvspawn:
description: Teleport to the spawn area
usage: /<command>
usage: /<command> -- Teleports you to the spawn area of your current world.
mvcoord:
description: Display World and Coordinates
usage: /<command>
description: Display World, Coordinates, Direction & Compression for a world.
usage: |
/<command> [world]
/<command> -- Shows the relevant coordinates in your current world.
/<command> creative -- Shows the relevant coordinates if you were in the 'creative' world.
mvwho:
description: Display online users per world.
usage: |
/<command> [world]
/<command> -- Shows who is online in each world.
/<command> creative -- Shows who is online in the 'creative' world.