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. |
| 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-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-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-002 | Ready | 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-002 | Planning | Add a command to teleport to a reservation you are part of. |
| GIT-001 | Planning | Add a command to move to a different home. |
# GIT-001 - Add a command to move to a different home.
**Status:** Ready

View File

@@ -1,4 +1,5 @@
plugins {
id 'com.diffplug.spotless' version '8.10.3'
id 'java-library'
id 'maven-publish'
id 'org.danilopianini.git-sensitive-semantic-versioning' version '7.0.24'
@@ -88,3 +89,14 @@ tasks.named('wrapper') {
archiveBase = Wrapper.PathBase.PROJECT
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;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -28,18 +45,22 @@ class MetropolisServerIntegrationTest {
void plotReservationIsPersistedByTheLoadedWorldGuardPlugin() throws IOException {
String regionId = "metropolis-it-" + UUID.randomUUID().toString().substring(0, 8);
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);
}
Path serverDirectory = Path.of(requiredEnvironment("METROPOLIS_SERVER_DIR"));
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("regions.yml");
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 {

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;
import org.bukkit.Location;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Location;
public class Cuboid implements Comparable<Cuboid> {
private int id;
@@ -17,15 +33,15 @@ public class Cuboid implements Comparable<Cuboid> {
public int maxY;
public int maxZ;
public int getId(){
public int getId() {
return id;
}
public void setId(int id){
public void setId(int id) {
this.id = id;
}
public Cuboid(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
public Cuboid(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
@@ -61,11 +77,11 @@ public class Cuboid implements Comparable<Cuboid> {
this.maxZ = selection.getMaximumPoint().z();
}
public BlockVector3 getMin(){
public BlockVector3 getMin() {
return BlockVector3.at(minX, minY, minZ);
}
public BlockVector3 getMax(){
public BlockVector3 getMax() {
return BlockVector3.at(maxX, maxY, maxZ);
}
@@ -74,46 +90,46 @@ public class Cuboid implements Comparable<Cuboid> {
BlockVector3 min = getMin();
BlockVector3 otherMin = o.getMin();
if(min.x() < otherMin.x()){
if (min.x() < otherMin.x()) {
return -1;
}else if(min.x() > otherMin.x()){
} else if (min.x() > otherMin.x()) {
return 1;
}else if(min.z() < otherMin.z()){
} else if (min.z() < otherMin.z()) {
return -1;
}else if(min.z() > otherMin.z()){
} else if (min.z() > otherMin.z()) {
return 1;
}else if(min.y() < otherMin.y()){
} else if (min.y() < otherMin.y()) {
return -1;
}else if(min.y() > otherMin.y()){
} else if (min.y() > otherMin.y()) {
return 1;
}else{
} else {
return 0;
}
}
public static int compareBlockVectors(BlockVector3 v1, BlockVector3 v2){
if(v1 == null){
if(v2 == null){
public static int compareBlockVectors(BlockVector3 v1, BlockVector3 v2) {
if (v1 == null) {
if (v2 == null) {
return 0;
}else{
} else {
return -1;
}
}else if(v2 == null){
} else if (v2 == null) {
return 1;
}
if(v1.x() < v2.x()){
if (v1.x() < v2.x()) {
return -1;
}else if(v1.x() > v2.x()){
} else if (v1.x() > v2.x()) {
return 1;
}else if(v1.z() < v2.z()){
} else if (v1.z() < v2.z()) {
return -1;
}else if(v1.z() > v2.z()){
} else if (v1.z() > v2.z()) {
return 1;
}else if(v1.y() < v2.y()){
} else if (v1.y() < v2.y()) {
return -1;
}else if(v1.y() > v2.y()){
} else if (v1.y() > v2.y()) {
return 1;
}else{
} else {
return 0;
}
}
@@ -122,89 +138,118 @@ public class Cuboid implements Comparable<Cuboid> {
return compareBlockVectors(v1, v2) < 0;
}
public Cuboid inset(int amount){
public Cuboid inset(int amount) {
return inset(amount, amount, amount);
}
public Cuboid inset(int x, int z){
public Cuboid inset(int x, int z) {
return inset(x, 0, z);
}
public Cuboid inset(int x, int y, int z){
return new Cuboid(this.minX + x, this.minY, this.minZ + z, this.maxX - x, this.maxY, this.maxZ - z);
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);
}
public int getVolume() {
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 getMinY(){return minY;}
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 int getMinX() {
return minX;
}
public void setMinX(int minX) {
this.minX = minX;
}
public int getMinY() {
return minY;
}
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) {
return outset(amount, amount, amount);
}
public Cuboid outset(int x, int z){
public Cuboid outset(int x, int z) {
return outset(x, 0, 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(){
return (this.minX + this.maxX) /2;
public int getCenterX() {
return (this.minX + this.maxX) / 2;
}
public int getCenterY(){
return (this.minY + this.maxY)/2;
public int getCenterY() {
return (this.minY + this.maxY) / 2;
}
public int getCenterZ(){
return (this.minZ + this.maxZ)/2;
public int getCenterZ() {
return (this.minZ + this.maxZ) / 2;
}
public boolean intersects(Cuboid other) {
if (this.maxX >= other.minX && this.minX <= other.maxX)
{
if (this.maxZ >= other.minZ && this.minZ <= other.maxZ)
{
if (this.maxY >= other.minY && this.minY <= other.maxY)
{
if (this.maxX >= other.minX && this.minX <= other.maxX) {
if (this.maxZ >= other.minZ && this.minZ <= other.maxZ) {
if (this.maxY >= other.minY && this.minY <= other.maxY) {
return true;
}
else
{
} else {
return false;
}
}
else
{
} else {
return false;
}
}
else
{
} else {
return false;
}
}
public boolean contains(Location bedSpawn) {
if(this.minX > bedSpawn.getBlockX() || this.maxX < bedSpawn.getBlockX()){
if (this.minX > bedSpawn.getBlockX() || this.maxX < bedSpawn.getBlockX()) {
return false;
}else if(this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()){
} else if (this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()) {
return false;
}else if(this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()){
} else if (this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()) {
return false;
}
@@ -213,8 +258,8 @@ public class Cuboid implements Comparable<Cuboid> {
@Override
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;
import java.io.File;

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;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class PlayerHome extends Plot{
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class PlayerHome extends Plot {
private UUID playerId;
private String playerName;
public UUID getPlayerId(){return this.playerId;}
public String getPlayerName(){return this.playerName;}
public void setPlayerName(String playerName){this.playerName = playerName;}
public UUID getPlayerId() {
return this.playerId;
}
public String getPlayerName() {
return this.playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
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);
this.playerId = ownerId;
this.playerName = ownerName;
@@ -31,7 +58,7 @@ public class PlayerHome extends Plot{
this.playerName = "";
}
public PlayerHome(ProtectedRegion homeRegion){
public PlayerHome(ProtectedRegion homeRegion) {
String regionName = homeRegion.getId();
if (!regionName.startsWith("h_")) {
throw new IllegalArgumentException("Not a Metropolis home region: " + regionName);
@@ -54,7 +81,8 @@ public class PlayerHome extends Plot{
this.playerName = offlinePlayer.getName() == null ? regionOwner : offlinePlayer.getName();
} catch (IllegalArgumentException ex) {
Set<UUID> ownerIds = homeRegion.getOwners().getUniqueIds();
this.playerId = ownerIds.isEmpty()
this.playerId =
ownerIds.isEmpty()
? Bukkit.getOfflinePlayer(regionOwner).getUniqueId()
: ownerIds.iterator().next();
this.playerName = regionOwner;
@@ -64,17 +92,17 @@ public class PlayerHome extends Plot{
@Override
public boolean equals(Object other) {
if(!(other instanceof PlayerHome)){
if (!(other instanceof PlayerHome)) {
return super.equals(other);
}
PlayerHome otherPlayerHome = (PlayerHome)other;
PlayerHome otherPlayerHome = (PlayerHome) other;
if(!java.util.Objects.equals(this.playerId, otherPlayerHome.playerId)){
if (!java.util.Objects.equals(this.playerId, otherPlayerHome.playerId)) {
return false;
}
if(!getCuboid().equals(otherPlayerHome.getCuboid())){
if (!getCuboid().equals(otherPlayerHome.getCuboid())) {
return false;
}
@@ -84,15 +112,24 @@ public class PlayerHome extends Plot{
public String toFriendlyString() {
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();
}
public static PlayerHome get(ProtectedRegion homeRegion){
if(homeRegion instanceof ProtectedCuboidRegion){
public static PlayerHome get(ProtectedRegion homeRegion) {
if (homeRegion instanceof ProtectedCuboidRegion) {
return new PlayerHome((ProtectedCuboidRegion) homeRegion);
}else{
} else {
return null;
}
}
@@ -101,7 +138,7 @@ public class PlayerHome extends Plot{
return number;
}
public void setNumber(int number){
public void setNumber(int number) {
this.number = number;
}
}

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;
import org.bukkit.entity.Player;

View File

@@ -1,64 +1,100 @@
/*
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;
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.Material;
import org.bukkit.World;
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;
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;
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;
public String getRegionName(){return _regionName;}
public void setRegionName(String regionName){_regionName = regionName;}
public Plot(String regionName, BlockVector3 min, BlockVector3 max){
public String getRegionName() {
return _regionName;
}
public void setRegionName(String regionName) {
_regionName = regionName;
}
public Plot(String regionName, BlockVector3 min, BlockVector3 max) {
_cuboid = new Cuboid(min, max);
_regionName = regionName;
}
public Plot(ProtectedCuboidRegion cuboid){
public Plot(ProtectedCuboidRegion cuboid) {
_cuboid = new Cuboid(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
_regionName = cuboid.getId();
}
public Plot(){
public Plot() {
_cuboid = new Cuboid();
_regionName = "";
}
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) {
BlockVector3 min = getPlotMin(roadWidth);
return min.z() / plotSizeZ;
}
public int getCol(int roadWidth, int plotSizeX){
public int getCol(int roadWidth, int plotSizeX) {
return getPlotMin(roadWidth).x() / plotSizeX;
}
@Override
public boolean equals(Object other) {
if(!(other instanceof Plot)){
if (!(other instanceof Plot)) {
return super.equals(other);
}
Plot otherPlayerHome = (Plot)other;
Plot otherPlayerHome = (Plot) other;
if(!getCuboid().equals(otherPlayerHome.getCuboid())){
if (!getCuboid().equals(otherPlayerHome.getCuboid())) {
return false;
}
@@ -71,7 +107,7 @@ public class Plot implements Comparable<Plot>{
}
@Override
public String toString(){
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{PlayerHome }"));
@@ -79,10 +115,10 @@ public class Plot implements Comparable<Plot>{
return sb.toString();
}
public static Plot get(ProtectedRegion region){
if(region instanceof ProtectedCuboidRegion){
public static Plot get(ProtectedRegion region) {
if (region instanceof ProtectedCuboidRegion) {
return new Plot((ProtectedCuboidRegion) region);
}else{
} else {
return null;
}
}
@@ -90,7 +126,15 @@ public class Plot implements Comparable<Plot>{
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()));
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();
}
@@ -101,13 +145,14 @@ public class Plot implements Comparable<Plot>{
public Location getViableSpawnLocation(World world) {
Cuboid cuboid = getCuboid();
for(int y=cuboid.maxY-1; y>= cuboid.minY; y--){
for(int x=cuboid.minX; x<= cuboid.maxX; x++){
for(int z=cuboid.minZ; z<= cuboid.maxZ; z++){
for (int y = cuboid.maxY - 1; y >= cuboid.minY; y--) {
for (int x = cuboid.minX; x <= cuboid.maxX; x++) {
for (int z = cuboid.minZ; z <= cuboid.maxZ; z++) {
Block block = world.getBlockAt(x, y, z);
Block blockAbove = 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){
Block blockAbove = 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) {
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;
public class UserOverride {
@@ -5,11 +22,19 @@ public class UserOverride {
private int _plotMultiplier;
private int _maxPlots;
public String getUsername(){return _username;}
public int getPlotMultiplier(){return _plotMultiplier;}
public int getMaxPlots(){return _maxPlots;}
public String getUsername() {
return _username;
}
public UserOverride(String username, int plotMultiplier, int maxPlots){
public int getPlotMultiplier() {
return _plotMultiplier;
}
public int getMaxPlots() {
return _maxPlots;
}
public UserOverride(String username, int plotMultiplier, int maxPlots) {
_username = username;
_plotMultiplier = plotMultiplier;
_maxPlots = maxPlots;

View File

@@ -1,24 +1,40 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisCommand implements CommandExecutor {
private MetropolisPlugin _plugin;
public MetropolisCommand(MetropolisPlugin plugin){
public MetropolisCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
sender.sendMessage("Metropolis: version "+ _plugin.pdf.getVersion());
sender.sendMessage("Metropolis: version " + _plugin.pdf.getVersion());
return true;
}
}

View File

@@ -1,32 +1,47 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisDebugGenerateTestHomesCommand implements CommandExecutor {
private MetropolisPlugin _plugin;
public MetropolisDebugGenerateTestHomesCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
try{
try {
int numHomes = Integer.parseInt(args[0]);
for(int i=1; i<= numHomes; i++){
for (int i = 1; i <= numHomes; i++) {
_plugin.generateHome(String.format("test%d", i));
}
return true;
}catch(NumberFormatException ex){
} catch (NumberFormatException ex) {
return false;
}
}
}

View File

@@ -1,18 +1,35 @@
package com.majinnaibu.bukkitplugins.metropolis.commands;
/*
This file is part of Metropolis.
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
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 {
private MetropolisPlugin _plugin;
public MetropolisFlagResetCommand(MetropolisPlugin plugin){
public MetropolisFlagResetCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@@ -29,8 +46,8 @@ public class MetropolisFlagResetCommand implements CommandExecutor {
cityRegion.setFlag(Flags.LAVA_FLOW, StateFlag.State.DENY);
cityRegion.setFlag(Flags.SNOW_FALL, StateFlag.State.DENY);
for(ProtectedRegion homeRegion: _plugin.regionManager.getRegions().values()){
if(homeRegion.getId().startsWith("h_")){
for (ProtectedRegion homeRegion : _plugin.regionManager.getRegions().values()) {
if (homeRegion.getId().startsWith("h_")) {
homeRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
homeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
homeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
@@ -38,16 +55,11 @@ public class MetropolisFlagResetCommand implements CommandExecutor {
homeRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
homeRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
homeRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
}
}
sender.sendMessage("Metropolis: flags have been reset");
return true;
}
}

View File

@@ -1,29 +1,46 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeAcquire implements CommandExecutor {
MetropolisPlugin _plugin;
public MetropolisHomeAcquire(MetropolisPlugin plugin){
public MetropolisHomeAcquire(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!(sender instanceof Player)){
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be used by players");
return false;
}
Player player = (Player) sender;
if(_plugin.getNumPlots(player.getUniqueId()) >= _plugin.getMaxPlots(player.getUniqueId())){
if (_plugin.getNumPlots(player.getUniqueId()) >= _plugin.getMaxPlots(player.getUniqueId())) {
sender.sendMessage("You cannot have any more plots");
return false;
}
@@ -31,5 +48,4 @@ public class MetropolisHomeAcquire implements CommandExecutor {
_plugin.assignPlot(player);
return true;
}
}

View File

@@ -1,60 +1,79 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class MetropolisHomeEvictCommand implements CommandExecutor {
MetropolisPlugin _plugin = null;
public MetropolisHomeEvictCommand(MetropolisPlugin plugin){
public MetropolisHomeEvictCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
//get the player and region
// get the player and region
String playerName = "";
if(args.length == 0){
if (args.length == 0) {
return false;
}
if(args.length >= 1){
if (args.length >= 1) {
playerName = args[0];
}
OfflinePlayer player = _plugin.getOfflinePlayer(playerName);
if(player == null){
sender.sendMessage(String.format("The requested player {%s}does not appear to exist.", playerName));
if (player == null) {
sender.sendMessage(
String.format("The requested player {%s}does not appear to exist.", playerName));
return false;
}
ProtectedRegion region = _plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId()));
if(region == null){
ProtectedRegion region =
_plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId()));
if (region == null) {
sender.sendMessage(String.format("The player {%s} has no home to be evicted from."));
return false;
}
//remove the player as owner and/or member of the region
// remove the player as owner and/or member of the region
region.getMembers().removePlayer(player.getUniqueId());
region.getOwners().removePlayer(player.getUniqueId());
//if the region has no owners delete the region
if(region.getMembers().size() == 0 && region.getOwners().size() == 0){
// if the region has no owners delete the region
if (region.getMembers().size() == 0 && region.getOwners().size() == 0) {
_plugin.removeRegion(region.getId());
}
_plugin.saveRegions();
//?optionally regen the region
//_plugin.worldEdit.getCommand("regen").execute(_plugin.getServer().getConsoleSender(), "regen", new String[]{});
// ?optionally regen the region
// _plugin.worldEdit.getCommand("regen").execute(_plugin.getServer().getConsoleSender(),
// "regen", new String[]{});
return true;
}
}

View File

@@ -1,23 +1,40 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.OfflinePlayer;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeGenerateCommand implements CommandExecutor {
private MetropolisPlugin _plugin;
public MetropolisHomeGenerateCommand(MetropolisPlugin plugin){
public MetropolisHomeGenerateCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(args.length < 1){
if (args.length < 1) {
return false;
}
@@ -32,5 +49,4 @@ public class MetropolisHomeGenerateCommand implements CommandExecutor {
return true;
}
}

View File

@@ -1,49 +1,66 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
public class MetropolisHomeGoCommand implements CommandExecutor {
MetropolisPlugin _plugin = null;
public MetropolisHomeGoCommand(MetropolisPlugin plugin){
public MetropolisHomeGoCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = null;
if(sender instanceof Player){
player = (Player)sender;
if (sender instanceof Player) {
player = (Player) sender;
if(args.length >= 1){
if(player.hasPermission("")){
if (args.length >= 1) {
if (player.hasPermission("")) {
player = _plugin.getPlayer(args[0]);
if(player == null){
if (player == null) {
sender.sendMessage(String.format("Unable to find player %s", args[0]));
return false;
}
}else{
} else {
sender.sendMessage("Permission denied");
return false;
}
}
}else{
if(args.length >= 1){
} else {
if (args.length >= 1) {
player = _plugin.getPlayer(args[0]);
if(player == null){
if (player == null) {
sender.sendMessage(String.format("Unable to find player %s", args[0]));
return false;
}
}else{
} else {
sender.sendMessage("You must be a player");
return false;
}
@@ -54,19 +71,20 @@ public class MetropolisHomeGoCommand implements CommandExecutor {
Location loc = null;
Location bedSpawn = player.getBedSpawnLocation();
if(home.contains(bedSpawn)){
if (home.contains(bedSpawn)) {
loc = bedSpawn;
}else {
} else {
loc = home.getViableSpawnLocation(_plugin.getWorld());
}
if(loc != null){
if (loc != null) {
player.teleport(loc);
}else{
if(sender == player){
} else {
if (sender == player) {
sender.sendMessage("There is no valid spawn location in your home");
}else{
sender.sendMessage(String.format("There is no valid spawn location in %s's home", player.getName()));
} else {
sender.sendMessage(
String.format("There is no valid spawn location in %s's home", player.getName()));
}
return false;
}

View File

@@ -1,25 +1,41 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
public class MetropolisHomeListCommand implements CommandExecutor {
private MetropolisPlugin _plugin;
public MetropolisHomeListCommand(MetropolisPlugin plugin){
public MetropolisHomeListCommand(MetropolisPlugin plugin) {
_plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for(Plot cityBlock : _plugin.getCityBlocks()){
for (Plot cityBlock : _plugin.getCityBlocks()) {
sender.sendMessage(String.format("%s", cityBlock.toFriendlyString()));
}
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class MetropolisHomeMoveCommand implements CommandExecutor {
MetropolisPlugin _plugin;
@@ -19,29 +36,29 @@ public class MetropolisHomeMoveCommand implements CommandExecutor {
OfflinePlayer player = null;
int newHomeNumber = 0;
if(sender instanceof OfflinePlayer){
player = (OfflinePlayer)sender;
if (sender instanceof OfflinePlayer) {
player = (OfflinePlayer) sender;
}
if(args.length == 1){
try{
if (args.length == 1) {
try {
newHomeNumber = Integer.parseInt(args[0]);
}catch(NumberFormatException ex){
} catch (NumberFormatException ex) {
return false;
}
}else if(args.length >= 2){
try{
} else if (args.length >= 2) {
try {
newHomeNumber = Integer.parseInt(args[0]);
}catch(NumberFormatException ex){
} catch (NumberFormatException ex) {
return false;
}
player = _plugin.getOfflinePlayer(args[1]);
}else{
} else {
return false;
}
if(player == null || !_plugin.homeExists(player.getUniqueId(), newHomeNumber)){
if (player == null || !_plugin.homeExists(player.getUniqueId(), newHomeNumber)) {
return false;
}
@@ -49,5 +66,4 @@ public class MetropolisHomeMoveCommand implements CommandExecutor {
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import com.majinnaibu.bukkitplugins.metropolis.Plot;
public class MetropolisPlotGoCommand implements CommandExecutor {
MetropolisPlugin _plugin;
@@ -20,30 +37,29 @@ public class MetropolisPlotGoCommand implements CommandExecutor {
Player player = null;
Plot plot = null;
if(sender instanceof Player){
if (sender instanceof Player) {
player = (Player) sender;
}
if(args.length == 1 && player != null){
if (args.length == 1 && player != null) {
plot = _plugin.getPlot(args[0]);
}else if(args.length >= 2){
} else if (args.length >= 2) {
player = _plugin.getPlayer(args[1]);
plot = _plugin.getPlot(args[0]);
}else{
} else {
return false;
}
if(plot == null || player == null){
if (plot == null || player == null) {
return false;
}
String errorMessage = _plugin.teleportPlayerToPlot(player, plot);
if(errorMessage != null){
if (errorMessage != null) {
sender.sendMessage(errorMessage);
return false;
}
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;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
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.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 {
MetropolisPlugin _plugin;
@@ -28,40 +45,43 @@ public class MetropolisPlotReserveCommand implements CommandExecutor {
int maxZ = 0;
Cuboid cuboid = new Cuboid();
if(sender instanceof Player && args.length == 1){
if (sender instanceof Player && args.length == 1) {
try {
Region selection = _plugin.worldEdit.getSession((Player) sender)
Region selection =
_plugin
.worldEdit
.getSession((Player) sender)
.getSelection(BukkitAdapter.adapt(_plugin.getWorld()));
cuboid = new Cuboid(selection);
} catch (IncompleteRegionException ex) {
sender.sendMessage("Select a WorldEdit region first.");
return false;
}
}else if(args.length == 7){
try{
} else if (args.length == 7) {
try {
minX = Integer.parseInt(args[1]);
minY = Integer.parseInt(args[2]);
minZ = Integer.parseInt(args[3]);
maxX = Integer.parseInt(args[4]);
maxY = Integer.parseInt(args[5]);
maxZ = Integer.parseInt(args[6]);
}catch(NumberFormatException ex){
} catch (NumberFormatException ex) {
return false;
}
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
}else if(args.length == 5){
try{
} else if (args.length == 5) {
try {
minX = Integer.parseInt(args[1]);
minY = 0;
minZ = Integer.parseInt(args[2]);
maxX = Integer.parseInt(args[3]);
maxY = _plugin.getWorld().getMaxHeight();
maxZ = Integer.parseInt(args[4]);
}catch(NumberFormatException ex){
} catch (NumberFormatException ex) {
return false;
}
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
}else{
} else {
return false;
}
@@ -72,5 +92,4 @@ public class MetropolisPlotReserveCommand implements CommandExecutor {
return true;
}
}

View File

@@ -1,21 +1,38 @@
/*
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;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
public class DebugListener implements Listener {
MetropolisPlugin _plugin;
public DebugListener(MetropolisPlugin plugin){
public DebugListener(MetropolisPlugin plugin) {
_plugin = plugin;
}
@EventHandler(priority=EventPriority.MONITOR)
public void onEvent(PlayerInteractEvent event){
//event.
@EventHandler(priority = EventPriority.MONITOR)
public void onEvent(PlayerInteractEvent event) {
// event.
}
}

View File

@@ -1,39 +1,73 @@
/*
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;
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.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
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 {
private MetropolisPlugin _plugin = null;
public PlayerJoinListener(MetropolisPlugin plugin){
public PlayerJoinListener(MetropolisPlugin plugin) {
_plugin = plugin;
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event){
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if(player == null){
if (player == null) {
return;
}
PlayerHome home = _plugin.getPlayerHome(player);
if(home==null){_plugin.getLogger().info("home is null");}
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) {
_plugin.getLogger().info("home is null");
} 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){
_plugin.getLogger().info(String.format("Metropolis: Unable to get or create home for player %s", player.getName()));
}else{
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()));
} else {
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;
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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Location;
import org.junit.jupiter.api.Test;
import com.sk89q.worldedit.math.BlockVector3;
class CuboidTest {
@Test
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;
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;
class CurrentHomesStoreTest {
@TempDir
File temporaryDirectory;
@TempDir File temporaryDirectory;
@Test
void roundTripsHomesByUuid() throws Exception {
@@ -33,7 +49,11 @@ class CurrentHomesStoreTest {
yaml.set("OldPlayerName", 2);
yaml.save(file);
assertEquals(Map.of(playerId, 2), CurrentHomesStore.load(file, name -> {
assertEquals(
Map.of(playerId, 2),
CurrentHomesStore.load(
file,
name -> {
assertEquals("OldPlayerName", name);
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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import com.sk89q.worldedit.math.BlockVector3;
import org.junit.jupiter.api.Test;
class PlayerHomeTest {
@Test
void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
PlayerHome home = new PlayerHome(
playerId,
"PlayerName",
2,
BlockVector3.at(1, 2, 3),
BlockVector3.at(4, 5, 6));
PlayerHome home =
new PlayerHome(
playerId, "PlayerName", 2, BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
assertEquals(playerId, home.getPlayerId());
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;
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;
import static org.junit.jupiter.api.Assertions.assertTrue;
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.never;
import static org.mockito.Mockito.verify;
@@ -9,12 +26,12 @@ import static org.mockito.Mockito.when;
import java.util.UUID;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.junit.jupiter.api.Test;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
class MetropolisHomeAcquireTest {
@Test
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;
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.verifyNoInteractions;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
class MetropolisPlotReserveCommandTest {
@Test
void reservesCoordinatesFromAllSixArguments() {
@@ -24,7 +41,9 @@ class MetropolisPlotReserveCommandTest {
Command command = mock(Command.class);
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);
verify(plugin).reserveCuboid(eq("north"), cuboid.capture());
@@ -43,7 +62,9 @@ class MetropolisPlotReserveCommandTest {
Command command = mock(Command.class);
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);
}
}

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;
import static org.mockito.ArgumentMatchers.contains;
@@ -7,14 +24,14 @@ import static org.mockito.Mockito.when;
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.PlayerHome;
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 {
@Test
void tellsJoiningPlayerTheirHomeBounds() {
@@ -23,7 +40,9 @@ class PlayerJoinListenerTest {
PlayerJoinEvent event = mock(PlayerJoinEvent.class);
when(event.getPlayer()).thenReturn(player);
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"),
"PlayerName",
1,