Automated code cleanup by IntelliJ IDEA

As I Switched from Eclipse to IntelliJ IDEA, I also had to add a few
entries to the .gitignore file.
This commit is contained in:
Eric 2016-05-28 15:47:57 +02:00
parent 5bb4169c80
commit 543da0682b
42 changed files with 3889 additions and 3658 deletions

3
.gitignore vendored
View File

@ -1,4 +1,7 @@
/bin/ /bin/
/out/
/.idea/
/.settings/ /.settings/
.classpath .classpath
.project .project
ShopChest.iml

View File

@ -1,17 +1,5 @@
package de.epiceric.shopchest; package de.epiceric.shopchest;
import java.lang.reflect.Method;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.interfaces.Utils; import de.epiceric.shopchest.interfaces.Utils;
@ -23,6 +11,18 @@ import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker; import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult; import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
import java.util.List;
public class Commands extends BukkitCommand { public class Commands extends BukkitCommand {
@ -38,8 +38,8 @@ public class Commands extends BukkitCommand {
public static void registerCommand(Command command, ShopChest plugin) throws ReflectiveOperationException { public static void registerCommand(Command command, ShopChest plugin) throws ReflectiveOperationException {
Method commandMap = plugin.getServer().getClass().getMethod("getCommandMap"); Method commandMap = plugin.getServer().getClass().getMethod("getCommandMap");
Object cmdmap = commandMap.invoke(plugin.getServer()); Object cmdmap = commandMap.invoke(plugin.getServer());
Method register = cmdmap.getClass().getMethod("register", String.class,Command.class); Method register = cmdmap.getClass().getMethod("register", String.class, Command.class);
register.invoke(cmdmap, command.getName(),command); register.invoke(cmdmap, command.getName(), command);
} }
@Override @Override
@ -65,7 +65,7 @@ public class Commands extends BukkitCommand {
p.sendMessage(Config.noPermission_createInfinite()); p.sendMessage(Config.noPermission_createInfinite());
return true; return true;
} }
} else if (args[4].equalsIgnoreCase("normal")){ } else if (args[4].equalsIgnoreCase("normal")) {
create(args, ShopType.NORMAL, p); create(args, ShopType.NORMAL, p);
return true; return true;
} else if (args[4].equalsIgnoreCase("admin")) { } else if (args[4].equalsIgnoreCase("admin")) {
@ -145,12 +145,23 @@ public class Commands extends BukkitCommand {
JsonBuilder jb; JsonBuilder jb;
switch (Utils.getVersion(plugin.getServer())) { switch (Utils.getVersion(plugin.getServer())) {
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)); break; case "v1_8_R1":
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)); break; jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion));
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)); break; break;
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)); break; case "v1_8_R2":
case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion)); break; jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion));
default: return; break;
case "v1_8_R3":
jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion));
break;
case "v1_9_R1":
jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion));
break;
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion));
break;
default:
return;
} }
jb.sendJson(player); jb.sendJson(player);

View File

