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 native server code package prefix.
125     *
126     * @return The package prefix
127     */
128    @NonNull String serverNativePackage();
129
130    /**
131     * Start Metrics.
132     */
133    void startMetrics();
134
135    /**
136     * If a world is already loaded, set the generator (use NMS if required).
137     *
138     * @param world The world to set the generator
139     */
140    void setGenerator(@NonNull String world);
141
142    /**
143     * Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off.
144     *
145     * @param player the player to remove
146     */
147    void unregister(@NonNull PlotPlayer<?> player);
148
149    /**
150     * Gets the generator wrapper for a world (world) and generator (name).
151     *
152     * @param world The world to get the generator from
153     * @param name  The name of the generator
154     * @return The generator being used for the provided world
155     */
156    @Nullable GeneratorWrapper<?> getGenerator(
157            @NonNull String world,
158            @Nullable String name
159    );
160
161    /**
162     * Create a platform generator from a plot generator
163     *
164     * @param world     World name
165     * @param generator Plot generator
166     * @return Platform generator wrapper
167     */
168    @NonNull GeneratorWrapper<?> wrapPlotGenerator(
169            @NonNull String world,
170            @NonNull IndependentPlotGenerator generator
171    );
172
173    /**
174     * Usually HybridGen
175     *
176     * @return Default implementation generator
177     */
178    default @NonNull IndependentPlotGenerator defaultGenerator() {
179        return injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
180    }
181
182    /**
183     * Get the backup manager instance
184     *
185     * @return Backup manager
186     */
187    default @NonNull BackupManager backupManager() {
188        return injector().getInstance(BackupManager.class);
189    }
190
191    /**
192     * Get the platform specific world manager
193     *
194     * @return World manager
195     */
196    default @NonNull PlatformWorldManager<?> worldManager() {
197        return injector().getInstance(PlatformWorldManager.class);
198    }
199
200    /**
201     * Get the player manager implementation for the platform
202     *
203     * @return Player manager
204     */
205    default @NonNull PlayerManager<? extends PlotPlayer<P>, ? extends P> playerManager() {
206        return injector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() {
207        }));
208    }
209
210    /**
211     * Get a platform world wrapper from a world name
212     *
213     * @param worldName World name
214     * @return Platform world wrapper
215     */
216    @Nullable World<?> getPlatformWorld(@NonNull String worldName);
217
218    /**
219     * Get the {@link com.google.inject.Injector} instance used by PlotSquared
220     *
221     * @return Injector instance
222     */
223    @NonNull Injector injector();
224
225    /**
226     * Get the world utility implementation
227     *
228     * @return World utility
229     */
230    default @NonNull WorldUtil worldUtil() {
231        return injector().getInstance(WorldUtil.class);
232    }
233
234    /**
235     * Get the global block queue implementation
236     *
237     * @return Global block queue implementation
238     */
239    default @NonNull GlobalBlockQueue globalBlockQueue() {
240        return injector().getInstance(GlobalBlockQueue.class);
241    }
242
243    /**
244     * Get the {@link HybridUtils} implementation for the platform
245     *
246     * @return Hybrid utils
247     */
248    default @NonNull HybridUtils hybridUtils() {
249        return injector().getInstance(HybridUtils.class);
250    }
251
252    /**
253     * Get the {@link SetupUtils} implementation for the platform
254     *
255     * @return Setup utils
256     */
257    default @NonNull SetupUtils setupUtils() {
258        return injector().getInstance(SetupUtils.class);
259    }
260
261    /**
262     * Get the {@link EconHandler} implementation for the platform
263     *
264     * @return Econ handler
265     */
266    default @NonNull EconHandler econHandler() {
267        return injector().getInstance(EconHandler.class);
268    }
269
270    /**
271     * Get the {@link RegionManager} implementation for the platform
272     *
273     * @return Region manager
274     */
275    default @NonNull RegionManager regionManager() {
276        return injector().getInstance(RegionManager.class);
277    }
278
279    /**
280     * Get the {@link ChunkManager} implementation for the platform
281     *
282     * @return Region manager
283     */
284    default @NonNull ChunkManager chunkManager() {
285        return injector().getInstance(ChunkManager.class);
286    }
287
288    /**
289     * Get the {@link ExpireManager} implementation for the platform
290     *
291     * @return Expire manager
292     * @since 6.10.2
293     */
294    default @NonNull ExpireManager expireManager() {
295        return injector().getInstance(ExpireManager.class);
296    }
297
298    /**
299     * Get the {@link PlotAreaManager} implementation.
300     *
301     * @return the PlotAreaManager
302     * @since 6.1.4
303     */
304    @NonNull PlotAreaManager plotAreaManager();
305
306    /**
307     * Get the platform specific console {@link Audience}
308     *
309     * @return Console audience
310     */
311    @NonNull Audience consoleAudience();
312
313    /**
314     * Get a formatted string containing all plugins on the server together
315     * with plugin metadata. Mainly for use in debug pastes
316     *
317     * @return Formatted string
318     */
319    @NonNull String pluginsFormatted();
320
321    /**
322     * Get the kind of WorldEdit implementation
323     *
324     * @return worldedit implementations
325     * @since 6.3.0
326     */
327    @DoNotUse
328    @NonNull String worldEditImplementations();
329
330    /**
331     * Load the caption maps
332     */
333    void copyCaptionMaps();
334
335    /**
336     * Get the {@link PermissionHandler} implementation for the platform
337     *
338     * @return Permission handler
339     */
340    default @NonNull PermissionHandler permissionHandler() {
341        return injector().getInstance(PermissionHandler.class);
342    }
343
344    /**
345     * Get the {@link ServicePipeline} implementation
346     *
347     * @return Service pipeline
348     */
349    default @NonNull ServicePipeline servicePipeline() {
350        return injector().getInstance(ServicePipeline.class);
351    }
352
353    /**
354     * Get the {@link PlaceholderRegistry} implementation
355     *
356     * @return Placeholder registry
357     */
358    default @NonNull PlaceholderRegistry placeholderRegistry() {
359        return injector().getInstance(PlaceholderRegistry.class);
360    }
361
362    /**
363     * Convert a component to a legacy string
364     *
365     * @param component Component to convert
366     * @return Converted string
367     */
368    @NonNull String toLegacyPlatformString(@NonNull Component component);
369
370    /**
371     * Returns if the FastAsyncWorldEdit-PlotSquared hook is active/enabled
372     *
373     * @return status of FastAsyncWorldEdit-PlotSquared hook
374     */
375    default boolean isFaweHooking() {
376        return false;
377    }
378
379}