mirror of
https://github.com/darksaid98/TownyRangeLimit.git
synced 2026-12-04 14:38:59 +00:00
Java 17
This commit is contained in:
1 parent
cb43d34be5
commit
80434fd2dd
2 files changed
+63
-38
No files matched your search
@@ -12,7 +12,8 @@
|
|||||||
<name>TownyRangeLimit</name>
|
<name>TownyRangeLimit</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -69,15 +70,15 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.19-R0.1-SNAPSHOT</version>
|
<version>1.19-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.LlmDl</groupId>
|
<groupId>com.github.LlmDl</groupId>
|
||||||
<artifactId>Towny</artifactId>
|
<artifactId>Towny</artifactId>
|
||||||
<version>0.98.6.0</version>
|
<version>0.98.3.3</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ package org.aubrithehuman.townyrangelimit;
|
|||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.TownySettings;
|
import com.palmergames.bukkit.towny.TownySettings;
|
||||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
|
||||||
import com.palmergames.bukkit.towny.object.*;
|
import com.palmergames.bukkit.towny.object.*;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -12,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
Nation nation2 = TownyAPI.getInstance().getNation(args[2]);
|
Nation nation2 = TownyAPI.getInstance().getNation(args[2]);
|
||||||
|
|
||||||
if(nation1 == null || nation2 == null) return;
|
if(nation1 == null || nation2 == null) return;
|
||||||
int dist = shortestDistance(nation1, nation2);
|
int dist = shortestDistance(nation1, nation2, event.getPlayer());
|
||||||
|
|
||||||
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
||||||
event.getPlayer().sendMessage("§e[Towny] " + "§c" + nation2.getName() + " is too far away from any town in your nation. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest town in either nation!");
|
event.getPlayer().sendMessage("§e[Towny] " + "§c" + nation2.getName() + " is too far away from any town in your nation. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest town in either nation!");
|
||||||
@@ -58,7 +60,7 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
if(r == null) return;
|
if(r == null) return;
|
||||||
Nation nation = r.getNationOrNull();
|
Nation nation = r.getNationOrNull();
|
||||||
|
|
||||||
int dist = shortestDistance(town, nation);
|
int dist = shortestDistance(town, nation, event.getPlayer());
|
||||||
|
|
||||||
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
||||||
event.getPlayer().sendMessage("§e[Towny] " + "§c" + town.getName() + " is too far away from any town in your nation. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest town in your nation!");
|
event.getPlayer().sendMessage("§e[Towny] " + "§c" + town.getName() + " is too far away from any town in your nation. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest town in your nation!");
|
||||||
@@ -75,7 +77,7 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
if(r == null) return;
|
if(r == null) return;
|
||||||
Town town = r.getTownOrNull();
|
Town town = r.getTownOrNull();
|
||||||
|
|
||||||
int dist = shortestDistance(town, nation);
|
int dist = shortestDistance(town, nation, event.getPlayer());
|
||||||
|
|
||||||
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
||||||
event.getPlayer().sendMessage("§e[Towny] " + "§c" + nation.getName() + " is too far away from any town in your town. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest town in that nation!");
|
event.getPlayer().sendMessage("§e[Towny] " + "§c" + nation.getName() + " is too far away from any town in your town. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest town in that nation!");
|
||||||
@@ -96,7 +98,7 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
if(town1 == null || town2 == null) return;
|
if(town1 == null || town2 == null) return;
|
||||||
|
|
||||||
int dist = shortestDistance(town1, town2);
|
int dist = shortestDistance(town1, town2, event.getPlayer());
|
||||||
|
|
||||||
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
if (dist > this.getConfig().getInt("townblockRangeMax")) {
|
||||||
event.getPlayer().sendMessage("§e[Towny] " + "§c" + town2.getName() + " is too far away from your town. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest chunk in your town!");
|
event.getPlayer().sendMessage("§e[Towny] " + "§c" + town2.getName() + " is too far away from your town. Must be within " + (this.getConfig().getInt("townblockRangeMax") * TownySettings.getTownBlockSize()) + " blocks of the nearest chunk in your town!");
|
||||||
@@ -114,16 +116,27 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
* @param town2 town1
|
* @param town2 town1
|
||||||
* @return shortest distance
|
* @return shortest distance
|
||||||
*/
|
*/
|
||||||
private static int shortestDistance(Town town1, Town town2) {
|
private static int shortestDistance(Town town1, Town town2, Player p) {
|
||||||
//max possible range (60M*sqrt2)
|
//max possible range (60M*sqrt2)
|
||||||
// 16 is block size
|
// 16 is block size
|
||||||
int dist = 84852814 / 16;
|
int dist = 84852814 / 16;
|
||||||
if (town1 != null && town2 != null) {
|
if (town1 != null && town2 != null) {
|
||||||
try {
|
TownBlock townHomeBlock1 = town1.getHomeBlockOrNull();
|
||||||
ArrayList<WorldCoord> clusterInvited = getCluster(town1.getHomeBlock().getWorldCoord());
|
TownBlock townHomeBlock2 = town2.getHomeBlockOrNull();
|
||||||
ArrayList<WorldCoord> clusterInviter = getCluster(town2.getHomeBlock().getWorldCoord());
|
if(townHomeBlock1 == null) {
|
||||||
WorldCoord invitedHomeblock = town1.getHomeBlock().getWorldCoord();
|
Bukkit.getLogger().log(Level.SEVERE, "[TownyRangeLimit] " + town1.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
WorldCoord inviterHomeblock = town2.getHomeBlock().getWorldCoord();
|
p.sendMessage("[TownyRangeLimit] " + town1.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
if(townHomeBlock2 == null) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "[TownyRangeLimit] " + town2.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
p.sendMessage("[TownyRangeLimit] " + town2.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
ArrayList<WorldCoord> clusterInvited = getCluster(townHomeBlock1.getWorldCoord());
|
||||||
|
ArrayList<WorldCoord> clusterInviter = getCluster(townHomeBlock2.getWorldCoord());
|
||||||
|
WorldCoord invitedHomeblock = townHomeBlock1.getWorldCoord();
|
||||||
|
WorldCoord inviterHomeblock = townHomeBlock2.getWorldCoord();
|
||||||
|
|
||||||
//find nearest block to inviter homeblock
|
//find nearest block to inviter homeblock
|
||||||
WorldCoord nearestInviter = null;
|
WorldCoord nearestInviter = null;
|
||||||
@@ -168,9 +181,6 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
dist = (int) Math.sqrt(((nearestInviter.getX() - nearestInvited.getX()) * (nearestInviter.getX() - nearestInvited.getX())) + ((nearestInviter.getZ() - nearestInvited.getZ()) * (nearestInviter.getZ() - nearestInvited.getZ())));
|
dist = (int) Math.sqrt(((nearestInviter.getX() - nearestInvited.getX()) * (nearestInviter.getX() - nearestInvited.getX())) + ((nearestInviter.getZ() - nearestInvited.getZ()) * (nearestInviter.getZ() - nearestInvited.getZ())));
|
||||||
|
|
||||||
} catch (TownyException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
@@ -181,23 +191,34 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
* @param nation nation
|
* @param nation nation
|
||||||
* @return shortest distance
|
* @return shortest distance
|
||||||
*/
|
*/
|
||||||
private static int shortestDistance(Town town, Nation nation) {
|
private static int shortestDistance(Town town, Nation nation, Player p) {
|
||||||
//max possible range (60M*sqrt2)
|
//max possible range (60M*sqrt2)
|
||||||
// 16 is block size
|
// 16 is block size
|
||||||
int dist = 84852814 / 16;
|
int dist = 84852814 / 16;
|
||||||
if (town != null && nation != null) {
|
if (town != null && nation != null) {
|
||||||
try {
|
TownBlock townHomeBlockM = town.getHomeBlockOrNull();
|
||||||
ArrayList<WorldCoord> clusterInvited = getCluster(town.getHomeBlock().getWorldCoord());
|
if(townHomeBlockM == null) {
|
||||||
WorldCoord invitedHomeblock = town.getHomeBlock().getWorldCoord();
|
Bukkit.getLogger().log(Level.SEVERE, "[TownyRangeLimit] " + town.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
p.sendMessage("[TownyRangeLimit] " + town.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
ArrayList<WorldCoord> clusterInvited = getCluster(townHomeBlockM.getWorldCoord());
|
||||||
|
WorldCoord invitedHomeblock = townHomeBlockM.getWorldCoord();
|
||||||
|
|
||||||
//Grab all the towns in the nation
|
//Grab all the towns in the nation
|
||||||
List<Town> nation1Towns = nation.getTowns();
|
List<Town> nation1Towns = nation.getTowns();
|
||||||
ArrayList<ArrayList<WorldCoord>> clustersInviter = new ArrayList<>();
|
ArrayList<ArrayList<WorldCoord>> clustersInviter = new ArrayList<>();
|
||||||
ArrayList<WorldCoord> inviterHomeblocks = new ArrayList<>();
|
ArrayList<WorldCoord> inviterHomeblocks = new ArrayList<>();
|
||||||
for (Town t : nation1Towns) {
|
for (Town t : nation1Towns) {
|
||||||
clustersInviter.add(getCluster(nation.getCapital().getHomeBlock().getWorldCoord()));
|
TownBlock townHomeBlock = t.getHomeBlockOrNull();
|
||||||
|
if(townHomeBlock == null) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "[TownyRangeLimit] " + t.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
p.sendMessage("[TownyRangeLimit] " + t.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
clustersInviter.add(getCluster(townHomeBlock.getWorldCoord()));
|
||||||
//grab homeblocks
|
//grab homeblocks
|
||||||
inviterHomeblocks.add(t.getHomeBlock().getWorldCoord());
|
inviterHomeblocks.add(townHomeBlock.getWorldCoord());
|
||||||
}
|
}
|
||||||
|
|
||||||
//find nearest block to invited homeblock
|
//find nearest block to invited homeblock
|
||||||
@@ -246,9 +267,6 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
dist = (int) Math.sqrt(((nearestInviter.getX() - nearestInvited.getX()) * (nearestInviter.getX() - nearestInvited.getX())) + ((nearestInviter.getZ() - nearestInvited.getZ()) * (nearestInviter.getZ() - nearestInvited.getZ())));
|
dist = (int) Math.sqrt(((nearestInviter.getX() - nearestInvited.getX()) * (nearestInviter.getX() - nearestInvited.getX())) + ((nearestInviter.getZ() - nearestInvited.getZ()) * (nearestInviter.getZ() - nearestInvited.getZ())));
|
||||||
|
|
||||||
} catch (TownyException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
@@ -260,20 +278,24 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
* @return shortest distance
|
* @return shortest distance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static int shortestDistance(Nation nation1, Nation nation2) {
|
private static int shortestDistance(Nation nation1, Nation nation2, Player p) {
|
||||||
//max possible range (60M*sqrt2)
|
//max possible range (60M*sqrt2)
|
||||||
// 16 is block size
|
// 16 is block size
|
||||||
int dist = 84852814 / 16;
|
int dist = 84852814 / 16;
|
||||||
if (nation1 != null && nation2 != null) {
|
if (nation1 != null && nation2 != null) {
|
||||||
try {
|
|
||||||
|
|
||||||
//Grab all the towns in the nation
|
//Grab all the towns in the nation
|
||||||
List<Town> nation1Towns = nation1.getTowns();
|
List<Town> nation1Towns = nation1.getTowns();
|
||||||
ArrayList<ArrayList<WorldCoord>> clustersInviter = new ArrayList<>();
|
ArrayList<ArrayList<WorldCoord>> clustersInviter = new ArrayList<>();
|
||||||
ArrayList<WorldCoord> inviterHomeblocks = new ArrayList<>();
|
ArrayList<WorldCoord> inviterHomeblocks = new ArrayList<>();
|
||||||
for (Town t : nation1Towns) {
|
for (Town t : nation1Towns) {
|
||||||
clustersInviter.add(getCluster(nation1.getCapital().getHomeBlock().getWorldCoord()));
|
TownBlock townHomeBlock = t.getHomeBlockOrNull();
|
||||||
inviterHomeblocks.add(t.getHomeBlock().getWorldCoord());
|
if(townHomeBlock == null) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "[TownyRangeLimit] " + t.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
p.sendMessage("[TownyRangeLimit] " + t.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
clustersInviter.add(getCluster(townHomeBlock.getWorldCoord()));
|
||||||
|
inviterHomeblocks.add(townHomeBlock.getWorldCoord());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,9 +304,14 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
ArrayList<ArrayList<WorldCoord>> clustersInvited = new ArrayList<>();
|
ArrayList<ArrayList<WorldCoord>> clustersInvited = new ArrayList<>();
|
||||||
ArrayList<WorldCoord> invitedHomeblocks = new ArrayList<>();
|
ArrayList<WorldCoord> invitedHomeblocks = new ArrayList<>();
|
||||||
for (Town t : nation2Towns) {
|
for (Town t : nation2Towns) {
|
||||||
clustersInvited.add(getCluster(nation2.getCapital().getHomeBlock().getWorldCoord()));
|
TownBlock townHomeBlock = t.getHomeBlockOrNull();
|
||||||
invitedHomeblocks.add(t.getHomeBlock().getWorldCoord());
|
if(townHomeBlock == null) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "[TownyRangeLimit] " + t.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
p.sendMessage("[TownyRangeLimit] " + t.getName() + " has not set a home block! Town must have a homeblock! Failing automatically.");
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
clustersInvited.add(getCluster(townHomeBlock.getWorldCoord()));
|
||||||
|
invitedHomeblocks.add(townHomeBlock.getWorldCoord());
|
||||||
}
|
}
|
||||||
|
|
||||||
//This may take forever :skull: at like multiple 900 size towns it takes like 1mil iterations?????
|
//This may take forever :skull: at like multiple 900 size towns it takes like 1mil iterations?????
|
||||||
@@ -359,9 +386,6 @@ public final class TownyRangeLimit extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
dist = (int) Math.sqrt(((nearestInviter1.getX() - nearestInvited1.getX()) * (nearestInviter1.getX() - nearestInvited1.getX())) + ((nearestInviter1.getZ() - nearestInvited1.getZ()) * (nearestInviter1.getZ() - nearestInvited1.getZ())));
|
dist = (int) Math.sqrt(((nearestInviter1.getX() - nearestInvited1.getX()) * (nearestInviter1.getX() - nearestInvited1.getX())) + ((nearestInviter1.getZ() - nearestInvited1.getZ()) * (nearestInviter1.getZ() - nearestInvited1.getZ())));
|
||||||
|
|
||||||
} catch (TownyException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user