PlotSquared/Core/src/main/java/com/plotsquared/core/PlotAPI.java

210 lines
6.2 KiB
Java
Raw Normal View History

/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core;
2016-02-23 05:11:28 +01: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;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
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.
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
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>
* <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
*/
@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
/**
* Gets all plots.
2016-02-23 05:11:28 +01:00
*
* @return all plots
*/
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
/**
* 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
*/
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
/**
* Adds a plot world.
2016-02-23 05:11:28 +01:00
*
* @param plotArea Plot World Object
* @see PlotSquared#addPlotArea(PlotArea)
2016-02-23 05:11:28 +01:00
*/
public void addPlotArea(final @NonNull PlotArea plotArea) {
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
* @see ChunkManager
2016-02-23 05:11:28 +01:00
*/
public @NonNull ChunkManager getChunkManager() {
return PlotSquared.platform().injector().getInstance(ChunkManager.class);
2016-02-23 05:11:28 +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
*/
public @NonNull GlobalBlockQueue getBlockQueue() {
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
* @see SchematicHandler
2016-02-23 05:11:28 +01:00
*/
public @NonNull SchematicHandler getSchematicHandler() {
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
/**
* 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
*/
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
}
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
*/
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
/**
* 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
*/
public void sendConsoleMessage(
final @NonNull Caption caption,
2021-08-18 11:58:18 +02:00
final @NonNull Template @NonNull ... replacements
) {
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
/**
* Gets the PlotSquared class.
2016-02-23 05:11:28 +01:00
*
* @return PlotSquared Class
* @see PlotSquared
2016-02-23 05:11:28 +01:00
*/
public @NonNull PlotSquared getPlotSquared() {
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
/**
* Gets the PlotPlayer for a UUID.
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
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
* 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
*/
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull UUID uuid) {
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
/**
* 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
*/
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull String player) {
return PlotSquared.platform().playerManager().getPlayerIfExists(player);
2016-02-23 05:11:28 +01:00
}
/**
* Registers a listener for PlotSquared Events
*
* @param listener the listener class to register
* @see EventDispatcher#registerListener(Object)
*/
public void registerListener(final @NonNull Object listener) {
PlotSquared.get().getEventDispatcher().registerListener(listener);
}
2016-02-23 05:11:28 +01:00
}