2018-11-04 00:33:37 +01:00
|
|
|
package com.songoda.ultimatetimber;
|
2018-11-03 21:49:10 +01:00
|
|
|
|
2020-01-27 14:16:29 +01:00
|
|
|
import com.songoda.core.SongodaCore;
|
|
|
|
import com.songoda.core.SongodaPlugin;
|
|
|
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
|
|
|
import com.songoda.core.configuration.Config;
|
2020-08-29 00:54:47 +02:00
|
|
|
import com.songoda.core.hooks.LogManager;
|
2020-11-07 20:38:58 +01:00
|
|
|
import com.songoda.ultimatetimber.commands.CommandGiveAxe;
|
2020-06-29 02:18:23 +02:00
|
|
|
import com.songoda.ultimatetimber.commands.CommandReload;
|
|
|
|
import com.songoda.ultimatetimber.commands.CommandToggle;
|
2020-11-07 20:38:58 +01:00
|
|
|
import com.songoda.ultimatetimber.manager.ChoppingManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.ConfigurationManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.Manager;
|
|
|
|
import com.songoda.ultimatetimber.manager.PlacedBlockManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.SaplingManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.TreeAnimationManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.TreeDefinitionManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.TreeDetectionManager;
|
|
|
|
import com.songoda.ultimatetimber.manager.TreeFallManager;
|
2018-11-03 21:49:10 +01:00
|
|
|
|
2019-03-28 05:22:13 +01:00
|
|
|
import java.util.HashSet;
|
2020-01-27 14:16:29 +01:00
|
|
|
import java.util.List;
|
2019-03-28 05:22:13 +01:00
|
|
|
import java.util.Set;
|
|
|
|
|
2020-01-27 14:16:29 +01:00
|
|
|
public class UltimateTimber extends SongodaPlugin {
|
2019-03-25 20:40:56 +01:00
|
|
|
|
2018-11-05 23:41:25 +01:00
|
|
|
private static UltimateTimber INSTANCE;
|
2019-03-06 05:31:14 +01:00
|
|
|
|
2019-03-28 05:22:13 +01:00
|
|
|
private Set<Manager> managers;
|
|
|
|
|
2019-03-28 07:42:22 +01:00
|
|
|
private ChoppingManager choppingManager;
|
2019-03-28 01:56:39 +01:00
|
|
|
private ConfigurationManager configurationManager;
|
2020-06-29 02:18:23 +02:00
|
|
|
private com.songoda.core.commands.CommandManager commandManager;
|
2019-04-29 02:58:38 +02:00
|
|
|
private PlacedBlockManager placedBlockManager;
|
2019-03-29 23:52:17 +01:00
|
|
|
private SaplingManager saplingManager;
|
2019-03-28 01:56:39 +01:00
|
|
|
private TreeAnimationManager treeAnimationManager;
|
|
|
|
private TreeDefinitionManager treeDefinitionManager;
|
2019-03-28 05:22:13 +01:00
|
|
|
private TreeDetectionManager treeDetectionManager;
|
2019-03-28 01:56:39 +01:00
|
|
|
private TreeFallManager treeFallManager;
|
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
|
2020-01-27 14:16:29 +01:00
|
|
|
public void onPluginLoad() {
|
2018-11-05 23:41:25 +01:00
|
|
|
INSTANCE = this;
|
2020-01-27 14:16:29 +01:00
|
|
|
}
|
2018-12-18 15:12:26 +01:00
|
|
|
|
2020-01-27 14:16:29 +01:00
|
|
|
@Override
|
|
|
|
public void onPluginEnable() {
|
|
|
|
// Run Songoda Updater
|
2020-06-11 18:32:19 +02:00
|
|
|
SongodaCore.registerPlugin(this, 18, CompatibleMaterial.IRON_AXE);
|
2019-05-02 04:17:06 +02:00
|
|
|
|
2020-08-29 00:54:47 +02:00
|
|
|
// Load hooks
|
|
|
|
LogManager.load();
|
|
|
|
|
2020-06-29 02:18:23 +02:00
|
|
|
// Setup plugin commands
|
|
|
|
this.commandManager = new com.songoda.core.commands.CommandManager(this);
|
|
|
|
this.commandManager.addMainCommand("ut")
|
2020-11-07 20:38:58 +01:00
|
|
|
.addSubCommands(
|
|
|
|
new CommandReload(this),
|
|
|
|
new CommandToggle(this),
|
|
|
|
new CommandGiveAxe(this)
|
2020-06-29 02:18:23 +02:00
|
|
|
);
|
|
|
|
|
2019-05-02 04:17:06 +02:00
|
|
|
// Register managers
|
2019-03-28 05:22:13 +01:00
|
|
|
this.managers = new HashSet<>();
|
2019-03-28 07:42:22 +01:00
|
|
|
this.choppingManager = this.registerManager(ChoppingManager.class);
|
2019-03-28 18:38:37 +01:00
|
|
|
this.configurationManager = new ConfigurationManager(this);
|
2019-04-29 02:58:38 +02:00
|
|
|
this.placedBlockManager = this.registerManager(PlacedBlockManager.class);
|
2019-03-29 23:52:17 +01:00
|
|
|
this.saplingManager = this.registerManager(SaplingManager.class);
|
2019-03-28 05:22:13 +01:00
|
|
|
this.treeAnimationManager = this.registerManager(TreeAnimationManager.class);
|
|
|
|
this.treeDefinitionManager = this.registerManager(TreeDefinitionManager.class);
|
|
|
|
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
|
|
|
|
this.treeFallManager = this.registerManager(TreeFallManager.class);
|
2019-03-28 01:56:39 +01:00
|
|
|
|
2020-06-29 02:18:23 +02:00
|
|
|
this.reloadConfig();
|
2018-11-03 21:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-27 14:16:29 +01:00
|
|
|
public void onPluginDisable() {
|
2019-03-28 05:22:13 +01:00
|
|
|
this.disable();
|
2020-01-27 14:16:29 +01:00
|
|
|
}
|
2019-03-29 23:52:17 +01:00
|
|
|
|
2020-08-29 00:54:47 +02:00
|
|
|
@Override
|
|
|
|
public void onDataLoad() {
|
|
|
|
}
|
|
|
|
|
2020-01-27 14:16:29 +01:00
|
|
|
@Override
|
|
|
|
public void onConfigReload() {
|
2020-06-29 02:18:23 +02:00
|
|
|
this.configurationManager.reload();
|
|
|
|
this.managers.forEach(Manager::reload);
|
|
|
|
this.setLocale(getConfig().getString("locale"), true);
|
2020-01-27 14:16:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Config> getExtraConfig() {
|
|
|
|
return null;
|
2019-02-07 04:37:16 +01:00
|
|
|
}
|
2018-11-05 23:41:25 +01:00
|
|
|
|
2019-03-28 05:22:13 +01:00
|
|
|
/**
|
|
|
|
* Disables most of the plugin
|
|
|
|
*/
|
|
|
|
public void disable() {
|
2019-03-28 18:38:37 +01:00
|
|
|
this.configurationManager.disable();
|
2019-03-28 05:22:13 +01:00
|
|
|
this.managers.forEach(Manager::disable);
|
2018-11-05 23:41:25 +01:00
|
|
|
}
|
2018-12-19 18:58:05 +01:00
|
|
|
|
2019-03-28 05:22:13 +01:00
|
|
|
/**
|
|
|
|
* Registers a manager
|
|
|
|
*
|
|
|
|
* @param managerClass The class of the manager to create a new instance of
|
2020-06-29 02:18:23 +02:00
|
|
|
* @param <T> extends Manager
|
2019-03-28 05:22:13 +01:00
|
|
|
* @return A new instance of the given manager class
|
|
|
|
*/
|
|
|
|
private <T extends Manager> T registerManager(Class<T> managerClass) {
|
|
|
|
try {
|
|
|
|
T newManager = managerClass.getConstructor(UltimateTimber.class).newInstance(this);
|
|
|
|
this.managers.add(newManager);
|
|
|
|
return newManager;
|
2019-03-28 18:38:37 +01:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2019-03-28 05:22:13 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 01:56:39 +01:00
|
|
|
/**
|
2019-03-28 07:42:22 +01:00
|
|
|
* Gets the chopping manager
|
2019-03-28 01:56:39 +01:00
|
|
|
*
|
2019-03-28 07:42:22 +01:00
|
|
|
* @return The ChoppingManager instance
|
2019-03-28 01:56:39 +01:00
|
|
|
*/
|
2019-03-28 07:42:22 +01:00
|
|
|
public ChoppingManager getChoppingManager() {
|
|
|
|
return this.choppingManager;
|
|
|
|
}
|
|
|
|
|
2019-03-28 01:56:39 +01:00
|
|
|
/**
|
2019-03-28 07:42:22 +01:00
|
|
|
* Gets the configuration manager
|
2019-03-28 01:56:39 +01:00
|
|
|
*
|
2019-03-28 07:42:22 +01:00
|
|
|
* @return The ConfigurationManager instance
|
2019-03-28 01:56:39 +01:00
|
|
|
*/
|
2019-03-28 07:42:22 +01:00
|
|
|
public ConfigurationManager getConfigurationManager() {
|
2019-03-29 23:52:17 +01:00
|
|
|
return this.configurationManager;
|
2019-03-28 01:56:39 +01:00
|
|
|
}
|
|
|
|
|
2019-04-29 02:58:38 +02:00
|
|
|
/**
|
|
|
|
* Gets the placed block manager
|
|
|
|
*
|
|
|
|
* @return The PlacedBlockManager instance
|
|
|
|
*/
|
|
|
|
public PlacedBlockManager getPlacedBlockManager() {
|
|
|
|
return this.placedBlockManager;
|
|
|
|
}
|
|
|
|
|
2019-03-29 23:52:17 +01:00
|
|
|
/**
|
|
|
|
* Gets the sapling manager
|
|
|
|
*
|
|
|
|
* @return The SaplingManager instance
|
|
|
|
*/
|
|
|
|
public SaplingManager getSaplingManager() {
|
|
|
|
return this.saplingManager;
|
2019-03-28 01:56:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the tree animation manager
|
|
|
|
*
|
|
|
|
* @return The TreeAnimationManager instance
|
|
|
|
*/
|
|
|
|
public TreeAnimationManager getTreeAnimationManager() {
|
2019-03-29 23:52:17 +01:00
|
|
|
return this.treeAnimationManager;
|
2019-02-06 07:38:37 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 01:56:39 +01:00
|
|
|
/**
|
|
|
|
* Gets the tree definition manager
|
|
|
|
*
|
|
|
|
* @return The TreeDefinitionManager instance
|
|
|
|
*/
|
|
|
|
public TreeDefinitionManager getTreeDefinitionManager() {
|
2019-03-29 23:52:17 +01:00
|
|
|
return this.treeDefinitionManager;
|
2019-02-06 07:38:37 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 05:22:13 +01:00
|
|
|
/**
|
|
|
|
* Gets the tree detection manager
|
|
|
|
*
|
|
|
|
* @return The TreeDetectionManager instance
|
|
|
|
*/
|
|
|
|
public TreeDetectionManager getTreeDetectionManager() {
|
2019-03-29 23:52:17 +01:00
|
|
|
return this.treeDetectionManager;
|
2019-03-28 05:22:13 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 01:56:39 +01:00
|
|
|
/**
|
|
|
|
* Gets the tree fall manager
|
|
|
|
*
|
|
|
|
* @return The TreeFallManager instance
|
|
|
|
*/
|
|
|
|
public TreeFallManager getTreeFallManager() {
|
2019-03-29 23:52:17 +01:00
|
|
|
return this.treeFallManager;
|
2019-03-25 20:40:56 +01:00
|
|
|
}
|
|
|
|
|
2018-11-03 21:49:10 +01:00
|
|
|
}
|