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