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