Skip to content

Commit 2b9968a

Browse files
committed
Add towny compatibilty & most other claim plugins partial compatibility.
1 parent ea68ad0 commit 2b9968a

7 files changed

Lines changed: 59 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.1.0
2+
Add towny compatibilty & most other claim plugins partial compatibility.
3+
14
# 1.0.0
25
Break woods & logs connected to the broken block by a face, an edge or a corner.
36
Avoid adding block to the queue more than once.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[**Discord**](https://discord.gg/RPNbtRSFqG) | [**Hangar**](https://hangar.papermc.io/Hydrolien/TreeFalls) | [**Modrinth**](https://modrinth.com/plugin/treefalls) | [**GitHub**](https://github.com/Mvndi/TreeFalls)
1010

1111
# TreeFalls
12+
1213
Smooth tree falling Paper/Folia plugin.
1314

1415
<img src="TreeFalls.gif" alt="tree falls" width="640" height="360" loop=infinite>
@@ -28,6 +29,11 @@ In the config you can set :
2829
- The list of materials that are concidered as trees.
2930
- The list of tools that are concidered as breaking tree tools.
3031

32+
## Claim plugins
33+
34+
Trees can't be cut in protected area for any protection plugin if it does not have blocks outside of the protected area.
35+
Towny town get an extra layer of protection, trying to cut a tree half in a foreign town will cut only the half outside of the town.
36+
3137

3238
## Statistics
3339
[![bStats Graph Data](https://bstats.org/signatures/bukkit/treefalls.svg)](https://bstats.org/plugin/bukkit/TreeFalls/29518)
@@ -38,8 +44,8 @@ Clone the project from [GitHub](https://github.com/Mvndi/TreeFalls).
3844
Run `./gradlew assemble`
3945
The plugin jar file will be in build/libs/
4046

41-
You can also start a test server directly from Gradle with `./gradlew runPaper`
47+
You can also start a test server directly from Gradle with `./gradlew runServer`
4248

4349
## Thanks
4450
Thanks to [SmoothTimber](https://github.com/SourceWriters/SmoothTimber) that inspired this project.
45-
This project is kind of a simplified version of SmoothTimber with modern tools (Maven -> Gradle, Spigot -> Paper, Manual run -> auto run with runPaper), much less dependencies and no legacy support (1.20+).
51+
This project is kind of a simplified version of SmoothTimber with modern tools (Maven -> Gradle, Spigot -> Paper, Manual run -> auto run with runServer), much less dependencies and no legacy support (1.20+).

build.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ plugins {
1111
}
1212

1313
group = "net.mvndicraft.treefalls"
14-
version = "1.0.0"
14+
version = "1.1.0"
1515
description = "Smooth tree falling when a log get broken by an axe"
1616
java.sourceCompatibility = JavaVersion.VERSION_21
1717
var mainMinecraftVersion = "1.21.11"
1818
val supportedMinecraftVersions = "1.20 - 1.21.11"
19-
19+
val townyVersion = "0.102.0.7"
2020

2121
repositories {
2222
mavenLocal()
@@ -25,10 +25,12 @@ repositories {
2525
// Paper
2626
maven("https://repo.papermc.io/repository/maven-public/")
2727
maven("https://repo.aikar.co/content/groups/aikar/")
28+
maven("https://repo.glaremasters.me/repository/towny/")
2829
}
2930

3031
dependencies {
3132
compileOnly("io.papermc.paper:paper-api:$mainMinecraftVersion-R0.1-SNAPSHOT")
33+
compileOnly("com.palmergames.bukkit.towny:towny:$townyVersion")
3234

3335
implementation("org.bstats:bstats-bukkit:3.1.0")
3436
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
@@ -81,6 +83,9 @@ tasks {
8183
}
8284

8385
runServer {
86+
downloadPlugins {
87+
github("TownyAdvanced", "Towny", "$townyVersion", "towny-$townyVersion.jar") // we can't use the latest release because it's inside a zip.
88+
}
8489
minecraftVersion("$mainMinecraftVersion")
8590
}
8691
runPaper.folia.registerTask()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.mvndicraft.treefalls;
2+
3+
import com.palmergames.bukkit.towny.object.TownyPermission.ActionType;
4+
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
5+
import org.bukkit.Location;
6+
import org.bukkit.Material;
7+
import org.bukkit.entity.Player;
8+
9+
public class TownyPerms {
10+
private TownyPerms() {}
11+
public static boolean canBreak(Player player, Location location, Material material) {
12+
return PlayerCacheUtil.getCachePermission(player, location, material, ActionType.DESTROY);
13+
}
14+
}

src/main/java/net/mvndicraft/treefalls/TreeFallsPlugin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.mvndicraft.treefalls.listener.FallingLogListener;
1616
import org.bstats.bukkit.Metrics;
1717
import org.bukkit.GameMode;
18+
import org.bukkit.Location;
1819
import org.bukkit.Material;
1920
import org.bukkit.NamespacedKey;
2021
import org.bukkit.entity.Player;
@@ -25,6 +26,7 @@ public class TreeFallsPlugin extends JavaPlugin {
2526
private Set<Material> axes;
2627
private Set<GameMode> gameModes;
2728
private NamespacedKey fallingLogKey = new NamespacedKey(this, "falling_log");
29+
private boolean townyEnabled;
2830
@Override
2931
public void onEnable() {
3032
new Metrics(this, 29518);
@@ -37,6 +39,8 @@ public void onEnable() {
3739

3840
getServer().getPluginManager().registerEvents(new BrokenLogListener(), this);
3941
getServer().getPluginManager().registerEvents(new FallingLogListener(), this);
42+
43+
townyEnabled = getServer().getPluginManager().getPlugin("Towny") != null;
4044
}
4145

4246
@Override
@@ -59,6 +63,11 @@ public void reloadConfig() {
5963
public boolean isGameModeOK(Player player) { return gameModes.contains(player.getGameMode()); }
6064
public NamespacedKey getFallingLogKey() { return fallingLogKey; }
6165

66+
// true if Towny is not enabled or if the player has Towny perms
67+
public boolean hasTownyPerms(Player player, Location location, Material material) {
68+
return !townyEnabled || TownyPerms.canBreak(player, location, material);
69+
}
70+
6271
private Set<GameMode> getConfigGameMode(String key) {
6372
if (!getConfig().isList(key)) {
6473
getLogger().warning(() -> "Invalid GameModes in config at '" + key + "': " + getConfig().get(key));

src/main/java/net/mvndicraft/treefalls/listener/BrokenLogListener.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.bukkit.entity.FallingBlock;
1313
import org.bukkit.entity.Player;
1414
import org.bukkit.event.EventHandler;
15+
import org.bukkit.event.EventPriority;
1516
import org.bukkit.event.Listener;
1617
import org.bukkit.event.block.BlockBreakEvent;
1718
import org.bukkit.inventory.ItemStack;
@@ -22,7 +23,9 @@
2223
public class BrokenLogListener implements Listener {
2324

2425
// Towny & most other plugins compatibility works by ignoring cancelled events
25-
@EventHandler(ignoreCancelled = true)
26+
// HIGHEST priority to allow Towny or other plugin to cancel the event.
27+
// Towny get an extra test to avoid breaking trees that are half in a claim.
28+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
2629
public void onLogBroken(BlockBreakEvent event) {
2730
if (TreeFallsPlugin.getInstance().isWood(event.getBlock().getType())
2831
&& TreeFallsPlugin.getInstance().isAxe(event.getPlayer().getInventory().getItemInMainHand().getType())
@@ -40,15 +43,17 @@ private void cutTree(Block block, Player player) {
4043
int cuttedBlocks = 0;
4144
while (!woodQueue.isEmpty() && cuttedBlocks < maxTreeSize && reduceDurability(player)) {
4245
block = woodQueue.poll();
43-
fallBlock(block);
44-
TreeFallsPlugin.debug("Falling block: " + block);
45-
for (Block nextBlock : getNextBlocks(block)) {
46-
if (TreeFallsPlugin.getInstance().isWood(nextBlock.getType()) && !woodQueue.contains(nextBlock)) {
47-
woodQueue.add(nextBlock);
48-
TreeFallsPlugin.debug("Added block to queue: " + nextBlock);
46+
if (TreeFallsPlugin.getInstance().hasTownyPerms(player, block.getLocation(), block.getType())) {
47+
fallBlock(block);
48+
TreeFallsPlugin.debug("Falling block: " + block);
49+
for (Block nextBlock : getNextBlocks(block)) {
50+
if (TreeFallsPlugin.getInstance().isWood(nextBlock.getType()) && !woodQueue.contains(nextBlock)) {
51+
woodQueue.add(nextBlock);
52+
TreeFallsPlugin.debug("Added block to queue: " + nextBlock);
53+
}
4954
}
55+
cuttedBlocks++;
5056
}
51-
cuttedBlocks++;
5257
}
5358
TreeFallsPlugin.debug("Cutted " + cuttedBlocks + " blocks");
5459
TreeFallsPlugin.debug("Can more blocks be cut? " + (cuttedBlocks < maxTreeSize));

src/main/resources/paper-plugin.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ folia-supported: true
66
authors: [ Hydrolien ]
77
description: $description
88
website: mvndicraft.net
9+
dependencies:
10+
server:
11+
Towny:
12+
required: false
13+
load: BEFORE

0 commit comments

Comments
 (0)