Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Towny API and other Depends #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down Expand Up @@ -122,6 +122,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>glaremasters repo</id>
<url>https://repo.glaremasters.me/repository/towny/</url>
</repository>
<repository>
<!-- LWC Extended -->
<id>ender-repo</id>
Expand All @@ -139,7 +143,7 @@
<repository>
<!-- MythicLib (MMOItems) -->
<id>MMOPlugins</id>
<url>https://mvn.lumine.io/repository/maven-releases/</url>
<url>https://mvn.lumine.io/repository/maven-public/</url>
</repository>
<repository>
<!-- Shopkeepers -->
Expand All @@ -152,7 +156,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -284,8 +288,8 @@
<dependency>
<!-- https://mythiccraft.io/index.php?pages/official-mythiclib-dev/ -->
<groupId>io.lumine</groupId>
<artifactId>MythicLib</artifactId>
<version>1.0.19</version>
<artifactId>MythicLib-dist</artifactId>
<version>1.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -297,9 +301,9 @@
</dependency>
<dependency>
<!-- https://www.spigotmc.org/resources/towny-advanced.72694/history -->
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.97.0.0</version>
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>towny</artifactId>
<version>0.98.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
34 changes: 15 additions & 19 deletions src/com/dre/brewery/utility/TownyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;

import org.bukkit.Location;
import org.bukkit.entity.Player;

Expand All @@ -14,36 +13,33 @@ private TownyUtil() {
}

public static boolean isInsideTown(Location location) {
try {
final TownBlock townBlock = TownyAPI.getInstance().getTownBlock(location);
if (townBlock != null) {
final Town town = TownyAPI.getInstance().getTownBlock(location).getTown();
if (town != null) {
// Execute your code here
return true;
}
}
} catch (NullPointerException | NotRegisteredException e) {
}
return false;
return TownyAPI.getInstance().getTown(location) != null;
}

public static boolean isInsideTown(Location location, Player player) {
if (player == null)
return isInsideTown(location);

final Resident resident = TownyAPI.getInstance().getResident(player);
if (resident == null || resident.hasTown())
return false; // if the resident doesnt exist or isnt in a town we can ignore them
final TownBlock townBlock = TownyAPI.getInstance().getTownBlock(location);
if (townBlock == null) return false; // no town here, we can leave
try {
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(player.getName());
TownBlock townBlock = TownyAPI.getInstance().getTownBlock(location);
if (townBlock != null && townBlock.hasResident()
&& resident.equals(townBlock.getResident()))
if (townBlock.hasResident() && resident.equals(townBlock.getResident())) // check if resident owns this plot
return true;
} catch (NotRegisteredException ignored) { // should never be fired bc we check if the townblock has a resident
return false; // unnecessary bút lets be safe
}

final Town town = TownyAPI.getInstance().getTownBlock(location).getTown();
final Town town = TownyAPI.getInstance().getTown(location);
try {
if (resident.getTown().equals(town)) {
// Execute your code here
return true;
}
} catch (NullPointerException | NotRegisteredException e) {
} catch (NotRegisteredException ignored) { // checked earlier
return false; // unnecessary but lets be safe
}
return false;
}
Expand Down