Use FactionsUUID and latest Towny

This commit is contained in:
Norbi Peti 2020-07-24 23:46:25 +02:00
parent c49ab63e25
commit 97928aff30
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 33 additions and 39 deletions

13
pom.xml
View file

@ -54,8 +54,8 @@
<url>https://jitpack.io</url>
</repository>
<repository>
<id>repo</id>
<url>file://${basedir}/repo</url>
<id>Factions</id>
<url>http://ci.ender.zone/plugin/repository/everything/</url>
</repository>
</repositories>
<dependencies>
@ -83,17 +83,12 @@
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>MassiveCore</artifactId>
<version>3.2.2</version>
<version>1.6.9.5-U0.5.16</version>
</dependency>
<dependency>
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>Towny</artifactId>
<version>0.95.2.0</version>
<version>0.96.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>

View file

@ -3,13 +3,13 @@ package buttondevteam.presents.components.townyfactions;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.presents.ButtonPresents;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.event.LandClaimEvent;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.event.TownPreClaimEvent;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Coord;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Location;
import org.bukkit.World;
@ -35,43 +35,42 @@ public class TownyFactionsComponent extends Component<ButtonPresents> implements
}
@EventHandler(ignoreCancelled = true)
public void onFactionsClaim(EventFactionsChunksChange event) throws NotRegisteredException {
if (event.getNewFaction().isNone())
public void onFactionsClaim(LandClaimEvent event) throws NotRegisteredException {
if (event.getFaction().isWilderness())
return; //Allow unclaiming
for (PS chunk : event.getChunks()) {
int x = chunk.getChunkX() * 16;
int z = chunk.getChunkZ() * 16;
int size = Coord.getCellSize();
int amount = 16 / size;
World world = chunk.asBukkitWorld();
int max = 0;
if (amount < 1) amount = 1; //For plot sizes > 16
for (int i = 0; i < amount; i++) {
for (int j = 0; j < amount; j++) {
Coord coord = Coord.parseCoord(new Location(world, x + i * size, 64, z + j * size));
int dist = TownyUniverse.getDataSource().getWorld(world.getName())
.getMinDistanceFromOtherTownsPlots(coord);
if (dist > max) max = dist;
}
}
int distance = max / amount;
if (distance().get() >= distance) {
event.setCancelled(true);
event.getSender().sendMessage("§cYou are too close to a town! " + (distance - 1) + " chunks away, " + distance().get() + " is allowed.");
FLocation chunk = event.getLocation();
long x = chunk.getX() << 4;
long z = chunk.getZ() << 4;
int size = Coord.getCellSize();
int amount = 16 / size;
World world = chunk.getWorld();
int max = 0;
if (amount < 1) amount = 1; //For plot sizes > 16
for (int i = 0; i < amount; i++) {
for (int j = 0; j < amount; j++) {
Coord coord = Coord.parseCoord(new Location(world, x + i * size, 64, z + j * size));
int dist = TownyAPI.getInstance().getDataSource().getWorld(world.getName())
.getMinDistanceFromOtherTownsPlots(coord);
if (dist > max) max = dist;
}
}
int distance = max / amount;
if (distance().get() >= distance) {
event.setCancelled(true);
event.getfPlayer().sendMessage("§cYou are too close to a town! " + (distance - 1) + " chunks away, " + distance().get() + " is allowed.");
}
}
@EventHandler(ignoreCancelled = true)
public void onTownyClaim(TownPreClaimEvent event) {
PS coord = PS.valueOf(getLocation(event.getTownBlock().getWorldCoord()));
FLocation coord = new FLocation(getLocation(event.getTownBlock().getWorldCoord()));
int distance = distance().get();
for (int i = -distance + 1; i <= distance - 1; i++) {
for (int j = -distance + 1; j <= distance - 1; j++) {
if (i * i + j * j <= distance * distance) {
PS chunk = PS.valueOf(coord.getChunkX(true) + i, coord.getChunkZ(true) + j)
.withWorld(coord.getWorld());
if (!BoardColl.get().getFactionAt(chunk).isNone()) {
FLocation chunk = new FLocation(coord.getWorldName(), (int) coord.getX() + i, (int) coord.getZ() + j);
if (!Board.getInstance().getFactionAt(chunk).isWilderness()) {
event.setCancelMessage("§cYou are too close to a faction! " + (distance - 1) + " chunks away, " + distance().get() + " is allowed.");
event.setCancelled(true);
}
}