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

5
.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,283 +11,306 @@ 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 {
private ShopChest plugin; private ShopChest plugin;
private Permission perm = ShopChest.perm; private Permission perm = ShopChest.perm;
public Commands(ShopChest plugin, String name, String description, String usageMessage, List<String> aliases) { public Commands(ShopChest plugin, String name, String description, String usageMessage, List<String> aliases) {
super(name, description, usageMessage, aliases); super(name, description, usageMessage, aliases);
this.plugin = plugin; this.plugin = plugin;
}
public static void registerCommand(Command command, ShopChest plugin) throws ReflectiveOperationException {
Method commandMap = plugin.getServer().getClass().getMethod("getCommandMap");
Object cmdmap = commandMap.invoke(plugin.getServer());
Method register = cmdmap.getClass().getMethod("register", String.class,Command.class);
register.invoke(cmdmap, command.getName(),command);
} }
@Override public static void registerCommand(Command command, ShopChest plugin) throws ReflectiveOperationException {
public boolean execute(CommandSender sender, String label, String[] args) { Method commandMap = plugin.getServer().getClass().getMethod("getCommandMap");
if (sender instanceof Player) { Object cmdmap = commandMap.invoke(plugin.getServer());
Player p = (Player) sender; Method register = cmdmap.getClass().getMethod("register", String.class, Command.class);
register.invoke(cmdmap, command.getName(), command);
if (args.length == 0) { }
sendBasicHelpMessage(p);
return true;
} else {
if (args[0].equalsIgnoreCase("create")) {
if (perm.has(p, "shopchest.create")) {
if (args.length == 4) {
create(args, ShopType.NORMAL, p);
return true;
} else if (args.length == 5) {
if (args[4].equalsIgnoreCase("infinite")) {
if (perm.has(p, "shopchest.create.infinite")) {
create(args, ShopType.INFINITE, p);
return true;
} else {
p.sendMessage(Config.noPermission_createInfinite());
return true;
}
} else if (args[4].equalsIgnoreCase("normal")){
create(args, ShopType.NORMAL, p);
return true;
} else if (args[4].equalsIgnoreCase("admin")) {
if (perm.has(p, "shopchest.create.admin")) {
create(args, ShopType.ADMIN, p);
return true;
} else {
p.sendMessage(Config.noPermission_createAdmin());
return true;
}
} else {
sendBasicHelpMessage(p);
return true;
}
} else {
sendBasicHelpMessage(p);
return true;
}
} else {
p.sendMessage(Config.noPermission_create());
return true;
}
} else if (args[0].equalsIgnoreCase("remove")) {
remove(p);
return true;
} else if (args[0].equalsIgnoreCase("info")) {
info(p);
return true;
} else if (args[0].equalsIgnoreCase("reload")) {
if (perm.has(p, "shopchest.reload")) {
reload(p);
return true;
} else {
p.sendMessage(Config.noPermission_reload());
return true;
}
} else if (args[0].equalsIgnoreCase("update")) {
if (perm.has(p, "shopchest.update")) {
checkUpdates(p);
return true;
} else {
p.sendMessage(Config.noPermission_update());
return true;
}
} else if (args[0].equalsIgnoreCase("limits")) {
if (perm.has(p, "shopchest.limits")) {
p.sendMessage(Config.occupied_shop_slots(ShopUtils.getShopLimit(p), ShopUtils.getShopAmount(p)));
return true;
} else {
p.sendMessage(Config.noPermission_limits());
}
} else {
sendBasicHelpMessage(p);
return true;
}
return true;
}
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Only players can execute this command.");
return true;
}
}
private void checkUpdates(Player player) {
player.sendMessage(Config.checking_update());
UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite());
UpdateCheckerResult result = uc.updateNeeded();
if (result == UpdateCheckerResult.TRUE) {
ShopChest.latestVersion = uc.getVersion();
ShopChest.downloadLink = uc.getLink();
ShopChest.isUpdateNeeded = true;
JsonBuilder jb;
switch (Utils.getVersion(plugin.getServer())) {
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)); break;
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)); 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);
} else if (result == UpdateCheckerResult.FALSE) {
ShopChest.latestVersion = "";
ShopChest.downloadLink = "";
ShopChest.isUpdateNeeded = false;
player.sendMessage(Config.no_new_update());
} else {
ShopChest.latestVersion = "";
ShopChest.downloadLink = "";
ShopChest.isUpdateNeeded = false;
player.sendMessage(Config.update_check_error());
}
if (perm.has(player, "shopchest.broadcast")) {
if (Config.enable_broadcast()) ShopChest.broadcast = uc.getBroadcast();
if (ShopChest.broadcast != null) {
for (String message : ShopChest.broadcast) {
player.sendMessage(message);
}
}
}
} @Override
public boolean execute(CommandSender sender, String label, String[] args) {
private void reload(Player player) { if (sender instanceof Player) {
ShopChest.utils.reload(player); Player p = (Player) sender;
}
if (args.length == 0) {
private void create(String[] args, ShopType shopType, Player p) { sendBasicHelpMessage(p);
int amount; return true;
double buyPrice, sellPrice; } else {
if (args[0].equalsIgnoreCase("create")) {
int limit = ShopUtils.getShopLimit(p); if (perm.has(p, "shopchest.create")) {
if (args.length == 4) {
if (limit != -1) { create(args, ShopType.NORMAL, p);
if (ShopUtils.getShopAmount(p) >= limit) { return true;
p.sendMessage(Config.limit_reached(limit)); } else if (args.length == 5) {
return; if (args[4].equalsIgnoreCase("infinite")) {
} if (perm.has(p, "shopchest.create.infinite")) {
} create(args, ShopType.INFINITE, p);
return true;
try { } else {
amount = Integer.parseInt(args[1]); p.sendMessage(Config.noPermission_createInfinite());
buyPrice = Double.parseDouble(args[2]); return true;
sellPrice = Double.parseDouble(args[3]); }
} catch (NumberFormatException e) { } else if (args[4].equalsIgnoreCase("normal")) {
p.sendMessage(Config.amount_and_price_not_number()); create(args, ShopType.NORMAL, p);
return; return true;
} } else if (args[4].equalsIgnoreCase("admin")) {
if (perm.has(p, "shopchest.create.admin")) {
boolean buyEnabled = !(buyPrice <= 0), sellEnabled = !(sellPrice <= 0); create(args, ShopType.ADMIN, p);
return true;
if (!buyEnabled && !sellEnabled) { } else {
p.sendMessage(Config.buy_and_sell_disabled()); p.sendMessage(Config.noPermission_createAdmin());
return; return true;
} }
} else {
if (p.getItemInHand().getType().equals(Material.AIR)) { sendBasicHelpMessage(p);
p.sendMessage(Config.no_item_in_hand()); return true;
return; }
} } else {
sendBasicHelpMessage(p);
for (String item : Config.blacklist()) { return true;
}
ItemStack itemStack; } else {
p.sendMessage(Config.noPermission_create());
if (item.contains(":")) { return true;
itemStack = new ItemStack(Material.getMaterial(item.split(":")[0]), 1, Short.parseShort(item.split(":")[1])); }
} else { } else if (args[0].equalsIgnoreCase("remove")) {
itemStack = new ItemStack(Material.getMaterial(item), 1); remove(p);
} return true;
} else if (args[0].equalsIgnoreCase("info")) {
if (itemStack.getType().equals(p.getItemInHand().getType()) && itemStack.getDurability() == p.getItemInHand().getDurability()) { info(p);
p.sendMessage(Config.cannot_sell_item()); return true;
return; } else if (args[0].equalsIgnoreCase("reload")) {
} if (perm.has(p, "shopchest.reload")) {
} reload(p);
return true;
for (String key : Config.minimum_prices()) { } else {
p.sendMessage(Config.noPermission_reload());
ItemStack itemStack; return true;
double price = plugin.getConfig().getDouble("minimum-prices." + key); }
} else if (args[0].equalsIgnoreCase("update")) {
if (key.contains(":")) { if (perm.has(p, "shopchest.update")) {
itemStack = new ItemStack(Material.getMaterial(key.split(":")[0]), 1, Short.parseShort(key.split(":")[1])); checkUpdates(p);
} else { return true;
itemStack = new ItemStack(Material.getMaterial(key), 1); } else {
} p.sendMessage(Config.noPermission_update());
return true;
if (itemStack.getType().equals(p.getItemInHand().getType()) && itemStack.getDurability() == p.getItemInHand().getDurability()) { }
if (buyEnabled) { } else if (args[0].equalsIgnoreCase("limits")) {
if ((buyPrice <= amount * price) && (buyPrice > 0)) { if (perm.has(p, "shopchest.limits")) {
p.sendMessage(Config.buyPrice_too_low(amount * price)); p.sendMessage(Config.occupied_shop_slots(ShopUtils.getShopLimit(p), ShopUtils.getShopAmount(p)));
return; return true;
} } else {
} p.sendMessage(Config.noPermission_limits());
}
if (sellEnabled) { } else {
if ((sellPrice <= amount * price) && (sellPrice > 0)) { sendBasicHelpMessage(p);
p.sendMessage(Config.sellPrice_too_low(amount * price)); return true;
return; }
}
} return true;
} }
}
} else {
if (sellEnabled && buyEnabled) { Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Only players can execute this command.");
if (Config.buy_greater_or_equal_sell()) { return true;
if (buyPrice < sellPrice) { }
p.sendMessage(Config.buyPrice_too_low(sellPrice));
return; }
}
} private void checkUpdates(Player player) {
} player.sendMessage(Config.checking_update());
ItemStack itemStack = new ItemStack(p.getItemInHand().getType(), amount, p.getItemInHand().getDurability()); UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite());
itemStack.setItemMeta(p.getItemInHand().getItemMeta()); UpdateCheckerResult result = uc.updateNeeded();
if (Enchantment.DURABILITY.canEnchantItem(itemStack)) { if (result == UpdateCheckerResult.TRUE) {
if (itemStack.getDurability() > 0) { ShopChest.latestVersion = uc.getVersion();
p.sendMessage(Config.cannot_sell_broken_item()); ShopChest.downloadLink = uc.getLink();
return; ShopChest.isUpdateNeeded = true;
}
} JsonBuilder jb;
switch (Utils.getVersion(plugin.getServer())) {
ClickType.addPlayerClickType(p, new ClickType(EnumClickType.CREATE, itemStack, buyPrice, sellPrice, shopType)); case "v1_8_R1":
p.sendMessage(Config.click_chest_to_create()); jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion));
break;
} case "v1_8_R2":
jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion));
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);
} else if (result == UpdateCheckerResult.FALSE) {
ShopChest.latestVersion = "";
ShopChest.downloadLink = "";
ShopChest.isUpdateNeeded = false;
player.sendMessage(Config.no_new_update());
} else {
ShopChest.latestVersion = "";
ShopChest.downloadLink = "";
ShopChest.isUpdateNeeded = false;
player.sendMessage(Config.update_check_error());
}
if (perm.has(player, "shopchest.broadcast")) {
if (Config.enable_broadcast()) ShopChest.broadcast = uc.getBroadcast();
if (ShopChest.broadcast != null) {
for (String message : ShopChest.broadcast) {
player.sendMessage(message);
}
}
}
}
private void reload(Player player) {
ShopChest.utils.reload(player);
}
private void create(String[] args, ShopType shopType, Player p) {
int amount;
double buyPrice, sellPrice;
int limit = ShopUtils.getShopLimit(p);
if (limit != -1) {
if (ShopUtils.getShopAmount(p) >= limit) {
p.sendMessage(Config.limit_reached(limit));
return;
}
}
try {
amount = Integer.parseInt(args[1]);
buyPrice = Double.parseDouble(args[2]);
sellPrice = Double.parseDouble(args[3]);
} catch (NumberFormatException e) {
p.sendMessage(Config.amount_and_price_not_number());
return;
}
boolean buyEnabled = !(buyPrice <= 0), sellEnabled = !(sellPrice <= 0);
if (!buyEnabled && !sellEnabled) {
p.sendMessage(Config.buy_and_sell_disabled());
return;
}
if (p.getItemInHand().getType().equals(Material.AIR)) {
p.sendMessage(Config.no_item_in_hand());
return;
}
for (String item : Config.blacklist()) {
ItemStack itemStack;
if (item.contains(":")) {
itemStack = new ItemStack(Material.getMaterial(item.split(":")[0]), 1, Short.parseShort(item.split(":")[1]));
} else {
itemStack = new ItemStack(Material.getMaterial(item), 1);
}
if (itemStack.getType().equals(p.getItemInHand().getType()) && itemStack.getDurability() == p.getItemInHand().getDurability()) {
p.sendMessage(Config.cannot_sell_item());
return;
}
}
for (String key : Config.minimum_prices()) {
ItemStack itemStack;
double price = plugin.getConfig().getDouble("minimum-prices." + key);
if (key.contains(":")) {
itemStack = new ItemStack(Material.getMaterial(key.split(":")[0]), 1, Short.parseShort(key.split(":")[1]));
} else {
itemStack = new ItemStack(Material.getMaterial(key), 1);
}
if (itemStack.getType().equals(p.getItemInHand().getType()) && itemStack.getDurability() == p.getItemInHand().getDurability()) {
if (buyEnabled) {
if ((buyPrice <= amount * price) && (buyPrice > 0)) {
p.sendMessage(Config.buyPrice_too_low(amount * price));
return;
}
}
if (sellEnabled) {
if ((sellPrice <= amount * price) && (sellPrice > 0)) {
p.sendMessage(Config.sellPrice_too_low(amount * price));
return;
}
}
}
}
if (sellEnabled && buyEnabled) {
if (Config.buy_greater_or_equal_sell()) {
if (buyPrice < sellPrice) {
p.sendMessage(Config.buyPrice_too_low(sellPrice));
return;
}
}
}
ItemStack itemStack = new ItemStack(p.getItemInHand().getType(), amount, p.getItemInHand().getDurability());
itemStack.setItemMeta(p.getItemInHand().getItemMeta());
if (Enchantment.DURABILITY.canEnchantItem(itemStack)) {
if (itemStack.getDurability() > 0) {
p.sendMessage(Config.cannot_sell_broken_item());
return;
}
}
ClickType.addPlayerClickType(p, new ClickType(EnumClickType.CREATE, itemStack, buyPrice, sellPrice, shopType));
p.sendMessage(Config.click_chest_to_create());
}
private void remove(Player p) {
p.sendMessage(Config.click_chest_to_remove());
ClickType.addPlayerClickType(p, new ClickType(EnumClickType.REMOVE));
}
private void info(Player p) {
p.sendMessage(Config.click_chest_for_info());
ClickType.addPlayerClickType(p, new ClickType(EnumClickType.INFO));
}
private void sendBasicHelpMessage(Player player) {
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " create <amount> <buy-price> <sell-price> [infinite|normal|admin] - " + Config.cmdDesc_create());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " remove - " + Config.cmdDesc_remove());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " info - " + Config.cmdDesc_info());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " reload - " + Config.cmdDesc_reload());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " update - " + Config.cmdDesc_update());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " limits - " + Config.cmdDesc_limits());
}
private void remove(Player p) {
p.sendMessage(Config.click_chest_to_remove());
ClickType.addPlayerClickType(p, new ClickType(EnumClickType.REMOVE));
}
private void info(Player p) {
p.sendMessage(Config.click_chest_for_info());
ClickType.addPlayerClickType(p, new ClickType(EnumClickType.INFO));
}
private void sendBasicHelpMessage(Player player) {
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " create <amount> <buy-price> <sell-price> [infinite|normal|admin] - " + Config.cmdDesc_create());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " remove - " + Config.cmdDesc_remove());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " info - " + Config.cmdDesc_info());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " reload - " + Config.cmdDesc_reload());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " update - " + Config.cmdDesc_update());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " limits - " + Config.cmdDesc_limits());
}
} }

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,32 +19,53 @@ 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 String latestVersion = "";
public static boolean isUpdateNeeded = false; public static String downloadLink = "";
public static String latestVersion = ""; public static String[] broadcast = null;
public static String downloadLink = ""; public static Utils utils;
public static String[] broadcast = null; private static ShopChest instance;
public static Utils utils; public static ShopChest getInstance() {
return instance;
public static ShopChest getInstance() { }
return instance;
} public static void copy(InputStream in, File file) {
try {
OutputStream out = new FileOutputStream(file);
private boolean setupEconomy() { 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() {
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) { if (rsp == null) {
return false; return false;
@ -73,244 +73,250 @@ public class ShopChest extends JavaPlugin{
econ = rsp.getProvider(); econ = rsp.getProvider();
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();
if (getServer().getPluginManager().getPlugin("Vault") == null) {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
logger.severe("Could not find plugin 'Vault'!"); logger.severe("Could not find plugin 'Vault'!");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
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;
} }
try {
Metrics metrics = new Metrics(this);
Graph shopType = metrics.createGraph("Shop Type");
shopType.addPlotter(new Plotter("Infinite") {
@Override
public int getValue() {
int value = 0;
for (Shop shop : ShopUtils.getShops()) {
if (shop.getShopType() == ShopType.INFINITE) value++;
}
return value;
}
});
shopType.addPlotter(new Plotter("Normal") {
@Override
public int getValue() {
int value = 0;
for (Shop shop : ShopUtils.getShops()) {
if (shop.getShopType() == ShopType.NORMAL) value++;
}
return value;
}
});
shopType.addPlotter(new Plotter("Admin") {
@Override try {
public int getValue() { Metrics metrics = new Metrics(this);
int value = 0; Graph shopType = metrics.createGraph("Shop Type");
for (Shop shop : ShopUtils.getShops()) {
if (shop.getShopType() == ShopType.ADMIN) value++;
}
return value;
}
});
metrics.start();
} catch (IOException e) {
logger.severe("Could not submit stats.");
}
reloadConfig(); shopType.addPlotter(new Plotter("Infinite") {
saveDefaultConfig();
sqlite = new SQLite(this);
sqlite.load();
switch (Utils.getVersion(getServer())) {
case "v1_8_R1": utils = new Utils_1_8_R1(); break;
case "v1_8_R2": 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:
logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!");
getServer().getPluginManager().disablePlugin(this);
return;
}
if (getServer().getPluginManager().getPlugin("LWC") != null) {
Plugin lwcp = getServer().getPluginManager().getPlugin("LWC");
lwc = ((LWCPlugin) lwcp).getLWC();
} else {
lwc = null;
}
if (getServer().getPluginManager().getPlugin("Lockette") != null) {
lockette = true;
} else {
lockette = false;
}
setupPermissions();
instance = this;
UpdateChecker uc = new UpdateChecker(this, getDescription().getWebsite()); @Override
UpdateCheckerResult result = uc.updateNeeded(); public int getValue() {
int value = 0;
if (Config.enable_broadcast()) broadcast = uc.getBroadcast();
for (Shop shop : ShopUtils.getShops()) {
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.checking_update()); if (shop.getShopType() == ShopType.INFINITE) value++;
if(result == UpdateCheckerResult.TRUE) { }
latestVersion = uc.getVersion();
downloadLink = uc.getLink(); return value;
isUpdateNeeded = true; }
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.update_available(latestVersion)); });
for (Player p : getServer().getOnlinePlayers()) { shopType.addPlotter(new Plotter("Normal") {
if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb; @Override
switch (Utils.getVersion(getServer())) { public int getValue() {
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(latestVersion)); break; int value = 0;
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(latestVersion)); break;
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(latestVersion)); break; for (Shop shop : ShopUtils.getShops()) {
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion)); break; if (shop.getShopType() == ShopType.NORMAL) value++;
case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(latestVersion)); break; }
default: return;
} return value;
jb.sendJson(p); }
}
} });
} else if (result == UpdateCheckerResult.FALSE) { shopType.addPlotter(new Plotter("Admin") {
latestVersion = "";
downloadLink = ""; @Override
isUpdateNeeded = false; public int getValue() {
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.no_new_update()); int value = 0;
} else {
latestVersion = ""; for (Shop shop : ShopUtils.getShops()) {
downloadLink = ""; if (shop.getShopType() == ShopType.ADMIN) value++;
isUpdateNeeded = false; }
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.update_check_error());
} return value;
}
for (Player p : getServer().getOnlinePlayers()) {
if (perm.has(p, "shopchest.broadcast")) { });
if (broadcast != null) {
for (String message : broadcast) { metrics.start();
p.sendMessage(message); } catch (IOException e) {
} logger.severe("Could not submit stats.");
} }
}
} reloadConfig();
saveDefaultConfig();
if (broadcast != null) {
for (String message : broadcast) { sqlite = new SQLite(this);
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + message); sqlite.load();
}
} switch (Utils.getVersion(getServer())) {
case "v1_8_R1":
utils = new Utils_1_8_R1();
break;
case "v1_8_R2":
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:
logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!");
getServer().getPluginManager().disablePlugin(this);
return;
}
if (getServer().getPluginManager().getPlugin("LWC") != null) {
Plugin lwcp = getServer().getPluginManager().getPlugin("LWC");
lwc = ((LWCPlugin) lwcp).getLWC();
} else {
lwc = null;
}
if (getServer().getPluginManager().getPlugin("Lockette") != null) {
lockette = true;
} else {
lockette = false;
}
setupPermissions();
instance = this;
UpdateChecker uc = new UpdateChecker(this, getDescription().getWebsite());
UpdateCheckerResult result = uc.updateNeeded();
if (Config.enable_broadcast()) broadcast = uc.getBroadcast();
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.checking_update());
if (result == UpdateCheckerResult.TRUE) {
latestVersion = uc.getVersion();
downloadLink = uc.getLink();
isUpdateNeeded = true;
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.update_available(latestVersion));
for (Player p : getServer().getOnlinePlayers()) {
if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb;
switch (Utils.getVersion(getServer())) {
case "v1_8_R1":
jb = new JsonBuilder_1_8_R1(Config.update_available(latestVersion));
break;
case "v1_8_R2":
jb = new JsonBuilder_1_8_R2(Config.update_available(latestVersion));
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);
}
}
} else if (result == UpdateCheckerResult.FALSE) {
latestVersion = "";
downloadLink = "";
isUpdateNeeded = false;
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.no_new_update());
} else {
latestVersion = "";
downloadLink = "";
isUpdateNeeded = false;
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + Config.update_check_error());
}
for (Player p : getServer().getOnlinePlayers()) {
if (perm.has(p, "shopchest.broadcast")) {
if (broadcast != null) {
for (String message : broadcast) {
p.sendMessage(message);
}
}
}
}
if (broadcast != null) {
for (String message : broadcast) {
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + message);
}
}
File itemNamesFile = new File(getDataFolder(), "item_names.txt");
if (!itemNamesFile.exists())
try {
itemNamesFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
copy(getResource("item_names.txt"), itemNamesFile);
try {
Commands.registerCommand(new Commands(this, Config.main_command_name(), "Manage Shops.", "", new ArrayList<String>()), this);
} catch (Exception e) {
e.printStackTrace();
}
initializeShops();
getServer().getPluginManager().registerEvents(new UpdateHolograms(), this);
getServer().getPluginManager().registerEvents(new RegenerateShopItem(), this);
getServer().getPluginManager().registerEvents(new InteractShop(this), this);
getServer().getPluginManager().registerEvents(new NotifyUpdate(), this);
getServer().getPluginManager().registerEvents(new ProtectChest(), this);
getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this);
if (getServer().getPluginManager().getPlugin("ClearLag") != null)
getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this);
}
@Override
public void onDisable() {
utils.removeShops();
}
private void initializeShops() {
int count = 0;
for (int id = 1; id < sqlite.getHighestID() + 1; id++) {
try {
Shop shop = sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
logger.info("Initialized " + String.valueOf(count) + " Shops");
}
File itemNamesFile = new File(getDataFolder(), "item_names.txt");
if (!itemNamesFile.exists())
try {itemNamesFile.createNewFile();} catch (IOException e) {e.printStackTrace();}
copy(getResource("item_names.txt"), itemNamesFile);
try {
Commands.registerCommand(new Commands(this, Config.main_command_name(), "Manage Shops.", "", new ArrayList<String>()), this);
} catch (Exception e) {
e.printStackTrace();
}
initializeShops();
getServer().getPluginManager().registerEvents(new UpdateHolograms(), this);
getServer().getPluginManager().registerEvents(new RegenerateShopItem(), this);
getServer().getPluginManager().registerEvents(new InteractShop(this), this);
getServer().getPluginManager().registerEvents(new NotifyUpdate(), this);
getServer().getPluginManager().registerEvents(new ProtectChest(), this);
getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this);
if (getServer().getPluginManager().getPlugin("ClearLag") != null) getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this);
}
@Override
public void onDisable() {
utils.removeShops();
}
private void initializeShops() {
int count = 0;
for (int id = 1; id < sqlite.getHighestID() + 1; id++) {
try {
Shop shop = sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
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,181 +1,353 @@
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> shopLimits_group() {return (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").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 boolean buy_greater_or_equal_sell() {return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");}
public static boolean hopper_protection() {return plugin.getConfig().getBoolean("hopper-protection");}
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 int default_limit() {return plugin.getConfig().getInt("shop-limits.default");}
public static String main_command_name() { return plugin.getConfig().getString("main-command-name");}
public static String currency_symbol() { return plugin.getConfig().getString("currency-symbol").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");}
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 String chest_no_shop() { return plugin.getConfig().getString("messages.chest-no-shop").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) {
return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String reloaded_shops(int amount) { public static Set<String> minimum_prices() {
return plugin.getConfig().getString("messages.reloaded-shops").replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true);
} }
public static String opened_shop(String vendor) { public static Set<String> shopLimits_group() {
return plugin.getConfig().getString("messages.opened-shop").replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);
} }
public static String buyPrice_too_low(double minPrice) { public static Set<String> shopLimits_player() {
return plugin.getConfig().getString("messages.buy-price-too-low").replace(Regex.minPrice, String.valueOf(minPrice)).replace(Regex.currencySymbol, currency_symbol()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);
} }
public static String sellPrice_too_low(double minPrice) { public static List<String> blacklist() {
return plugin.getConfig().getString("messages.sell-price-too-low").replace(Regex.minPrice, String.valueOf(minPrice)).replace(Regex.currencySymbol, currency_symbol()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList<String>() : plugin.getConfig().getStringList("blacklist");
} }
public static String update_available(String version) { public static boolean buy_greater_or_equal_sell() {
return plugin.getConfig().getString("messages.update.update-available").replace(Regex.version, version); return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");
} }
public static String hologram_format(int amount, String itemName) { public static boolean hopper_protection() {
return plugin.getConfig().getString("messages.hologram.format").replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getBoolean("hopper-protection");
} }
public static String hologram_buy_sell(double buyPrice, double sellPrice) { public static boolean explosion_protection() {
return plugin.getConfig().getString("messages.hologram.buy-and-sell").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getBoolean("explosion-protection)");
} }
public static String hologram_buy(double buyPrice) { public static boolean enable_broadcast() {
return plugin.getConfig().getString("messages.hologram.only-buy").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getBoolean("enable-broadcast");
} }
public static String hologram_sell(double sellPrice) { public static double maximal_distance() {
return plugin.getConfig().getString("messages.hologram.only-sell").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getDouble("maximal-distance");
} }
public static String error_occurred(String error) { public static int default_limit() {
return plugin.getConfig().getString("messages.error-occurred").replace(Regex.error, error).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getInt("shop-limits.default");
} }
public static String shopInfo_vendor(String vendor) { public static String main_command_name() {
return plugin.getConfig().getString("messages.shop-info.vendor").replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("main-command-name");
} }
public static String shopInfo_product(int amount, String itemName) { public static String currency_symbol() {
return plugin.getConfig().getString("messages.shop-info.product").replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("currency-symbol").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String shopInfo_enchantment(String enchantment) { public static String shop_created() {
return plugin.getConfig().getString("messages.shop-info.enchantments").replace(Regex.enchantment, enchantment).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.shop-created").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String shopInfo_arrowEffect(String arrowEffect) { public static String chest_already_shop() {
return plugin.getConfig().getString("messages.shop-info.arrow-effect").replace(Regex.arrowEffect, arrowEffect).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 shopInfo_price(double buyPrice, double sellPrice) { public static String shop_removed() {
if ((buyPrice <= 0) && (sellPrice > 0)) { return plugin.getConfig().getString("messages.shop-removed").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice + currency_symbol(), disabled()).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); }
} else if ((sellPrice <= 0) && (buyPrice > 0)) {
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice + currency_symbol(), disabled()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); public static String chest_no_shop() {
} else if ((sellPrice > 0) && (buyPrice > 0)) { return plugin.getConfig().getString("messages.chest-no-shop").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); }
} else {
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice + currency_symbol(), disabled()).replace(Regex.sellPrice + currency_symbol(), disabled()).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 buy_success(int amount, String itemName, double buyPrice, String vendor) { public static String not_enough_inventory_space() {
return plugin.getConfig().getString("messages.buy-success").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.not-enough-inventory-space").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String buy_success_admin(int amount, String itemName, double buyPrice) { public static String chest_not_enough_inventory_space() {
return plugin.getConfig().getString("messages.buy-success-admin").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.buyPrice, String.valueOf(buyPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.chest-not-enough-inventory-space").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String sell_success(int amount, String itemName, double sellPrice, String vendor) { public static String not_enough_money() {
return plugin.getConfig().getString("messages.sell-success").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.not-enough-money").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String sell_success_admin(int amount, String itemName, double sellPrice) { public static String not_enough_items() {
return plugin.getConfig().getString("messages.sell-success-admin").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.not-enough-items").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String someone_bought(int amount, String itemName, double buyPrice, String player) { public static String vendor_not_enough_money() {
return plugin.getConfig().getString("messages.someone-bought").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.player, player).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.vendor-not-enough-money").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String someone_sold(int amount, String itemName, double sellPrice, String player) { public static String out_of_stock() {
return plugin.getConfig().getString("messages.someone-sold").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replace(Regex.player, player).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.out-of-stock").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String occupied_shop_slots(int limit, int amount) { public static String amount_and_price_not_number() {
return plugin.getConfig().getString("messages.occupied-shop-slots").replace(Regex.limit, String.valueOf(limit)).replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); return plugin.getConfig().getString("messages.amount-and-price-not-number").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }
public static String shopInfo_stock(int amount) { public static String no_item_in_hand() {
return plugin.getConfig().getString("messages.shop-info.stock").replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); 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) {
return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String reloaded_shops(int amount) {
return plugin.getConfig().getString("messages.reloaded-shops").replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String opened_shop(String vendor) {
return plugin.getConfig().getString("messages.opened-shop").replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String buyPrice_too_low(double minPrice) {
return plugin.getConfig().getString("messages.buy-price-too-low").replace(Regex.minPrice, String.valueOf(minPrice)).replace(Regex.currencySymbol, currency_symbol()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String sellPrice_too_low(double minPrice) {
return plugin.getConfig().getString("messages.sell-price-too-low").replace(Regex.minPrice, String.valueOf(minPrice)).replace(Regex.currencySymbol, currency_symbol()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String update_available(String version) {
return plugin.getConfig().getString("messages.update.update-available").replace(Regex.version, version);
}
public static String hologram_format(int amount, String itemName) {
return plugin.getConfig().getString("messages.hologram.format").replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String hologram_buy_sell(double buyPrice, double sellPrice) {
return plugin.getConfig().getString("messages.hologram.buy-and-sell").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String hologram_buy(double buyPrice) {
return plugin.getConfig().getString("messages.hologram.only-buy").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String hologram_sell(double sellPrice) {
return plugin.getConfig().getString("messages.hologram.only-sell").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String error_occurred(String error) {
return plugin.getConfig().getString("messages.error-occurred").replace(Regex.error, error).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_vendor(String vendor) {
return plugin.getConfig().getString("messages.shop-info.vendor").replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_product(int amount, String itemName) {
return plugin.getConfig().getString("messages.shop-info.product").replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_enchantment(String enchantment) {
return plugin.getConfig().getString("messages.shop-info.enchantments").replace(Regex.enchantment, enchantment).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_arrowEffect(String arrowEffect) {
return plugin.getConfig().getString("messages.shop-info.arrow-effect").replace(Regex.arrowEffect, arrowEffect).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_price(double buyPrice, double sellPrice) {
if ((buyPrice <= 0) && (sellPrice > 0)) {
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice + currency_symbol(), disabled()).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} else if ((sellPrice <= 0) && (buyPrice > 0)) {
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice + currency_symbol(), disabled()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} else if ((sellPrice > 0) && (buyPrice > 0)) {
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} else {
return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice + currency_symbol(), disabled()).replace(Regex.sellPrice + currency_symbol(), disabled()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
}
public static String buy_success(int amount, String itemName, double buyPrice, String vendor) {
return plugin.getConfig().getString("messages.buy-success").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String buy_success_admin(int amount, String itemName, double buyPrice) {
return plugin.getConfig().getString("messages.buy-success-admin").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.buyPrice, String.valueOf(buyPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String sell_success(int amount, String itemName, double sellPrice, String vendor) {
return plugin.getConfig().getString("messages.sell-success").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replace(Regex.vendor, vendor).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String sell_success_admin(int amount, String itemName, double sellPrice) {
return plugin.getConfig().getString("messages.sell-success-admin").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String someone_bought(int amount, String itemName, double buyPrice, String player) {
return plugin.getConfig().getString("messages.someone-bought").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.buyPrice, String.valueOf(buyPrice)).replace(Regex.player, player).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String someone_sold(int amount, String itemName, double sellPrice, String player) {
return plugin.getConfig().getString("messages.someone-sold").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.amount, String.valueOf(amount)).replace(Regex.itemName, itemName).replace(Regex.sellPrice, String.valueOf(sellPrice)).replace(Regex.player, player).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String occupied_shop_slots(int limit, int amount) {
return plugin.getConfig().getString("messages.occupied-shop-slots").replace(Regex.limit, String.valueOf(limit)).replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_stock(int amount) {
return plugin.getConfig().getString("messages.shop-info.stock").replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
} }

View File

@ -2,19 +2,19 @@ package de.epiceric.shopchest.config;
public class Regex { public class Regex {
public static String vendor = "%VENDOR%"; public static String vendor = "%VENDOR%";
public static String amount = "%AMOUNT%"; public static String amount = "%AMOUNT%";
public static String itemName = "%ITEMNAME%"; public static String itemName = "%ITEMNAME%";
public static String price = "%PRICE%"; public static String price = "%PRICE%";
public static String currencySymbol = "%CURRENCY-SYMBOL%"; public static String currencySymbol = "%CURRENCY-SYMBOL%";
public static String error = "%ERROR%"; public static String error = "%ERROR%";
public static String enchantment = "%ENCHANTMENT%"; public static String enchantment = "%ENCHANTMENT%";
public static String minPrice = "%MIN-PRICE%"; public static String minPrice = "%MIN-PRICE%";
public static String version = "%VERSION%"; public static String version = "%VERSION%";
public static String buyPrice = "%BUY-PRICE%"; public static String buyPrice = "%BUY-PRICE%";
public static String sellPrice = "%SELL-PRICE%"; public static String sellPrice = "%SELL-PRICE%";
public static String limit = "%LIMIT%"; public static String limit = "%LIMIT%";
public static String player = "%PLAYER%"; public static String player = "%PLAYER%";
public static String arrowEffect = "%ARROW-EFFECT%"; public static String arrowEffect = "%ARROW-EFFECT%";
} }

File diff suppressed because it is too large Load Diff

View File

@ -6,12 +6,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent; 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,52 +1,63 @@
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
public void onPlayerJoin(PlayerJoinEvent e) { @EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
Player p = e.getPlayer();
if (ShopChest.isUpdateNeeded) {
if (p.isOp() || perm.has(p, "shopchest.notification.update")) { if (ShopChest.isUpdateNeeded) {
JsonBuilder jb; if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb;
switch (Utils.getVersion(ShopChest.getInstance().getServer())) {
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)); break; switch (Utils.getVersion(ShopChest.getInstance().getServer())) {
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)); break; case "v1_8_R1":
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)); break; jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion));
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)); break; break;
case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion)); break; case "v1_8_R2":
default: return; jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion));
} break;
jb.sendJson(p); case "v1_8_R3":
} jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion));
} break;
case "v1_9_R1":
if (perm.has(p, "shopchest.broadcast")) { jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion));
if (ShopChest.broadcast != null) { break;
for (String message : ShopChest.broadcast) { case "v1_9_R2":
p.sendMessage(message); jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion));
} break;
} default:
} return;
}
} jb.sendJson(p);
}
}
if (perm.has(p, "shopchest.broadcast")) {
if (ShopChest.broadcast != null) {
for (String message : ShopChest.broadcast) {
p.sendMessage(message);
}
}
}
}
} }

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,110 +19,108 @@ 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
public void onBlockBreak(BlockBreakEvent e) { @EventHandler
if (ShopUtils.isShop(e.getBlock().getLocation())) { public void onBlockBreak(BlockBreakEvent e) {
e.setCancelled(true); if (ShopUtils.isShop(e.getBlock().getLocation())) {
e.getPlayer().sendMessage(Config.cannot_break_shop()); e.setCancelled(true);
} e.getPlayer().sendMessage(Config.cannot_break_shop());
} }
}
@EventHandler
public void onBlockExplode(BlockExplodeEvent e) { @EventHandler
if (Config.explosion_protection()) { public void onBlockExplode(BlockExplodeEvent e) {
ArrayList<Block> bl = new ArrayList<>(e.blockList()); if (Config.explosion_protection()) {
for (Block b : bl) { ArrayList<Block> bl = new ArrayList<>(e.blockList());
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { for (Block b : bl) {
if (ShopUtils.isShop(b.getLocation())) e.blockList().remove(b); if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
} if (ShopUtils.isShop(b.getLocation())) e.blockList().remove(b);
} }
} }
} }
}
@EventHandler
public void onEntityExplode(EntityExplodeEvent e) { @EventHandler
if (Config.explosion_protection()) { public void onEntityExplode(EntityExplodeEvent e) {
ArrayList<Block> bl = new ArrayList<>(e.blockList()); if (Config.explosion_protection()) {
for (Block b : bl) { ArrayList<Block> bl = new ArrayList<>(e.blockList());
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { for (Block b : bl) {
if (ShopUtils.isShop(b.getLocation())) e.blockList().remove(b); if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
} if (ShopUtils.isShop(b.getLocation())) e.blockList().remove(b);
} }
} }
} }
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) { @EventHandler
Block b = e.getBlockPlaced(); public void onBlockPlace(BlockPlaceEvent e) {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { Block b = e.getBlockPlaced();
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
Chest c = (Chest) b.getState();
InventoryHolder ih = c.getInventory().getHolder(); Chest c = (Chest) b.getState();
InventoryHolder ih = c.getInventory().getHolder();
if (ih instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) ih; if (ih instanceof DoubleChest) {
Chest r = (Chest) dc.getRightSide(); DoubleChest dc = (DoubleChest) ih;
Chest l = (Chest) dc.getLeftSide(); Chest r = (Chest) dc.getRightSide();
Chest l = (Chest) dc.getLeftSide();
if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) {
Shop shop; if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) {
Shop shop;
if (b.getLocation().equals(r.getLocation())) {
shop = ShopUtils.getShop(l.getLocation()); if (b.getLocation().equals(r.getLocation())) {
ShopUtils.removeShop(shop); shop = ShopUtils.getShop(l.getLocation());
ShopChest.sqlite.removeShop(shop); ShopUtils.removeShop(shop);
} else if (b.getLocation().equals(l.getLocation())) { ShopChest.sqlite.removeShop(shop);
shop = ShopUtils.getShop(r.getLocation()); } else if (b.getLocation().equals(l.getLocation())) {
ShopUtils.removeShop(shop); shop = ShopUtils.getShop(r.getLocation());
ShopChest.sqlite.removeShop(shop); ShopUtils.removeShop(shop);
} else { ShopChest.sqlite.removeShop(shop);
return; } else {
} return;
}
if (shop.hasItem()) shop.getItem().remove();
if (shop.hasItem()) shop.getItem().remove();
Shop newShop = new Shop(ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
newShop.createHologram(); Shop newShop = new Shop(ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
newShop.createItem(); newShop.createHologram();
ShopUtils.addShop(newShop); newShop.createItem();
ShopChest.sqlite.addShop(newShop); ShopUtils.addShop(newShop);
ShopChest.sqlite.addShop(newShop);
}
}
}
}
}
} }
}
@EventHandler(priority = EventPriority.HIGH)
public void onItemMove(InventoryMoveItemEvent e) { @EventHandler(priority = EventPriority.HIGH)
if (Config.hopper_protection()) { public void onItemMove(InventoryMoveItemEvent e) {
if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) { if (Config.hopper_protection()) {
if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {
if (e.getSource().getHolder() instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) e.getSource().getHolder(); if (e.getSource().getHolder() instanceof DoubleChest) {
Chest r = (Chest) dc.getRightSide(); DoubleChest dc = (DoubleChest) e.getSource().getHolder();
Chest l = (Chest) dc.getLeftSide(); Chest r = (Chest) dc.getRightSide();
Chest l = (Chest) dc.getLeftSide();
if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) e.setCancelled(true);
if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) e.setCancelled(true);
} else if (e.getSource().getHolder() instanceof Chest) {
Chest c = (Chest) e.getSource().getHolder(); } else if (e.getSource().getHolder() instanceof Chest) {
Chest c = (Chest) e.getSource().getHolder();
if (ShopUtils.isShop(c.getLocation())) e.setCancelled(true);
} if (ShopUtils.isShop(c.getLocation())) e.setCancelled(true);
}
}
} }
} }
}
} }

