mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-12-01 22:33:23 +01:00
Additional boilerplate, actually start implementing some stuff
This commit is contained in:
parent
4192e5ba74
commit
a267bd745c
@ -14,6 +14,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Esophose
|
||||||
|
*/
|
||||||
public class UltimateTimber extends JavaPlugin {
|
public class UltimateTimber extends JavaPlugin {
|
||||||
|
|
||||||
private static final CommandSender console = Bukkit.getConsoleSender();
|
private static final CommandSender console = Bukkit.getConsoleSender();
|
||||||
@ -22,11 +25,11 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
private Set<Manager> managers;
|
private Set<Manager> managers;
|
||||||
|
|
||||||
private VersionAdapter versionAdapter;
|
private VersionAdapter versionAdapter;
|
||||||
|
private ChoppingManager choppingManager;
|
||||||
|
private CommandManager commandManager;
|
||||||
private ConfigurationManager configurationManager;
|
private ConfigurationManager configurationManager;
|
||||||
private DisabledWorldManager disabledWorldManager;
|
|
||||||
private HookManager hookManager;
|
private HookManager hookManager;
|
||||||
private MessageManager messageManager;
|
private MessageManager messageManager;
|
||||||
private SettingsManager settingsManager;
|
|
||||||
private TreeAnimationManager treeAnimationManager;
|
private TreeAnimationManager treeAnimationManager;
|
||||||
private TreeDefinitionManager treeDefinitionManager;
|
private TreeDefinitionManager treeDefinitionManager;
|
||||||
private TreeDetectionManager treeDetectionManager;
|
private TreeDetectionManager treeDetectionManager;
|
||||||
@ -45,18 +48,17 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||||
|
|
||||||
this.managers = new HashSet<>();
|
this.managers = new HashSet<>();
|
||||||
|
this.choppingManager = this.registerManager(ChoppingManager.class);
|
||||||
|
this.commandManager = this.registerManager(CommandManager.class);
|
||||||
this.configurationManager = this.registerManager(ConfigurationManager.class);
|
this.configurationManager = this.registerManager(ConfigurationManager.class);
|
||||||
this.disabledWorldManager = this.registerManager(DisabledWorldManager.class);
|
|
||||||
this.hookManager = this.registerManager(HookManager.class);
|
this.hookManager = this.registerManager(HookManager.class);
|
||||||
this.messageManager = this.registerManager(MessageManager.class);
|
this.messageManager = this.registerManager(MessageManager.class);
|
||||||
this.settingsManager = this.registerManager(SettingsManager.class);
|
|
||||||
this.treeAnimationManager = this.registerManager(TreeAnimationManager.class);
|
this.treeAnimationManager = this.registerManager(TreeAnimationManager.class);
|
||||||
this.treeDefinitionManager = this.registerManager(TreeDefinitionManager.class);
|
this.treeDefinitionManager = this.registerManager(TreeDefinitionManager.class);
|
||||||
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
|
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
|
||||||
this.treeFallManager = this.registerManager(TreeFallManager.class);
|
this.treeFallManager = this.registerManager(TreeFallManager.class);
|
||||||
|
|
||||||
this.setupVersionAdapter();
|
this.setupVersionAdapter();
|
||||||
this.reload();
|
|
||||||
|
|
||||||
new Metrics(this);
|
new Metrics(this);
|
||||||
|
|
||||||
@ -110,6 +112,7 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
T newManager = managerClass.getConstructor(UltimateTimber.class).newInstance(this);
|
T newManager = managerClass.getConstructor(UltimateTimber.class).newInstance(this);
|
||||||
this.managers.add(newManager);
|
this.managers.add(newManager);
|
||||||
|
newManager.reload();
|
||||||
return newManager;
|
return newManager;
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
return null;
|
return null;
|
||||||
@ -125,6 +128,24 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
return this.versionAdapter;
|
return this.versionAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the chopping manager
|
||||||
|
*
|
||||||
|
* @return The ChoppingManager instance
|
||||||
|
*/
|
||||||
|
public ChoppingManager getChoppingManager() {
|
||||||
|
return this.choppingManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the command manager
|
||||||
|
*
|
||||||
|
* @return The CommandManager instance
|
||||||
|
*/
|
||||||
|
public CommandManager getCommandManager() {
|
||||||
|
return this.commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the configuration manager
|
* Gets the configuration manager
|
||||||
*
|
*
|
||||||
@ -134,15 +155,6 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
return configurationManager;
|
return configurationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the disabled world manager
|
|
||||||
*
|
|
||||||
* @return The DisabledWorldManager instance
|
|
||||||
*/
|
|
||||||
public DisabledWorldManager getDisabledWorldManager() {
|
|
||||||
return disabledWorldManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the hook manager
|
* Gets the hook manager
|
||||||
*
|
*
|
||||||
@ -161,15 +173,6 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
return messageManager;
|
return messageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the settings manager
|
|
||||||
*
|
|
||||||
* @return The SettingsManager instance
|
|
||||||
*/
|
|
||||||
public SettingsManager getSettingsManager() {
|
|
||||||
return settingsManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the tree animation manager
|
* Gets the tree animation manager
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,7 @@ import com.songoda.ultimatetimber.tree.TreeBlock;
|
|||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -14,11 +15,20 @@ public interface VersionAdapter {
|
|||||||
VersionAdapterType getVersionAdapterType();
|
VersionAdapterType getVersionAdapterType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a Set of TreeDefinitions from the config
|
* Parses a String into a BlockState
|
||||||
*
|
*
|
||||||
* @return A Set of loaded TreeDefinitions
|
* @param blockStateString The String to parse
|
||||||
|
* @return A BlockState that the given String represents
|
||||||
*/
|
*/
|
||||||
Set<TreeDefinition> loadTreeDefinitions();
|
BlockState parseBlockStateFromString(String blockStateString);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a String into an ItemStack
|
||||||
|
*
|
||||||
|
* @param itemStackString The String to parse
|
||||||
|
* @return An ItemStack that the given String represents
|
||||||
|
*/
|
||||||
|
ItemStack parseItemStackFromString(String itemStackString);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the items that a tree block should drop when it breaks
|
* Get the items that a tree block should drop when it breaks
|
||||||
|
@ -7,6 +7,7 @@ import com.songoda.ultimatetimber.tree.TreeBlock;
|
|||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -19,7 +20,12 @@ public class CurrentAdapter implements VersionAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<TreeDefinition> loadTreeDefinitions() {
|
public BlockState parseBlockStateFromString(String blockStateString) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack parseItemStackFromString(String itemStackString) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import com.songoda.ultimatetimber.tree.TreeBlock;
|
|||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -19,7 +20,12 @@ public class LegacyAdapter implements VersionAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<TreeDefinition> loadTreeDefinitions() {
|
public BlockState parseBlockStateFromString(String blockStateString) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack parseItemStackFromString(String itemStackString) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
package com.songoda.ultimatetimber.commands;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
|
||||||
import com.songoda.ultimatetimber.old_code.CustomLoot;
|
|
||||||
import com.songoda.ultimatetimber.utils.Methods;
|
|
||||||
|
|
||||||
class ReloadCommand {
|
|
||||||
|
|
||||||
static void reloadConfig(CommandSender commandSender) {
|
|
||||||
UltimateTimber plugin = UltimateTimber.getInstance();
|
|
||||||
plugin.reloadConfig();
|
|
||||||
plugin.reloadValidWorlds();
|
|
||||||
CustomLoot.initializeCustomItems();
|
|
||||||
commandSender.sendMessage(Methods.formatText(plugin.getPrefix() + " &7Configuration reloaded"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
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(UltimateTimber.getInstance().getPrefix() + " Chopping Mode: &aEnabled"));
|
|
||||||
} else {
|
|
||||||
player.sendMessage(Methods.formatText(UltimateTimber.getInstance().getPrefix() + " Chopping Mode: &cDisabled"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.songoda.ultimatetimber.manager;
|
||||||
|
|
||||||
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ChoppingManager extends Manager {
|
||||||
|
|
||||||
|
private Set<UUID> disabledPlayers;
|
||||||
|
|
||||||
|
public ChoppingManager(UltimateTimber ultimateTimber) {
|
||||||
|
super(ultimateTimber);
|
||||||
|
this.disabledPlayers = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
this.disabledPlayers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles a player's chopping status
|
||||||
|
*
|
||||||
|
* @param player The player to toggle
|
||||||
|
* @return True if the player has chopping enabled, or false if they have it disabled
|
||||||
|
*/
|
||||||
|
public boolean togglePlayer(Player player) {
|
||||||
|
if (this.disabledPlayers.contains(player.getUniqueId())) {
|
||||||
|
this.disabledPlayers.remove(player.getUniqueId());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.disabledPlayers.add(player.getUniqueId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a player has chopping enabled
|
||||||
|
*
|
||||||
|
* @param player The player to check
|
||||||
|
* @return True if the player has chopping enabled, or false if they have it disabled
|
||||||
|
*/
|
||||||
|
public boolean isChopping(Player player) {
|
||||||
|
return !this.disabledPlayers.contains(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,46 +1,67 @@
|
|||||||
package com.songoda.ultimatetimber.commands;
|
package com.songoda.ultimatetimber.manager;
|
||||||
|
|
||||||
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
|
import com.songoda.ultimatetimber.utils.Methods;
|
||||||
|
import org.bukkit.command.*;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
public class CommandManager extends Manager implements CommandExecutor, TabCompleter {
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
public CommandManager(UltimateTimber ultimateTimber) {
|
||||||
import com.songoda.ultimatetimber.utils.Methods;
|
super(ultimateTimber);
|
||||||
|
|
||||||
public class CommandHandler implements CommandExecutor, TabCompleter {
|
PluginCommand command = ultimateTimber.getCommand("ultimatetimber");
|
||||||
|
command.setExecutor(this);
|
||||||
|
command.setTabCompleter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@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"))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
ReloadCommand.reloadConfig(commandSender);
|
UltimateTimber.getInstance().reload();
|
||||||
|
commandSender.sendMessage(Methods.formatText(UltimateTimber.getInstance().getMessageManager().getPrefix() + " &7Configuration reloaded"));
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("toggle")) {
|
} else if (args[0].equalsIgnoreCase("toggle")) {
|
||||||
if (commandSender instanceof Player) {
|
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!"));
|
commandSender.sendMessage(Methods.formatText("&cConsole cannot toggle chopping mode!"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!permCheck((Player) commandSender, "ultimatetimber.toggle"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (UltimateTimber.getInstance().getChoppingManager().togglePlayer((Player)commandSender)) {
|
||||||
|
commandSender.sendMessage(Methods.formatText(UltimateTimber.getInstance().getMessageManager().getPrefix() + " Chopping Mode: &aEnabled"));
|
||||||
|
} else {
|
||||||
|
commandSender.sendMessage(Methods.formatText(UltimateTimber.getInstance().getMessageManager().getPrefix() + " Chopping Mode: &cDisabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commandSender.sendMessage("");
|
commandSender.sendMessage("");
|
||||||
commandSender.sendMessage(Methods.formatText(UltimateTimber.getInstance().getPrefix() + " &7Version " + UltimateTimber.getInstance().getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
|
commandSender.sendMessage(Methods.formatText(UltimateTimber.getInstance().getMessageManager().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("");
|
@ -1,21 +1,140 @@
|
|||||||
package com.songoda.ultimatetimber.manager;
|
package com.songoda.ultimatetimber.manager;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
|
import com.songoda.ultimatetimber.adapter.VersionAdapterType;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigurationManager extends Manager {
|
public class ConfigurationManager extends Manager {
|
||||||
|
|
||||||
|
public enum Setting {
|
||||||
|
DISABLED_WORLDS,
|
||||||
|
MAX_LOGS_PER_CHOP,
|
||||||
|
LEAVES_REQUIRED_FOR_TREE,
|
||||||
|
REALISTIC_TOOL_DAMAGE,
|
||||||
|
BREAK_ENTIRE_TREE_BASE,
|
||||||
|
DESTROY_INITIATED_BLOCK,
|
||||||
|
ONLY_DETECT_LOGS_UPWARDS,
|
||||||
|
ONLY_TOPPLE_WHILE_SNEAKING,
|
||||||
|
ALLOW_CREATIVE_MODE,
|
||||||
|
REQUIRE_CHOP_PERMISSION,
|
||||||
|
IGNORE_REQUIRED_TOOLS,
|
||||||
|
REPLANT_SAPLINGS,
|
||||||
|
REPLANT_SAPLINGS_COOLDOWN,
|
||||||
|
FALLING_BLOCKS_REPLANT_SAPLINGS,
|
||||||
|
FALLING_BLOCKS_REPLANT_SAPLINGS_CHANCE,
|
||||||
|
FALLING_BLOCKS_DEAL_DAMAGE,
|
||||||
|
FALLING_BLOCK_DAMAGE,
|
||||||
|
ADD_ITEMS_TO_INVENTORY,
|
||||||
|
USE_CUSTOM_SOUNDS,
|
||||||
|
SCATTER_TREE_BLOCKS_ON_GROUND,
|
||||||
|
MIX_ALL_TREE_TYPES;
|
||||||
|
|
||||||
|
private Object value = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the setting as a boolean
|
||||||
|
*
|
||||||
|
* @return The setting as a boolean
|
||||||
|
*/
|
||||||
|
public boolean getBoolean() {
|
||||||
|
this.loadValue();
|
||||||
|
return (boolean)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the setting as an int
|
||||||
|
*
|
||||||
|
* @return The setting as an int
|
||||||
|
*/
|
||||||
|
public int getInt() {
|
||||||
|
this.loadValue();
|
||||||
|
return (int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the setting as a string list
|
||||||
|
*
|
||||||
|
* @return The setting as a string list
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<String> getStringList() {
|
||||||
|
this.loadValue();
|
||||||
|
return (List<String>)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the cached value
|
||||||
|
*/
|
||||||
|
public void reset() {
|
||||||
|
this.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the value from the config and caches it if it isn't set yet
|
||||||
|
*/
|
||||||
|
private void loadValue() {
|
||||||
|
if (this.value == null)
|
||||||
|
value = UltimateTimber.getInstance().getConfigurationManager().getConfig().get(this.getNameAsKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this Setting as a config-compatible key
|
||||||
|
*
|
||||||
|
* @return The key in the config
|
||||||
|
*/
|
||||||
|
private String getNameAsKey() {
|
||||||
|
return this.name().replace("_", "-").toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private YamlConfiguration configuration;
|
||||||
|
|
||||||
public ConfigurationManager(UltimateTimber ultimateTimber) {
|
public ConfigurationManager(UltimateTimber ultimateTimber) {
|
||||||
super(ultimateTimber);
|
super(ultimateTimber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
File configFile = new File(ultimateTimber.getDataFolder() + "/config.yml");
|
||||||
|
|
||||||
|
// If an old config still exists, rename it so it doesn't interfere
|
||||||
|
if (configFile.exists() && ultimateTimber.getConfig().get("server-type") == null) {
|
||||||
|
File renameConfigTo = new File(ultimateTimber.getDataFolder() + "/config-old.yml");
|
||||||
|
configFile.renameTo(renameConfigTo);
|
||||||
|
configFile = new File(ultimateTimber.getDataFolder() + "/config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the new config if it doesn't exist
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
boolean isCurrentConfig = ultimateTimber.getVersionAdapter().getVersionAdapterType() == VersionAdapterType.CURRENT;
|
||||||
|
String newConfigName = "config-" + (isCurrentConfig ? "current" : "legacy") + ".yml";
|
||||||
|
File newConfigFile = new File(ultimateTimber.getDataFolder() + "/" + newConfigName);
|
||||||
|
ultimateTimber.saveResource(newConfigName, false);
|
||||||
|
newConfigFile.renameTo(configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
|
for (Setting setting : Setting.values())
|
||||||
|
setting.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
for (Setting setting : Setting.values())
|
||||||
|
setting.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the config.yml as a YamlConfiguration
|
||||||
|
*
|
||||||
|
* @return The YamlConfiguration of the config.yml
|
||||||
|
*/
|
||||||
|
public YamlConfiguration getConfig() {
|
||||||
|
return this.configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,27 +0,0 @@
|
|||||||
package com.songoda.ultimatetimber.manager;
|
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class DisabledWorldManager extends Manager {
|
|
||||||
|
|
||||||
private Set<String> disabledWorldNames;
|
|
||||||
|
|
||||||
public DisabledWorldManager(UltimateTimber ultimateTimber) {
|
|
||||||
super(ultimateTimber);
|
|
||||||
this.disabledWorldNames = new HashSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.songoda.ultimatetimber.manager;
|
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
|
||||||
|
|
||||||
public class SettingsManager extends Manager {
|
|
||||||
|
|
||||||
public SettingsManager(UltimateTimber ultimateTimber) {
|
|
||||||
super(ultimateTimber);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -20,7 +20,7 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
public void reload() {
|
public void reload() {
|
||||||
this.treeDefinitions.clear();
|
this.treeDefinitions.clear();
|
||||||
|
|
||||||
this.treeDefinitions = this.ultimateTimber.getVersionAdapter().loadTreeDefinitions();
|
ConfigurationManager configurationManager = ultimateTimber.getConfigurationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.songoda.ultimatetimber.old_code;
|
package com.songoda.ultimatetimber.old_code;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.songoda.ultimatetimber.configurations;
|
package com.songoda.ultimatetimber.old_code;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
@ -1,7 +1,6 @@
|
|||||||
package com.songoda.ultimatetimber.old_code;
|
package com.songoda.ultimatetimber.old_code;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|
||||||
import com.songoda.ultimatetimber.utils.LogToLeafConverter;
|
import com.songoda.ultimatetimber.utils.LogToLeafConverter;
|
||||||
|
|
||||||
public class TreeChecker {
|
public class TreeChecker {
|
||||||
|
@ -20,7 +20,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|
||||||
|
|
||||||
public class TreeFallAnimation implements Listener, Runnable {
|
public class TreeFallAnimation implements Listener, Runnable {
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|
||||||
import com.songoda.ultimatetimber.events.TreeFallEvent;
|
import com.songoda.ultimatetimber.events.TreeFallEvent;
|
||||||
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
||||||
import com.songoda.ultimatetimber.manager.HookManager;
|
import com.songoda.ultimatetimber.manager.HookManager;
|
||||||
|
@ -13,7 +13,6 @@ import org.bukkit.entity.FallingBlock;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|
||||||
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
|
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
|
||||||
|
|
||||||
class TreeReplant {
|
class TreeReplant {
|
||||||
|
@ -81,8 +81,10 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public boolean add(Object o) {
|
public boolean add(Object o) {
|
||||||
ITreeBlock<BlockType> treeBlock = (ITreeBlock<BlockType>) o;
|
if (!(o instanceof ITreeBlock)) return false;
|
||||||
|
ITreeBlock treeBlock = (ITreeBlock) o;
|
||||||
switch (treeBlock.getTreeBlockType()) {
|
switch (treeBlock.getTreeBlockType()) {
|
||||||
case LOG:
|
case LOG:
|
||||||
return this.logBlocks.add(treeBlock);
|
return this.logBlocks.add(treeBlock);
|
||||||
@ -94,7 +96,8 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
ITreeBlock<BlockType> treeBlock = (ITreeBlock<BlockType>) o;
|
if (!(o instanceof ITreeBlock)) return false;
|
||||||
|
ITreeBlock treeBlock = (ITreeBlock) o;
|
||||||
switch (treeBlock.getTreeBlockType()) {
|
switch (treeBlock.getTreeBlockType()) {
|
||||||
case LOG:
|
case LOG:
|
||||||
return this.logBlocks.remove(treeBlock);
|
return this.logBlocks.remove(treeBlock);
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.songoda.ultimatetimber.tree.animation;
|
package com.songoda.ultimatetimber.tree.animation;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlock;
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
public class TreeAnimationChaos extends TreeAnimation {
|
public class TreeAnimationChaos extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationChaos(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
|
public TreeAnimationChaos(TreeBlockSet<Block> treeBlocks, TreeDefinition treeDefinition) {
|
||||||
super(TreeAnimationType.CHAOS, treeBlocks, treeDefinition);
|
super(TreeAnimationType.CHAOS, treeBlocks, treeDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.songoda.ultimatetimber.tree.animation;
|
package com.songoda.ultimatetimber.tree.animation;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlock;
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
public class TreeAnimationDisintegrate extends TreeAnimation {
|
public class TreeAnimationDisintegrate extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationDisintegrate(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
|
public TreeAnimationDisintegrate(TreeBlockSet<Block> treeBlocks, TreeDefinition treeDefinition) {
|
||||||
super(TreeAnimationType.DISINTIGRATE, treeBlocks, treeDefinition);
|
super(TreeAnimationType.DISINTIGRATE, treeBlocks, treeDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.songoda.ultimatetimber.tree.animation;
|
package com.songoda.ultimatetimber.tree.animation;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlock;
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
public class TreeAnimationFancy extends TreeAnimation {
|
public class TreeAnimationFancy extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationFancy(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
|
public TreeAnimationFancy(TreeBlockSet<Block> treeBlocks, TreeDefinition treeDefinition) {
|
||||||
super(TreeAnimationType.FANCY, treeBlocks, treeDefinition);
|
super(TreeAnimationType.FANCY, treeBlocks, treeDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.songoda.ultimatetimber.tree.animation;
|
package com.songoda.ultimatetimber.tree.animation;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlock;
|
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
public class TreeAnimationNone extends TreeAnimation {
|
public class TreeAnimationNone extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationNone(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
|
public TreeAnimationNone(TreeBlockSet<Block> treeBlocks, TreeDefinition treeDefinition) {
|
||||||
super(TreeAnimationType.NONE, treeBlocks, treeDefinition);
|
super(TreeAnimationType.NONE, treeBlocks, treeDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user