@ -1,37 +1,16 @@
package de.epiceric.shopchest; package de.epiceric.shopchest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.lwc.LWCPlugin; import com.griefcraft.lwc.LWCPlugin;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.event.InteractShop; import de.epiceric.shopchest.event.*;
import de.epiceric.shopchest.event.ItemCustomNameListener; import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.event.NotifyUpdate;
import de.epiceric.shopchest.event.ProtectChest;
import de.epiceric.shopchest.event.RegenerateShopItem;
import de.epiceric.shopchest.event.RegenerateShopItemAfterRemove;
import de.epiceric.shopchest.event.UpdateHolograms;
import de.epiceric.shopchest.interfaces.Utils; import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.interfaces.utils.*; import de.epiceric.shopchest.interfaces.utils.*;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.sql.SQLite; import de.epiceric.shopchest.sql.SQLite;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.utils.Metrics; import de.epiceric.shopchest.utils.Metrics;
import de.epiceric.shopchest.utils.Metrics.Graph; import de.epiceric.shopchest.utils.Metrics.Graph;
import de.epiceric.shopchest.utils.Metrics.Plotter; import de.epiceric.shopchest.utils.Metrics.Plotter;
@ -40,30 +19,51 @@ import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult; import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class ShopChest extends JavaPlugin{ import java.io.*;
import java.util.ArrayList;
import java.util.logging.Logger;
private static ShopChest instance; public class ShopChest extends JavaPlugin {
public static Statement statement;
public static Logger logger; public static Logger logger;
public static Economy econ = null; public static Economy econ = null;
public static Permission perm = null; public static Permission perm = null;
public static LWC lwc = null; public static LWC lwc = null;
public static boolean lockette = false; public static boolean lockette = false;
public static SQLite sqlite; public static SQLite sqlite;
public static boolean isUpdateNeeded = false; public static boolean isUpdateNeeded = false;
public static String latestVersion = ""; public static String latestVersion = "";
public static String downloadLink = ""; public static String downloadLink = "";
public static String[] broadcast = null; public static String[] broadcast = null;
public static Utils utils; public static Utils utils;
private static ShopChest instance;
public static ShopChest getInstance() { public static ShopChest getInstance() {
return instance; return instance;
} }
public static void copy(InputStream in, File file) {
try {
OutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean setupEconomy() { private boolean setupEconomy() {
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
@ -74,14 +74,12 @@ public class ShopChest extends JavaPlugin{
return econ != null; return econ != null;
} }
private boolean setupPermissions() { private boolean setupPermissions() {
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class); RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
perm = rsp.getProvider(); perm = rsp.getProvider();
return perm != null; return perm != null;
} }
@Override @Override
public void onEnable() { public void onEnable() {
logger = getLogger(); logger = getLogger();
@ -92,7 +90,7 @@ public class ShopChest extends JavaPlugin{
return; return;
} }
if (!setupEconomy() ) { if (!setupEconomy()) {
logger.severe("Could not find any Vault dependency!"); logger.severe("Could not find any Vault dependency!");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
@ -159,11 +157,21 @@ public class ShopChest extends JavaPlugin{
switch (Utils.getVersion(getServer())) { switch (Utils.getVersion(getServer())) {
case "v1_8_R1": utils = new Utils_1_8_R1(); break; case "v1_8_R1":
case "v1_8_R2": utils = new Utils_1_8_R2(); break; utils = new Utils_1_8_R1();
case "v1_8_R3": utils = new Utils_1_8_R3(); break; break;
case "v1_9_R1": utils = new Utils_1_9_R1(); break; case "v1_8_R2":
case "v1_9_R2": utils = new Utils_1_9_R2(); break; utils = new Utils_1_8_R2();
break;
case "v1_8_R3":
utils = new Utils_1_8_R3();
break;
case "v1_9_R1":
utils = new Utils_1_9_R1();
break;
case "v1_9_R2":
utils = new Utils_1_9_R2();
break;
default: default:
logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!"); logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
@ -193,7 +201,7 @@ public class ShopChest extends JavaPlugin{
if (Config.enable_broadcast()) broadcast = uc.getBroadcast(); if (Config.enable_broadcast()) broadcast = uc.getBroadcast();
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.checking_update()); Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.checking_update());
if(result == UpdateCheckerResult.TRUE) { if (result == UpdateCheckerResult.TRUE) {
latestVersion = uc.getVersion(); latestVersion = uc.getVersion();
downloadLink = uc.getLink(); downloadLink = uc.getLink();
isUpdateNeeded = true; isUpdateNeeded = true;
@ -203,12 +211,23 @@ public class ShopChest extends JavaPlugin{
if (p.isOp() || perm.has(p, "shopchest.notification.update")) { if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb; JsonBuilder jb;
switch (Utils.getVersion(getServer())) { switch (Utils.getVersion(getServer())) {
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(latestVersion)); break; case "v1_8_R1":
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(latestVersion)); break; jb = new JsonBuilder_1_8_R1(Config.update_available(latestVersion));
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(latestVersion)); break; break;
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion)); break; case "v1_8_R2":
case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(latestVersion)); break; jb = new JsonBuilder_1_8_R2(Config.update_available(latestVersion));
default: return; break;
case "v1_8_R3":
jb = new JsonBuilder_1_8_R3(Config.update_available(latestVersion));
break;
case "v1_9_R1":
jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion));
break;
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(Config.update_available(latestVersion));
break;
default:
return;
} }
jb.sendJson(p); jb.sendJson(p);
} }
@ -245,7 +264,11 @@ public class ShopChest extends JavaPlugin{
File itemNamesFile = new File(getDataFolder(), "item_names.txt"); File itemNamesFile = new File(getDataFolder(), "item_names.txt");
if (!itemNamesFile.exists()) if (!itemNamesFile.exists())
try {itemNamesFile.createNewFile();} catch (IOException e) {e.printStackTrace();} try {
itemNamesFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
copy(getResource("item_names.txt"), itemNamesFile); copy(getResource("item_names.txt"), itemNamesFile);
@ -265,10 +288,10 @@ public class ShopChest extends JavaPlugin{
getServer().getPluginManager().registerEvents(new ProtectChest(), this); getServer().getPluginManager().registerEvents(new ProtectChest(), this);
getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this); getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this);
if (getServer().getPluginManager().getPlugin("ClearLag") != null) getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this); if (getServer().getPluginManager().getPlugin("ClearLag") != null)
getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this);
} }
@Override @Override
public void onDisable() { public void onDisable() {
utils.removeShops(); utils.removeShops();
@ -295,22 +318,5 @@ public class ShopChest extends JavaPlugin{
logger.info("Initialized " + String.valueOf(count) + " Shops"); logger.info("Initialized " + String.valueOf(count) + " Shops");
} }
public static void copy(InputStream in, File file) {
try {
OutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while((len=in.read(buf))>0){
out.write(buf,0,len);
}
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} }

View File

@ -1,79 +1,251 @@
package de.epiceric.shopchest.config; package de.epiceric.shopchest.config;
import de.epiceric.shopchest.ShopChest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import de.epiceric.shopchest.ShopChest;
public class Config { public class Config {
private static ShopChest plugin = ShopChest.getInstance(); private static ShopChest plugin = ShopChest.getInstance();
public static Set<String> minimum_prices() {return (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true);} public static Set<String> minimum_prices() {
public static Set<String> shopLimits_group() {return (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);} return (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true);
public static Set<String> shopLimits_player() {return (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);} }
public static List<String> blacklist() {return (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList<String>() : plugin.getConfig().getStringList("blacklist");}; public static Set<String> shopLimits_group() {
return (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);
}
public static boolean buy_greater_or_equal_sell() {return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");} public static Set<String> shopLimits_player() {
public static boolean hopper_protection() {return plugin.getConfig().getBoolean("hopper-protection");} return (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);
public static boolean explosion_protection() {return plugin.getConfig().getBoolean("explosion-protection)");} }
public static boolean enable_broadcast() {return plugin.getConfig().getBoolean("enable-broadcast");}
public static double maximal_distance() {return plugin.getConfig().getDouble("maximal-distance");} public static List<String> blacklist() {
public static int default_limit() {return plugin.getConfig().getInt("shop-limits.default");} return (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList<String>() : plugin.getConfig().getStringList("blacklist");
}
public static String main_command_name() { return plugin.getConfig().getString("main-command-name");} public static boolean buy_greater_or_equal_sell() {
public static String currency_symbol() { return plugin.getConfig().getString("currency-symbol").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");
public static String shop_created() { return plugin.getConfig().getString("messages.shop-created").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String chest_already_shop() { return plugin.getConfig().getString("messages.chest-already-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String shop_removed() { return plugin.getConfig().getString("messages.shop-removed").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static boolean hopper_protection() {
public static String chest_no_shop() { return plugin.getConfig().getString("messages.chest-no-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getBoolean("hopper-protection");
public static String block_no_chest() { return plugin.getConfig().getString("messages.block-no-chest").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String not_enough_inventory_space() { return plugin.getConfig().getString("messages.not-enough-inventory-space").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String chest_not_enough_inventory_space() { return plugin.getConfig().getString("messages.chest-not-enough-inventory-space").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static boolean explosion_protection() {
public static String not_enough_money() { return plugin.getConfig().getString("messages.not-enough-money").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getBoolean("explosion-protection)");
public static String not_enough_items() { return plugin.getConfig().getString("messages.not-enough-items").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String vendor_not_enough_money() { return plugin.getConfig().getString("messages.vendor-not-enough-money").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String out_of_stock() { return plugin.getConfig().getString("messages.out-of-stock").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static boolean enable_broadcast() {
public static String amount_and_price_not_number() { return plugin.getConfig().getString("messages.amount-and-price-not-number").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getBoolean("enable-broadcast");
public static String no_item_in_hand() { return plugin.getConfig().getString("messages.no-item-in-hand").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String click_chest_to_create() { return plugin.getConfig().getString("messages.click-chest-to-create-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String click_chest_to_remove() { return plugin.getConfig().getString("messages.click-chest-to-remove-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static double maximal_distance() {
public static String click_chest_for_info() { return plugin.getConfig().getString("messages.click-chest-for-info").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getDouble("maximal-distance");
public static String cmdDesc_create() { return plugin.getConfig().getString("messages.command-description.create").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String cmdDesc_remove() { return plugin.getConfig().getString("messages.command-description.remove").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String cmdDesc_info() { return plugin.getConfig().getString("messages.command-description.info").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static int default_limit() {
public static String cmdDesc_reload() { return plugin.getConfig().getString("messages.command-description.reload").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getInt("shop-limits.default");
public static String cmdDesc_update() { return plugin.getConfig().getString("messages.command-description.update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String cmdDesc_limits() { return plugin.getConfig().getString("messages.command-description.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String shopInfo_isInfinite() { return plugin.getConfig().getString("messages.shop-info.is-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}; public static String main_command_name() {
public static String shopInfo_isNormal() { return plugin.getConfig().getString("messages.shop-info.is-normal").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}; return plugin.getConfig().getString("main-command-name");
public static String shopInfo_isAdmin() { return plugin.getConfig().getString("messages.shop-info.is-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}; }
public static String noPermission_create() { return plugin.getConfig().getString("messages.no-permission.create").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String noPermission_createInfinite() { return plugin.getConfig().getString("messages.no-permission.create-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String currency_symbol() {
public static String noPermission_createAdmin() { return plugin.getConfig().getString("messages.no-permission.create-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getString("currency-symbol").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
public static String noPermission_openOthers() { return plugin.getConfig().getString("messages.no-permission.open-others").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String noPermission_removeOthers() { return plugin.getConfig().getString("messages.no-permission.remove-others").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String noPermission_buy() { return plugin.getConfig().getString("messages.no-permission.buy").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String shop_created() {
public static String noPermission_sell() { return plugin.getConfig().getString("messages.no-permission.sell").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getString("messages.shop-created").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
public static String noPermission_reload() { return plugin.getConfig().getString("messages.no-permission.reload").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String noPermission_update() { return plugin.getConfig().getString("messages.no-permission.update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String noPermission_limits() { return plugin.getConfig().getString("messages.no-permission.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String chest_already_shop() {
public static String cannot_break_shop() { return plugin.getConfig().getString("messages.cannot-break-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getString("messages.chest-already-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
public static String cannot_sell_broken_item() { return plugin.getConfig().getString("messages.cannot-sell-broken-item").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String disabled() {return plugin.getConfig().getString("messages.shop-info.disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String buy_and_sell_disabled() {return plugin.getConfig().getString("messages.buy-and-sell-disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String shop_removed() {
public static String selling_disabled() {return plugin.getConfig().getString("messages.selling-disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getString("messages.shop-removed").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
public static String buying_disabled() {return plugin.getConfig().getString("messages.buying-disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String checking_update() {return plugin.getConfig().getString("messages.update.checking").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String no_new_update() {return plugin.getConfig().getString("messages.update.no-update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String chest_no_shop() {
public static String click_to_download() {return plugin.getConfig().getString("messages.update.click-to-download").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} return plugin.getConfig().getString("messages.chest-no-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
public static String update_check_error() {return plugin.getConfig().getString("messages.update.error").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} }
public static String cannot_sell_item() {return plugin.getConfig().getString("messages.cannot-sell-item").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
public static String none() {return plugin.getConfig().getString("messages.shop-info.none").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String block_no_chest() {
return plugin.getConfig().getString("messages.block-no-chest").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String not_enough_inventory_space() {
return plugin.getConfig().getString("messages.not-enough-inventory-space").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String chest_not_enough_inventory_space() {
return plugin.getConfig().getString("messages.chest-not-enough-inventory-space").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String not_enough_money() {
return plugin.getConfig().getString("messages.not-enough-money").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String not_enough_items() {
return plugin.getConfig().getString("messages.not-enough-items").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String vendor_not_enough_money() {
return plugin.getConfig().getString("messages.vendor-not-enough-money").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String out_of_stock() {
return plugin.getConfig().getString("messages.out-of-stock").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String amount_and_price_not_number() {
return plugin.getConfig().getString("messages.amount-and-price-not-number").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String no_item_in_hand() {
return plugin.getConfig().getString("messages.no-item-in-hand").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String click_chest_to_create() {
return plugin.getConfig().getString("messages.click-chest-to-create-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String click_chest_to_remove() {
return plugin.getConfig().getString("messages.click-chest-to-remove-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String click_chest_for_info() {
return plugin.getConfig().getString("messages.click-chest-for-info").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cmdDesc_create() {
return plugin.getConfig().getString("messages.command-description.create").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cmdDesc_remove() {
return plugin.getConfig().getString("messages.command-description.remove").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cmdDesc_info() {
return plugin.getConfig().getString("messages.command-description.info").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cmdDesc_reload() {
return plugin.getConfig().getString("messages.command-description.reload").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cmdDesc_update() {
return plugin.getConfig().getString("messages.command-description.update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cmdDesc_limits() {
return plugin.getConfig().getString("messages.command-description.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_isInfinite() {
return plugin.getConfig().getString("messages.shop-info.is-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_isNormal() {
return plugin.getConfig().getString("messages.shop-info.is-normal").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_isAdmin() {
return plugin.getConfig().getString("messages.shop-info.is-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_create() {
return plugin.getConfig().getString("messages.no-permission.create").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_createInfinite() {
return plugin.getConfig().getString("messages.no-permission.create-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_createAdmin() {
return plugin.getConfig().getString("messages.no-permission.create-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_openOthers() {
return plugin.getConfig().getString("messages.no-permission.open-others").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_removeOthers() {
return plugin.getConfig().getString("messages.no-permission.remove-others").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_buy() {
return plugin.getConfig().getString("messages.no-permission.buy").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_sell() {
return plugin.getConfig().getString("messages.no-permission.sell").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_reload() {
return plugin.getConfig().getString("messages.no-permission.reload").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_update() {
return plugin.getConfig().getString("messages.no-permission.update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_limits() {
return plugin.getConfig().getString("messages.no-permission.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cannot_break_shop() {
return plugin.getConfig().getString("messages.cannot-break-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cannot_sell_broken_item() {
return plugin.getConfig().getString("messages.cannot-sell-broken-item").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String disabled() {
return plugin.getConfig().getString("messages.shop-info.disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String buy_and_sell_disabled() {
return plugin.getConfig().getString("messages.buy-and-sell-disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String selling_disabled() {
return plugin.getConfig().getString("messages.selling-disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String buying_disabled() {
return plugin.getConfig().getString("messages.buying-disabled").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String checking_update() {
return plugin.getConfig().getString("messages.update.checking").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String no_new_update() {
return plugin.getConfig().getString("messages.update.no-update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String click_to_download() {
return plugin.getConfig().getString("messages.update.click-to-download").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String update_check_error() {
return plugin.getConfig().getString("messages.update.error").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String cannot_sell_item() {
return plugin.getConfig().getString("messages.cannot-sell-item").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String none() {
return plugin.getConfig().getString("messages.shop-info.none").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String limit_reached(int limit) { public static String limit_reached(int limit) {
return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");

View File

@ -1,8 +1,16 @@
package de.epiceric.shopchest.event; package de.epiceric.shopchest.event;
import java.util.HashMap; import com.griefcraft.model.Protection;
import java.util.Map; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.sql.SQLite;
import de.epiceric.shopchest.utils.*;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -20,24 +28,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.yi.acru.bukkit.Lockette.Lockette; import org.yi.acru.bukkit.Lockette.Lockette;
import com.griefcraft.model.Protection; import java.util.HashMap;
import java.util.Map;
import de.epiceric.shopchest.ShopChest; public class InteractShop implements Listener {
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.sql.SQLite;
import de.epiceric.shopchest.utils.ArrowEffectNames;
import de.epiceric.shopchest.utils.ClickType;
import de.epiceric.shopchest.utils.EnchantmentNames;
import de.epiceric.shopchest.utils.ItemNames;
import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.interfaces.Utils;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.permission.Permission;
public class InteractShop implements Listener{
private ShopChest plugin; private ShopChest plugin;
private Permission perm = ShopChest.perm; private Permission perm = ShopChest.perm;
@ -194,7 +188,6 @@ public class InteractShop implements Listener{
} }
} else if (e.getAction() == Action.LEFT_CLICK_BLOCK) { } else if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (ShopUtils.isShop(b.getLocation())) { if (ShopUtils.isShop(b.getLocation())) {
@ -402,13 +395,15 @@ public class InteractShop implements Listener{
if (leftAmount > 0) { if (leftAmount > 0) {
ItemStack boughtProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability()); ItemStack boughtProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
boughtProduct.setItemMeta(product.clone().getItemMeta()); boughtProduct.setItemMeta(product.clone().getItemMeta());
if (shop.getShopType() == ShopType.NORMAL) c.getInventory().removeItem(boughtProduct); if (shop.getShopType() == ShopType.NORMAL)
c.getInventory().removeItem(boughtProduct);
if (slot != 40) { if (slot != 40) {
inventory.addItem(boughtProduct); inventory.addItem(boughtProduct);
} else { } else {
ItemStack is = new ItemStack(boughtProduct); ItemStack is = new ItemStack(boughtProduct);
int amount = 0; int amount = 0;
if (inventory.getItem(40) != null) amount = inventory.getItem(40).getAmount(); if (inventory.getItem(40) != null)
amount = inventory.getItem(40).getAmount();
is.setAmount(amount + 1); is.setAmount(amount + 1);
inventory.setItem(40, is); inventory.setItem(40, is);
} }
@ -416,7 +411,8 @@ public class InteractShop implements Listener{
leftAmount--; leftAmount--;
} else if (leftAmount == 0) { } else if (leftAmount == 0) {
executor.sendMessage(Config.buy_success(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), shop.getVendor().getName())); executor.sendMessage(Config.buy_success(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), shop.getVendor().getName()));
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_bought(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName())); if (shop.getVendor().isOnline())
shop.getVendor().getPlayer().sendMessage(Config.someone_bought(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName()));
return; return;
} }
} }
@ -530,7 +526,8 @@ public class InteractShop implements Listener{
executor.updateInventory(); executor.updateInventory();
} }
executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName())); executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName()));
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), executor.getName())); if (shop.getVendor().isOnline())
shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), executor.getName()));
} else { } else {
executor.sendMessage(Config.error_occurred(r2.errorMessage)); executor.sendMessage(Config.error_occurred(r2.errorMessage));
} }
@ -581,7 +578,8 @@ public class InteractShop implements Listener{
executor.updateInventory(); executor.updateInventory();
} }
executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName())); executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName()));
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName())); if (shop.getVendor().isOnline())
shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName()));
} else { } else {
executor.sendMessage(Config.error_occurred(r2.errorMessage)); executor.sendMessage(Config.error_occurred(r2.errorMessage));
} }

View File

@ -7,7 +7,7 @@ import org.bukkit.event.entity.ItemSpawnEvent;
public class ItemCustomNameListener implements Listener { public class ItemCustomNameListener implements Listener {
@EventHandler(priority=EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onItemSpawn(ItemSpawnEvent e) { public void onItemSpawn(ItemSpawnEvent e) {
if (e.getEntity().hasMetadata("shopItem")) { if (e.getEntity().hasMetadata("shopItem")) {
e.getEntity().setCustomNameVisible(false); e.getEntity().setCustomNameVisible(false);

View File

@ -1,22 +1,22 @@
package de.epiceric.shopchest.event; package de.epiceric.shopchest.event;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.milkbowl.vault.permission.Permission;
public class NotifyUpdate implements Listener { public class NotifyUpdate implements Listener {
private Permission perm = ShopChest.perm; private Permission perm = ShopChest.perm;
public NotifyUpdate() {} public NotifyUpdate() {
}
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
@ -28,12 +28,23 @@ public class NotifyUpdate implements Listener {
JsonBuilder jb; JsonBuilder jb;
switch (Utils.getVersion(ShopChest.getInstance().getServer())) { switch (Utils.getVersion(ShopChest.getInstance().getServer())) {
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)); break; case "v1_8_R1":
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)); break; jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion));
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)); break; break;
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)); break; case "v1_8_R2":
case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion)); break; jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion));
default: return; break;
case "v1_8_R3":
jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion));
break;
case "v1_9_R1":
jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion));
break;
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion));
break;
default:
return;
} }
jb.sendJson(p); jb.sendJson(p);
} }

View File

@ -1,7 +1,9 @@
package de.epiceric.shopchest.event; package de.epiceric.shopchest.event;
import java.util.ArrayList; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
@ -17,14 +19,12 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import de.epiceric.shopchest.ShopChest; import java.util.ArrayList;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils;
public class ProtectChest implements Listener { public class ProtectChest implements Listener {
public ProtectChest() {} public ProtectChest() {
}
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent e) { public void onBlockBreak(BlockBreakEvent e) {

View File

@ -12,7 +12,8 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
public class RegenerateShopItem implements Listener { public class RegenerateShopItem implements Listener {
public RegenerateShopItem() {} public RegenerateShopItem() {
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onItemDespawn(ItemDespawnEvent e) { public void onItemDespawn(ItemDespawnEvent e) {

View File

@ -1,10 +1,10 @@
package de.epiceric.shopchest.event; package de.epiceric.shopchest.event;
import de.epiceric.shopchest.ShopChest;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import de.epiceric.shopchest.ShopChest;
public class RegenerateShopItemAfterRemove implements Listener { public class RegenerateShopItemAfterRemove implements Listener {

View File

@ -1,18 +1,18 @@
package de.epiceric.shopchest.event; package de.epiceric.shopchest.event;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import de.epiceric.shopchest.config.Config; public class UpdateHolograms implements Listener {
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils;
public class UpdateHolograms implements Listener{ public UpdateHolograms() {
}
public UpdateHolograms() {}
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent e) {

View File

@ -1,17 +1,21 @@
package de.epiceric.shopchest.interfaces; package de.epiceric.shopchest.interfaces;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import java.util.List;
public interface Hologram { public interface Hologram {
public Location getLocation(); public Location getLocation();
public List<?> getEntities(); public List<?> getEntities();
public void showPlayer(OfflinePlayer p); public void showPlayer(OfflinePlayer p);
public void hidePlayer(OfflinePlayer p); public void hidePlayer(OfflinePlayer p);
public boolean isVisible(OfflinePlayer p); public boolean isVisible(OfflinePlayer p);
} }

View File

@ -5,6 +5,22 @@ import org.bukkit.entity.Player;
public interface JsonBuilder { public interface JsonBuilder {
public JsonBuilder parse(String text);
public JsonBuilder withText(String text);
public JsonBuilder withColor(ChatColor color);
public JsonBuilder withColor(String color);
public JsonBuilder withClickEvent(ClickAction action, String value);
public JsonBuilder withHoverEvent(HoverAction action, String value);
public String toString();
public void sendJson(Player p);
public enum ClickAction { public enum ClickAction {
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL
} }
@ -13,13 +29,4 @@ public interface JsonBuilder {
SHOW_TEXT SHOW_TEXT
} }
public JsonBuilder parse(String text);
public JsonBuilder withText(String text);
public JsonBuilder withColor(ChatColor color);
public JsonBuilder withColor(String color);
public JsonBuilder withClickEvent(ClickAction action, String value);
public JsonBuilder withHoverEvent(HoverAction action, String value);
public String toString();
public void sendJson(Player p);
} }

View File

@ -11,10 +11,6 @@ import org.bukkit.inventory.meta.ItemMeta;
public abstract class Utils { public abstract class Utils {
public abstract void reload(Player p);
public abstract void removeShops();
public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) { public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) {
ItemStack[] items = inventory.getContents(); ItemStack[] items = inventory.getContents();
int amount = 0; int amount = 0;
@ -59,6 +55,9 @@ public abstract class Utils {
return config.getItemStack("i", null); return config.getItemStack("i", null);
} }
public abstract void reload(Player p);
public abstract void removeShops();
} }

View File

@ -1,27 +1,25 @@
package de.epiceric.shopchest.interfaces.hologram; package de.epiceric.shopchest.interfaces.hologram;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_8_R1.EntityArmorStand; import net.minecraft.server.v1_8_R1.EntityArmorStand;
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_8_R1 implements Hologram { public class Hologram_1_8_R1 implements Hologram {
int count;
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>(); private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
private String[] text; private String[] text;
private Location location; private Location location;
private double DISTANCE = 0.25D; private double DISTANCE = 0.25D;
int count;
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>(); private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
public Hologram_1_8_R1(String[] text, Location location) { public Hologram_1_8_R1(String[] text, Location location) {
@ -31,7 +29,7 @@ public class Hologram_1_8_R1 implements Hologram {
} }
public Hologram_1_8_R1(String text, Location location) { public Hologram_1_8_R1(String text, Location location) {
this.text = new String[] {text}; this.text = new String[]{text};
this.location = location; this.location = location;
create(); create();
} }
@ -63,12 +61,13 @@ public class Hologram_1_8_R1 implements Hologram {
} }
public boolean isVisible(OfflinePlayer p) { public boolean isVisible(OfflinePlayer p) {
if (visible.containsKey(p)) return visible.get(p); else return false; if (visible.containsKey(p)) return visible.get(p);
else return false;
} }
private void create() { private void create() {
for (String text : this.text) { for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ()); EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
entity.setCustomName(text); entity.setCustomName(text);
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
entity.setInvisible(true); entity.setInvisible(true);

View File

@ -1,27 +1,25 @@
package de.epiceric.shopchest.interfaces.hologram; package de.epiceric.shopchest.interfaces.hologram;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_8_R2.EntityArmorStand; import net.minecraft.server.v1_8_R2.EntityArmorStand;
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_8_R2 implements Hologram { public class Hologram_1_8_R2 implements Hologram {
int count;
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>(); private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
private String[] text; private String[] text;
private Location location; private Location location;
private double DISTANCE = 0.25D; private double DISTANCE = 0.25D;
int count;
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>(); private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
public Hologram_1_8_R2(String[] text, Location location) { public Hologram_1_8_R2(String[] text, Location location) {
@ -31,7 +29,7 @@ public class Hologram_1_8_R2 implements Hologram {
} }
public Hologram_1_8_R2(String text, Location location) { public Hologram_1_8_R2(String text, Location location) {
this.text = new String[] {text}; this.text = new String[]{text};
this.location = location; this.location = location;
create(); create();
} }
@ -63,12 +61,13 @@ public class Hologram_1_8_R2 implements Hologram {
} }
public boolean isVisible(OfflinePlayer p) { public boolean isVisible(OfflinePlayer p) {
if (visible.containsKey(p)) return visible.get(p); else return false; if (visible.containsKey(p)) return visible.get(p);
else return false;
} }
private void create() { private void create() {
for (String text : this.text) { for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ()); EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
entity.setCustomName(text); entity.setCustomName(text);
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
entity.setInvisible(true); entity.setInvisible(true);

View File

@ -1,27 +1,25 @@
package de.epiceric.shopchest.interfaces.hologram; package de.epiceric.shopchest.interfaces.hologram;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_8_R3.EntityArmorStand; import net.minecraft.server.v1_8_R3.EntityArmorStand;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_8_R3 implements Hologram { public class Hologram_1_8_R3 implements Hologram {
int count;
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>(); private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
private String[] text; private String[] text;
private Location location; private Location location;
private double DISTANCE = 0.25D; private double DISTANCE = 0.25D;
int count;
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>(); private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
public Hologram_1_8_R3(String[] text, Location location) { public Hologram_1_8_R3(String[] text, Location location) {
@ -31,7 +29,7 @@ public class Hologram_1_8_R3 implements Hologram {
} }
public Hologram_1_8_R3(String text, Location location) { public Hologram_1_8_R3(String text, Location location) {
this.text = new String[] {text}; this.text = new String[]{text};
this.location = location; this.location = location;
create(); create();
} }
@ -63,12 +61,13 @@ public class Hologram_1_8_R3 implements Hologram {
} }
public boolean isVisible(OfflinePlayer p) { public boolean isVisible(OfflinePlayer p) {
if (visible.containsKey(p)) return visible.get(p); else return false; if (visible.containsKey(p)) return visible.get(p);
else return false;
} }
private void create() { private void create() {
for (String text : this.text) { for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ()); EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
entity.setCustomName(text); entity.setCustomName(text);
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
entity.setInvisible(true); entity.setInvisible(true);

View File

@ -1,27 +1,25 @@
package de.epiceric.shopchest.interfaces.hologram; package de.epiceric.shopchest.interfaces.hologram;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_9_R1.EntityArmorStand; import net.minecraft.server.v1_9_R1.EntityArmorStand;
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_9_R1 implements Hologram { public class Hologram_1_9_R1 implements Hologram {
int count;
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>(); private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
private String[] text; private String[] text;
private Location location; private Location location;
private double DISTANCE = 0.25D; private double DISTANCE = 0.25D;
int count;
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>(); private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
public Hologram_1_9_R1(String[] text, Location location) { public Hologram_1_9_R1(String[] text, Location location) {
@ -31,7 +29,7 @@ public class Hologram_1_9_R1 implements Hologram {
} }
public Hologram_1_9_R1(String text, Location location) { public Hologram_1_9_R1(String text, Location location) {
this.text = new String[] {text}; this.text = new String[]{text};
this.location = location; this.location = location;
create(); create();
} }
@ -63,12 +61,13 @@ public class Hologram_1_9_R1 implements Hologram {
} }
public boolean isVisible(OfflinePlayer p) { public boolean isVisible(OfflinePlayer p) {
if (visible.containsKey(p)) return visible.get(p); else return false; if (visible.containsKey(p)) return visible.get(p);
else return false;
} }
private void create() { private void create() {
for (String text : this.text) { for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ()); EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
entity.setCustomName(text); entity.setCustomName(text);
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
entity.setInvisible(true); entity.setInvisible(true);

View File

@ -1,27 +1,25 @@
package de.epiceric.shopchest.interfaces.hologram; package de.epiceric.shopchest.interfaces.hologram;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_9_R2.EntityArmorStand; import net.minecraft.server.v1_9_R2.EntityArmorStand;
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_9_R2.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_9_R2.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_9_R2 implements Hologram { public class Hologram_1_9_R2 implements Hologram {
int count;
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>(); private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
private String[] text; private String[] text;
private Location location; private Location location;
private double DISTANCE = 0.25D; private double DISTANCE = 0.25D;
int count;
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>(); private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
public Hologram_1_9_R2(String[] text, Location location) { public Hologram_1_9_R2(String[] text, Location location) {
@ -31,7 +29,7 @@ public class Hologram_1_9_R2 implements Hologram {
} }
public Hologram_1_9_R2(String text, Location location) { public Hologram_1_9_R2(String text, Location location) {
this.text = new String[] {text}; this.text = new String[]{text};
this.location = location; this.location = location;
create(); create();
} }
@ -63,12 +61,13 @@ public class Hologram_1_9_R2 implements Hologram {
} }
public boolean isVisible(OfflinePlayer p) { public boolean isVisible(OfflinePlayer p) {
if (visible.containsKey(p)) return visible.get(p); else return false; if (visible.containsKey(p)) return visible.get(p);
else return false;
} }
private void create() { private void create() {
for (String text : this.text) { for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ()); EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
entity.setCustomName(text); entity.setCustomName(text);
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
entity.setInvisible(true); entity.setInvisible(true);

View File

@ -1,18 +1,17 @@
package de.epiceric.shopchest.interfaces.jsonbuilder; package de.epiceric.shopchest.interfaces.jsonbuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.minecraft.server.v1_8_R1.ChatSerializer; import net.minecraft.server.v1_8_R1.ChatSerializer;
import net.minecraft.server.v1_8_R1.PacketPlayOutChat; import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_8_R1 implements JsonBuilder { public class JsonBuilder_1_8_R1 implements JsonBuilder {
@ -23,26 +22,27 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder {
public JsonBuilder_1_8_R1(String... text) { public JsonBuilder_1_8_R1(String... text) {
for(String extra : text) for (String extra : text)
parse(extra); parse(extra);
} }
@Override @Override
public JsonBuilder_1_8_R1 parse(String text) { public JsonBuilder_1_8_R1 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; String regex = "[&<EFBFBD>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1"); text = text.replaceAll(regex, "<EFBFBD>$1");
if(!Pattern.compile(regex).matcher(text).find()) { if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this; return this;
} }
String[] words = text.split(regex); String[] words = text.split(regex);
int index = words[0].length(); int index = words[0].length();
for(String word : words) { for (String word : words) {
try { try {
if(index != words[0].length()) if (index != words[0].length())
withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
} catch(Exception e){} } catch (Exception e) {
}
index += word.length() + 2; index += word.length() + 2;
} }
return this; return this;
@ -63,7 +63,7 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder {
@Override @Override
public JsonBuilder_1_8_R1 withColor(String color) { public JsonBuilder_1_8_R1 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim(); while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color)); withColor(ChatColor.getByChar(color));
return this; return this;
} }
@ -85,16 +85,17 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder {
private void addSegment(String segment) { private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1); String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1) lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}"; + "," + segment + "}";
extras.remove(extras.size() - 1); extras.remove(extras.size() - 1);
extras.add(lastText); extras.add(lastText);
} }
@Override @Override
public String toString() { public String toString() {
if(extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0); if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":["; String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);; extras.remove(0);
;
for (String extra : extras) for (String extra : extras)
text = text + extra + ","; text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}"; text = text.substring(0, text.length() - 1) + "]}";
@ -108,4 +109,4 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder {
} }
} }

View File

@ -1,18 +1,17 @@
package de.epiceric.shopchest.interfaces.jsonbuilder; package de.epiceric.shopchest.interfaces.jsonbuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R2.PacketPlayOutChat; import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_8_R2 implements JsonBuilder { public class JsonBuilder_1_8_R2 implements JsonBuilder {
@ -23,26 +22,27 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder {
public JsonBuilder_1_8_R2(String... text) { public JsonBuilder_1_8_R2(String... text) {
for(String extra : text) for (String extra : text)
parse(extra); parse(extra);
} }
@Override @Override
public JsonBuilder_1_8_R2 parse(String text) { public JsonBuilder_1_8_R2 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; String regex = "[&<EFBFBD>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1"); text = text.replaceAll(regex, "<EFBFBD>$1");
if(!Pattern.compile(regex).matcher(text).find()) { if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this; return this;
} }
String[] words = text.split(regex); String[] words = text.split(regex);
int index = words[0].length(); int index = words[0].length();
for(String word : words) { for (String word : words) {
try { try {
if(index != words[0].length()) if (index != words[0].length())
withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
} catch(Exception e){} } catch (Exception e) {
}
index += word.length() + 2; index += word.length() + 2;
} }
return this; return this;
@ -63,7 +63,7 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder {
@Override @Override
public JsonBuilder_1_8_R2 withColor(String color) { public JsonBuilder_1_8_R2 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim(); while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color)); withColor(ChatColor.getByChar(color));
return this; return this;
} }
@ -85,16 +85,17 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder {
private void addSegment(String segment) { private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1); String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1) lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}"; + "," + segment + "}";
extras.remove(extras.size() - 1); extras.remove(extras.size() - 1);
extras.add(lastText); extras.add(lastText);
} }
@Override @Override
public String toString() { public String toString() {
if(extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0); if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":["; String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);; extras.remove(0);
;
for (String extra : extras) for (String extra : extras)
text = text + extra + ","; text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}"; text = text.substring(0, text.length() - 1) + "]}";
@ -108,4 +109,4 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder {
} }
} }

View File

@ -1,18 +1,17 @@
package de.epiceric.shopchest.interfaces.jsonbuilder; package de.epiceric.shopchest.interfaces.jsonbuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat; import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_8_R3 implements JsonBuilder { public class JsonBuilder_1_8_R3 implements JsonBuilder {
@ -23,26 +22,27 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder {
public JsonBuilder_1_8_R3(String... text) { public JsonBuilder_1_8_R3(String... text) {
for(String extra : text) for (String extra : text)
parse(extra); parse(extra);
} }
@Override @Override
public JsonBuilder_1_8_R3 parse(String text) { public JsonBuilder_1_8_R3 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; String regex = "[&<EFBFBD>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1"); text = text.replaceAll(regex, "<EFBFBD>$1");
if(!Pattern.compile(regex).matcher(text).find()) { if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this; return this;
} }
String[] words = text.split(regex); String[] words = text.split(regex);
int index = words[0].length(); int index = words[0].length();
for(String word : words) { for (String word : words) {
try { try {
if(index != words[0].length()) if (index != words[0].length())
withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
} catch(Exception e){} } catch (Exception e) {
}
index += word.length() + 2; index += word.length() + 2;
} }
return this; return this;
@ -63,7 +63,7 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder {
@Override @Override
public JsonBuilder_1_8_R3 withColor(String color) { public JsonBuilder_1_8_R3 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim(); while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color)); withColor(ChatColor.getByChar(color));
return this; return this;
} }
@ -85,16 +85,17 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder {
private void addSegment(String segment) { private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1); String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1) lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}"; + "," + segment + "}";
extras.remove(extras.size() - 1); extras.remove(extras.size() - 1);
extras.add(lastText); extras.add(lastText);
} }
@Override @Override
public String toString() { public String toString() {
if(extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0); if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":["; String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);; extras.remove(0);
;
for (String extra : extras) for (String extra : extras)
text = text + extra + ","; text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}"; text = text.substring(0, text.length() - 1) + "]}";
@ -108,4 +109,4 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder {
} }
} }

View File

@ -1,18 +1,17 @@
package de.epiceric.shopchest.interfaces.jsonbuilder; package de.epiceric.shopchest.interfaces.jsonbuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutChat; import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_9_R1 implements JsonBuilder { public class JsonBuilder_1_9_R1 implements JsonBuilder {
@ -23,26 +22,27 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder {
public JsonBuilder_1_9_R1(String... text) { public JsonBuilder_1_9_R1(String... text) {
for(String extra : text) for (String extra : text)
parse(extra); parse(extra);
} }
@Override @Override
public JsonBuilder_1_9_R1 parse(String text) { public JsonBuilder_1_9_R1 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; String regex = "[&<EFBFBD>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1"); text = text.replaceAll(regex, "<EFBFBD>$1");
if(!Pattern.compile(regex).matcher(text).find()) { if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this; return this;
} }
String[] words = text.split(regex); String[] words = text.split(regex);
int index = words[0].length(); int index = words[0].length();
for(String word : words) { for (String word : words) {
try { try {
if(index != words[0].length()) if (index != words[0].length())
withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
} catch(Exception e){} } catch (Exception e) {
}
index += word.length() + 2; index += word.length() + 2;
} }
return this; return this;
@ -63,7 +63,7 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder {
@Override @Override
public JsonBuilder_1_9_R1 withColor(String color) { public JsonBuilder_1_9_R1 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim(); while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color)); withColor(ChatColor.getByChar(color));
return this; return this;
} }
@ -85,16 +85,17 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder {
private void addSegment(String segment) { private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1); String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1) lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}"; + "," + segment + "}";
extras.remove(extras.size() - 1); extras.remove(extras.size() - 1);
extras.add(lastText); extras.add(lastText);
} }
@Override @Override
public String toString() { public String toString() {
if(extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0); if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":["; String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);; extras.remove(0);
;
for (String extra : extras) for (String extra : extras)
text = text + extra + ","; text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}"; text = text.substring(0, text.length() - 1) + "]}";
@ -108,4 +109,4 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder {
} }
} }

View File

@ -1,18 +1,17 @@
package de.epiceric.shopchest.interfaces.jsonbuilder; package de.epiceric.shopchest.interfaces.jsonbuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R2.PacketPlayOutChat; import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_9_R2 implements JsonBuilder { public class JsonBuilder_1_9_R2 implements JsonBuilder {
@ -23,26 +22,27 @@ public class JsonBuilder_1_9_R2 implements JsonBuilder {
public JsonBuilder_1_9_R2(String... text) { public JsonBuilder_1_9_R2(String... text) {
for(String extra : text) for (String extra : text)
parse(extra); parse(extra);
} }
@Override @Override
public JsonBuilder_1_9_R2 parse(String text) { public JsonBuilder_1_9_R2 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; String regex = "[&<EFBFBD>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1"); text = text.replaceAll(regex, "<EFBFBD>$1");
if(!Pattern.compile(regex).matcher(text).find()) { if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this; return this;
} }
String[] words = text.split(regex); String[] words = text.split(regex);
int index = words[0].length(); int index = words[0].length();
for(String word : words) { for (String word : words) {
try { try {
if(index != words[0].length()) if (index != words[0].length())
withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
} catch(Exception e){} } catch (Exception e) {
}
index += word.length() + 2; index += word.length() + 2;
} }
return this; return this;
@ -63,7 +63,7 @@ public class JsonBuilder_1_9_R2 implements JsonBuilder {
@Override @Override
public JsonBuilder_1_9_R2 withColor(String color) { public JsonBuilder_1_9_R2 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim(); while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color)); withColor(ChatColor.getByChar(color));
return this; return this;
} }
@ -85,16 +85,17 @@ public class JsonBuilder_1_9_R2 implements JsonBuilder {
private void addSegment(String segment) { private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1); String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1) lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}"; + "," + segment + "}";
extras.remove(extras.size() - 1); extras.remove(extras.size() - 1);
extras.add(lastText); extras.add(lastText);
} }
@Override @Override
public String toString() { public String toString() {
if(extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0); if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":["; String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);; extras.remove(0);
;
for (String extra : extras) for (String extra : extras)
text = text + extra + ","; text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}"; text = text.substring(0, text.length() - 1) + "]}";
@ -108,4 +109,4 @@ public class JsonBuilder_1_9_R2 implements JsonBuilder {
} }
} }

View File

@ -1,15 +1,15 @@
package de.epiceric.shopchest.interfaces.utils; package de.epiceric.shopchest.interfaces.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import net.minecraft.server.v1_8_R1.EntityArmorStand; import net.minecraft.server.v1_8_R1.EntityArmorStand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public class Utils_1_8_R1 extends Utils { public class Utils_1_8_R1 extends Utils {
@ -81,5 +81,4 @@ public class Utils_1_8_R1 extends Utils {
} }
} }

View File

@ -1,9 +1,5 @@
package de.epiceric.shopchest.interfaces.utils; package de.epiceric.shopchest.interfaces.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
@ -11,6 +7,9 @@ import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import net.minecraft.server.v1_8_R2.EntityArmorStand; import net.minecraft.server.v1_8_R2.EntityArmorStand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public class Utils_1_8_R2 extends Utils { public class Utils_1_8_R2 extends Utils {
@ -84,5 +83,4 @@ public class Utils_1_8_R2 extends Utils {
} }
} }

View File

@ -1,15 +1,15 @@
package de.epiceric.shopchest.interfaces.utils; package de.epiceric.shopchest.interfaces.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import net.minecraft.server.v1_8_R3.EntityArmorStand; import net.minecraft.server.v1_8_R3.EntityArmorStand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public class Utils_1_8_R3 extends Utils { public class Utils_1_8_R3 extends Utils {
@ -82,5 +82,4 @@ public class Utils_1_8_R3 extends Utils {
} }
} }

View File

@ -1,15 +1,15 @@
package de.epiceric.shopchest.interfaces.utils; package de.epiceric.shopchest.interfaces.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import net.minecraft.server.v1_9_R1.EntityArmorStand; import net.minecraft.server.v1_9_R1.EntityArmorStand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public class Utils_1_9_R1 extends Utils { public class Utils_1_9_R1 extends Utils {
@ -82,5 +82,4 @@ public class Utils_1_9_R1 extends Utils {
} }
} }

View File

@ -1,15 +1,15 @@
package de.epiceric.shopchest.interfaces.utils; package de.epiceric.shopchest.interfaces.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.Hologram; import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import net.minecraft.server.v1_9_R2.EntityArmorStand; import net.minecraft.server.v1_9_R2.EntityArmorStand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public class Utils_1_9_R2 extends Utils { public class Utils_1_9_R2 extends Utils {
@ -82,5 +82,4 @@ public class Utils_1_9_R2 extends Utils {
} }
} }

View File

@ -1,8 +1,11 @@
package de.epiceric.shopchest.shop; package de.epiceric.shopchest.shop;
import java.util.ArrayList; import de.epiceric.shopchest.ShopChest;
import java.util.UUID; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.hologram.*;
import de.epiceric.shopchest.utils.ItemNames;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -17,21 +20,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import de.epiceric.shopchest.ShopChest; import java.util.ArrayList;
import de.epiceric.shopchest.config.Config; import java.util.UUID;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.interfaces.hologram.*;
import de.epiceric.shopchest.utils.ItemNames;
public class Shop { public class Shop {
public enum ShopType {
NORMAL,
INFINITE,
ADMIN;
}
private ShopChest plugin; private ShopChest plugin;
private OfflinePlayer vendor; private OfflinePlayer vendor;
private ItemStack product; private ItemStack product;
@ -41,7 +34,6 @@ public class Shop {
private double buyPrice; private double buyPrice;
private double sellPrice; private double sellPrice;
private ShopType shopType; private ShopType shopType;
public Shop(ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) { public Shop(ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
this.plugin = plugin; this.plugin = plugin;
this.vendor = vendor; this.vendor = vendor;
@ -130,14 +122,18 @@ public class Shop {
if (b.getLocation().equals(r.getLocation())) { if (b.getLocation().equals(r.getLocation())) {
if (r.getX() != l.getX()) holoLocation = new Location(b.getWorld(), b.getX(), b.getY() - 0.6, b.getZ() + 0.5); if (r.getX() != l.getX())
else if (r.getZ() != l.getZ()) holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ()); holoLocation = new Location(b.getWorld(), b.getX(), b.getY() - 0.6, b.getZ() + 0.5);
else if (r.getZ() != l.getZ())
holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ());
else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5); else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
} else { } else {
if (r.getX() != l.getX()) holoLocation = new Location(b.getWorld(), b.getX() + 1, b.getY() - 0.6, b.getZ() + 0.5); if (r.getX() != l.getX())
else if (r.getZ() != l.getZ()) holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 1); holoLocation = new Location(b.getWorld(), b.getX() + 1, b.getY() - 0.6, b.getZ() + 0.5);
else if (r.getZ() != l.getZ())
holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 1);
else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5); else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
} }
@ -152,12 +148,23 @@ public class Shop {
else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice); else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice);
switch (Utils.getVersion(plugin.getServer())) { switch (Utils.getVersion(plugin.getServer())) {
case "v1_8_R1": hologram = new Hologram_1_8_R1(holoText, holoLocation); break; case "v1_8_R1":
case "v1_8_R2": hologram = new Hologram_1_8_R2(holoText, holoLocation); break; hologram = new Hologram_1_8_R1(holoText, holoLocation);
case "v1_8_R3": hologram = new Hologram_1_8_R3(holoText, holoLocation); break; break;
case "v1_9_R1": hologram = new Hologram_1_9_R1(holoText, holoLocation); break; case "v1_8_R2":
case "v1_9_R2": hologram = new Hologram_1_9_R2(holoText, holoLocation); break; hologram = new Hologram_1_8_R2(holoText, holoLocation);
default: return; break;
case "v1_8_R3":
hologram = new Hologram_1_8_R3(holoText, holoLocation);
break;
case "v1_9_R1":
hologram = new Hologram_1_9_R1(holoText, holoLocation);
break;
case "v1_9_R2":
hologram = new Hologram_1_9_R2(holoText, holoLocation);
break;
default:
return;
} }
} }
@ -198,4 +205,10 @@ public class Shop {
return item != null; return item != null;
} }
public enum ShopType {
NORMAL,
INFINITE,
ADMIN;
}
} }

View File

@ -1,24 +1,19 @@
package de.epiceric.shopchest.sql; package de.epiceric.shopchest.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.Utils; import de.epiceric.shopchest.interfaces.Utils;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import java.sql.*;
import java.util.UUID;
import java.util.logging.Level;
public abstract class Database { public abstract class Database {
@ -35,12 +30,8 @@ public abstract class Database {
"`shoptype` varchar(32) NOT NULL," + "`shoptype` varchar(32) NOT NULL," +
"PRIMARY KEY (`id`)" + "PRIMARY KEY (`id`)" +
");"; ");";
ShopChest plugin;
Connection connection;
// The name of the table we created back in SQLite class. // The name of the table we created back in SQLite class.
public String table = "shop_list"; public String table = "shop_list";
public String world = ""; public String world = "";
public String vendor = ""; public String vendor = "";
public ItemStack product = null; public ItemStack product = null;
@ -48,8 +39,10 @@ public abstract class Database {
public double buyPrice = 0; public double buyPrice = 0;
public double sellPrice = 0; public double sellPrice = 0;
public ShopType shopType = ShopType.NORMAL; public ShopType shopType = ShopType.NORMAL;
ShopChest plugin;
Connection connection;
public Database(ShopChest instance){ public Database(ShopChest instance) {
plugin = instance; plugin = instance;
} }
@ -57,12 +50,12 @@ public abstract class Database {
public abstract void load(); public abstract void load();
public void initialize(){ public void initialize() {
connection = getSQLConnection(); connection = getSQLConnection();
try{ try {
PreparedStatement ps = connection.prepareStatement("SELECT * FROM " + table + " WHERE id = ?"); PreparedStatement ps = connection.prepareStatement("SELECT * FROM " + table + " WHERE id = ?");
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
close(ps,rs); close(ps, rs);
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, "Unable to retreive connection", ex); plugin.getLogger().log(Level.SEVERE, "Unable to retreive connection", ex);
@ -126,8 +119,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") > highestID) { if (rs.getInt("id") > highestID) {
highestID = rs.getInt("id"); highestID = rs.getInt("id");
} }
} }
@ -211,8 +204,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id) { if (rs.getInt("id") == id) {
return Bukkit.getWorld(rs.getString("world")); return Bukkit.getWorld(rs.getString("world"));
} }
} }
@ -240,8 +233,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("vendor"))); return Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("vendor")));
} }
} }
@ -269,8 +262,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return Utils.decode(rs.getString("product")); return Utils.decode(rs.getString("product"));
} }
} }
@ -298,8 +291,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return rs.getInt("x"); return rs.getInt("x");
} }
} }
@ -327,8 +320,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return rs.getInt("y"); return rs.getInt("y");
} }
} }
@ -356,8 +349,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return rs.getInt("z"); return rs.getInt("z");
} }
} }
@ -389,8 +382,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return rs.getDouble("buyprice"); return rs.getDouble("buyprice");
} }
} }
@ -418,8 +411,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
return rs.getDouble("sellprice"); return rs.getDouble("sellprice");
} }
} }
@ -447,8 +440,8 @@ public abstract class Database {
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";"); ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()){ while (rs.next()) {
if(rs.getInt("id") == id){ if (rs.getInt("id") == id) {
if (rs.getString("shoptype").equals("0") || rs.getString("shoptype").equals("1")) { if (rs.getString("shoptype").equals("0") || rs.getString("shoptype").equals("1")) {
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '0', 'NORMAL')"); ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '0', 'NORMAL')");
ps.executeUpdate(); ps.executeUpdate();
@ -461,7 +454,7 @@ public abstract class Database {
} }
} }
} catch (SQLException ex) { } catch (SQLException ex) {
if (ex.getMessage().equals("no such column: 'shoptype'")){ if (ex.getMessage().equals("no such column: 'shoptype'")) {
renameColumnInfiniteToShopType(); renameColumnInfiniteToShopType();
return getShopType(id); return getShopType(id);
} }
@ -534,7 +527,7 @@ public abstract class Database {
} }
public void close(PreparedStatement ps,ResultSet rs){ public void close(PreparedStatement ps, ResultSet rs) {
try { try {
if (ps != null) if (ps != null)
ps.close(); ps.close();

View File

@ -1,14 +1,15 @@
package de.epiceric.shopchest.sql; package de.epiceric.shopchest.sql;
import java.util.logging.Level;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import java.util.logging.Level;
public class Error { public class Error {
public static void execute(ShopChest plugin, Exception ex){ public static void execute(ShopChest plugin, Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Couldn't execute MySQL statement: ", ex); plugin.getLogger().log(Level.SEVERE, "Couldn't execute MySQL statement: ", ex);
} }
public static void close(ShopChest plugin, Exception ex){
public static void close(ShopChest plugin, Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Failed to close MySQL connection: ", ex); plugin.getLogger().log(Level.SEVERE, "Failed to close MySQL connection: ", ex);
} }
} }

View File

@ -1,16 +1,19 @@
package de.epiceric.shopchest.sql; package de.epiceric.shopchest.sql;
public class Errors { public class Errors {
public static String sqlConnectionExecute(){ public static String sqlConnectionExecute() {
return "Couldn't execute MySQL statement: "; return "Couldn't execute MySQL statement: ";
} }
public static String sqlConnectionClose(){
public static String sqlConnectionClose() {
return "Failed to close MySQL connection: "; return "Failed to close MySQL connection: ";
} }
public static String noSQLConnection(){
public static String noSQLConnection() {
return "Unable to retreive MYSQL connection: "; return "Unable to retreive MYSQL connection: ";
} }
public static String noTableFound(){
public static String noTableFound() {
return "Database Error: No Table Found"; return "Database Error: No Table Found";
} }
} }

View File

@ -1,5 +1,7 @@
package de.epiceric.shopchest.sql; package de.epiceric.shopchest.sql;
import de.epiceric.shopchest.ShopChest;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
@ -8,36 +10,34 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.logging.Level; import java.util.logging.Level;
import de.epiceric.shopchest.ShopChest;
public class SQLite extends Database { public class SQLite extends Database {
String dbname; String dbname;
public SQLite(ShopChest instance){ public SQLite(ShopChest instance) {
super(instance); super(instance);
dbname = "shops"; dbname = "shops";
} }
// SQL creation stuff, You can leave the below stuff untouched. // SQL creation stuff, You can leave the below stuff untouched.
public Connection getSQLConnection() { public Connection getSQLConnection() {
File dataFolder = new File(plugin.getDataFolder(), dbname+".db"); File dataFolder = new File(plugin.getDataFolder(), dbname + ".db");
if (!dataFolder.exists()){ if (!dataFolder.exists()) {
try { try {
dataFolder.createNewFile(); dataFolder.createNewFile();
} catch (IOException e) { } catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "File write error: "+dbname+".db"); plugin.getLogger().log(Level.SEVERE, "File write error: " + dbname + ".db");
} }
} }
try { try {
if(connection!=null&&!connection.isClosed()){ if (connection != null && !connection.isClosed()) {
return connection; return connection;
} }
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder); connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
return connection; return connection;
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE,"SQLite exception on initialize", ex); plugin.getLogger().log(Level.SEVERE, "SQLite exception on initialize", ex);
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
plugin.getLogger().log(Level.SEVERE, "You need the SQLite JBDC library. Google it. Put it in /lib folder."); plugin.getLogger().log(Level.SEVERE, "You need the SQLite JBDC library. Google it. Put it in /lib folder.");
} }

View File

@ -1,11 +1,10 @@
package de.epiceric.shopchest.utils; package de.epiceric.shopchest.utils;
import java.util.Map; import com.google.common.collect.ImmutableMap;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import com.google.common.collect.ImmutableMap; import java.util.Map;
public class ArrowEffectNames { public class ArrowEffectNames {
@ -29,7 +28,7 @@ public class ArrowEffectNames {
public static String getTippedArrowName(ItemStack itemStack) { public static String getTippedArrowName(ItemStack itemStack) {
if (!(itemStack.getItemMeta() instanceof PotionMeta)){ if (!(itemStack.getItemMeta() instanceof PotionMeta)) {
return null; return null;
} }
@ -39,31 +38,67 @@ public class ArrowEffectNames {
name = effectMap.get(meta.getBasePotionData().getType().toString()); name = effectMap.get(meta.getBasePotionData().getType().toString());
if (meta.getBasePotionData().isUpgraded()){ if (meta.getBasePotionData().isUpgraded()) {
name += " II"; name += " II";
switch (meta.getBasePotionData().getType()) { switch (meta.getBasePotionData().getType()) {
case JUMP: name += " (0:11)"; break; case JUMP:
case SPEED: name += " (0:11)"; break; name += " (0:11)";
case POISON: name += " (0:02)"; break; break;
case REGEN: name += " (0:02)"; break; case SPEED:
case STRENGTH: name += " (0:11)"; break; name += " (0:11)";
default: break; break;
case POISON:
name += " (0:02)";
break;
case REGEN:
name += " (0:02)";
break;
case STRENGTH:
name += " (0:11)";
break;
default:
break;
} }
} else { } else {
switch (meta.getBasePotionData().getType()) { switch (meta.getBasePotionData().getType()) {
case FIRE_RESISTANCE: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; case FIRE_RESISTANCE:
case INVISIBILITY: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
case JUMP: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; break;
case LUCK: name += " (0:37)"; break; case INVISIBILITY:
case NIGHT_VISION: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
case POISON: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")"; break; break;
case REGEN: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")"; break; case JUMP:
case SLOWNESS: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")"; break; name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
case SPEED: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; break;
case STRENGTH: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; case LUCK:
case WATER_BREATHING: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; name += " (0:37)";
case WEAKNESS: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")"; break; break;
default: break; case NIGHT_VISION:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
break;
case POISON:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")";
break;
case REGEN:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")";
break;
case SLOWNESS:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")";
break;
case SPEED:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
break;
case STRENGTH:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
break;
case WATER_BREATHING:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
break;
case WEAKNESS:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")";
break;
default:
break;
} }
} }

View File

@ -1,15 +1,29 @@
package de.epiceric.shopchest.utils; package de.epiceric.shopchest.utils;
import java.util.HashMap; import de.epiceric.shopchest.shop.Shop.ShopType;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import de.epiceric.shopchest.shop.Shop.ShopType; import java.util.HashMap;
public class ClickType { public class ClickType {
private static HashMap<OfflinePlayer, ClickType> playerClickType = new HashMap<>(); private static HashMap<OfflinePlayer, ClickType> playerClickType = new HashMap<>();
private EnumClickType enumClickType;
private ItemStack product;
private double buyPrice;
private double sellPrice;
private ShopType shopType;
public ClickType(EnumClickType enumClickType) {
this.enumClickType = enumClickType;
}
public ClickType(EnumClickType enumClickType, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
this.enumClickType = enumClickType;
this.product = product;
this.sellPrice = sellPrice;
this.buyPrice = buyPrice;
this.shopType = shopType;
}
public static ClickType getPlayerClickType(OfflinePlayer player) { public static ClickType getPlayerClickType(OfflinePlayer player) {
if (playerClickType.containsKey(player)) if (playerClickType.containsKey(player))
@ -26,28 +40,6 @@ public class ClickType {
playerClickType.put(player, clickType); playerClickType.put(player, clickType);
} }
public enum EnumClickType {
CREATE, REMOVE, INFO;
}
private EnumClickType enumClickType;
private ItemStack product;
private double buyPrice;
private double sellPrice;
private ShopType shopType;
public ClickType(EnumClickType enumClickType) {
this.enumClickType = enumClickType;
}
public ClickType(EnumClickType enumClickType, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
this.enumClickType = enumClickType;
this.product = product;
this.sellPrice = sellPrice;
this.buyPrice = buyPrice;
this.shopType = shopType;
}
public EnumClickType getClickType() { public EnumClickType getClickType() {
return enumClickType; return enumClickType;
} }
@ -68,4 +60,8 @@ public class ClickType {
return shopType; return shopType;
} }
public enum EnumClickType {
CREATE, REMOVE, INFO;
}
} }

View File

@ -1,12 +1,11 @@
package de.epiceric.shopchest.utils; package de.epiceric.shopchest.utils;
import com.google.common.collect.ImmutableMap;
import org.bukkit.enchantments.Enchantment;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.enchantments.Enchantment;
import com.google.common.collect.ImmutableMap;
public class EnchantmentNames { public class EnchantmentNames {
private static final Map<String, String> enchMap = ImmutableMap.<String, String>builder() private static final Map<String, String> enchMap = ImmutableMap.<String, String>builder()
@ -62,8 +61,8 @@ public class EnchantmentNames {
roman_numerals.put("IV", 4); roman_numerals.put("IV", 4);
roman_numerals.put("I", 1); roman_numerals.put("I", 1);
String res = ""; String res = "";
for(Map.Entry<String, Integer> entry : roman_numerals.entrySet()){ for (Map.Entry<String, Integer> entry : roman_numerals.entrySet()) {
int matches = Int/entry.getValue(); int matches = Int / entry.getValue();
res += repeat(entry.getKey(), matches); res += repeat(entry.getKey(), matches);
Int = Int % entry.getValue(); Int = Int % entry.getValue();
} }
@ -71,11 +70,11 @@ public class EnchantmentNames {
} }
public static String repeat(String s, int n) { public static String repeat(String s, int n) {
if(s == null) { if (s == null) {
return null; return null;
} }
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
sb.append(s); sb.append(s);
} }
return sb.toString(); return sb.toString();

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest.utils; package de.epiceric.shopchest.utils;
import java.util.Map; import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,11 +9,11 @@ import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import com.google.common.collect.ImmutableMap; import java.util.Map;
public class ItemNames { public class ItemNames {
private static final Map<String,String> map = ImmutableMap.<String,String>builder() private static final Map<String, String> map = ImmutableMap.<String, String>builder()
.put("1", "Stone") .put("1", "Stone")
.put("1:1", "Granite") .put("1:1", "Granite")
.put("1:2", "Polished Granite") .put("1:2", "Polished Granite")
@ -640,7 +639,7 @@ public class ItemNames {
if (meta.getDisplayName() != null) { if (meta.getDisplayName() != null) {
return meta.getDisplayName(); return meta.getDisplayName();
} else if (meta instanceof BookMeta) { } else if (meta instanceof BookMeta) {
return ((BookMeta)meta).getTitle(); return ((BookMeta) meta).getTitle();
} }
} }
@ -651,7 +650,7 @@ public class ItemNames {
// special case: white wool/carpet is just called "Wool" or "Carpet" // special case: white wool/carpet is just called "Wool" or "Carpet"
result = map.get(key); result = map.get(key);
} else if (mat == Material.WOOL || mat == Material.CARPET || mat == Material.STAINED_CLAY || mat == Material.STAINED_GLASS || mat == Material.STAINED_GLASS_PANE) { } else if (mat == Material.WOOL || mat == Material.CARPET || mat == Material.STAINED_CLAY || mat == Material.STAINED_GLASS || mat == Material.STAINED_GLASS_PANE) {
DyeColor dc = DyeColor.getByWoolData((byte)stack.getDurability()); DyeColor dc = DyeColor.getByWoolData((byte) stack.getDurability());
result = dc == null ? map.get(key) : WordUtils.capitalizeFully(dc.toString().replace("_", " ")) + " " + map.get(key); result = dc == null ? map.get(key) : WordUtils.capitalizeFully(dc.toString().replace("_", " ")) + " " + map.get(key);
} else if (mat == Material.LEATHER_HELMET || mat == Material.LEATHER_CHESTPLATE || mat == Material.LEATHER_LEGGINGS || mat == Material.LEATHER_BOOTS) { } else if (mat == Material.LEATHER_HELMET || mat == Material.LEATHER_CHESTPLATE || mat == Material.LEATHER_LEGGINGS || mat == Material.LEATHER_BOOTS) {
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) stack.getItemMeta(); LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) stack.getItemMeta();

View File

@ -36,25 +36,13 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Collection; import java.util.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -147,6 +135,121 @@ public class Metrics {
debug = configuration.getBoolean("debug", false); debug = configuration.getBoolean("debug", false);
} }
/**
* GZip compress a string of bytes
*
* @param input
* @return
*/
public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (gzos != null) try {
gzos.close();
} catch (IOException ignore) {
}
}
return baos.toByteArray();
}
/**
* Appends a json encoded key/value pair to the given string builder.
*
* @param json
* @param key
* @param value
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false;
try {
if (value.equals("0") || !value.endsWith("0")) {
Double.parseDouble(value);
isValueNumeric = true;
}
} catch (NumberFormatException e) {
isValueNumeric = false;
}
if (json.charAt(json.length() - 1) != '{') {
json.append(',');
}
json.append(escapeJSON(key));
json.append(':');
if (isValueNumeric) {
json.append(value);
} else {
json.append(escapeJSON(value));
}
}
/**
* Escape a string to create a valid JSON string
*
* @param text
* @return
*/
private static String escapeJSON(String text) {
StringBuilder builder = new StringBuilder();
builder.append('"');
for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index);
switch (chr) {
case '"':
case '\\':
builder.append('\\');
builder.append(chr);
break;
case '\b':
builder.append("\\b");
break;
case '\t':
builder.append("\\t");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
default:
if (chr < ' ') {
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
} else {
builder.append(chr);
}
break;
}
}
builder.append('"');
return builder.toString();
}
/**
* Encode text as UTF-8
*
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/** /**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* website. Plotters can be added to the graph object returned. * website. Plotters can be added to the graph object returned.
@ -334,10 +437,10 @@ public class Metrics {
private int getOnlinePlayers() { private int getOnlinePlayers() {
try { try {
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers"); Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
if(onlinePlayerMethod.getReturnType().equals(Collection.class)) { if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size(); return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
} else { } else {
return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length; return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
} }
} catch (Exception ex) { } catch (Exception ex) {
if (debug) { if (debug) {
@ -510,31 +613,6 @@ public class Metrics {
} }
} }
/**
* GZip compress a string of bytes
*
* @param input
* @return
*/
public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (gzos != null) try {
gzos.close();
} catch (IOException ignore) {
}
}
return baos.toByteArray();
}
/** /**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests * Check if mineshafter is present. If it is, we need to bypass it to send POST requests
* *
@ -549,96 +627,6 @@ public class Metrics {
} }
} }
/**
* Appends a json encoded key/value pair to the given string builder.
*
* @param json
* @param key
* @param value
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false;
try {
if (value.equals("0") || !value.endsWith("0")) {
Double.parseDouble(value);
isValueNumeric = true;
}
} catch (NumberFormatException e) {
isValueNumeric = false;
}
if (json.charAt(json.length() - 1) != '{') {
json.append(',');
}
json.append(escapeJSON(key));
json.append(':');
if (isValueNumeric) {
json.append(value);
} else {
json.append(escapeJSON(value));
}
}
/**
* Escape a string to create a valid JSON string
*
* @param text
* @return
*/
private static String escapeJSON(String text) {
StringBuilder builder = new StringBuilder();
builder.append('"');
for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index);
switch (chr) {
case '"':
case '\\':
builder.append('\\');
builder.append(chr);
break;
case '\b':
builder.append("\\b");
break;
case '\t':
builder.append("\\t");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
default:
if (chr < ' ') {
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
} else {
builder.append(chr);
}
break;
}
}
builder.append('"');
return builder.toString();
}
/**
* Encode text as UTF-8
*
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/** /**
* Represents a custom graph on the website * Represents a custom graph on the website
*/ */

View File

@ -1,10 +1,9 @@
package de.epiceric.shopchest.utils; package de.epiceric.shopchest.utils;
import java.util.ArrayList; import de.epiceric.shopchest.ShopChest;
import java.util.HashMap; import de.epiceric.shopchest.config.Config;
import java.util.List; import de.epiceric.shopchest.interfaces.Utils;
import java.util.UUID; import de.epiceric.shopchest.shop.Shop;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -14,10 +13,10 @@ import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import de.epiceric.shopchest.ShopChest; import java.util.ArrayList;
import de.epiceric.shopchest.config.Config; import java.util.HashMap;
import de.epiceric.shopchest.interfaces.Utils; import java.util.List;
import de.epiceric.shopchest.shop.Shop; import java.util.UUID;
public class ShopUtils { public class ShopUtils {

View File

@ -1,24 +1,16 @@
package de.epiceric.shopchest.utils; package de.epiceric.shopchest.utils;
import de.epiceric.shopchest.ShopChest;
import org.jsoup.Connection; import org.jsoup.Connection;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import de.epiceric.shopchest.ShopChest;
public class UpdateChecker { public class UpdateChecker {
public enum UpdateCheckerResult {
TRUE,
FALSE,
ERROR;
}
private ShopChest plugin; private ShopChest plugin;
private String url; private String url;
private String version; private String version;
private String link; private String link;
public UpdateChecker(ShopChest plugin, String url) { public UpdateChecker(ShopChest plugin, String url) {
this.plugin = plugin; this.plugin = plugin;
this.url = url; this.url = url;
@ -34,7 +26,7 @@ public class UpdateChecker {
version = doc.text().split("\\|")[0]; version = doc.text().split("\\|")[0];
link = url + "download?version=" + doc.text().split("\\|")[1]; link = url + "download?version=" + doc.text().split("\\|")[1];
if(plugin.getDescription().getVersion().equals(version)) if (plugin.getDescription().getVersion().equals(version))
return UpdateCheckerResult.FALSE; return UpdateCheckerResult.FALSE;
else else
return UpdateCheckerResult.TRUE; return UpdateCheckerResult.TRUE;
@ -58,7 +50,8 @@ public class UpdateChecker {
if (!broadcast.equals("/")) if (!broadcast.equals("/"))
return messages; return messages;
} catch (Exception | Error e) {} } catch (Exception | Error e) {
}
return null; return null;
} }
@ -71,5 +64,11 @@ public class UpdateChecker {
return link; return link;
} }
public enum UpdateCheckerResult {
TRUE,
FALSE,
ERROR;
}
} }