1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-09-27 22:57:34 +02:00
addon-welcomewarpsigns/src/main/java/world/bentobox/warps/Warp.java

122 lines
3.5 KiB
Java
Raw Normal View History

package world.bentobox.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 java.util.UUID;
2018-05-29 00:42:03 +02:00
import org.bukkit.World;
2019-01-16 21:46:39 +01:00
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.Level;
import world.bentobox.warps.commands.WarpCommand;
import world.bentobox.warps.commands.WarpsCommand;
import world.bentobox.warps.config.PluginConfig;
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 = "BSkyBlock";
private static final String ACIDISLAND = "AcidIsland";
private static final String LEVEL_ADDON_NAME = "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 objects
private WarpPanelManager warpPanelManager;
2017-10-26 03:33:23 +02:00
// Warps signs objects
private WarpSignsManager warpSignsManager;
2017-10-26 03:33:23 +02:00
2018-05-29 00:42:03 +02:00
private Set<World> registeredWorlds;
private PluginConfig settings;
2017-10-26 03:33:23 +02:00
@Override
public void onEnable() {
// Load the plugin's config
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()) {
2018-10-31 02:12:30 +01:00
this.setState(State.DISABLED);
2017-10-26 03:33:23 +02:00
return;
}
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
2019-01-16 21:46:39 +01:00
getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(a -> a.getDescription().getName().equals(BSKYBLOCK) || a.getDescription().getName().equals(ACIDISLAND))
.forEach(a -> {
a.getPlayerCommand().ifPresent(c -> {
new WarpCommand(this, c);
new WarpsCommand(this, c);
registeredWorlds.add(c.getWorld());
});
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
}
2018-05-29 00:42:03 +02:00
public String getPermPrefix(World world) {
return this.getPlugin().getIWM().getPermissionPrefix(world);
2018-05-29 00:42:03 +02:00
}
/**
* 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));
}
/**
* @return the settings
*/
public PluginConfig getSettings() {
return settings;
}
/**
* Get the island level
* @param world - world
* @param uniqueId - player's UUID
* @return island level or null if there is no level plugin
*/
public Long getLevel(World world, UUID uniqueId) {
return plugin.getAddonsManager().getAddonByName(LEVEL_ADDON_NAME).map(l -> ((Level) l).getIslandLevel(world, uniqueId)).orElse(null);
}
2017-10-26 03:33:23 +02:00
}