2018-11-04 00:33:37 +01:00
|
|
|
package com.songoda.ultimatetimber;
|
2018-11-03 21:49:10 +01:00
|
|
|
|
2019-03-06 05:31:14 +01:00
|
|
|
import java.util.*;
|
2019-02-07 04:37:16 +01:00
|
|
|
|
2019-03-25 20:40:56 +01:00
|
|
|
import com.songoda.ultimatetimber.adapter.VersionAdapter;
|
|
|
|
import com.songoda.ultimatetimber.adapter.current.CurrentAdapter;
|
|
|
|
import com.songoda.ultimatetimber.adapter.legacy.LegacyAdapter;
|
2019-03-06 05:06:38 +01:00
|
|
|
import com.songoda.ultimatetimber.utils.Metrics;
|
2019-03-25 20:40:56 +01:00
|
|
|
import com.songoda.ultimatetimber.utils.NMSUtil;
|
2018-11-03 21:49:10 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2018-11-05 05:15:18 +01:00
|
|
|
import org.bukkit.World;
|
2018-11-05 23:41:25 +01:00
|
|
|
import org.bukkit.command.CommandSender;
|
2019-02-07 04:37:16 +01:00
|
|
|
import org.bukkit.command.PluginCommand;
|
2019-02-06 07:38:37 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2018-11-03 21:49:10 +01:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2019-02-07 04:37:16 +01:00
|
|
|
import com.songoda.ultimatetimber.commands.CommandHandler;
|
|
|
|
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
2019-03-26 21:35:17 +01:00
|
|
|
import com.songoda.ultimatetimber.manager.HookManager;
|
2019-02-07 04:37:16 +01:00
|
|
|
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
|
|
|
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
|
|
|
|
import com.songoda.ultimatetimber.treefall.TreeFallListener;
|
|
|
|
import com.songoda.ultimatetimber.utils.Methods;
|
2018-11-05 05:15:18 +01:00
|
|
|
|
2018-11-04 00:33:37 +01:00
|
|
|
public class UltimateTimber extends JavaPlugin {
|
2019-03-25 20:40:56 +01:00
|
|
|
|
|
|
|
private static final String prefix = "&8[&6UltimateTimber&8]";
|
|
|
|
private static final CommandSender console = Bukkit.getConsoleSender();
|
2018-11-05 23:41:25 +01:00
|
|
|
private static UltimateTimber INSTANCE;
|
2019-03-06 05:31:14 +01:00
|
|
|
|
2019-03-25 20:40:56 +01:00
|
|
|
private VersionAdapter adapter;
|
2019-03-06 05:31:14 +01:00
|
|
|
private Set<String> validWorlds = new HashSet<>();
|
2019-02-06 07:38:37 +01:00
|
|
|
private List<UUID> isNotChopping = new ArrayList<>();
|
2018-11-03 21:49:10 +01:00
|
|
|
|
2018-12-19 18:58:05 +01:00
|
|
|
public static UltimateTimber getInstance() {
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
2018-11-03 21:49:10 +01:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2018-11-05 23:41:25 +01:00
|
|
|
INSTANCE = this;
|
2018-12-18 15:12:26 +01:00
|
|
|
|
2018-11-05 23:41:25 +01:00
|
|
|
console.sendMessage(Methods.formatText("&a============================="));
|
2019-02-06 07:38:37 +01:00
|
|
|
console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
|
2018-11-05 23:41:25 +01:00
|
|
|
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
2019-03-25 20:40:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Set up version adapter
|
|
|
|
*/
|
|
|
|
this.setupAdapter();
|
|
|
|
|
2018-11-03 21:49:10 +01:00
|
|
|
/*
|
|
|
|
Register the main event that handles toppling down trees
|
|
|
|
*/
|
2019-01-19 07:35:05 +01:00
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(new TreeFallListener(), this);
|
2018-11-03 21:49:10 +01:00
|
|
|
|
2018-11-06 21:18:16 +01:00
|
|
|
/*
|
|
|
|
Prevent falling blocks from forming new blocks on the floor
|
|
|
|
*/
|
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(new TreeFallAnimation(), this);
|
|
|
|
|
2018-11-03 21:49:10 +01:00
|
|
|
/*
|
2018-11-07 05:41:40 +01:00
|
|
|
Initialize config
|
2018-11-03 21:49:10 +01:00
|
|
|
*/
|
|
|
|
DefaultConfig.initialize();
|
|
|
|
|
2018-11-07 05:41:40 +01:00
|
|
|
/*
|
|
|
|
Initialize custom loot
|
|
|
|
*/
|
|
|
|
CustomLoot.initializeCustomItems();
|
|
|
|
|
2018-11-05 05:15:18 +01:00
|
|
|
/*
|
2019-02-07 04:37:16 +01:00
|
|
|
Cache valid world names for later use
|
2018-11-05 05:15:18 +01:00
|
|
|
*/
|
2019-02-07 04:37:16 +01:00
|
|
|
this.reloadValidWorlds();
|
|
|
|
|
2019-02-11 05:50:07 +01:00
|
|
|
/*
|
2019-02-16 08:16:54 +01:00
|
|
|
Hook into supported plugins
|
2019-02-11 05:50:07 +01:00
|
|
|
*/
|
2019-02-16 08:16:54 +01:00
|
|
|
HookManager.getInstance().hook();
|
2019-02-16 06:32:12 +01:00
|
|
|
|
2019-02-07 04:37:16 +01:00
|
|
|
/*
|
|
|
|
Register command executor and tab completer
|
|
|
|
*/
|
|
|
|
PluginCommand ultimatetimber = this.getCommand("ultimatetimber");
|
|
|
|
CommandHandler commandHandler = new CommandHandler();
|
|
|
|
ultimatetimber.setExecutor(commandHandler);
|
|
|
|
ultimatetimber.setTabCompleter(commandHandler);
|
2019-03-25 20:40:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Set up metrics
|
|
|
|
*/
|
2019-03-06 05:06:38 +01:00
|
|
|
new Metrics(this);
|
|
|
|
|
2018-11-05 23:41:25 +01:00
|
|
|
console.sendMessage(Methods.formatText("&a============================="));
|
2018-11-03 21:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2019-02-07 04:37:16 +01:00
|
|
|
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);
|
2018-11-05 23:41:25 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 04:37:16 +01:00
|
|
|
public boolean isWorldValid(World world) {
|
|
|
|
return this.validWorlds.contains(world.getName());
|
2018-11-03 21:49:10 +01:00
|
|
|
}
|
|
|
|
|
2018-11-05 23:41:25 +01:00
|
|
|
public String getPrefix() {
|
|
|
|
return prefix;
|
|
|
|
}
|
2018-12-19 18:58:05 +01:00
|
|
|
|
2019-03-25 20:40:56 +01:00
|
|
|
private void setupAdapter() {
|
|
|
|
if (NMSUtil.getVersionNumber() > 12) {
|
|
|
|
this.adapter = new CurrentAdapter();
|
|
|
|
} else {
|
|
|
|
this.adapter = new LegacyAdapter();
|
2018-12-18 15:12:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-06 07:38:37 +01:00
|
|
|
public boolean toggleChopping(Player player) {
|
2019-02-07 04:37:16 +01:00
|
|
|
boolean removed = this.isNotChopping.remove(player.getUniqueId());
|
|
|
|
if (!removed)
|
|
|
|
this.isNotChopping.add(player.getUniqueId());
|
|
|
|
return removed;
|
2019-02-06 07:38:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isChopping(Player player) {
|
2019-02-07 04:37:16 +01:00
|
|
|
return !this.isNotChopping.contains(player.getUniqueId());
|
2019-02-06 07:38:37 +01:00
|
|
|
}
|
|
|
|
|
2019-03-25 20:40:56 +01:00
|
|
|
public VersionAdapter getAdapter() {
|
|
|
|
return this.adapter;
|
|
|
|
}
|
|
|
|
|
2018-11-03 21:49:10 +01:00
|
|
|
}
|