View File

@ -11,25 +11,26 @@ import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
public class RegenerateShopItem implements Listener { public class RegenerateShopItem implements Listener {
public RegenerateShopItem() {} public RegenerateShopItem() {
}
@EventHandler(priority = EventPriority.HIGH)
public void onItemDespawn(ItemDespawnEvent e) { @EventHandler(priority = EventPriority.HIGH)
Item item = e.getEntity(); public void onItemDespawn(ItemDespawnEvent e) {
if (item.hasMetadata("shopItem")) e.setCancelled(true); Item item = e.getEntity();
} if (item.hasMetadata("shopItem")) e.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPickUpItem(PlayerPickupItemEvent e) { @EventHandler(priority = EventPriority.HIGH)
if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true); public void onPlayerPickUpItem(PlayerPickupItemEvent e) {
} if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGH)
public void onItemPickup(InventoryPickupItemEvent e) { @EventHandler(priority = EventPriority.HIGH)
if (e.getInventory().getType().equals(InventoryType.HOPPER)) { public void onItemPickup(InventoryPickupItemEvent e) {
if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true); if (e.getInventory().getType().equals(InventoryType.HOPPER)) {
} if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
} }
}
} }

View File

@ -1,26 +1,26 @@
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 {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onEntityRemove(me.minebuilders.clearlag.events.EntityRemoveEvent e) { public void onEntityRemove(me.minebuilders.clearlag.events.EntityRemoveEvent e) {
boolean containsShopItem = false; boolean containsShopItem = false;
for (Entity entity : e.getEntityList()) { for (Entity entity : e.getEntityList()) {
if (entity.hasMetadata("shopItem")) { if (entity.hasMetadata("shopItem")) {
containsShopItem = true; containsShopItem = true;
break; break;
} }
} }
if (containsShopItem) ShopChest.utils.reload(null); if (containsShopItem) ShopChest.utils.reload(null);
} }
} }

