Fixed a new bug in plot allocation
This commit is contained in:
@@ -41,7 +41,6 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
public World world = null;
|
||||
public RegionManager regionManager = null;
|
||||
|
||||
private List<PlayerHome> _occupiedHomes;
|
||||
private List<Plot> _occupiedPlots;
|
||||
|
||||
private PlayerJoinListener _playerJoinListener = null;
|
||||
@@ -118,7 +117,7 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
regionManager.addRegion(cityRegion);
|
||||
}
|
||||
|
||||
_occupiedHomes = new ArrayList<PlayerHome>();
|
||||
_occupiedPlots = new ArrayList<Plot>();
|
||||
fillOccupiedPlots();
|
||||
resizeCityRegion();
|
||||
|
||||
@@ -135,16 +134,14 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void fillOccupiedPlots(){
|
||||
_occupiedPlots = new ArrayList<Plot>();
|
||||
_occupiedHomes = new ArrayList<PlayerHome>();
|
||||
_occupiedPlots.clear();
|
||||
|
||||
for(ProtectedRegion region: regionManager.getRegions().values()){
|
||||
if(region instanceof ProtectedCuboidRegion){
|
||||
ProtectedCuboidRegion cuboidRegion = (ProtectedCuboidRegion) region;
|
||||
if(cuboidRegion.getId().startsWith("h_")){
|
||||
PlayerHome home = PlayerHome.get(cuboidRegion);
|
||||
PlayerHome home = PlayerHome.get(region);
|
||||
_occupiedPlots.add(home);
|
||||
_occupiedHomes.add(home);
|
||||
}else if(cuboidRegion.getId().startsWith("r_")){
|
||||
_occupiedPlots.add(Plot.get(cuboidRegion));
|
||||
}
|
||||
@@ -336,7 +333,7 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
private int calculateCitySize() {
|
||||
int iSize = 3;
|
||||
|
||||
for(PlayerHome home: _occupiedHomes){
|
||||
for(Plot home: _occupiedPlots){
|
||||
int plotCol=Math.abs(getPlotXFromMin(home.getCuboid()));
|
||||
int plotRow=Math.abs(getPlotZFromMin(home.getCuboid()));
|
||||
if(DEBUG){log.info(String.format("col: %d, row: %d, iSize: %d", plotCol, plotRow, iSize));}
|
||||
@@ -370,9 +367,8 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
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);
|
||||
if(!_occupiedPlots.contains(home)){
|
||||
_occupiedPlots.add(home);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,6 +379,10 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
Cuboid homeCuboid = null;
|
||||
ProtectedRegion homeRegion = null;
|
||||
String regionName = "h_" + playerName;
|
||||
homeRegion = regionManager.getRegion("h_" + playerName);
|
||||
if(homeRegion != null){
|
||||
return PlayerHome.get(homeRegion);
|
||||
}
|
||||
|
||||
plotCuboid = findNextUnownedHomeRegion();
|
||||
homeCuboid = plotCuboid.inset(roadWidth/2, roadWidth/2);
|
||||
@@ -438,8 +438,8 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlayerHome> getCityBlocks() {
|
||||
return Collections.unmodifiableList(_occupiedHomes);
|
||||
public List<Plot> getCityBlocks() {
|
||||
return Collections.unmodifiableList(_occupiedPlots);
|
||||
}
|
||||
|
||||
public World getWorld(){
|
||||
|
||||
@@ -75,7 +75,11 @@ public class PlayerHome extends Plot{
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static PlayerHome get(ProtectedCuboidRegion cuboidRegion){
|
||||
return new PlayerHome(cuboidRegion);
|
||||
public static PlayerHome get(ProtectedRegion homeRegion){
|
||||
if(homeRegion instanceof ProtectedCuboidRegion){
|
||||
return new PlayerHome((ProtectedCuboidRegion) homeRegion);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import javax.persistence.Table;
|
||||
import com.avaje.ebean.validation.NotNull;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
@Entity()
|
||||
@Table(name="Metropolis_Plot")
|
||||
public class Plot implements Comparable<PlayerHome>{
|
||||
public class Plot implements Comparable<Plot>{
|
||||
@Id
|
||||
private int _id;
|
||||
public int getId(){return _id;}
|
||||
@@ -70,7 +71,7 @@ public class Plot implements Comparable<PlayerHome>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PlayerHome another) {
|
||||
public int compareTo(Plot another) {
|
||||
return getCuboid().compareTo(another.getCuboid());
|
||||
}
|
||||
|
||||
@@ -83,7 +84,19 @@ public class Plot implements Comparable<PlayerHome>{
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static Plot get(ProtectedCuboidRegion cuboidRegion){
|
||||
return new Plot(cuboidRegion);
|
||||
public static Plot get(ProtectedRegion region){
|
||||
if(region instanceof ProtectedCuboidRegion){
|
||||
return new Plot((ProtectedCuboidRegion) region);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toFriendlyString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(String.format("Metropolis Reserved Plot {min: (%d, %d, %d) max: (%d, %d, %d)}", getCuboid().getMinX(), getCuboid().getMinY(), getCuboid().getMinZ(), getCuboid().getMaxX(), getCuboid().getMaxY(), getCuboid().getMaxZ()));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Plot;
|
||||
|
||||
public class MetropolisHomeListCommand implements CommandExecutor {
|
||||
private MetropolisPlugin _plugin;
|
||||
@@ -16,7 +16,7 @@ public class MetropolisHomeListCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for(PlayerHome cityBlock : _plugin.getCityBlocks()){
|
||||
for(Plot cityBlock : _plugin.getCityBlocks()){
|
||||
sender.sendMessage(String.format("%s", cityBlock.toFriendlyString()));
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user