2018-08-04 08:32:05 +02:00
|
|
|
package bentobox.addon.warps;
|
2017-10-26 03:33:23 +02:00
|
|
|
|
2018-05-29 00:42:03 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.bukkit.World;
|
2018-01-01 20:49:02 +01:00
|
|
|
|
2018-08-04 08:32:05 +02:00
|
|
|
import bentobox.addon.warps.commands.WarpCommand;
|
|
|
|
import bentobox.addon.warps.commands.WarpsCommand;
|
|
|
|
import bentobox.addon.warps.config.PluginConfig;
|
2018-08-01 18:47:57 +02:00
|
|
|
import world.bentobox.bentobox.BentoBox;
|
|
|
|
import world.bentobox.bentobox.api.addons.Addon;
|
|
|
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|
|
|
import world.bentobox.bentobox.util.Util;
|
2017-10-26 03:33:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Addin to BSkyBlock that enables welcome warp signs
|
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
2017-12-31 06:15:47 +01:00
|
|
|
public class Warp extends Addon {
|
2017-10-26 03:33:23 +02:00
|
|
|
|
2018-08-04 08:32:05 +02:00
|
|
|
private static final String BSKYBLOCK = "BSkyBlock";
|
|
|
|
private static final String ACIDISLAND = "AcidIsland";
|
2018-01-01 20:49:02 +01:00
|
|
|
|
2018-07-29 06:42:05 +02:00
|
|
|
// The plugin instance.
|
|
|
|
private BentoBox plugin;
|
2017-10-26 03:33:23 +02:00
|
|
|
|
|
|
|
// Warp panel object
|
2017-12-31 06:15:47 +01:00
|
|
|
private WarpPanelManager warpPanelManager;
|
2017-10-26 03:33:23 +02:00
|
|
|
|
|
|
|
// Warps signs object
|
2017-12-31 06:15:47 +01:00
|
|
|
private WarpSignsManager warpSignsManager;
|
2017-10-26 03:33:23 +02:00
|
|
|
|
2018-05-29 00:42:03 +02:00
|
|
|
private Set<World> registeredWorlds;
|
|
|
|
|
2018-08-01 04:48:13 +02:00
|
|
|
private PluginConfig settings;
|
|
|
|
|
2017-10-26 03:33:23 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
// Load the plugin's config
|
2018-08-01 04:48:13 +02:00
|
|
|
settings = new PluginConfig(this);
|
2017-10-26 03:33:23 +02:00
|
|
|
// Get the BSkyBlock plugin. This will be available because this plugin depends on it in plugin.yml.
|
2018-07-30 02:22:53 +02:00
|
|
|
plugin = this.getPlugin();
|
2017-10-26 03:33:23 +02:00
|
|
|
// Check if it is enabled - it might be loaded, but not enabled.
|
2018-05-29 00:42:03 +02:00
|
|
|
if (!plugin.isEnabled()) {
|
2017-10-26 03:33:23 +02:00
|
|
|
this.setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
2018-08-18 06:58:56 +02:00
|
|
|
registeredWorlds = new HashSet<>();
|
|
|
|
// Start warp signs
|
|
|
|
warpSignsManager = new WarpSignsManager(this, plugin);
|
|
|
|
warpPanelManager = new WarpPanelManager(this);
|
|
|
|
// Load the listener
|
|
|
|
getServer().getPluginManager().registerEvents(new WarpSignsListener(this), plugin);
|
|
|
|
// Register commands
|
|
|
|
|
|
|
|
// BSkyBlock hook in
|
|
|
|
this.getPlugin().getAddonsManager().getAddonByName(BSKYBLOCK).ifPresent(acidIsland -> {
|
|
|
|
CompositeCommand bsbIslandCmd = BentoBox.getInstance().getCommandsManager().getCommand("island");
|
|
|
|
if (bsbIslandCmd != null) {
|
|
|
|
new WarpCommand(this, bsbIslandCmd);
|
|
|
|
new WarpsCommand(this, bsbIslandCmd);
|
|
|
|
registeredWorlds.add(plugin.getIWM().getWorld(BSKYBLOCK));
|
|
|
|
}
|
2017-10-27 00:58:58 +02:00
|
|
|
});
|
2018-08-18 06:58:56 +02:00
|
|
|
// AcidIsland hook in
|
|
|
|
this.getPlugin().getAddonsManager().getAddonByName(ACIDISLAND).ifPresent(acidIsland -> {
|
|
|
|
CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand("ai");
|
|
|
|
if (acidIslandCmd != null) {
|
|
|
|
new WarpCommand(this, acidIslandCmd);
|
|
|
|
new WarpsCommand(this, acidIslandCmd);
|
|
|
|
registeredWorlds.add(plugin.getIWM().getWorld(ACIDISLAND));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-26 03:33:23 +02:00
|
|
|
// Done
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable(){
|
|
|
|
// Save the warps
|
2017-12-31 06:15:47 +01:00
|
|
|
if (warpSignsManager != null)
|
|
|
|
warpSignsManager.saveWarpList();
|
2017-10-26 03:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-31 06:15:47 +01:00
|
|
|
* Get warp panel manager
|
|
|
|
* @return
|
2017-10-26 03:33:23 +02:00
|
|
|
*/
|
2017-12-31 06:15:47 +01:00
|
|
|
public WarpPanelManager getWarpPanelManager() {
|
|
|
|
return warpPanelManager;
|
2017-10-26 03:33:23 +02:00
|
|
|
}
|
2018-01-01 20:49:02 +01:00
|
|
|
|
2017-12-31 06:15:47 +01:00
|
|
|
public WarpSignsManager getWarpSignsManager() {
|
|
|
|
return warpSignsManager;
|
2017-10-26 03:33:23 +02:00
|
|
|
}
|
|
|
|
|
2018-05-29 00:42:03 +02:00
|
|
|
public String getPermPrefix(World world) {
|
2018-07-30 02:22:53 +02:00
|
|
|
this.getPlugin().getIWM().getPermissionPrefix(world);
|
2018-05-29 00:42:03 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an event is in a registered world
|
|
|
|
* @param world - world to check
|
|
|
|
* @return true if it is
|
|
|
|
*/
|
|
|
|
public boolean inRegisteredWorld(World world) {
|
|
|
|
return registeredWorlds.contains(Util.getWorld(world));
|
|
|
|
}
|
|
|
|
|
2018-08-01 04:48:13 +02:00
|
|
|
/**
|
|
|
|
* @return the settings
|
|
|
|
*/
|
|
|
|
public PluginConfig getSettings() {
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2017-10-26 03:33:23 +02:00
|
|
|
}
|