View File

@ -1,53 +1,53 @@
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() {
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
Location playerLocation = p.getLocation();
for (Shop shop : ShopUtils.getShops()) {
if (shop.getHologram() != null) {
Location shopLocation = shop.getLocation();
if (playerLocation.getWorld().equals(shopLocation.getWorld())) {
if (playerLocation.distance(shop.getHologram().getLocation()) <= Config.maximal_distance()) {
if (!shop.getHologram().isVisible(p)) {
shop.getHologram().showPlayer(p);
}
} else {
if (shop.getHologram().isVisible(p)) {
shop.getHologram().hidePlayer(p);
}
}
}
}
}
}
public UpdateHolograms() {}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
Location playerLocation = p.getLocation();
for (Shop shop : ShopUtils.getShops()) {
if (shop.getHologram() != null) {
Location shopLocation = shop.getLocation();
if (playerLocation.getWorld().equals(shopLocation.getWorld())) {
if (playerLocation.distance(shop.getHologram().getLocation()) <= Config.maximal_distance()) {
if (!shop.getHologram().isVisible(p)) {
shop.getHologram().showPlayer(p);
}
} else {
if (shop.getHologram().isVisible(p)) {
shop.getHologram().hidePlayer(p);
}
}
}
}
}
}
} }

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 void showPlayer(OfflinePlayer p); public List<?> getEntities();
public void hidePlayer(OfflinePlayer p);
public boolean isVisible(OfflinePlayer p); public void showPlayer(OfflinePlayer p);
public void hidePlayer(OfflinePlayer p);
public boolean isVisible(OfflinePlayer p);
} }

