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;
@@ -15,110 +32,114 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class MetropolisServerIntegrationTest { class MetropolisServerIntegrationTest {
@Test @Test
void runningPaperLoadsMetropolis() throws IOException { void runningPaperLoadsMetropolis() throws IOException {
String installedPlugins; String installedPlugins;
try (RconClient rcon = connectToConfiguredServer()) { try (RconClient rcon = connectToConfiguredServer()) {
installedPlugins = rcon.execute("plugins"); installedPlugins = rcon.execute("plugins");
} }
assertTrue(installedPlugins.contains("Metropolis"), installedPlugins); assertTrue(installedPlugins.contains("Metropolis"), installedPlugins);
} }
@Test @Test
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 =
assertTrue(response.contains("Reserved plot region " + regionId), 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")); 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 =
.resolve(worldName) serverDirectory
.resolve("regions.yml"); .resolve("plugins/WorldGuard/worlds")
YamlConfiguration regions = YamlConfiguration.loadConfiguration(regionsFile.toFile()); .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 { private static RconClient connectToConfiguredServer() throws IOException {
String host = requiredEnvironment("METROPOLIS_RCON_HOST"); String host = requiredEnvironment("METROPOLIS_RCON_HOST");
int port = Integer.parseInt(requiredEnvironment("METROPOLIS_RCON_PORT")); int port = Integer.parseInt(requiredEnvironment("METROPOLIS_RCON_PORT"));
String password = requiredEnvironment("METROPOLIS_RCON_PASSWORD"); String password = requiredEnvironment("METROPOLIS_RCON_PASSWORD");
return new RconClient(host, port, password); return new RconClient(host, port, password);
} }
private static String requiredEnvironment(String name) { private static String requiredEnvironment(String name) {
String value = System.getenv(name); String value = System.getenv(name);
if (value == null || value.isBlank()) { if (value == null || value.isBlank()) {
throw new IllegalStateException("Set " + name + " to run integrationTest."); throw new IllegalStateException("Set " + name + " to run integrationTest.");
} }
return value; return value;
} }
private static final class RconClient implements AutoCloseable { private static final class RconClient implements AutoCloseable {
private final Socket socket = new Socket(); private final Socket socket = new Socket();
private final DataInputStream input; private final DataInputStream input;
private final DataOutputStream output; private final DataOutputStream output;
private int requestId = 1; private int requestId = 1;
private RconClient(String host, int port, String password) throws IOException { private RconClient(String host, int port, String password) throws IOException {
socket.connect(new InetSocketAddress(host, port), 5000); socket.connect(new InetSocketAddress(host, port), 5000);
socket.setSoTimeout(5000); socket.setSoTimeout(5000);
input = new DataInputStream(socket.getInputStream()); input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream()); output = new DataOutputStream(socket.getOutputStream());
int authId = requestId++; int authId = requestId++;
Packet response = send(authId, 3, password); Packet response = send(authId, 3, password);
if (response.id != authId) { if (response.id != authId) {
throw new IOException("RCON authentication failed."); throw new IOException("RCON authentication failed.");
} }
} }
private String execute(String command) throws IOException { private String execute(String command) throws IOException {
return send(requestId++, 2, command).payload; return send(requestId++, 2, command).payload;
} }
private Packet send(int id, int type, String payload) throws IOException { private Packet send(int id, int type, String payload) throws IOException {
byte[] data = payload.getBytes(StandardCharsets.UTF_8); byte[] data = payload.getBytes(StandardCharsets.UTF_8);
writeLittleEndianInt(data.length + 10); writeLittleEndianInt(data.length + 10);
writeLittleEndianInt(id); writeLittleEndianInt(id);
writeLittleEndianInt(type); writeLittleEndianInt(type);
output.write(data); output.write(data);
output.writeByte(0); output.writeByte(0);
output.writeByte(0); output.writeByte(0);
output.flush(); output.flush();
int length = readLittleEndianInt(); int length = readLittleEndianInt();
byte[] packet = input.readNBytes(length); byte[] packet = input.readNBytes(length);
if (packet.length != length || length < 10) { if (packet.length != length || length < 10) {
throw new IOException("Received an invalid RCON packet."); throw new IOException("Received an invalid RCON packet.");
} }
int responseId = littleEndianInt(packet, 0); int responseId = littleEndianInt(packet, 0);
String response = new String(packet, 8, length - 10, StandardCharsets.UTF_8); String response = new String(packet, 8, length - 10, StandardCharsets.UTF_8);
return new Packet(responseId, response); return new Packet(responseId, response);
} }
private void writeLittleEndianInt(int value) throws IOException { private void writeLittleEndianInt(int value) throws IOException {
output.writeInt(Integer.reverseBytes(value)); output.writeInt(Integer.reverseBytes(value));
} }
private int readLittleEndianInt() throws IOException { private int readLittleEndianInt() throws IOException {
return Integer.reverseBytes(input.readInt()); return Integer.reverseBytes(input.readInt());
} }
private static int littleEndianInt(byte[] bytes, int offset) { private static int littleEndianInt(byte[] bytes, int offset) {
return (bytes[offset] & 0xff) return (bytes[offset] & 0xff)
| ((bytes[offset + 1] & 0xff) << 8) | ((bytes[offset + 1] & 0xff) << 8)
| ((bytes[offset + 2] & 0xff) << 16) | ((bytes[offset + 2] & 0xff) << 16)
| (bytes[offset + 3] << 24); | (bytes[offset + 3] << 24);
} }
@Override @Override
public void close() throws IOException { public void close() throws IOException {
socket.close(); socket.close();
} }
} }
private record Packet(int id, String payload) {} private record Packet(int id, String payload) {}
} }

View File

@@ -1,220 +1,265 @@
/*
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;
public int minX; public int minX;
public int minY; public int minY;
public int minZ; public int minZ;
public int maxX; public int maxX;
public int maxY; public int maxY;
public int maxZ; public int maxZ;
public int getId(){ public int getId() {
return id; return id;
} }
public void setId(int id){ public void setId(int id) {
this.id = 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.minX = minX;
this.minY = minY; this.minY = minY;
this.minZ = minZ; this.minZ = minZ;
this.maxX = maxX; this.maxX = maxX;
this.maxY = maxY; this.maxY = maxY;
this.maxZ = maxZ; this.maxZ = maxZ;
} }
public Cuboid(BlockVector3 min, BlockVector3 max) { public Cuboid(BlockVector3 min, BlockVector3 max) {
this.minX = min.x(); this.minX = min.x();
this.minY = min.y(); this.minY = min.y();
this.minZ = min.z(); this.minZ = min.z();
this.maxX = max.x(); this.maxX = max.x();
this.maxY = max.y(); this.maxY = max.y();
this.maxZ = max.z(); this.maxZ = max.z();
} }
public Cuboid() { public Cuboid() {
this.minX = 0; this.minX = 0;
this.minY = 0; this.minY = 0;
this.minZ = 0; this.minZ = 0;
this.maxX = 0; this.maxX = 0;
this.maxY = 0; this.maxY = 0;
this.maxZ = 0; this.maxZ = 0;
} }
public Cuboid(Region selection) { public Cuboid(Region selection) {
this.minX = selection.getMinimumPoint().x(); this.minX = selection.getMinimumPoint().x();
this.minY = selection.getMinimumPoint().y(); this.minY = selection.getMinimumPoint().y();
this.minZ = selection.getMinimumPoint().z(); this.minZ = selection.getMinimumPoint().z();
this.maxX = selection.getMaximumPoint().x(); this.maxX = selection.getMaximumPoint().x();
this.maxY = selection.getMaximumPoint().y(); this.maxY = selection.getMaximumPoint().y();
this.maxZ = selection.getMaximumPoint().z(); this.maxZ = selection.getMaximumPoint().z();
} }
public BlockVector3 getMin(){ public BlockVector3 getMin() {
return BlockVector3.at(minX, minY, minZ); return BlockVector3.at(minX, minY, minZ);
} }
public BlockVector3 getMax(){ public BlockVector3 getMax() {
return BlockVector3.at(maxX, maxY, maxZ); return BlockVector3.at(maxX, maxY, maxZ);
} }
@Override @Override
public int compareTo(Cuboid o) { public int compareTo(Cuboid o) {
BlockVector3 min = getMin(); BlockVector3 min = getMin();
BlockVector3 otherMin = o.getMin(); BlockVector3 otherMin = o.getMin();
if(min.x() < otherMin.x()){ if (min.x() < otherMin.x()) {
return -1; return -1;
}else if(min.x() > otherMin.x()){ } else if (min.x() > otherMin.x()) {
return 1; return 1;
}else if(min.z() < otherMin.z()){ } else if (min.z() < otherMin.z()) {
return -1; return -1;
}else if(min.z() > otherMin.z()){ } else if (min.z() > otherMin.z()) {
return 1; return 1;
}else if(min.y() < otherMin.y()){ } else if (min.y() < otherMin.y()) {
return -1; return -1;
}else if(min.y() > otherMin.y()){ } else if (min.y() > otherMin.y()) {
return 1; return 1;
}else{ } else {
return 0; return 0;
} }
} }
public static int compareBlockVectors(BlockVector3 v1, BlockVector3 v2){ public static int compareBlockVectors(BlockVector3 v1, BlockVector3 v2) {
if(v1 == null){ if (v1 == null) {
if(v2 == null){ if (v2 == null) {
return 0; return 0;
}else{ } else {
return -1; return -1;
} }
}else if(v2 == null){ } else if (v2 == null) {
return 1; return 1;
} }
if(v1.x() < v2.x()){ if (v1.x() < v2.x()) {
return -1; return -1;
}else if(v1.x() > v2.x()){ } else if (v1.x() > v2.x()) {
return 1; return 1;
}else if(v1.z() < v2.z()){ } else if (v1.z() < v2.z()) {
return -1; return -1;
}else if(v1.z() > v2.z()){ } else if (v1.z() > v2.z()) {
return 1; return 1;
}else if(v1.y() < v2.y()){ } else if (v1.y() < v2.y()) {
return -1; return -1;
}else if(v1.y() > v2.y()){ } else if (v1.y() > v2.y()) {
return 1; return 1;
}else{ } else {
return 0; return 0;
} }
} }
public static boolean isBlockLessThan(BlockVector3 v1, BlockVector3 v2) { public static boolean isBlockLessThan(BlockVector3 v1, BlockVector3 v2) {
return compareBlockVectors(v1, v2) < 0; return compareBlockVectors(v1, v2) < 0;
} }
public Cuboid inset(int amount){ public Cuboid inset(int amount) {
return inset(amount, amount, 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); return inset(x, 0, z);
} }
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 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) { public int getMinX() {
return outset(amount, amount, amount); return minX;
} }
public Cuboid outset(int x, int z){ public void setMinX(int minX) {
return outset(x, 0, z); this.minX = minX;
} }
public Cuboid outset(int x, int y, int z) { public int getMinY() {
return new Cuboid(this.minX - x, this.minY - y, this.minZ - z, this.maxX + x, this.maxY + y, this.maxZ + z); return minY;
} }
public int getCenterX(){ public void setMinY(int minY) {
return (this.minX + this.maxX) /2; this.minY = minY;
} }
public int getCenterY(){ public int getMinZ() {
return (this.minY + this.maxY)/2; return minZ;
} }
public int getCenterZ(){ public void setMinZ(int minZ) {
return (this.minZ + this.maxZ)/2; this.minZ = minZ;
} }
public boolean intersects(Cuboid other) { public int getMaxX() {
if (this.maxX >= other.minX && this.minX <= other.maxX) return maxX;
{ }
if (this.maxZ >= other.minZ && this.minZ <= other.maxZ)
{ public void setMaxX(int maxX) {
if (this.maxY >= other.minY && this.minY <= other.maxY) this.maxX = maxX;
{ }
return true;
} public int getMaxY() {
else return maxY;
{ }
return false;
} public void setMaxY(int maxY) {
} this.maxY = maxY;
else }
{
return false; 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) {
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);
}
public int getCenterX() {
return (this.minX + this.maxX) / 2;
}
public int getCenterY() {
return (this.minY + this.maxY) / 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) {
return true;
} else {
return false;
} }
else } else {
{ return false;
return false; }
} } else {
} return false;
}
}
public boolean contains(Location bedSpawn) { 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; return false;
}else if(this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()){ } else if (this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()) {
return false; return false;
}else if(this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()){ } else if (this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()) {
return false; return false;
} }
return true;
}
@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 true;
}
@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);
}
} }

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;
@@ -11,40 +28,40 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
final class CurrentHomesStore { final class CurrentHomesStore {
private CurrentHomesStore() {} private CurrentHomesStore() {}
static Map<UUID, Integer> load(File file, Function<String, UUID> legacyOwnerResolver) static Map<UUID, Integer> load(File file, Function<String, UUID> legacyOwnerResolver)
throws IOException, InvalidConfigurationException { throws IOException, InvalidConfigurationException {
Map<UUID, Integer> homesByOwner = new HashMap<>(); Map<UUID, Integer> homesByOwner = new HashMap<>();
if (!file.exists()) { if (!file.exists()) {
return homesByOwner; return homesByOwner;
} }
YamlConfiguration yaml = new YamlConfiguration(); YamlConfiguration yaml = new YamlConfiguration();
yaml.load(file); yaml.load(file);
for (String ownerKey : yaml.getKeys(false)) { for (String ownerKey : yaml.getKeys(false)) {
UUID ownerId; UUID ownerId;
try { try {
ownerId = UUID.fromString(ownerKey); ownerId = UUID.fromString(ownerKey);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ownerId = legacyOwnerResolver.apply(ownerKey); ownerId = legacyOwnerResolver.apply(ownerKey);
} }
int homeNumber = yaml.getInt(ownerKey, 0); int homeNumber = yaml.getInt(ownerKey, 0);
if (ownerId != null && homeNumber > 0) { if (ownerId != null && homeNumber > 0) {
homesByOwner.put(ownerId, homeNumber); homesByOwner.put(ownerId, homeNumber);
} }
} }
return homesByOwner; return homesByOwner;
} }
static void save(File file, Map<UUID, Integer> homesByOwner) throws IOException { static void save(File file, Map<UUID, Integer> homesByOwner) throws IOException {
File parent = file.getParentFile(); File parent = file.getParentFile();
if (parent != null) { if (parent != null) {
parent.mkdirs(); parent.mkdirs();
} }
YamlConfiguration yaml = new YamlConfiguration(); YamlConfiguration yaml = new YamlConfiguration();
homesByOwner.forEach((ownerId, homeNumber) -> yaml.set(ownerId.toString(), homeNumber)); homesByOwner.forEach((ownerId, homeNumber) -> yaml.set(ownerId.toString(), homeNumber));
yaml.save(file); yaml.save(file);
} }
} }

View File

@@ -1,107 +1,144 @@
/*
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;
public class PlayerHome extends Plot{ import org.bukkit.Bukkit;
private UUID playerId; import org.bukkit.OfflinePlayer;
private String 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 class PlayerHome extends Plot {
private UUID playerId;
private String playerName;
public PlayerHome(UUID ownerId, String ownerName, int homeNumber, BlockVector3 min, BlockVector3 max) { public UUID getPlayerId() {
super(String.format("h_%d_%s", homeNumber, ownerId), min, max); return this.playerId;
this.playerId = ownerId; }
this.playerName = ownerName;
this.number = homeNumber;
}
public PlayerHome() { public String getPlayerName() {
this.playerId = null; return this.playerName;
this.playerName = ""; }
}
public PlayerHome(ProtectedRegion homeRegion){ public void setPlayerName(String playerName) {
String regionName = homeRegion.getId(); this.playerName = playerName;
if (!regionName.startsWith("h_")) { }
throw new IllegalArgumentException("Not a Metropolis home region: " + regionName);
}
String regionOwner = regionName.substring(2);
int separator = regionOwner.indexOf('_');
if (separator > 0) {
try {
this.number = Integer.parseInt(regionOwner.substring(0, separator));
regionOwner = regionOwner.substring(separator + 1);
} catch (NumberFormatException ex) {
this.number = 1;
}
} else {
this.number = 1;
}
try {
this.playerId = UUID.fromString(regionOwner);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerId);
this.playerName = offlinePlayer.getName() == null ? regionOwner : offlinePlayer.getName();
} catch (IllegalArgumentException ex) {
Set<UUID> ownerIds = homeRegion.getOwners().getUniqueIds();
this.playerId = ownerIds.isEmpty()
? Bukkit.getOfflinePlayer(regionOwner).getUniqueId()
: ownerIds.iterator().next();
this.playerName = regionOwner;
}
setCuboid(new Cuboid(homeRegion.getMinimumPoint(), homeRegion.getMaximumPoint()));
}
@Override private int number;
public boolean equals(Object other) {
if(!(other instanceof PlayerHome)){
return super.equals(other);
}
PlayerHome otherPlayerHome = (PlayerHome)other; 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;
this.number = homeNumber;
}
if(!java.util.Objects.equals(this.playerId, otherPlayerHome.playerId)){ public PlayerHome() {
return false; this.playerId = null;
} this.playerName = "";
}
if(!getCuboid().equals(otherPlayerHome.getCuboid())){ public PlayerHome(ProtectedRegion homeRegion) {
return false; String regionName = homeRegion.getId();
} if (!regionName.startsWith("h_")) {
throw new IllegalArgumentException("Not a Metropolis home region: " + regionName);
}
String regionOwner = regionName.substring(2);
int separator = regionOwner.indexOf('_');
if (separator > 0) {
try {
this.number = Integer.parseInt(regionOwner.substring(0, separator));
regionOwner = regionOwner.substring(separator + 1);
} catch (NumberFormatException ex) {
this.number = 1;
}
} else {
this.number = 1;
}
try {
this.playerId = UUID.fromString(regionOwner);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerId);
this.playerName = offlinePlayer.getName() == null ? regionOwner : offlinePlayer.getName();
} catch (IllegalArgumentException ex) {
Set<UUID> ownerIds = homeRegion.getOwners().getUniqueIds();
this.playerId =
ownerIds.isEmpty()
? Bukkit.getOfflinePlayer(regionOwner).getUniqueId()
: ownerIds.iterator().next();
this.playerName = regionOwner;
}
setCuboid(new Cuboid(homeRegion.getMinimumPoint(), homeRegion.getMaximumPoint()));
}
return true; @Override
} public boolean equals(Object other) {
if (!(other instanceof PlayerHome)) {
return super.equals(other);
}
public String toFriendlyString() { PlayerHome otherPlayerHome = (PlayerHome) other;
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())); if (!java.util.Objects.equals(this.playerId, otherPlayerHome.playerId)) {
return false;
}
return sb.toString(); if (!getCuboid().equals(otherPlayerHome.getCuboid())) {
} return false;
}
public static PlayerHome get(ProtectedRegion homeRegion){ return true;
if(homeRegion instanceof ProtectedCuboidRegion){ }
return new PlayerHome((ProtectedCuboidRegion) homeRegion);
}else{
return null;
}
}
public Integer getNumber() { public String toFriendlyString() {
return number; StringBuilder sb = new StringBuilder();
}
public void setNumber(int number){ sb.append(
this.number = number; 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) {
return new PlayerHome((ProtectedCuboidRegion) homeRegion);
} else {
return null;
}
}
public Integer getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
} }

View File

@@ -1,19 +1,36 @@
/*
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;
final class PlayerLookup { final class PlayerLookup {
private PlayerLookup() {} private PlayerLookup() {}
static Player findOnline(String requestedName, Iterable<? extends Player> onlinePlayers) { static Player findOnline(String requestedName, Iterable<? extends Player> onlinePlayers) {
if (requestedName == null) { if (requestedName == null) {
return null; return null;
} }
for (Player player : onlinePlayers) { for (Player player : onlinePlayers) {
if (requestedName.equalsIgnoreCase(player.getName())) { if (requestedName.equalsIgnoreCase(player.getName())) {
return player; return player;
} }
} }
return null; return null;
} }
} }

View File

@@ -1,119 +1,164 @@
/*
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; public class Plot implements Comparable<Plot> {
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; private int _id;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class Plot implements Comparable<Plot>{ public int getId() {
private int _id; return _id;
public int getId(){return _id;} }
public void setId(int id){_id = id;}
private Cuboid _cuboid; public void setId(int id) {
public Cuboid getCuboid(){return _cuboid;} _id = id;
public void setCuboid(Cuboid cuboid){_cuboid = cuboid;} }
private String _regionName; private Cuboid _cuboid;
public String getRegionName(){return _regionName;}
public void setRegionName(String regionName){_regionName = regionName;}
public Plot(String regionName, BlockVector3 min, BlockVector3 max){ public Cuboid getCuboid() {
_cuboid = new Cuboid(min, max); return _cuboid;
_regionName = regionName; }
}
public Plot(ProtectedCuboidRegion cuboid){ public void setCuboid(Cuboid cuboid) {
_cuboid = new Cuboid(cuboid.getMinimumPoint(), cuboid.getMaximumPoint()); _cuboid = cuboid;
_regionName = cuboid.getId(); }
}
public Plot(){ private String _regionName;
_cuboid = new Cuboid();
_regionName = "";
}
public BlockVector3 getPlotMin(int roadWidth) { public String getRegionName() {
return BlockVector3.at(_cuboid.minX - roadWidth/2, _cuboid.minY, _cuboid.minZ - roadWidth/2); return _regionName;
} }
public int getRow(int roadWidth, int plotSizeZ){ public void setRegionName(String regionName) {
BlockVector3 min = getPlotMin(roadWidth); _regionName = regionName;
return min.z() / plotSizeZ; }
}
public int getCol(int roadWidth, int plotSizeX){ public Plot(String regionName, BlockVector3 min, BlockVector3 max) {
return getPlotMin(roadWidth).x() / plotSizeX; _cuboid = new Cuboid(min, max);
} _regionName = regionName;
}
@Override public Plot(ProtectedCuboidRegion cuboid) {
public boolean equals(Object other) { _cuboid = new Cuboid(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
if(!(other instanceof Plot)){ _regionName = cuboid.getId();
return super.equals(other); }
}
Plot otherPlayerHome = (Plot)other; public Plot() {
_cuboid = new Cuboid();
_regionName = "";
}
if(!getCuboid().equals(otherPlayerHome.getCuboid())){ public BlockVector3 getPlotMin(int roadWidth) {
return false; return BlockVector3.at(
} _cuboid.minX - roadWidth / 2, _cuboid.minY, _cuboid.minZ - roadWidth / 2);
}
return true; public int getRow(int roadWidth, int plotSizeZ) {
} BlockVector3 min = getPlotMin(roadWidth);
return min.z() / plotSizeZ;
}
@Override public int getCol(int roadWidth, int plotSizeX) {
public int compareTo(Plot another) { return getPlotMin(roadWidth).x() / plotSizeX;
return getCuboid().compareTo(another.getCuboid()); }
}
@Override @Override
public String toString(){ public boolean equals(Object other) {
StringBuilder sb = new StringBuilder(); if (!(other instanceof Plot)) {
return super.equals(other);
}
sb.append(String.format("{PlayerHome }")); Plot otherPlayerHome = (Plot) other;
return sb.toString(); if (!getCuboid().equals(otherPlayerHome.getCuboid())) {
} return false;
}
public static Plot get(ProtectedRegion region){ return true;
if(region instanceof ProtectedCuboidRegion){ }
return new Plot((ProtectedCuboidRegion) region);
}else{
return null;
}
}
public String toFriendlyString() { @Override
StringBuilder sb = new StringBuilder(); public int compareTo(Plot another) {
return getCuboid().compareTo(another.getCuboid());
}
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())); @Override
public String toString() {
StringBuilder sb = new StringBuilder();
return sb.toString(); sb.append(String.format("{PlayerHome }"));
}
public boolean contains(Location bedSpawn) { return sb.toString();
return _cuboid.contains(bedSpawn); }
}
public Location getViableSpawnLocation(World world) { public static Plot get(ProtectedRegion region) {
Cuboid cuboid = getCuboid(); if (region instanceof ProtectedCuboidRegion) {
for(int y=cuboid.maxY-1; y>= cuboid.minY; y--){ return new Plot((ProtectedCuboidRegion) region);
for(int x=cuboid.minX; x<= cuboid.maxX; x++){ } else {
for(int z=cuboid.minZ; z<= cuboid.maxZ; z++){ return null;
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){
return new Location(world, x, y, z);
}
}
}
}
return null; public String toFriendlyString() {
} StringBuilder sb = new StringBuilder();
sb.append(
String.format(
"Metropolis Reserved Plot {min: (%d, %d, %d) max: (%d, %d, %d)}",
getCuboid().getMinX(),
getCuboid().getMinY(),
getCuboid().getMinZ(),
getCuboid().getMaxX(),
getCuboid().getMaxY(),
getCuboid().getMaxZ()));
return sb.toString();
}
public boolean contains(Location bedSpawn) {
return _cuboid.contains(bedSpawn);
}
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++) {
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) {
return new Location(world, x, y, z);
}
}
}
}
return null;
}
} }

View File

@@ -1,17 +1,42 @@
/*
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 {
private String _username; private String _username;
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 UserOverride(String username, int plotMultiplier, int maxPlots){ public int getPlotMultiplier() {
_username = username; return _plotMultiplier;
_plotMultiplier = plotMultiplier; }
_maxPlots = maxPlots;
} 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; 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;
public MetropolisCommand(MetropolisPlugin plugin){ public MetropolisCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { 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;
}
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; 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
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
@Override try {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { int numHomes = Integer.parseInt(args[0]);
try{ for (int i = 1; i <= numHomes; i++) {
int numHomes = Integer.parseInt(args[0]); _plugin.generateHome(String.format("test%d", i));
for(int i=1; i<= numHomes; i++){ }
_plugin.generateHome(String.format("test%d", i));
}
return true;
}catch(NumberFormatException ex){
return false;
}
}
return true;
} catch (NumberFormatException ex) {
return false;
}
}
} }

View File

@@ -1,53 +1,65 @@
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;
public MetropolisFlagResetCommand(MetropolisPlugin plugin){ public MetropolisFlagResetCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
ProtectedRegion cityRegion = _plugin.regionManager.getRegion("City"); ProtectedRegion cityRegion = _plugin.regionManager.getRegion("City");
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);
cityRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY); cityRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
cityRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY); cityRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY);
cityRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY); cityRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
cityRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY); cityRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
cityRegion.setFlag(Flags.TNT, StateFlag.State.DENY); cityRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
cityRegion.setFlag(Flags.LAVA_FLOW, StateFlag.State.DENY); cityRegion.setFlag(Flags.LAVA_FLOW, StateFlag.State.DENY);
cityRegion.setFlag(Flags.SNOW_FALL, StateFlag.State.DENY); cityRegion.setFlag(Flags.SNOW_FALL, StateFlag.State.DENY);
for(ProtectedRegion homeRegion: _plugin.regionManager.getRegions().values()){ for (ProtectedRegion homeRegion : _plugin.regionManager.getRegions().values()) {
if(homeRegion.getId().startsWith("h_")){ if (homeRegion.getId().startsWith("h_")) {
homeRegion.setFlag(Flags.PVP, StateFlag.State.DENY); homeRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
homeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY); homeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
homeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY); homeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
homeRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY); homeRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY);
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,35 +1,51 @@
/*
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;
public MetropolisHomeAcquire(MetropolisPlugin plugin){ public MetropolisHomeAcquire(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { 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"); sender.sendMessage("This command can only be used by players");
return false; return false;
} }
Player player = (Player) sender; 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"); sender.sendMessage("You cannot have any more plots");
return false; return false;
} }
_plugin.assignPlot(player);
return true;
}
_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; 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;
public MetropolisHomeEvictCommand(MetropolisPlugin plugin){ public MetropolisHomeEvictCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
//get the player and region // get the player and region
String playerName = ""; String playerName = "";
if(args.length == 0){ if (args.length == 0) {
return false; return false;
} }
if(args.length >= 1){ if (args.length >= 1) {
playerName = args[0]; playerName = args[0];
} }
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(
return false; String.format("The requested player {%s}does not appear to exist.", playerName));
} return false;
}
ProtectedRegion region = _plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId())); ProtectedRegion region =
if(region == null){ _plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId()));
sender.sendMessage(String.format("The player {%s} has no home to be evicted from.")); if (region == null) {
return false; 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.getMembers().removePlayer(player.getUniqueId());
region.getOwners().removePlayer(player.getUniqueId()); region.getOwners().removePlayer(player.getUniqueId());
//if the region has no owners delete the region // if the region has no owners delete the region
if(region.getMembers().size() == 0 && region.getOwners().size() == 0){ if (region.getMembers().size() == 0 && region.getOwners().size() == 0) {
_plugin.removeRegion(region.getId()); _plugin.removeRegion(region.getId());
} }
_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,36 +1,52 @@
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.OfflinePlayer; (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 org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class MetropolisHomeGenerateCommand implements CommandExecutor { public class MetropolisHomeGenerateCommand implements CommandExecutor {
private MetropolisPlugin _plugin; private MetropolisPlugin _plugin;
public MetropolisHomeGenerateCommand(MetropolisPlugin plugin){ public MetropolisHomeGenerateCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(args.length < 1){ if (args.length < 1) {
return false; return false;
} }
OfflinePlayer player = _plugin.getOfflinePlayer(args[0]); OfflinePlayer player = _plugin.getOfflinePlayer(args[0]);
if (player == null) { if (player == null) {
sender.sendMessage("Unable to find player " + args[0]); sender.sendMessage("Unable to find player " + args[0]);
return false; return false;
} }
_plugin.generateHome(player); _plugin.generateHome(player);
sender.sendMessage("[Metropolis] Home generated for " + args[0]); sender.sendMessage("[Metropolis] Home generated for " + args[0]);
return true;
}
return true;
}
} }

View File

@@ -1,76 +1,94 @@
/*
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;
public MetropolisHomeGoCommand(MetropolisPlugin plugin){ public MetropolisHomeGoCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = null; Player player = null;
if(sender instanceof Player){ if (sender instanceof Player) {
player = (Player)sender; player = (Player) sender;
if(args.length >= 1){ if (args.length >= 1) {
if(player.hasPermission("")){ if (player.hasPermission("")) {
player = _plugin.getPlayer(args[0]); player = _plugin.getPlayer(args[0]);
if(player == null){ if (player == null) {
sender.sendMessage(String.format("Unable to find player %s", args[0])); sender.sendMessage(String.format("Unable to find player %s", args[0]));
return false; return false;
} }
}else{ } else {
sender.sendMessage("Permission denied"); sender.sendMessage("Permission denied");
return false; return false;
} }
} }
}else{ } else {
if(args.length >= 1){ if (args.length >= 1) {
player = _plugin.getPlayer(args[0]); player = _plugin.getPlayer(args[0]);
if(player == null){ if (player == null) {
sender.sendMessage(String.format("Unable to find player %s", args[0])); sender.sendMessage(String.format("Unable to find player %s", args[0]));
return false; return false;
} }
}else{ } else {
sender.sendMessage("You must be a player"); sender.sendMessage("You must be a player");
return false; return false;
} }
} }
PlayerHome home = _plugin.getPlayerHome(player); PlayerHome home = _plugin.getPlayerHome(player);
Location loc = null; Location loc = null;
Location bedSpawn = player.getBedSpawnLocation(); Location bedSpawn = player.getBedSpawnLocation();
if(home.contains(bedSpawn)){ if (home.contains(bedSpawn)) {
loc = bedSpawn; loc = bedSpawn;
}else { } else {
loc = home.getViableSpawnLocation(_plugin.getWorld()); loc = home.getViableSpawnLocation(_plugin.getWorld());
} }
if(loc != null){ if (loc != null) {
player.teleport(loc); player.teleport(loc);
}else{ } else {
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;
}
return true; return true;
} }
} }

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; 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;
public MetropolisHomeListCommand(MetropolisPlugin plugin){ public MetropolisHomeListCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for(Plot cityBlock : _plugin.getCityBlocks()){
sender.sendMessage(String.format("%s", cityBlock.toFriendlyString()));
}
return true;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (Plot cityBlock : _plugin.getCityBlocks()) {
sender.sendMessage(String.format("%s", cityBlock.toFriendlyString()));
}
return true;
}
} }

View File

@@ -1,53 +1,69 @@
/*
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;
public MetropolisHomeMoveCommand(MetropolisPlugin plugin) { public MetropolisHomeMoveCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
OfflinePlayer player = null; OfflinePlayer player = null;
int newHomeNumber = 0; int newHomeNumber = 0;
if(sender instanceof OfflinePlayer){ if (sender instanceof OfflinePlayer) {
player = (OfflinePlayer)sender; player = (OfflinePlayer) sender;
} }
if(args.length == 1){ if (args.length == 1) {
try{ try {
newHomeNumber = Integer.parseInt(args[0]); newHomeNumber = Integer.parseInt(args[0]);
}catch(NumberFormatException ex){ } catch (NumberFormatException ex) {
return false; return false;
} }
}else if(args.length >= 2){ } else if (args.length >= 2) {
try{ try {
newHomeNumber = Integer.parseInt(args[0]); newHomeNumber = Integer.parseInt(args[0]);
}catch(NumberFormatException ex){ } catch (NumberFormatException ex) {
return false; return false;
} }
player = _plugin.getOfflinePlayer(args[1]); player = _plugin.getOfflinePlayer(args[1]);
}else{ } else {
return false; return false;
} }
if(player == null || !_plugin.homeExists(player.getUniqueId(), newHomeNumber)){ if (player == null || !_plugin.homeExists(player.getUniqueId(), newHomeNumber)) {
return false; return false;
} }
_plugin.setHome(player.getUniqueId(), newHomeNumber); _plugin.setHome(player.getUniqueId(), newHomeNumber);
return true;
}
return true;
}
} }

View File

@@ -1,49 +1,65 @@
/*
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;
public MetropolisPlotGoCommand(MetropolisPlugin plugin) { public MetropolisPlotGoCommand(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = null; Player player = null;
Plot plot = null; Plot plot = null;
if(sender instanceof Player){ if (sender instanceof Player) {
player = (Player) sender; player = (Player) sender;
} }
if(args.length == 1 && player != null){ if (args.length == 1 && player != null) {
plot = _plugin.getPlot(args[0]); plot = _plugin.getPlot(args[0]);
}else if(args.length >= 2){ } else if (args.length >= 2) {
player = _plugin.getPlayer(args[1]); player = _plugin.getPlayer(args[1]);
plot = _plugin.getPlot(args[0]); plot = _plugin.getPlot(args[0]);
}else{ } else {
return false; return false;
} }
if(plot == null || player == null){ if (plot == null || player == null) {
return false; return false;
} }
String errorMessage = _plugin.teleportPlayerToPlot(player, plot); String errorMessage = _plugin.teleportPlayerToPlot(player, plot);
if(errorMessage != null){ if (errorMessage != null) {
sender.sendMessage(errorMessage); sender.sendMessage(errorMessage);
return false; return false;
} }
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,66 +23,73 @@ 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;
public MetropolisPlotReserveCommand(MetropolisPlugin metropolisPlugin) { public MetropolisPlotReserveCommand(MetropolisPlugin metropolisPlugin) {
_plugin = metropolisPlugin; _plugin = metropolisPlugin;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
int minX = 0; int minX = 0;
int minY = 0; int minY = 0;
int minZ = 0; int minZ = 0;
int maxX = 0; int maxX = 0;
int maxY = 0; int maxY = 0;
int maxZ = 0; int maxZ = 0;
Cuboid cuboid = new Cuboid(); Cuboid cuboid = new Cuboid();
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 =
.getSelection(BukkitAdapter.adapt(_plugin.getWorld())); _plugin
cuboid = new Cuboid(selection); .worldEdit
} catch (IncompleteRegionException ex) { .getSession((Player) sender)
sender.sendMessage("Select a WorldEdit region first."); .getSelection(BukkitAdapter.adapt(_plugin.getWorld()));
return false; cuboid = new Cuboid(selection);
} } catch (IncompleteRegionException ex) {
}else if(args.length == 7){ sender.sendMessage("Select a WorldEdit region first.");
try{ return false;
minX = Integer.parseInt(args[1]); }
minY = Integer.parseInt(args[2]); } else if (args.length == 7) {
minZ = Integer.parseInt(args[3]); try {
maxX = Integer.parseInt(args[4]); minX = Integer.parseInt(args[1]);
maxY = Integer.parseInt(args[5]); minY = Integer.parseInt(args[2]);
maxZ = Integer.parseInt(args[6]); minZ = Integer.parseInt(args[3]);
}catch(NumberFormatException ex){ maxX = Integer.parseInt(args[4]);
return false; maxY = Integer.parseInt(args[5]);
} maxZ = Integer.parseInt(args[6]);
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ); } catch (NumberFormatException ex) {
}else if(args.length == 5){ return false;
try{ }
minX = Integer.parseInt(args[1]); cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
minY = 0; } else if (args.length == 5) {
minZ = Integer.parseInt(args[2]); try {
maxX = Integer.parseInt(args[3]); minX = Integer.parseInt(args[1]);
maxY = _plugin.getWorld().getMaxHeight(); minY = 0;
maxZ = Integer.parseInt(args[4]); minZ = Integer.parseInt(args[2]);
}catch(NumberFormatException ex){ maxX = Integer.parseInt(args[3]);
return false; maxY = _plugin.getWorld().getMaxHeight();
} maxZ = Integer.parseInt(args[4]);
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ); } catch (NumberFormatException ex) {
}else{ return false;
return false; }
} cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
} else {
return false;
}
String regionName = args[0]; String regionName = args[0];
_plugin.reserveCuboid(regionName, cuboid); _plugin.reserveCuboid(regionName, cuboid);
sender.sendMessage("Reserved plot region " + regionName + "."); sender.sendMessage("Reserved plot region " + regionName + ".");
return true;
}
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; 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;
public DebugListener(MetropolisPlugin plugin){ public DebugListener(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@EventHandler(priority=EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onEvent(PlayerInteractEvent event){ public void onEvent(PlayerInteractEvent event) {
//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; 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;
public PlayerJoinListener(MetropolisPlugin plugin){ public PlayerJoinListener(MetropolisPlugin plugin) {
_plugin = plugin; _plugin = plugin;
} }
@EventHandler(priority=EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event){ public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player == null){ if (player == null) {
return; return;
} }
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
}else{ .getLogger()
Cuboid cuboid = home.getCuboid(); .info(
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())); 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()));
}
}
} }

View File

@@ -1,5 +1,22 @@
/*
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 {
public static final int signTypeId = 63; public static final int signTypeId = 63;
} }

View File

@@ -1,53 +1,70 @@
/*
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() {
Cuboid cuboid = new Cuboid(BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6)); Cuboid cuboid = new Cuboid(BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
assertEquals(1, cuboid.getMinX()); assertEquals(1, cuboid.getMinX());
assertEquals(2, cuboid.getMinY()); assertEquals(2, cuboid.getMinY());
assertEquals(3, cuboid.getMinZ()); assertEquals(3, cuboid.getMinZ());
assertEquals(4, cuboid.getMaxX()); assertEquals(4, cuboid.getMaxX());
assertEquals(5, cuboid.getMaxY()); assertEquals(5, cuboid.getMaxY());
assertEquals(6, cuboid.getMaxZ()); assertEquals(6, cuboid.getMaxZ());
} }
@Test @Test
void comparesVectorsByXThenZThenYAndHandlesNulls() { void comparesVectorsByXThenZThenYAndHandlesNulls() {
assertEquals(-1, Cuboid.compareBlockVectors(null, BlockVector3.ZERO)); assertEquals(-1, Cuboid.compareBlockVectors(null, BlockVector3.ZERO));
assertEquals(1, Cuboid.compareBlockVectors(BlockVector3.ZERO, null)); assertEquals(1, Cuboid.compareBlockVectors(BlockVector3.ZERO, null));
assertEquals(0, Cuboid.compareBlockVectors(null, null)); assertEquals(0, Cuboid.compareBlockVectors(null, null));
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 0), BlockVector3.at(2, 0, 0)) < 0); assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 0), BlockVector3.at(2, 0, 0)) < 0);
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 1), BlockVector3.at(1, 0, 2)) < 0); assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 1), BlockVector3.at(1, 0, 2)) < 0);
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 1, 2), BlockVector3.at(1, 2, 2)) < 0); assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 1, 2), BlockVector3.at(1, 2, 2)) < 0);
} }
@Test @Test
void treatsTouchingBoundsAsIntersecting() { void treatsTouchingBoundsAsIntersecting() {
Cuboid first = new Cuboid(0, 0, 0, 10, 10, 10); Cuboid first = new Cuboid(0, 0, 0, 10, 10, 10);
Cuboid touching = new Cuboid(10, 10, 10, 20, 20, 20); Cuboid touching = new Cuboid(10, 10, 10, 20, 20, 20);
Cuboid separate = new Cuboid(11, 0, 0, 20, 10, 10); Cuboid separate = new Cuboid(11, 0, 0, 20, 10, 10);
assertTrue(first.intersects(touching)); assertTrue(first.intersects(touching));
assertFalse(first.intersects(separate)); assertFalse(first.intersects(separate));
} }
@Test @Test
void containsPointsOnBoundsButRejectsPointsOutside() { void containsPointsOnBoundsButRejectsPointsOutside() {
Cuboid cuboid = new Cuboid(1, 2, 3, 4, 5, 6); Cuboid cuboid = new Cuboid(1, 2, 3, 4, 5, 6);
assertTrue(cuboid.contains(new Location(null, 1, 2, 3))); assertTrue(cuboid.contains(new Location(null, 1, 2, 3)));
assertTrue(cuboid.contains(new Location(null, 4, 5, 6))); assertTrue(cuboid.contains(new Location(null, 4, 5, 6)));
assertFalse(cuboid.contains(new Location(null, 5, 5, 6))); assertFalse(cuboid.contains(new Location(null, 5, 5, 6)));
} }
} }

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,31 +28,34 @@ 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 {
File file = new File(temporaryDirectory, "currentHomes.yml"); File file = new File(temporaryDirectory, "currentHomes.yml");
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
Map<UUID, Integer> expected = Map.of(playerId, 3); Map<UUID, Integer> expected = Map.of(playerId, 3);
CurrentHomesStore.save(file, expected); CurrentHomesStore.save(file, expected);
assertEquals(expected, CurrentHomesStore.load(file, ignored -> null)); assertEquals(expected, CurrentHomesStore.load(file, ignored -> null));
} }
@Test @Test
void resolvesLegacyPlayerNameKeys() throws Exception { void resolvesLegacyPlayerNameKeys() throws Exception {
File file = new File(temporaryDirectory, "currentHomes.yml"); File file = new File(temporaryDirectory, "currentHomes.yml");
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
YamlConfiguration yaml = new YamlConfiguration(); YamlConfiguration yaml = new YamlConfiguration();
yaml.set("OldPlayerName", 2); yaml.set("OldPlayerName", 2);
yaml.save(file); yaml.save(file);
assertEquals(Map.of(playerId, 2), CurrentHomesStore.load(file, name -> { assertEquals(
assertEquals("OldPlayerName", name); Map.of(playerId, 2),
return playerId; CurrentHomesStore.load(
})); file,
} name -> {
assertEquals("OldPlayerName", name);
return playerId;
}));
}
} }

View File

@@ -1,27 +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; 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;
class PlayerHomeTest { import org.junit.jupiter.api.Test;
@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));
assertEquals(playerId, home.getPlayerId()); class PlayerHomeTest {
assertEquals("PlayerName", home.getPlayerName()); @Test
assertEquals(2, home.getNumber()); void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
assertEquals("h_2_" + playerId, home.getRegionName()); 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));
assertEquals(playerId, home.getPlayerId());
assertEquals("PlayerName", home.getPlayerName());
assertEquals(2, home.getNumber());
assertEquals("h_2_" + playerId, home.getRegionName());
}
} }

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;
@@ -11,12 +28,12 @@ import org.bukkit.entity.Player;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class PlayerLookupTest { class PlayerLookupTest {
@Test @Test
void matchesOnlinePlayerNamesCaseInsensitivelyButNotByPrefix() { void matchesOnlinePlayerNamesCaseInsensitivelyButNotByPrefix() {
Player player = mock(Player.class); Player player = mock(Player.class);
when(player.getName()).thenReturn("PlayerName"); when(player.getName()).thenReturn("PlayerName");
assertSame(player, PlayerLookup.findOnline("playername", List.of(player))); assertSame(player, PlayerLookup.findOnline("playername", List.of(player)));
assertNull(PlayerLookup.findOnline("Player", List.of(player))); assertNull(PlayerLookup.findOnline("Player", List.of(player)));
} }
} }

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,40 +26,40 @@ 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() {
MetropolisPlugin plugin = mock(MetropolisPlugin.class); MetropolisPlugin plugin = mock(MetropolisPlugin.class);
Player player = mock(Player.class); Player player = mock(Player.class);
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
when(player.getUniqueId()).thenReturn(playerId); when(player.getUniqueId()).thenReturn(playerId);
when(plugin.getNumPlots(playerId)).thenReturn(0); when(plugin.getNumPlots(playerId)).thenReturn(0);
when(plugin.getMaxPlots(playerId)).thenReturn(1); when(plugin.getMaxPlots(playerId)).thenReturn(1);
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin); MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
assertTrue(executor.onCommand(player, mock(Command.class), "acquire", new String[0])); assertTrue(executor.onCommand(player, mock(Command.class), "acquire", new String[0]));
verify(plugin).assignPlot(player); verify(plugin).assignPlot(player);
} }
@Test @Test
void doesNotAssignAPlotAfterThePlayerReachesTheirLimit() { void doesNotAssignAPlotAfterThePlayerReachesTheirLimit() {
MetropolisPlugin plugin = mock(MetropolisPlugin.class); MetropolisPlugin plugin = mock(MetropolisPlugin.class);
Player player = mock(Player.class); Player player = mock(Player.class);
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
when(player.getUniqueId()).thenReturn(playerId); when(player.getUniqueId()).thenReturn(playerId);
when(plugin.getNumPlots(playerId)).thenReturn(1); when(plugin.getNumPlots(playerId)).thenReturn(1);
when(plugin.getMaxPlots(playerId)).thenReturn(1); when(plugin.getMaxPlots(playerId)).thenReturn(1);
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin); MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
assertFalse(executor.onCommand(player, mock(Command.class), "acquire", new String[0])); assertFalse(executor.onCommand(player, mock(Command.class), "acquire", new String[0]));
verify(plugin, never()).assignPlot(player); verify(plugin, never()).assignPlot(player);
} }
} }

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,42 +25,46 @@ 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() {
MetropolisPlugin plugin = mock(MetropolisPlugin.class); MetropolisPlugin plugin = mock(MetropolisPlugin.class);
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
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());
assertEquals(1, cuboid.getValue().getMinX()); assertEquals(1, cuboid.getValue().getMinX());
assertEquals(2, cuboid.getValue().getMinY()); assertEquals(2, cuboid.getValue().getMinY());
assertEquals(3, cuboid.getValue().getMinZ()); assertEquals(3, cuboid.getValue().getMinZ());
assertEquals(4, cuboid.getValue().getMaxX()); assertEquals(4, cuboid.getValue().getMaxX());
assertEquals(5, cuboid.getValue().getMaxY()); assertEquals(5, cuboid.getValue().getMaxY());
assertEquals(6, cuboid.getValue().getMaxZ()); assertEquals(6, cuboid.getValue().getMaxZ());
} }
@Test @Test
void rejectsMalformedCoordinateArgumentsWithoutCallingPlugin() { void rejectsMalformedCoordinateArgumentsWithoutCallingPlugin() {
MetropolisPlugin plugin = mock(MetropolisPlugin.class); MetropolisPlugin plugin = mock(MetropolisPlugin.class);
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
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(
verifyNoInteractions(plugin); 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; package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.contains;
@@ -7,31 +24,33 @@ 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() {
MetropolisPlugin plugin = mock(MetropolisPlugin.class); MetropolisPlugin plugin = mock(MetropolisPlugin.class);
Player player = mock(Player.class); Player player = mock(Player.class);
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))
UUID.fromString("123e4567-e89b-12d3-a456-426614174000"), .thenReturn(
"PlayerName", new PlayerHome(
1, UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
BlockVector3.at(1, 2, 3), "PlayerName",
BlockVector3.at(4, 5, 6))); 1,
BlockVector3.at(1, 2, 3),
BlockVector3.at(4, 5, 6)));
new PlayerJoinListener(plugin).onPlayerJoin(event); new PlayerJoinListener(plugin).onPlayerJoin(event);
verify(player).sendMessage(contains("home is between (1, 2, 3) and (4, 5, 6)")); verify(player).sendMessage(contains("home is between (1, 2, 3) and (4, 5, 6)"));
} }
} }