Updates spotless and adds a license header.
This commit is contained in:
8
TODO.md
8
TODO.md
@@ -26,13 +26,13 @@
|
||||
| MET-022 | Planning | (Optional) Add new features, quality-of-life improvements, or CI configuration after the modernization and documentation tasks are complete. |
|
||||
| GIT-009 | Planning | i have three reserve plots and one just got overwritten when a new player joined. |
|
||||
| GIT-008 | Ready | Implement multiple plot sizes by granting multiple plots around each other.
|
||||
| GIT-007 | Ready | Allow buying and selling of homes via an ecnoomy plugin. |
|
||||
| GIT-007 | Planning | Allow buying and selling of homes via an ecnoomy plugin. |
|
||||
| GIT-006 | Ready | Add levels support. |
|
||||
| GIT-005 | Planning | Add the possibility to create multiple plot homes in shapes. |
|
||||
| GIT-004 | Ready | Add a command to request home allocation. |
|
||||
| GIT-004 | Planning | Add a command to request home allocation. |
|
||||
| GIT-003 | Ready | Add support for multiple homes. |
|
||||
| GIT-002 | Ready | Add a command to teleport to a reservation you are part of. |
|
||||
| GIT-001 | Ready | Add a command to move to a different home. |
|
||||
| GIT-002 | Planning | Add a command to teleport to a reservation you are part of. |
|
||||
| GIT-001 | Planning | Add a command to move to a different home. |
|
||||
|
||||
# GIT-001 - Add a command to move to a different home.
|
||||
**Status:** Ready
|
||||
|
||||
12
build.gradle
12
build.gradle
@@ -1,4 +1,5 @@
|
||||
plugins {
|
||||
id 'com.diffplug.spotless' version '8.10.3'
|
||||
id 'java-library'
|
||||
id 'maven-publish'
|
||||
id 'org.danilopianini.git-sensitive-semantic-versioning' version '7.0.24'
|
||||
@@ -88,3 +89,14 @@ tasks.named('wrapper') {
|
||||
archiveBase = Wrapper.PathBase.PROJECT
|
||||
archivePath = '.gradle/wrapper/dists'
|
||||
}
|
||||
|
||||
spotless {
|
||||
java {
|
||||
googleJavaFormat('1.36.1')
|
||||
importOrder 'java', 'javax', 'com', 'net', 'org', ''
|
||||
licenseHeaderFile 'config/license-header.txt'
|
||||
target 'src/**/*.java'
|
||||
removeUnusedImports()
|
||||
toggleOffOn()
|
||||
}
|
||||
}
|
||||
17
config/license-header.txt
Normal file
17
config/license-header.txt
Normal 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>.
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -15,110 +32,114 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MetropolisServerIntegrationTest {
|
||||
@Test
|
||||
void runningPaperLoadsMetropolis() throws IOException {
|
||||
String installedPlugins;
|
||||
try (RconClient rcon = connectToConfiguredServer()) {
|
||||
installedPlugins = rcon.execute("plugins");
|
||||
}
|
||||
assertTrue(installedPlugins.contains("Metropolis"), installedPlugins);
|
||||
}
|
||||
@Test
|
||||
void runningPaperLoadsMetropolis() throws IOException {
|
||||
String installedPlugins;
|
||||
try (RconClient rcon = connectToConfiguredServer()) {
|
||||
installedPlugins = rcon.execute("plugins");
|
||||
}
|
||||
assertTrue(installedPlugins.contains("Metropolis"), installedPlugins);
|
||||
}
|
||||
|
||||
@Test
|
||||
void plotReservationIsPersistedByTheLoadedWorldGuardPlugin() throws IOException {
|
||||
String regionId = "metropolis-it-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
try (RconClient rcon = connectToConfiguredServer()) {
|
||||
String response = rcon.execute("metropolis-plot-reserve " + regionId + " 100 60 100 105 70 105");
|
||||
assertTrue(response.contains("Reserved plot region " + regionId), response);
|
||||
}
|
||||
@Test
|
||||
void plotReservationIsPersistedByTheLoadedWorldGuardPlugin() throws IOException {
|
||||
String regionId = "metropolis-it-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
try (RconClient rcon = connectToConfiguredServer()) {
|
||||
String response =
|
||||
rcon.execute("metropolis-plot-reserve " + regionId + " 100 60 100 105 70 105");
|
||||
assertTrue(response.contains("Reserved plot region " + regionId), response);
|
||||
}
|
||||
|
||||
Path serverDirectory = Path.of(requiredEnvironment("METROPOLIS_SERVER_DIR"));
|
||||
String worldName = System.getenv().getOrDefault("METROPOLIS_WORLD", "world");
|
||||
Path regionsFile = serverDirectory.resolve("plugins/WorldGuard/worlds")
|
||||
.resolve(worldName)
|
||||
.resolve("regions.yml");
|
||||
YamlConfiguration regions = YamlConfiguration.loadConfiguration(regionsFile.toFile());
|
||||
Path serverDirectory = Path.of(requiredEnvironment("METROPOLIS_SERVER_DIR"));
|
||||
String worldName = System.getenv().getOrDefault("METROPOLIS_WORLD", "world");
|
||||
Path regionsFile =
|
||||
serverDirectory
|
||||
.resolve("plugins/WorldGuard/worlds")
|
||||
.resolve(worldName)
|
||||
.resolve("regions.yml");
|
||||
YamlConfiguration regions = YamlConfiguration.loadConfiguration(regionsFile.toFile());
|
||||
|
||||
assertTrue(regions.contains("regions." + regionId), "WorldGuard did not persist region " + regionId);
|
||||
}
|
||||
assertTrue(
|
||||
regions.contains("regions." + regionId), "WorldGuard did not persist region " + regionId);
|
||||
}
|
||||
|
||||
private static RconClient connectToConfiguredServer() throws IOException {
|
||||
String host = requiredEnvironment("METROPOLIS_RCON_HOST");
|
||||
int port = Integer.parseInt(requiredEnvironment("METROPOLIS_RCON_PORT"));
|
||||
String password = requiredEnvironment("METROPOLIS_RCON_PASSWORD");
|
||||
return new RconClient(host, port, password);
|
||||
}
|
||||
private static RconClient connectToConfiguredServer() throws IOException {
|
||||
String host = requiredEnvironment("METROPOLIS_RCON_HOST");
|
||||
int port = Integer.parseInt(requiredEnvironment("METROPOLIS_RCON_PORT"));
|
||||
String password = requiredEnvironment("METROPOLIS_RCON_PASSWORD");
|
||||
return new RconClient(host, port, password);
|
||||
}
|
||||
|
||||
private static String requiredEnvironment(String name) {
|
||||
String value = System.getenv(name);
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new IllegalStateException("Set " + name + " to run integrationTest.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
private static String requiredEnvironment(String name) {
|
||||
String value = System.getenv(name);
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new IllegalStateException("Set " + name + " to run integrationTest.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static final class RconClient implements AutoCloseable {
|
||||
private final Socket socket = new Socket();
|
||||
private final DataInputStream input;
|
||||
private final DataOutputStream output;
|
||||
private int requestId = 1;
|
||||
private static final class RconClient implements AutoCloseable {
|
||||
private final Socket socket = new Socket();
|
||||
private final DataInputStream input;
|
||||
private final DataOutputStream output;
|
||||
private int requestId = 1;
|
||||
|
||||
private RconClient(String host, int port, String password) throws IOException {
|
||||
socket.connect(new InetSocketAddress(host, port), 5000);
|
||||
socket.setSoTimeout(5000);
|
||||
input = new DataInputStream(socket.getInputStream());
|
||||
output = new DataOutputStream(socket.getOutputStream());
|
||||
int authId = requestId++;
|
||||
Packet response = send(authId, 3, password);
|
||||
if (response.id != authId) {
|
||||
throw new IOException("RCON authentication failed.");
|
||||
}
|
||||
}
|
||||
private RconClient(String host, int port, String password) throws IOException {
|
||||
socket.connect(new InetSocketAddress(host, port), 5000);
|
||||
socket.setSoTimeout(5000);
|
||||
input = new DataInputStream(socket.getInputStream());
|
||||
output = new DataOutputStream(socket.getOutputStream());
|
||||
int authId = requestId++;
|
||||
Packet response = send(authId, 3, password);
|
||||
if (response.id != authId) {
|
||||
throw new IOException("RCON authentication failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private String execute(String command) throws IOException {
|
||||
return send(requestId++, 2, command).payload;
|
||||
}
|
||||
private String execute(String command) throws IOException {
|
||||
return send(requestId++, 2, command).payload;
|
||||
}
|
||||
|
||||
private Packet send(int id, int type, String payload) throws IOException {
|
||||
byte[] data = payload.getBytes(StandardCharsets.UTF_8);
|
||||
writeLittleEndianInt(data.length + 10);
|
||||
writeLittleEndianInt(id);
|
||||
writeLittleEndianInt(type);
|
||||
output.write(data);
|
||||
output.writeByte(0);
|
||||
output.writeByte(0);
|
||||
output.flush();
|
||||
private Packet send(int id, int type, String payload) throws IOException {
|
||||
byte[] data = payload.getBytes(StandardCharsets.UTF_8);
|
||||
writeLittleEndianInt(data.length + 10);
|
||||
writeLittleEndianInt(id);
|
||||
writeLittleEndianInt(type);
|
||||
output.write(data);
|
||||
output.writeByte(0);
|
||||
output.writeByte(0);
|
||||
output.flush();
|
||||
|
||||
int length = readLittleEndianInt();
|
||||
byte[] packet = input.readNBytes(length);
|
||||
if (packet.length != length || length < 10) {
|
||||
throw new IOException("Received an invalid RCON packet.");
|
||||
}
|
||||
int responseId = littleEndianInt(packet, 0);
|
||||
String response = new String(packet, 8, length - 10, StandardCharsets.UTF_8);
|
||||
return new Packet(responseId, response);
|
||||
}
|
||||
int length = readLittleEndianInt();
|
||||
byte[] packet = input.readNBytes(length);
|
||||
if (packet.length != length || length < 10) {
|
||||
throw new IOException("Received an invalid RCON packet.");
|
||||
}
|
||||
int responseId = littleEndianInt(packet, 0);
|
||||
String response = new String(packet, 8, length - 10, StandardCharsets.UTF_8);
|
||||
return new Packet(responseId, response);
|
||||
}
|
||||
|
||||
private void writeLittleEndianInt(int value) throws IOException {
|
||||
output.writeInt(Integer.reverseBytes(value));
|
||||
}
|
||||
private void writeLittleEndianInt(int value) throws IOException {
|
||||
output.writeInt(Integer.reverseBytes(value));
|
||||
}
|
||||
|
||||
private int readLittleEndianInt() throws IOException {
|
||||
return Integer.reverseBytes(input.readInt());
|
||||
}
|
||||
private int readLittleEndianInt() throws IOException {
|
||||
return Integer.reverseBytes(input.readInt());
|
||||
}
|
||||
|
||||
private static int littleEndianInt(byte[] bytes, int offset) {
|
||||
return (bytes[offset] & 0xff)
|
||||
| ((bytes[offset + 1] & 0xff) << 8)
|
||||
| ((bytes[offset + 2] & 0xff) << 16)
|
||||
| (bytes[offset + 3] << 24);
|
||||
}
|
||||
private static int littleEndianInt(byte[] bytes, int offset) {
|
||||
return (bytes[offset] & 0xff)
|
||||
| ((bytes[offset + 1] & 0xff) << 8)
|
||||
| ((bytes[offset + 2] & 0xff) << 16)
|
||||
| (bytes[offset + 3] << 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
private record Packet(int id, String payload) {}
|
||||
private record Packet(int id, String payload) {}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Cuboid implements Comparable<Cuboid> {
|
||||
private int id;
|
||||
private int id;
|
||||
|
||||
public int minX;
|
||||
public int minY;
|
||||
public int minZ;
|
||||
public int minX;
|
||||
public int minY;
|
||||
public int minZ;
|
||||
|
||||
public int maxX;
|
||||
public int maxY;
|
||||
public int maxZ;
|
||||
public int maxX;
|
||||
public int maxY;
|
||||
public int maxZ;
|
||||
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id){
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Cuboid(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
public Cuboid(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
|
||||
public Cuboid(BlockVector3 min, BlockVector3 max) {
|
||||
this.minX = min.x();
|
||||
this.minY = min.y();
|
||||
this.minZ = min.z();
|
||||
this.maxX = max.x();
|
||||
this.maxY = max.y();
|
||||
this.maxZ = max.z();
|
||||
}
|
||||
public Cuboid(BlockVector3 min, BlockVector3 max) {
|
||||
this.minX = min.x();
|
||||
this.minY = min.y();
|
||||
this.minZ = min.z();
|
||||
this.maxX = max.x();
|
||||
this.maxY = max.y();
|
||||
this.maxZ = max.z();
|
||||
}
|
||||
|
||||
public Cuboid() {
|
||||
this.minX = 0;
|
||||
this.minY = 0;
|
||||
this.minZ = 0;
|
||||
this.maxX = 0;
|
||||
this.maxY = 0;
|
||||
this.maxZ = 0;
|
||||
}
|
||||
public Cuboid() {
|
||||
this.minX = 0;
|
||||
this.minY = 0;
|
||||
this.minZ = 0;
|
||||
this.maxX = 0;
|
||||
this.maxY = 0;
|
||||
this.maxZ = 0;
|
||||
}
|
||||
|
||||
public Cuboid(Region selection) {
|
||||
this.minX = selection.getMinimumPoint().x();
|
||||
this.minY = selection.getMinimumPoint().y();
|
||||
this.minZ = selection.getMinimumPoint().z();
|
||||
this.maxX = selection.getMaximumPoint().x();
|
||||
this.maxY = selection.getMaximumPoint().y();
|
||||
this.maxZ = selection.getMaximumPoint().z();
|
||||
}
|
||||
public Cuboid(Region selection) {
|
||||
this.minX = selection.getMinimumPoint().x();
|
||||
this.minY = selection.getMinimumPoint().y();
|
||||
this.minZ = selection.getMinimumPoint().z();
|
||||
this.maxX = selection.getMaximumPoint().x();
|
||||
this.maxY = selection.getMaximumPoint().y();
|
||||
this.maxZ = selection.getMaximumPoint().z();
|
||||
}
|
||||
|
||||
public BlockVector3 getMin(){
|
||||
return BlockVector3.at(minX, minY, minZ);
|
||||
}
|
||||
public BlockVector3 getMin() {
|
||||
return BlockVector3.at(minX, minY, minZ);
|
||||
}
|
||||
|
||||
public BlockVector3 getMax(){
|
||||
return BlockVector3.at(maxX, maxY, maxZ);
|
||||
}
|
||||
public BlockVector3 getMax() {
|
||||
return BlockVector3.at(maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Cuboid o) {
|
||||
BlockVector3 min = getMin();
|
||||
BlockVector3 otherMin = o.getMin();
|
||||
@Override
|
||||
public int compareTo(Cuboid o) {
|
||||
BlockVector3 min = getMin();
|
||||
BlockVector3 otherMin = o.getMin();
|
||||
|
||||
if(min.x() < otherMin.x()){
|
||||
return -1;
|
||||
}else if(min.x() > otherMin.x()){
|
||||
return 1;
|
||||
}else if(min.z() < otherMin.z()){
|
||||
return -1;
|
||||
}else if(min.z() > otherMin.z()){
|
||||
return 1;
|
||||
}else if(min.y() < otherMin.y()){
|
||||
return -1;
|
||||
}else if(min.y() > otherMin.y()){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (min.x() < otherMin.x()) {
|
||||
return -1;
|
||||
} else if (min.x() > otherMin.x()) {
|
||||
return 1;
|
||||
} else if (min.z() < otherMin.z()) {
|
||||
return -1;
|
||||
} else if (min.z() > otherMin.z()) {
|
||||
return 1;
|
||||
} else if (min.y() < otherMin.y()) {
|
||||
return -1;
|
||||
} else if (min.y() > otherMin.y()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int compareBlockVectors(BlockVector3 v1, BlockVector3 v2){
|
||||
if(v1 == null){
|
||||
if(v2 == null){
|
||||
return 0;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}else if(v2 == null){
|
||||
return 1;
|
||||
}
|
||||
if(v1.x() < v2.x()){
|
||||
return -1;
|
||||
}else if(v1.x() > v2.x()){
|
||||
return 1;
|
||||
}else if(v1.z() < v2.z()){
|
||||
return -1;
|
||||
}else if(v1.z() > v2.z()){
|
||||
return 1;
|
||||
}else if(v1.y() < v2.y()){
|
||||
return -1;
|
||||
}else if(v1.y() > v2.y()){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static int compareBlockVectors(BlockVector3 v1, BlockVector3 v2) {
|
||||
if (v1 == null) {
|
||||
if (v2 == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (v2 == null) {
|
||||
return 1;
|
||||
}
|
||||
if (v1.x() < v2.x()) {
|
||||
return -1;
|
||||
} else if (v1.x() > v2.x()) {
|
||||
return 1;
|
||||
} else if (v1.z() < v2.z()) {
|
||||
return -1;
|
||||
} else if (v1.z() > v2.z()) {
|
||||
return 1;
|
||||
} else if (v1.y() < v2.y()) {
|
||||
return -1;
|
||||
} else if (v1.y() > v2.y()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBlockLessThan(BlockVector3 v1, BlockVector3 v2) {
|
||||
return compareBlockVectors(v1, v2) < 0;
|
||||
}
|
||||
public static boolean isBlockLessThan(BlockVector3 v1, BlockVector3 v2) {
|
||||
return compareBlockVectors(v1, v2) < 0;
|
||||
}
|
||||
|
||||
public Cuboid inset(int amount){
|
||||
return inset(amount, amount, amount);
|
||||
}
|
||||
public Cuboid inset(int amount) {
|
||||
return inset(amount, amount, amount);
|
||||
}
|
||||
|
||||
public Cuboid inset(int x, int z){
|
||||
return inset(x, 0, z);
|
||||
}
|
||||
public Cuboid inset(int x, int z) {
|
||||
return inset(x, 0, z);
|
||||
}
|
||||
|
||||
public Cuboid inset(int x, int y, int z){
|
||||
return new Cuboid(this.minX + x, this.minY, this.minZ + z, this.maxX - x, this.maxY, this.maxZ - z);
|
||||
}
|
||||
public Cuboid inset(int x, int y, int z) {
|
||||
return new Cuboid(
|
||||
this.minX + x, this.minY, this.minZ + z, this.maxX - x, this.maxY, this.maxZ - z);
|
||||
}
|
||||
|
||||
public int getVolume() {
|
||||
return (this.maxX - this.minX) * (this.maxY - this.minY) * (this.maxZ - this.minZ);
|
||||
}
|
||||
public int getMinX(){return minX;}
|
||||
public void setMinX(int minX){this.minX = minX;}
|
||||
public int getMinY(){return minY;}
|
||||
public void setMinY(int minY){this.minY = minY;}
|
||||
public int getMinZ(){return minZ;}
|
||||
public void setMinZ(int minZ){this.minZ = minZ;}
|
||||
public int getMaxX(){return maxX;}
|
||||
public void setMaxX(int maxX){this.maxX = maxX;}
|
||||
public int getMaxY(){return maxY;}
|
||||
public void setMaxY(int maxY){this.maxY = maxY;}
|
||||
public int getMaxZ(){return maxZ;}
|
||||
public void setMaxZ(int maxZ){this.maxZ = maxZ;}
|
||||
public int getVolume() {
|
||||
return (this.maxX - this.minX) * (this.maxY - this.minY) * (this.maxZ - this.minZ);
|
||||
}
|
||||
|
||||
public Cuboid outset(int amount) {
|
||||
return outset(amount, amount, amount);
|
||||
}
|
||||
public int getMinX() {
|
||||
return minX;
|
||||
}
|
||||
|
||||
public Cuboid outset(int x, int z){
|
||||
return outset(x, 0, z);
|
||||
}
|
||||
public void setMinX(int minX) {
|
||||
this.minX = minX;
|
||||
}
|
||||
|
||||
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 getMinY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
public int getCenterX(){
|
||||
return (this.minX + this.maxX) /2;
|
||||
}
|
||||
public void setMinY(int minY) {
|
||||
this.minY = minY;
|
||||
}
|
||||
|
||||
public int getCenterY(){
|
||||
return (this.minY + this.maxY)/2;
|
||||
}
|
||||
public int getMinZ() {
|
||||
return minZ;
|
||||
}
|
||||
|
||||
public int getCenterZ(){
|
||||
return (this.minZ + this.maxZ)/2;
|
||||
}
|
||||
public void setMinZ(int minZ) {
|
||||
this.minZ = minZ;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public int getMaxX() {
|
||||
return maxX;
|
||||
}
|
||||
|
||||
public void setMaxX(int maxX) {
|
||||
this.maxX = maxX;
|
||||
}
|
||||
|
||||
public int getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
|
||||
public void setMaxY(int maxY) {
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
public int getMaxZ() {
|
||||
return maxZ;
|
||||
}
|
||||
|
||||
public void setMaxZ(int maxZ) {
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
|
||||
public Cuboid outset(int amount) {
|
||||
return outset(amount, amount, amount);
|
||||
}
|
||||
|
||||
public Cuboid outset(int x, int z) {
|
||||
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
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(Location bedSpawn) {
|
||||
if(this.minX > bedSpawn.getBlockX() || this.maxX < bedSpawn.getBlockX()){
|
||||
return false;
|
||||
}else if(this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()){
|
||||
return false;
|
||||
}else if(this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()){
|
||||
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);
|
||||
}
|
||||
public boolean contains(Location bedSpawn) {
|
||||
if (this.minX > bedSpawn.getBlockX() || this.maxX < bedSpawn.getBlockX()) {
|
||||
return false;
|
||||
} else if (this.minZ > bedSpawn.getBlockZ() || this.maxZ < bedSpawn.getBlockZ()) {
|
||||
return false;
|
||||
} else if (this.minY > bedSpawn.getBlockY() || this.maxY < bedSpawn.getBlockY()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import java.io.File;
|
||||
@@ -11,40 +28,40 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
final class CurrentHomesStore {
|
||||
private CurrentHomesStore() {}
|
||||
private CurrentHomesStore() {}
|
||||
|
||||
static Map<UUID, Integer> load(File file, Function<String, UUID> legacyOwnerResolver)
|
||||
throws IOException, InvalidConfigurationException {
|
||||
Map<UUID, Integer> homesByOwner = new HashMap<>();
|
||||
if (!file.exists()) {
|
||||
return homesByOwner;
|
||||
}
|
||||
static Map<UUID, Integer> load(File file, Function<String, UUID> legacyOwnerResolver)
|
||||
throws IOException, InvalidConfigurationException {
|
||||
Map<UUID, Integer> homesByOwner = new HashMap<>();
|
||||
if (!file.exists()) {
|
||||
return homesByOwner;
|
||||
}
|
||||
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
yaml.load(file);
|
||||
for (String ownerKey : yaml.getKeys(false)) {
|
||||
UUID ownerId;
|
||||
try {
|
||||
ownerId = UUID.fromString(ownerKey);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
ownerId = legacyOwnerResolver.apply(ownerKey);
|
||||
}
|
||||
int homeNumber = yaml.getInt(ownerKey, 0);
|
||||
if (ownerId != null && homeNumber > 0) {
|
||||
homesByOwner.put(ownerId, homeNumber);
|
||||
}
|
||||
}
|
||||
return homesByOwner;
|
||||
}
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
yaml.load(file);
|
||||
for (String ownerKey : yaml.getKeys(false)) {
|
||||
UUID ownerId;
|
||||
try {
|
||||
ownerId = UUID.fromString(ownerKey);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
ownerId = legacyOwnerResolver.apply(ownerKey);
|
||||
}
|
||||
int homeNumber = yaml.getInt(ownerKey, 0);
|
||||
if (ownerId != null && homeNumber > 0) {
|
||||
homesByOwner.put(ownerId, homeNumber);
|
||||
}
|
||||
}
|
||||
return homesByOwner;
|
||||
}
|
||||
|
||||
static void save(File file, Map<UUID, Integer> homesByOwner) throws IOException {
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
static void save(File file, Map<UUID, Integer> homesByOwner) throws IOException {
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
homesByOwner.forEach((ownerId, homeNumber) -> yaml.set(ownerId.toString(), homeNumber));
|
||||
yaml.save(file);
|
||||
}
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
homesByOwner.forEach((ownerId, homeNumber) -> yaml.set(ownerId.toString(), homeNumber));
|
||||
yaml.save(file);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class PlayerHome extends Plot{
|
||||
private UUID playerId;
|
||||
private String playerName;
|
||||
public UUID getPlayerId(){return this.playerId;}
|
||||
public String getPlayerName(){return this.playerName;}
|
||||
public void setPlayerName(String playerName){this.playerName = playerName;}
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
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) {
|
||||
super(String.format("h_%d_%s", homeNumber, ownerId), min, max);
|
||||
this.playerId = ownerId;
|
||||
this.playerName = ownerName;
|
||||
this.number = homeNumber;
|
||||
}
|
||||
public UUID getPlayerId() {
|
||||
return this.playerId;
|
||||
}
|
||||
|
||||
public PlayerHome() {
|
||||
this.playerId = null;
|
||||
this.playerName = "";
|
||||
}
|
||||
public String getPlayerName() {
|
||||
return this.playerName;
|
||||
}
|
||||
|
||||
public PlayerHome(ProtectedRegion homeRegion){
|
||||
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()));
|
||||
}
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if(!(other instanceof PlayerHome)){
|
||||
return super.equals(other);
|
||||
}
|
||||
private int number;
|
||||
|
||||
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)){
|
||||
return false;
|
||||
}
|
||||
public PlayerHome() {
|
||||
this.playerId = null;
|
||||
this.playerName = "";
|
||||
}
|
||||
|
||||
if(!getCuboid().equals(otherPlayerHome.getCuboid())){
|
||||
return false;
|
||||
}
|
||||
public PlayerHome(ProtectedRegion homeRegion) {
|
||||
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() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
PlayerHome otherPlayerHome = (PlayerHome) other;
|
||||
|
||||
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){
|
||||
if(homeRegion instanceof ProtectedCuboidRegion){
|
||||
return new PlayerHome((ProtectedCuboidRegion) homeRegion);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
public String toFriendlyString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
public void setNumber(int number){
|
||||
this.number = number;
|
||||
}
|
||||
sb.append(
|
||||
String.format(
|
||||
"Metropolis Home {Owner: %s min: (%d, %d, %d) max: (%d, %d, %d)}",
|
||||
getPlayerName(),
|
||||
getCuboid().getMinX(),
|
||||
getCuboid().getMinY(),
|
||||
getCuboid().getMinZ(),
|
||||
getCuboid().getMaxX(),
|
||||
getCuboid().getMaxY(),
|
||||
getCuboid().getMaxZ()));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static PlayerHome get(ProtectedRegion homeRegion) {
|
||||
if (homeRegion instanceof ProtectedCuboidRegion) {
|
||||
return new PlayerHome((ProtectedCuboidRegion) homeRegion);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
final class PlayerLookup {
|
||||
private PlayerLookup() {}
|
||||
private PlayerLookup() {}
|
||||
|
||||
static Player findOnline(String requestedName, Iterable<? extends Player> onlinePlayers) {
|
||||
if (requestedName == null) {
|
||||
return null;
|
||||
}
|
||||
for (Player player : onlinePlayers) {
|
||||
if (requestedName.equalsIgnoreCase(player.getName())) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static Player findOnline(String requestedName, Iterable<? extends Player> onlinePlayers) {
|
||||
if (requestedName == null) {
|
||||
return null;
|
||||
}
|
||||
for (Player player : onlinePlayers) {
|
||||
if (requestedName.equalsIgnoreCase(player.getName())) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
public class Plot implements Comparable<Plot> {
|
||||
private int _id;
|
||||
|
||||
public class Plot implements Comparable<Plot>{
|
||||
private int _id;
|
||||
public int getId(){return _id;}
|
||||
public void setId(int id){_id = id;}
|
||||
public int getId() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
private Cuboid _cuboid;
|
||||
public Cuboid getCuboid(){return _cuboid;}
|
||||
public void setCuboid(Cuboid cuboid){_cuboid = cuboid;}
|
||||
public void setId(int id) {
|
||||
_id = id;
|
||||
}
|
||||
|
||||
private String _regionName;
|
||||
public String getRegionName(){return _regionName;}
|
||||
public void setRegionName(String regionName){_regionName = regionName;}
|
||||
private Cuboid _cuboid;
|
||||
|
||||
public Plot(String regionName, BlockVector3 min, BlockVector3 max){
|
||||
_cuboid = new Cuboid(min, max);
|
||||
_regionName = regionName;
|
||||
}
|
||||
public Cuboid getCuboid() {
|
||||
return _cuboid;
|
||||
}
|
||||
|
||||
public Plot(ProtectedCuboidRegion cuboid){
|
||||
_cuboid = new Cuboid(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
|
||||
_regionName = cuboid.getId();
|
||||
}
|
||||
public void setCuboid(Cuboid cuboid) {
|
||||
_cuboid = cuboid;
|
||||
}
|
||||
|
||||
public Plot(){
|
||||
_cuboid = new Cuboid();
|
||||
_regionName = "";
|
||||
}
|
||||
private String _regionName;
|
||||
|
||||
public BlockVector3 getPlotMin(int roadWidth) {
|
||||
return BlockVector3.at(_cuboid.minX - roadWidth/2, _cuboid.minY, _cuboid.minZ - roadWidth/2);
|
||||
}
|
||||
public String getRegionName() {
|
||||
return _regionName;
|
||||
}
|
||||
|
||||
public int getRow(int roadWidth, int plotSizeZ){
|
||||
BlockVector3 min = getPlotMin(roadWidth);
|
||||
return min.z() / plotSizeZ;
|
||||
}
|
||||
public void setRegionName(String regionName) {
|
||||
_regionName = regionName;
|
||||
}
|
||||
|
||||
public int getCol(int roadWidth, int plotSizeX){
|
||||
return getPlotMin(roadWidth).x() / plotSizeX;
|
||||
}
|
||||
public Plot(String regionName, BlockVector3 min, BlockVector3 max) {
|
||||
_cuboid = new Cuboid(min, max);
|
||||
_regionName = regionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if(!(other instanceof Plot)){
|
||||
return super.equals(other);
|
||||
}
|
||||
public Plot(ProtectedCuboidRegion cuboid) {
|
||||
_cuboid = new Cuboid(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
|
||||
_regionName = cuboid.getId();
|
||||
}
|
||||
|
||||
Plot otherPlayerHome = (Plot)other;
|
||||
public Plot() {
|
||||
_cuboid = new Cuboid();
|
||||
_regionName = "";
|
||||
}
|
||||
|
||||
if(!getCuboid().equals(otherPlayerHome.getCuboid())){
|
||||
return false;
|
||||
}
|
||||
public BlockVector3 getPlotMin(int roadWidth) {
|
||||
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 compareTo(Plot another) {
|
||||
return getCuboid().compareTo(another.getCuboid());
|
||||
}
|
||||
public int getCol(int roadWidth, int plotSizeX) {
|
||||
return getPlotMin(roadWidth).x() / plotSizeX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
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){
|
||||
if(region instanceof ProtectedCuboidRegion){
|
||||
return new Plot((ProtectedCuboidRegion) region);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toFriendlyString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@Override
|
||||
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 _cuboid.contains(bedSpawn);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static Plot get(ProtectedRegion region) {
|
||||
if (region instanceof ProtectedCuboidRegion) {
|
||||
return new Plot((ProtectedCuboidRegion) region);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
public class UserOverride {
|
||||
private String _username;
|
||||
private int _plotMultiplier;
|
||||
private int _maxPlots;
|
||||
private String _username;
|
||||
private int _plotMultiplier;
|
||||
private int _maxPlots;
|
||||
|
||||
public String getUsername(){return _username;}
|
||||
public int getPlotMultiplier(){return _plotMultiplier;}
|
||||
public int getMaxPlots(){return _maxPlots;}
|
||||
public String getUsername() {
|
||||
return _username;
|
||||
}
|
||||
|
||||
public UserOverride(String username, int plotMultiplier, int maxPlots){
|
||||
_username = username;
|
||||
_plotMultiplier = plotMultiplier;
|
||||
_maxPlots = maxPlots;
|
||||
}
|
||||
public int getPlotMultiplier() {
|
||||
return _plotMultiplier;
|
||||
}
|
||||
|
||||
public int getMaxPlots() {
|
||||
return _maxPlots;
|
||||
}
|
||||
|
||||
public UserOverride(String username, int plotMultiplier, int maxPlots) {
|
||||
_username = username;
|
||||
_plotMultiplier = plotMultiplier;
|
||||
_maxPlots = maxPlots;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,40 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
public class MetropolisCommand implements CommandExecutor {
|
||||
private MetropolisPlugin _plugin;
|
||||
private MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisCommand(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
sender.sendMessage("Metropolis: version "+ _plugin.pdf.getVersion());
|
||||
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("Metropolis: version " + _plugin.pdf.getVersion());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,47 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
public class MetropolisDebugGenerateTestHomesCommand implements CommandExecutor {
|
||||
|
||||
private MetropolisPlugin _plugin;
|
||||
private MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisDebugGenerateTestHomesCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
public MetropolisDebugGenerateTestHomesCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
try{
|
||||
int numHomes = Integer.parseInt(args[0]);
|
||||
for(int i=1; i<= numHomes; i++){
|
||||
_plugin.generateHome(String.format("test%d", i));
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(NumberFormatException ex){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
try {
|
||||
int numHomes = Integer.parseInt(args[0]);
|
||||
for (int i = 1; i <= numHomes; i++) {
|
||||
_plugin.generateHome(String.format("test%d", i));
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,65 @@
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class MetropolisFlagResetCommand implements CommandExecutor {
|
||||
private MetropolisPlugin _plugin;
|
||||
private MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisFlagResetCommand(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisFlagResetCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
ProtectedRegion cityRegion = _plugin.regionManager.getRegion("City");
|
||||
cityRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.LAVA_FLOW, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.SNOW_FALL, StateFlag.State.DENY);
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
ProtectedRegion cityRegion = _plugin.regionManager.getRegion("City");
|
||||
cityRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.LAVA_FLOW, StateFlag.State.DENY);
|
||||
cityRegion.setFlag(Flags.SNOW_FALL, StateFlag.State.DENY);
|
||||
|
||||
for(ProtectedRegion homeRegion: _plugin.regionManager.getRegions().values()){
|
||||
if(homeRegion.getId().startsWith("h_")){
|
||||
homeRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
|
||||
for (ProtectedRegion homeRegion : _plugin.regionManager.getRegions().values()) {
|
||||
if (homeRegion.getId().startsWith("h_")) {
|
||||
homeRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.CREEPER_EXPLOSION, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.ENDER_BUILD, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.GHAST_FIREBALL, StateFlag.State.DENY);
|
||||
homeRegion.setFlag(Flags.TNT, StateFlag.State.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage("Metropolis: flags have been reset");
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
sender.sendMessage("Metropolis: flags have been reset");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
public class MetropolisHomeAcquire implements CommandExecutor {
|
||||
MetropolisPlugin _plugin;
|
||||
MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisHomeAcquire(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisHomeAcquire(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if(!(sender instanceof Player)){
|
||||
sender.sendMessage("This command can only be used by players");
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("This command can only be used by players");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(_plugin.getNumPlots(player.getUniqueId()) >= _plugin.getMaxPlots(player.getUniqueId())){
|
||||
sender.sendMessage("You cannot have any more plots");
|
||||
return false;
|
||||
}
|
||||
|
||||
_plugin.assignPlot(player);
|
||||
return true;
|
||||
}
|
||||
if (_plugin.getNumPlots(player.getUniqueId()) >= _plugin.getMaxPlots(player.getUniqueId())) {
|
||||
sender.sendMessage("You cannot have any more plots");
|
||||
return false;
|
||||
}
|
||||
|
||||
_plugin.assignPlot(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,79 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class MetropolisHomeEvictCommand implements CommandExecutor {
|
||||
MetropolisPlugin _plugin = null;
|
||||
MetropolisPlugin _plugin = null;
|
||||
|
||||
public MetropolisHomeEvictCommand(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisHomeEvictCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
//get the player and region
|
||||
String playerName = "";
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
// get the player and region
|
||||
String playerName = "";
|
||||
|
||||
if(args.length == 0){
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args.length >= 1){
|
||||
playerName = args[0];
|
||||
}
|
||||
if (args.length >= 1) {
|
||||
playerName = args[0];
|
||||
}
|
||||
|
||||
OfflinePlayer player = _plugin.getOfflinePlayer(playerName);
|
||||
if(player == null){
|
||||
sender.sendMessage(String.format("The requested player {%s}does not appear to exist.", playerName));
|
||||
return false;
|
||||
}
|
||||
OfflinePlayer player = _plugin.getOfflinePlayer(playerName);
|
||||
if (player == null) {
|
||||
sender.sendMessage(
|
||||
String.format("The requested player {%s}does not appear to exist.", playerName));
|
||||
return false;
|
||||
}
|
||||
|
||||
ProtectedRegion region = _plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId()));
|
||||
if(region == null){
|
||||
sender.sendMessage(String.format("The player {%s} has no home to be evicted from."));
|
||||
return false;
|
||||
}
|
||||
ProtectedRegion region =
|
||||
_plugin.getRegion(_plugin.getCurrentHomeRegionName(player.getUniqueId()));
|
||||
if (region == null) {
|
||||
sender.sendMessage(String.format("The player {%s} has no home to be evicted from."));
|
||||
return false;
|
||||
}
|
||||
|
||||
//remove the player as owner and/or member of the region
|
||||
region.getMembers().removePlayer(player.getUniqueId());
|
||||
region.getOwners().removePlayer(player.getUniqueId());
|
||||
// remove the player as owner and/or member of the region
|
||||
region.getMembers().removePlayer(player.getUniqueId());
|
||||
region.getOwners().removePlayer(player.getUniqueId());
|
||||
|
||||
//if the region has no owners delete the region
|
||||
if(region.getMembers().size() == 0 && region.getOwners().size() == 0){
|
||||
_plugin.removeRegion(region.getId());
|
||||
}
|
||||
// if the region has no owners delete the region
|
||||
if (region.getMembers().size() == 0 && region.getOwners().size() == 0) {
|
||||
_plugin.removeRegion(region.getId());
|
||||
}
|
||||
|
||||
_plugin.saveRegions();
|
||||
_plugin.saveRegions();
|
||||
|
||||
//?optionally regen the region
|
||||
//_plugin.worldEdit.getCommand("regen").execute(_plugin.getServer().getConsoleSender(), "regen", new String[]{});
|
||||
|
||||
return true;
|
||||
}
|
||||
// ?optionally regen the region
|
||||
// _plugin.worldEdit.getCommand("regen").execute(_plugin.getServer().getConsoleSender(),
|
||||
// "regen", new String[]{});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,52 @@
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class MetropolisHomeGenerateCommand implements CommandExecutor {
|
||||
|
||||
private MetropolisPlugin _plugin;
|
||||
private MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisHomeGenerateCommand(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisHomeGenerateCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(args.length < 1){
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflinePlayer player = _plugin.getOfflinePlayer(args[0]);
|
||||
if (player == null) {
|
||||
sender.sendMessage("Unable to find player " + args[0]);
|
||||
return false;
|
||||
}
|
||||
_plugin.generateHome(player);
|
||||
OfflinePlayer player = _plugin.getOfflinePlayer(args[0]);
|
||||
if (player == null) {
|
||||
sender.sendMessage("Unable to find player " + args[0]);
|
||||
return false;
|
||||
}
|
||||
_plugin.generateHome(player);
|
||||
|
||||
sender.sendMessage("[Metropolis] Home generated for " + args[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("[Metropolis] Home generated for " + args[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
|
||||
public class MetropolisHomeGoCommand implements CommandExecutor {
|
||||
MetropolisPlugin _plugin = null;
|
||||
MetropolisPlugin _plugin = null;
|
||||
|
||||
public MetropolisHomeGoCommand(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisHomeGoCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = null;
|
||||
if(sender instanceof Player){
|
||||
player = (Player)sender;
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
|
||||
if(args.length >= 1){
|
||||
if(player.hasPermission("")){
|
||||
player = _plugin.getPlayer(args[0]);
|
||||
if (args.length >= 1) {
|
||||
if (player.hasPermission("")) {
|
||||
player = _plugin.getPlayer(args[0]);
|
||||
|
||||
if(player == null){
|
||||
sender.sendMessage(String.format("Unable to find player %s", args[0]));
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
sender.sendMessage("Permission denied");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(args.length >= 1){
|
||||
player = _plugin.getPlayer(args[0]);
|
||||
if (player == null) {
|
||||
sender.sendMessage(String.format("Unable to find player %s", args[0]));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Permission denied");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (args.length >= 1) {
|
||||
player = _plugin.getPlayer(args[0]);
|
||||
|
||||
if(player == null){
|
||||
sender.sendMessage(String.format("Unable to find player %s", args[0]));
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
sender.sendMessage("You must be a player");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (player == null) {
|
||||
sender.sendMessage(String.format("Unable to find player %s", args[0]));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You must be a player");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerHome home = _plugin.getPlayerHome(player);
|
||||
PlayerHome home = _plugin.getPlayerHome(player);
|
||||
|
||||
Location loc = null;
|
||||
Location bedSpawn = player.getBedSpawnLocation();
|
||||
Location loc = null;
|
||||
Location bedSpawn = player.getBedSpawnLocation();
|
||||
|
||||
if(home.contains(bedSpawn)){
|
||||
loc = bedSpawn;
|
||||
}else {
|
||||
loc = home.getViableSpawnLocation(_plugin.getWorld());
|
||||
}
|
||||
if (home.contains(bedSpawn)) {
|
||||
loc = bedSpawn;
|
||||
} else {
|
||||
loc = home.getViableSpawnLocation(_plugin.getWorld());
|
||||
}
|
||||
|
||||
if(loc != null){
|
||||
player.teleport(loc);
|
||||
}else{
|
||||
if(sender == player){
|
||||
sender.sendMessage("There is no valid spawn location in your home");
|
||||
}else{
|
||||
sender.sendMessage(String.format("There is no valid spawn location in %s's home", player.getName()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (loc != null) {
|
||||
player.teleport(loc);
|
||||
} else {
|
||||
if (sender == player) {
|
||||
sender.sendMessage("There is no valid spawn location in your home");
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
String.format("There is no valid spawn location in %s's home", player.getName()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Plot;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Plot;
|
||||
|
||||
public class MetropolisHomeListCommand implements CommandExecutor {
|
||||
private MetropolisPlugin _plugin;
|
||||
private MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisHomeListCommand(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for(Plot cityBlock : _plugin.getCityBlocks()){
|
||||
sender.sendMessage(String.format("%s", cityBlock.toFriendlyString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public MetropolisHomeListCommand(MetropolisPlugin 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
public class MetropolisHomeMoveCommand implements CommandExecutor {
|
||||
MetropolisPlugin _plugin;
|
||||
MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisHomeMoveCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisHomeMoveCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
OfflinePlayer player = null;
|
||||
int newHomeNumber = 0;
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
OfflinePlayer player = null;
|
||||
int newHomeNumber = 0;
|
||||
|
||||
if(sender instanceof OfflinePlayer){
|
||||
player = (OfflinePlayer)sender;
|
||||
}
|
||||
if (sender instanceof OfflinePlayer) {
|
||||
player = (OfflinePlayer) sender;
|
||||
}
|
||||
|
||||
if(args.length == 1){
|
||||
try{
|
||||
newHomeNumber = Integer.parseInt(args[0]);
|
||||
}catch(NumberFormatException ex){
|
||||
return false;
|
||||
}
|
||||
}else if(args.length >= 2){
|
||||
try{
|
||||
newHomeNumber = Integer.parseInt(args[0]);
|
||||
}catch(NumberFormatException ex){
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
newHomeNumber = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
} else if (args.length >= 2) {
|
||||
try {
|
||||
newHomeNumber = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
player = _plugin.getOfflinePlayer(args[1]);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
player = _plugin.getOfflinePlayer(args[1]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(player == null || !_plugin.homeExists(player.getUniqueId(), newHomeNumber)){
|
||||
return false;
|
||||
}
|
||||
if (player == null || !_plugin.homeExists(player.getUniqueId(), newHomeNumber)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_plugin.setHome(player.getUniqueId(), newHomeNumber);
|
||||
|
||||
return true;
|
||||
}
|
||||
_plugin.setHome(player.getUniqueId(), newHomeNumber);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Plot;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Plot;
|
||||
|
||||
public class MetropolisPlotGoCommand implements CommandExecutor {
|
||||
MetropolisPlugin _plugin;
|
||||
MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisPlotGoCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
public MetropolisPlotGoCommand(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = null;
|
||||
Plot plot = null;
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = null;
|
||||
Plot plot = null;
|
||||
|
||||
if(sender instanceof Player){
|
||||
player = (Player) sender;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
|
||||
if(args.length == 1 && player != null){
|
||||
plot = _plugin.getPlot(args[0]);
|
||||
}else if(args.length >= 2){
|
||||
player = _plugin.getPlayer(args[1]);
|
||||
plot = _plugin.getPlot(args[0]);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1 && player != null) {
|
||||
plot = _plugin.getPlot(args[0]);
|
||||
} else if (args.length >= 2) {
|
||||
player = _plugin.getPlayer(args[1]);
|
||||
plot = _plugin.getPlot(args[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(plot == null || player == null){
|
||||
return false;
|
||||
}
|
||||
if (plot == null || player == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String errorMessage = _plugin.teleportPlayerToPlot(player, plot);
|
||||
if(errorMessage != null){
|
||||
sender.sendMessage(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
String errorMessage = _plugin.teleportPlayerToPlot(player, plot);
|
||||
if (errorMessage != null) {
|
||||
sender.sendMessage(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
@@ -11,66 +23,73 @@ import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MetropolisPlotReserveCommand implements CommandExecutor {
|
||||
MetropolisPlugin _plugin;
|
||||
MetropolisPlugin _plugin;
|
||||
|
||||
public MetropolisPlotReserveCommand(MetropolisPlugin metropolisPlugin) {
|
||||
_plugin = metropolisPlugin;
|
||||
}
|
||||
public MetropolisPlotReserveCommand(MetropolisPlugin metropolisPlugin) {
|
||||
_plugin = metropolisPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
int minX = 0;
|
||||
int minY = 0;
|
||||
int minZ = 0;
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
int maxZ = 0;
|
||||
Cuboid cuboid = new Cuboid();
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
int minX = 0;
|
||||
int minY = 0;
|
||||
int minZ = 0;
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
int maxZ = 0;
|
||||
Cuboid cuboid = new Cuboid();
|
||||
|
||||
if(sender instanceof Player && args.length == 1){
|
||||
try {
|
||||
Region selection = _plugin.worldEdit.getSession((Player) sender)
|
||||
.getSelection(BukkitAdapter.adapt(_plugin.getWorld()));
|
||||
cuboid = new Cuboid(selection);
|
||||
} catch (IncompleteRegionException ex) {
|
||||
sender.sendMessage("Select a WorldEdit region first.");
|
||||
return false;
|
||||
}
|
||||
}else if(args.length == 7){
|
||||
try{
|
||||
minX = Integer.parseInt(args[1]);
|
||||
minY = Integer.parseInt(args[2]);
|
||||
minZ = Integer.parseInt(args[3]);
|
||||
maxX = Integer.parseInt(args[4]);
|
||||
maxY = Integer.parseInt(args[5]);
|
||||
maxZ = Integer.parseInt(args[6]);
|
||||
}catch(NumberFormatException ex){
|
||||
return false;
|
||||
}
|
||||
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}else if(args.length == 5){
|
||||
try{
|
||||
minX = Integer.parseInt(args[1]);
|
||||
minY = 0;
|
||||
minZ = Integer.parseInt(args[2]);
|
||||
maxX = Integer.parseInt(args[3]);
|
||||
maxY = _plugin.getWorld().getMaxHeight();
|
||||
maxZ = Integer.parseInt(args[4]);
|
||||
}catch(NumberFormatException ex){
|
||||
return false;
|
||||
}
|
||||
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
if (sender instanceof Player && args.length == 1) {
|
||||
try {
|
||||
Region selection =
|
||||
_plugin
|
||||
.worldEdit
|
||||
.getSession((Player) sender)
|
||||
.getSelection(BukkitAdapter.adapt(_plugin.getWorld()));
|
||||
cuboid = new Cuboid(selection);
|
||||
} catch (IncompleteRegionException ex) {
|
||||
sender.sendMessage("Select a WorldEdit region first.");
|
||||
return false;
|
||||
}
|
||||
} else if (args.length == 7) {
|
||||
try {
|
||||
minX = Integer.parseInt(args[1]);
|
||||
minY = Integer.parseInt(args[2]);
|
||||
minZ = Integer.parseInt(args[3]);
|
||||
maxX = Integer.parseInt(args[4]);
|
||||
maxY = Integer.parseInt(args[5]);
|
||||
maxZ = Integer.parseInt(args[6]);
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
cuboid = new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
} else if (args.length == 5) {
|
||||
try {
|
||||
minX = Integer.parseInt(args[1]);
|
||||
minY = 0;
|
||||
minZ = Integer.parseInt(args[2]);
|
||||
maxX = Integer.parseInt(args[3]);
|
||||
maxY = _plugin.getWorld().getMaxHeight();
|
||||
maxZ = Integer.parseInt(args[4]);
|
||||
} catch (NumberFormatException ex) {
|
||||
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);
|
||||
sender.sendMessage("Reserved plot region " + regionName + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
_plugin.reserveCuboid(regionName, cuboid);
|
||||
sender.sendMessage("Reserved plot region " + regionName + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
public class DebugListener implements Listener {
|
||||
MetropolisPlugin _plugin;
|
||||
MetropolisPlugin _plugin;
|
||||
|
||||
public DebugListener(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public DebugListener(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onEvent(PlayerInteractEvent event){
|
||||
//event.
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onEvent(PlayerInteractEvent event) {
|
||||
// event.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,73 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
private MetropolisPlugin _plugin = null;
|
||||
private MetropolisPlugin _plugin = null;
|
||||
|
||||
public PlayerJoinListener(MetropolisPlugin plugin){
|
||||
_plugin = plugin;
|
||||
}
|
||||
public PlayerJoinListener(MetropolisPlugin plugin) {
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event){
|
||||
Player player = event.getPlayer();
|
||||
if(player == null){
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerHome home = _plugin.getPlayerHome(player);
|
||||
if(home==null){_plugin.getLogger().info("home is null");}
|
||||
else if(home.getCuboid() == null){_plugin.getLogger().info("home.getCuboid() is null");}
|
||||
else if(home.getCuboid().getVolume() == 0){_plugin.getLogger().info("home.getCuboid().getVolume() is 0");}
|
||||
PlayerHome home = _plugin.getPlayerHome(player);
|
||||
if (home == null) {
|
||||
_plugin.getLogger().info("home is null");
|
||||
} else if (home.getCuboid() == null) {
|
||||
_plugin.getLogger().info("home.getCuboid() is null");
|
||||
} else if (home.getCuboid().getVolume() == 0) {
|
||||
_plugin.getLogger().info("home.getCuboid().getVolume() is 0");
|
||||
}
|
||||
|
||||
if(home == null || home.getCuboid() == null || home.getCuboid().getVolume() == 0){
|
||||
_plugin.getLogger().info(String.format("Metropolis: Unable to get or create home for player %s", player.getName()));
|
||||
}else{
|
||||
Cuboid cuboid = home.getCuboid();
|
||||
player.sendMessage(String.format("Metropolis: Welcome %s your home is between (%d, %d, %d) and (%d, %d, %d)", player.getName(), cuboid.getMinX(), cuboid.getMinY(), cuboid.getMinZ(), cuboid.getMaxX(), cuboid.getMaxY(), cuboid.getMaxZ()));
|
||||
}
|
||||
}
|
||||
if (home == null || home.getCuboid() == null || home.getCuboid().getVolume() == 0) {
|
||||
_plugin
|
||||
.getLogger()
|
||||
.info(
|
||||
String.format(
|
||||
"Metropolis: Unable to get or create home for player %s", player.getName()));
|
||||
} else {
|
||||
Cuboid cuboid = home.getCuboid();
|
||||
player.sendMessage(
|
||||
String.format(
|
||||
"Metropolis: Welcome %s your home is between (%d, %d, %d) and (%d, %d, %d)",
|
||||
player.getName(),
|
||||
cuboid.getMinX(),
|
||||
cuboid.getMinY(),
|
||||
cuboid.getMinZ(),
|
||||
cuboid.getMaxX(),
|
||||
cuboid.getMaxY(),
|
||||
cuboid.getMaxZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
public class Material {
|
||||
public static final int signTypeId = 63;
|
||||
public static final int signTypeId = 63;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
class CuboidTest {
|
||||
@Test
|
||||
void convertsWorldEditBoundsToCuboidCoordinates() {
|
||||
Cuboid cuboid = new Cuboid(BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
|
||||
@Test
|
||||
void convertsWorldEditBoundsToCuboidCoordinates() {
|
||||
Cuboid cuboid = new Cuboid(BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
|
||||
|
||||
assertEquals(1, cuboid.getMinX());
|
||||
assertEquals(2, cuboid.getMinY());
|
||||
assertEquals(3, cuboid.getMinZ());
|
||||
assertEquals(4, cuboid.getMaxX());
|
||||
assertEquals(5, cuboid.getMaxY());
|
||||
assertEquals(6, cuboid.getMaxZ());
|
||||
}
|
||||
assertEquals(1, cuboid.getMinX());
|
||||
assertEquals(2, cuboid.getMinY());
|
||||
assertEquals(3, cuboid.getMinZ());
|
||||
assertEquals(4, cuboid.getMaxX());
|
||||
assertEquals(5, cuboid.getMaxY());
|
||||
assertEquals(6, cuboid.getMaxZ());
|
||||
}
|
||||
|
||||
@Test
|
||||
void comparesVectorsByXThenZThenYAndHandlesNulls() {
|
||||
assertEquals(-1, Cuboid.compareBlockVectors(null, BlockVector3.ZERO));
|
||||
assertEquals(1, Cuboid.compareBlockVectors(BlockVector3.ZERO, 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, 1), BlockVector3.at(1, 0, 2)) < 0);
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 1, 2), BlockVector3.at(1, 2, 2)) < 0);
|
||||
}
|
||||
@Test
|
||||
void comparesVectorsByXThenZThenYAndHandlesNulls() {
|
||||
assertEquals(-1, Cuboid.compareBlockVectors(null, BlockVector3.ZERO));
|
||||
assertEquals(1, Cuboid.compareBlockVectors(BlockVector3.ZERO, 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, 1), BlockVector3.at(1, 0, 2)) < 0);
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 1, 2), BlockVector3.at(1, 2, 2)) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void treatsTouchingBoundsAsIntersecting() {
|
||||
Cuboid first = new Cuboid(0, 0, 0, 10, 10, 10);
|
||||
Cuboid touching = new Cuboid(10, 10, 10, 20, 20, 20);
|
||||
Cuboid separate = new Cuboid(11, 0, 0, 20, 10, 10);
|
||||
@Test
|
||||
void treatsTouchingBoundsAsIntersecting() {
|
||||
Cuboid first = new Cuboid(0, 0, 0, 10, 10, 10);
|
||||
Cuboid touching = new Cuboid(10, 10, 10, 20, 20, 20);
|
||||
Cuboid separate = new Cuboid(11, 0, 0, 20, 10, 10);
|
||||
|
||||
assertTrue(first.intersects(touching));
|
||||
assertFalse(first.intersects(separate));
|
||||
}
|
||||
assertTrue(first.intersects(touching));
|
||||
assertFalse(first.intersects(separate));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsPointsOnBoundsButRejectsPointsOutside() {
|
||||
Cuboid cuboid = new Cuboid(1, 2, 3, 4, 5, 6);
|
||||
@Test
|
||||
void containsPointsOnBoundsButRejectsPointsOutside() {
|
||||
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, 4, 5, 6)));
|
||||
assertFalse(cuboid.contains(new Location(null, 5, 5, 6)));
|
||||
}
|
||||
assertTrue(cuboid.contains(new Location(null, 1, 2, 3)));
|
||||
assertTrue(cuboid.contains(new Location(null, 4, 5, 6)));
|
||||
assertFalse(cuboid.contains(new Location(null, 5, 5, 6)));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -11,31 +28,34 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class CurrentHomesStoreTest {
|
||||
@TempDir
|
||||
File temporaryDirectory;
|
||||
@TempDir File temporaryDirectory;
|
||||
|
||||
@Test
|
||||
void roundTripsHomesByUuid() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
Map<UUID, Integer> expected = Map.of(playerId, 3);
|
||||
@Test
|
||||
void roundTripsHomesByUuid() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
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
|
||||
void resolvesLegacyPlayerNameKeys() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
yaml.set("OldPlayerName", 2);
|
||||
yaml.save(file);
|
||||
@Test
|
||||
void resolvesLegacyPlayerNameKeys() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
yaml.set("OldPlayerName", 2);
|
||||
yaml.save(file);
|
||||
|
||||
assertEquals(Map.of(playerId, 2), CurrentHomesStore.load(file, name -> {
|
||||
assertEquals("OldPlayerName", name);
|
||||
return playerId;
|
||||
}));
|
||||
}
|
||||
assertEquals(
|
||||
Map.of(playerId, 2),
|
||||
CurrentHomesStore.load(
|
||||
file,
|
||||
name -> {
|
||||
assertEquals("OldPlayerName", name);
|
||||
return playerId;
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
class PlayerHomeTest {
|
||||
@Test
|
||||
void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
PlayerHome home = new PlayerHome(
|
||||
playerId,
|
||||
"PlayerName",
|
||||
2,
|
||||
BlockVector3.at(1, 2, 3),
|
||||
BlockVector3.at(4, 5, 6));
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
assertEquals(playerId, home.getPlayerId());
|
||||
assertEquals("PlayerName", home.getPlayerName());
|
||||
assertEquals(2, home.getNumber());
|
||||
assertEquals("h_2_" + playerId, home.getRegionName());
|
||||
}
|
||||
class PlayerHomeTest {
|
||||
@Test
|
||||
void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
PlayerHome home =
|
||||
new PlayerHome(
|
||||
playerId, "PlayerName", 2, BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
|
||||
|
||||
assertEquals(playerId, home.getPlayerId());
|
||||
assertEquals("PlayerName", home.getPlayerName());
|
||||
assertEquals(2, home.getNumber());
|
||||
assertEquals("h_2_" + playerId, home.getRegionName());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
@@ -11,12 +28,12 @@ import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PlayerLookupTest {
|
||||
@Test
|
||||
void matchesOnlinePlayerNamesCaseInsensitivelyButNotByPrefix() {
|
||||
Player player = mock(Player.class);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
@Test
|
||||
void matchesOnlinePlayerNamesCaseInsensitivelyButNotByPrefix() {
|
||||
Player player = mock(Player.class);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
|
||||
assertSame(player, PlayerLookup.findOnline("playername", List.of(player)));
|
||||
assertNull(PlayerLookup.findOnline("Player", List.of(player)));
|
||||
}
|
||||
assertSame(player, PlayerLookup.findOnline("playername", List.of(player)));
|
||||
assertNull(PlayerLookup.findOnline("Player", List.of(player)));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,24 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -9,40 +26,40 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
class MetropolisHomeAcquireTest {
|
||||
@Test
|
||||
void assignsAPlotWhenThePlayerIsBelowTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(0);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
|
||||
@Test
|
||||
void assignsAPlotWhenThePlayerIsBelowTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(0);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
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
|
||||
void doesNotAssignAPlotAfterThePlayerReachesTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(1);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
|
||||
@Test
|
||||
void doesNotAssignAPlotAfterThePlayerReachesTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(1);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -8,42 +25,46 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
class MetropolisPlotReserveCommandTest {
|
||||
@Test
|
||||
void reservesCoordinatesFromAllSixArguments() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
@Test
|
||||
void reservesCoordinatesFromAllSixArguments() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
|
||||
assertTrue(executor.onCommand(sender, command, "reserve", new String[] {"north", "1", "2", "3", "4", "5", "6"}));
|
||||
assertTrue(
|
||||
executor.onCommand(
|
||||
sender, command, "reserve", new String[] {"north", "1", "2", "3", "4", "5", "6"}));
|
||||
|
||||
ArgumentCaptor<Cuboid> cuboid = ArgumentCaptor.forClass(Cuboid.class);
|
||||
verify(plugin).reserveCuboid(eq("north"), cuboid.capture());
|
||||
assertEquals(1, cuboid.getValue().getMinX());
|
||||
assertEquals(2, cuboid.getValue().getMinY());
|
||||
assertEquals(3, cuboid.getValue().getMinZ());
|
||||
assertEquals(4, cuboid.getValue().getMaxX());
|
||||
assertEquals(5, cuboid.getValue().getMaxY());
|
||||
assertEquals(6, cuboid.getValue().getMaxZ());
|
||||
}
|
||||
ArgumentCaptor<Cuboid> cuboid = ArgumentCaptor.forClass(Cuboid.class);
|
||||
verify(plugin).reserveCuboid(eq("north"), cuboid.capture());
|
||||
assertEquals(1, cuboid.getValue().getMinX());
|
||||
assertEquals(2, cuboid.getValue().getMinY());
|
||||
assertEquals(3, cuboid.getValue().getMinZ());
|
||||
assertEquals(4, cuboid.getValue().getMaxX());
|
||||
assertEquals(5, cuboid.getValue().getMaxY());
|
||||
assertEquals(6, cuboid.getValue().getMaxZ());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsMalformedCoordinateArgumentsWithoutCallingPlugin() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
@Test
|
||||
void rejectsMalformedCoordinateArgumentsWithoutCallingPlugin() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
|
||||
assertFalse(executor.onCommand(sender, command, "reserve", new String[] {"north", "1", "two", "3", "4", "5", "6"}));
|
||||
verifyNoInteractions(plugin);
|
||||
}
|
||||
assertFalse(
|
||||
executor.onCommand(
|
||||
sender, command, "reserve", new String[] {"north", "1", "two", "3", "4", "5", "6"}));
|
||||
verifyNoInteractions(plugin);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
@@ -7,31 +24,33 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PlayerJoinListenerTest {
|
||||
@Test
|
||||
void tellsJoiningPlayerTheirHomeBounds() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
PlayerJoinEvent event = mock(PlayerJoinEvent.class);
|
||||
when(event.getPlayer()).thenReturn(player);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
when(plugin.getPlayerHome(player)).thenReturn(new PlayerHome(
|
||||
UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
|
||||
"PlayerName",
|
||||
1,
|
||||
BlockVector3.at(1, 2, 3),
|
||||
BlockVector3.at(4, 5, 6)));
|
||||
@Test
|
||||
void tellsJoiningPlayerTheirHomeBounds() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
PlayerJoinEvent event = mock(PlayerJoinEvent.class);
|
||||
when(event.getPlayer()).thenReturn(player);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
when(plugin.getPlayerHome(player))
|
||||
.thenReturn(
|
||||
new PlayerHome(
|
||||
UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
|
||||
"PlayerName",
|
||||
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)"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user