Implemented MetropolisHomeGoCommand

This commit is contained in:
2012-02-28 14:23:58 -08:00
parent 8d20bf9d98
commit 26d7188dbb
11 changed files with 495 additions and 268 deletions

View File

@@ -0,0 +1,5 @@
#Tue Feb 28 07:18:32 PST 2012
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

View File

@@ -2,6 +2,8 @@ package com.majinnaibu.bukkitplugins.metropolis;
import java.util.logging.Logger;
import org.bukkit.Location;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.selections.Selection;
@@ -204,4 +206,16 @@ public class Cuboid implements Comparable<Cuboid> {
return false;
}
}
public boolean contains(Location bedSpawn) {
if(this.minX > bedSpawn.getBlockX() || this.maxX < bedSpawn.getBlockX()){
return false;
}else if(this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()){
return false;
}else if(this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()){
return false;
}
return true;
}
}

View File

@@ -19,8 +19,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisDebugGenerateTestHomesCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisFlagResetCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeEvictCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeGenerateCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeGoCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeListCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeMoveCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisPlotGoCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisPlotReserveCommand;
import com.majinnaibu.bukkitplugins.metropolis.eventlisteners.PlayerJoinListener;
import com.sk89q.worldedit.BlockVector;
@@ -37,6 +41,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class MetropolisPlugin extends JavaPlugin {
public static final boolean DEBUG = true;
public static final Logger log=Logger.getLogger("Minecraft");
private static final int version = 1;
public PluginDescriptionFile pdf = null;
public WorldGuardPlugin worldGuard = null;
@@ -88,29 +93,52 @@ public class MetropolisPlugin extends JavaPlugin {
pdf = getDescription();
Configuration config = getConfig();
if(!config.contains("version")){
//new or upgrading from ancient
if(config.contains("plot.sizeX")){
//upgrading from ancient
int oldSizeX = safeGetIntFromConfig(config, "plot.sizeX");
int oldSizeZ = safeGetIntFromConfig(config, "plot.sizeZ");
int oldRoadWidth = safeGetIntFromConfig(config, "road.width");
oldSizeX -= oldRoadWidth;
oldSizeZ -= oldRoadWidth;
config.set("plot.sizeX", oldSizeX);
config.set("plot.sizeZ", oldSizeZ);
}else{
//new
}
}else{
int configVersion = safeGetIntFromConfig(config, "version");
if(configVersion != version){
//upgrade config
config.set("version", version);
}
}
config.options().copyDefaults(true);
plotSizeX = config.getInt("plot.sizeX");
plotSizeZ = config.getInt("plot.sizeZ");
generateFloor = config.getBoolean("plot.floor.generate");
floorMaterial = config.getInt("plot.floor.material");
spaceAboveFloor = config.getInt("plot.floor.clearSpaceAbove");
generateFloorSupports = config.getBoolean("plot.floor.supports.generate");
floorSupportMaterial = config.getInt("plot.floor.supports.material");
generateSign = config.getBoolean("plot.sign.generate");
roadWidth = config.getInt("road.width");
spaceAboveRoad = config.getInt("road.clearSpaceAbove");
roadLevel = config.getInt("road.level");
roadMaterial = config.getInt("road.material");
generateRoadSupports = config.getBoolean("road.supports.generate");
roadSupportMaterial = config.getInt("road.supports.material");
generateSpawn = config.getBoolean("spawn.generate");
setWorldSpawn = config.getBoolean("spawn.setAsWorldSpawn");
spawnFloorMaterial = config.getInt("spawn.material");
generateWall = config.getBoolean("wall.generate");
wallMaterial = config.getInt("wall.material");
wallHeight = config.getInt("wall.material");
worldName =config.getString("worldname");
plotSizeX = safeGetIntFromConfig(config, "plot.sizeX");
plotSizeZ = safeGetIntFromConfig(config, "plot.sizeZ");
generateFloor = safeGetBooleanFromConfig(config, "plot.floor.generate");
floorMaterial = safeGetIntFromConfig(config, "plot.floor.material");
spaceAboveFloor = safeGetIntFromConfig(config, "plot.floor.clearSpaceAbove");
generateFloorSupports = safeGetBooleanFromConfig(config, "plot.floor.supports.generate");
floorSupportMaterial = safeGetIntFromConfig(config, "plot.floor.supports.material");
generateSign = safeGetBooleanFromConfig(config, "plot.sign.generate");
roadWidth = safeGetIntFromConfig(config, "road.width");
spaceAboveRoad = safeGetIntFromConfig(config, "road.clearSpaceAbove");
roadLevel = safeGetIntFromConfig(config, "road.level");
roadMaterial = safeGetIntFromConfig(config, "road.material");
generateRoadSupports = safeGetBooleanFromConfig(config, "road.supports.generate");
roadSupportMaterial = safeGetIntFromConfig(config, "road.supports.material");
generateSpawn = safeGetBooleanFromConfig(config, "spawn.generate");
setWorldSpawn = safeGetBooleanFromConfig(config, "spawn.setAsWorldSpawn");
spawnFloorMaterial = safeGetIntFromConfig(config, "spawn.material");
generateWall = safeGetBooleanFromConfig(config, "wall.generate");
wallMaterial = safeGetIntFromConfig(config, "wall.material");
wallHeight = safeGetIntFromConfig(config, "wall.material");
worldName = safeGetStringFromConfig(config, "worldname");
saveConfig();
log.info(String.format("Metropolis: world name is %s", worldName));
@@ -179,13 +207,53 @@ public class MetropolisPlugin extends JavaPlugin {
log.info(String.format("%s enabled", pdf.getFullName()));
getCommand("metropolis-home-generate").setExecutor(new MetropolisHomeGenerateCommand(this));
getCommand("metropolis-home-list").setExecutor(new MetropolisHomeListCommand(this));
getCommand("metropolis-flag-reset").setExecutor(new MetropolisFlagResetCommand(this));
getCommand("metropolis-plot-reserve").setExecutor(new MetropolisPlotReserveCommand(this));
if(DEBUG){
getCommand("gentesthomes").setExecutor(new MetropolisDebugGenerateTestHomesCommand(this));
getCommand("metropolis-debug-generatetesthomes").setExecutor(new MetropolisDebugGenerateTestHomesCommand(this));
}
getCommand("metropolis-flag-reset").setExecutor(new MetropolisFlagResetCommand(this));
getCommand("metropolis-home-evict").setExecutor(new MetropolisHomeEvictCommand(this));
getCommand("metropolis-home-generate").setExecutor(new MetropolisHomeGenerateCommand(this));
getCommand("metropolis-home-go").setExecutor(new MetropolisHomeGoCommand(this));
getCommand("metropolis-home-list").setExecutor(new MetropolisHomeListCommand(this));
getCommand("metropolis-home-move").setExecutor(new MetropolisHomeMoveCommand(this));
getCommand("metropolis-plot-go").setExecutor(new MetropolisPlotGoCommand(this));
getCommand("metropolis-plot-reserve").setExecutor(new MetropolisPlotReserveCommand(this));
}
private String safeGetStringFromConfig(Configuration config, String name) {
if(config.isString(name)){
return config.getString(name);
}else{
throwInvalidConfigException();
return null;
}
}
private boolean safeGetBooleanFromConfig(Configuration config, String name) {
if(config.isBoolean(name)){
return config.getBoolean(name);
}else{
throwInvalidConfigException();
return false;
}
}
private int safeGetIntFromConfig(Configuration config, String name) {
if(config.isInt(name)){
return config.getInt(name);
}else{
throwInvalidConfigException();
return 0;
}
}
private void throwInvalidConfigException() {
log.info("Metropolis: ERROR config file is invalid. Please correct Metropolis/config.yml and restart the server.");
throw new RuntimeException("Config file is invalid.");
}
private void setupSpawn() {
@@ -203,6 +271,7 @@ public class MetropolisPlugin extends JavaPlugin {
Block block = world.getBlockAt(x, y, z);
block.setTypeId(0);
}
y=roadLevel;
Block block = world.getBlockAt(x, y, z);
block.setTypeId(spawnFloorMaterial);
@@ -557,7 +626,7 @@ public class MetropolisPlugin extends JavaPlugin {
try {
regionManager.save();
} catch (ProtectionDatabaseException e) {
// TODO Auto-generated catch block
log.info("Metropolis: ERROR Problem saving region");
e.printStackTrace();
}

View File

@@ -3,6 +3,8 @@ package com.majinnaibu.bukkitplugins.metropolis;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.bukkit.Location;
import com.avaje.ebean.validation.NotNull;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;

View File

@@ -4,6 +4,11 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import com.avaje.ebean.validation.NotNull;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
@@ -99,4 +104,26 @@ public class Plot implements Comparable<Plot>{
return sb.toString();
}
public boolean contains(Location bedSpawn) {
return _cuboid.contains(bedSpawn);
}
public Location getViableSpawnLocation(World world) {
Cuboid cuboid = getCuboid();
for(int y=cuboid.maxY-1; y>= cuboid.minY; y--){
for(int x=cuboid.minX; x<= cuboid.maxX; x++){
for(int z=cuboid.minZ; z<= cuboid.maxZ; z++){
Block block = world.getBlockAt(x, y, z);
Block blockAbove = world.getBlockAt(x, y+1, z);
Block blockUnder = world.getBlockAt(x, y-1, z);
if(block.getType() == Material.AIR & blockAbove.getType() == Material.AIR && blockUnder.getType() != Material.AIR){
return new Location(world, x, y, z);
}
}
}
}
return null;
}
}

View File

@@ -1,5 +0,0 @@
package com.majinnaibu.bukkitplugins.metropolis.commands;
public class MetropolisCommand {
}

View File

@@ -0,0 +1,23 @@
package com.majinnaibu.bukkitplugins.metropolis.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeEvictCommand implements CommandExecutor {
MetropolisPlugin _plugin = null;
public MetropolisHomeEvictCommand(MetropolisPlugin plugin){
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// TODO Auto-generated method stub
return false;
}
}

View File

@@ -0,0 +1,76 @@
package com.majinnaibu.bukkitplugins.metropolis.commands;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
public class MetropolisHomeGoCommand implements CommandExecutor {
MetropolisPlugin _plugin = null;
public MetropolisHomeGoCommand(MetropolisPlugin plugin){
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = null;
if(sender instanceof Player){
player = (Player)sender;
if(args.length >= 1){
if(player.hasPermission("")){
player = _plugin.getServer().getPlayer(args[0]);
if(player == null){
sender.sendMessage(String.format("Unable to find player %s", args[0]));
return false;
}
}else{
sender.sendMessage("Permission denied");
return false;
}
}
}else{
if(args.length >= 1){
player = _plugin.getServer().getPlayer(args[0]);
if(player == null){
sender.sendMessage(String.format("Unable to find player %s", args[0]));
return false;
}
}else{
sender.sendMessage("You must be a player");
return false;
}
}
PlayerHome home = _plugin.getPlayerHome(player);
Location loc = null;
Location bedSpawn = player.getBedSpawnLocation();
if(home.contains(bedSpawn)){
loc = bedSpawn;
}else {
loc = home.getViableSpawnLocation(_plugin.getWorld());
}
if(loc != null){
player.teleport(loc);
}else{
if(sender == player){
sender.sendMessage("There is no valid spawn location in your home");
}else{
sender.sendMessage(String.format("There is no valid spawn location in %s's home", player.getName()));
}
return false;
}
return true;
}
}

View File

@@ -0,0 +1,22 @@
package com.majinnaibu.bukkitplugins.metropolis.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeMoveCommand implements CommandExecutor {
public MetropolisHomeMoveCommand(MetropolisPlugin metropolisPlugin) {
// TODO Auto-generated constructor stub
}
@Override
public boolean onCommand(CommandSender arg0, Command arg1, String arg2,
String[] arg3) {
// TODO Auto-generated method stub
return false;
}
}

View File

@@ -0,0 +1,22 @@
package com.majinnaibu.bukkitplugins.metropolis.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisPlotGoCommand implements CommandExecutor {
public MetropolisPlotGoCommand(MetropolisPlugin metropolisPlugin) {
// TODO Auto-generated constructor stub
}
@Override
public boolean onCommand(CommandSender arg0, Command arg1, String arg2,
String[] arg3) {
// TODO Auto-generated method stub
return false;
}
}

View File

@@ -4,32 +4,4 @@ depend: [WorldGuard]
softdepend: [WorldEdit,CommandBook]
version: 0.5
database: false
commands:
metropolis-home-generate:
description: This command generates a home for a user as if they'd just logged in.
permission: metropolis.home.generate
usage: /metropolis-home-generate <playername>
metropolis-home-list:
description: This lists the regions managed by Metropolis
permission: metropolis.home.list
usage: /metropolis-home-list
metropolis-flag-reset:
description: This command resets the WorldGuard flags for all managed regions (city and h_*).
permission: metropolis.flag.reset
usage: /metropolis-flag-reset
metropolis-plot-reserve:
description: This command reserves a plot so it won't be assigned as a home.
permission: metropolis.plot.reserve
usage: /metropolis-plot-reserve <name> <minX> <minY> <minZ> <maxX> <maxY> <maxZ>
metropolis-home-evict:
description: This unassigns a player's current home.
permission: metropolis.home.evict
usage: /metropolis-home-evict <playerName>
metropolis-home-move:
description: This command swaps a player's current home with a reserved plot.
permission: metropolis.home.move
usage: /metropolis-home-move <newRegionName>
gentesthomes:
description: This command is ignored on non-debug builds.
permission: metropolis.debug
usage: /gentesthomes
commands: