2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-07-10 18:17:44 +02:00
|
|
|
package com.plotsquared.core;
|
2016-02-23 05:11:28 +01:00
|
|
|
|
2020-07-21 13:05:40 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.Caption;
|
2020-07-22 21:06:23 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.StaticCaption;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
2020-07-22 21:06:23 +02:00
|
|
|
import com.plotsquared.core.player.ConsolePlayer;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
|
|
|
import com.plotsquared.core.queue.GlobalBlockQueue;
|
|
|
|
import com.plotsquared.core.util.ChunkManager;
|
|
|
|
import com.plotsquared.core.util.EventDispatcher;
|
|
|
|
import com.plotsquared.core.util.SchematicHandler;
|
2020-07-08 15:09:25 +02:00
|
|
|
import com.plotsquared.core.util.query.PlotQuery;
|
2020-07-22 21:06:23 +02:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2016-06-24 02:12:17 +02:00
|
|
|
|
2018-08-20 11:35:41 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
2016-03-29 06:56:44 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-03-29 06:56:44 +02:00
|
|
|
* PlotSquared API.
|
2018-11-14 15:44:07 +01:00
|
|
|
*
|
2016-06-01 22:50:35 +02:00
|
|
|
* <p>Useful classes:
|
2016-04-06 05:50:04 +02:00
|
|
|
* <ul>
|
2018-08-10 17:01:10 +02:00
|
|
|
* <li>{@link PlotPlayer}</li>
|
|
|
|
* <li>{@link Plot}</li>
|
2020-04-11 02:19:18 +02:00
|
|
|
* <li>{@link Location}</li>
|
2018-08-10 17:01:10 +02:00
|
|
|
* <li>{@link PlotArea}</li>
|
2018-11-14 14:19:56 +01:00
|
|
|
* <li>{@link PlotSquared}</li>
|
2016-04-06 05:50:04 +02:00
|
|
|
* </ul>
|
2018-08-10 17:01:10 +02:00
|
|
|
*
|
2021-06-21 12:05:56 +02:00
|
|
|
* @version 6
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
|
|
public class PlotAPI {
|
2020-07-17 17:24:45 +02:00
|
|
|
|
|
|
|
public PlotAPI() {
|
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2019-02-06 06:03:52 +01:00
|
|
|
* Gets all plots.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @return all plots
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull Set<@NonNull Plot> getAllPlots() {
|
2020-07-08 15:09:25 +02:00
|
|
|
return PlotQuery.newQuery().allPlots().asSet();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2019-02-22 03:31:12 +01:00
|
|
|
* Gets all plots for a player.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @param player Player, whose plots to search for
|
|
|
|
* @return all plots that a player owns
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull Set<@NonNull Plot> getPlayerPlots(final @NonNull PlotPlayer<?> player) {
|
2020-07-08 15:09:25 +02:00
|
|
|
return PlotQuery.newQuery().ownedBy(player).asSet();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2019-02-22 17:51:06 +01:00
|
|
|
* Adds a plot world.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @param plotArea Plot World Object
|
2018-11-14 14:19:56 +01:00
|
|
|
* @see PlotSquared#addPlotArea(PlotArea)
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void addPlotArea(final @NonNull PlotArea plotArea) {
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.get().addPlotArea(plotArea);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-03-29 20:35:40 +02:00
|
|
|
* ChunkManager class contains several useful methods.
|
|
|
|
* <ul>
|
2018-08-10 17:01:10 +02:00
|
|
|
* <li>Chunk deletion</li>
|
|
|
|
* <li>Moving or copying regions</li>
|
|
|
|
* <li>Plot swapping</li>
|
|
|
|
* <li>Entity Tracking</li>
|
|
|
|
* <li>Region Regeneration</li>
|
2016-03-29 20:35:40 +02:00
|
|
|
* </ul>
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @return ChunkManager
|
2016-04-02 01:14:46 +02:00
|
|
|
* @see ChunkManager
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull ChunkManager getChunkManager() {
|
2020-12-05 18:41:25 +01:00
|
|
|
return PlotSquared.platform().injector().getInstance(ChunkManager.class);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-06 06:03:52 +01:00
|
|
|
* Gets the block/biome set queue
|
2018-08-10 17:01:10 +02:00
|
|
|
*
|
2016-06-13 06:47:50 +02:00
|
|
|
* @return GlobalBlockQueue.IMP
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull GlobalBlockQueue getBlockQueue() {
|
2020-12-05 18:41:25 +01:00
|
|
|
return PlotSquared.platform().globalBlockQueue();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-03-29 20:35:40 +02:00
|
|
|
* SchematicHandler class contains methods related to pasting, reading
|
|
|
|
* and writing schematics.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @return SchematicHandler
|
2016-04-02 01:14:46 +02:00
|
|
|
* @see SchematicHandler
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull SchematicHandler getSchematicHandler() {
|
2020-12-05 18:41:25 +01:00
|
|
|
return PlotSquared.platform().injector().getInstance(SchematicHandler.class);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-03-29 20:35:40 +02:00
|
|
|
/**
|
2019-02-06 06:03:52 +01:00
|
|
|
* Gets a list of PlotAreas in the world.
|
2018-08-10 17:01:10 +02:00
|
|
|
*
|
2016-03-29 20:35:40 +02:00
|
|
|
* @param world The world to check for plot areas
|
|
|
|
* @return A set of PlotAreas
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull Set<@NonNull PlotArea> getPlotAreas(final @Nullable String world) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (world == null) {
|
2016-06-02 17:38:47 +02:00
|
|
|
return Collections.emptySet();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-07-07 13:37:03 +02:00
|
|
|
return PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-05-26 15:19:38 +02:00
|
|
|
* Send a message to the console. The message supports color codes.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
2020-07-22 21:06:23 +02:00
|
|
|
* @param message the message
|
|
|
|
* @param replacements Variable replacements
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void sendConsoleMessage(
|
|
|
|
final @NonNull String message,
|
2021-08-18 11:58:18 +02:00
|
|
|
final @NonNull Template @NonNull ... replacements
|
|
|
|
) {
|
2020-07-22 21:06:23 +02:00
|
|
|
ConsolePlayer.getConsole().sendMessage(StaticCaption.of(message), replacements);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2019-02-22 17:51:06 +01:00
|
|
|
* Sends a message to the console.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
2020-07-22 21:06:23 +02:00
|
|
|
* @param caption the message
|
|
|
|
* @param replacements Variable replacements
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void sendConsoleMessage(
|
|
|
|
final @NonNull Caption caption,
|
2021-08-18 11:58:18 +02:00
|
|
|
final @NonNull Template @NonNull ... replacements
|
2021-01-09 22:28:41 +01:00
|
|
|
) {
|
2020-07-22 21:06:23 +02:00
|
|
|
ConsolePlayer.getConsole().sendMessage(caption, replacements);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-06-24 02:12:17 +02:00
|
|
|
* Gets the PlotSquared class.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @return PlotSquared Class
|
2018-11-14 14:19:56 +01:00
|
|
|
* @see PlotSquared
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull PlotSquared getPlotSquared() {
|
2018-11-14 14:19:56 +01:00
|
|
|
return PlotSquared.get();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2019-02-06 06:03:52 +01:00
|
|
|
* Gets the PlotPlayer for a UUID.
|
2018-11-14 15:44:07 +01:00
|
|
|
*
|
2016-03-29 20:35:40 +02:00
|
|
|
* <p><i>Please note that PlotSquared can be configured to provide
|
2021-01-09 22:28:41 +01:00
|
|
|
* different UUIDs than Bukkit</i>
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
2016-06-01 22:50:35 +02:00
|
|
|
* @param uuid the uuid of the player to wrap
|
2021-08-24 15:34:21 +02:00
|
|
|
* @return a {@link PlotPlayer}
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull UUID uuid) {
|
2020-12-05 18:41:25 +01:00
|
|
|
return PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-20 23:19:37 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2019-02-06 06:03:52 +01:00
|
|
|
* Gets the PlotPlayer for a username.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
2016-06-01 22:50:35 +02:00
|
|
|
* @param player the player to wrap
|
2021-08-24 15:34:21 +02:00
|
|
|
* @return a {@link PlotPlayer}
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull String player) {
|
2020-12-05 18:41:25 +01:00
|
|
|
return PlotSquared.platform().playerManager().getPlayerIfExists(player);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-03-15 12:22:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a listener for PlotSquared Events
|
|
|
|
*
|
|
|
|
* @param listener the listener class to register
|
|
|
|
* @see EventDispatcher#registerListener(Object)
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public void registerListener(final @NonNull Object listener) {
|
2020-03-15 12:22:49 +01:00
|
|
|
PlotSquared.get().getEventDispatcher().registerListener(listener);
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|