Chop toggle.

This commit is contained in:
Brianna O'Keefe 2019-02-06 01:38:37 -05:00
parent 08d304444e
commit 041c265024
6 changed files with 65 additions and 15 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "UltimateTimber"
path: "/builds/$CI_PROJECT_PATH"
version: "1.0.5"
version: "1.0.8"
build:
stage: build

View File

@ -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<World> validWorlds = new ArrayList<>();
private List<UUID> 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());
}
}

View File

@ -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;
}
}

View File

@ -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"));
}
}

View File

@ -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"));
}
}
}

View File

@ -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<Block> blocks = treeChecker.validTreeHandler(event.getBlock());