View File

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

View File

@ -11,44 +11,40 @@ import org.bukkit.inventory.meta.ItemMeta;
public abstract class Utils { public abstract class Utils {
public abstract void reload(Player p); public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) {
ItemStack[] items = inventory.getContents();
public abstract void removeShops(); int amount = 0;
for (ItemStack item : items) {
public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) { if ((item != null) && (item.getType().equals(type)) && (item.getDurability() == damage) && (item.getAmount() > 0) && (item.getItemMeta().equals(itemMeta))) {
ItemStack[] items = inventory.getContents(); amount += item.getAmount();
int amount = 0; }
for (ItemStack item : items) { }
if ((item != null) && (item.getType().equals(type)) && (item.getDurability() == damage) && (item.getAmount() > 0) && (item.getItemMeta().equals(itemMeta))) { return amount;
amount += item.getAmount(); }
}
} public static String getVersion(Server server) {
return amount; String packageName = server.getClass().getPackage().getName();
}
return packageName.substring(packageName.lastIndexOf('.') + 1);
public static String getVersion(Server server) { }
String packageName = server.getClass().getPackage().getName();
public static boolean isUUID(String string) {
return packageName.substring(packageName.lastIndexOf('.') + 1); return string.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");
} }
public static boolean isUUID(String string) { public static String encode(ItemStack itemStack) {
return string.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");
}
public static String encode(ItemStack itemStack) {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.set("i", itemStack); config.set("i", itemStack);
return new String(Base64.encodeBase64(config.saveToString().getBytes())); return new String(Base64.encodeBase64(config.saveToString().getBytes()));
} }
public static String toString(ItemStack itemStack) { public static String toString(ItemStack itemStack) {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.set("i", itemStack); config.set("i", itemStack);
return config.saveToString(); return config.saveToString();
} }
public static ItemStack decode(String string) { public static ItemStack decode(String string) {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
try { try {
config.loadFromString(new String(Base64.decodeBase64(string.getBytes()))); config.loadFromString(new String(Base64.decodeBase64(string.getBytes())));
@ -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,52 +1,50 @@
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) {
this.text = text; this.text = text;
this.location = location;
create();
}
public Hologram_1_8_R1(String text, Location location) {
this.text = new String[] {text};
this.location = location; this.location = location;
create(); create();
} }
public Hologram_1_8_R1(String text, Location location) {
this.text = new String[]{text};
this.location = location;
create();
}
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public List<EntityArmorStand> getEntities() { public List<EntityArmorStand> getEntities() {
return entitylist; return entitylist;
} }
public void showPlayer(OfflinePlayer p) { public void showPlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
@ -54,34 +52,35 @@ public class Hologram_1_8_R1 implements Hologram {
} }
public void hidePlayer(OfflinePlayer p) { public void hidePlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId()); PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
visible.put(p, false); visible.put(p, false);
} }
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() {
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) { private void create() {
this.location.add(0, this.DISTANCE, 0); for (String text : this.text) {
} EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
this.count = 0; entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) {
this.location.add(0, this.DISTANCE, 0);
}
this.count = 0;
} }
} }

View File

@ -1,52 +1,50 @@
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) {
this.text = text; this.text = text;
this.location = location;
create();
}
public Hologram_1_8_R2(String text, Location location) {
this.text = new String[] {text};
this.location = location; this.location = location;
create(); create();
} }
public Hologram_1_8_R2(String text, Location location) {
this.text = new String[]{text};
this.location = location;
create();
}
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public List<EntityArmorStand> getEntities() { public List<EntityArmorStand> getEntities() {
return entitylist; return entitylist;
} }
public void showPlayer(OfflinePlayer p) { public void showPlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
@ -54,34 +52,35 @@ public class Hologram_1_8_R2 implements Hologram {
} }
public void hidePlayer(OfflinePlayer p) { public void hidePlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId()); PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
visible.put(p, false); visible.put(p, false);
} }
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() {
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) { private void create() {
this.location.add(0, this.DISTANCE, 0); for (String text : this.text) {
} EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
this.count = 0; entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) {
this.location.add(0, this.DISTANCE, 0);
}
this.count = 0;
} }
} }

View File

@ -1,52 +1,50 @@
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) {
this.text = text; this.text = text;
this.location = location;
create();
}
public Hologram_1_8_R3(String text, Location location) {
this.text = new String[] {text};
this.location = location; this.location = location;
create(); create();
} }
public Hologram_1_8_R3(String text, Location location) {
this.text = new String[]{text};
this.location = location;
create();
}
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public List<EntityArmorStand> getEntities() { public List<EntityArmorStand> getEntities() {
return entitylist; return entitylist;
} }
public void showPlayer(OfflinePlayer p) { public void showPlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
@ -54,34 +52,35 @@ public class Hologram_1_8_R3 implements Hologram {
} }
public void hidePlayer(OfflinePlayer p) { public void hidePlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId()); PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
visible.put(p, false); visible.put(p, false);
} }
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() {
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) { private void create() {
this.location.add(0, this.DISTANCE, 0); for (String text : this.text) {
} EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
this.count = 0; entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) {
this.location.add(0, this.DISTANCE, 0);
}
this.count = 0;
} }
} }

View File

@ -1,52 +1,50 @@
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) {
this.text = text; this.text = text;
this.location = location;
create();
}
public Hologram_1_9_R1(String text, Location location) {
this.text = new String[] {text};
this.location = location; this.location = location;
create(); create();
} }
public Hologram_1_9_R1(String text, Location location) {
this.text = new String[]{text};
this.location = location;
create();
}
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public List<EntityArmorStand> getEntities() { public List<EntityArmorStand> getEntities() {
return entitylist; return entitylist;
} }
public void showPlayer(OfflinePlayer p) { public void showPlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
@ -54,34 +52,35 @@ public class Hologram_1_9_R1 implements Hologram {
} }
public void hidePlayer(OfflinePlayer p) { public void hidePlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId()); PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
visible.put(p, false); visible.put(p, false);
} }
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() {
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) { private void create() {
this.location.add(0, this.DISTANCE, 0); for (String text : this.text) {
} EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
this.count = 0; entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) {
this.location.add(0, this.DISTANCE, 0);
}
this.count = 0;
} }
} }

View File

@ -1,52 +1,50 @@
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) {
this.text = text; this.text = text;
this.location = location;
create();
}
public Hologram_1_9_R2(String text, Location location) {
this.text = new String[] {text};
this.location = location; this.location = location;
create(); create();
} }
public Hologram_1_9_R2(String text, Location location) {
this.text = new String[]{text};
this.location = location;
create();
}
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public List<EntityArmorStand> getEntities() { public List<EntityArmorStand> getEntities() {
return entitylist; return entitylist;
} }
public void showPlayer(OfflinePlayer p) { public void showPlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
@ -54,34 +52,35 @@ public class Hologram_1_9_R2 implements Hologram {
} }
public void hidePlayer(OfflinePlayer p) { public void hidePlayer(OfflinePlayer p) {
for (Object o : entitylist) { for (Object o : entitylist) {
EntityArmorStand armor = (EntityArmorStand) o; EntityArmorStand armor = (EntityArmorStand) o;
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId()); PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
visible.put(p, false); visible.put(p, false);
} }
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() {
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) { private void create() {
this.location.add(0, this.DISTANCE, 0); for (String text : this.text) {
} EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(), this.location.getX(), this.location.getY(), this.location.getZ());
this.count = 0; entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setGravity(false);
entitylist.add(entity);
this.location.subtract(0, this.DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) {
this.location.add(0, this.DISTANCE, 0);
}
this.count = 0;
} }
} }

View File

@ -1,111 +1,112 @@
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 {
/* JsonBuilder by FisheyLP */ /* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_8_R1(String... text) {
for(String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R1 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1");
if(!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for(String word : words) {
try {
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);
} catch(Exception e){}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R1 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_8_R1(String... text) {
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R1 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
} }
} String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
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) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R1 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,111 +1,112 @@
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 {
/* JsonBuilder by FisheyLP */ /* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_8_R2(String... text) {
for(String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R2 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1");
if(!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for(String word : words) {
try {
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);
} catch(Exception e){}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R2 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R2 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R2 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R2 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R2 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_8_R2(String... text) {
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R2 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
} }
} String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
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) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R2 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R2 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R2 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R2 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R2 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,111 +1,112 @@
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 {
/* JsonBuilder by FisheyLP */ /* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_8_R3(String... text) {
for(String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R3 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1");
if(!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for(String word : words) {
try {
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);
} catch(Exception e){}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R3 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R3 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R3 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R3 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R3 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_8_R3(String... text) {
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R3 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
} }
} String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
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) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R3 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R3 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R3 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R3 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R3 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,111 +1,112 @@
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 {
/* JsonBuilder by FisheyLP */ /* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_9_R1(String... text) {
for(String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_9_R1 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1");
if(!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for(String word : words) {
try {
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);
} catch(Exception e){}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_9_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_9_R1 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_9_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_9_R1(String... text) {
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_9_R1 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
} }
} String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
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) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_9_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_9_R1 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_9_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,111 +1,112 @@
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 {
/* JsonBuilder by FisheyLP */ /* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_9_R2(String... text) {
for(String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_9_R2 parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "§$1");
if(!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for(String word : words) {
try {
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);
} catch(Exception e){}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_9_R2 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R2 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_9_R2 withColor(String color) {
while(color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_9_R2 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R2 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ ","+segment+"}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_9_R2(String... text) {
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_9_R2 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink);
return this;
} }
} String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
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) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_9_R2 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R2 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_9_R2 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_9_R2 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R2 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
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\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,85 +1,84 @@
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 {
@Override @Override
public void reload(Player player) { public void reload(Player player) {
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram(); Hologram hologram = shop.getHologram();
if (shop.hasItem()) shop.getItem().remove();
ShopUtils.removeShop(shop);
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) { if (shop.hasItem()) shop.getItem().remove();
EntityArmorStand e = (EntityArmorStand) o; ShopUtils.removeShop(shop);
e.getWorld().removeEntity(e);
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
@Override for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
public void removeShops() { hologram.hidePlayer(p);
for (Shop shop : ShopUtils.getShops()) { }
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
for (Object o : hologram.getEntities()) {
if (shop.hasItem()) shop.getItem().remove(); EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
} }
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
@Override
public void removeShops() {
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
if (shop.hasItem()) shop.getItem().remove();
}
}
} }

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,78 +7,80 @@ 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 {
@Override @Override
public void reload(Player player) { public void reload(Player player) {
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram(); Hologram hologram = shop.getHologram();
if (shop.hasItem()) shop.getItem().remove();
ShopUtils.removeShop(shop);
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) { if (shop.hasItem()) shop.getItem().remove();
EntityArmorStand e = (EntityArmorStand) o; ShopUtils.removeShop(shop);
e.getWorld().removeEntity(e);
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
@Override hologram.hidePlayer(p);
public void removeShops() { }
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
for (Object o : hologram.getEntities()) {
if (shop.hasItem()) shop.getItem().remove(); EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
} }
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
@Override
public void removeShops() {
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
if (shop.hasItem()) shop.getItem().remove();
}
}
} }

View File

@ -1,86 +1,85 @@
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 {
@Override @Override
public void reload(Player player) { public void reload(Player player) {
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram(); Hologram hologram = shop.getHologram();
if (shop.hasItem()) shop.getItem().remove();
ShopUtils.removeShop(shop);
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) { if (shop.hasItem()) shop.getItem().remove();
EntityArmorStand e = (EntityArmorStand) o; ShopUtils.removeShop(shop);
e.getWorld().removeEntity(e);
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
@Override hologram.hidePlayer(p);
public void removeShops() { }
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
for (Object o : hologram.getEntities()) {
if (shop.hasItem()) shop.getItem().remove(); EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
} }
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
@Override
public void removeShops() {
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
if (shop.hasItem()) shop.getItem().remove();
}
}
} }

View File

@ -1,86 +1,85 @@
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 {
@Override @Override
public void reload(Player player) { public void reload(Player player) {
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram(); Hologram hologram = shop.getHologram();
if (shop.hasItem()) shop.getItem().remove();
ShopUtils.removeShop(shop);
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) { if (shop.hasItem()) shop.getItem().remove();
EntityArmorStand e = (EntityArmorStand) o; ShopUtils.removeShop(shop);
e.getWorld().removeEntity(e);
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
@Override hologram.hidePlayer(p);
public void removeShops() { }
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
for (Object o : hologram.getEntities()) {
if (shop.hasItem()) shop.getItem().remove(); EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
} }
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
@Override
public void removeShops() {
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
if (shop.hasItem()) shop.getItem().remove();
}
}
} }

View File

@ -1,86 +1,85 @@
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 {
@Override @Override
public void reload(Player player) { public void reload(Player player) {
for (Shop shop : ShopUtils.getShops()) { for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram(); Hologram hologram = shop.getHologram();
if (shop.hasItem()) shop.getItem().remove();
ShopUtils.removeShop(shop);
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) { if (shop.hasItem()) shop.getItem().remove();
EntityArmorStand e = (EntityArmorStand) o; ShopUtils.removeShop(shop);
e.getWorld().removeEntity(e);
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
@Override hologram.hidePlayer(p);
public void removeShops() { }
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
for (Object o : hologram.getEntities()) {
if (shop.hasItem()) shop.getItem().remove(); EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
} }
}
}
int count = 0;
for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) {
try {
Shop shop = ShopChest.sqlite.getShop(id);
shop.createHologram();
shop.createItem();
ShopUtils.addShop(shop);
} catch (NullPointerException e) {
continue;
}
count++;
}
if (player != null) player.sendMessage(Config.reloaded_shops(count));
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
@Override
public void removeShops() {
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
for (Player p : Bukkit.getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
if (shop.hasItem()) shop.getItem().remove();
}
}
} }

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,185 +20,195 @@ 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 { private ShopChest plugin;
NORMAL, private OfflinePlayer vendor;
INFINITE, private ItemStack product;
ADMIN; private Location location;
} private Hologram hologram;
private Item item;
private ShopChest plugin; private double buyPrice;
private OfflinePlayer vendor; private double sellPrice;
private ItemStack product; private ShopType shopType;
private Location location; public Shop(ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
private Hologram hologram; this.plugin = plugin;
private Item item; this.vendor = vendor;
private double buyPrice; this.product = product;
private double sellPrice; this.location = location;
private ShopType shopType; this.buyPrice = buyPrice;
this.sellPrice = sellPrice;
public Shop(ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) { this.shopType = shopType;
this.plugin = plugin; }
this.vendor = vendor;
this.product = product; public void removeHologram() {
this.location = location; for (Player player : plugin.getServer().getOnlinePlayers()) {
this.buyPrice = buyPrice; getHologram().hidePlayer(player);
this.sellPrice = sellPrice; }
this.shopType = shopType; }
}
public void createItem() {
public void removeHologram() {
for (Player player : plugin.getServer().getOnlinePlayers()) { Item item;
getHologram().hidePlayer(player); Location itemLocation;
} ItemStack itemStack;
} ItemMeta itemMeta = product.getItemMeta().clone();
itemMeta.setDisplayName(UUID.randomUUID().toString());
public void createItem() {
ArrayList<String> lore = new ArrayList<>();
Item item; lore.add("Shop Item");
Location itemLocation; itemMeta.setLore(lore);
ItemStack itemStack;
ItemMeta itemMeta = product.getItemMeta().clone(); itemLocation = new Location(location.getWorld(), hologram.getLocation().getX(), location.getY() + 1, hologram.getLocation().getZ());
itemMeta.setDisplayName(UUID.randomUUID().toString()); itemStack = new ItemStack(product.getType(), 1, product.getDurability());
itemStack.setItemMeta(itemMeta);
ArrayList<String> lore = new ArrayList<>();
lore.add("Shop Item"); item = location.getWorld().dropItem(itemLocation, itemStack);
itemMeta.setLore(lore); item.setVelocity(new Vector(0, 0, 0));
item.setMetadata("shopItem", new FixedMetadataValue(plugin, true));
itemLocation = new Location(location.getWorld(), hologram.getLocation().getX(), location.getY() + 1, hologram.getLocation().getZ()); item.setCustomNameVisible(false);
itemStack = new ItemStack(product.getType(), 1, product.getDurability());
itemStack.setItemMeta(itemMeta); this.item = item;
}
item = location.getWorld().dropItem(itemLocation, itemStack);
item.setVelocity(new Vector(0, 0, 0)); public void createHologram() {
item.setMetadata("shopItem", new FixedMetadataValue(plugin, true));
item.setCustomNameVisible(false); boolean doubleChest;
this.item = item; Chest[] chests = new Chest[2];
}
Block b = location.getBlock();
public void createHologram() {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
boolean doubleChest;
Chest c = (Chest) b.getState();
Chest[] chests = new Chest[2]; InventoryHolder ih = c.getInventory().getHolder();
Block b = location.getBlock(); if (ih instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) ih;
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
Chest r = (Chest) dc.getRightSide();
Chest c = (Chest) b.getState(); Chest l = (Chest) dc.getLeftSide();
InventoryHolder ih = c.getInventory().getHolder();
chests[0] = r;
if (ih instanceof DoubleChest) { chests[1] = l;
DoubleChest dc = (DoubleChest) ih;
doubleChest = true;
Chest r = (Chest) dc.getRightSide();
Chest l = (Chest) dc.getLeftSide(); } else {
doubleChest = false;
chests[0] = r; chests[0] = c;
chests[1] = l; }
doubleChest = true; } else {
try {
} else { throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
doubleChest = false; } catch (Exception e) {
chests[0] = c; e.printStackTrace();
} }
return;
} else { }
try {
throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ()); Location holoLocation;
} catch (Exception e) { String[] holoText = new String[2];
e.printStackTrace();
} if (doubleChest) {
return;
} Chest r = chests[0];
Chest l = chests[1];
Location holoLocation;
String[] holoText = new String[2]; if (b.getLocation().equals(r.getLocation())) {
if (doubleChest) { if (r.getX() != l.getX())
holoLocation = new Location(b.getWorld(), b.getX(), b.getY() - 0.6, b.getZ() + 0.5);
Chest r = chests[0]; else if (r.getZ() != l.getZ())
Chest l = chests[1]; 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);
if (b.getLocation().equals(r.getLocation())) {
} else {
if (r.getX() != l.getX()) 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()); if (r.getX() != l.getX())
else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5); holoLocation = new Location(b.getWorld(), b.getX() + 1, b.getY() - 0.6, b.getZ() + 0.5);
else if (r.getZ() != l.getZ())
} else { 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);
if (r.getX() != l.getX()) 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);
}
holoText[0] = Config.hologram_format(product.getAmount(), ItemNames.lookup(product));
} else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
if ((buyPrice <= 0) && (sellPrice > 0)) holoText[1] = Config.hologram_sell(sellPrice);
holoText[0] = Config.hologram_format(product.getAmount(), ItemNames.lookup(product)); else if ((buyPrice > 0) && (sellPrice <= 0)) holoText[1] = Config.hologram_buy(buyPrice);
else if ((buyPrice > 0) && (sellPrice > 0)) holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice);
if ((buyPrice <= 0) && (sellPrice > 0)) holoText[1] = Config.hologram_sell(sellPrice); else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice);
else if ((buyPrice > 0) && (sellPrice <= 0)) holoText[1] = Config.hologram_buy(buyPrice);
else if ((buyPrice > 0) && (sellPrice > 0)) holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice); switch (Utils.getVersion(plugin.getServer())) {
else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice); case "v1_8_R1":
hologram = new Hologram_1_8_R1(holoText, holoLocation);
switch (Utils.getVersion(plugin.getServer())) { break;
case "v1_8_R1": hologram = new Hologram_1_8_R1(holoText, holoLocation); break; case "v1_8_R2":
case "v1_8_R2": hologram = new Hologram_1_8_R2(holoText, holoLocation); break; hologram = new Hologram_1_8_R2(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_R3":
case "v1_9_R2": hologram = new Hologram_1_9_R2(holoText, holoLocation); break; hologram = new Hologram_1_8_R3(holoText, holoLocation);
default: return; break;
} case "v1_9_R1":
hologram = new Hologram_1_9_R1(holoText, holoLocation);
} break;
case "v1_9_R2":
public OfflinePlayer getVendor() { hologram = new Hologram_1_9_R2(holoText, holoLocation);
return vendor; break;
} default:
return;
public ItemStack getProduct() { }
return product;
} }
public Location getLocation() { public OfflinePlayer getVendor() {
return location; return vendor;
} }
public double getBuyPrice() { public ItemStack getProduct() {
return buyPrice; return product;
} }
public double getSellPrice() { public Location getLocation() {
return sellPrice; return location;
} }
public ShopType getShopType() { public double getBuyPrice() {
return shopType; return buyPrice;
} }
public Hologram getHologram() { public double getSellPrice() {
return hologram; return sellPrice;
} }
public Item getItem() { public ShopType getShopType() {
return item; return shopType;
} }
public boolean hasItem() { public Hologram getHologram() {
return item != null; return hologram;
} }
public Item getItem() {
return item;
}
public boolean hasItem() {
return item != null;
}
public enum ShopType {
NORMAL,
INFINITE,
ADMIN;
}
} }

View File

@ -1,29 +1,24 @@
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 {
public String SQLiteCreateTokensTable = "CREATE TABLE IF NOT EXISTS shop_list (" + public String SQLiteCreateTokensTable = "CREATE TABLE IF NOT EXISTS shop_list (" +
"`id` int(11) NOT NULL," + "`id` int(11) NOT NULL," +
"`vendor` varchar(32) NOT NULL," + "`vendor` varchar(32) NOT NULL," +
"`product` varchar(32) NOT NULL," + "`product` varchar(32) NOT NULL," +
"`world` varchar(32) NOT NULL," + "`world` varchar(32) NOT NULL," +
@ -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;
public Database(ShopChest instance){ Connection connection;
public Database(ShopChest instance) {
plugin = instance; plugin = instance;
} }
@ -57,39 +50,39 @@ 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);
} }
} }
public void renameColumnInfiniteToShopType() { public void renameColumnInfiniteToShopType() {
Connection conn = null; Connection conn = null;
Statement s = null; Statement s = null;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
s = conn.createStatement(); s = conn.createStatement();
s.execute("ALTER TABLE " + table + " RENAME TO " + table + "_old"); s.execute("ALTER TABLE " + table + " RENAME TO " + table + "_old");
s.close(); s.close();
s.execute(SQLiteCreateTokensTable); s.execute(SQLiteCreateTokensTable);
s.close(); s.close();
s.execute("INSERT INTO " + table + "(id, vendor, product, world, x, y, z, buyprice, sellprice, shoptype) SELECT id, vendor, product, world, x, y, z, buyprice, sellprice, infinite FROM " + table + "_old"); s.execute("INSERT INTO " + table + "(id, vendor, product, world, x, y, z, buyprice, sellprice, shoptype) SELECT id, vendor, product, world, x, y, z, buyprice, sellprice, infinite FROM " + table + "_old");
s.close(); s.close();
conn.close(); conn.close();
conn = getSQLConnection(); conn = getSQLConnection();
s = conn.createStatement(); s = conn.createStatement();
s.execute("DROP TABLE " + table + "_old"); s.execute("DROP TABLE " + table + "_old");
s.close(); s.close();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally { } finally {
try { try {
if (s != null) if (s != null)
s.close(); s.close();
@ -100,39 +93,39 @@ public abstract class Database {
} }
} }
} }
public int getNextFreeID() { public int getNextFreeID() {
for (int i = 1; i < getHighestID() + 1; i++) { for (int i = 1; i < getHighestID() + 1; i++) {
if (getProduct(i) == null) { if (getProduct(i) == null) {
return i; return i;
} else { } else {
if (i == getHighestID()) { if (i == getHighestID()) {
return i + 1; return i + 1;
} }
} }
} }
return 1; return 1;
} }
public int getHighestID() { public int getHighestID() {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
int highestID = 1; int highestID = 1;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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");
} }
} }
return highestID; return highestID;
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally { } finally {
@ -145,40 +138,40 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return 0; return 0;
} }
public int getShopID(Shop shop) { public int getShopID(Shop shop) {
for (int i = 1; i < getHighestID() + 1; i++) { for (int i = 1; i < getHighestID() + 1; i++) {
try { try {
Shop s = getShop(i); Shop s = getShop(i);
if (s.getLocation().equals(shop.getLocation())) { if (s.getLocation().equals(shop.getLocation())) {
return i; return i;
} }
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
continue; continue;
} }
} }
return 0; return 0;
} }
public void removeShop(Shop shop) { public void removeShop(Shop shop) {
int id = getShopID(shop); int id = getShopID(shop);
if (id == 0) return; if (id == 0) return;
if (shop.hasItem()) shop.getItem().remove(); if (shop.hasItem()) shop.getItem().remove();
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("DELETE FROM " + table + " where id = " + id + ";"); ps = conn.prepareStatement("DELETE FROM " + table + " where id = " + id + ";");
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
@ -191,17 +184,17 @@ public abstract class Database {
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
} }
public void removeShop(int id) { public void removeShop(int id) {
if (id == 0) return; if (id == 0) return;
removeShop(getShop(id)); removeShop(getShop(id));
} }
private World getWorld(int id) { private World getWorld(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -209,10 +202,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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"));
} }
} }
@ -228,20 +221,20 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return null; return null;
} }
public OfflinePlayer getVendor(int id) { public OfflinePlayer getVendor(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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")));
} }
} }
@ -257,9 +250,9 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return null; return null;
} }
public ItemStack getProduct(int id) { public ItemStack getProduct(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -267,10 +260,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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"));
} }
} }
@ -286,9 +279,9 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return null; return null;
} }
private int getX(int id) { private int getX(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -296,10 +289,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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");
} }
} }
@ -315,9 +308,9 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return 0; return 0;
} }
private int getY(int id) { private int getY(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -325,10 +318,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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");
} }
} }
@ -344,9 +337,9 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return 0; return 0;
} }
private int getZ(int id) { private int getZ(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -354,10 +347,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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");
} }
} }
@ -373,13 +366,13 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return 0; return 0;
} }
public Location getLocation(int id) { public Location getLocation(int id) {
return new Location(getWorld(id), getX(id), getY(id), getZ(id)); return new Location(getWorld(id), getX(id), getY(id), getZ(id));
} }
public double getBuyPrice(int id) { public double getBuyPrice(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -387,10 +380,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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");
} }
} }
@ -406,9 +399,9 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return 0; return 0;
} }
public double getSellPrice(int id) { public double getSellPrice(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -416,10 +409,10 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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");
} }
} }
@ -435,9 +428,9 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return 0; return 0;
} }
public ShopType getShopType(int id) { public ShopType getShopType(int id) {
Connection conn = null; Connection conn = null;
PreparedStatement ps = null; PreparedStatement ps = null;
@ -445,26 +438,26 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
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();
ps.close(); ps.close();
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '1', 'INFINITE')"); ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '1', 'INFINITE')");
ps.executeUpdate(); ps.executeUpdate();
return getShopType(id); return getShopType(id);
} }
return ShopType.valueOf(rs.getString("shoptype")); return ShopType.valueOf(rs.getString("shoptype"));
} }
} }
} 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);
} }
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally { } finally {
try { try {
@ -476,20 +469,20 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return ShopType.NORMAL; return ShopType.NORMAL;
} }
public Shop getShop(int id) { public Shop getShop(int id) {
OfflinePlayer vendor = getVendor(id); OfflinePlayer vendor = getVendor(id);
Location location = getLocation(id); Location location = getLocation(id);
ItemStack product = getProduct(id); ItemStack product = getProduct(id);
double buyPrice = getBuyPrice(id); double buyPrice = getBuyPrice(id);
double sellPrice = getSellPrice(id); double sellPrice = getSellPrice(id);
ShopType shopType = getShopType(id); ShopType shopType = getShopType(id);
if (ShopUtils.isShop(location)) return ShopUtils.getShop(location); if (ShopUtils.isShop(location)) return ShopUtils.getShop(location);
else return new Shop(plugin, vendor, product, location, buyPrice, sellPrice, shopType); else return new Shop(plugin, vendor, product, location, buyPrice, sellPrice, shopType);
} }
@ -499,8 +492,8 @@ public abstract class Database {
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("REPLACE INTO " + table + " (id,vendor,product,world,x,y,z,buyprice,sellprice,shoptype) VALUES(?,?,?,?,?,?,?,?,?,?)"); ps = conn.prepareStatement("REPLACE INTO " + table + " (id,vendor,product,world,x,y,z,buyprice,sellprice,shoptype) VALUES(?,?,?,?,?,?,?,?,?,?)");
ps.setInt(1, id); ps.setInt(1, id);
ps.setString(2, shop.getVendor().getUniqueId().toString()); ps.setString(2, shop.getVendor().getUniqueId().toString());
ps.setString(3, Utils.encode(shop.getProduct())); ps.setString(3, Utils.encode(shop.getProduct()));
ps.setString(4, shop.getLocation().getWorld().getName()); ps.setString(4, shop.getLocation().getWorld().getName());
@ -510,7 +503,7 @@ public abstract class Database {
ps.setDouble(8, shop.getBuyPrice()); ps.setDouble(8, shop.getBuyPrice());
ps.setDouble(9, shop.getSellPrice()); ps.setDouble(9, shop.getSellPrice());
ps.setString(10, shop.getShopType().toString()); ps.setString(10, shop.getShopType().toString());
ps.executeUpdate(); ps.executeUpdate();
return; return;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -525,16 +518,16 @@ public abstract class Database {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
} }
} }
return; return;
} }
public void addShop(Shop shop) {
int id = getNextFreeID();
setShop(id, shop);
}
public void close(PreparedStatement ps,ResultSet rs){ public void addShop(Shop shop) {
int id = getNextFreeID();
setShop(id, shop);
}
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,44 +10,42 @@ 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.");
} }
return null; return null;
} }
public void load() { public void load() {
connection = getSQLConnection(); connection = getSQLConnection();
try { try {
Statement s = connection.createStatement(); Statement s = connection.createStatement();
s.executeUpdate(SQLiteCreateTokensTable); s.executeUpdate(SQLiteCreateTokensTable);

View File

@ -1,73 +1,108 @@
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 {
private static final Map<String, String> effectMap = ImmutableMap.<String, String>builder() private static final Map<String, String> effectMap = ImmutableMap.<String, String>builder()
.put("FIRE_RESISTANCE", "Fire Resistance") .put("FIRE_RESISTANCE", "Fire Resistance")
.put("INSTANT_DAMAGE", "Instant Damage") .put("INSTANT_DAMAGE", "Instant Damage")
.put("INSTANT_HEAL", "Instant Health") .put("INSTANT_HEAL", "Instant Health")
.put("INVISIBILITY", "Invisibility") .put("INVISIBILITY", "Invisibility")
.put("JUMP", "Jump Boost") .put("JUMP", "Jump Boost")
.put("LUCK", "Luck") .put("LUCK", "Luck")
.put("NIGHT_VISION", "Night Vision") .put("NIGHT_VISION", "Night Vision")
.put("POISION", "Poison") .put("POISION", "Poison")
.put("REGEN", "Regeneration") .put("REGEN", "Regeneration")
.put("SLOWNESS", "Slowness") .put("SLOWNESS", "Slowness")
.put("SPEED", "Speed") .put("SPEED", "Speed")
.put("STRENGTH", "Strength") .put("STRENGTH", "Strength")
.put("WATER_BREATHING", "Water Breathing") .put("WATER_BREATHING", "Water Breathing")
.put("WEAKNESS", "Weakness") .put("WEAKNESS", "Weakness")
.build(); .build();
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;
} }
String name; String name;
PotionMeta meta = (PotionMeta) itemStack.getItemMeta(); PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
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:
} else { name += " (0:02)";
switch (meta.getBasePotionData().getType()) { break;
case FIRE_RESISTANCE: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; case REGEN:
case INVISIBILITY: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; name += " (0:02)";
case JUMP: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; break;
case LUCK: name += " (0:37)"; break; case STRENGTH:
case NIGHT_VISION: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; name += " (0:11)";
case POISON: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")"; break; break;
case REGEN: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")"; break; default:
case SLOWNESS: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")"; break; break;
case SPEED: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; }
case STRENGTH: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; } else {
case WATER_BREATHING: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; switch (meta.getBasePotionData().getType()) {
case WEAKNESS: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")"; break; case FIRE_RESISTANCE:
default: break; name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
} break;
} case INVISIBILITY:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
break;
case JUMP:
name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")";
break;
case LUCK:
name += " (0:37)";
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;
}
}
return name;
}
return name;
}
} }

View File

@ -1,71 +1,67 @@
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;
public static ClickType getPlayerClickType(OfflinePlayer player) { private ItemStack product;
if (playerClickType.containsKey(player)) private double buyPrice;
return playerClickType.get(player); private double sellPrice;
else private ShopType shopType;
return null; public ClickType(EnumClickType enumClickType) {
} this.enumClickType = enumClickType;
}
public static void removePlayerClickType(OfflinePlayer player) { public ClickType(EnumClickType enumClickType, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
playerClickType.remove(player); this.enumClickType = enumClickType;
} this.product = product;
this.sellPrice = sellPrice;
public static void addPlayerClickType(OfflinePlayer player, ClickType clickType) { this.buyPrice = buyPrice;
playerClickType.put(player, clickType); this.shopType = shopType;
} }
public enum EnumClickType { public static ClickType getPlayerClickType(OfflinePlayer player) {
CREATE, REMOVE, INFO; if (playerClickType.containsKey(player))
} return playerClickType.get(player);
else
private EnumClickType enumClickType; return null;
private ItemStack product; }
private double buyPrice;
private double sellPrice; public static void removePlayerClickType(OfflinePlayer player) {
private ShopType shopType; playerClickType.remove(player);
}
public ClickType(EnumClickType enumClickType) {
this.enumClickType = enumClickType; public static void addPlayerClickType(OfflinePlayer player, ClickType clickType) {
} playerClickType.put(player, clickType);
}
public ClickType(EnumClickType enumClickType, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
this.enumClickType = enumClickType; public EnumClickType getClickType() {
this.product = product; return enumClickType;
this.sellPrice = sellPrice; }
this.buyPrice = buyPrice;
this.shopType = shopType; public ItemStack getProduct() {
} return product;
}
public EnumClickType getClickType() {
return enumClickType; public double getBuyPrice() {
} return buyPrice;
}
public ItemStack getProduct() {
return product; public double getSellPrice() {
} return sellPrice;
}
public double getBuyPrice() {
return buyPrice; public ShopType getShopType() {
} return shopType;
}
public double getSellPrice() {
return sellPrice; public enum EnumClickType {
} CREATE, REMOVE, INFO;
}
public ShopType getShopType() {
return shopType;
}
} }

View File

@ -1,84 +1,83 @@
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()
.put("PROTECTION_ENVIRONMENTAL", "Protection") .put("PROTECTION_ENVIRONMENTAL", "Protection")
.put("PROTECTION_FIRE", "Fire Protection") .put("PROTECTION_FIRE", "Fire Protection")
.put("PROTECTION_FALL", "Feather Falling") .put("PROTECTION_FALL", "Feather Falling")
.put("PROTECTION_EXPLOSIONS", "Blast Protection") .put("PROTECTION_EXPLOSIONS", "Blast Protection")
.put("OXYGEN", "Respiration") .put("OXYGEN", "Respiration")
.put("WATER_WORKER", "Aqua Affinity") .put("WATER_WORKER", "Aqua Affinity")
.put("THORNS", "Thorns") .put("THORNS", "Thorns")
.put("DEPTH_STRIDER", "Depth Strider") .put("DEPTH_STRIDER", "Depth Strider")
.put("DAMAGE_ALL", "Sharpness") .put("DAMAGE_ALL", "Sharpness")
.put("DAMAGE_UNDEAD", "smite") .put("DAMAGE_UNDEAD", "smite")
.put("DAMAGE_ARTHROPODS", "Bane of Arthropods") .put("DAMAGE_ARTHROPODS", "Bane of Arthropods")
.put("KNOCKBACK", "Knockback") .put("KNOCKBACK", "Knockback")
.put("FIRE_ASPECT", "Fire Aspect") .put("FIRE_ASPECT", "Fire Aspect")
.put("LOOT_BONUS_MOBS", "Looting") .put("LOOT_BONUS_MOBS", "Looting")
.put("DIG_SPEED", "Efficiency") .put("DIG_SPEED", "Efficiency")
.put("SILK_TOUCH", "Silk Touch") .put("SILK_TOUCH", "Silk Touch")
.put("DURABILITY", "Unbreaking") .put("DURABILITY", "Unbreaking")
.put("LOOT_BONUS_BLOCKS", "Fortune") .put("LOOT_BONUS_BLOCKS", "Fortune")
.put("ARROW_DAMAGE", "Power") .put("ARROW_DAMAGE", "Power")
.put("ARROW_KNOCKBACK", "Punch") .put("ARROW_KNOCKBACK", "Punch")
.put("ARROW_FIRE", "Flame") .put("ARROW_FIRE", "Flame")
.put("ARROW_INFINITE", "Infinity") .put("ARROW_INFINITE", "Infinity")
.put("LUCK", "Luck of the Sea") .put("LUCK", "Luck of the Sea")
.put("LURE", "Lure") .put("LURE", "Lure")
.build(); .build();
public static String lookup(Enchantment enchantment, int level) { public static String lookup(Enchantment enchantment, int level) {
String key = enchantment.getName(); String key = enchantment.getName();
String name = enchMap.get(key); String name = enchMap.get(key);
String levelString = getRomanNumber(level); String levelString = getRomanNumber(level);
return name + " " + levelString; return name + " " + levelString;
} }
public static String getRomanNumber(int Int) { public static String getRomanNumber(int Int) {
LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>(); LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>();
roman_numerals.put("M", 1000); roman_numerals.put("M", 1000);
roman_numerals.put("CM", 900); roman_numerals.put("CM", 900);
roman_numerals.put("D", 500); roman_numerals.put("D", 500);
roman_numerals.put("CD", 400); roman_numerals.put("CD", 400);
roman_numerals.put("C", 100); roman_numerals.put("C", 100);
roman_numerals.put("XC", 90); roman_numerals.put("XC", 90);
roman_numerals.put("L", 50); roman_numerals.put("L", 50);
roman_numerals.put("XL", 40); roman_numerals.put("XL", 40);
roman_numerals.put("X", 10); roman_numerals.put("X", 10);
roman_numerals.put("IX", 9); roman_numerals.put("IX", 9);
roman_numerals.put("V", 5); roman_numerals.put("V", 5);
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();
} }
return res; return res;
} }
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")
@ -523,34 +522,34 @@ public class ItemNames {
.put("380", "Cauldron") .put("380", "Cauldron")
.put("381", "Eye of Ender") .put("381", "Eye of Ender")
.put("382", "Glistering Melon") .put("382", "Glistering Melon")
.put("383", "Spawn Egg") .put("383", "Spawn Egg")
.put("383:50", "Spawn Creeper") .put("383:50", "Spawn Creeper")
.put("383:51", "Spawn Skeleton") .put("383:51", "Spawn Skeleton")
.put("383:52", "Spawn Spider") .put("383:52", "Spawn Spider")
.put("383:54", "Spawn Zombie") .put("383:54", "Spawn Zombie")
.put("383:55", "Spawn Slime") .put("383:55", "Spawn Slime")
.put("383:56", "Spawn Ghast") .put("383:56", "Spawn Ghast")
.put("383:57", "Spawn Pigman") .put("383:57", "Spawn Pigman")
.put("383:58", "Spawn Enderman") .put("383:58", "Spawn Enderman")
.put("383:59", "Spawn Cave Spider") .put("383:59", "Spawn Cave Spider")
.put("383:60", "Spawn Silverfish") .put("383:60", "Spawn Silverfish")
.put("383:61", "Spawn Blaze") .put("383:61", "Spawn Blaze")
.put("383:62", "Spawn Magma Cube") .put("383:62", "Spawn Magma Cube")
.put("383:65", "Spawn Bat") .put("383:65", "Spawn Bat")
.put("383:66", "Spawn Witch") .put("383:66", "Spawn Witch")
.put("383:67", "Spawn Endermite") .put("383:67", "Spawn Endermite")
.put("383:68", "Spawn Guardian") .put("383:68", "Spawn Guardian")
.put("383:90", "Spawn Pig") .put("383:90", "Spawn Pig")
.put("383:91", "Spawn Sheep") .put("383:91", "Spawn Sheep")
.put("383:92", "Spawn Cow") .put("383:92", "Spawn Cow")
.put("383:93", "Spawn Chicken") .put("383:93", "Spawn Chicken")
.put("383:94", "Spawn Squid") .put("383:94", "Spawn Squid")
.put("383:95", "Spawn Wolf") .put("383:95", "Spawn Wolf")
.put("383:96", "Spawn Mooshroom") .put("383:96", "Spawn Mooshroom")
.put("383:98", "Spawn Ocelot") .put("383:98", "Spawn Ocelot")
.put("383:100", "Spawn Horse") .put("383:100", "Spawn Horse")
.put("383:101", "Spawn Rabbit") .put("383:101", "Spawn Rabbit")
.put("383:120", "Spawn Villager") .put("383:120", "Spawn Villager")
.put("384", "Bottle o' Enchanting") .put("384", "Bottle o' Enchanting")
.put("385", "Fire Charge") .put("385", "Fire Charge")
.put("386", "Book and Quill") .put("386", "Book and Quill")
@ -633,14 +632,14 @@ public class ItemNames {
.put("2266", "Music Disk (11)") .put("2266", "Music Disk (11)")
.put("2267", "Music Disk (wait)") .put("2267", "Music Disk (wait)")
.build(); .build();
public static String lookup(ItemStack stack) { public static String lookup(ItemStack stack) {
if (stack.hasItemMeta()) { if (stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta(); ItemMeta meta = stack.getItemMeta();
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();
@ -668,5 +667,5 @@ public class ItemNames {
return result; return result;
} }
} }

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.
@ -325,26 +428,26 @@ public class Metrics {
// return => base/plugins/PluginMetrics/config.yml // return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
} }
/** /**
* Gets the online player (backwards compatibility) * Gets the online player (backwards compatibility)
* *
* @return online player amount * @return online player amount
*/ */
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) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
} }
} }
return 0; return 0;
} }
@ -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,158 +13,158 @@ 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 {
private static HashMap<Location, Shop> shopLocation = new HashMap<>(); private static HashMap<Location, Shop> shopLocation = new HashMap<>();
public static Shop getShop(Location location) { public static Shop getShop(Location location) {
Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
if (shopLocation.containsKey(newLocation)) { if (shopLocation.containsKey(newLocation)) {
return shopLocation.get(newLocation); return shopLocation.get(newLocation);
} else { } else {
return null; return null;
} }
} }
public static boolean isShop(Location location) { public static boolean isShop(Location location) {
Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
return shopLocation.containsKey(newLocation); return shopLocation.containsKey(newLocation);
} }
public static Shop[] getShops() { public static Shop[] getShops() {
ArrayList<Shop> shops = new ArrayList<>(); ArrayList<Shop> shops = new ArrayList<>();
for (Shop shop : shopLocation.values()) { for (Shop shop : shopLocation.values()) {
shops.add(shop); shops.add(shop);
} }
return shops.toArray(new Shop[shops.size()]); return shops.toArray(new Shop[shops.size()]);
} }
public static void addShop(Shop shop) { public static void addShop(Shop shop) {
Location loc = shop.getLocation(); Location loc = shop.getLocation();
Block b = loc.getBlock(); Block b = loc.getBlock();
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
Chest c = (Chest) b.getState(); Chest c = (Chest) b.getState();
InventoryHolder ih = c.getInventory().getHolder(); InventoryHolder ih = c.getInventory().getHolder();
if (ih instanceof DoubleChest) { if (ih instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) ih; DoubleChest dc = (DoubleChest) ih;
Chest r = (Chest) dc.getRightSide(); Chest r = (Chest) dc.getRightSide();
Chest l = (Chest) dc.getLeftSide(); Chest l = (Chest) dc.getLeftSide();
shopLocation.put(r.getLocation(), shop); shopLocation.put(r.getLocation(), shop);
shopLocation.put(l.getLocation(), shop); shopLocation.put(l.getLocation(), shop);
return; return;
} }
} }
shopLocation.put(shop.getLocation(), shop); shopLocation.put(shop.getLocation(), shop);
} }
public static void removeShop(Shop shop) { public static void removeShop(Shop shop) {
Location loc = shop.getLocation(); Location loc = shop.getLocation();
Block b = loc.getBlock(); Block b = loc.getBlock();
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
Chest c = (Chest) b.getState(); Chest c = (Chest) b.getState();
InventoryHolder ih = c.getInventory().getHolder(); InventoryHolder ih = c.getInventory().getHolder();
if (ih instanceof DoubleChest) { if (ih instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) ih; DoubleChest dc = (DoubleChest) ih;
Chest r = (Chest) dc.getRightSide(); Chest r = (Chest) dc.getRightSide();
Chest l = (Chest) dc.getLeftSide(); Chest l = (Chest) dc.getLeftSide();
if (shop.hasItem()) shop.getItem().remove(); if (shop.hasItem()) shop.getItem().remove();
shop.removeHologram(); shop.removeHologram();
shopLocation.remove(r.getLocation()); shopLocation.remove(r.getLocation());
shopLocation.remove(l.getLocation()); shopLocation.remove(l.getLocation());
return; return;
} }
} }
shopLocation.remove(shop.getLocation()); shopLocation.remove(shop.getLocation());
} }
public static int getShopLimit(Player p) {
int limit = Config.default_limit();
if (ShopChest.perm.hasGroupSupport()) {
List<String> groups = new ArrayList<String>();
for (String key : Config.shopLimits_group()) {
for (int i = 0; i < ShopChest.perm.getGroups().length; i++) {
if (ShopChest.perm.getGroups()[i].equals(key)) {
if (ShopChest.perm.playerInGroup(p, key)) {
groups.add(key);
}
}
}
}
if (groups.size() != 0) {
List<Integer> limits = new ArrayList<>();
for (String group : groups) {
int gLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.group." + group);
limits.add(gLimit);
}
int highestLimit = 0;
for (int l : limits) {
if (l > highestLimit) {
highestLimit = l;
} else if (l == -1) {
highestLimit = -1;
break;
}
}
limit = highestLimit;
}
}
for (String key : Config.shopLimits_player()) {
int pLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.player." + key);
if (Utils.isUUID(key)) {
if (p.getUniqueId().equals(UUID.fromString(key))) {
limit = pLimit;
}
} else {
if (p.getName().equals(key)) {
limit = pLimit;
}
}
}
return limit;
}
public static int getShopAmount(OfflinePlayer p) {
int shopCount = 0;
for (Shop shop : ShopUtils.getShops()) {
if (shop.getVendor().equals(p)) shopCount++;
}
return shopCount;
}
public static int getShopLimit(Player p) {
int limit = Config.default_limit();
if (ShopChest.perm.hasGroupSupport()) {
List<String> groups = new ArrayList<String>();
for (String key : Config.shopLimits_group()) {
for (int i = 0; i < ShopChest.perm.getGroups().length; i++) {
if (ShopChest.perm.getGroups()[i].equals(key)) {
if (ShopChest.perm.playerInGroup(p, key)) {
groups.add(key);
}
}
}
}
if (groups.size() != 0) {
List<Integer> limits = new ArrayList<>();
for (String group : groups) {
int gLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.group." + group);
limits.add(gLimit);
}
int highestLimit = 0;
for (int l : limits) {
if (l > highestLimit) {
highestLimit = l;
} else if (l == -1) {
highestLimit = -1;
break;
}
}
limit = highestLimit;
}
}
for (String key : Config.shopLimits_player()) {
int pLimit = ShopChest.getInstance().getConfig().getInt("shop-limits.player." + key);
if (Utils.isUUID(key)) {
if (p.getUniqueId().equals(UUID.fromString(key))) {
limit = pLimit;
}
} else {
if (p.getName().equals(key)) {
limit = pLimit;
}
}
}
return limit;
}
public static int getShopAmount(OfflinePlayer p) {
int shopCount = 0;
for (Shop shop : ShopUtils.getShops()) {
if (shop.getVendor().equals(p)) shopCount++;
}
return shopCount;
}
} }

