Initial import

This commit is contained in:
2012-02-07 11:48:45 -08:00
commit 48268bd52f
9 changed files with 571 additions and 0 deletions

9
Metropolis/.classpath Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="C:/Users/Tom/Desktop/mc-1.1/bukkit-1.1-R3.jar"/>
<classpathentry kind="lib" path="C:/Users/Tom/Desktop/MC Servers/City/plugins/WorldEdit.jar"/>
<classpathentry kind="lib" path="C:/Users/Tom/Desktop/MC Servers/City/plugins/WorldGuard.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Metropolis/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Metropolis</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -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

16
Metropolis/Plugin.jardesc Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
<jar path="C:/Users/Tom/Desktop/MC Servers/plugins/Metropolis-0.1.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/Metropolis/Plugin.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<javaElement handleIdentifier="=Metropolis/src"/>
</selectedElements>
</jardesc>

View File

@@ -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<Cuboid> {
@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);
}
}

View File

@@ -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);
}
}

View File

@@ -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<PlayerHome> _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<PlayerHome>();
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<String, ProtectedRegion> 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<PlayerHome>();
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<Class<?>> getDatabaseClasses(){
List<Class<?>> list = new ArrayList<Class<?>>();
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<plotCuboid.minX + roadWidth/2; x++){
for(z=plotCuboid.minZ; z<=plotCuboid.maxZ; z++){
Block block = world.getBlockAt(x, y, z);
block.setTypeId(4);
for(int y1 = 0; y1 < spaceAboveRoad; y1++){
block = world.getBlockAt(x, y+y1+1, z);
block.setTypeId(0);
}
}
}
log.info("road2");
for(x=plotCuboid.maxX - roadWidth/2+1; x<=plotCuboid.maxX; x++){
for(z=plotCuboid.minZ; z<=plotCuboid.maxZ; z++){
Block block = world.getBlockAt(x, y, z);
block.setTypeId(4);
for(int y1 = 0; y1 < spaceAboveRoad; y1++){
block = world.getBlockAt(x, y+y1+1, z);
block.setTypeId(0);
}
}
}
log.info("road3");
for(z=plotCuboid.minZ; z<plotCuboid.minZ + roadWidth/2; z++){
for(x=plotCuboid.minX; x<=plotCuboid.maxX; x++){
Block block = world.getBlockAt(x, y, z);
block.setTypeId(4);
for(int y1 = 0; y1 < spaceAboveRoad; y1++){
block = world.getBlockAt(x, y+y1+1, z);
block.setTypeId(0);
}
}
}
log.info("road4");
for(z=plotCuboid.maxZ - roadWidth/2+1; z<=plotCuboid.maxZ; z++){
for(x=plotCuboid.minX; x<=plotCuboid.maxX; x++){
Block block = world.getBlockAt(x, y, z);
block.setTypeId(4);
for(int y1 = 0; y1 < spaceAboveRoad; y1++){
block = world.getBlockAt(x, y+y1+1, z);
block.setTypeId(0);
}
}
}
}
}
private Cuboid findNextUnownedHomeRegion() {
log.info("findNextUnownedHomeRegion");
int homeIndex = 0;
if(_occupiedHomes.size() == 0){
if(size < 1){
size=1;
}
expandCityRegion();
return new Cuboid(getPlotMin(-1, -1), getPlotMax(-1, -1));
}
PlayerHome home = _occupiedHomes.get(homeIndex);
for(int row = -size/2; row<=size/2; row++){
for(int col = -size/2; col <= size/2; col++){
if(home == null){
expandCityRegion();
return new Cuboid(getPlotMin(row, col), getPlotMax(row, col));
}else if(Cuboid.isBlockLessThan(getPlotMin(row, col), home.getCuboid().getMin())){
return new Cuboid(getPlotMin(row, col), getPlotMax(row, col));
}else{
homeIndex++;
if(homeIndex < _occupiedHomes.size()){
home = _occupiedHomes.get(homeIndex);
}else{
home = null;
}
}
}
}
size++;
return new Cuboid(getPlotMin(-size/2, -size/2), getPlotMax(-size/2, -size/2));
}
private void expandCityRegion() {
ProtectedRegion cityRegion = regionManager.getRegion("City");
if(cityRegion instanceof ProtectedCuboidRegion){
ProtectedCuboidRegion region = (ProtectedCuboidRegion)cityRegion;
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
min = new BlockVector(min.getBlockX() - plotSizeX, min.getBlockY(), min.getBlockZ() - plotSizeZ);
max = new BlockVector(max.getBlockX() + plotSizeX, max.getBlockY(), max.getBlockZ() + plotSizeZ);
region.setMinimumPoint(min);
region.setMaximumPoint(max);
}
}
public BlockVector getPlotMin(int row, int col){
return new BlockVector(col * plotSizeX, 0, row * plotSizeZ);
}
public BlockVector getPlotMax(int row, int col){
return new BlockVector(col * plotSizeX + plotSizeX-1, 128, row * plotSizeZ + plotSizeZ-1);
}
private void setHomeOccupied(String owner, BlockVector minimumPoint, BlockVector maximumPoint) {
PlayerHome home = new PlayerHome(owner, minimumPoint, maximumPoint);
if(!_occupiedHomes.contains(home)){
_occupiedHomes.add(home);
Collections.sort(_occupiedHomes);
}
}
public Cuboid getSpawnCuboid(){
// TODO Auto-generated method stub
return null;
}
public Cuboid getNextUnusedHome(){
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -0,0 +1,74 @@
package com.majinnaibu.bukkit.plugins.metropolis;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.avaje.ebean.validation.NotNull;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
@Entity()
@Table(name="met_home")
public class PlayerHome implements Comparable<PlayerHome>{
@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);
}
}

View File

@@ -0,0 +1,6 @@
name: Metropolis
main: com.majinnaibu.bukkit.plugins.metropolis.MetropolisPlugin
depend: [WorldEdit, WorldGuard]
version: 0.2
database: true