1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-09-28 07:07:31 +02:00
addon-welcomewarpsigns/src/bskyblock/addon/warps/Warp.java

128 lines
4.0 KiB
Java
Raw Normal View History

2018-04-16 20:05:26 +02:00
package bskyblock.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.Optional;
2018-05-29 00:42:03 +02:00
import java.util.Set;
import org.bukkit.World;
2018-07-29 06:42:05 +02:00
import bentobox.addon.acidisland.AcidIsland;
2018-04-16 20:05:26 +02:00
import bskyblock.addon.warps.commands.WarpCommand;
import bskyblock.addon.warps.commands.WarpsCommand;
import bskyblock.addon.warps.config.PluginConfig;
2018-07-29 06:42:05 +02:00
import world.bentobox.bbox.BentoBox;
import world.bentobox.bbox.api.addons.Addon;
import world.bentobox.bbox.api.commands.CompositeCommand;
import world.bentobox.bbox.util.Util;
2017-10-26 03:33:23 +02:00
/**
* Addin to BSkyBlock that enables welcome warp signs
* @author tastybento
*
*/
public class Warp extends Addon {
2017-10-26 03:33:23 +02:00
private static final String BSKYBLOCK_LEVEL = "BSkyBlock-Level";
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
private WarpPanelManager warpPanelManager;
2017-10-26 03:33:23 +02:00
// Warps signs object
private WarpSignsManager warpSignsManager;
2017-10-26 03:33:23 +02:00
// Level addon
private Optional<Addon> levelAddon;
2018-05-29 00:42:03 +02:00
private Set<World> registeredWorlds;
2017-10-26 03:33:23 +02:00
@Override
public void onEnable() {
// Load the plugin's config
new PluginConfig(this);
// 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;
}
2017-10-27 00:58:58 +02:00
// We have to wait for the worlds to load, so we do the rest 1 tick later
2018-07-30 02:22:53 +02:00
getServer().getScheduler().runTask(this.getPlugin(), () -> {
2018-05-29 00:42:03 +02:00
registeredWorlds = new HashSet<>();
2017-10-27 00:58:58 +02:00
// Start warp signs
2018-05-29 00:42:03 +02:00
warpSignsManager = new WarpSignsManager(this, plugin);
warpPanelManager = new WarpPanelManager(this);
// Load the listener
2018-05-29 00:42:03 +02:00
getServer().getPluginManager().registerEvents(new WarpSignsListener(this, plugin), plugin);
2017-10-27 00:58:58 +02:00
// Register commands
2018-07-30 02:22:53 +02:00
getServer().getScheduler().runTask(getPlugin(), () -> {
2018-07-29 06:42:05 +02:00
// Register for BSkyBlock
/*
CompositeCommand bsbIslandCmd = BentoBox.getInstance().getCommandsManager().getCommand("island");
new WarpCommand(this, bsbIslandCmd);
new WarpsCommand(this, bsbIslandCmd);
registeredWorlds.add(plugin.getIWM().getBSBIslandWorld());
*/
// AcidIsland hook in
2018-07-30 02:22:53 +02:00
this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(acidIsland -> {
CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand("ai");
2018-07-29 06:42:05 +02:00
if (acidIslandCmd != null) {
new WarpCommand(this, acidIslandCmd);
new WarpsCommand(this, acidIslandCmd);
registeredWorlds.add(((AcidIsland)acidIsland).getAiw().getOverWorld());
}
2018-05-29 00:42:03 +02:00
});
});
2018-07-29 06:42:05 +02:00
// Get the level addon if it exists
2018-07-30 02:22:53 +02:00
setLevelAddon(getPlugin().getAddonsManager().getAddonByName(BSKYBLOCK_LEVEL));
2017-10-27 00:58:58 +02:00
});
2017-10-26 03:33:23 +02:00
// Done
}
@Override
public void onDisable(){
// Save the warps
if (warpSignsManager != null)
warpSignsManager.saveWarpList();
2017-10-26 03:33:23 +02:00
}
/**
* Get warp panel manager
* @return
2017-10-26 03:33:23 +02:00
*/
public WarpPanelManager getWarpPanelManager() {
return warpPanelManager;
2017-10-26 03:33:23 +02:00
}
public WarpSignsManager getWarpSignsManager() {
return warpSignsManager;
2017-10-26 03:33:23 +02:00
}
public Optional<Addon> getLevelAddon() {
return levelAddon;
}
public void setLevelAddon(Optional<Addon> levelAddon) {
this.levelAddon = levelAddon;
}
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));
}
2017-10-26 03:33:23 +02:00
}