mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Move PlotAPI to Core and move bukkit specific methods to BukkitUtil.
This commit is contained in:
@ -1,15 +1,10 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -27,9 +22,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class BukkitUtil extends WorldUtil {
|
||||
@ -54,6 +47,141 @@ public class BukkitUtil extends WorldUtil {
|
||||
return new BukkitPlayer(player, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the location.
|
||||
*
|
||||
* @param location the location to check
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
* @see Plot
|
||||
*/
|
||||
public static Plot getPlot(org.bukkit.Location location) {
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
return getLocation(location).getPlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the player location.
|
||||
*
|
||||
* @param player the player to check
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
* @see #getPlot(org.bukkit.Location)
|
||||
* @see Plot
|
||||
*/
|
||||
public static Plot getPlot(Player player) {
|
||||
return getPlot(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get home location.
|
||||
*
|
||||
* @param plot Plot that you want to get the location for
|
||||
* @return plot bottom location
|
||||
* @see Plot
|
||||
*/
|
||||
public static org.bukkit.Location getHomeLocation(Plot plot) {
|
||||
return BukkitUtil.getLocation(plot.getHome());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for an offline player.
|
||||
* <p>
|
||||
* <p>Note that this will work if the player is offline, however not all
|
||||
* functionality will work.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public static PlotPlayer wrapPlayer(OfflinePlayer player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
||||
* will provide useful functions relating to players.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public static PlotPlayer wrapPlayer(Player player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of plots, which the player is able to build in.
|
||||
*
|
||||
* @param player player, for whom we're getting the plots
|
||||
* @return the number of allowed plots
|
||||
*/
|
||||
public static int getAllowedPlots(Player player) {
|
||||
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
||||
return plotPlayer.getAllowedPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player is in a plot.
|
||||
*
|
||||
* @param player who we're checking for
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*/
|
||||
public static boolean isInPlot(Player player) {
|
||||
return getPlot(player) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collection containing the players plots.
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plots
|
||||
* @return a set containing the players plots
|
||||
* @see Plot
|
||||
*/
|
||||
public static Set<Plot> getPlayerPlots(String world, Player player) {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return PlotPlayer.wrap(player).getPlots(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player. The message supports color codes.
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param string the message
|
||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||
*/
|
||||
public static void sendMessage(Player player, String string) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player plot count.
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plot count
|
||||
* @return the number of plots the player has
|
||||
*/
|
||||
public static int getPlayerPlotCount(String world, Player player) {
|
||||
if (world == null) {
|
||||
return 0;
|
||||
}
|
||||
return BukkitUtil.getPlayer(player).getPlotCount(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param caption the message
|
||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
*/
|
||||
public static void sendMessage(Player player, C caption) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
||||
}
|
||||
|
||||
public static PlotPlayer getPlayer(@NonNull final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
|
@ -1,365 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.api;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
|
||||
import com.github.intellectualsites.plotsquared.plot.PS;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* PlotSquared API.
|
||||
* <p>
|
||||
* <p>Useful classes:
|
||||
* <ul>
|
||||
* <li>{@link BukkitUtil}</li>
|
||||
* <li>{@link PlotPlayer}</li>
|
||||
* <li>{@link Plot}</li>
|
||||
* <li>{@link com.github.intellectualsites.plotsquared.plot.object.Location}</li>
|
||||
* <li>{@link PlotArea}</li>
|
||||
* <li>{@link PS}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @version 3.3.3
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Get all plots.
|
||||
*
|
||||
* @return all plots
|
||||
* @see PS#getPlots()
|
||||
*/
|
||||
public Set<Plot> getAllPlots() {
|
||||
return PS.get().getPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all plots for a player.
|
||||
*
|
||||
* @param player Player, whose plots to search for
|
||||
* @return all plots that a player owns
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(Player player) {
|
||||
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plot world.
|
||||
*
|
||||
* @param plotArea Plot World Object
|
||||
* @see PS#addPlotArea(PlotArea)
|
||||
*/
|
||||
public void addPlotArea(PlotArea plotArea) {
|
||||
PS.get().addPlotArea(plotArea);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PlotSquared configurations file.
|
||||
*
|
||||
* @return main configuration
|
||||
* @see PS#config
|
||||
*/
|
||||
public YamlConfiguration getConfig() {
|
||||
return PS.get().config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotSquared storage file.
|
||||
*
|
||||
* @return storage configuration
|
||||
* @see PS#storage
|
||||
*/
|
||||
public YamlConfiguration getStorage() {
|
||||
return PS.get().storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main class for this plugin. Only use this if you really need it.
|
||||
*
|
||||
* @return PlotSquared PlotSquared Main Class
|
||||
* @see PS
|
||||
*/
|
||||
public PS getMain() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* ChunkManager class contains several useful methods.
|
||||
* <ul>
|
||||
* <li>Chunk deletion</li>
|
||||
* <li>Moving or copying regions</li>
|
||||
* <li>Plot swapping</li>
|
||||
* <li>Entity Tracking</li>
|
||||
* <li>Region Regeneration</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return ChunkManager
|
||||
* @see ChunkManager
|
||||
*/
|
||||
public ChunkManager getChunkManager() {
|
||||
return ChunkManager.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block/biome set queue
|
||||
*
|
||||
* @return GlobalBlockQueue.IMP
|
||||
*/
|
||||
public GlobalBlockQueue getBlockQueue() {
|
||||
return GlobalBlockQueue.IMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDWrapper class has basic methods for getting UUIDS. It's recommended
|
||||
* to use the UUIDHandler class instead.
|
||||
*
|
||||
* @return UUIDWrapper
|
||||
* @see UUIDWrapper
|
||||
*/
|
||||
public UUIDWrapper getUUIDWrapper() {
|
||||
return UUIDHandler.getUUIDWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* SchematicHandler class contains methods related to pasting, reading
|
||||
* and writing schematics.
|
||||
*
|
||||
* @return SchematicHandler
|
||||
* @see SchematicHandler
|
||||
*/
|
||||
public SchematicHandler getSchematicHandler() {
|
||||
return SchematicHandler.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of PlotAreas in the world.
|
||||
*
|
||||
* @param world The world to check for plot areas
|
||||
* @return A set of PlotAreas
|
||||
*/
|
||||
public Set<PlotArea> getPlotAreas(World world) {
|
||||
if (world == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return PS.get().getPlotAreas(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param caption the message
|
||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
*/
|
||||
public void sendMessage(Player player, C caption) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player. The message supports color codes.
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param string the message
|
||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||
*/
|
||||
public void sendMessage(Player player, String string) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console. The message supports color codes.
|
||||
*
|
||||
* @param message the message
|
||||
* @see MainUtil#sendConsoleMessage(C, String...)
|
||||
*/
|
||||
public void sendConsoleMessage(String message) {
|
||||
PS.log(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console.
|
||||
*
|
||||
* @param caption the message
|
||||
* @see #sendConsoleMessage(String)
|
||||
* @see C
|
||||
*/
|
||||
public void sendConsoleMessage(C caption) {
|
||||
sendConsoleMessage(caption.s());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a flag for use in plots.
|
||||
*
|
||||
* @param flag the flag to register
|
||||
*/
|
||||
public void addFlag(Flag<?> flag) {
|
||||
Flags.registerFlag(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the location.
|
||||
*
|
||||
* @param location the location to check
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
* @see Plot
|
||||
*/
|
||||
public Plot getPlot(Location location) {
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
return BukkitUtil.getLocation(location).getPlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the player location.
|
||||
*
|
||||
* @param player the player to check
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
* @see #getPlot(Location)
|
||||
* @see Plot
|
||||
*/
|
||||
public Plot getPlot(Player player) {
|
||||
return this.getPlot(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get home location.
|
||||
*
|
||||
* @param plot Plot that you want to get the location for
|
||||
* @return plot bottom location
|
||||
* @see Plot
|
||||
*/
|
||||
public Location getHomeLocation(Plot plot) {
|
||||
return BukkitUtil.getLocation(plot.getHome());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player is in a plot.
|
||||
*
|
||||
* @param player who we're checking for
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*/
|
||||
public boolean isInPlot(Player player) {
|
||||
return getPlot(player) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PlotSquared class.
|
||||
*
|
||||
* @return PlotSquared Class
|
||||
* @see PS
|
||||
*/
|
||||
public PS getPlotSquared() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player plot count.
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plot count
|
||||
* @return the number of plots the player has
|
||||
*/
|
||||
public int getPlayerPlotCount(World world, Player player) {
|
||||
if (world == null) {
|
||||
return 0;
|
||||
}
|
||||
return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collection containing the players plots.
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plots
|
||||
* @return a set containing the players plots
|
||||
* @see PS#getPlots(String, PlotPlayer)
|
||||
* @see Plot
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(World world, Player player) {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return PlotPlayer.wrap(player).getPlots(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of plots, which the player is able to build in.
|
||||
*
|
||||
* @param player player, for whom we're getting the plots
|
||||
* @return the number of allowed plots
|
||||
*/
|
||||
public int getAllowedPlots(Player player) {
|
||||
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
||||
return plotPlayer.getAllowedPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
||||
* will provide useful functions relating to players.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(Player player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for a UUID.
|
||||
* <p>
|
||||
* <p><i>Please note that PlotSquared can be configured to provide
|
||||
* different UUIDs than bukkit</i>
|
||||
*
|
||||
* @param uuid the uuid of the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(UUID uuid) {
|
||||
return PlotPlayer.wrap(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for a username.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(String player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for an offline player.
|
||||
* <p>
|
||||
* <p>Note that this will work if the player is offline, however not all
|
||||
* functionality will work.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(OfflinePlayer player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user