Updates spotless and adds a license header.

This commit is contained in:
2026-09-27 02:29:28 -07:00
parent 8dbbdbac91
commit 08d27ede40
32 changed files with 3124 additions and 2430 deletions

View File

@@ -26,13 +26,13 @@
| MET-022 | Planning | (Optional) Add new features, quality-of-life improvements, or CI configuration after the modernization and documentation tasks are complete. | | MET-022 | Planning | (Optional) Add new features, quality-of-life improvements, or CI configuration after the modernization and documentation tasks are complete. |
| GIT-009 | Planning | i have three reserve plots and one just got overwritten when a new player joined. | | GIT-009 | Planning | i have three reserve plots and one just got overwritten when a new player joined. |
| GIT-008 | Ready | Implement multiple plot sizes by granting multiple plots around each other. | GIT-008 | Ready | Implement multiple plot sizes by granting multiple plots around each other.
| GIT-007 | Ready | Allow buying and selling of homes via an ecnoomy plugin. | | GIT-007 | Planning | Allow buying and selling of homes via an ecnoomy plugin. |
| GIT-006 | Ready | Add levels support. | | GIT-006 | Ready | Add levels support. |
| GIT-005 | Planning | Add the possibility to create multiple plot homes in shapes. | | GIT-005 | Planning | Add the possibility to create multiple plot homes in shapes. |
| GIT-004 | Ready | Add a command to request home allocation. | | GIT-004 | Planning | Add a command to request home allocation. |
| GIT-003 | Ready | Add support for multiple homes. | | GIT-003 | Ready | Add support for multiple homes. |
| GIT-002 | Ready | Add a command to teleport to a reservation you are part of. | | GIT-002 | Planning | Add a command to teleport to a reservation you are part of. |
| GIT-001 | Ready | Add a command to move to a different home. | | GIT-001 | Planning | Add a command to move to a different home. |
# GIT-001 - Add a command to move to a different home. # GIT-001 - Add a command to move to a different home.
**Status:** Ready **Status:** Ready

View File

