From 80a32bf0dc6a6dbb88a3b2b88e878aed4655846f Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 30 Jun 2016 21:59:06 +0200 Subject: [PATCH] Added Javadoc --- src/de/epiceric/shopchest/Commands.java | 41 +++++++++-- src/de/epiceric/shopchest/ShopChest.java | 69 ++++++++++++++++++- src/de/epiceric/shopchest/config/Config.java | 38 ++++++++++ .../shopchest/interfaces/Hologram.java | 23 ++++++- .../shopchest/interfaces/JsonBuilder.java | 20 +++--- .../shopchest/interfaces/SpawnEggMeta.java | 7 ++ .../shopchest/language/EnchantmentName.java | 13 +++- .../shopchest/language/EntityName.java | 6 ++ .../epiceric/shopchest/language/ItemName.java | 9 +++ .../shopchest/language/LanguageUtils.java | 58 ++++++++++++++-- .../shopchest/language/LocalizedMessage.java | 17 ++++- .../shopchest/language/MusicDiscName.java | 6 ++ .../shopchest/language/PotionEffectName.java | 7 +- .../shopchest/language/PotionName.java | 11 ++- .../listeners/HologramUpdateListener.java | 3 - .../listeners/ShopInteractListener.java | 42 +++++++++++ src/de/epiceric/shopchest/shop/Shop.java | 41 ++++++++++- src/de/epiceric/shopchest/sql/Database.java | 36 +++++++++- .../epiceric/shopchest/utils/ClickType.java | 35 +++++++++- .../epiceric/shopchest/utils/ShopUtils.java | 45 +++++++++++- .../shopchest/utils/UpdateChecker.java | 21 ++++-- src/de/epiceric/shopchest/utils/Utils.java | 34 +++++++-- 22 files changed, 535 insertions(+), 47 deletions(-) diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index 7cd739a..1b4efea 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -39,6 +39,13 @@ public class Commands extends BukkitCommand { this.perm = plugin.getPermission(); } + /** + * Register a command to ShopChest + * + * @param command Command to register + * @param plugin Instance of ShopChest + * @throws ReflectiveOperationException + */ public static void registerCommand(Command command, ShopChest plugin) throws ReflectiveOperationException { Method commandMap = plugin.getServer().getClass().getMethod("getCommandMap"); Object cmdmap = commandMap.invoke(plugin.getServer()); @@ -131,10 +138,14 @@ public class Commands extends BukkitCommand { } + /** + * A given player checks for updates + * @param player The command executor + */ private void checkUpdates(Player player) { player.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CHECKING)); - UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite()); + UpdateChecker uc = new UpdateChecker(ShopChest.getInstance()); UpdateCheckerResult result = uc.updateNeeded(); if (result == UpdateCheckerResult.TRUE) { @@ -190,10 +201,20 @@ public class Commands extends BukkitCommand { } + /** + * A given player reloads the shops + * @param player The command executor + */ private void reload(Player player) { player.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(ShopUtils.reloadShops())))); } + /** + * A given player creates a shop + * @param args Arguments of the entered command + * @param shopType The {@link ShopType}, the shop will have + * @param p The command executor + */ private void create(String[] args, ShopType shopType, Player p) { int amount; double buyPrice, sellPrice; @@ -307,21 +328,33 @@ public class Commands extends BukkitCommand { } } - ClickType.addPlayerClickType(p, new ClickType(EnumClickType.CREATE, itemStack, buyPrice, sellPrice, shopType)); + ClickType.setPlayerClickType(p, new ClickType(EnumClickType.CREATE, itemStack, buyPrice, sellPrice, shopType)); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_CREATE)); } + /** + * A given player removes a shop + * @param p The command executor + */ private void remove(Player p) { p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE)); - ClickType.addPlayerClickType(p, new ClickType(EnumClickType.REMOVE)); + ClickType.setPlayerClickType(p, new ClickType(EnumClickType.REMOVE)); } + /** + * A given player retrieves information about a shop + * @param p The command executor + */ private void info(Player p) { p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_INFO)); - ClickType.addPlayerClickType(p, new ClickType(EnumClickType.INFO)); + ClickType.setPlayerClickType(p, new ClickType(EnumClickType.INFO)); } + /** + * Sends the basic help message to a given player + * @param player Player who will receive the message + */ private void sendBasicHelpMessage(Player player) { player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " create [normal|admin] - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE)); player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name + " remove - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE)); diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index 154f94d..e0db978 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -3,11 +3,11 @@ package de.epiceric.shopchest; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.LanguageConfiguration; import de.epiceric.shopchest.config.Regex; -import de.epiceric.shopchest.listeners.*; import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.jsonbuilder.*; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LocalizedMessage; +import de.epiceric.shopchest.listeners.*; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.sql.Database; @@ -50,10 +50,19 @@ public class ShopChest extends JavaPlugin { private String[] broadcast = null; private LanguageConfiguration langConfig; + /** + * Get an instance of ShopChest + * + * @return + */ public static ShopChest getInstance() { return instance; } + /** + * Sets up the economy of Vault + * @return + */ private boolean setupEconomy() { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { @@ -63,12 +72,19 @@ public class ShopChest extends JavaPlugin { return econ != null; } + /** + * Sets up the permissions of Vault + * @return + */ private boolean setupPermissions() { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Permission.class); perm = rsp.getProvider(); return perm != null; } + /** + * Initializes the language configuration + */ private void initLanguageConfig() { langConfig = new LanguageConfiguration(this); File langFolder = new File(getDataFolder(), "lang"); @@ -246,7 +262,7 @@ public class ShopChest extends JavaPlugin { lockette = getServer().getPluginManager().getPlugin("Lockette") != null; lwc = getServer().getPluginManager().getPlugin("LWC") != null; - UpdateChecker uc = new UpdateChecker(this, getDescription().getWebsite()); + UpdateChecker uc = new UpdateChecker(this); UpdateCheckerResult result = uc.updateNeeded(); if (Config.enable_broadcast) broadcast = uc.getBroadcast(); @@ -352,63 +368,112 @@ public class ShopChest extends JavaPlugin { } } + /** + * Initializes the shops + */ private void initializeShops() { int count = ShopUtils.reloadShops(); getLogger().info("Initialized " + String.valueOf(count) + " Shops"); } + /** + * @return ShopChest's {@link LanguageConfiguration} + */ public LanguageConfiguration getLanguageConfig() { return langConfig; } + /** + * @return Registered Economy of Vault + */ public Economy getEconomy() { return econ; } + /** + * @return Registered Permission of Vault + */ public Permission getPermission() { return perm; } + /** + * @return ShopChest's shop database + */ public Database getShopDatabase() { return database; } + /** + * @return Whether LWC is available + */ public boolean hasLWC() { return lwc; } + /** + * @return Whether Lockette is available + */ public boolean hasLockette() { return lockette; } + /** + * @return Whether an update is needed (will return false if not checked) + */ public boolean isUpdateNeeded() { return isUpdateNeeded; } + /** + * Set whether an update is needed + * @param isUpdateNeeded Whether an update should be needed + */ public void setUpdateNeeded(boolean isUpdateNeeded) { this.isUpdateNeeded = isUpdateNeeded; } + /** + * @return The latest version of ShopChest (will return null if not checked or if no update is available) + */ public String getLatestVersion() { return latestVersion; } + /** + * Set the latest version + * @param latestVersion Version to set as latest version + */ public void setLatestVersion(String latestVersion) { this.latestVersion = latestVersion; } + /** + * @return The download link of the latest version (will return null if not checked or if no update is available) + */ public String getDownloadLink() { return downloadLink; } + /** + * Set the download Link of the latest version (will return null if not checked or if no update is available) + * @param downloadLink Link to set as Download Link + */ public void setDownloadLink(String downloadLink) { this.downloadLink = downloadLink; } + /** + * @return The broadcast message as a string array of lines (will return null if not checked or if no message is available) + */ public String[] getBroadcast() { return broadcast; } + /** + * Set the broadcast message + * @param broadcast Broadcast message as a string array of lines to set + */ public void setBroadcast(String[] broadcast) { this.broadcast = broadcast; } diff --git a/src/de/epiceric/shopchest/config/Config.java b/src/de/epiceric/shopchest/config/Config.java index ff2c66f..34e8d16 100644 --- a/src/de/epiceric/shopchest/config/Config.java +++ b/src/de/epiceric/shopchest/config/Config.java @@ -12,46 +12,84 @@ public class Config { private static ShopChest plugin = ShopChest.getInstance(); + /** + * The hostname used in ShopChest's MySQL database + **/ public static String database_mysql_host = plugin.getConfig().getString("database.mysql.hostname"); + /** The port used for ShopChest's MySQL database **/ public static int database_mysql_port = plugin.getConfig().getInt("database.mysql.port"); + /** The database used for ShopChest's MySQL database **/ public static String database_mysql_database = plugin.getConfig().getString("database.mysql.database"); + /** The username used in ShopChest's MySQL database **/ public static String database_mysql_username = plugin.getConfig().getString("database.mysql.username"); + /** The password used in ShopChest's MySQL database **/ public static String database_mysql_password = plugin.getConfig().getString("database.mysql.password"); + /** The database type used for ShopChest. **/ public static Database.DatabaseType database_type = Database.DatabaseType.valueOf(plugin.getConfig().getString("database.type")); + /** + *

The minimum prices for certain items

+ * This returns a key set, which contains e.g "STONE", "STONE:1", of the minimum-prices section in ShopChest's config. + * To actually retrieve the price for an item, you have to get the Double minimum-prices.key. + **/ public static Set minimum_prices = (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true); + /** + *

The shop limits of certain groups

+ * This returns a key set, which contains the group names, of the shop-limits.group section in ShopChest's config. + * To actually retrieve the limits for a group, you have to get the Integer shop-limits.group.key. + **/ public static Set shopLimits_group = (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true); + /** + *

The shop limits of certain players

+ * This returns a key set, which contains the player names, of the shop-limits.player section in ShopChest's config. + * To actually retrieve the limits for a player, you have to get the Integer shop-limits.player.key. + **/ public static Set shopLimits_player = (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true); + /** + *

List containing items, of which players can't create a shop

+ * If this list contains an item (e.g "STONE", "STONE:1"), it's in the blacklist. + **/ public static List blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList() : plugin.getConfig().getStringList("blacklist"); + /** Whether the buy price of a shop must be greater than or equal the sell price **/ public static boolean buy_greater_or_equal_sell = plugin.getConfig().getBoolean("buy-greater-or-equal-sell"); + /** Whether shops should be protected by hoppers **/ public static boolean hopper_protection = plugin.getConfig().getBoolean("hopper-protection"); + /** Whether shops should be protected by explosions **/ public static boolean explosion_protection = plugin.getConfig().getBoolean("explosion-protection"); + /** Whether broadcast messages should be enabled **/ public static boolean enable_broadcast = plugin.getConfig().getBoolean("enable-broadcast"); + /** Whether admin shops should be excluded of the shop limits **/ public static boolean exclude_admin_shops = plugin.getConfig().getBoolean("shop-limits.exclude-admin-shops"); + /** The maximum distance between a player and a shop to see the hologram **/ public static double maximal_distance = plugin.getConfig().getDouble("maximal-distance"); + /** The price a player has to pay in order to create a normal shop **/ public static double shop_creation_price_normal = plugin.getConfig().getDouble("shop-creation-price.normal"); + /** The price a player has to pay in order to create an admin shop **/ public static double shop_creation_price_admin = plugin.getConfig().getDouble("shop-creation-price.admin"); + /** The default shop limit for players and groups that are not listed in {@link #shopLimits_player} or in {@link #shopLimits_group} **/ public static int default_limit = plugin.getConfig().getInt("shop-limits.default"); + /** The main command of ShopChest (default: shop) **/ public static String main_command_name = plugin.getConfig().getString("main-command-name"); + /** The language file to use (e.g en_US, de_DE) **/ public static String language_file = plugin.getConfig().getString("language-file"); } diff --git a/src/de/epiceric/shopchest/interfaces/Hologram.java b/src/de/epiceric/shopchest/interfaces/Hologram.java index 97e5b0a..be43db8 100644 --- a/src/de/epiceric/shopchest/interfaces/Hologram.java +++ b/src/de/epiceric/shopchest/interfaces/Hologram.java @@ -4,20 +4,39 @@ package de.epiceric.shopchest.interfaces; import org.bukkit.Location; import org.bukkit.OfflinePlayer; -import java.util.List; - public interface Hologram { + /** + * @return Location of the hologram + */ Location getLocation(); + /** + * @param p Player to which the hologram should be shown + */ void showPlayer(OfflinePlayer p); + + /** + * @param p Player from which the hologram should be hidden + */ void hidePlayer(OfflinePlayer p); + /** + * @param p Player to check + * @return Whether the hologram is visible to the player + */ boolean isVisible(OfflinePlayer p); + /** + * @return Whether the hologram exists and is not dead + */ boolean exists(); + /** + * Removes the hologram.
+ * Hologram will be hidden from all players and will be killed + */ void remove(); } diff --git a/src/de/epiceric/shopchest/interfaces/JsonBuilder.java b/src/de/epiceric/shopchest/interfaces/JsonBuilder.java index 16144a5..3b58f81 100644 --- a/src/de/epiceric/shopchest/interfaces/JsonBuilder.java +++ b/src/de/epiceric/shopchest/interfaces/JsonBuilder.java @@ -5,27 +5,27 @@ import org.bukkit.entity.Player; public interface JsonBuilder { - public JsonBuilder parse(String text); + JsonBuilder parse(String text); - public JsonBuilder withText(String text); + JsonBuilder withText(String text); - public JsonBuilder withColor(ChatColor color); + JsonBuilder withColor(ChatColor color); - public JsonBuilder withColor(String color); + JsonBuilder withColor(String color); - public JsonBuilder withClickEvent(ClickAction action, String value); + JsonBuilder withClickEvent(ClickAction action, String value); - public JsonBuilder withHoverEvent(HoverAction action, String value); + JsonBuilder withHoverEvent(HoverAction action, String value); - public String toString(); + String toString(); - public void sendJson(Player p); + void sendJson(Player p); - public enum ClickAction { + enum ClickAction { RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL } - public enum HoverAction { + enum HoverAction { SHOW_TEXT } diff --git a/src/de/epiceric/shopchest/interfaces/SpawnEggMeta.java b/src/de/epiceric/shopchest/interfaces/SpawnEggMeta.java index a310150..a87aaed 100644 --- a/src/de/epiceric/shopchest/interfaces/SpawnEggMeta.java +++ b/src/de/epiceric/shopchest/interfaces/SpawnEggMeta.java @@ -4,8 +4,15 @@ import org.bukkit.entity.EntityType; public abstract class SpawnEggMeta { + /** + * @return The NBT Tag EntityTag.id of the Spawn Egg + */ public abstract String getNBTEntityID(); + /** + * @param nbtEntityID EntityID returned by {@link #getNBTEntityID()} + * @return The {@link EntityType} the Spawn Egg will spawn or null if nbtEntityID is null + */ public EntityType getEntityTypeFromNBTEntityID(String nbtEntityID) { if (nbtEntityID == null) return null; diff --git a/src/de/epiceric/shopchest/language/EnchantmentName.java b/src/de/epiceric/shopchest/language/EnchantmentName.java index 2dc8ea6..277d951 100644 --- a/src/de/epiceric/shopchest/language/EnchantmentName.java +++ b/src/de/epiceric/shopchest/language/EnchantmentName.java @@ -12,11 +12,16 @@ public class EnchantmentName { this.localizedName = localizedName; } - + /** + * @return Enchantment linked to the name + */ public Enchantment getEnchantment() { return enchantment; } + /** + * @return Name linked to the enchantment + */ public String getLocalizedName() { return localizedName; } @@ -30,10 +35,16 @@ public class EnchantmentName { this.localizedName = localizedName; } + /** + * @return Level linked to the name + */ public int getLevel() { return level; } + /** + * @return Name linked to the level + */ public String getLocalizedName() { return localizedName; } diff --git a/src/de/epiceric/shopchest/language/EntityName.java b/src/de/epiceric/shopchest/language/EntityName.java index 072be34..953fb78 100644 --- a/src/de/epiceric/shopchest/language/EntityName.java +++ b/src/de/epiceric/shopchest/language/EntityName.java @@ -12,10 +12,16 @@ public class EntityName { this.localizedName = localizedName; } + /** + * @return EntityType linked to the name + */ public EntityType getEntityType() { return entityType; } + /** + * @return Name linked to the EntityType + */ public String getLocalizedName() { return localizedName; } diff --git a/src/de/epiceric/shopchest/language/ItemName.java b/src/de/epiceric/shopchest/language/ItemName.java index e8c00e4..4f43746 100644 --- a/src/de/epiceric/shopchest/language/ItemName.java +++ b/src/de/epiceric/shopchest/language/ItemName.java @@ -20,14 +20,23 @@ public class ItemName { this.localizedName = localizedName; } + /** + * @return Material linked to the name + */ public Material getMaterial() { return material; } + /** + * @return Sub ID linked to the name + */ public int getSubID() { return subID; } + /** + * @return Name linked to the item + */ public String getLocalizedName() { return localizedName; } diff --git a/src/de/epiceric/shopchest/language/LanguageUtils.java b/src/de/epiceric/shopchest/language/LanguageUtils.java index 212b324..8d729be 100644 --- a/src/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/de/epiceric/shopchest/language/LanguageUtils.java @@ -34,6 +34,7 @@ public class LanguageUtils { public static void load() { + // Add Block Names itemNames.add(new ItemName(Material.STONE, langConfig.getString("tile.stone.stone.name", "Stone"))); itemNames.add(new ItemName(Material.STONE, 1, langConfig.getString("tile.stone.granite.name", "Granite"))); itemNames.add(new ItemName(Material.STONE, 2, langConfig.getString("tile.stone.graniteSmooth.name", "Polished Granite"))); @@ -338,6 +339,7 @@ public class LanguageUtils { itemNames.add(new ItemName(Material.ACACIA_FENCE, langConfig.getString("tile.acaciaFence.name", "Acacia Fence"))); if (Utils.getMajorVersion() >= 9) { + // Add Block Names of 1.9 itemNames.add(new ItemName(Material.END_ROD, langConfig.getString("tile.endRod.name", "End Rod"))); itemNames.add(new ItemName(Material.CHORUS_PLANT, langConfig.getString("tile.chorusPlant.name", "Chorus Plant"))); itemNames.add(new ItemName(Material.CHORUS_FLOWER, langConfig.getString("tile.chorusFlower.name", "Chorus Flower"))); @@ -353,6 +355,7 @@ public class LanguageUtils { } if (Utils.getMajorVersion() >= 10) { + // Add Block Names of 1.10 itemNames.add(new ItemName(Material.MAGMA, langConfig.getString("tile.magma.name", "Magma Block"))); itemNames.add(new ItemName(Material.NETHER_WART_BLOCK, langConfig.getString("tile.netherWartBlock.name", "Nether Wart Block"))); itemNames.add(new ItemName(Material.RED_NETHER_BRICK, langConfig.getString("tile.redNetherBrick.name", "Red Nether Brick"))); @@ -360,6 +363,7 @@ public class LanguageUtils { itemNames.add(new ItemName(Material.STRUCTURE_VOID, langConfig.getString("tile.structureVoid.name", "Structure Void"))); } + // Add Item Names itemNames.add(new ItemName(Material.IRON_SPADE, langConfig.getString("item.shovelIron.name", "Iron Shovel"))); itemNames.add(new ItemName(Material.IRON_PICKAXE, langConfig.getString("item.pickaxeIron.name", "Iron Pickaxe"))); itemNames.add(new ItemName(Material.IRON_AXE, langConfig.getString("item.hatchetIron.name", "Iron Axe"))); @@ -605,6 +609,7 @@ public class LanguageUtils { itemNames.add(new ItemName(Material.RECORD_11, langConfig.getString("item.record.name", "Music Disc"))); itemNames.add(new ItemName(Material.RECORD_12, langConfig.getString("item.record.name", "Music Disc"))); + // Add Enchantment Names enchantmentNames.add(new EnchantmentName(Enchantment.ARROW_DAMAGE, langConfig.getString("enchantment.arrowDamage", "Power"))); enchantmentNames.add(new EnchantmentName(Enchantment.ARROW_FIRE, langConfig.getString("enchantment.arrowFire", "Flame"))); enchantmentNames.add(new EnchantmentName(Enchantment.ARROW_INFINITE, langConfig.getString("enchantment.arrowInfinite", "Infinity"))); @@ -632,10 +637,12 @@ public class LanguageUtils { enchantmentNames.add(new EnchantmentName(Enchantment.WATER_WORKER, langConfig.getString("enchantment.waterWorker", "Aqua Affinity"))); if (Utils.getMajorVersion() >= 9) { + // Add Enchantment Names of 1.9 enchantmentNames.add(new EnchantmentName(Enchantment.FROST_WALKER, langConfig.getString("enchantment.frostWalker", "Frost Walker"))); enchantmentNames.add(new EnchantmentName(Enchantment.MENDING, langConfig.getString("enchantment.mending", "Mending"))); } + // Add Enchantment Level Names enchantmentLevelNames.add(new EnchantmentName.EnchantmentLevelName(1, langConfig.getString("enchantment.level.1", "I"))); enchantmentLevelNames.add(new EnchantmentName.EnchantmentLevelName(2, langConfig.getString("enchantment.level.2", "II"))); enchantmentLevelNames.add(new EnchantmentName.EnchantmentLevelName(3, langConfig.getString("enchantment.level.3", "II"))); @@ -647,6 +654,7 @@ public class LanguageUtils { enchantmentLevelNames.add(new EnchantmentName.EnchantmentLevelName(9, langConfig.getString("enchantment.level.9", "IX"))); enchantmentLevelNames.add(new EnchantmentName.EnchantmentLevelName(10, langConfig.getString("enchantment.level.10", "X"))); + // Add Entity Names entityNames.add(new EntityName(EntityType.CREEPER, langConfig.getString("entity.Creeper.name", "Creeper"))); entityNames.add(new EntityName(EntityType.SKELETON, langConfig.getString("entity.Skeleton.name", "Skeleton"))); entityNames.add(new EntityName(EntityType.SPIDER, langConfig.getString("entity.Spider.name", "Spider"))); @@ -676,13 +684,16 @@ public class LanguageUtils { entityNames.add(new EntityName(EntityType.VILLAGER, langConfig.getString("entity.Villager.name", "Villager"))); if (Utils.getMajorVersion() >= 9) { + // Add Entity Names of 1.9 entityNames.add(new EntityName(EntityType.SHULKER, langConfig.getString("entity.Shulker.name", "Shulker"))); } if (Utils.getMajorVersion() >= 10) { + // Add Entity Names of 1.10 entityNames.add(new EntityName(EntityType.POLAR_BEAR, langConfig.getString("entity.PolarBear.name", "Polar Bear"))); } + // Add Potion Effect Names potionEffectNames.add(new PotionEffectName(PotionType.FIRE_RESISTANCE, langConfig.getString("effect.fireResistance", "Fire Resistance"))); potionEffectNames.add(new PotionEffectName(PotionType.INSTANT_DAMAGE, langConfig.getString("effect.harm", "Instant Damage"))); potionEffectNames.add(new PotionEffectName(PotionType.INSTANT_HEAL, langConfig.getString("effect.heal", "Instant Health"))); @@ -700,12 +711,14 @@ public class LanguageUtils { potionEffectNames.add(new PotionEffectName(PotionType.AWKWARD, langConfig.getString("effect.none", "No Effects"))); if (Utils.getMajorVersion() >= 9) { + // Add Potion Effect Names of 1.9 potionEffectNames.add(new PotionEffectName(PotionType.LUCK, langConfig.getString("effect.luck", "Luck"))); potionEffectNames.add(new PotionEffectName(PotionType.MUNDANE, langConfig.getString("effect.none", "No Effects"))); potionEffectNames.add(new PotionEffectName(PotionType.THICK, langConfig.getString("effect.none", "No Effects"))); potionEffectNames.add(new PotionEffectName(PotionType.UNCRAFTABLE, langConfig.getString("effect.none", "No Effects"))); } + // Add Potion Names potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.AWKWARD, langConfig.getString("potion.effect.awkward", "Awkward Potion"))); potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.FIRE_RESISTANCE, langConfig.getString("potion.effect.fire_resistance", "Potion of Fire Resistance"))); potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.INSTANT_DAMAGE, langConfig.getString("potion.effect.harming", "Potion of Harming"))); @@ -723,6 +736,7 @@ public class LanguageUtils { potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.WATER, langConfig.getString("potion.effect.water", "Water Bottle"))); if (Utils.getMajorVersion() >= 9) { + // Add Potion Names of 1.9 potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.LUCK, langConfig.getString("potion.effect.luck", "Potion of Luck"))); potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.MUNDANE, langConfig.getString("potion.effect.mundane", "Mundane Potion"))); potionNames.add(new PotionName(PotionName.PotionItemType.POTION, PotionType.THICK, langConfig.getString("potion.effect.thick", "Thick Potion"))); @@ -730,6 +744,7 @@ public class LanguageUtils { } if (Utils.getMajorVersion() >= 9) { + // Add Tipped Arrow Names (implemented in Minecraft since 1.9) potionNames.add(new PotionName(PotionName.PotionItemType.TIPPED_ARROW, PotionType.AWKWARD, langConfig.getString("tipped_arrow.effect.awkward", "Tipped Arrow"))); potionNames.add(new PotionName(PotionName.PotionItemType.TIPPED_ARROW, PotionType.FIRE_RESISTANCE, langConfig.getString("tipped_arrow.effect.fire_resistance", "Arrow of Fire Resistance"))); potionNames.add(new PotionName(PotionName.PotionItemType.TIPPED_ARROW, PotionType.INSTANT_DAMAGE, langConfig.getString("tipped_arrow.effect.harming", "Arrow of Harming"))); @@ -751,6 +766,7 @@ public class LanguageUtils { potionNames.add(new PotionName(PotionName.PotionItemType.TIPPED_ARROW, PotionType.UNCRAFTABLE, langConfig.getString("tipped_arrow.effect.empty", "Tipped Arrow"))); } + // Add Splash Potion Names potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.AWKWARD, langConfig.getString("splash_potion.effect.awkward", "Awkward Splash Potion"))); potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.FIRE_RESISTANCE, langConfig.getString("splash_potion.effect.fire_resistance", "Splash Potion of Fire Resistance"))); potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.INSTANT_DAMAGE, langConfig.getString("splash_potion.effect.harming", "Splash Potion of Harming"))); @@ -768,6 +784,7 @@ public class LanguageUtils { potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.WATER, langConfig.getString("splash_potion.effect.water", "Splash Water Bottle"))); if (Utils.getMajorVersion() >= 9) { + // Add Splash Potion Names of 1.9 potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.LUCK, langConfig.getString("splash_potion.effect.luck", "Splash Potion of Luck"))); potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.MUNDANE, langConfig.getString("splash_potion.effect.mundane", "Mundane Splash Potion"))); potionNames.add(new PotionName(PotionName.PotionItemType.SPLASH_POTION, PotionType.THICK, langConfig.getString("splash_potion.effect.thick", "Thick Splash Potion"))); @@ -775,6 +792,7 @@ public class LanguageUtils { } if (Utils.getMajorVersion() >= 9) { + // Add Lingering Potion Names (implemented in Minecraft since 1.9) potionNames.add(new PotionName(PotionName.PotionItemType.LINGERING_POTION, PotionType.AWKWARD, langConfig.getString("lingering_potion.effect.awkward", "Awkward Lingering Potion"))); potionNames.add(new PotionName(PotionName.PotionItemType.LINGERING_POTION, PotionType.FIRE_RESISTANCE, langConfig.getString("lingering_potion.effect.fire_resistance", "Lingering Potion of Fire Resistance"))); potionNames.add(new PotionName(PotionName.PotionItemType.LINGERING_POTION, PotionType.INSTANT_DAMAGE, langConfig.getString("lingering_potion.effect.harming", "Lingering Potion of Harming"))); @@ -796,6 +814,7 @@ public class LanguageUtils { potionNames.add(new PotionName(PotionName.PotionItemType.LINGERING_POTION, PotionType.UNCRAFTABLE, langConfig.getString("lingering_potion.effect.empty", "Lingering Uncraftable Potion"))); } + // Add Music Disc Titles musicDiscNames.add(new MusicDiscName(Material.GOLD_RECORD, langConfig.getString("item.record.13.desc", "C418 - 13"))); musicDiscNames.add(new MusicDiscName(Material.GREEN_RECORD, langConfig.getString("item.record.cat.desc", "C418 - cat"))); musicDiscNames.add(new MusicDiscName(Material.RECORD_3, langConfig.getString("item.record.blocks.desc", "C418 - blocks"))); @@ -809,6 +828,7 @@ public class LanguageUtils { musicDiscNames.add(new MusicDiscName(Material.RECORD_11, langConfig.getString("item.record.11.desc", "C418 - 11"))); musicDiscNames.add(new MusicDiscName(Material.RECORD_12, langConfig.getString("item.record.wait.desc", "C418 - wait"))); + // Add ShopChest Messages messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_CREATED, langConfig.getString("message.shop-created", "&6Shop created."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP, langConfig.getString("message.chest-already-shop", "&cChest already shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_REMOVED, langConfig.getString("message.shop-removed", "&6Shop removed."))); @@ -881,6 +901,10 @@ public class LanguageUtils { messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS, langConfig.getString("message.commandDescription.limits", "View shop limits."))); } + /** + * @param stack Item whose name to lookup + * @return Localized Name of the Item, the custom name, or if stack is a book, the title of the book + */ public static String getItemName(ItemStack stack) { if (stack.hasItemMeta()) { ItemMeta meta = stack.getItemMeta(); @@ -959,7 +983,7 @@ public class LanguageUtils { } } - return itemName.getLocalizedName() + " " + capitalizeDefaultString(spawnedType.toString()); + return itemName.getLocalizedName() + " " + formatDefaultString(spawnedType.toString()); } @@ -969,11 +993,16 @@ public class LanguageUtils { } - return capitalizeDefaultString(material.toString()); + return formatDefaultString(material.toString()); } + /** + * @param enchantment Enchantment whose name should be looked up + * @param level Level of the enchantment + * @return Localized Name of the enchantment with the given level afterwards + */ public static String getEnchantmentName(Enchantment enchantment, int level) { - String enchantmentString = capitalizeDefaultString(enchantment.getName()); + String enchantmentString = formatDefaultString(enchantment.getName()); String levelString = langConfig.getString("enchantment.level." + level, String.valueOf(level)); for (EnchantmentName enchantmentName : enchantmentNames) { @@ -991,10 +1020,14 @@ public class LanguageUtils { return enchantmentString + " " + levelString; } + /** + * @param itemStack Potion Item whose base effect name should be looked up + * @return Localized Name of the Base Potion Effect + */ public static String getPotionEffectName(ItemStack itemStack) { PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); - String potionEffectString = capitalizeDefaultString(potionMeta.getBasePotionData().getType().toString()); + String potionEffectString = formatDefaultString(potionMeta.getBasePotionData().getType().toString()); String upgradeString = potionMeta.getBasePotionData().isUpgraded() ? "II" : ""; for (PotionEffectName potionEffectName : potionEffectNames) { @@ -1006,6 +1039,10 @@ public class LanguageUtils { return potionEffectString + (upgradeString.length() > 0 ? " " + upgradeString : ""); } + /** + * @param musicDiscMaterial Material of the Music Disc whose name should be looked up + * @return Localized title of the Music Disc + */ public static String getMusicDiscName(Material musicDiscMaterial) { for (MusicDiscName musicDiscName : musicDiscNames) { if (musicDiscMaterial == musicDiscName.getMusicDiscMaterial()) { @@ -1016,6 +1053,11 @@ public class LanguageUtils { return ""; } + /** + * @param message Message which should be translated + * @param replacedRegexes Regexes which might be required to be replaced in the message + * @return Localized Message + */ public static String getMessage(LocalizedMessage.Message message, LocalizedMessage.ReplacedRegex... replacedRegexes) { String _message = ChatColor.RED + "An error occurred: Message not found: " + message.toString(); @@ -1055,7 +1097,13 @@ public class LanguageUtils { return _message; } - private static String capitalizeDefaultString(String string) { + /** + * Underscores will be replaced by spaces and the first letter of each word will be capitalized + * + * @param string String to format + * @return Formatted String with underscores replaced by spaces and the first letter of each word capitalized + */ + private static String formatDefaultString(String string) { string = string.replace("_", " "); String newString = ""; diff --git a/src/de/epiceric/shopchest/language/LocalizedMessage.java b/src/de/epiceric/shopchest/language/LocalizedMessage.java index d87a255..67fb595 100644 --- a/src/de/epiceric/shopchest/language/LocalizedMessage.java +++ b/src/de/epiceric/shopchest/language/LocalizedMessage.java @@ -20,14 +20,23 @@ public class LocalizedMessage { this.localizedString = ChatColor.translateAlternateColorCodes('&', localizedString); } + /** + * @return {@link Message} linked to this object + */ public Message getMessage() { return message; } + /** + * @return Array of {@link Regex}, which are required by the message + */ public Regex[] getRegexes() { return regexes; } + /** + * @return Localized Message + */ public String getLocalizedString() { return localizedString; } @@ -102,7 +111,7 @@ public class LocalizedMessage { COMMAND_DESC_INFO, COMMAND_DESC_RELOAD, COMMAND_DESC_UPDATE, - COMMAND_DESC_LIMITS; + COMMAND_DESC_LIMITS } public static class ReplacedRegex { @@ -115,10 +124,16 @@ public class LocalizedMessage { this.replace = replace; } + /** + * @return String which will replace the regex + */ public String getReplace() { return replace; } + /** + * @return Regex that will be replaced + */ public Regex getRegex() { return regex; } diff --git a/src/de/epiceric/shopchest/language/MusicDiscName.java b/src/de/epiceric/shopchest/language/MusicDiscName.java index d4ef8fe..4c2ff18 100644 --- a/src/de/epiceric/shopchest/language/MusicDiscName.java +++ b/src/de/epiceric/shopchest/language/MusicDiscName.java @@ -12,10 +12,16 @@ public class MusicDiscName { this.localizedName = localizedName; } + /** + * @return Localized Title of the Music Disc + */ public String getLocalizedName() { return localizedName; } + /** + * @return Material of the Music Disc + */ public Material getMusicDiscMaterial() { return musicDiscMaterial; } diff --git a/src/de/epiceric/shopchest/language/PotionEffectName.java b/src/de/epiceric/shopchest/language/PotionEffectName.java index 04a121e..7a17e28 100644 --- a/src/de/epiceric/shopchest/language/PotionEffectName.java +++ b/src/de/epiceric/shopchest/language/PotionEffectName.java @@ -12,11 +12,16 @@ public class PotionEffectName { this.localizedName = localizedName; } - + /** + * @return Potion Effect linked to the name + */ public PotionType getEffect() { return effect; } + /** + * @return Localized Name of the potion effect + */ public String getLocalizedName() { return localizedName; } diff --git a/src/de/epiceric/shopchest/language/PotionName.java b/src/de/epiceric/shopchest/language/PotionName.java index 2db8916..9eae377 100644 --- a/src/de/epiceric/shopchest/language/PotionName.java +++ b/src/de/epiceric/shopchest/language/PotionName.java @@ -15,14 +15,23 @@ public class PotionName { this.potionType = potionType; } + /** + * @return {@link PotionItemType} linked to the Potion name + */ public PotionItemType getPotionItemType() { return potionItemType; } + /** + * @return Potion Type linked to the Potion name + */ public PotionType getPotionType() { return potionType; } + /** + * @return Localized Name of the Potion + */ public String getLocalizedName() { return localizedName; } @@ -31,6 +40,6 @@ public class PotionName { POTION, LINGERING_POTION, SPLASH_POTION, - TIPPED_ARROW; + TIPPED_ARROW } } diff --git a/src/de/epiceric/shopchest/listeners/HologramUpdateListener.java b/src/de/epiceric/shopchest/listeners/HologramUpdateListener.java index e78e668..09c57e9 100644 --- a/src/de/epiceric/shopchest/listeners/HologramUpdateListener.java +++ b/src/de/epiceric/shopchest/listeners/HologramUpdateListener.java @@ -11,9 +11,6 @@ import org.bukkit.event.player.PlayerMoveEvent; public class HologramUpdateListener implements Listener { - public HologramUpdateListener() { - } - @EventHandler public void onPlayerMove(PlayerMoveEvent e) { diff --git a/src/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/de/epiceric/shopchest/listeners/ShopInteractListener.java index 6c25753..bb293fc 100644 --- a/src/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -223,6 +223,16 @@ public class ShopInteractListener implements Listener { } + /** + * Create a new shop + * + * @param executor Player, who executed the command, will receive the message and become the vendor of the shop + * @param location Where the shop will be located + * @param product Product of the Shop + * @param buyPrice Buy price + * @param sellPrice Sell price + * @param shopType Type of the shop + */ private void create(Player executor, Location location, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) { Shop shop = new Shop(database.getNextFreeID(), plugin, executor, product, location, buyPrice, sellPrice, shopType); @@ -235,11 +245,21 @@ public class ShopInteractListener implements Listener { } + /** + * Remove a shop + * @param executor Player, who executed the command and will receive the message + * @param shop Shop to be removed + */ private void remove(Player executor, Shop shop) { ShopUtils.removeShop(shop, true); executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED)); } + /** + * + * @param executor Player, who executed the command and will retrieve the information + * @param shop Shop from which the information will be retrieved + */ private void info(Player executor, Shop shop) { Chest c = (Chest) shop.getLocation().getBlock().getState(); @@ -308,6 +328,11 @@ public class ShopInteractListener implements Listener { executor.sendMessage(" "); } + /** + * A player buys from a shop + * @param executor Player, who executed the command and will buy the product + * @param shop Shop, from which the player buys + */ private void buy(Player executor, Shop shop) { if (econ.getBalance(executor) >= shop.getBuyPrice()) { @@ -390,6 +415,11 @@ public class ShopInteractListener implements Listener { } } + /** + * A player sells to a shop + * @param executor Player, who executed the command and will sell the product + * @param shop Shop, to which the player sells + */ private void sell(Player executor, Shop shop) { if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice() || shop.getShopType() == ShopType.ADMIN) { @@ -463,6 +493,12 @@ public class ShopInteractListener implements Listener { } } + /** + * Adds items to an inventory + * @param inventory The inventory, to which the items will be added + * @param itemStack Items to add + * @return Whether all items were added to the inventory + */ private boolean addToInventory(Inventory inventory, ItemStack itemStack) { HashMap inventoryItems = new HashMap<>(); int amount = itemStack.getAmount(); @@ -513,6 +549,12 @@ public class ShopInteractListener implements Listener { return (added == amount); } + /** + * Removes items to from an inventory + * @param inventory The inventory, from which the items will be removed + * @param itemStack Items to remove + * @return Whether all items were removed from the inventory + */ private boolean removeFromInventory(Inventory inventory, ItemStack itemStack) { HashMap inventoryItems = new HashMap<>(); int amount = itemStack.getAmount(); diff --git a/src/de/epiceric/shopchest/shop/Shop.java b/src/de/epiceric/shopchest/shop/Shop.java index 16a2379..3c67807 100644 --- a/src/de/epiceric/shopchest/shop/Shop.java +++ b/src/de/epiceric/shopchest/shop/Shop.java @@ -22,7 +22,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; -import java.util.ArrayList; import java.util.UUID; public class Shop { @@ -65,6 +64,9 @@ public class Shop { if (item == null || item.isDead()) createItem(); } + /** + * Creates the hologram of the shop if it doesn't exist + */ public void removeHologram() { if (hologram != null && hologram.exists()) { for (Player p : Bukkit.getOnlinePlayers()) { @@ -75,11 +77,18 @@ public class Shop { } } + /** + * Removes the floating item of the shop + */ public void removeItem() { if (item != null && !item.isDead()) item.remove(); } + /** + *

Creates the floating item of the shop

+ * Call this after {@link #createHologram()}, because it depends on the hologram's location + */ private void createItem() { Item item; Location itemLocation; @@ -101,6 +110,9 @@ public class Shop { this.item = item; } + /** + * Creates the hologram of the shop + */ private void createHologram() { boolean doubleChest; @@ -188,38 +200,65 @@ public class Shop { } + /** + * @return The ID of the shop + */ public int getID() { return id; } + /** + * @return Vendor of the shop; probably the creator of it + */ public OfflinePlayer getVendor() { return vendor; } + /** + * @return Product the shop sells (or buys) + */ public ItemStack getProduct() { return product; } + /** + * @return Location of (one of) the shop's chest + */ public Location getLocation() { return location; } + /** + * @return Buy price of the shop + */ public double getBuyPrice() { return buyPrice; } + /** + * @return Sell price of the shop + */ public double getSellPrice() { return sellPrice; } + /** + * @return Type of the shop + */ public ShopType getShopType() { return shopType; } + /** + * @return Hologram of the shop + */ public Hologram getHologram() { return hologram; } + /** + * @return Chest of the shop. If double chest, only one chest is returned + */ public Chest getChest() { return chest; } diff --git a/src/de/epiceric/shopchest/sql/Database.java b/src/de/epiceric/shopchest/sql/Database.java index 388acd4..ffa4b67 100644 --- a/src/de/epiceric/shopchest/sql/Database.java +++ b/src/de/epiceric/shopchest/sql/Database.java @@ -24,8 +24,15 @@ public abstract class Database { initialize(); } + /** + * @return Connection to the database + */ public abstract Connection getConnection(); + /** + * Initializes the database.
+ * Creates the table (if doesn't exist) and tests the connection + */ private void initialize() { connection = getConnection(); @@ -57,6 +64,9 @@ public abstract class Database { } } + /** + * @return Lowest possible ID which is not used (> 0) + */ public int getNextFreeID() { for (int i = 1; i < getHighestID() + 1; i++) { if (get(i, ShopInfo.X) == null) { @@ -71,6 +81,9 @@ public abstract class Database { return 1; } + /** + * @return Highest ID which is used + */ public int getHighestID() { PreparedStatement ps = null; ResultSet rs = null; @@ -98,6 +111,11 @@ public abstract class Database { return 0; } + /** + * Remove a shop from the database + * + * @param shop Shop to remove + */ public void removeShop(Shop shop) { PreparedStatement ps = null; @@ -112,6 +130,11 @@ public abstract class Database { } + /** + * @param id ID of the shop + * @param shopInfo What to get + * @return Value you wanted to get. This needs to be casted to the right type! + */ public Object get(int id, ShopInfo shopInfo) { PreparedStatement ps = null; ResultSet rs = null; @@ -186,6 +209,10 @@ public abstract class Database { return null; } + /** + * Adds a shop to the database + * @param shop Shop to add + */ public void addShop(Shop shop) { PreparedStatement ps = null; @@ -211,6 +238,11 @@ public abstract class Database { } } + /** + * Closes a {@link PreparedStatement} and a {@link ResultSet} + * @param ps {@link PreparedStatement} to close + * @param rs {@link ResultSet} to close + */ private void close(PreparedStatement ps, ResultSet rs) { try { if (ps != null) @@ -233,11 +265,11 @@ public abstract class Database { LOCATION, BUYPRICE, SELLPRICE, - SHOPTYPE; + SHOPTYPE } public enum DatabaseType { SQLite, - MySQL; + MySQL } } \ No newline at end of file diff --git a/src/de/epiceric/shopchest/utils/ClickType.java b/src/de/epiceric/shopchest/utils/ClickType.java index c83aa2e..3faa32c 100644 --- a/src/de/epiceric/shopchest/utils/ClickType.java +++ b/src/de/epiceric/shopchest/utils/ClickType.java @@ -27,6 +27,12 @@ public class ClickType { this.shopType = shopType; } + /** + * Gets the click type of a player + * + * @param player Player whose click type should be gotten + * @return The Player's click type or null if he doesn't have one + */ public static ClickType getPlayerClickType(OfflinePlayer player) { if (playerClickType.containsKey(player)) return playerClickType.get(player); @@ -34,36 +40,61 @@ public class ClickType { return null; } + /** + * Removes the click type from a player + * @param player Player to remove the click type from + */ public static void removePlayerClickType(OfflinePlayer player) { playerClickType.remove(player); } - public static void addPlayerClickType(OfflinePlayer player, ClickType clickType) { + /** + * Sets the click type of a player + * + * @param player Player whose click type should be set + * @param clickType Click type to set + */ + public static void setPlayerClickType(OfflinePlayer player, ClickType clickType) { playerClickType.put(player, clickType); } + /** + * @return Type of the click type + */ public EnumClickType getClickType() { return enumClickType; } + /** + * @return If {@link #getClickType()} returns {@link EnumClickType#CREATE}, this returns the item, the player has hold in his hands, else null. + */ public ItemStack getProduct() { return product; } + /** + * @return If {@link #getClickType()} returns {@link EnumClickType#CREATE}, this returns the buy price, the player has entered, else null. + */ public double getBuyPrice() { return buyPrice; } + /** + * @return If {@link #getClickType()} returns {@link EnumClickType#CREATE}, this returns the sell price, the player has entered, else null. + */ public double getSellPrice() { return sellPrice; } + /** + * @return If {@link #getClickType()} returns {@link EnumClickType#CREATE}, this returns the shop type, the player has entered, else null. + */ public ShopType getShopType() { return shopType; } public enum EnumClickType { - CREATE, REMOVE, INFO; + CREATE, REMOVE, INFO } } diff --git a/src/de/epiceric/shopchest/utils/ShopUtils.java b/src/de/epiceric/shopchest/utils/ShopUtils.java index 8ce3a25..a431dea 100644 --- a/src/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/de/epiceric/shopchest/utils/ShopUtils.java @@ -4,8 +4,10 @@ import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.sql.Database; -import org.bukkit.*; -import org.bukkit.block.Block; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; import org.bukkit.entity.Entity; @@ -23,17 +25,32 @@ public class ShopUtils { private static HashMap shopLocation = new HashMap<>(); private static ShopChest plugin = ShopChest.getInstance(); + /** + * Get the shop at a given location + * + * @param location Location of the shop + * @return Shop at the given location or null if no shop is found there + */ public static Shop getShop(Location location) { Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); return shopLocation.get(newLocation); } + /** + * Checks whether there is a shop at a given location + * @param location Location to check + * @return Whether there is a shop at the given location + */ public static boolean isShop(Location location) { Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); return shopLocation.containsKey(newLocation); } + /** + * Get all Shops + * @return Array of all Shops + */ public static Shop[] getShops() { ArrayList shops = new ArrayList<>(); @@ -44,6 +61,11 @@ public class ShopUtils { return shops.toArray(new Shop[shops.size()]); } + /** + * Add a shop + * @param shop Shop to add + * @param addToDatabase Whether the shop should also be added to the database + */ public static void addShop(Shop shop, boolean addToDatabase) { InventoryHolder ih = shop.getChest().getInventory().getHolder(); @@ -63,6 +85,11 @@ public class ShopUtils { } + /** + * Remove a shop + * @param shop Shop to remove + * @param removeFromDatabase Whether the shop should also be removed from the database + */ public static void removeShop(Shop shop, boolean removeFromDatabase) { InventoryHolder ih = shop.getChest().getInventory().getHolder(); @@ -84,6 +111,11 @@ public class ShopUtils { plugin.getShopDatabase().removeShop(shop); } + /** + * Get the shop limits of a player + * @param p Player, whose shop limits should be returned + * @return The shop limits of the given player + */ public static int getShopLimit(Player p) { int limit = Config.default_limit; @@ -137,6 +169,11 @@ public class ShopUtils { return limit; } + /** + * Get the amount of shops of a player + * @param p Player, whose shops should be counted + * @return The amount of a shops a player has (if {@link Config#exclude_admin_shops} is true, admin shops won't be counted) + */ public static int getShopAmount(OfflinePlayer p) { float shopCount = 0; @@ -154,6 +191,10 @@ public class ShopUtils { return Math.round(shopCount); } + /** + * Reload the shops + * @return Amount of shops, which were reloaded + */ public static int reloadShops() { for (Shop shop : ShopUtils.getShops()) { ShopUtils.removeShop(shop, false); diff --git a/src/de/epiceric/shopchest/utils/UpdateChecker.java b/src/de/epiceric/shopchest/utils/UpdateChecker.java index 5afa653..8209c0e 100644 --- a/src/de/epiceric/shopchest/utils/UpdateChecker.java +++ b/src/de/epiceric/shopchest/utils/UpdateChecker.java @@ -10,15 +10,18 @@ import java.net.URLConnection; public class UpdateChecker { private ShopChest plugin; - private String url; private String version; private String link; - public UpdateChecker(ShopChest plugin, String url) { + public UpdateChecker(ShopChest plugin) { this.plugin = plugin; - this.url = url; } + /** + * Check if an update is needed + * + * @return {@link UpdateCheckerResult#TRUE} if an update is available, {@link UpdateCheckerResult#FALSE} of no update is needed and {@link UpdateCheckerResult#ERROR} if an error occurred + */ public UpdateCheckerResult updateNeeded() { try { URL url = new URL("http://textuploader.com/all1l/raw"); @@ -47,6 +50,10 @@ public class UpdateChecker { } } + /** + * Get the broadcast message + * @return A String Array of the lines of the broadcast message or null when no message is available + */ public String[] getBroadcast() { try { URL url = new URL("http://textuploader.com/5b51f/raw"); @@ -74,10 +81,16 @@ public class UpdateChecker { return null; } + /** + * @return Latest Version or null if no update is available + */ public String getVersion() { return version; } + /** + * @return Download Link of the latest version of null if no update is available + */ public String getLink() { return link; } @@ -85,7 +98,7 @@ public class UpdateChecker { public enum UpdateCheckerResult { TRUE, FALSE, - ERROR; + ERROR } diff --git a/src/de/epiceric/shopchest/utils/Utils.java b/src/de/epiceric/shopchest/utils/Utils.java index 3b44226..c9a1e7d 100644 --- a/src/de/epiceric/shopchest/utils/Utils.java +++ b/src/de/epiceric/shopchest/utils/Utils.java @@ -11,6 +11,13 @@ import java.util.ArrayList; public class Utils { + /** + * Gets the amount of items in an inventory + * + * @param inventory The inventory, in which the items are counted + * @param itemStack The items to count + * @return Amount of given items in the given inventory + */ public static int getAmount(Inventory inventory, ItemStack itemStack) { int amount = 0; @@ -42,32 +49,47 @@ public class Utils { return amount; } + /** + * @return The current server version with revision number (e.g. 1_9_R2, 1_10_R1) + */ public static String getServerVersion() { String packageName = Bukkit.getServer().getClass().getPackage().getName(); return packageName.substring(packageName.lastIndexOf('.') + 1); } + /** + * @return The major version of the server (e.g. 9 for 1.9.2, 10 for 1.10) + */ public static int getMajorVersion() { return Integer.valueOf(getServerVersion().split("_")[1]); } + /** + * Checks if a given String is a UUID + * @param string String to check + * @return Whether the string is a UUID + */ public static boolean isUUID(String string) { return string.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}"); } + /** + * Encodes an {@link ItemStack} in a Base64 String + * @param itemStack {@link ItemStack} to encode + * @return Base64 encoded String + */ public static String encode(ItemStack itemStack) { YamlConfiguration config = new YamlConfiguration(); config.set("i", itemStack); return new String(Base64.encodeBase64(config.saveToString().getBytes())); } - public static String toString(ItemStack itemStack) { - YamlConfiguration config = new YamlConfiguration(); - config.set("i", itemStack); - return config.saveToString(); - } - + /** + * Decodes an {@link ItemStack} from a Base64 String + * @param string Base64 encoded String to decode + * @return Decoded {@link ItemStack} + */ public static ItemStack decode(String string) { YamlConfiguration config = new YamlConfiguration(); try {