mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-09-27 13:22:39 +02:00
Tab complete, valid world reloading, onDisable message
This commit is contained in:
parent
5cad56e436
commit
83ceca627c
@ -1,22 +1,24 @@
|
|||||||
package com.songoda.ultimatetimber;
|
package com.songoda.ultimatetimber;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.commands.CommandHandler;
|
import com.songoda.ultimatetimber.commands.CommandHandler;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
||||||
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
||||||
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
|
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
|
||||||
import com.songoda.ultimatetimber.treefall.TreeFallListener;
|
import com.songoda.ultimatetimber.treefall.TreeFallListener;
|
||||||
import com.songoda.ultimatetimber.utils.Methods;
|
import com.songoda.ultimatetimber.utils.Methods;
|
||||||
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
|
Note: In this plugin, I have called the act of a tree falling over with pseudo-physics "toppling over". This is reflected
|
||||||
@ -25,10 +27,12 @@ PS: MagmaGuy was here
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class UltimateTimber extends JavaPlugin {
|
public class UltimateTimber extends JavaPlugin {
|
||||||
private static CommandSender console = Bukkit.getConsoleSender();
|
|
||||||
|
private final static CommandSender console = Bukkit.getConsoleSender();
|
||||||
private static UltimateTimber INSTANCE;
|
private static UltimateTimber INSTANCE;
|
||||||
|
|
||||||
private final String prefix = "&8[&6UltimateTimber&8]";
|
private final String prefix = "&8[&6UltimateTimber&8]";
|
||||||
private List<World> validWorlds = new ArrayList<>();
|
private Set<String> validWorlds;
|
||||||
private List<UUID> isNotChopping = new ArrayList<>();
|
private List<UUID> isNotChopping = new ArrayList<>();
|
||||||
|
|
||||||
public static UltimateTimber getInstance() {
|
public static UltimateTimber getInstance() {
|
||||||
@ -66,23 +70,39 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
CustomLoot.initializeCustomItems();
|
CustomLoot.initializeCustomItems();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cache valid worlds for later use
|
Cache valid world names for later use
|
||||||
*/
|
*/
|
||||||
for (World world : Bukkit.getWorlds())
|
this.reloadValidWorlds();
|
||||||
if (getConfig().getBoolean(DefaultConfig.VALID_WORLDS + world.getName()))
|
|
||||||
validWorlds.add(world);
|
/*
|
||||||
|
Register command executor and tab completer
|
||||||
|
*/
|
||||||
|
PluginCommand ultimatetimber = this.getCommand("ultimatetimber");
|
||||||
|
CommandHandler commandHandler = new CommandHandler();
|
||||||
|
ultimatetimber.setExecutor(commandHandler);
|
||||||
|
ultimatetimber.setTabCompleter(commandHandler);
|
||||||
|
|
||||||
this.getCommand("ultimatetimber").setExecutor(new CommandHandler(this));
|
|
||||||
console.sendMessage(Methods.formatText("&a============================="));
|
console.sendMessage(Methods.formatText("&a============================="));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
validWorlds.clear();
|
console.sendMessage(Methods.formatText("&a============================="));
|
||||||
|
console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
|
||||||
|
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||||
|
|
||||||
|
this.validWorlds.clear();
|
||||||
|
this.isNotChopping.clear();
|
||||||
|
|
||||||
|
console.sendMessage(Methods.formatText("&a============================="));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadValidWorlds() {
|
||||||
|
this.validWorlds = this.getConfig().getConfigurationSection(DefaultConfig.VALID_WORLDS).getKeys(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<World> getValidWorlds() {
|
public boolean isWorldValid(World world) {
|
||||||
return Collections.unmodifiableList(validWorlds);
|
return this.validWorlds.contains(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
@ -96,9 +116,9 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
|
|
||||||
if (currentVersion < workingVersion) {
|
if (currentVersion < workingVersion) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||||
Bukkit.getConsoleSender().sendMessage("");
|
console.sendMessage("");
|
||||||
Bukkit.getConsoleSender().sendMessage(String.format("%sYou installed the 1.%s only version of %s on a 1.%s server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using %s.", ChatColor.RED, workingVersion, this.getDescription().getName(), currentVersion, this.getDescription().getName()));
|
console.sendMessage(String.format("%sYou installed the 1.%s only version of %s on a 1.%s server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using %s.", ChatColor.RED, workingVersion, this.getDescription().getName(), currentVersion, this.getDescription().getName()));
|
||||||
Bukkit.getConsoleSender().sendMessage("");
|
console.sendMessage("");
|
||||||
}, 20L);
|
}, 20L);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -106,17 +126,14 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean toggleChopping(Player player) {
|
public boolean toggleChopping(Player player) {
|
||||||
if (!isNotChopping.contains(player.getUniqueId())) {
|
boolean removed = this.isNotChopping.remove(player.getUniqueId());
|
||||||
isNotChopping.add(player.getUniqueId());
|
if (!removed)
|
||||||
return false;
|
this.isNotChopping.add(player.getUniqueId());
|
||||||
}
|
return removed;
|
||||||
isNotChopping.remove(player.getUniqueId());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChopping(Player player) {
|
public boolean isChopping(Player player) {
|
||||||
return !isNotChopping.contains(player.getUniqueId());
|
return !this.isNotChopping.contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
package com.songoda.ultimatetimber.commands;
|
package com.songoda.ultimatetimber.commands;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import java.util.ArrayList;
|
||||||
import com.songoda.ultimatetimber.utils.Methods;
|
import java.util.HashSet;
|
||||||
import org.bukkit.ChatColor;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
public class CommandHandler implements CommandExecutor {
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
|
import com.songoda.ultimatetimber.utils.Methods;
|
||||||
|
|
||||||
private final UltimateTimber plugin;
|
public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
public CommandHandler(UltimateTimber plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
if (args[0].equalsIgnoreCase("reload")) {
|
||||||
if (commandSender instanceof Player && !permCheck((Player) commandSender, "ultimatetimber.reload")) {
|
if (commandSender instanceof Player && !permCheck((Player) commandSender, "ultimatetimber.reload")) {
|
||||||
@ -39,7 +39,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commandSender.sendMessage("");
|
commandSender.sendMessage("");
|
||||||
commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
|
commandSender.sendMessage(Methods.formatText(UltimateTimber.getInstance().getPrefix() + " &7Version " + UltimateTimber.getInstance().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 reload &7 - Reloads the config."));
|
||||||
commandSender.sendMessage(Methods.formatText("&8 - &a/ut toggle &7 - Toggles your chopping mode"));
|
commandSender.sendMessage(Methods.formatText("&8 - &a/ut toggle &7 - Toggles your chopping mode"));
|
||||||
commandSender.sendMessage("");
|
commandSender.sendMessage("");
|
||||||
@ -55,5 +55,24 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (!(commandSender instanceof Player) || args.length == 0 || args.length > 1)
|
||||||
|
return completions;
|
||||||
|
|
||||||
|
Set<String> possibleCompletions = new HashSet<>();
|
||||||
|
|
||||||
|
if (permCheck((Player) commandSender, "ultimatetimber.reload"))
|
||||||
|
possibleCompletions.add("reload");
|
||||||
|
|
||||||
|
if (permCheck((Player) commandSender, "ultimatetimber.toggle"))
|
||||||
|
possibleCompletions.add("toggle");
|
||||||
|
|
||||||
|
StringUtil.copyPartialMatches(args[0], possibleCompletions, completions);
|
||||||
|
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package com.songoda.ultimatetimber.commands;
|
package com.songoda.ultimatetimber.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
||||||
import com.songoda.ultimatetimber.utils.Methods;
|
import com.songoda.ultimatetimber.utils.Methods;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
class ReloadCommand {
|
class ReloadCommand {
|
||||||
|
|
||||||
static void reloadConfig(CommandSender commandSender) {
|
static void reloadConfig(CommandSender commandSender) {
|
||||||
UltimateTimber plugin = UltimateTimber.getInstance();
|
UltimateTimber plugin = UltimateTimber.getInstance();
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
|
plugin.reloadValidWorlds();
|
||||||
CustomLoot.initializeCustomItems();
|
CustomLoot.initializeCustomItems();
|
||||||
commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Configuration reloaded"));
|
commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Configuration reloaded"));
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class EventFilter {
|
|||||||
General catchers
|
General catchers
|
||||||
*/
|
*/
|
||||||
if (event.isCancelled()
|
if (event.isCancelled()
|
||||||
|| !plugin.getValidWorlds().contains(event.getPlayer().getWorld())
|
|| !plugin.isWorldValid(event.getPlayer().getWorld())
|
||||||
|| !TreeChecker.validMaterials.contains(event.getBlock().getType())) return false;
|
|| !TreeChecker.validMaterials.contains(event.getBlock().getType())) return false;
|
||||||
|
|
||||||
FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig();
|
FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig();
|
||||||
|
@ -30,7 +30,7 @@ public class LeafToSaplingConverter {
|
|||||||
material = org.bukkit.Material.SPRUCE_SAPLING;
|
material = org.bukkit.Material.SPRUCE_SAPLING;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
material = material;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user