Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.froobworld.nabsuite.modules.mechs.border.WorldBorderManager;
import com.froobworld.nabsuite.modules.mechs.chat.ClickableLinkReplacer;
import com.froobworld.nabsuite.modules.mechs.command.BorderWarningCommand;
import com.froobworld.nabsuite.modules.mechs.command.EffectiveViewDistanceCommand;
import com.froobworld.nabsuite.modules.mechs.command.PvpCommand;
import com.froobworld.nabsuite.modules.mechs.command.ToggleViewDistanceCommand;
import com.froobworld.nabsuite.modules.mechs.command.NoReplantCommand;
import com.froobworld.nabsuite.modules.mechs.config.MechsConfig;
import com.froobworld.nabsuite.modules.mechs.signedit.SignEditDisabler;
import com.froobworld.nabsuite.modules.mechs.mobgriefing.MobGriefingManager;
Expand Down Expand Up @@ -50,7 +50,8 @@ public void onEnable() {
new PvpCommand(this),
new ToggleViewDistanceCommand(this),
//new EffectiveViewDistanceCommand(),
new BorderWarningCommand(this)
new BorderWarningCommand(this),
new NoReplantCommand(this)
).forEach(getPlugin().getCommandManager()::registerCommand);
}

Expand All @@ -68,6 +69,10 @@ public PvpManager getPvpManager() {
return pvpManager;
}

public TreeManager getTreeManager() {
return treeManager;
}

public ViewDistanceManager getViewDistanceManager() {
return viewDistanceManager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.froobworld.nabsuite.modules.mechs.command;

import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext;
import com.froobworld.nabsuite.command.NabCommand;
import com.froobworld.nabsuite.modules.mechs.MechsModule;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class NoReplantCommand extends NabCommand {
private final MechsModule mechsModule;

public NoReplantCommand(MechsModule mechsModule) {
super(
"noreplant",
"Toggle automatic tree replanting.",
"nabsuite.command.noreplant",
Player.class
);
this.mechsModule = mechsModule;
}

@Override
public void execute(CommandContext<CommandSender> context) {
Player sender = (Player) context.getSender();
boolean current = mechsModule.getTreeManager().replantEnabled(sender);

mechsModule.getTreeManager().setReplantEnabled(sender, !current);
if (current) {
sender.sendMessage(Component.text("Automatic tree replanting disabled temporarily.", NamedTextColor.YELLOW));
} else {
sender.sendMessage(Component.text("Automatic tree replanting enabled.", NamedTextColor.YELLOW));
}
}

@Override
public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSender> builder) {
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

public class TreeManager implements Listener {
private static final Pattern fileNamePattern = Pattern.compile("^(([0-9]+)|(-[0-9]+))\\.(([0-9]+)|(-[0-9]+))\\.json$");
protected final DataSaver regionDataSaver;
private final BiMap<UnnaturalLogRegion.Key, UnnaturalLogRegion> logRegionMap = HashBiMap.create();
private final File directory;
private final Set<UUID> noreplantPlayers = new HashSet<>();

public TreeManager(MechsModule mechsModule) {
directory = new File(mechsModule.getDataFolder(), "unnatural-logs/");
Expand Down Expand Up @@ -73,4 +79,26 @@ private void onBlockPlace(BlockPlaceEvent event) {
}
}

@EventHandler(priority = EventPriority.MONITOR)
private void onPlayerQuit(PlayerQuitEvent event) {
noreplantPlayers.remove(event.getPlayer().getUniqueId());
}

public Boolean replantEnabled(Player player) {
if (player == null) {
return true;
}
return !noreplantPlayers.contains(player.getUniqueId());
}

public void setReplantEnabled(Player player, boolean replant) {
if (player != null) {
if (!replant) {
noreplantPlayers.add(player.getUniqueId());
} else {
noreplantPlayers.remove(player.getUniqueId());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.froobworld.nabsuite.modules.mechs.trees;

import com.froobworld.nabsuite.modules.mechs.MechsModule;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -18,13 +15,12 @@ public class TreeReplanter implements Listener {
public TreeReplanter(MechsModule mechsModule, TreeManager treeManager) {
this.mechsModule = mechsModule;
this.treeManager = treeManager;

}

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
private void onBlockBreak(BlockBreakEvent event) {
if (Tag.LOGS.isTagged(event.getBlock().getType())) {
if (treeManager.isNaturalLog(event.getBlock().getLocation())) {
if (treeManager.replantEnabled(event.getPlayer()) && treeManager.isNaturalLog(event.getBlock().getLocation())) {
Material saplingMaterial = saplingTypeForWood(event.getBlock().getType());
if (saplingMaterial != null) {
schedulePlantTask(event.getBlock().getLocation(), saplingMaterial);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ permissions:
description: "Access to the /effectivevd command."
nabsuite.command.borderwarning:
description: "Access to the /borderwarning command."
nabsuite.command.noreplant:
description: "Access to the /noreplant command."

# Mechs module other permissions
nabsuite.nabmode:
Expand Down