terrainTypeMap =
map.get(plotArea.getType().name().toLowerCase());
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1);
}
return map;
}));
metrics.addCustomChart(new Metrics.SimplePie("premium",
() -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"));
metrics.addCustomChart(new Metrics.SimplePie("worldedit_implementation",
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ?
"FastAsyncWorldEdit" :
"WorldEdit"));
}
@Override public ChunkManager initChunkManager() {
return new BukkitChunkManager();
}
@Override public RegionManager initRegionManager() {
return new BukkitRegionManager();
}
@Override public void unregister(@NonNull final PlotPlayer player) {
BukkitUtil.removePlayer(player.getUUID());
}
@Override public void registerChunkProcessor() {
getServer().getPluginManager().registerEvents(new ChunkListener(this.plotAreaManager), this);
}
@Override public void registerWorldEvents() {
getServer().getPluginManager().registerEvents(new WorldEvents(this.plotAreaManager), this);
}
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen(this.eventDispatcher, this.plotListener, this.worldConfiguration);
}
@Override public InventoryUtil initInventoryUtil() {
return new BukkitInventoryUtil();
}
@Override public void setGenerator(@NonNull final String worldName) {
World world = BukkitUtil.getWorld(worldName);
if (world == null) {
// create world
ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", getPluginName());
PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager)
.generatorName(worldConfig.getString("generator.init", manager))
.plotAreaType(MainUtil.getType(worldConfig))
.terrainType(MainUtil.getTerrain(worldConfig))
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
.worldName(worldName);
SetupUtils.manager.setupWorld(builder);
world = Bukkit.getWorld(worldName);
} else {
try {
if (!this.plotAreaManager.hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
} catch (Exception e) {
PlotSquared.log("Failed to reload world: " + world + " | " + e.getMessage());
Bukkit.getServer().unloadWorld(world, false);
return;
}
}
assert world != null;
ChunkGenerator gen = world.getGenerator();
if (gen instanceof BukkitPlotGenerator) {
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
} else if (gen != null) {
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager));
} else if (this.worldConfiguration.contains("worlds." + worldName)) {
PlotSquared.get().loadWorld(worldName, null);
}
}
@Override public SchematicHandler initSchematicHandler() {
return new BukkitSchematicHandler();
}
/**
* Attempt to retrieve a {@link PlotPlayer} from a player identifier.
* This method accepts:
* - {@link Player} objects,
* - {@link OfflinePlayer} objects,
* - {@link String} usernames for online players, and
* - {@link UUID} UUIDs for online players
*
* In the case of offline players, a fake {@link Player} instance will be created.
* This is a rather expensive operation, and should be avoided if possible.
*
* @param player The player to convert to a PlotPlayer
* @return The plot player instance that corresponds to the identifier, or null
* if no such player object could be created
*/
@Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
if (player instanceof Player) {
return BukkitUtil.getPlayer((Player) player);
}
if (player instanceof OfflinePlayer) {
return BukkitUtil.getPlayer((OfflinePlayer) player);
}
if (player instanceof String) {
return (PlotPlayer) PlotSquared.platform().getPlayerManager()
.getPlayerIfExists((String) player);
}
if (player instanceof UUID) {
return (PlotPlayer) PlotSquared.platform().getPlayerManager()
.getPlayerIfExists((UUID) player);
}
return null;
}
@Override public String getNMSPackage() {
final String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1);
}
@Override public ChatManager> initChatManager() {
if (Settings.Chat.INTERACTIVE) {
return new BukkitChatManager();
} else {
return new PlainChatManager();
}
}
@Override public GeneratorWrapper> wrapPlotGenerator(@Nullable final String world,
@NonNull final IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
}
@Override public List, Boolean>> getPluginIds() {
List, Boolean>> names = new ArrayList<>();
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
Map.Entry id = new AbstractMap.SimpleEntry<>(plugin.getName(),
plugin.getDescription().getVersion());
names.add(new AbstractMap.SimpleEntry<>(id, plugin.isEnabled()));
}
return names;
}
@Override public Actor getConsole() {
@NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
WorldEditPlugin wePlugin =
((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
return wePlugin.wrapCommandSender(console);
}
@Override @NotNull
public PlayerManager extends PlotPlayer, ? extends Player> getPlayerManager() {
return this.playerManager;
}
@Override @NotNull public com.plotsquared.core.location.World> getPlatformWorld(@NotNull final String worldName) {
return BukkitWorld.of(worldName);
}
}