View File

@ -1,75 +1,74 @@
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 { private ShopChest plugin;
TRUE, private String url;
FALSE, private String version;
ERROR; private String link;
} public UpdateChecker(ShopChest plugin, String url) {
this.plugin = plugin;
private ShopChest plugin; this.url = url;
private String url; }
private String version;
private String link; public UpdateCheckerResult updateNeeded() {
try {
public UpdateChecker(ShopChest plugin, String url) { Connection con = Jsoup.connect("http://textuploader.com/all1l/raw");
this.plugin = plugin; con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");
this.url = url;
} Document doc = con.get();
public UpdateCheckerResult updateNeeded() { version = doc.text().split("\\|")[0];
try { link = url + "download?version=" + doc.text().split("\\|")[1];
Connection con = Jsoup.connect("http://textuploader.com/all1l/raw");
con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"); if (plugin.getDescription().getVersion().equals(version))
return UpdateCheckerResult.FALSE;
Document doc = con.get(); else
return UpdateCheckerResult.TRUE;
version = doc.text().split("\\|")[0];
link = url + "download?version=" + doc.text().split("\\|")[1]; } catch (Exception | Error e) {
return UpdateCheckerResult.ERROR;
if(plugin.getDescription().getVersion().equals(version)) }
return UpdateCheckerResult.FALSE; }
else
return UpdateCheckerResult.TRUE; public String[] getBroadcast() {
try {
} catch (Exception | Error e) { Connection con = Jsoup.connect("http://textuploader.com/5b51f/raw");
return UpdateCheckerResult.ERROR; con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");
}
} Document doc = con.get();
public String[] getBroadcast() { String broadcast = doc.text();
try {
Connection con = Jsoup.connect("http://textuploader.com/5b51f/raw"); String[] messages = broadcast.split("#n");
con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");
if (!broadcast.equals("/"))
Document doc = con.get(); return messages;
String broadcast = doc.text(); } catch (Exception | Error e) {
}
String[] messages = broadcast.split("#n");
return null;
if (!broadcast.equals("/")) }
return messages;
public String getVersion() {
} catch (Exception | Error e) {} return version;
}
return null;
} public String getLink() {
return link;
public String getVersion() { }
return version;
} public enum UpdateCheckerResult {
TRUE,
public String getLink() { FALSE,
return link; ERROR;
} }
} }