added Plot API class

This commit is contained in:
boy0001 2015-03-13 14:15:00 +11:00
parent 890be085ae
commit 86f3b993a6
5 changed files with 688 additions and 1 deletions

1
.gitignore vendored
View File

@ -63,6 +63,7 @@ tmp/
local.properties
.settings/
.loadpath
\doc
# External tool builders
.externalToolBuilders/

View File

@ -325,7 +325,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} else {
AbstractTitle.TITLE_CLASS = new DefaultTitle();
}
if (Settings.OFFLINE_MODE || Bukkit.getOnlineMode() == false) {
if (Settings.OFFLINE_MODE) {
UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
Settings.OFFLINE_MODE = true;
} else if (checkVersion) {

View File

@ -0,0 +1,674 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// 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, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.api;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.SubCommand;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.PlotSquaredException;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
/**
* PlotSquared API
*
* @author Citymonstret
* @author Empire92
* @version API 2.0
*/
@SuppressWarnings("unused") public class PlotAPI {
/**
* Permission that allows for admin access, this permission node will allow the player to use any part of the
* plugin, without limitations.
*/
public static final String ADMIN_PERMISSION = "plots.admin";
/**
* Constructor. Insert any Plugin. (Optimally the plugin that is accessing the method)
*
* @param plugin Plugin used to access this method
*
* @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotSquared
* instance
* @see com.intellectualcrafters.plot.PlotSquared
*/
@Deprecated
public PlotAPI(final JavaPlugin plugin) {
}
/**
* Get all plots
*
* @return all plots
*
* @see com.intellectualcrafters.plot.PlotSquared#getPlots()
*/
public Set<Plot> getAllPlots() {
return PlotSquared.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(final Player player) {
return PlotSquared.getPlots(BukkitUtil.getPlayer(player));
}
/**
* Add a plot world
*
* @param world World Name
* @param plotWorld Plot World Object
* @param manager World Manager
*
* @see com.intellectualcrafters.plot.PlotSquared#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld,
* com.intellectualcrafters.plot.object.PlotManager)
*/
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) {
PlotSquared.addPlotWorld(world, plotWorld, manager);
}
/**
* @return main configuration
*
* @see com.intellectualcrafters.plot.PlotSquared#config
*/
public YamlConfiguration getConfig() {
return PlotSquared.config;
}
/**
* @return storage configuration
*
* @see com.intellectualcrafters.plot.PlotSquared#storage
*/
public YamlConfiguration getStorage() {
return PlotSquared.storage;
}
/**
* Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br>
* Only use this if you really need it
*
* @return PlotSquared PlotSquared Main Class
*
* @see com.intellectualcrafters.plot.PlotSquared
*/
public PlotSquared getMain() {
return PlotSquared.THIS;
}
/**
* ChunkManager class contains several useful methods<br>
* - Chunk deletion<br>
* - Moving or copying regions<br>
* - plot swapping<br>
* - Entity tracking<br>
* - region regeneration<br>
*
* @return ChunkManager
*
* @see com.intellectualcrafters.plot.util.ChunkManager
*/
public ChunkManager getChunkManager() {
return ChunkManager.manager;
}
/**
* BlockManager class contains useful methods relating to blocks.
*
* @return BlockManager
*
* @see com.intellectualcrafters.plot.util.BlockManager
*/
public BlockManager getBlockManager() {
return BlockManager.manager;
}
/**
* BukkitSetBlockManager class contains useful methods relating to bukkit blocks.
*
* @return BukkitSetBlockManager
*
* @see com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager
*/
public BukkitSetBlockManager getBukkitBlockManager() {
return BukkitSetBlockManager.setBlockManager;
}
/**
* UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead)
*
* @return UUIDWrapper
*
* @see com.intellectualcrafters.plot.uuid.UUIDWrapper
*/
public UUIDWrapper getUUIDWrapper() {
return UUIDHandler.uuidWrapper;
}
/**
* Do not use this. Instead use FlagManager.<method> in your code.
* - Flag related stuff
*
* @return FlagManager
*
* @see com.intellectualcrafters.plot.flag.FlagManager
*/
@Deprecated
public FlagManager getFlagManager() {
return new FlagManager();
}
/**
* Do not use this. Instead use ClusterManager.<method> in your code.
* - Plot cluster related stuff
*
* @return ClusterManager
*
* @see com.intellectualcrafters.plot.util.ClusterManager
*/
@Deprecated
public ClusterManager getClusterManager() {
return new ClusterManager();
}
/**
* Do not use this. Instead use MainUtil.<method> in your code.
* - Basic plot management stuff
*
* @return MainUtil
*
* @see com.intellectualcrafters.plot.util.MainUtil
*/
@Deprecated
public MainUtil getMainUtil() {
return new MainUtil();
}
/**
* Do not use this. Instead use Permissions.<method> in your code.
* - Basic permission management stuff
*
* @return MainUtil
*
* @see com.intellectualcrafters.plot.util.Permissions
*/
@Deprecated
public Permissions getPermissions() {
return new Permissions();
}
/**
* SchematicHandler class contains methods related to pasting, reading and writing schematics
*
* @return SchematicHandler
*
* @see com.intellectualcrafters.plot.util.SchematicHandler
*/
public SchematicHandler getSchematicHandler() {
return SchematicHandler.manager;
}
/**
* Use C.<caption> instead
*
* @return C
*
* @see com.intellectualcrafters.plot.config.C
*/
@Deprecated
public C[] getCaptions() {
return C.values();
}
/**
* Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil
*
* @param world Which manager to get
*
* @return PlotManager
*
* @see com.intellectualcrafters.plot.object.PlotManager
* @see PlotSquared#getPlotManager(org.bukkit.World)
*/
public PlotManager getPlotManager(final World world) {
return PlotSquared.getPlotManager(world.getName());
}
/**
* Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
* tessellation
*
* @param world Plot World
*
* @return PlotManager
*
* @see PlotSquared#getPlotManager(String)
* @see com.intellectualcrafters.plot.object.PlotManager
*/
public PlotManager getPlotManager(final String world) {
return PlotSquared.getPlotManager(world);
}
/**
* Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld
*
* @param world (to get settings of)
*
* @return PlotWorld class for that world ! will return null if not a plot world world
*
* @see PlotSquared#getWorldSettings(org.bukkit.World)
* @see com.intellectualcrafters.plot.object.PlotWorld
*/
public PlotWorld getWorldSettings(final World world) {
return PlotSquared.getPlotWorld(world.getName());
}
/**
* Get the settings for a world (settings bundled in PlotWorld class)
*
* @param world (to get settings of)
*
* @return PlotWorld class for that world ! will return null if not a plot world world
*
* @see PlotSquared#getWorldSettings(String)
* @see com.intellectualcrafters.plot.object.PlotWorld
*/
public PlotWorld getWorldSettings(final String world) {
return PlotSquared.getPlotWorld(world);
}
/**
* Send a message to a player.
*
* @param player Player that will receive the message
* @param c (Caption)
*
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
* com.intellectualcrafters.plot.config.C, String...)
*/
public void sendMessage(final Player player, final C c) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
}
/**
* Send a message to a player. - Supports color codes
*
* @param player Player that will receive the message
* @param string The message
*
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, String)
*/
public void sendMessage(final Player player, final String string) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
}
/**
* Send a message to the console. - Supports color codes
*
* @param msg Message that should be sent to the console
*
* @see PlotSquared#sendConsoleSenderMessage(String)
*/
public void sendConsoleMessage(final String msg) {
MainUtil.sendConsoleMessage(msg);
}
/**
* Send a message to the console
*
* @param c (Caption)
*
* @see #sendConsoleMessage(String)
* @see com.intellectualcrafters.plot.config.C
*/
public void sendConsoleMessage(final C c) {
sendConsoleMessage(c.s());
}
/**
* Register a flag for use in plots
*
* @param flag Flag that should be registered
*
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
* @see com.intellectualcrafters.plot.flag.AbstractFlag
*/
public void addFlag(final AbstractFlag flag) {
FlagManager.addFlag(flag);
}
/**
* get all the currently registered flags
*
* @return array of Flag[]
*
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
* @see com.intellectualcrafters.plot.flag.AbstractFlag
*/
public AbstractFlag[] getFlags() {
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
}
/**
* Get a plot based on the ID
*
* @param world World in which the plot is located
* @param x Plot Location X Co-ord
* @param z Plot Location Z Co-ord
*
* @return plot, null if ID is wrong
*
* @see MainUtil#getPlot(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot getPlot(final World world, final int x, final int z) {
return MainUtil.getPlot(world.getName(), new PlotId(x, z));
}
/**
* Get a plot based on the location
*
* @param l The location that you want to to retrieve the plot from
*
* @return plot if found, otherwise it creates a temporary plot-
*
* @see MainUtil#getCurrentPlot(org.bukkit.Location)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot getPlot(final Location l) {
return MainUtil.getPlot(BukkitUtil.getLocation(l));
}
/**
* Get a plot based on the player location
*
* @param player Get the current plot for the player location
*
* @return plot if found, otherwise it creates a temporary plot
*
* @see #getPlot(org.bukkit.Location)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot getPlot(final Player player) {
return this.getPlot(player.getLocation());
}
/**
* Check whether or not a player has a plot
*
* @param player Player that you want to check for
*
* @return true if player has a plot, false if not.
*
* @see #getPlots(org.bukkit.World, org.bukkit.entity.Player, boolean)
*/
public boolean hasPlot(final World world, final Player player) {
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
}
/**
* Get all plots for the player
*
* @param plr to search for
* @param just_owner should we just search for owner? Or with rights?
*
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
final ArrayList<Plot> pPlots = new ArrayList<>();
for (final Plot plot : PlotSquared.getPlots(world.getName()).values()) {
if (just_owner) {
if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) {
pPlots.add(plot);
}
} else {
if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) {
pPlots.add(plot);
}
}
}
return pPlots.toArray(new Plot[pPlots.size()]);
}
/**
* Get all plots for the world
*
* @param world to get plots of
*
* @return Plot[] - array of plot objects in world
*
* @see PlotSquared#getWorldPlots(org.bukkit.World)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot[] getPlots(final World world) {
Collection<Plot> plots = PlotSquared.getPlots(world.getName()).values();
return plots.toArray(new Plot[plots.size()]);
}
/**
* Get all plot worlds
*
* @return World[] - array of plot worlds
*
* @see com.intellectualcrafters.plot.PlotSquared#getPlotWorlds()
*/
public String[] getPlotWorlds() {
Set<String> worlds = PlotSquared.getPlotWorlds();
return worlds.toArray(new String[worlds.size()]);
}
/**
* Get if plot world
*
* @param world (to check if plot world)
*
* @return boolean (if plot world or not)
*
* @see com.intellectualcrafters.plot.PlotSquared#isPlotWorld(org.bukkit.World)
*/
public boolean isPlotWorld(final World world) {
return PlotSquared.isPlotWorld(world.getName());
}
/**
* Get plot locations
*
* @param p Plot that you want to get the locations for
*
* @return [0] = bottomLc, [1] = topLoc, [2] = home
*
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotBottomLoc(org.bukkit.World,
* com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotTopLoc(org.bukkit.World,
* com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotHome(org.bukkit.World,
* com.intellectualcrafters.plot.object.Plot)
* @see com.intellectualcrafters.plot.object.PlotHomePosition
* @see com.intellectualcrafters.plot.object.Plot
*/
public Location[] getLocations(final Plot p) {
return new Location[]{BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)), BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)), BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id))};
}
/**
* Get home location
*
* @param p Plot that you want to get the location for
*
* @return plot bottom location
*
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotHome(org.bukkit.World,
* com.intellectualcrafters.plot.object.Plot)
* @see com.intellectualcrafters.plot.object.PlotHomePosition
* @see com.intellectualcrafters.plot.object.Plot
*/
public Location getHomeLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id));
}
/**
* Get Bottom Location (min, min, min)
*
* @param p Plot that you want to get the location for
*
* @return plot bottom location
*
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotBottomLoc(org.bukkit.World,
* com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Location getBottomLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id));
}
/**
* Get Top Location (max, max, max)
*
* @param p Plot that you want to get the location for
*
* @return plot top location
*
* @see MainUtil#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Location getTopLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id));
}
/**
* 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-
*
* @see com.intellectualcrafters.plot.util.PlayerFunctions#isInPlot(org.bukkit.entity.Player)
*/
public boolean isInPlot(final Player player) {
return MainUtil.getPlot(BukkitUtil.getLocation(player)) != null;
}
/**
* Register a subcommand
*
* @param c SubCommand, that we want to register
*
* @see com.intellectualcrafters.plot.commands.MainCommand#subCommands
* @see com.intellectualcrafters.plot.commands.SubCommand
*/
public void registerCommand(final SubCommand c) {
MainCommand.subCommands.add(c);
}
/**
* Get the PlotSquared class
*
* @return PlotSquared Class
*
* @see com.intellectualcrafters.plot.PlotSquared
*/
public PlotSquared getPlotSquared() {
return PlotSquared.THIS;
}
/**
* Get 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
*
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World,
* org.bukkit.entity.Player)
*/
public int getPlayerPlotCount(final World world, final Player player) {
return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player));
}
/**
* Get 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 com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlots(org.bukkit.World,
* org.bukkit.entity.Player)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Set<Plot> getPlayerPlots(final World world, final Player player) {
return PlotSquared.getPlots(world.getName(), BukkitUtil.getPlayer(player));
}
/**
* Get the numbers of plots, which the player is able to build in
*
* @param player Player, for whom we're getting the plots (trusted, helper and owner)
*
* @return the number of allowed plots
*
* @see com.intellectualcrafters.plot.util.PlayerFunctions#getAllowedPlots(org.bukkit.entity.Player)
*/
public int getAllowedPlots(final Player player) {
PlotPlayer pp = BukkitUtil.getPlayer(player);
return MainUtil.getAllowedPlots(pp, MainUtil.getPlayerPlotCount(player.getWorld().getName(), pp));
}
}

View File

@ -879,6 +879,14 @@ public class MainUtil {
}
return new String(b);
}
public static void sendConsoleMessage(String msg) {
sendMessage(null, msg);
}
public static void sendConsoleMessage(C caption, String... args) {
sendMessage(null, caption, args);
}
public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) {
msg = colorise('&', msg);

View File

@ -65,6 +65,10 @@ public class BukkitUtil extends BlockManager {
public static Location getLocation(final org.bukkit.Location loc) {
return new Location(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
public static org.bukkit.Location getLocation(final Location loc) {
return new org.bukkit.Location(getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ());
}
public static World getWorld(final String string) {
if (string == lastString) {