UltimateTimber/src/main/java/com/songoda/ultimatetimber/UltimateTimber.java

201 lines
5.9 KiB
Java
Raw Normal View History

2018-11-04 00:33:37 +01:00
package com.songoda.ultimatetimber;
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;
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;
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;
2019-03-28 05:22:13 +01:00
import java.util.HashSet;
import java.util.List;
2019-03-28 05:22:13 +01:00
import java.util.Set;
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;
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;
private PlacedBlockManager placedBlockManager;
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-12-19 18:58:05 +01:00
public static UltimateTimber getInstance() {
return INSTANCE;
}
@Override
public void onPluginLoad() {
2018-11-05 23:41:25 +01:00
INSTANCE = this;
}
2018-12-18 15:12:26 +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")
.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<>();
this.choppingManager = this.registerManager(ChoppingManager.class);
2019-03-28 18:38:37 +01:00
this.configurationManager = new ConfigurationManager(this);
this.placedBlockManager = this.registerManager(PlacedBlockManager.class);
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();
}
@Override
public void onPluginDisable() {
2019-03-28 05:22:13 +01:00
this.disable();
}
2020-08-29 00:54:47 +02:00
@Override
public void onDataLoad() {
}
@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);
}
@Override
public List<Config> getExtraConfig() {
return null;
}
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
/**
* Gets the chopping manager
2019-03-28 01:56:39 +01:00
*
* @return The ChoppingManager instance
2019-03-28 01:56:39 +01:00
*/
public ChoppingManager getChoppingManager() {
return this.choppingManager;
}
2019-03-28 01:56:39 +01:00
/**
* Gets the configuration manager
2019-03-28 01:56:39 +01:00
*
* @return The ConfigurationManager instance
2019-03-28 01:56:39 +01:00
*/
public ConfigurationManager getConfigurationManager() {
return this.configurationManager;
2019-03-28 01:56:39 +01:00
}
/**
* Gets the placed block manager
*
* @return The PlacedBlockManager instance
*/
public PlacedBlockManager getPlacedBlockManager() {
return this.placedBlockManager;
}
/**
* 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() {
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() {
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() {
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() {
return this.treeFallManager;
2019-03-25 20:40:56 +01:00
}
}