Skip to content

Commit

Permalink
Improve FactionsUUID support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed Jul 30, 2023
1 parent 3d8bae4 commit f1ac757
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.syntaxphoenix.spigot</groupId>
<artifactId>smoothtimber-legacy</artifactId>
<version>1.24.6</version>
<version>1.24.7</version>
<name>SmoothTimber</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
package com.syntaxphoenix.spigot.smoothtimber.compatibility.factionsuuid;

import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.config.file.MainConfig;
import com.massivecraft.factions.listeners.FactionsBlockListener;
import com.massivecraft.factions.perms.PermissibleActions;
import com.syntaxphoenix.spigot.smoothtimber.event.AsyncPlayerChopTreeEvent;
import com.syntaxphoenix.spigot.smoothtimber.event.reason.DefaultReason;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class FactionsUUIDChopListener implements Listener {

private MainConfig config;
private FPlayers players;

public FactionsUUIDChopListener() {
this.config = FactionsPlugin.getInstance().conf();
this.players = FPlayers.getInstance();
}

@EventHandler
public void onAsyncPlayerChopTree(final AsyncPlayerChopTreeEvent event) {
FPlayer player = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (event.getBlockLocations().stream()
.map(FLocation::new)
.distinct()
.anyMatch(location -> !Board.getInstance().getFactionAt(location).hasAccess(player, PermissibleActions.DESTROY, location))
) {
event.setCancelled(true);
event.setReason(DefaultReason.FACTIONS);
Player player = event.getPlayer();
if (config.factions().protection().getPlayersWhoBypassAllProtection().contains(player.getName()) || players.getByPlayer(player).isAdminBypassing()) {
return;
}
for(Location bktLocation : event.getBlockLocations()) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), bktLocation, PermissibleActions.DESTROY, true)) {
event.setCancelled(true);
event.setReason(DefaultReason.FACTIONS);
return;
}
}
}

Expand Down

0 comments on commit f1ac757

Please sign in to comment.