commit 48268bd52f17d823e074faa90ded7c0bdc641403 Author: headhunter45 Date: Tue Feb 7 11:48:45 2012 -0800 Initial import diff --git a/Metropolis/.classpath b/Metropolis/.classpath new file mode 100644 index 0000000..07fbea5 --- /dev/null +++ b/Metropolis/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Metropolis/.project b/Metropolis/.project new file mode 100644 index 0000000..2819a03 --- /dev/null +++ b/Metropolis/.project @@ -0,0 +1,17 @@ + + + Metropolis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Metropolis/.settings/org.eclipse.jdt.core.prefs b/Metropolis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a213a68 --- /dev/null +++ b/Metropolis/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sun Feb 05 03:44:35 PST 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/Metropolis/Plugin.jardesc b/Metropolis/Plugin.jardesc new file mode 100644 index 0000000..e685cfc --- /dev/null +++ b/Metropolis/Plugin.jardesc @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/Cuboid.java b/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/Cuboid.java new file mode 100644 index 0000000..5c2d4e2 --- /dev/null +++ b/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/Cuboid.java @@ -0,0 +1,106 @@ +package com.majinnaibu.bukkit.plugins.metropolis; + +import javax.persistence.Entity; +import javax.persistence.Id; + +import com.sk89q.worldedit.BlockVector; + +@Entity +public class Cuboid implements Comparable { + @Id + private int id; + + public int minX; + public int minY; + public int minZ; + + public int maxX; + public int maxY; + public int maxZ; + + public int getId(){ + return id; + } + + public void setId(int id){ + this.id = id; + } + + public Cuboid(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ + this.minX = minX; + this.minY = minY; + this.minZ = minZ; + this.maxX = maxX; + this.maxY = maxY; + this.maxZ = maxZ; + } + + public Cuboid(BlockVector min, BlockVector max) { + this.minX = min.getBlockX(); + this.minY = min.getBlockY(); + this.minZ = min.getBlockZ(); + this.maxX = max.getBlockX(); + this.maxY = max.getBlockY(); + this.maxZ = max.getBlockZ(); + } + + public BlockVector getMin(){ + return new BlockVector(minX, minY, minZ); + } + + public BlockVector getMax(){ + return new BlockVector(maxX, maxY, maxZ); + } + + @Override + public int compareTo(Cuboid o) { + BlockVector min = getMin(); + BlockVector otherMin = o.getMin(); + + if(min.getBlockX() < otherMin.getBlockX()){ + return -1; + }else if(min.getBlockX() > otherMin.getBlockX()){ + return 1; + }else if(min.getBlockZ() < otherMin.getBlockZ()){ + return -1; + }else if(min.getBlockZ() > otherMin.getBlockZ()){ + return 1; + }else if(min.getBlockY() < otherMin.getBlockY()){ + return -1; + }else if(min.getBlockY() > otherMin.getBlockY()){ + return 1; + }else{ + return 0; + } + } + + public static int compareBlockVectors(BlockVector min, BlockVector otherMin){ + if(min.getBlockX() < otherMin.getBlockX()){ + return -1; + }else if(min.getBlockX() > otherMin.getBlockX()){ + return 1; + }else if(min.getBlockZ() < otherMin.getBlockZ()){ + return -1; + }else if(min.getBlockZ() > otherMin.getBlockZ()){ + return 1; + }else if(min.getBlockY() < otherMin.getBlockY()){ + return -1; + }else if(min.getBlockY() > otherMin.getBlockY()){ + return 1; + }else{ + return 0; + } + } + + public static boolean isBlockLessThan(BlockVector v1, BlockVector v2) { + return compareBlockVectors(v1, v2) < 0; + } + + public Cuboid inset(int x, int z){ + return inset(x, 0, z); + } + + public Cuboid inset(int x, int y, int z){ + return new Cuboid(this.minX + x, this.minY, this.minZ + z, this.maxX - x, this.maxY, this.maxZ - z); + } +} diff --git a/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/LoginListener.java b/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/LoginListener.java new file mode 100644 index 0000000..86a1e75 --- /dev/null +++ b/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/LoginListener.java @@ -0,0 +1,29 @@ +package com.majinnaibu.bukkit.plugins.metropolis; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerLoginEvent; + +public class LoginListener implements Listener { + private MetropolisPlugin _plugin = null; + + public LoginListener(MetropolisPlugin plugin){ + _plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + + + @EventHandler(priority=EventPriority.MONITOR) + public void onPlayerLogin(PlayerLoginEvent event){ + MetropolisPlugin.log.info("Metropolis: player login"); + Player player = event.getPlayer(); + if(player == null){ + return; + } + + _plugin.getPlayerHome(player); + } +} diff --git a/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/MetropolisPlugin.java b/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/MetropolisPlugin.java new file mode 100644 index 0000000..53ce2d9 --- /dev/null +++ b/Metropolis/src/com/majinnaibu/bukkit/plugins/metropolis/MetropolisPlugin.java @@ -0,0 +1,302 @@ +package com.majinnaibu.bukkit.plugins.metropolis; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.java.JavaPlugin; + +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.domains.DefaultDomain; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +public class MetropolisPlugin extends JavaPlugin { + public static final Logger log=Logger.getLogger("Minecraft"); + public static final String DEFAULT_WORLD_NAME = "world"; + + public PluginDescriptionFile pdf = null; + public WorldGuardPlugin worldGuard = null; + public WorldEditPlugin worldEdit = null; + public World world = null; + public RegionManager regionManager = null; + + private List _occupiedHomes; + + private LoginListener _loginListener = null; + int size = 0; + int plotSizeX = 24; + int plotSizeZ = 24; + int roadWidth = 4; + int roadLevel = 62; + int spaceAboveRoad = 2; + + @Override + public void onDisable() { + log.info(String.format("%s disabled", pdf.getFullName())); + } + + @Override + public void onEnable() { + pdf = getDescription(); + + Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard"); + if(plugin == null || !(plugin instanceof WorldGuardPlugin)){ + throw new RuntimeException("WorldGuard must be loaded first"); + } + + worldGuard = (WorldGuardPlugin) plugin; + + plugin = getServer().getPluginManager().getPlugin("WorldEdit"); + if(plugin == null || !(plugin instanceof WorldEditPlugin)){ + throw new RuntimeException("WorldEdit must be loaded first"); + } + worldEdit = (WorldEditPlugin) plugin; + + world = getServer().getWorld(DEFAULT_WORLD_NAME); + + regionManager = worldGuard.getRegionManager(world); + + _occupiedHomes = new ArrayList(); + + fillOccupiedHomes(); + + ProtectedRegion cityRegion = regionManager.getRegion("City"); + if(cityRegion == null){ + cityRegion = new ProtectedCuboidRegion("City", getPlotMin(0, 0), this.getPlotMax(0, 0)); + cityRegion.setPriority(0); + regionManager.addRegion(cityRegion); + //TODO determine appropriate chest flags + } + + //setupDatabase(); + + if(_loginListener == null){ + _loginListener = new LoginListener(this); + } + + Map regions = regionManager.getRegions(); + + for(ProtectedRegion region: regions.values()){ + if(region.getId().startsWith("h_")){ + setHomeOccupied(region.getId().substring(2), region.getMinimumPoint(), region.getMaximumPoint()); + } + } + + log.info(String.format("%s enabled", pdf.getFullName())); + } + /* + private void setupDatabase() { + try{ + getDatabase().find(PlayerHome.class).findRowCount(); + }catch(PersistenceException ex){ + System.out.println("Installing database for " + pdf.getName() + " due to first time usage"); + installDDL(); + } + } + /**/ + + private void fillOccupiedHomes() { + _occupiedHomes = new ArrayList(); + for(ProtectedRegion region : regionManager.getRegions().values()){ + if(region instanceof ProtectedCuboidRegion && region.getId().startsWith("h_")){ + ProtectedCuboidRegion cuboidRegion = (ProtectedCuboidRegion) region; + _occupiedHomes.add(new PlayerHome(cuboidRegion)); + } + } + + Collections.sort(_occupiedHomes); + } + + PlayerHome getPlayerHome(Player player) { + PlayerHome home = null; + home = new PlayerHome(); + + String regionName = "h_" + player.getName(); + ProtectedRegion homeRegion = regionManager.getRegion(regionName); + Cuboid plotCuboid = null; + Cuboid homeCuboid = null; + + log.info(homeRegion == null? "null" : homeRegion.toString()); + if(homeRegion == null){ + plotCuboid = findNextUnownedHomeRegion(); + homeCuboid = plotCuboid.inset(roadWidth/2, roadWidth/2); + homeRegion = new ProtectedCuboidRegion(regionName, homeCuboid.getMin(), homeCuboid.getMax()); + DefaultDomain d = homeRegion.getOwners(); + d.addPlayer(player.getName()); + //TODO: set flags for chest protection + homeRegion.setPriority(1); + regionManager.addRegion(homeRegion); + + createRoads(plotCuboid); + } + + return home; + } + + /* + @Override + public List> getDatabaseClasses(){ + List> list = new ArrayList>(); + + list.add(PlayerHome.class); + + return list; + } + /**/ + + private void createRoads(Cuboid plotCuboid) { + log.info("createRoads"); + if(roadWidth>0){ + int x=0; + int y= roadLevel; + int z=0; + + if(plotCuboid == null){ + log.info("plotCuboid is null"); + return; + } + + log.info("road1"); + for(x=plotCuboid.minX; x{ + @Id + private int id; + + @NotNull + private String playerName; + + @NotNull + private Cuboid cuboid; + + public PlayerHome(String owner, BlockVector min, BlockVector max) { + cuboid = new Cuboid(min, max); + playerName = owner; + } + + public PlayerHome() { + // TODO Auto-generated constructor stub + } + + public PlayerHome(ProtectedCuboidRegion region){ + if(region.getId().startsWith("h_") && region.getId().length() > 2){ + this.playerName = region.getId().substring(2); + }else{ + this.playerName = region.getId(); + } + + this.cuboid = new Cuboid(region.getMinimumPoint(), region.getMaximumPoint()); + } + + public int getId(){return this.id;} + public void setId(int id){this.id = id;} + + public String getPlayerName(){return this.playerName;} + public void setPlayerName(String playerName){this.playerName = playerName;} + + public Cuboid getCuboid(){return this.cuboid;} + public void setCuboid(Cuboid cuboid){this.cuboid = cuboid;} + + @Override + public boolean equals(Object other) { + if(!(other instanceof PlayerHome)){ + return super.equals(other); + } + + PlayerHome otherPlayerHome = (PlayerHome)other; + + if(!this.playerName.equals(otherPlayerHome.playerName)){ + return false; + } + + if(!this.cuboid.equals(otherPlayerHome.cuboid)){ + return false; + } + + return true; + } + + @Override + public int compareTo(PlayerHome another) { + return cuboid.compareTo(another.cuboid); + } +} diff --git a/Metropolis/src/plugin.yml b/Metropolis/src/plugin.yml new file mode 100644 index 0000000..860c170 --- /dev/null +++ b/Metropolis/src/plugin.yml @@ -0,0 +1,6 @@ +name: Metropolis +main: com.majinnaibu.bukkit.plugins.metropolis.MetropolisPlugin +depend: [WorldEdit, WorldGuard] +version: 0.2 +database: true +