@@ -1,4 +1,5 @@
plugins { plugins {
id 'com.diffplug.spotless' version '8.10.3'
id 'java-library' id 'java-library'
id 'maven-publish' id 'maven-publish'
id 'org.danilopianini.git-sensitive-semantic-versioning' version '7.0.24' id 'org.danilopianini.git-sensitive-semantic-versioning' version '7.0.24'
@@ -88,3 +89,14 @@ tasks.named('wrapper') {
archiveBase = Wrapper.PathBase.PROJECT archiveBase = Wrapper.PathBase.PROJECT
archivePath = '.gradle/wrapper/dists' archivePath = '.gradle/wrapper/dists'
} }
spotless {
java {
googleJavaFormat('1.36.1')
importOrder 'java', 'javax', 'com', 'net', 'org', ''
licenseHeaderFile 'config/license-header.txt'
target 'src/**/*.java'
removeUnusedImports()
toggleOffOn()
}
}

17
config/license-header.txt Normal file
View File

@@ -0,0 +1,17 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -28,18 +45,22 @@ class MetropolisServerIntegrationTest {
void plotReservationIsPersistedByTheLoadedWorldGuardPlugin() throws IOException { void plotReservationIsPersistedByTheLoadedWorldGuardPlugin() throws IOException {
String regionId = "metropolis-it-" + UUID.randomUUID().toString().substring(0, 8); String regionId = "metropolis-it-" + UUID.randomUUID().toString().substring(0, 8);
try (RconClient rcon = connectToConfiguredServer()) { try (RconClient rcon = connectToConfiguredServer()) {
String response = rcon.execute("metropolis-plot-reserve " + regionId + " 100 60 100 105 70 105"); String response =
rcon.execute("metropolis-plot-reserve " + regionId + " 100 60 100 105 70 105");
assertTrue(response.contains("Reserved plot region " + regionId), response); assertTrue(response.contains("Reserved plot region " + regionId), response);
} }
Path serverDirectory = Path.of(requiredEnvironment("METROPOLIS_SERVER_DIR")); Path serverDirectory = Path.of(requiredEnvironment("METROPOLIS_SERVER_DIR"));
String worldName = System.getenv().getOrDefault("METROPOLIS_WORLD", "world"); String worldName = System.getenv().getOrDefault("METROPOLIS_WORLD", "world");
Path regionsFile = serverDirectory.resolve("plugins/WorldGuard/worlds") Path regionsFile =
serverDirectory
.resolve("plugins/WorldGuard/worlds")
.resolve(worldName) .resolve(worldName)
.resolve("regions.yml"); .resolve("regions.yml");
YamlConfiguration regions = YamlConfiguration.loadConfiguration(regionsFile.toFile()); YamlConfiguration regions = YamlConfiguration.loadConfiguration(regionsFile.toFile());
assertTrue(regions.contains("regions." + regionId), "WorldGuard did not persist region " + regionId); assertTrue(
regions.contains("regions." + regionId), "WorldGuard did not persist region " + regionId);
} }
private static RconClient connectToConfiguredServer() throws IOException { private static RconClient connectToConfiguredServer() throws IOException {

View File

@@ -1,11 +1,27 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import org.bukkit.Location;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import org.bukkit.Location;
public class Cuboid implements Comparable<Cuboid> { public class Cuboid implements Comparable<Cuboid> {
private int id; private int id;
@@ -131,24 +147,61 @@ public class Cuboid implements Comparable<Cuboid> {
} }
public Cuboid inset(int x, int y, int 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); return new Cuboid(
this.minX + x, this.minY, this.minZ + z, this.maxX - x, this.maxY, this.maxZ - z);
} }
public int getVolume() { public int getVolume() {
return (this.maxX - this.minX) * (this.maxY - this.minY) * (this.maxZ - this.minZ); return (this.maxX - this.minX) * (this.maxY - this.minY) * (this.maxZ - this.minZ);
} }
public int getMinX(){return minX;}
public void setMinX(int minX){this.minX = minX;} public int getMinX() {
public int getMinY(){return minY;} return minX;
public void setMinY(int minY){this.minY = minY;} }
public int getMinZ(){return minZ;}
public void setMinZ(int minZ){this.minZ = minZ;} public void setMinX(int minX) {
public int getMaxX(){return maxX;} this.minX = minX;
public void setMaxX(int maxX){this.maxX = maxX;} }
public int getMaxY(){return maxY;}
public void setMaxY(int maxY){this.maxY = maxY;} public int getMinY() {
public int getMaxZ(){return maxZ;} return minY;
public void setMaxZ(int maxZ){this.maxZ = maxZ;} }
public void setMinY(int minY) {
this.minY = minY;
}
public int getMinZ() {
return minZ;
}
public void setMinZ(int minZ) {
this.minZ = minZ;
}
public int getMaxX() {
return maxX;
}
public void setMaxX(int maxX) {
this.maxX = maxX;
}
public int getMaxY() {
return maxY;
}
public void setMaxY(int maxY) {
this.maxY = maxY;
}
public int getMaxZ() {
return maxZ;
}
public void setMaxZ(int maxZ) {
this.maxZ = maxZ;
}
public Cuboid outset(int amount) { public Cuboid outset(int amount) {
return outset(amount, amount, amount); return outset(amount, amount, amount);
@@ -159,7 +212,8 @@ public class Cuboid implements Comparable<Cuboid> {
} }
public Cuboid outset(int x, int y, int z) { public Cuboid outset(int x, int y, int z) {
return new Cuboid(this.minX - x, this.minY - y, this.minZ - z, this.maxX + x, this.maxY + y, this.maxZ + z); return new Cuboid(
this.minX - x, this.minY - y, this.minZ - z, this.maxX + x, this.maxY + y, this.maxZ + z);
} }
public int getCenterX() { public int getCenterX() {
@@ -175,26 +229,17 @@ public class Cuboid implements Comparable<Cuboid> {
} }
public boolean intersects(Cuboid other) { public boolean intersects(Cuboid other) {
if (this.maxX >= other.minX && this.minX <= other.maxX) if (this.maxX >= other.minX && this.minX <= other.maxX) {
{ if (this.maxZ >= other.minZ && this.minZ <= other.maxZ) {
if (this.maxZ >= other.minZ && this.minZ <= other.maxZ) if (this.maxY >= other.minY && this.minY <= other.maxY) {
{
if (this.maxY >= other.minY && this.minY <= other.maxY)
{
return true; return true;
} } else {
else
{
return false; return false;
} }
} } else {
else
{
return false; return false;
} }
} } else {
else
{
return false; return false;
} }
} }
@@ -213,8 +258,8 @@ public class Cuboid implements Comparable<Cuboid> {
@Override @Override
public String toString() { public String toString() {
return String.format("{Cuboid minX=%d, minY=%d, minZ=%d, maxX=%d, maxY=%d, maxZ=%d}", minX, minY, minZ, maxX, maxY, maxZ); return String.format(
"{Cuboid minX=%d, minY=%d, minZ=%d, maxX=%d, maxY=%d, maxZ=%d}",
minX, minY, minZ, maxX, maxY, maxZ);
} }
} }

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import java.io.File; import java.io.File;

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import java.io.File; import java.io.File;
@@ -6,9 +23,32 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisDebugGenerateTestHomesCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisFlagResetCommand;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisHomeAcquire;
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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -27,30 +67,6 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.majinnaibu.bukkitplugins.metropolis.commands.MetropolisCommand;
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.MetropolisHomeAcquire;
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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
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 class MetropolisPlugin extends JavaPlugin {
public static final boolean DEBUG = false; public static final boolean DEBUG = false;
private static final int version = 1; private static final int version = 1;
@@ -108,7 +124,6 @@ public class MetropolisPlugin extends JavaPlugin {
private ProtectedRegion _spawnRegion = null; private ProtectedRegion _spawnRegion = null;
private ProtectedRegion _cityRegion = null; private ProtectedRegion _cityRegion = null;
@Override @Override
public void onDisable() { public void onDisable() {
getLogger().info(String.format("%s disabled", pdf.getFullName())); getLogger().info(String.format("%s disabled", pdf.getFullName()));
@@ -123,21 +138,32 @@ public class MetropolisPlugin extends JavaPlugin {
_currentHomes = new HashMap<UUID, Integer>(); _currentHomes = new HashMap<UUID, Integer>();
loadCurrentHomes(); loadCurrentHomes();
if(DEBUG){getLogger().info("Checking config");} if (DEBUG) {
getLogger().info("Checking config");
}
Configuration config = getConfig(); Configuration config = getConfig();
if (!config.contains("version")) { if (!config.contains("version")) {
// new // new
if(DEBUG){getLogger().info("No config exists. Assuming new installation.");} if (DEBUG) {
getLogger().info("No config exists. Assuming new installation.");
}
} else { } else {
int configVersion = safeGetIntFromConfig(config, "version"); int configVersion = safeGetIntFromConfig(config, "version");
if (configVersion < version) { if (configVersion < version) {
if(DEBUG){getLogger().info(String.format("Updating config from version v%s to v%s.", configVersion, version));} if (DEBUG) {
getLogger()
.info(
String.format(
"Updating config from version v%s to v%s.", configVersion, version));
}
if (configVersion != version) { if (configVersion != version) {
// upgrade config // upgrade config
config.set("version", version); config.set("version", version);
} }
saveConfig(); saveConfig();
if(DEBUG){getLogger().info("Config updated");} if (DEBUG) {
getLogger().info("Config updated");
}
} }
} }
@@ -146,7 +172,9 @@ public class MetropolisPlugin extends JavaPlugin {
config.options().copyDefaults(true); config.options().copyDefaults(true);
if(DEBUG){getLogger().info("Reading configuration from file.");} if (DEBUG) {
getLogger().info("Reading configuration from file.");
}
plotSizeX = safeGetIntFromConfig(config, "plot.sizeX"); plotSizeX = safeGetIntFromConfig(config, "plot.sizeX");
plotSizeZ = safeGetIntFromConfig(config, "plot.sizeZ"); plotSizeZ = safeGetIntFromConfig(config, "plot.sizeZ");
generateFloor = safeGetBooleanFromConfig(config, "plot.floor.generate"); generateFloor = safeGetBooleanFromConfig(config, "plot.floor.generate");
@@ -174,7 +202,9 @@ public class MetropolisPlugin extends JavaPlugin {
buildUserOverrides(); buildUserOverrides();
saveConfig(); saveConfig();
if(DEBUG){getLogger().info("Done reading config.");} if (DEBUG) {
getLogger().info("Done reading config.");
}
getLogger().info(String.format("Metropolis: world name is %s", worldName)); getLogger().info(String.format("Metropolis: world name is %s", worldName));
@@ -209,14 +239,16 @@ public class MetropolisPlugin extends JavaPlugin {
gridSizeY = world.getMaxHeight(); gridSizeY = world.getMaxHeight();
gridSizeZ = plotSizeZ + roadWidth; gridSizeZ = plotSizeZ + roadWidth;
regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); regionManager =
WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (regionManager == null) { if (regionManager == null) {
throw new RuntimeException("WorldGuard regions don't seem to be enabled."); throw new RuntimeException("WorldGuard regions don't seem to be enabled.");
} }
_cityRegion = regionManager.getRegion("City"); _cityRegion = regionManager.getRegion("City");
if (_cityRegion == null) { if (_cityRegion == null) {
_cityRegion = new ProtectedCuboidRegion("City", getPlotMin(0, 0, 1), this.getPlotMax(0, 0, 1)); _cityRegion =
new ProtectedCuboidRegion("City", getPlotMin(0, 0, 1), this.getPlotMax(0, 0, 1));
_cityRegion.setPriority(0); _cityRegion.setPriority(0);
_cityRegion.setFlag(Flags.PVP, StateFlag.State.DENY); _cityRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
_cityRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY); _cityRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
@@ -283,7 +315,8 @@ public class MetropolisPlugin extends JavaPlugin {
RegisterCommandHandler("metropolis", new MetropolisCommand(this)); RegisterCommandHandler("metropolis", new MetropolisCommand(this));
RegisterCommandHandler("metropolis-debug-generatetesthomes", new MetropolisDebugGenerateTestHomesCommand(this)); RegisterCommandHandler(
"metropolis-debug-generatetesthomes", new MetropolisDebugGenerateTestHomesCommand(this));
RegisterCommandHandler("metropolis-flag-reset", new MetropolisFlagResetCommand(this)); RegisterCommandHandler("metropolis-flag-reset", new MetropolisFlagResetCommand(this));
@@ -301,9 +334,9 @@ public class MetropolisPlugin extends JavaPlugin {
private void loadCurrentHomes() { private void loadCurrentHomes() {
File homesFile = new File(getDataFolder(), "currentHomes.yml"); File homesFile = new File(getDataFolder(), "currentHomes.yml");
try { try {
_currentHomes.putAll(CurrentHomesStore.load( _currentHomes.putAll(
homesFile, CurrentHomesStore.load(
ownerName -> getServer().getOfflinePlayer(ownerName).getUniqueId())); homesFile, ownerName -> getServer().getOfflinePlayer(ownerName).getUniqueId()));
saveCurrentHomes(); saveCurrentHomes();
} catch (IOException | org.bukkit.configuration.InvalidConfigurationException e) { } catch (IOException | org.bukkit.configuration.InvalidConfigurationException e) {
getLogger().log(java.util.logging.Level.SEVERE, "Unable to load currentHomes.yml", e); getLogger().log(java.util.logging.Level.SEVERE, "Unable to load currentHomes.yml", e);
@@ -359,7 +392,8 @@ public class MetropolisPlugin extends JavaPlugin {
private void RegisterCommandHandler(String commandName, CommandExecutor executor) { private void RegisterCommandHandler(String commandName, CommandExecutor executor) {
PluginCommand command = getCommand(commandName); PluginCommand command = getCommand(commandName);
if (command == null) { if (command == null) {
throw new RuntimeException(String.format("The command %s does not appear to exist", commandName)); throw new RuntimeException(
String.format("The command %s does not appear to exist", commandName));
} else { } else {
command.setExecutor(executor); command.setExecutor(executor);
} }
@@ -395,7 +429,8 @@ public class MetropolisPlugin extends JavaPlugin {
private Material safeGetMaterialFromConfig(Configuration config, String name) { private Material safeGetMaterialFromConfig(Configuration config, String name) {
Material material = null; Material material = null;
if (config.isInt(name)) { if (config.isInt(name)) {
material = switch (config.getInt(name)) { material =
switch (config.getInt(name)) {
case 1 -> Material.STONE; case 1 -> Material.STONE;
case 2 -> Material.GRASS_BLOCK; case 2 -> Material.GRASS_BLOCK;
case 4 -> Material.COBBLESTONE; case 4 -> Material.COBBLESTONE;
@@ -413,7 +448,9 @@ public class MetropolisPlugin extends JavaPlugin {
} }
private void throwInvalidConfigException() { private void throwInvalidConfigException() {
getLogger().info("Metropolis: ERROR config file is invalid. Please correct Metropolis/config.yml and restart the server."); getLogger()
.info(
"Metropolis: ERROR config file is invalid. Please correct Metropolis/config.yml and restart the server.");
throw new RuntimeException("Config file is invalid."); throw new RuntimeException("Config file is invalid.");
} }
@@ -457,8 +494,7 @@ public class MetropolisPlugin extends JavaPlugin {
ProtectedCuboidRegion cuboidRegion = (ProtectedCuboidRegion) region; ProtectedCuboidRegion cuboidRegion = (ProtectedCuboidRegion) region;
if (cuboidRegion.getId().startsWith("h_")) { if (cuboidRegion.getId().startsWith("h_")) {
PlayerHome home = PlayerHome.get(region); PlayerHome home = PlayerHome.get(region);
if(!_currentHomes.containsKey(home.getPlayerId())) if (!_currentHomes.containsKey(home.getPlayerId())) {
{
_currentHomes.put(home.getPlayerId(), home.getNumber()); _currentHomes.put(home.getPlayerId(), home.getNumber());
} }
_occupiedPlots.add(home); _occupiedPlots.add(home);
@@ -670,17 +706,16 @@ public class MetropolisPlugin extends JavaPlugin {
} }
private boolean isSolidMaterial(Material material) { private boolean isSolidMaterial(Material material) {
return material.isBlock() && return material.isBlock()
material != Material.AIR && && material != Material.AIR
material != Material.WATER && && material != Material.WATER
material != Material.LAVA && && material != Material.LAVA
material != Material.TORCH && && material != Material.TORCH
material != Material.REDSTONE_TORCH; && material != Material.REDSTONE_TORCH;
} }
private boolean isPhysicsMaterial(Material material) { private boolean isPhysicsMaterial(Material material) {
return material == Material.GRAVEL || return material == Material.GRAVEL || material == Material.SAND;
material == Material.SAND;
} }
public boolean isBlockOccupied(int row, int col) { public boolean isBlockOccupied(int row, int col) {
@@ -725,8 +760,11 @@ public class MetropolisPlugin extends JavaPlugin {
// Top // Top
for (col = min; col <= max; col++) { for (col = min; col <= max; col++) {
if (!areBlocksOccupied(row, col, plotMultiplier)) { if (!areBlocksOccupied(row, col, plotMultiplier)) {
if(DEBUG){getLogger().info(String.format("row: %d, col: %d", row, col));} if (DEBUG) {
return new Cuboid(getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier)); getLogger().info(String.format("row: %d, col: %d", row, col));
}
return new Cuboid(
getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier));
} }
} }
@@ -734,8 +772,11 @@ public class MetropolisPlugin extends JavaPlugin {
col = max; col = max;
for (row = min + 1; row < max; row++) { for (row = min + 1; row < max; row++) {
if (!areBlocksOccupied(row, col, plotMultiplier)) { if (!areBlocksOccupied(row, col, plotMultiplier)) {
if(DEBUG){getLogger().info(String.format("row: %d, col: %d", row, col));} if (DEBUG) {
return new Cuboid(getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier)); getLogger().info(String.format("row: %d, col: %d", row, col));
}
return new Cuboid(
getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier));
} }
} }
@@ -743,8 +784,11 @@ public class MetropolisPlugin extends JavaPlugin {
row = max; row = max;
for (col = max; col >= min; col--) { for (col = max; col >= min; col--) {
if (!areBlocksOccupied(row, col, plotMultiplier)) { if (!areBlocksOccupied(row, col, plotMultiplier)) {
if(DEBUG){getLogger().info(String.format("row: %d, col: %d", row, col));} if (DEBUG) {
return new Cuboid(getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier)); getLogger().info(String.format("row: %d, col: %d", row, col));
}
return new Cuboid(
getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier));
} }
} }
@@ -753,8 +797,11 @@ public class MetropolisPlugin extends JavaPlugin {
for (row = max; row > min; row--) { for (row = max; row > min; row--) {
if (!areBlocksOccupied(row, col, plotMultiplier)) { if (!areBlocksOccupied(row, col, plotMultiplier)) {
if (row != 0 || col != 0) { if (row != 0 || col != 0) {
if(DEBUG){getLogger().info(String.format("row: %d, col: %d", row, col));} if (DEBUG) {
return new Cuboid(getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier)); getLogger().info(String.format("row: %d, col: %d", row, col));
}
return new Cuboid(
getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier));
} }
} }
} }
@@ -764,7 +811,9 @@ public class MetropolisPlugin extends JavaPlugin {
max = ring - (plotMultiplier - 1); max = ring - (plotMultiplier - 1);
} }
if(DEBUG){getLogger().info(String.format("row: %d, col: %d", row, col));} if (DEBUG) {
getLogger().info(String.format("row: %d, col: %d", row, col));
}
return new Cuboid(getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier)); return new Cuboid(getPlotMin(row, col, plotMultiplier), getPlotMax(row, col, plotMultiplier));
} }
@@ -796,18 +845,23 @@ public class MetropolisPlugin extends JavaPlugin {
for (Plot home : _occupiedPlots) { 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){getLogger().info(String.format("col: %d, row: %d, iSize: %d", plotCol, plotRow, iSize));} if (DEBUG) {
getLogger().info(String.format("col: %d, row: %d, iSize: %d", plotCol, plotRow, iSize));
}
iSize = Math.max(Math.max(plotRow * 2 + 1, plotCol * 2 + 1), iSize); iSize = Math.max(Math.max(plotRow * 2 + 1, plotCol * 2 + 1), iSize);
} }
if(DEBUG){getLogger().info(String.format("City size is %d", iSize));} if (DEBUG) {
getLogger().info(String.format("City size is %d", iSize));
}
return iSize; return iSize;
} }
public BlockVector3 getPlotMin(int row, int col, int plotMultiplier) { public BlockVector3 getPlotMin(int row, int col, int plotMultiplier) {
BlockVector3 gridMin = getGridMin(row, col, plotMultiplier); BlockVector3 gridMin = getGridMin(row, col, plotMultiplier);
BlockVector3 bv = BlockVector3.at(gridMin.x() + roadWidth/2, gridMin.y(), gridMin.z() + roadWidth/2); BlockVector3 bv =
BlockVector3.at(gridMin.x() + roadWidth / 2, gridMin.y(), gridMin.z() + roadWidth / 2);
getLogger().info(String.format("getPlotMin (%d, %d, %d)", bv.x(), bv.y(), bv.z())); getLogger().info(String.format("getPlotMin (%d, %d, %d)", bv.x(), bv.y(), bv.z()));
return bv; return bv;
} }
@@ -815,7 +869,11 @@ public class MetropolisPlugin extends JavaPlugin {
public BlockVector3 getPlotMax(int row, int col, int plotMultiplier) { public BlockVector3 getPlotMax(int row, int col, int plotMultiplier) {
BlockVector3 gridMax = getGridMax(row, col, plotMultiplier); BlockVector3 gridMax = getGridMax(row, col, plotMultiplier);
BlockVector3 bv = BlockVector3.at(gridMax.x() - (roadWidth - roadWidth/2), gridMax.y(), gridMax.z() - (roadWidth-roadWidth/2)); BlockVector3 bv =
BlockVector3.at(
gridMax.x() - (roadWidth - roadWidth / 2),
gridMax.y(),
gridMax.z() - (roadWidth - roadWidth / 2));
getLogger().info(String.format("getPlotMax (%d, %d, %d)", bv.x(), bv.y(), bv.z())); getLogger().info(String.format("getPlotMax (%d, %d, %d)", bv.x(), bv.y(), bv.z()));
return bv; return bv;
} }
@@ -831,7 +889,11 @@ public class MetropolisPlugin extends JavaPlugin {
public BlockVector3 getGridMax(int row, int col, int plotMultiplier) { public BlockVector3 getGridMax(int row, int col, int plotMultiplier) {
int level = 0; int level = 0;
BlockVector3 bv = BlockVector3.at((col+plotMultiplier) * gridSizeX*plotMultiplier-1, (level+1/*plotMultiplier*/) * gridSizeY-1, (row+plotMultiplier) * gridSizeZ-1); BlockVector3 bv =
BlockVector3.at(
(col + plotMultiplier) * gridSizeX * plotMultiplier - 1,
(level + 1 /*plotMultiplier*/) * gridSizeY - 1,
(row + plotMultiplier) * gridSizeZ - 1);
getLogger().info(String.format("getGridMax (%d, %d, %d)", bv.x(), bv.y(), bv.z())); getLogger().info(String.format("getGridMax (%d, %d, %d)", bv.x(), bv.y(), bv.z()));
return bv; return bv;
} }
@@ -844,7 +906,12 @@ public class MetropolisPlugin extends JavaPlugin {
return (cuboid.minZ - roadWidth / 2) / gridSizeZ; return (cuboid.minZ - roadWidth / 2) / gridSizeZ;
} }
private void setHomeOccupied(UUID ownerId, String ownerName, int homeNumber, BlockVector3 minimumPoint, BlockVector3 maximumPoint) { private void setHomeOccupied(
UUID ownerId,
String ownerName,
int homeNumber,
BlockVector3 minimumPoint,
BlockVector3 maximumPoint) {
PlayerHome home = new PlayerHome(ownerId, ownerName, homeNumber, minimumPoint, maximumPoint); PlayerHome home = new PlayerHome(ownerId, ownerName, homeNumber, minimumPoint, maximumPoint);
if (!_occupiedPlots.contains(home)) { if (!_occupiedPlots.contains(home)) {
_occupiedPlots.add(home); _occupiedPlots.add(home);
@@ -862,7 +929,9 @@ public class MetropolisPlugin extends JavaPlugin {
int homeNumber = _currentHomes.getOrDefault(playerId, 1); int homeNumber = _currentHomes.getOrDefault(playerId, 1);
int multiplier = getPlotMultiplier(playerId); int multiplier = getPlotMultiplier(playerId);
if(DEBUG){getLogger().info(String.format("Generating home for %s", playerName));} if (DEBUG) {
getLogger().info(String.format("Generating home for %s", playerName));
}
Cuboid homeCuboid = null; Cuboid homeCuboid = null;
ProtectedRegion phomeRegion = null; ProtectedRegion phomeRegion = null;
String regionName = getHomeRegionName(playerId, homeNumber); String regionName = getHomeRegionName(playerId, homeNumber);
@@ -879,7 +948,8 @@ public class MetropolisPlugin extends JavaPlugin {
getLogger().info("Metropolis Generating home in " + homeCuboid.toString()); getLogger().info("Metropolis Generating home in " + homeCuboid.toString());
ProtectedCuboidRegion newHomeRegion = new ProtectedCuboidRegion(regionName, homeCuboid.getMin(), homeCuboid.getMax()); ProtectedCuboidRegion newHomeRegion =
new ProtectedCuboidRegion(regionName, homeCuboid.getMin(), homeCuboid.getMax());
newHomeRegion.setFlag(Flags.PVP, StateFlag.State.DENY); newHomeRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
newHomeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY); newHomeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
newHomeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY); newHomeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
@@ -906,17 +976,23 @@ public class MetropolisPlugin extends JavaPlugin {
getLogger().info("Metropolis: ERROR Problem saving region"); getLogger().info("Metropolis: ERROR Problem saving region");
e.printStackTrace(); e.printStackTrace();
} }
getLogger().info(String.format( getLogger()
.info(
String.format(
"New home region (%d, %d, %d) (%d, %d, %d)", "New home region (%d, %d, %d) (%d, %d, %d)",
newHomeRegion.getMinimumPoint().x(), newHomeRegion.getMinimumPoint().x(),
newHomeRegion.getMinimumPoint().y(), newHomeRegion.getMinimumPoint().y(),
newHomeRegion.getMinimumPoint().z(), newHomeRegion.getMinimumPoint().z(),
newHomeRegion.getMaximumPoint().x(), newHomeRegion.getMaximumPoint().x(),
newHomeRegion.getMaximumPoint().y(), newHomeRegion.getMaximumPoint().y(),
newHomeRegion.getMaximumPoint().z() newHomeRegion.getMaximumPoint().z()));
));
setHomeOccupied(playerId, playerName, homeNumber, newHomeRegion.getMinimumPoint(), newHomeRegion.getMaximumPoint()); setHomeOccupied(
playerId,
playerName,
homeNumber,
newHomeRegion.getMinimumPoint(),
newHomeRegion.getMaximumPoint());
_currentHomes.putIfAbsent(playerId, homeNumber); _currentHomes.putIfAbsent(playerId, homeNumber);
saveCurrentHomes(); saveCurrentHomes();
@@ -926,12 +1002,16 @@ public class MetropolisPlugin extends JavaPlugin {
generateFloor(homeCuboid); generateFloor(homeCuboid);
} }
if(DEBUG){getLogger().info(String.format("generateSign: %s", String.valueOf(generateSign)));} if (DEBUG) {
getLogger().info(String.format("generateSign: %s", String.valueOf(generateSign)));
}
if (generateSign) { if (generateSign) {
generateSign(homeCuboid, playerName); generateSign(homeCuboid, playerName);
} }
if(DEBUG){getLogger().info(String.format("Done generating home for %s", playerName));} if (DEBUG) {
getLogger().info(String.format("Done generating home for %s", playerName));
}
PlayerHome home = new PlayerHome(newHomeRegion); PlayerHome home = new PlayerHome(newHomeRegion);
home.setPlayerName(playerName); home.setPlayerName(playerName);
@@ -939,7 +1019,8 @@ public class MetropolisPlugin extends JavaPlugin {
} }
private void generateSign(Cuboid plotCuboid, String playerName) { private void generateSign(Cuboid plotCuboid, String playerName) {
Block signBlock = world.getBlockAt(plotCuboid.getCenterX(), roadLevel+1, plotCuboid.getCenterZ()); Block signBlock =
world.getBlockAt(plotCuboid.getCenterX(), roadLevel + 1, plotCuboid.getCenterZ());
signBlock.setType(Material.OAK_SIGN); signBlock.setType(Material.OAK_SIGN);
Sign sign = (Sign) signBlock.getState(); Sign sign = (Sign) signBlock.getState();
sign.setLine(0, "Home of"); sign.setLine(0, "Home of");
@@ -964,7 +1045,8 @@ public class MetropolisPlugin extends JavaPlugin {
} }
public void reserveCuboid(String regionName, Cuboid cuboid) { public void reserveCuboid(String regionName, Cuboid cuboid) {
ProtectedCuboidRegion reservedRegion = new ProtectedCuboidRegion(regionName, cuboid.getMin(), cuboid.getMax()); ProtectedCuboidRegion reservedRegion =
new ProtectedCuboidRegion(regionName, cuboid.getMin(), cuboid.getMax());
reservedRegion.setFlag(Flags.PVP, StateFlag.State.DENY); reservedRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
reservedRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY); reservedRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
reservedRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY); reservedRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
@@ -991,6 +1073,7 @@ public class MetropolisPlugin extends JavaPlugin {
public Material getWallMaterial() { public Material getWallMaterial() {
return wallMaterial; return wallMaterial;
} }
public int getWallheight() { public int getWallheight() {
return wallHeight; return wallHeight;
} }
@@ -1011,7 +1094,8 @@ public class MetropolisPlugin extends JavaPlugin {
try { try {
regionManager.removeRegion(regionId); regionManager.removeRegion(regionId);
} catch (Exception ex) { } catch (Exception ex) {
getLogger().info(String.format("[ERROR] Metropolis: Unable to remove region {%s}.", regionId)); getLogger()
.info(String.format("[ERROR] Metropolis: Unable to remove region {%s}.", regionId));
return; return;
} }
} }
@@ -1062,7 +1146,7 @@ public class MetropolisPlugin extends JavaPlugin {
/** /**
* string is the name of the region to get a plot for * string is the name of the region to get a plot for
* *
* loop through all regions and find one with the specified name return null if there is none * <p>loop through all regions and find one with the specified name return null if there is none
*/ */
for (Plot plot : _occupiedPlots) { for (Plot plot : _occupiedPlots) {
if (plot.getRegionName().equals(string)) { if (plot.getRegionName().equals(string)) {
@@ -1106,7 +1190,9 @@ public class MetropolisPlugin extends JavaPlugin {
public boolean homeExists(UUID playerId, int homeNumber) { public boolean homeExists(UUID playerId, int homeNumber) {
for (Plot plot : _occupiedPlots) { for (Plot plot : _occupiedPlots) {
if(plot instanceof PlayerHome home && home.getPlayerId().equals(playerId) && home.getNumber() == homeNumber){ if (plot instanceof PlayerHome home
&& home.getPlayerId().equals(playerId)
&& home.getNumber() == homeNumber) {
return true; return true;
} }
} }

View File

@@ -1,25 +1,52 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class PlayerHome extends Plot { public class PlayerHome extends Plot {
private UUID playerId; private UUID playerId;
private String playerName; private String playerName;
public UUID getPlayerId(){return this.playerId;}
public String getPlayerName(){return this.playerName;} public UUID getPlayerId() {
public void setPlayerName(String playerName){this.playerName = playerName;} return this.playerId;
}
public String getPlayerName() {
return this.playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
private int number; private int number;
public PlayerHome(UUID ownerId, String ownerName, int homeNumber, BlockVector3 min, BlockVector3 max) { public PlayerHome(
UUID ownerId, String ownerName, int homeNumber, BlockVector3 min, BlockVector3 max) {
super(String.format("h_%d_%s", homeNumber, ownerId), min, max); super(String.format("h_%d_%s", homeNumber, ownerId), min, max);
this.playerId = ownerId; this.playerId = ownerId;
this.playerName = ownerName; this.playerName = ownerName;
@@ -54,7 +81,8 @@ public class PlayerHome extends Plot{
this.playerName = offlinePlayer.getName() == null ? regionOwner : offlinePlayer.getName(); this.playerName = offlinePlayer.getName() == null ? regionOwner : offlinePlayer.getName();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
Set<UUID> ownerIds = homeRegion.getOwners().getUniqueIds(); Set<UUID> ownerIds = homeRegion.getOwners().getUniqueIds();
this.playerId = ownerIds.isEmpty() this.playerId =
ownerIds.isEmpty()
? Bukkit.getOfflinePlayer(regionOwner).getUniqueId() ? Bukkit.getOfflinePlayer(regionOwner).getUniqueId()
: ownerIds.iterator().next(); : ownerIds.iterator().next();
this.playerName = regionOwner; this.playerName = regionOwner;
@@ -84,7 +112,16 @@ public class PlayerHome extends Plot{
public String toFriendlyString() { public String toFriendlyString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(String.format("Metropolis Home {Owner: %s min: (%d, %d, %d) max: (%d, %d, %d)}", getPlayerName(), getCuboid().getMinX(), getCuboid().getMinY(), getCuboid().getMinZ(), getCuboid().getMaxX(), getCuboid().getMaxY(), getCuboid().getMaxZ())); sb.append(
String.format(
"Metropolis Home {Owner: %s min: (%d, %d, %d) max: (%d, %d, %d)}",
getPlayerName(),
getCuboid().getMinX(),
getCuboid().getMinY(),
getCuboid().getMinZ(),
getCuboid().getMaxX(),
getCuboid().getMaxY(),
getCuboid().getMaxZ()));
return sb.toString(); return sb.toString();
} }

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -1,26 +1,61 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class Plot implements Comparable<Plot> { public class Plot implements Comparable<Plot> {
private int _id; private int _id;
public int getId(){return _id;}
public void setId(int id){_id = id;} public int getId() {
return _id;
}
public void setId(int id) {
_id = id;
}
private Cuboid _cuboid; private Cuboid _cuboid;
public Cuboid getCuboid(){return _cuboid;}
public void setCuboid(Cuboid cuboid){_cuboid = cuboid;} public Cuboid getCuboid() {
return _cuboid;
}
public void setCuboid(Cuboid cuboid) {
_cuboid = cuboid;
}
private String _regionName; private String _regionName;
public String getRegionName(){return _regionName;}
public void setRegionName(String regionName){_regionName = regionName;} public String getRegionName() {
return _regionName;
}
public void setRegionName(String regionName) {
_regionName = regionName;
}
public Plot(String regionName, BlockVector3 min, BlockVector3 max) { public Plot(String regionName, BlockVector3 min, BlockVector3 max) {
_cuboid = new Cuboid(min, max); _cuboid = new Cuboid(min, max);
@@ -38,7 +73,8 @@ public class Plot implements Comparable<Plot>{
} }
public BlockVector3 getPlotMin(int roadWidth) { public BlockVector3 getPlotMin(int roadWidth) {
return BlockVector3.at(_cuboid.minX - roadWidth/2, _cuboid.minY, _cuboid.minZ - roadWidth/2); return BlockVector3.at(
_cuboid.minX - roadWidth / 2, _cuboid.minY, _cuboid.minZ - roadWidth / 2);
} }
public int getRow(int roadWidth, int plotSizeZ) { public int getRow(int roadWidth, int plotSizeZ) {
@@ -90,7 +126,15 @@ public class Plot implements Comparable<Plot>{
public String toFriendlyString() { public String toFriendlyString() {
StringBuilder sb = new StringBuilder(); 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())); 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(); return sb.toString();
} }
@@ -107,7 +151,8 @@ public class Plot implements Comparable<Plot>{
Block block = world.getBlockAt(x, y, z); Block block = world.getBlockAt(x, y, z);
Block blockAbove = world.getBlockAt(x, y + 1, z); Block blockAbove = world.getBlockAt(x, y + 1, z);
Block blockUnder = 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){ if (block.getType() == Material.AIR & blockAbove.getType() == Material.AIR
&& blockUnder.getType() != Material.AIR) {
return new Location(world, x, y, z); return new Location(world, x, y, z);
} }
} }

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
public class UserOverride { public class UserOverride {
@@ -5,9 +22,17 @@ public class UserOverride {
private int _plotMultiplier; private int _plotMultiplier;
private int _maxPlots; private int _maxPlots;
public String getUsername(){return _username;} public String getUsername() {
public int getPlotMultiplier(){return _plotMultiplier;} return _username;
public int getMaxPlots(){return _maxPlots;} }
public int getPlotMultiplier() {
return _plotMultiplier;
}
public int getMaxPlots() {
return _maxPlots;
}
public UserOverride(String username, int plotMultiplier, int maxPlots) { public UserOverride(String username, int plotMultiplier, int maxPlots) {
_username = username; _username = username;

View File

@@ -1,11 +1,28 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisCommand implements CommandExecutor { public class MetropolisCommand implements CommandExecutor {
private MetropolisPlugin _plugin; private MetropolisPlugin _plugin;
@@ -20,5 +37,4 @@ public class MetropolisCommand implements CommandExecutor {
return true; return true;
} }
} }

View File

@@ -1,18 +1,34 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisDebugGenerateTestHomesCommand implements CommandExecutor { public class MetropolisDebugGenerateTestHomesCommand implements CommandExecutor {
private MetropolisPlugin _plugin; private MetropolisPlugin _plugin;
public MetropolisDebugGenerateTestHomesCommand(MetropolisPlugin plugin) { public MetropolisDebugGenerateTestHomesCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
@@ -28,5 +44,4 @@ public class MetropolisDebugGenerateTestHomesCommand implements CommandExecutor
return false; return false;
} }
} }
} }

View File

@@ -1,14 +1,31 @@
package com.majinnaibu.bukkitplugins.metropolis.commands; /*
This file is part of Metropolis.
import org.bukkit.command.Command; Metropolis is free software: you can redistribute it and/or modify
import org.bukkit.command.CommandExecutor; it under the terms of the GNU Affero General Public License as published by
import org.bukkit.command.CommandSender; the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin; import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class MetropolisFlagResetCommand implements CommandExecutor { public class MetropolisFlagResetCommand implements CommandExecutor {
private MetropolisPlugin _plugin; private MetropolisPlugin _plugin;
@@ -38,16 +55,11 @@ public class MetropolisFlagResetCommand implements CommandExecutor {
homeRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY); homeRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
homeRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY); homeRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
homeRegion.setFlag(Flags.TNT, StateFlag.State.DENY); homeRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
} }
} }
sender.sendMessage("Metropolis: flags have been reset"); sender.sendMessage("Metropolis: flags have been reset");
return true; return true;
} }
} }

View File

@@ -1,12 +1,29 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeAcquire implements CommandExecutor { public class MetropolisHomeAcquire implements CommandExecutor {
MetropolisPlugin _plugin; MetropolisPlugin _plugin;
@@ -31,5 +48,4 @@ public class MetropolisHomeAcquire implements CommandExecutor {
_plugin.assignPlot(player); _plugin.assignPlot(player);
return true; return true;
} }
} }

View File

@@ -1,13 +1,30 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class MetropolisHomeEvictCommand implements CommandExecutor { public class MetropolisHomeEvictCommand implements CommandExecutor {
MetropolisPlugin _plugin = null; MetropolisPlugin _plugin = null;
@@ -30,11 +47,13 @@ public class MetropolisHomeEvictCommand implements CommandExecutor {
OfflinePlayer player = _plugin.getOfflinePlayer(playerName); OfflinePlayer player = _plugin.getOfflinePlayer(playerName);
if (player == null) { if (player == null) {
sender.sendMessage(String.format("The requested player {%s}does not appear to exist.", playerName)); sender.sendMessage(
String.format("The requested player {%s}does not appear to exist.", playerName));
return false; return false;
} }
ProtectedRegion region = _plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId())); ProtectedRegion region =
_plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId()));
if (region == null) { if (region == null) {
sender.sendMessage(String.format("The player {%s} has no home to be evicted from.")); sender.sendMessage(String.format("The player {%s} has no home to be evicted from."));
return false; return false;
@@ -52,9 +71,9 @@ public class MetropolisHomeEvictCommand implements CommandExecutor {
_plugin.saveRegions(); _plugin.saveRegions();
// ?optionally regen the region // ?optionally regen the region
//_plugin.worldEdit.getCommand("regen").execute(_plugin.getServer().getConsoleSender(), "regen", new String[]{}); // _plugin.worldEdit.getCommand("regen").execute(_plugin.getServer().getConsoleSender(),
// "regen", new String[]{});
return true; return true;
} }
} }

View File

@@ -1,11 +1,28 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.OfflinePlayer;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeGenerateCommand implements CommandExecutor { public class MetropolisHomeGenerateCommand implements CommandExecutor {
@@ -32,5 +49,4 @@ public class MetropolisHomeGenerateCommand implements CommandExecutor {
return true; return true;
} }
} }

View File

@@ -1,14 +1,31 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
public class MetropolisHomeGoCommand implements CommandExecutor { public class MetropolisHomeGoCommand implements CommandExecutor {
MetropolisPlugin _plugin = null; MetropolisPlugin _plugin = null;
@@ -66,7 +83,8 @@ public class MetropolisHomeGoCommand implements CommandExecutor {
if (sender == player) { if (sender == player) {
sender.sendMessage("There is no valid spawn location in your home"); sender.sendMessage("There is no valid spawn location in your home");
} else { } else {
sender.sendMessage(String.format("There is no valid spawn location in %s's home", player.getName())); sender.sendMessage(
String.format("There is no valid spawn location in %s's home", player.getName()));
} }
return false; return false;
} }

View File

@@ -1,12 +1,29 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; 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.Plot;
public class MetropolisHomeListCommand implements CommandExecutor { public class MetropolisHomeListCommand implements CommandExecutor {
private MetropolisPlugin _plugin; private MetropolisPlugin _plugin;
@@ -21,5 +38,4 @@ public class MetropolisHomeListCommand implements CommandExecutor {
} }
return true; return true;
} }
} }

View File

@@ -1,12 +1,29 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeMoveCommand implements CommandExecutor { public class MetropolisHomeMoveCommand implements CommandExecutor {
MetropolisPlugin _plugin; MetropolisPlugin _plugin;
@@ -49,5 +66,4 @@ public class MetropolisHomeMoveCommand implements CommandExecutor {
return true; return true;
} }
} }

View File

@@ -1,13 +1,30 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
public class MetropolisPlotGoCommand implements CommandExecutor { public class MetropolisPlotGoCommand implements CommandExecutor {
MetropolisPlugin _plugin; MetropolisPlugin _plugin;
@@ -45,5 +62,4 @@ public class MetropolisPlotGoCommand implements CommandExecutor {
return true; return true;
} }
} }

View File

@@ -1,9 +1,21 @@
package com.majinnaibu.bukkitplugins.metropolis.commands; /*
This file is part of Metropolis.
import org.bukkit.command.Command; Metropolis is free software: you can redistribute it and/or modify
import org.bukkit.command.CommandExecutor; it under the terms of the GNU Affero General Public License as published by
import org.bukkit.command.CommandSender; the Free Software Foundation, either version 3 of the License, or
import org.bukkit.entity.Player; (at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid; import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin; import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
@@ -11,6 +23,11 @@ import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MetropolisPlotReserveCommand implements CommandExecutor { public class MetropolisPlotReserveCommand implements CommandExecutor {
MetropolisPlugin _plugin; MetropolisPlugin _plugin;
@@ -30,7 +47,10 @@ public class MetropolisPlotReserveCommand implements CommandExecutor {
if (sender instanceof Player && args.length == 1) { if (sender instanceof Player && args.length == 1) {
try { try {
Region selection = _plugin.worldEdit.getSession((Player) sender) Region selection =
_plugin
.worldEdit
.getSession((Player) sender)
.getSelection(BukkitAdapter.adapt(_plugin.getWorld())); .getSelection(BukkitAdapter.adapt(_plugin.getWorld()));
cuboid = new Cuboid(selection); cuboid = new Cuboid(selection);
} catch (IncompleteRegionException ex) { } catch (IncompleteRegionException ex) {
@@ -72,5 +92,4 @@ public class MetropolisPlotReserveCommand implements CommandExecutor {
return true; return true;
} }
} }

View File

@@ -1,12 +1,29 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners; package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class DebugListener implements Listener { public class DebugListener implements Listener {
MetropolisPlugin _plugin; MetropolisPlugin _plugin;

View File

@@ -1,15 +1,32 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners; package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
public class PlayerJoinListener implements Listener { public class PlayerJoinListener implements Listener {
private MetropolisPlugin _plugin = null; private MetropolisPlugin _plugin = null;
@@ -25,15 +42,32 @@ public class PlayerJoinListener implements Listener {
} }
PlayerHome home = _plugin.getPlayerHome(player); PlayerHome home = _plugin.getPlayerHome(player);
if(home==null){_plugin.getLogger().info("home is null");} if (home == null) {
else if(home.getCuboid() == null){_plugin.getLogger().info("home.getCuboid() is null");} _plugin.getLogger().info("home is null");
else if(home.getCuboid().getVolume() == 0){_plugin.getLogger().info("home.getCuboid().getVolume() is 0");} } else if (home.getCuboid() == null) {
_plugin.getLogger().info("home.getCuboid() is null");
} else if (home.getCuboid().getVolume() == 0) {
_plugin.getLogger().info("home.getCuboid().getVolume() is 0");
}
if (home == null || home.getCuboid() == null || home.getCuboid().getVolume() == 0) { if (home == null || home.getCuboid() == null || home.getCuboid().getVolume() == 0) {
_plugin.getLogger().info(String.format("Metropolis: Unable to get or create home for player %s", player.getName())); _plugin
.getLogger()
.info(
String.format(
"Metropolis: Unable to get or create home for player %s", player.getName()));
} else { } else {
Cuboid cuboid = home.getCuboid(); Cuboid cuboid = home.getCuboid();
player.sendMessage(String.format("Metropolis: Welcome %s your home is between (%d, %d, %d) and (%d, %d, %d)", player.getName(), cuboid.getMinX(), cuboid.getMinY(), cuboid.getMinZ(), cuboid.getMaxX(), cuboid.getMaxY(), cuboid.getMaxZ())); player.sendMessage(
String.format(
"Metropolis: Welcome %s your home is between (%d, %d, %d) and (%d, %d, %d)",
player.getName(),
cuboid.getMinX(),
cuboid.getMinY(),
cuboid.getMinZ(),
cuboid.getMaxX(),
cuboid.getMaxY(),
cuboid.getMaxZ()));
} }
} }
} }

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.util; package com.majinnaibu.bukkitplugins.metropolis.util;
public class Material { public class Material {

View File

@@ -1,14 +1,31 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Location; import org.bukkit.Location;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import com.sk89q.worldedit.math.BlockVector3;
class CuboidTest { class CuboidTest {
@Test @Test
void convertsWorldEditBoundsToCuboidCoordinates() { void convertsWorldEditBoundsToCuboidCoordinates() {

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -11,8 +28,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
class CurrentHomesStoreTest { class CurrentHomesStoreTest {
@TempDir @TempDir File temporaryDirectory;
File temporaryDirectory;
@Test @Test
void roundTripsHomesByUuid() throws Exception { void roundTripsHomesByUuid() throws Exception {
@@ -33,7 +49,11 @@ class CurrentHomesStoreTest {
yaml.set("OldPlayerName", 2); yaml.set("OldPlayerName", 2);
yaml.save(file); yaml.save(file);
assertEquals(Map.of(playerId, 2), CurrentHomesStore.load(file, name -> { assertEquals(
Map.of(playerId, 2),
CurrentHomesStore.load(
file,
name -> {
assertEquals("OldPlayerName", name); assertEquals("OldPlayerName", name);
return playerId; return playerId;
})); }));

View File

@@ -1,23 +1,37 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.UUID; import java.util.UUID;
import org.junit.jupiter.api.Test;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import org.junit.jupiter.api.Test;
class PlayerHomeTest { class PlayerHomeTest {
@Test @Test
void buildsUuidBasedRegionIdentityAndPreservesDisplayName() { void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
PlayerHome home = new PlayerHome( PlayerHome home =
playerId, new PlayerHome(
"PlayerName", playerId, "PlayerName", 2, BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
2,
BlockVector3.at(1, 2, 3),
BlockVector3.at(4, 5, 6));
assertEquals(playerId, home.getPlayerId()); assertEquals(playerId, home.getPlayerId());
assertEquals("PlayerName", home.getPlayerName()); assertEquals("PlayerName", home.getPlayerName());

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis; package com.majinnaibu.bukkitplugins.metropolis;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;

View File

@@ -1,7 +1,24 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -9,12 +26,12 @@ import static org.mockito.Mockito.when;
import java.util.UUID; import java.util.UUID;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
class MetropolisHomeAcquireTest { class MetropolisHomeAcquireTest {
@Test @Test
void assignsAPlotWhenThePlayerIsBelowTheirLimit() { void assignsAPlotWhenThePlayerIsBelowTheirLimit() {

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.commands; package com.majinnaibu.bukkitplugins.metropolis.commands;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,14 +25,14 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoInteractions;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
class MetropolisPlotReserveCommandTest { class MetropolisPlotReserveCommandTest {
@Test @Test
void reservesCoordinatesFromAllSixArguments() { void reservesCoordinatesFromAllSixArguments() {
@@ -24,7 +41,9 @@ class MetropolisPlotReserveCommandTest {
Command command = mock(Command.class); Command command = mock(Command.class);
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin); MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
assertTrue(executor.onCommand(sender, command, "reserve", new String[] {"north", "1", "2", "3", "4", "5", "6"})); assertTrue(
executor.onCommand(
sender, command, "reserve", new String[] {"north", "1", "2", "3", "4", "5", "6"}));
ArgumentCaptor<Cuboid> cuboid = ArgumentCaptor.forClass(Cuboid.class); ArgumentCaptor<Cuboid> cuboid = ArgumentCaptor.forClass(Cuboid.class);
verify(plugin).reserveCuboid(eq("north"), cuboid.capture()); verify(plugin).reserveCuboid(eq("north"), cuboid.capture());
@@ -43,7 +62,9 @@ class MetropolisPlotReserveCommandTest {
Command command = mock(Command.class); Command command = mock(Command.class);
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin); MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
assertFalse(executor.onCommand(sender, command, "reserve", new String[] {"north", "1", "two", "3", "4", "5", "6"})); assertFalse(
executor.onCommand(
sender, command, "reserve", new String[] {"north", "1", "two", "3", "4", "5", "6"}));
verifyNoInteractions(plugin); verifyNoInteractions(plugin);
} }
} }

View File

@@ -1,3 +1,20 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners; package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.contains;
@@ -7,14 +24,14 @@ import static org.mockito.Mockito.when;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.junit.jupiter.api.Test;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin; import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome; import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.junit.jupiter.api.Test;
class PlayerJoinListenerTest { class PlayerJoinListenerTest {
@Test @Test
void tellsJoiningPlayerTheirHomeBounds() { void tellsJoiningPlayerTheirHomeBounds() {
@@ -23,7 +40,9 @@ class PlayerJoinListenerTest {
PlayerJoinEvent event = mock(PlayerJoinEvent.class); PlayerJoinEvent event = mock(PlayerJoinEvent.class);
when(event.getPlayer()).thenReturn(player); when(event.getPlayer()).thenReturn(player);
when(player.getName()).thenReturn("PlayerName"); when(player.getName()).thenReturn("PlayerName");
when(plugin.getPlayerHome(player)).thenReturn(new PlayerHome( when(plugin.getPlayerHome(player))
.thenReturn(
new PlayerHome(
UUID.fromString("123e4567-e89b-12d3-a456-426614174000"), UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
"PlayerName", "PlayerName",
1, 1,