Some documentation updates

This commit is contained in:
Sauilitired 2014-10-28 01:57:14 +01:00
parent be846c2e98
commit 595db4a51f
6 changed files with 198 additions and 85 deletions

View File

@ -52,7 +52,9 @@ import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
/**
* @awesome @author Citymonstret, Empire92 PlotMain class.
* PlotMain class.
* @author Citymonstret
* @author Empire92
*/
public class PlotMain extends JavaPlugin {
@ -66,8 +68,7 @@ public class PlotMain extends JavaPlugin {
* The main configuration file
*/
public static YamlConfiguration config;
private static int config_ver = 1;
/**
/**
* storage.properties
*/
public static File storageFile;
@ -135,10 +136,10 @@ public class PlotMain extends JavaPlugin {
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br>
* Returns highest integer in range.
*
* @param player
* @param stub
* @param range
* @return
* @param player to check
* @param stub to check
* @param range tp check
* @return permitted range
*/
public static int hasPermissionRange(Player player, String stub, int range) {
if (player==null || player.isOp()) {
@ -160,10 +161,11 @@ public class PlotMain extends JavaPlugin {
* - Op has all permissions <br>
* - checks for '*' nodes
*
* @param player
* @param perms
* @return
* @param player to check
* @param perms to check
* @return true of player has permissions
*/
@SuppressWarnings("unused")
public static boolean hasPermissions(Player player, String[] perms) {
// Assumes null player is console.
if (player==null || player.isOp()) {
@ -178,7 +180,7 @@ public class PlotMain extends JavaPlugin {
String[] nodes = perm.split("\\.");
StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i] + ".");
n.append(nodes[i]).append(".");
if (player.hasPermission(n + "*")) {
hasperm = true;
break;
@ -206,9 +208,9 @@ public class PlotMain extends JavaPlugin {
* - Op has all permissions <br>
* - checks for '*' nodes
*
* @param player
* @param perm
* @return
* @param player to check
* @param perm to check
* @return true if player has the permission
*/
public static boolean hasPermission(Player player, String perm) {
if (player==null || player.isOp()) {
@ -220,7 +222,7 @@ public class PlotMain extends JavaPlugin {
String[] nodes = perm.split("\\.");
StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i] + ".");
n.append(nodes[i]).append(".");
if (player.hasPermission(n + "*")) {
return true;
}
@ -237,8 +239,8 @@ public class PlotMain extends JavaPlugin {
/**
* All loaded plot worlds
*/
private static HashMap<String, PlotWorld> worlds = new HashMap<String, PlotWorld>();
private static HashMap<String, PlotManager> managers = new HashMap<String, PlotManager>();
private static HashMap<String, PlotWorld> worlds = new HashMap<>();
private static HashMap<String, PlotManager> managers = new HashMap<>();
/**
* Get all plots
@ -246,20 +248,20 @@ public class PlotMain extends JavaPlugin {
* @return HashMap containing the plot ID and the plot object.
*/
public static Set<Plot> getPlots() {
ArrayList<Plot> myplots = new ArrayList<Plot>();
ArrayList<Plot> myplots = new ArrayList<>();
for (HashMap<PlotId, Plot> world : plots.values()) {
myplots.addAll(world.values());
}
return new HashSet<Plot>(myplots);
return new HashSet<>(myplots);
}
/**
* @param player
* @return
* @param player player
* @return Set Containing the players plots
*/
public static Set<Plot> getPlots(Player player) {
UUID uuid = player.getUniqueId();
ArrayList<Plot> myplots = new ArrayList<Plot>();
ArrayList<Plot> myplots = new ArrayList<>();
for (HashMap<PlotId, Plot> world : plots.values()) {
for (Plot plot : world.values()) {
if (plot.hasOwner()) {
@ -269,13 +271,13 @@ public class PlotMain extends JavaPlugin {
}
}
}
return new HashSet<Plot>(myplots);
return new HashSet<>(myplots);
}
/**
* @param world
* @param player
* @return
* @param world plot world
* @param player plot owner
* @return players plots
*/
public static Set<Plot> getPlots(World world, Player player) {
UUID uuid = player.getUniqueId();
@ -298,8 +300,8 @@ public class PlotMain extends JavaPlugin {
}
/**
* @param world
* @return
* @param world plot world
* @return plots in world
*/
public static HashMap<PlotId, Plot> getPlots(World world) {
if (plots.containsKey(world.getName())) {
@ -316,31 +318,31 @@ public class PlotMain extends JavaPlugin {
}
/**
* @return
* @return plots worlds
*/
public static String[] getPlotWorldsString() {
return plots.keySet().toArray(new String[0]);
}
/**
* @param world
* @return
* @param world plotworld(?)
* @return true if the world is a plotworld
*/
public static boolean isPlotWorld(World world) {
return (worlds.containsKey(world.getName()));
}
/**
* @param world
* @return
* @param world plotworld(?)
* @return true if the world is a plotworld
*/
public static boolean isPlotWorld(String world) {
return (worlds.containsKey(world));
}
/**
* @param world
* @return
* @param world World to get manager for
* @return manager for world
*/
public static PlotManager getPlotManager(World world) {
if (managers.containsKey(world.getName())) {
@ -1074,7 +1076,8 @@ public class PlotMain extends JavaPlugin {
* SETUP: settings.yml
*/
private static void setupConfig() {
config.set("version", config_ver);
int config_ver = 1;
config.set("version", config_ver);
Map<String, Object> options = new HashMap<String, Object>();
options.put("auto_update", false);
options.put("worldguard.enabled", Settings.WORLDGUARD);
@ -1426,7 +1429,8 @@ public class PlotMain extends JavaPlugin {
managers.remove(world);
worlds.remove(world);
}
@SuppressWarnings("unused")
public static HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw() {
return plots;
}

View File

@ -21,10 +21,20 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* Created by Citymonstret on 2014-09-15.
* Schematic Handler
* @author Citymonstret
* @author Empire92
*/
@SuppressWarnings({"all"})
public class SchematicHandler {
/**
* Paste a schematic
* @param location origin
* @param schematic schematic to paste
* @param plot plot to paste in
* @return true if succeeded
*/
public static boolean paste(Location location, Schematic schematic, Plot plot) {
if (schematic == null) {
PlotMain.sendConsoleSenderMessage("Schematic == null :|");
@ -73,6 +83,11 @@ public class SchematicHandler {
return true;
}
/**
* Get a schematic
* @param name to check
* @return schematic if found, else null
*/
public static Schematic getSchematic(String name) {
{
File parent =
@ -89,7 +104,7 @@ public class SchematicHandler {
return null;
}
Schematic schematic = null;
Schematic schematic;
try {
InputStream iStream = new FileInputStream(file);
NBTInputStream stream = new NBTInputStream(new GZIPInputStream(iStream));
@ -141,6 +156,10 @@ public class SchematicHandler {
return schematic;
}
/**
* Schematic Class
* @author Citymonstret
*/
public static class Schematic {
private DataCollection[] blockCollection;
private Dimension schematicDimension;
@ -165,6 +184,10 @@ public class SchematicHandler {
}
}
/**
* Schematic Dimensions
* @author Citymonstret
*/
public static class Dimension {
private int x;
private int y;
@ -191,9 +214,9 @@ public class SchematicHandler {
/**
* Saves a schematic to a file path
* @param tag
* @param path
* @return
* @param tag to save
* @param path to save in
* @return true if succeeded
*/
public static boolean save(CompoundTag tag, String path) {
@ -217,9 +240,9 @@ public class SchematicHandler {
/**
* Gets the schematic of a plot
* @param world
* @param plot
* @return
* @param world to check
* @param id plot
* @return tag
*/
public static CompoundTag getCompoundTag(World world, PlotId id) {
@ -255,7 +278,7 @@ public class SchematicHandler {
int height = 256;
int length = pos2.getBlockZ()-pos1.getBlockZ();
HashMap<String, Tag> schematic = new HashMap<String, Tag>();
HashMap<String, Tag> schematic = new HashMap<>();
schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height));
@ -269,17 +292,13 @@ public class SchematicHandler {
byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null;
byte[] blockData = new byte[width * height * length];
int count = 0;
for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) {
for (int y = 0; y < height; y++) {
int index = y * width * length + z * width + x;
count++;
Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, 0 + y, pos1.getBlockZ() + z));
Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, y, pos1.getBlockZ() + z));
int id2 = block.getTypeId();
@ -294,7 +313,7 @@ public class SchematicHandler {
}
blocks[index] = (byte) id2;
blockData[index] = (byte) block.getData();
blockData[index] = block.getData();
// We need worldedit to save tileentity data or entities
@ -311,10 +330,13 @@ public class SchematicHandler {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
}
CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
return schematicTag;
return new CompoundTag("Schematic", schematic);
}
/**
* Schematic Data Collection
* @author Citymonstret
*/
public static class DataCollection {
private short block;
private byte data;

View File

@ -15,7 +15,13 @@ package com.intellectualcrafters.plot;
* @author Empire92
*/
public class Settings {
/**
* Schematic Save Path
*/
public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics";
/**
* Max allowed plots
*/
public static int MAX_PLOTS = 20;
/**
* WorldGuard region on claimed plots
@ -49,29 +55,27 @@ public class Settings {
* Delete plots on ban?
*/
public static boolean DELETE_PLOTS_ON_BAN = false;
/**
* Update settings
*
* @author Citymonstret
*/
public static String URL = "http://dev.bukkit.org/bukkit-plugins/plotsquared/";
/**
* Verbose?
*/
public static boolean DEBUG = true;
/**
* Auto clear enabled
*/
public static boolean AUTO_CLEAR = false;
/**
* Days until a plot gets cleared
*/
public static int AUTO_CLEAR_DAYS = 365;
/**
* API Location
*/
public static String API_URL = "http://www.intellectualsites.com/minecraft.php";
/**
* Use the custom API
*/
public static boolean CUSTOM_API = true;
public static class Update {
/**
* Update plugin?
*
* @deprecated
*/
@Deprecated
public static boolean AUTO_UPDATE = false;
}
/**
* Database settings
@ -79,19 +83,49 @@ public class Settings {
* @author Citymonstret
*/
public static class DB {
/**
* MongoDB enabled?
*/
public static boolean USE_MONGO = false; /*
* TODO: Implement Mongo
*
* @Brandon
*/;
*/
/**
* SQLite enabled?
*/
public static boolean USE_SQLITE = false;
/**
* MySQL Enabled?
*/
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
/**
* SQLite Database name
*/
public static String SQLITE_DB = "storage";
/**
* MySQL Host name
*/
public static String HOST_NAME = "localhost";
/**
* MySQL Port
*/
public static String PORT = "3306";
/**
* MySQL DB
*/
public static String DATABASE = "plot_db";
/**
* MySQL User
*/
public static String USER = "root";
/**
* MySQL Password
*/
public static String PASSWORD = "password";
/**
* MySQL Prefix
*/
public static String PREFIX = "";
}
}

View File

@ -1,12 +1,24 @@
package com.intellectualcrafters.plot;
/**
* @author Empire92
*/
public class StringWrapper {
public String value;
/**
* Constructor
* @param value to wrap
*/
public StringWrapper(String value) {
this.value = value;
}
/**
* Check if a wrapped string equals another one
* @param obj to compare
* @return true if obj equals the stored value
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
@ -22,11 +34,19 @@ public class StringWrapper {
return other.value.toLowerCase().equals(this.value.toLowerCase());
}
/**
* Get the string value
* @return string value
*/
@Override
public String toString() {
return this.value;
}
/**
* Get the hash value
* @return has value
*/
@Override
public int hashCode() {
return this.value.toLowerCase().hashCode();

View File

@ -34,22 +34,48 @@ import java.util.UUID;
*/
public class UUIDHandler {
/**
* Online mode
* @see org.bukkit.Server#getOnlineMode()
*/
private static boolean online = Bukkit.getServer().getOnlineMode();
/**
* Map containing names and UUID's
*/
private static BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
/**
* Get the map containing all names/uuids
* @return map with names + uuids
*/
public static BiMap<StringWrapper, UUID> getUuidMap() {
return uuidMap;
}
/**
* Check if a uuid is cached
* @param uuid to check
* @return true of the uuid is cached
*/
public static boolean uuidExists(UUID uuid) {
return uuidMap.containsValue(uuid);
}
/**
* Check if a name is cached
* @param name to check
* @return true of the name is cached
*/
public static boolean nameExists(StringWrapper name) {
return uuidMap.containsKey(name);
}
/**
* Add a set to the cache
* @param name to cache
* @param uuid to cache
*/
public static void add(StringWrapper name, UUID uuid) {
if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) {
uuidMap.put(name, uuid);
@ -57,7 +83,7 @@ public class UUIDHandler {
}
/**
* @param name
* @param name to use as key
* @return uuid
*/
public static UUID getUUID(String name) {
@ -65,6 +91,7 @@ public class UUIDHandler {
if (uuidMap.containsKey(nameWrap)) {
return uuidMap.get(nameWrap);
}
@SuppressWarnings("deprecation")
Player player = Bukkit.getPlayer(name);
if (player!=null) {
UUID uuid = player.getUniqueId();
@ -107,7 +134,7 @@ public class UUIDHandler {
}
/**
* @param uuid
* @param uuid to use as key
* @return name (cache)
*/
private static StringWrapper loopSearch(UUID uuid) {
@ -115,7 +142,7 @@ public class UUIDHandler {
}
/**
* @param uuid
* @param uuid to use as key
* @return Name
*/
public static String getName(UUID uuid) {
@ -173,7 +200,7 @@ public class UUIDHandler {
}
/**
* @param name
* @param name to use as key
* @return UUID (name hash)
*/
private static UUID getUuidOfflineMode(StringWrapper name) {
@ -183,7 +210,7 @@ public class UUIDHandler {
}
/**
* @param uuid
* @param uuid to use as key
* @return String - name
*/
private static String getNameOnlinePlayer(UUID uuid) {
@ -197,7 +224,7 @@ public class UUIDHandler {
}
/**
* @param uuid
* @param uuid to use as key
* @return String - name
*/
private static String getNameOfflinePlayer(UUID uuid) {
@ -211,10 +238,11 @@ public class UUIDHandler {
}
/**
* @param name
* @param name to use as key
* @return UUID
*/
private static UUID getUuidOnlinePlayer(StringWrapper name) {
@SuppressWarnings("deprecation")
Player player = Bukkit.getPlayer(name.value);
if (player == null) {
return null;
@ -225,9 +253,10 @@ public class UUIDHandler {
}
/**
* @param name
* @param name to use as key
* @return UUID (username hash)
*/
@SuppressWarnings("unused")
private static UUID getUuidOfflinePlayer(StringWrapper name) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
add(name, uuid);
@ -235,7 +264,11 @@ public class UUIDHandler {
}
/* Save UUIDS */
/**
* Handle saving of uuids
* @see com.intellectualcrafters.plot.uuid.UUIDSaver#globalSave(com.google.common.collect.BiMap)
*/
@SuppressWarnings("unused")
public static void handleSaving() {
UUIDSaver saver = PlotMain.getUUIDSaver();
// Should it save per UUIDSet or all of them? TODO: Let Jesse decide xD

View File

@ -24,7 +24,7 @@ import java.util.Set;
/**
* The plotMain api class.
*
* @author Citymonstret
* @author Citymonstret, Empire92
*/
@SuppressWarnings({ "unused", "javadoc" })
public class PlotAPI {