diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8559e05..c6a1f3f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "UltimateTimber" path: "/builds/$CI_PROJECT_PATH" - version: "1.0.5" + version: "1.0.8" build: stage: build diff --git a/src/main/java/com/songoda/ultimatetimber/UltimateTimber.java b/src/main/java/com/songoda/ultimatetimber/UltimateTimber.java index fd68122..fdef0fd 100644 --- a/src/main/java/com/songoda/ultimatetimber/UltimateTimber.java +++ b/src/main/java/com/songoda/ultimatetimber/UltimateTimber.java @@ -10,11 +10,13 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.UUID; /* Note: In this plugin, I have called the act of a tree falling over with pseudo-physics "toppling over". This is reflected @@ -27,6 +29,7 @@ public class UltimateTimber extends JavaPlugin { private static UltimateTimber INSTANCE; private final String prefix = "&8[&6UltimateTimber&8]"; private List validWorlds = new ArrayList<>(); + private List isNotChopping = new ArrayList<>(); public static UltimateTimber getInstance() { return INSTANCE; @@ -40,7 +43,7 @@ public class UltimateTimber extends JavaPlugin { INSTANCE = this; console.sendMessage(Methods.formatText("&a=============================")); - console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); + console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!")); console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); /* Register the main event that handles toppling down trees @@ -102,4 +105,18 @@ public class UltimateTimber extends JavaPlugin { return true; } + public boolean toggleChopping(Player player) { + if (!isNotChopping.contains(player.getUniqueId())) { + isNotChopping.add(player.getUniqueId()); + return false; + } + isNotChopping.remove(player.getUniqueId()); + return true; + } + + public boolean isChopping(Player player) { + return !isNotChopping.contains(player.getUniqueId()); + } + + } diff --git a/src/main/java/com/songoda/ultimatetimber/commands/CommandHandler.java b/src/main/java/com/songoda/ultimatetimber/commands/CommandHandler.java index d3e12b9..20c3309 100644 --- a/src/main/java/com/songoda/ultimatetimber/commands/CommandHandler.java +++ b/src/main/java/com/songoda/ultimatetimber/commands/CommandHandler.java @@ -2,9 +2,11 @@ package com.songoda.ultimatetimber.commands; import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.utils.Methods; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class CommandHandler implements CommandExecutor { @@ -19,16 +21,39 @@ public class CommandHandler implements CommandExecutor { if (args.length > 0) if (args[0].equalsIgnoreCase("reload")) { + if (commandSender instanceof Player && !permCheck((Player) commandSender, "ultimatetimber.reload")) { + return true; + } ReloadCommand.reloadConfig(commandSender); return true; + } else if (args[0].equalsIgnoreCase("toggle")) { + if (commandSender instanceof Player) { + if (!permCheck((Player) commandSender, "ultimatetimber.toggle")) { + return true; + } + ToggleCommand.toggleChopping((Player) commandSender); + return true; + } + commandSender.sendMessage(Methods.formatText("&cConsole cannot toggle chopping mode!")); + return true; } commandSender.sendMessage(""); - commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna")); + commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda")); commandSender.sendMessage(Methods.formatText("&8 - &a/ut reload &7 - Reloads the config.")); + commandSender.sendMessage(Methods.formatText("&8 - &a/ut toggle &7 - Toggles your chopping mode")); commandSender.sendMessage(""); return true; } + private boolean permCheck(Player sender, String permission) { + if (!sender.hasPermission(permission)) { + sender.sendMessage(Methods.formatText("&cYou don't have permission for that!")); + return false; + } + return true; + } + + } diff --git a/src/main/java/com/songoda/ultimatetimber/commands/ReloadCommand.java b/src/main/java/com/songoda/ultimatetimber/commands/ReloadCommand.java index 43fb0cc..c51a388 100644 --- a/src/main/java/com/songoda/ultimatetimber/commands/ReloadCommand.java +++ b/src/main/java/com/songoda/ultimatetimber/commands/ReloadCommand.java @@ -10,22 +10,10 @@ import org.bukkit.entity.Player; class ReloadCommand { static void reloadConfig(CommandSender commandSender) { - - if (commandSender instanceof Player) { - - if (!commandSender.hasPermission("ut.reload")) { - commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou don't have permission!")); - return; - } - - } - UltimateTimber plugin = UltimateTimber.getInstance(); plugin.reloadConfig(); CustomLoot.initializeCustomItems(); commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Configuration reloaded")); - - } } diff --git a/src/main/java/com/songoda/ultimatetimber/commands/ToggleCommand.java b/src/main/java/com/songoda/ultimatetimber/commands/ToggleCommand.java new file mode 100644 index 0000000..75f7ab2 --- /dev/null +++ b/src/main/java/com/songoda/ultimatetimber/commands/ToggleCommand.java @@ -0,0 +1,18 @@ +package com.songoda.ultimatetimber.commands; + + +import com.songoda.ultimatetimber.UltimateTimber; +import com.songoda.ultimatetimber.utils.Methods; +import org.bukkit.entity.Player; + +public class ToggleCommand { + + public static void toggleChopping(Player player) { + if (UltimateTimber.getInstance().toggleChopping(player)) { + player.sendMessage(Methods.formatText("UT Chopping Mode: &aEnabled")); + } else { + player.sendMessage(Methods.formatText("UT Chopping Mode: &cDisabled")); + } + } + +} diff --git a/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java b/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java index b4f0fa4..830a56e 100644 --- a/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java +++ b/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java @@ -29,6 +29,8 @@ public class TreeFallEvent implements Listener { if (!EventFilter.eventIsValid(event)) return; if (fileConfiguration.getBoolean(DefaultConfig.SNEAK_ONLY) && !event.getPlayer().isSneaking()) return; + if (!UltimateTimber.getInstance().isChopping(event.getPlayer())) return; + TreeChecker treeChecker = new TreeChecker(); HashSet blocks = treeChecker.validTreeHandler(event.getBlock());