001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core; 020 021import cloud.commandframework.services.ServicePipeline; 022import com.google.inject.Injector; 023import com.google.inject.Key; 024import com.google.inject.TypeLiteral; 025import com.intellectualsites.annotations.DoNotUse; 026import com.plotsquared.core.backup.BackupManager; 027import com.plotsquared.core.configuration.caption.LocaleHolder; 028import com.plotsquared.core.generator.GeneratorWrapper; 029import com.plotsquared.core.generator.HybridUtils; 030import com.plotsquared.core.generator.IndependentPlotGenerator; 031import com.plotsquared.core.inject.annotations.DefaultGenerator; 032import com.plotsquared.core.location.World; 033import com.plotsquared.core.permissions.PermissionHandler; 034import com.plotsquared.core.player.PlotPlayer; 035import com.plotsquared.core.plot.expiration.ExpireManager; 036import com.plotsquared.core.plot.world.PlotAreaManager; 037import com.plotsquared.core.queue.GlobalBlockQueue; 038import com.plotsquared.core.util.ChunkManager; 039import com.plotsquared.core.util.EconHandler; 040import com.plotsquared.core.util.PlatformWorldManager; 041import com.plotsquared.core.util.PlayerManager; 042import com.plotsquared.core.util.RegionManager; 043import com.plotsquared.core.util.SetupUtils; 044import com.plotsquared.core.util.WorldUtil; 045import com.plotsquared.core.util.placeholders.PlaceholderRegistry; 046import net.kyori.adventure.audience.Audience; 047import net.kyori.adventure.text.Component; 048import org.checkerframework.checker.nullness.qual.NonNull; 049import org.checkerframework.checker.nullness.qual.Nullable; 050 051import java.io.File; 052 053/** 054 * PlotSquared main utility class 055 * 056 * @param <P> Player type 057 */ 058public interface PlotPlatform<P> extends LocaleHolder { 059 060 /** 061 * Gets the directory which contains PlotSquared files. The directory may not exist. 062 * 063 * @return the PlotSquared directory 064 */ 065 @NonNull File getDirectory(); 066 067 /** 068 * Gets the folder where all world data is stored. 069 * 070 * @return the world folder 071 */ 072 @NonNull File worldContainer(); 073 074 /** 075 * Completely shuts down the plugin. 076 */ 077 void shutdown(); 078 079 /** 080 * Completely shuts down the server. 081 */ 082 void shutdownServer(); 083 084 /** 085 * Get the name of the plugin 086 * 087 * @return Plugin name 088 */ 089 default @NonNull String pluginName() { 090 return "PlotSquared"; 091 } 092 093 /** 094 * Gets the version of Minecraft that is running 095 * 096 * @return server version as array of numbers 097 */ 098 int[] serverVersion(); 099 100 /** 101 * Gets the default minimum world height for the version of Minecraft that the server is running. 102 * 103 * @return minimum world height 104 * @since 6.6.0 105 */ 106 int versionMinHeight(); 107 108 /** 109 * Gets the default maximum world height for the version of Minecraft that the server is running. 110 * 111 * @return maximum world height (inclusive) 112 * @since 6.6.0 113 */ 114 int versionMaxHeight(); 115 116 /** 117 * Gets the server implementation name and version 118 * 119 * @return server implementation and version as string 120 */ 121 @NonNull String serverImplementation(); 122 123 /** 124 * Gets the server brand name 125 * 126 * @return server brand 127 * @since 7.5.3 128 */ 129 @NonNull String serverBrand(); 130 131 /** 132 * Gets the native server code package prefix. 133 * 134 * @return The package prefix 135 */ 136 @NonNull String serverNativePackage(); 137 138 /** 139 * Start Metrics. 140 */ 141 void startMetrics(); 142 143 /** 144 * If a world is already loaded, set the generator (use NMS if required). 145 * 146 * @param world The world to set the generator 147 */ 148 void setGenerator(@NonNull String world); 149 150 /** 151 * Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off. 152 * 153 * @param player the player to remove 154 */ 155 void unregister(@NonNull PlotPlayer<?> player); 156 157 /** 158 * Gets the generator wrapper for a world (world) and generator (name). 159 * 160 * @param world The world to get the generator from 161 * @param name The name of the generator 162 * @return The generator being used for the provided world 163 */ 164 @Nullable GeneratorWrapper<?> getGenerator( 165 @NonNull String world, 166 @Nullable String name 167 ); 168 169 /** 170 * Create a platform generator from a plot generator 171 * 172 * @param world World name 173 * @param generator Plot generator 174 * @return Platform generator wrapper 175 */ 176 @NonNull GeneratorWrapper<?> wrapPlotGenerator( 177 @NonNull String world, 178 @NonNull IndependentPlotGenerator generator 179 ); 180 181 /** 182 * Usually HybridGen 183 * 184 * @return Default implementation generator 185 */ 186 default @NonNull IndependentPlotGenerator defaultGenerator() { 187 return injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)); 188 } 189 190 /** 191 * Get the backup manager instance 192 * 193 * @return Backup manager 194 */ 195 default @NonNull BackupManager backupManager() { 196 return injector().getInstance(BackupManager.class); 197 } 198 199 /** 200 * Get the platform specific world manager 201 * 202 * @return World manager 203 */ 204 default @NonNull PlatformWorldManager<?> worldManager() { 205 return injector().getInstance(PlatformWorldManager.class); 206 } 207 208 /** 209 * Get the player manager implementation for the platform 210 * 211 * @return Player manager 212 */ 213 default @NonNull PlayerManager<? extends PlotPlayer<P>, ? extends P> playerManager() { 214 return injector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() { 215 })); 216 } 217 218 /** 219 * Get a platform world wrapper from a world name 220 * 221 * @param worldName World name 222 * @return Platform world wrapper 223 */ 224 @Nullable World<?> getPlatformWorld(@NonNull String worldName); 225 226 /** 227 * Get the {@link com.google.inject.Injector} instance used by PlotSquared 228 * 229 * @return Injector instance 230 */ 231 @NonNull Injector injector(); 232 233 /** 234 * Get the world utility implementation 235 * 236 * @return World utility 237 */ 238 default @NonNull WorldUtil worldUtil() { 239 return injector().getInstance(WorldUtil.class); 240 } 241 242 /** 243 * Get the global block queue implementation 244 * 245 * @return Global block queue implementation 246 */ 247 default @NonNull GlobalBlockQueue globalBlockQueue() { 248 return injector().getInstance(GlobalBlockQueue.class); 249 } 250 251 /** 252 * Get the {@link HybridUtils} implementation for the platform 253 * 254 * @return Hybrid utils 255 */ 256 default @NonNull HybridUtils hybridUtils() { 257 return injector().getInstance(HybridUtils.class); 258 } 259 260 /** 261 * Get the {@link SetupUtils} implementation for the platform 262 * 263 * @return Setup utils 264 */ 265 default @NonNull SetupUtils setupUtils() { 266 return injector().getInstance(SetupUtils.class); 267 } 268 269 /** 270 * Get the {@link EconHandler} implementation for the platform 271 * 272 * @return Econ handler 273 */ 274 default @NonNull EconHandler econHandler() { 275 return injector().getInstance(EconHandler.class); 276 } 277 278 /** 279 * Get the {@link RegionManager} implementation for the platform 280 * 281 * @return Region manager 282 */ 283 default @NonNull RegionManager regionManager() { 284 return injector().getInstance(RegionManager.class); 285 } 286 287 /** 288 * Get the {@link ChunkManager} implementation for the platform 289 * 290 * @return Region manager 291 */ 292 default @NonNull ChunkManager chunkManager() { 293 return injector().getInstance(ChunkManager.class); 294 } 295 296 /** 297 * Get the {@link ExpireManager} implementation for the platform 298 * 299 * @return Expire manager 300 * @since 6.10.2 301 */ 302 default @NonNull ExpireManager expireManager() { 303 return injector().getInstance(ExpireManager.class); 304 } 305 306 /** 307 * Get the {@link PlotAreaManager} implementation. 308 * 309 * @return the PlotAreaManager 310 * @since 6.1.4 311 */ 312 @NonNull PlotAreaManager plotAreaManager(); 313 314 /** 315 * Get the platform specific console {@link Audience} 316 * 317 * @return Console audience 318 */ 319 @NonNull Audience consoleAudience(); 320 321 /** 322 * Get a formatted string containing all plugins on the server together 323 * with plugin metadata. Mainly for use in debug pastes 324 * 325 * @return Formatted string 326 */ 327 @NonNull String pluginsFormatted(); 328 329 /** 330 * Get the kind of WorldEdit implementation 331 * 332 * @return worldedit implementations 333 * @since 6.3.0 334 */ 335 @DoNotUse 336 @NonNull String worldEditImplementations(); 337 338 /** 339 * Load the caption maps 340 */ 341 void copyCaptionMaps(); 342 343 /** 344 * Get the {@link PermissionHandler} implementation for the platform 345 * 346 * @return Permission handler 347 */ 348 default @NonNull PermissionHandler permissionHandler() { 349 return injector().getInstance(PermissionHandler.class); 350 } 351 352 /** 353 * Get the {@link ServicePipeline} implementation 354 * 355 * @return Service pipeline 356 */ 357 default @NonNull ServicePipeline servicePipeline() { 358 return injector().getInstance(ServicePipeline.class); 359 } 360 361 /** 362 * Get the {@link PlaceholderRegistry} implementation 363 * 364 * @return Placeholder registry 365 */ 366 default @NonNull PlaceholderRegistry placeholderRegistry() { 367 return injector().getInstance(PlaceholderRegistry.class); 368 } 369 370 /** 371 * Convert a component to a legacy string 372 * 373 * @param component Component to convert 374 * @return Converted string 375 */ 376 @NonNull String toLegacyPlatformString(@NonNull Component component); 377 378 /** 379 * Returns if the FastAsyncWorldEdit-PlotSquared hook is active/enabled 380 * 381 * @return status of FastAsyncWorldEdit-PlotSquared hook 382 */ 383 default boolean isFaweHooking() { 384 return false; 385 } 386 387}