mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-12-28 20:01:54 +00:00
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:
parent
5bb4169c80
commit
543da0682b
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,7 @@
|
||||
/bin/
|
||||
/out/
|
||||
/.idea/
|
||||
/.settings/
|
||||
.classpath
|
||||
.project
|
||||
.project
|
||||
ShopChest.iml
|
@ -1,17 +1,5 @@
|
||||
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.interfaces.JsonBuilder;
|
||||
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.UpdateCheckerResult;
|
||||
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 {
|
||||
|
||||
private ShopChest plugin;
|
||||
private ShopChest plugin;
|
||||
|
||||
private Permission perm = ShopChest.perm;
|
||||
|
||||
public Commands(ShopChest plugin, String name, String description, String usageMessage, List<String> aliases) {
|
||||
super(name, description, usageMessage, aliases);
|
||||
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);
|
||||
private Permission perm = ShopChest.perm;
|
||||
|
||||
public Commands(ShopChest plugin, String name, String description, String usageMessage, List<String> aliases) {
|
||||
super(name, description, usageMessage, aliases);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,37 +1,16 @@
|
||||
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.LWCPlugin;
|
||||
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.event.InteractShop;
|
||||
import de.epiceric.shopchest.event.ItemCustomNameListener;
|
||||
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.event.*;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
|
||||
import de.epiceric.shopchest.interfaces.utils.*;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.shop.Shop.ShopType;
|
||||
import de.epiceric.shopchest.sql.SQLite;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
|
||||
import de.epiceric.shopchest.utils.Metrics;
|
||||
import de.epiceric.shopchest.utils.Metrics.Graph;
|
||||
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 net.milkbowl.vault.economy.Economy;
|
||||
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 static Statement statement;
|
||||
public static Logger logger;
|
||||
public static Economy econ = null;
|
||||
public static Permission perm = null;
|
||||
public static LWC lwc = null;
|
||||
public static boolean lockette = false;
|
||||
public static SQLite sqlite;
|
||||
|
||||
public static boolean isUpdateNeeded = false;
|
||||
public static String latestVersion = "";
|
||||
public static String downloadLink = "";
|
||||
public static String[] broadcast = null;
|
||||
|
||||
public static Utils utils;
|
||||
|
||||
public static ShopChest getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private boolean setupEconomy() {
|
||||
public class ShopChest extends JavaPlugin {
|
||||
|
||||
public static Logger logger;
|
||||
public static Economy econ = null;
|
||||
public static Permission perm = null;
|
||||
public static LWC lwc = null;
|
||||
public static boolean lockette = false;
|
||||
public static SQLite sqlite;
|
||||
public static boolean isUpdateNeeded = false;
|
||||
public static String latestVersion = "";
|
||||
public static String downloadLink = "";
|
||||
public static String[] broadcast = null;
|
||||
public static Utils utils;
|
||||
private static ShopChest instance;
|
||||
|
||||
public static ShopChest getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void copy(InputStream in, File file) {
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
@ -73,244 +73,250 @@ public class ShopChest extends JavaPlugin{
|
||||
econ = rsp.getProvider();
|
||||
return econ != null;
|
||||
}
|
||||
|
||||
|
||||
private boolean setupPermissions() {
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
perm = rsp.getProvider();
|
||||
return perm != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
logger = getLogger();
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
logger = getLogger();
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
logger.severe("Could not find plugin 'Vault'!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!setupEconomy() ) {
|
||||
|
||||
if (!setupEconomy()) {
|
||||
logger.severe("Could not find any Vault dependency!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
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
|
||||
public int getValue() {
|
||||
int value = 0;
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
if (shop.getShopType() == ShopType.ADMIN) value++;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
logger.severe("Could not submit stats.");
|
||||
}
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
Graph shopType = metrics.createGraph("Shop Type");
|
||||
|
||||
reloadConfig();
|
||||
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;
|
||||
shopType.addPlotter(new Plotter("Infinite") {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@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
|
||||
public int getValue() {
|
||||
int value = 0;
|
||||
|
||||
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();
|
||||
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());
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,181 +1,353 @@
|
||||
package de.epiceric.shopchest.config;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
public class Config {
|
||||
|
||||
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");
|
||||
}
|
||||
private static ShopChest plugin = ShopChest.getInstance();
|
||||
|
||||
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 Set<String> minimum_prices() {
|
||||
return (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet<String>() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
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) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,19 @@ package de.epiceric.shopchest.config;
|
||||
|
||||
public class Regex {
|
||||
|
||||
public static String vendor = "%VENDOR%";
|
||||
public static String amount = "%AMOUNT%";
|
||||
public static String itemName = "%ITEMNAME%";
|
||||
public static String price = "%PRICE%";
|
||||
public static String currencySymbol = "%CURRENCY-SYMBOL%";
|
||||
public static String error = "%ERROR%";
|
||||
public static String enchantment = "%ENCHANTMENT%";
|
||||
public static String minPrice = "%MIN-PRICE%";
|
||||
public static String version = "%VERSION%";
|
||||
public static String buyPrice = "%BUY-PRICE%";
|
||||
public static String sellPrice = "%SELL-PRICE%";
|
||||
public static String limit = "%LIMIT%";
|
||||
public static String player = "%PLAYER%";
|
||||
public static String arrowEffect = "%ARROW-EFFECT%";
|
||||
|
||||
public static String vendor = "%VENDOR%";
|
||||
public static String amount = "%AMOUNT%";
|
||||
public static String itemName = "%ITEMNAME%";
|
||||
public static String price = "%PRICE%";
|
||||
public static String currencySymbol = "%CURRENCY-SYMBOL%";
|
||||
public static String error = "%ERROR%";
|
||||
public static String enchantment = "%ENCHANTMENT%";
|
||||
public static String minPrice = "%MIN-PRICE%";
|
||||
public static String version = "%VERSION%";
|
||||
public static String buyPrice = "%BUY-PRICE%";
|
||||
public static String sellPrice = "%SELL-PRICE%";
|
||||
public static String limit = "%LIMIT%";
|
||||
public static String player = "%PLAYER%";
|
||||
public static String arrowEffect = "%ARROW-EFFECT%";
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,12 +6,12 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
|
||||
public class ItemCustomNameListener implements Listener {
|
||||
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onItemSpawn(ItemSpawnEvent e) {
|
||||
if (e.getEntity().hasMetadata("shopItem")) {
|
||||
e.getEntity().setCustomNameVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onItemSpawn(ItemSpawnEvent e) {
|
||||
if (e.getEntity().hasMetadata("shopItem")) {
|
||||
e.getEntity().setCustomNameVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,63 @@
|
||||
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.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
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 {
|
||||
|
||||
private Permission perm = ShopChest.perm;
|
||||
|
||||
public NotifyUpdate() {}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (ShopChest.isUpdateNeeded) {
|
||||
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;
|
||||
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(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (perm.has(p, "shopchest.broadcast")) {
|
||||
if (ShopChest.broadcast != null) {
|
||||
for (String message : ShopChest.broadcast) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Permission perm = ShopChest.perm;
|
||||
|
||||
public NotifyUpdate() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (ShopChest.isUpdateNeeded) {
|
||||
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;
|
||||
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(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (perm.has(p, "shopchest.broadcast")) {
|
||||
if (ShopChest.broadcast != null) {
|
||||
for (String message : ShopChest.broadcast) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
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.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
@ -17,110 +19,108 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ProtectChest implements Listener {
|
||||
|
||||
public ProtectChest() {}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
if (ShopUtils.isShop(e.getBlock().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(Config.cannot_break_shop());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockExplode(BlockExplodeEvent e) {
|
||||
if (Config.explosion_protection()) {
|
||||
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
||||
for (Block b : bl) {
|
||||
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) {
|
||||
if (Config.explosion_protection()) {
|
||||
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
||||
for (Block b : bl) {
|
||||
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) {
|
||||
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();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) {
|
||||
Shop shop;
|
||||
|
||||
if (b.getLocation().equals(r.getLocation())) {
|
||||
shop = ShopUtils.getShop(l.getLocation());
|
||||
ShopUtils.removeShop(shop);
|
||||
ShopChest.sqlite.removeShop(shop);
|
||||
} else if (b.getLocation().equals(l.getLocation())) {
|
||||
shop = ShopUtils.getShop(r.getLocation());
|
||||
ShopUtils.removeShop(shop);
|
||||
ShopChest.sqlite.removeShop(shop);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
newShop.createItem();
|
||||
ShopUtils.addShop(newShop);
|
||||
ShopChest.sqlite.addShop(newShop);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemMove(InventoryMoveItemEvent e) {
|
||||
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();
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
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();
|
||||
|
||||
if (ShopUtils.isShop(c.getLocation())) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ProtectChest() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
if (ShopUtils.isShop(e.getBlock().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(Config.cannot_break_shop());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockExplode(BlockExplodeEvent e) {
|
||||
if (Config.explosion_protection()) {
|
||||
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
||||
for (Block b : bl) {
|
||||
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) {
|
||||
if (Config.explosion_protection()) {
|
||||
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
||||
for (Block b : bl) {
|
||||
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) {
|
||||
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();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) {
|
||||
Shop shop;
|
||||
|
||||
if (b.getLocation().equals(r.getLocation())) {
|
||||
shop = ShopUtils.getShop(l.getLocation());
|
||||
ShopUtils.removeShop(shop);
|
||||
ShopChest.sqlite.removeShop(shop);
|
||||
} else if (b.getLocation().equals(l.getLocation())) {
|
||||
shop = ShopUtils.getShop(r.getLocation());
|
||||
ShopUtils.removeShop(shop);
|
||||
ShopChest.sqlite.removeShop(shop);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
newShop.createItem();
|
||||
ShopUtils.addShop(newShop);
|
||||
ShopChest.sqlite.addShop(newShop);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemMove(InventoryMoveItemEvent e) {
|
||||
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();
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
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();
|
||||
|
||||
if (ShopUtils.isShop(c.getLocation())) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,25 +11,26 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
|
||||
public class RegenerateShopItem implements Listener {
|
||||
|
||||
public RegenerateShopItem() {}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemDespawn(ItemDespawnEvent e) {
|
||||
Item item = e.getEntity();
|
||||
if (item.hasMetadata("shopItem")) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerPickUpItem(PlayerPickupItemEvent e) {
|
||||
if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemPickup(InventoryPickupItemEvent e) {
|
||||
if (e.getInventory().getType().equals(InventoryType.HOPPER)) {
|
||||
if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RegenerateShopItem() {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemDespawn(ItemDespawnEvent e) {
|
||||
Item item = e.getEntity();
|
||||
if (item.hasMetadata("shopItem")) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerPickUpItem(PlayerPickupItemEvent e) {
|
||||
if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemPickup(InventoryPickupItemEvent e) {
|
||||
if (e.getInventory().getType().equals(InventoryType.HOPPER)) {
|
||||
if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
package de.epiceric.shopchest.event;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
public class RegenerateShopItemAfterRemove implements Listener {
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityRemove(me.minebuilders.clearlag.events.EntityRemoveEvent e) {
|
||||
boolean containsShopItem = false;
|
||||
for (Entity entity : e.getEntityList()) {
|
||||
if (entity.hasMetadata("shopItem")) {
|
||||
containsShopItem = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (containsShopItem) ShopChest.utils.reload(null);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityRemove(me.minebuilders.clearlag.events.EntityRemoveEvent e) {
|
||||
boolean containsShopItem = false;
|
||||
for (Entity entity : e.getEntityList()) {
|
||||
if (entity.hasMetadata("shopItem")) {
|
||||
containsShopItem = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (containsShopItem) ShopChest.utils.reload(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,53 +1,53 @@
|
||||
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.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
public class UpdateHolograms implements Listener {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,21 @@
|
||||
package de.epiceric.shopchest.interfaces;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Hologram {
|
||||
|
||||
public Location getLocation();
|
||||
public List<?> getEntities();
|
||||
public void showPlayer(OfflinePlayer p);
|
||||
public void hidePlayer(OfflinePlayer p);
|
||||
public boolean isVisible(OfflinePlayer p);
|
||||
|
||||
public Location getLocation();
|
||||
|
||||
public List<?> getEntities();
|
||||
|
||||
public void showPlayer(OfflinePlayer p);
|
||||
|
||||
public void hidePlayer(OfflinePlayer p);
|
||||
|
||||
public boolean isVisible(OfflinePlayer p);
|
||||
|
||||
}
|
||||
|
@ -5,21 +5,28 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public interface JsonBuilder {
|
||||
|
||||
public enum ClickAction {
|
||||
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL
|
||||
}
|
||||
|
||||
public enum HoverAction {
|
||||
SHOW_TEXT
|
||||
}
|
||||
|
||||
public JsonBuilder parse(String text);
|
||||
public JsonBuilder withText(String text);
|
||||
public JsonBuilder withColor(ChatColor color);
|
||||
public JsonBuilder withColor(String color);
|
||||
public JsonBuilder withClickEvent(ClickAction action, String value);
|
||||
public JsonBuilder withHoverEvent(HoverAction action, String value);
|
||||
public String toString();
|
||||
public void sendJson(Player p);
|
||||
|
||||
public JsonBuilder parse(String text);
|
||||
|
||||
public JsonBuilder withText(String text);
|
||||
|
||||
public JsonBuilder withColor(ChatColor color);
|
||||
|
||||
public JsonBuilder withColor(String color);
|
||||
|
||||
public JsonBuilder withClickEvent(ClickAction action, String value);
|
||||
|
||||
public JsonBuilder withHoverEvent(HoverAction action, String value);
|
||||
|
||||
public String toString();
|
||||
|
||||
public void sendJson(Player p);
|
||||
|
||||
public enum ClickAction {
|
||||
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL
|
||||
}
|
||||
|
||||
public enum HoverAction {
|
||||
SHOW_TEXT
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,44 +11,40 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class Utils {
|
||||
|
||||
public abstract void reload(Player p);
|
||||
|
||||
public abstract void removeShops();
|
||||
|
||||
public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) {
|
||||
ItemStack[] items = inventory.getContents();
|
||||
int amount = 0;
|
||||
for (ItemStack item : items) {
|
||||
if ((item != null) && (item.getType().equals(type)) && (item.getDurability() == damage) && (item.getAmount() > 0) && (item.getItemMeta().equals(itemMeta))) {
|
||||
amount += item.getAmount();
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static String getVersion(Server server) {
|
||||
String packageName = server.getClass().getPackage().getName();
|
||||
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public static boolean isUUID(String string) {
|
||||
return string.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");
|
||||
}
|
||||
|
||||
public static String encode(ItemStack itemStack) {
|
||||
public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) {
|
||||
ItemStack[] items = inventory.getContents();
|
||||
int amount = 0;
|
||||
for (ItemStack item : items) {
|
||||
if ((item != null) && (item.getType().equals(type)) && (item.getDurability() == damage) && (item.getAmount() > 0) && (item.getItemMeta().equals(itemMeta))) {
|
||||
amount += item.getAmount();
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static String getVersion(Server server) {
|
||||
String packageName = server.getClass().getPackage().getName();
|
||||
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public static boolean isUUID(String string) {
|
||||
return string.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");
|
||||
}
|
||||
|
||||
public static String encode(ItemStack itemStack) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.set("i", itemStack);
|
||||
return new String(Base64.encodeBase64(config.saveToString().getBytes()));
|
||||
}
|
||||
|
||||
public static String toString(ItemStack itemStack) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
public static String toString(ItemStack itemStack) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.set("i", itemStack);
|
||||
return config.saveToString();
|
||||
}
|
||||
|
||||
public static ItemStack decode(String string) {
|
||||
}
|
||||
|
||||
public static ItemStack decode(String string) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
try {
|
||||
config.loadFromString(new String(Base64.decodeBase64(string.getBytes())));
|
||||
@ -59,6 +55,9 @@ public abstract class Utils {
|
||||
return config.getItemStack("i", null);
|
||||
}
|
||||
|
||||
public abstract void reload(Player p);
|
||||
|
||||
public abstract void removeShops();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,50 @@
|
||||
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 net.minecraft.server.v1_8_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
|
||||
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 {
|
||||
|
||||
|
||||
int count;
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_1_8_R1(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_1_8_R1(String text, Location location) {
|
||||
this.text = new String[] {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;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
@ -54,34 +52,35 @@ public class Hologram_1_8_R1 implements Hologram {
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,50 @@
|
||||
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 net.minecraft.server.v1_8_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy;
|
||||
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 {
|
||||
|
||||
|
||||
int count;
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_1_8_R2(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_1_8_R2(String text, Location location) {
|
||||
this.text = new String[] {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;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
@ -54,34 +52,35 @@ public class Hologram_1_8_R2 implements Hologram {
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,50 @@
|
||||
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 net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
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 {
|
||||
|
||||
|
||||
int count;
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_1_8_R3(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_1_8_R3(String text, Location location) {
|
||||
this.text = new String[] {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;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
@ -54,34 +52,35 @@ public class Hologram_1_8_R3 implements Hologram {
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,50 @@
|
||||
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 net.minecraft.server.v1_9_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy;
|
||||
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 {
|
||||
|
||||
|
||||
int count;
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_1_9_R1(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_1_9_R1(String text, Location location) {
|
||||
this.text = new String[] {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;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
@ -54,34 +52,35 @@ public class Hologram_1_9_R1 implements Hologram {
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,50 @@
|
||||
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 net.minecraft.server.v1_9_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy;
|
||||
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 {
|
||||
|
||||
|
||||
int count;
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_1_9_R2(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_1_9_R2(String text, Location location) {
|
||||
this.text = new String[] {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;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
@ -54,34 +52,35 @@ public class Hologram_1_9_R2 implements Hologram {
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
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++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,111 +1,112 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_8_R1.ChatSerializer;
|
||||
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 {
|
||||
|
||||
/* 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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,111 +1,112 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
|
||||
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 {
|
||||
|
||||
/* 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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,111 +1,112 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
|
||||
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 {
|
||||
|
||||
/* 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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,111 +1,112 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
|
||||
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 {
|
||||
|
||||
/* 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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,111 +1,112 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
|
||||
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 {
|
||||
|
||||
/* 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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,85 +1,84 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
@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);
|
||||
}
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
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.config.Config;
|
||||
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.utils.ShopUtils;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,86 +1,85 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,86 +1,85 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,86 +1,85 @@
|
||||
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.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
for (Object o : hologram.getEntities()) {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package de.epiceric.shopchest.shop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
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.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -17,185 +20,195 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Shop {
|
||||
|
||||
public enum ShopType {
|
||||
NORMAL,
|
||||
INFINITE,
|
||||
ADMIN;
|
||||
}
|
||||
|
||||
private ShopChest plugin;
|
||||
private OfflinePlayer vendor;
|
||||
private ItemStack product;
|
||||
private Location location;
|
||||
private Hologram hologram;
|
||||
private Item item;
|
||||
private double buyPrice;
|
||||
private double sellPrice;
|
||||
private ShopType shopType;
|
||||
|
||||
public Shop(ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
|
||||
this.plugin = plugin;
|
||||
this.vendor = vendor;
|
||||
this.product = product;
|
||||
this.location = location;
|
||||
this.buyPrice = buyPrice;
|
||||
this.sellPrice = sellPrice;
|
||||
this.shopType = shopType;
|
||||
}
|
||||
|
||||
public void removeHologram() {
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
getHologram().hidePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void createItem() {
|
||||
|
||||
Item item;
|
||||
Location itemLocation;
|
||||
ItemStack itemStack;
|
||||
ItemMeta itemMeta = product.getItemMeta().clone();
|
||||
itemMeta.setDisplayName(UUID.randomUUID().toString());
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("Shop Item");
|
||||
itemMeta.setLore(lore);
|
||||
|
||||
itemLocation = new Location(location.getWorld(), hologram.getLocation().getX(), location.getY() + 1, hologram.getLocation().getZ());
|
||||
itemStack = new ItemStack(product.getType(), 1, product.getDurability());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
||||
item = location.getWorld().dropItem(itemLocation, itemStack);
|
||||
item.setVelocity(new Vector(0, 0, 0));
|
||||
item.setMetadata("shopItem", new FixedMetadataValue(plugin, true));
|
||||
item.setCustomNameVisible(false);
|
||||
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void createHologram() {
|
||||
|
||||
boolean doubleChest;
|
||||
|
||||
Chest[] chests = new Chest[2];
|
||||
|
||||
Block b = location.getBlock();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
chests[0] = r;
|
||||
chests[1] = l;
|
||||
|
||||
doubleChest = true;
|
||||
|
||||
} else {
|
||||
doubleChest = false;
|
||||
chests[0] = c;
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Location holoLocation;
|
||||
String[] holoText = new String[2];
|
||||
|
||||
if (doubleChest) {
|
||||
|
||||
Chest r = chests[0];
|
||||
Chest l = chests[1];
|
||||
|
||||
if (b.getLocation().equals(r.getLocation())) {
|
||||
|
||||
if (r.getX() != l.getX()) holoLocation = new Location(b.getWorld(), b.getX(), b.getY() - 0.6, b.getZ() + 0.5);
|
||||
else if (r.getZ() != l.getZ()) holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ());
|
||||
else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
|
||||
|
||||
} else {
|
||||
|
||||
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));
|
||||
|
||||
if ((buyPrice <= 0) && (sellPrice > 0)) holoText[1] = Config.hologram_sell(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);
|
||||
else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice);
|
||||
|
||||
switch (Utils.getVersion(plugin.getServer())) {
|
||||
case "v1_8_R1": hologram = new Hologram_1_8_R1(holoText, holoLocation); break;
|
||||
case "v1_8_R2": hologram = new Hologram_1_8_R2(holoText, holoLocation); break;
|
||||
case "v1_8_R3": hologram = new Hologram_1_8_R3(holoText, holoLocation); break;
|
||||
case "v1_9_R1": hologram = new Hologram_1_9_R1(holoText, holoLocation); break;
|
||||
case "v1_9_R2": hologram = new Hologram_1_9_R2(holoText, holoLocation); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public OfflinePlayer getVendor() {
|
||||
return vendor;
|
||||
}
|
||||
|
||||
public ItemStack getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public double getBuyPrice() {
|
||||
return buyPrice;
|
||||
}
|
||||
|
||||
public double getSellPrice() {
|
||||
return sellPrice;
|
||||
}
|
||||
|
||||
public ShopType getShopType() {
|
||||
return shopType;
|
||||
}
|
||||
|
||||
public Hologram getHologram() {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public boolean hasItem() {
|
||||
return item != null;
|
||||
}
|
||||
|
||||
private ShopChest plugin;
|
||||
private OfflinePlayer vendor;
|
||||
private ItemStack product;
|
||||
private Location location;
|
||||
private Hologram hologram;
|
||||
private Item item;
|
||||
private double buyPrice;
|
||||
private double sellPrice;
|
||||
private ShopType shopType;
|
||||
public Shop(ShopChest plugin, OfflinePlayer vendor, ItemStack product, Location location, double buyPrice, double sellPrice, ShopType shopType) {
|
||||
this.plugin = plugin;
|
||||
this.vendor = vendor;
|
||||
this.product = product;
|
||||
this.location = location;
|
||||
this.buyPrice = buyPrice;
|
||||
this.sellPrice = sellPrice;
|
||||
this.shopType = shopType;
|
||||
}
|
||||
|
||||
public void removeHologram() {
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
getHologram().hidePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void createItem() {
|
||||
|
||||
Item item;
|
||||
Location itemLocation;
|
||||
ItemStack itemStack;
|
||||
ItemMeta itemMeta = product.getItemMeta().clone();
|
||||
itemMeta.setDisplayName(UUID.randomUUID().toString());
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("Shop Item");
|
||||
itemMeta.setLore(lore);
|
||||
|
||||
itemLocation = new Location(location.getWorld(), hologram.getLocation().getX(), location.getY() + 1, hologram.getLocation().getZ());
|
||||
itemStack = new ItemStack(product.getType(), 1, product.getDurability());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
||||
item = location.getWorld().dropItem(itemLocation, itemStack);
|
||||
item.setVelocity(new Vector(0, 0, 0));
|
||||
item.setMetadata("shopItem", new FixedMetadataValue(plugin, true));
|
||||
item.setCustomNameVisible(false);
|
||||
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void createHologram() {
|
||||
|
||||
boolean doubleChest;
|
||||
|
||||
Chest[] chests = new Chest[2];
|
||||
|
||||
Block b = location.getBlock();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
chests[0] = r;
|
||||
chests[1] = l;
|
||||
|
||||
doubleChest = true;
|
||||
|
||||
} else {
|
||||
doubleChest = false;
|
||||
chests[0] = c;
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Location holoLocation;
|
||||
String[] holoText = new String[2];
|
||||
|
||||
if (doubleChest) {
|
||||
|
||||
Chest r = chests[0];
|
||||
Chest l = chests[1];
|
||||
|
||||
if (b.getLocation().equals(r.getLocation())) {
|
||||
|
||||
if (r.getX() != l.getX())
|
||||
holoLocation = new Location(b.getWorld(), b.getX(), b.getY() - 0.6, b.getZ() + 0.5);
|
||||
else if (r.getZ() != l.getZ())
|
||||
holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ());
|
||||
else holoLocation = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.6, b.getZ() + 0.5);
|
||||
|
||||
} else {
|
||||
|
||||
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));
|
||||
|
||||
if ((buyPrice <= 0) && (sellPrice > 0)) holoText[1] = Config.hologram_sell(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);
|
||||
else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice);
|
||||
|
||||
switch (Utils.getVersion(plugin.getServer())) {
|
||||
case "v1_8_R1":
|
||||
hologram = new Hologram_1_8_R1(holoText, holoLocation);
|
||||
break;
|
||||
case "v1_8_R2":
|
||||
hologram = new Hologram_1_8_R2(holoText, holoLocation);
|
||||
break;
|
||||
case "v1_8_R3":
|
||||
hologram = new Hologram_1_8_R3(holoText, holoLocation);
|
||||
break;
|
||||
case "v1_9_R1":
|
||||
hologram = new Hologram_1_9_R1(holoText, holoLocation);
|
||||
break;
|
||||
case "v1_9_R2":
|
||||
hologram = new Hologram_1_9_R2(holoText, holoLocation);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public OfflinePlayer getVendor() {
|
||||
return vendor;
|
||||
}
|
||||
|
||||
public ItemStack getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public double getBuyPrice() {
|
||||
return buyPrice;
|
||||
}
|
||||
|
||||
public double getSellPrice() {
|
||||
return sellPrice;
|
||||
}
|
||||
|
||||
public ShopType getShopType() {
|
||||
return shopType;
|
||||
}
|
||||
|
||||
public Hologram getHologram() {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public boolean hasItem() {
|
||||
return item != null;
|
||||
}
|
||||
|
||||
public enum ShopType {
|
||||
NORMAL,
|
||||
INFINITE,
|
||||
ADMIN;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,29 +1,24 @@
|
||||
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.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.shop.Shop.ShopType;
|
||||
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 String SQLiteCreateTokensTable = "CREATE TABLE IF NOT EXISTS shop_list (" +
|
||||
"`id` int(11) NOT NULL," +
|
||||
|
||||
public String SQLiteCreateTokensTable = "CREATE TABLE IF NOT EXISTS shop_list (" +
|
||||
"`id` int(11) NOT NULL," +
|
||||
"`vendor` varchar(32) NOT NULL," +
|
||||
"`product` varchar(32) NOT NULL," +
|
||||
"`world` varchar(32) NOT NULL," +
|
||||
@ -35,12 +30,8 @@ public abstract class Database {
|
||||
"`shoptype` varchar(32) NOT NULL," +
|
||||
"PRIMARY KEY (`id`)" +
|
||||
");";
|
||||
|
||||
ShopChest plugin;
|
||||
Connection connection;
|
||||
// The name of the table we created back in SQLite class.
|
||||
public String table = "shop_list";
|
||||
|
||||
public String world = "";
|
||||
public String vendor = "";
|
||||
public ItemStack product = null;
|
||||
@ -48,8 +39,10 @@ public abstract class Database {
|
||||
public double buyPrice = 0;
|
||||
public double sellPrice = 0;
|
||||
public ShopType shopType = ShopType.NORMAL;
|
||||
|
||||
public Database(ShopChest instance){
|
||||
ShopChest plugin;
|
||||
Connection connection;
|
||||
|
||||
public Database(ShopChest instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
@ -57,39 +50,39 @@ public abstract class Database {
|
||||
|
||||
public abstract void load();
|
||||
|
||||
public void initialize(){
|
||||
public void initialize() {
|
||||
connection = getSQLConnection();
|
||||
try{
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT * FROM " + table + " WHERE id = ?");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
close(ps,rs);
|
||||
|
||||
close(ps, rs);
|
||||
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Unable to retreive connection", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void renameColumnInfiniteToShopType() {
|
||||
Connection conn = null;
|
||||
Statement s = null;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
s = conn.createStatement();
|
||||
s.execute("ALTER TABLE " + table + " RENAME TO " + table + "_old");
|
||||
s.close();
|
||||
s.execute(SQLiteCreateTokensTable);
|
||||
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.close();
|
||||
conn.close();
|
||||
|
||||
conn = getSQLConnection();
|
||||
s = conn.createStatement();
|
||||
s.execute("DROP TABLE " + table + "_old");
|
||||
s.close();
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
Connection conn = null;
|
||||
Statement s = null;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
s = conn.createStatement();
|
||||
s.execute("ALTER TABLE " + table + " RENAME TO " + table + "_old");
|
||||
s.close();
|
||||
s.execute(SQLiteCreateTokensTable);
|
||||
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.close();
|
||||
conn.close();
|
||||
|
||||
conn = getSQLConnection();
|
||||
s = conn.createStatement();
|
||||
s.execute("DROP TABLE " + table + "_old");
|
||||
s.close();
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
try {
|
||||
if (s != null)
|
||||
s.close();
|
||||
@ -100,39 +93,39 @@ public abstract class Database {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getNextFreeID() {
|
||||
for (int i = 1; i < getHighestID() + 1; i++) {
|
||||
if (getProduct(i) == null) {
|
||||
return i;
|
||||
} else {
|
||||
if (i == getHighestID()) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
public int getNextFreeID() {
|
||||
for (int i = 1; i < getHighestID() + 1; i++) {
|
||||
if (getProduct(i) == null) {
|
||||
return i;
|
||||
} else {
|
||||
if (i == getHighestID()) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
public int getHighestID() {
|
||||
Connection conn = null;
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
|
||||
int highestID = 1;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") > highestID) {
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") > highestID) {
|
||||
highestID = rs.getInt("id");
|
||||
}
|
||||
}
|
||||
return highestID;
|
||||
|
||||
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
@ -145,40 +138,40 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getShopID(Shop shop) {
|
||||
|
||||
|
||||
for (int i = 1; i < getHighestID() + 1; i++) {
|
||||
|
||||
try {
|
||||
Shop s = getShop(i);
|
||||
if (s.getLocation().equals(shop.getLocation())) {
|
||||
return i;
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
for (int i = 1; i < getHighestID() + 1; i++) {
|
||||
|
||||
try {
|
||||
Shop s = getShop(i);
|
||||
if (s.getLocation().equals(shop.getLocation())) {
|
||||
return i;
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public void removeShop(Shop shop) {
|
||||
|
||||
int id = getShopID(shop);
|
||||
if (id == 0) return;
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
Connection conn = null;
|
||||
|
||||
int id = getShopID(shop);
|
||||
if (id == 0) return;
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("DELETE FROM " + table + " where id = " + id + ";");
|
||||
ps = conn.prepareStatement("DELETE FROM " + table + " where id = " + id + ";");
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
@ -191,17 +184,17 @@ public abstract class Database {
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void removeShop(int id) {
|
||||
|
||||
if (id == 0) return;
|
||||
removeShop(getShop(id));
|
||||
|
||||
|
||||
if (id == 0) return;
|
||||
removeShop(getShop(id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private World getWorld(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -209,10 +202,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id) {
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return Bukkit.getWorld(rs.getString("world"));
|
||||
}
|
||||
}
|
||||
@ -228,20 +221,20 @@ public abstract class Database {
|
||||
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;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("vendor")));
|
||||
}
|
||||
}
|
||||
@ -257,9 +250,9 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getProduct(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -267,10 +260,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return Utils.decode(rs.getString("product"));
|
||||
}
|
||||
}
|
||||
@ -286,9 +279,9 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private int getX(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -296,10 +289,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return rs.getInt("x");
|
||||
}
|
||||
}
|
||||
@ -315,9 +308,9 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
private int getY(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -325,10 +318,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return rs.getInt("y");
|
||||
}
|
||||
}
|
||||
@ -344,9 +337,9 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
private int getZ(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -354,10 +347,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return rs.getInt("z");
|
||||
}
|
||||
}
|
||||
@ -373,13 +366,13 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -387,10 +380,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return rs.getDouble("buyprice");
|
||||
}
|
||||
}
|
||||
@ -406,9 +399,9 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public double getSellPrice(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -416,10 +409,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
return rs.getDouble("sellprice");
|
||||
}
|
||||
}
|
||||
@ -435,9 +428,9 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public ShopType getShopType(int id) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
@ -445,26 +438,26 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE id = " + id + ";");
|
||||
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
if(rs.getInt("id") == id){
|
||||
if (rs.getString("shoptype").equals("0") || rs.getString("shoptype").equals("1")) {
|
||||
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '0', 'NORMAL')");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '1', 'INFINITE')");
|
||||
ps.executeUpdate();
|
||||
return getShopType(id);
|
||||
}
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("id") == id) {
|
||||
if (rs.getString("shoptype").equals("0") || rs.getString("shoptype").equals("1")) {
|
||||
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '0', 'NORMAL')");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '1', 'INFINITE')");
|
||||
ps.executeUpdate();
|
||||
return getShopType(id);
|
||||
}
|
||||
return ShopType.valueOf(rs.getString("shoptype"));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
if (ex.getMessage().equals("no such column: 'shoptype'")){
|
||||
renameColumnInfiniteToShopType();
|
||||
return getShopType(id);
|
||||
}
|
||||
if (ex.getMessage().equals("no such column: 'shoptype'")) {
|
||||
renameColumnInfiniteToShopType();
|
||||
return getShopType(id);
|
||||
}
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
try {
|
||||
@ -476,20 +469,20 @@ public abstract class Database {
|
||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
return ShopType.NORMAL;
|
||||
|
||||
return ShopType.NORMAL;
|
||||
}
|
||||
|
||||
|
||||
public Shop getShop(int id) {
|
||||
OfflinePlayer vendor = getVendor(id);
|
||||
Location location = getLocation(id);
|
||||
ItemStack product = getProduct(id);
|
||||
double buyPrice = getBuyPrice(id);
|
||||
double sellPrice = getSellPrice(id);
|
||||
ShopType shopType = getShopType(id);
|
||||
|
||||
if (ShopUtils.isShop(location)) return ShopUtils.getShop(location);
|
||||
else return new Shop(plugin, vendor, product, location, buyPrice, sellPrice, shopType);
|
||||
OfflinePlayer vendor = getVendor(id);
|
||||
Location location = getLocation(id);
|
||||
ItemStack product = getProduct(id);
|
||||
double buyPrice = getBuyPrice(id);
|
||||
double sellPrice = getSellPrice(id);
|
||||
ShopType shopType = getShopType(id);
|
||||
|
||||
if (ShopUtils.isShop(location)) return ShopUtils.getShop(location);
|
||||
else return new Shop(plugin, vendor, product, location, buyPrice, sellPrice, shopType);
|
||||
}
|
||||
|
||||
|
||||
@ -499,8 +492,8 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
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(3, Utils.encode(shop.getProduct()));
|
||||
ps.setString(4, shop.getLocation().getWorld().getName());
|
||||
@ -510,7 +503,7 @@ public abstract class Database {
|
||||
ps.setDouble(8, shop.getBuyPrice());
|
||||
ps.setDouble(9, shop.getSellPrice());
|
||||
ps.setString(10, shop.getShopType().toString());
|
||||
|
||||
|
||||
ps.executeUpdate();
|
||||
return;
|
||||
} catch (SQLException ex) {
|
||||
@ -525,16 +518,16 @@ public abstract class Database {
|
||||
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 {
|
||||
if (ps != null)
|
||||
ps.close();
|
||||
|
@ -1,14 +1,15 @@
|
||||
package de.epiceric.shopchest.sql;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Error {
|
||||
public static void execute(ShopChest plugin, Exception ex){
|
||||
plugin.getLogger().log(Level.SEVERE, "Couldn't execute MySQL statement: ", ex);
|
||||
public static void execute(ShopChest plugin, Exception 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);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
package de.epiceric.shopchest.sql;
|
||||
|
||||
public class Errors {
|
||||
public static String sqlConnectionExecute(){
|
||||
public static String sqlConnectionExecute() {
|
||||
return "Couldn't execute MySQL statement: ";
|
||||
}
|
||||
public static String sqlConnectionClose(){
|
||||
|
||||
public static String sqlConnectionClose() {
|
||||
return "Failed to close MySQL connection: ";
|
||||
}
|
||||
public static String noSQLConnection(){
|
||||
|
||||
public static String noSQLConnection() {
|
||||
return "Unable to retreive MYSQL connection: ";
|
||||
}
|
||||
public static String noTableFound(){
|
||||
|
||||
public static String noTableFound() {
|
||||
return "Database Error: No Table Found";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.epiceric.shopchest.sql;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
@ -8,44 +10,42 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
public class SQLite extends Database {
|
||||
|
||||
|
||||
String dbname;
|
||||
|
||||
public SQLite(ShopChest instance){
|
||||
|
||||
public SQLite(ShopChest instance) {
|
||||
super(instance);
|
||||
dbname = "shops";
|
||||
}
|
||||
|
||||
// SQL creation stuff, You can leave the below stuff untouched.
|
||||
public Connection getSQLConnection() {
|
||||
File dataFolder = new File(plugin.getDataFolder(), dbname+".db");
|
||||
if (!dataFolder.exists()){
|
||||
File dataFolder = new File(plugin.getDataFolder(), dbname + ".db");
|
||||
if (!dataFolder.exists()) {
|
||||
try {
|
||||
dataFolder.createNewFile();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "File write error: "+dbname+".db");
|
||||
plugin.getLogger().log(Level.SEVERE, "File write error: " + dbname + ".db");
|
||||
}
|
||||
}
|
||||
try {
|
||||
if(connection!=null&&!connection.isClosed()){
|
||||
if (connection != null && !connection.isClosed()) {
|
||||
return connection;
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||
return connection;
|
||||
} 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) {
|
||||
plugin.getLogger().log(Level.SEVERE, "You need the SQLite JBDC library. Google it. Put it in /lib folder.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void load() {
|
||||
connection = getSQLConnection();
|
||||
connection = getSQLConnection();
|
||||
try {
|
||||
Statement s = connection.createStatement();
|
||||
s.executeUpdate(SQLiteCreateTokensTable);
|
||||
|
@ -1,73 +1,108 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ArrowEffectNames {
|
||||
|
||||
private static final Map<String, String> effectMap = ImmutableMap.<String, String>builder()
|
||||
.put("FIRE_RESISTANCE", "Fire Resistance")
|
||||
.put("INSTANT_DAMAGE", "Instant Damage")
|
||||
.put("INSTANT_HEAL", "Instant Health")
|
||||
.put("INVISIBILITY", "Invisibility")
|
||||
.put("JUMP", "Jump Boost")
|
||||
.put("LUCK", "Luck")
|
||||
.put("NIGHT_VISION", "Night Vision")
|
||||
.put("POISION", "Poison")
|
||||
.put("REGEN", "Regeneration")
|
||||
.put("SLOWNESS", "Slowness")
|
||||
.put("SPEED", "Speed")
|
||||
.put("STRENGTH", "Strength")
|
||||
.put("WATER_BREATHING", "Water Breathing")
|
||||
.put("WEAKNESS", "Weakness")
|
||||
.build();
|
||||
|
||||
|
||||
public static String getTippedArrowName(ItemStack itemStack) {
|
||||
|
||||
if (!(itemStack.getItemMeta() instanceof PotionMeta)){
|
||||
return null;
|
||||
}
|
||||
|
||||
String name;
|
||||
|
||||
PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
|
||||
|
||||
name = effectMap.get(meta.getBasePotionData().getType().toString());
|
||||
|
||||
if (meta.getBasePotionData().isUpgraded()){
|
||||
name += " II";
|
||||
switch (meta.getBasePotionData().getType()) {
|
||||
case JUMP: name += " (0:11)"; break;
|
||||
case SPEED: name += " (0:11)"; break;
|
||||
case POISON: name += " (0:02)"; break;
|
||||
case REGEN: name += " (0:02)"; break;
|
||||
case STRENGTH: name += " (0:11)"; break;
|
||||
default: break;
|
||||
}
|
||||
} else {
|
||||
switch (meta.getBasePotionData().getType()) {
|
||||
case FIRE_RESISTANCE: 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;
|
||||
}
|
||||
}
|
||||
private static final Map<String, String> effectMap = ImmutableMap.<String, String>builder()
|
||||
.put("FIRE_RESISTANCE", "Fire Resistance")
|
||||
.put("INSTANT_DAMAGE", "Instant Damage")
|
||||
.put("INSTANT_HEAL", "Instant Health")
|
||||
.put("INVISIBILITY", "Invisibility")
|
||||
.put("JUMP", "Jump Boost")
|
||||
.put("LUCK", "Luck")
|
||||
.put("NIGHT_VISION", "Night Vision")
|
||||
.put("POISION", "Poison")
|
||||
.put("REGEN", "Regeneration")
|
||||
.put("SLOWNESS", "Slowness")
|
||||
.put("SPEED", "Speed")
|
||||
.put("STRENGTH", "Strength")
|
||||
.put("WATER_BREATHING", "Water Breathing")
|
||||
.put("WEAKNESS", "Weakness")
|
||||
.build();
|
||||
|
||||
|
||||
public static String getTippedArrowName(ItemStack itemStack) {
|
||||
|
||||
if (!(itemStack.getItemMeta() instanceof PotionMeta)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String name;
|
||||
|
||||
PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
|
||||
|
||||
name = effectMap.get(meta.getBasePotionData().getType().toString());
|
||||
|
||||
if (meta.getBasePotionData().isUpgraded()) {
|
||||
name += " II";
|
||||
switch (meta.getBasePotionData().getType()) {
|
||||
case JUMP:
|
||||
name += " (0:11)";
|
||||
break;
|
||||
case SPEED:
|
||||
name += " (0:11)";
|
||||
break;
|
||||
case POISON:
|
||||
name += " (0:02)";
|
||||
break;
|
||||
case REGEN:
|
||||
name += " (0:02)";
|
||||
break;
|
||||
case STRENGTH:
|
||||
name += " (0:11)";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (meta.getBasePotionData().getType()) {
|
||||
case FIRE_RESISTANCE:
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,71 +1,67 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.epiceric.shopchest.shop.Shop.ShopType;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.epiceric.shopchest.shop.Shop.ShopType;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ClickType {
|
||||
|
||||
private static HashMap<OfflinePlayer, ClickType> playerClickType = new HashMap<>();
|
||||
|
||||
public static ClickType getPlayerClickType(OfflinePlayer player) {
|
||||
if (playerClickType.containsKey(player))
|
||||
return playerClickType.get(player);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void removePlayerClickType(OfflinePlayer player) {
|
||||
playerClickType.remove(player);
|
||||
}
|
||||
|
||||
public static void addPlayerClickType(OfflinePlayer player, ClickType clickType) {
|
||||
playerClickType.put(player, clickType);
|
||||
}
|
||||
|
||||
public enum EnumClickType {
|
||||
CREATE, REMOVE, INFO;
|
||||
}
|
||||
|
||||
private EnumClickType enumClickType;
|
||||
private ItemStack product;
|
||||
private double buyPrice;
|
||||
private double sellPrice;
|
||||
private ShopType shopType;
|
||||
|
||||
public ClickType(EnumClickType enumClickType) {
|
||||
this.enumClickType = enumClickType;
|
||||
}
|
||||
|
||||
public ClickType(EnumClickType enumClickType, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
|
||||
this.enumClickType = enumClickType;
|
||||
this.product = product;
|
||||
this.sellPrice = sellPrice;
|
||||
this.buyPrice = buyPrice;
|
||||
this.shopType = shopType;
|
||||
}
|
||||
|
||||
public EnumClickType getClickType() {
|
||||
return enumClickType;
|
||||
}
|
||||
|
||||
public ItemStack getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public double getBuyPrice() {
|
||||
return buyPrice;
|
||||
}
|
||||
|
||||
public double getSellPrice() {
|
||||
return sellPrice;
|
||||
}
|
||||
|
||||
public ShopType getShopType() {
|
||||
return shopType;
|
||||
}
|
||||
|
||||
private static HashMap<OfflinePlayer, ClickType> playerClickType = new HashMap<>();
|
||||
private EnumClickType enumClickType;
|
||||
private ItemStack product;
|
||||
private double buyPrice;
|
||||
private double sellPrice;
|
||||
private ShopType shopType;
|
||||
public ClickType(EnumClickType enumClickType) {
|
||||
this.enumClickType = enumClickType;
|
||||
}
|
||||
public ClickType(EnumClickType enumClickType, ItemStack product, double buyPrice, double sellPrice, ShopType shopType) {
|
||||
this.enumClickType = enumClickType;
|
||||
this.product = product;
|
||||
this.sellPrice = sellPrice;
|
||||
this.buyPrice = buyPrice;
|
||||
this.shopType = shopType;
|
||||
}
|
||||
|
||||
public static ClickType getPlayerClickType(OfflinePlayer player) {
|
||||
if (playerClickType.containsKey(player))
|
||||
return playerClickType.get(player);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void removePlayerClickType(OfflinePlayer player) {
|
||||
playerClickType.remove(player);
|
||||
}
|
||||
|
||||
public static void addPlayerClickType(OfflinePlayer player, ClickType clickType) {
|
||||
playerClickType.put(player, clickType);
|
||||
}
|
||||
|
||||
public EnumClickType getClickType() {
|
||||
return enumClickType;
|
||||
}
|
||||
|
||||
public ItemStack getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public double getBuyPrice() {
|
||||
return buyPrice;
|
||||
}
|
||||
|
||||
public double getSellPrice() {
|
||||
return sellPrice;
|
||||
}
|
||||
|
||||
public ShopType getShopType() {
|
||||
return shopType;
|
||||
}
|
||||
|
||||
public enum EnumClickType {
|
||||
CREATE, REMOVE, INFO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,84 +1,83 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class EnchantmentNames {
|
||||
|
||||
private static final Map<String, String> enchMap = ImmutableMap.<String, String>builder()
|
||||
.put("PROTECTION_ENVIRONMENTAL", "Protection")
|
||||
.put("PROTECTION_FIRE", "Fire Protection")
|
||||
.put("PROTECTION_FALL", "Feather Falling")
|
||||
.put("PROTECTION_EXPLOSIONS", "Blast Protection")
|
||||
.put("OXYGEN", "Respiration")
|
||||
.put("WATER_WORKER", "Aqua Affinity")
|
||||
.put("THORNS", "Thorns")
|
||||
.put("DEPTH_STRIDER", "Depth Strider")
|
||||
.put("DAMAGE_ALL", "Sharpness")
|
||||
.put("DAMAGE_UNDEAD", "smite")
|
||||
.put("DAMAGE_ARTHROPODS", "Bane of Arthropods")
|
||||
.put("KNOCKBACK", "Knockback")
|
||||
.put("FIRE_ASPECT", "Fire Aspect")
|
||||
.put("LOOT_BONUS_MOBS", "Looting")
|
||||
.put("DIG_SPEED", "Efficiency")
|
||||
.put("SILK_TOUCH", "Silk Touch")
|
||||
.put("DURABILITY", "Unbreaking")
|
||||
.put("LOOT_BONUS_BLOCKS", "Fortune")
|
||||
.put("ARROW_DAMAGE", "Power")
|
||||
.put("ARROW_KNOCKBACK", "Punch")
|
||||
.put("ARROW_FIRE", "Flame")
|
||||
.put("ARROW_INFINITE", "Infinity")
|
||||
.put("LUCK", "Luck of the Sea")
|
||||
.put("LURE", "Lure")
|
||||
.build();
|
||||
|
||||
public static String lookup(Enchantment enchantment, int level) {
|
||||
String key = enchantment.getName();
|
||||
String name = enchMap.get(key);
|
||||
|
||||
String levelString = getRomanNumber(level);
|
||||
|
||||
return name + " " + levelString;
|
||||
private static final Map<String, String> enchMap = ImmutableMap.<String, String>builder()
|
||||
.put("PROTECTION_ENVIRONMENTAL", "Protection")
|
||||
.put("PROTECTION_FIRE", "Fire Protection")
|
||||
.put("PROTECTION_FALL", "Feather Falling")
|
||||
.put("PROTECTION_EXPLOSIONS", "Blast Protection")
|
||||
.put("OXYGEN", "Respiration")
|
||||
.put("WATER_WORKER", "Aqua Affinity")
|
||||
.put("THORNS", "Thorns")
|
||||
.put("DEPTH_STRIDER", "Depth Strider")
|
||||
.put("DAMAGE_ALL", "Sharpness")
|
||||
.put("DAMAGE_UNDEAD", "smite")
|
||||
.put("DAMAGE_ARTHROPODS", "Bane of Arthropods")
|
||||
.put("KNOCKBACK", "Knockback")
|
||||
.put("FIRE_ASPECT", "Fire Aspect")
|
||||
.put("LOOT_BONUS_MOBS", "Looting")
|
||||
.put("DIG_SPEED", "Efficiency")
|
||||
.put("SILK_TOUCH", "Silk Touch")
|
||||
.put("DURABILITY", "Unbreaking")
|
||||
.put("LOOT_BONUS_BLOCKS", "Fortune")
|
||||
.put("ARROW_DAMAGE", "Power")
|
||||
.put("ARROW_KNOCKBACK", "Punch")
|
||||
.put("ARROW_FIRE", "Flame")
|
||||
.put("ARROW_INFINITE", "Infinity")
|
||||
.put("LUCK", "Luck of the Sea")
|
||||
.put("LURE", "Lure")
|
||||
.build();
|
||||
|
||||
public static String lookup(Enchantment enchantment, int level) {
|
||||
String key = enchantment.getName();
|
||||
String name = enchMap.get(key);
|
||||
|
||||
String levelString = getRomanNumber(level);
|
||||
|
||||
return name + " " + levelString;
|
||||
}
|
||||
|
||||
public static String getRomanNumber(int Int) {
|
||||
|
||||
LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>();
|
||||
roman_numerals.put("M", 1000);
|
||||
roman_numerals.put("CM", 900);
|
||||
roman_numerals.put("D", 500);
|
||||
roman_numerals.put("CD", 400);
|
||||
roman_numerals.put("C", 100);
|
||||
roman_numerals.put("XC", 90);
|
||||
roman_numerals.put("L", 50);
|
||||
roman_numerals.put("XL", 40);
|
||||
roman_numerals.put("X", 10);
|
||||
roman_numerals.put("IX", 9);
|
||||
roman_numerals.put("V", 5);
|
||||
roman_numerals.put("IV", 4);
|
||||
roman_numerals.put("I", 1);
|
||||
String res = "";
|
||||
for(Map.Entry<String, Integer> entry : roman_numerals.entrySet()){
|
||||
int matches = Int/entry.getValue();
|
||||
res += repeat(entry.getKey(), matches);
|
||||
Int = Int % entry.getValue();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String repeat(String s, int n) {
|
||||
if(s == null) {
|
||||
return null;
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < n; i++) {
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getRomanNumber(int Int) {
|
||||
|
||||
LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>();
|
||||
roman_numerals.put("M", 1000);
|
||||
roman_numerals.put("CM", 900);
|
||||
roman_numerals.put("D", 500);
|
||||
roman_numerals.put("CD", 400);
|
||||
roman_numerals.put("C", 100);
|
||||
roman_numerals.put("XC", 90);
|
||||
roman_numerals.put("L", 50);
|
||||
roman_numerals.put("XL", 40);
|
||||
roman_numerals.put("X", 10);
|
||||
roman_numerals.put("IX", 9);
|
||||
roman_numerals.put("V", 5);
|
||||
roman_numerals.put("IV", 4);
|
||||
roman_numerals.put("I", 1);
|
||||
String res = "";
|
||||
for (Map.Entry<String, Integer> entry : roman_numerals.entrySet()) {
|
||||
int matches = Int / entry.getValue();
|
||||
res += repeat(entry.getKey(), matches);
|
||||
Int = Int % entry.getValue();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String repeat(String s, int n) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) {
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.DyeColor;
|
||||
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.LeatherArmorMeta;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
|
||||
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:1", "Granite")
|
||||
.put("1:2", "Polished Granite")
|
||||
@ -523,34 +522,34 @@ public class ItemNames {
|
||||
.put("380", "Cauldron")
|
||||
.put("381", "Eye of Ender")
|
||||
.put("382", "Glistering Melon")
|
||||
.put("383", "Spawn Egg")
|
||||
.put("383:50", "Spawn Creeper")
|
||||
.put("383:51", "Spawn Skeleton")
|
||||
.put("383:52", "Spawn Spider")
|
||||
.put("383:54", "Spawn Zombie")
|
||||
.put("383:55", "Spawn Slime")
|
||||
.put("383:56", "Spawn Ghast")
|
||||
.put("383:57", "Spawn Pigman")
|
||||
.put("383:58", "Spawn Enderman")
|
||||
.put("383:59", "Spawn Cave Spider")
|
||||
.put("383:60", "Spawn Silverfish")
|
||||
.put("383:61", "Spawn Blaze")
|
||||
.put("383:62", "Spawn Magma Cube")
|
||||
.put("383:65", "Spawn Bat")
|
||||
.put("383:66", "Spawn Witch")
|
||||
.put("383:67", "Spawn Endermite")
|
||||
.put("383:68", "Spawn Guardian")
|
||||
.put("383:90", "Spawn Pig")
|
||||
.put("383:91", "Spawn Sheep")
|
||||
.put("383:92", "Spawn Cow")
|
||||
.put("383:93", "Spawn Chicken")
|
||||
.put("383:94", "Spawn Squid")
|
||||
.put("383:95", "Spawn Wolf")
|
||||
.put("383:96", "Spawn Mooshroom")
|
||||
.put("383:98", "Spawn Ocelot")
|
||||
.put("383:100", "Spawn Horse")
|
||||
.put("383:101", "Spawn Rabbit")
|
||||
.put("383:120", "Spawn Villager")
|
||||
.put("383", "Spawn Egg")
|
||||
.put("383:50", "Spawn Creeper")
|
||||
.put("383:51", "Spawn Skeleton")
|
||||
.put("383:52", "Spawn Spider")
|
||||
.put("383:54", "Spawn Zombie")
|
||||
.put("383:55", "Spawn Slime")
|
||||
.put("383:56", "Spawn Ghast")
|
||||
.put("383:57", "Spawn Pigman")
|
||||
.put("383:58", "Spawn Enderman")
|
||||
.put("383:59", "Spawn Cave Spider")
|
||||
.put("383:60", "Spawn Silverfish")
|
||||
.put("383:61", "Spawn Blaze")
|
||||
.put("383:62", "Spawn Magma Cube")
|
||||
.put("383:65", "Spawn Bat")
|
||||
.put("383:66", "Spawn Witch")
|
||||
.put("383:67", "Spawn Endermite")
|
||||
.put("383:68", "Spawn Guardian")
|
||||
.put("383:90", "Spawn Pig")
|
||||
.put("383:91", "Spawn Sheep")
|
||||
.put("383:92", "Spawn Cow")
|
||||
.put("383:93", "Spawn Chicken")
|
||||
.put("383:94", "Spawn Squid")
|
||||
.put("383:95", "Spawn Wolf")
|
||||
.put("383:96", "Spawn Mooshroom")
|
||||
.put("383:98", "Spawn Ocelot")
|
||||
.put("383:100", "Spawn Horse")
|
||||
.put("383:101", "Spawn Rabbit")
|
||||
.put("383:120", "Spawn Villager")
|
||||
.put("384", "Bottle o' Enchanting")
|
||||
.put("385", "Fire Charge")
|
||||
.put("386", "Book and Quill")
|
||||
@ -633,14 +632,14 @@ public class ItemNames {
|
||||
.put("2266", "Music Disk (11)")
|
||||
.put("2267", "Music Disk (wait)")
|
||||
.build();
|
||||
|
||||
public static String lookup(ItemStack stack) {
|
||||
|
||||
public static String lookup(ItemStack stack) {
|
||||
if (stack.hasItemMeta()) {
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if (meta.getDisplayName() != null) {
|
||||
return meta.getDisplayName();
|
||||
} 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"
|
||||
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) {
|
||||
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);
|
||||
} else if (mat == Material.LEATHER_HELMET || mat == Material.LEATHER_CHESTPLATE || mat == Material.LEATHER_LEGGINGS || mat == Material.LEATHER_BOOTS) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) stack.getItemMeta();
|
||||
@ -668,5 +667,5 @@ public class ItemNames {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -36,25 +36,13 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
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.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collection;
|
||||
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.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@ -147,6 +135,121 @@ public class Metrics {
|
||||
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
|
||||
* website. Plotters can be added to the graph object returned.
|
||||
@ -325,26 +428,26 @@ public class Metrics {
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the online player (backwards compatibility)
|
||||
*
|
||||
*
|
||||
* @return online player amount
|
||||
*/
|
||||
private int getOnlinePlayers() {
|
||||
try {
|
||||
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
|
||||
if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
|
||||
return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
|
||||
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
|
||||
return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
|
||||
} else {
|
||||
return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
|
||||
return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
*
|
||||
@ -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
|
||||
*/
|
||||
|
@ -1,10 +1,9 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -14,158 +13,158 @@ import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ShopUtils {
|
||||
|
||||
private static HashMap<Location, Shop> shopLocation = new HashMap<>();
|
||||
|
||||
public static Shop getShop(Location location) {
|
||||
|
||||
Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
|
||||
if (shopLocation.containsKey(newLocation)) {
|
||||
return shopLocation.get(newLocation);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean isShop(Location location) {
|
||||
|
||||
Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
|
||||
return shopLocation.containsKey(newLocation);
|
||||
|
||||
}
|
||||
|
||||
public static Shop[] getShops() {
|
||||
|
||||
ArrayList<Shop> shops = new ArrayList<>();
|
||||
|
||||
for (Shop shop : shopLocation.values()) {
|
||||
shops.add(shop);
|
||||
}
|
||||
|
||||
return shops.toArray(new Shop[shops.size()]);
|
||||
|
||||
}
|
||||
|
||||
public static void addShop(Shop shop) {
|
||||
|
||||
Location loc = shop.getLocation();
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
shopLocation.put(r.getLocation(), shop);
|
||||
shopLocation.put(l.getLocation(), shop);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
shopLocation.put(shop.getLocation(), shop);
|
||||
|
||||
}
|
||||
|
||||
public static void removeShop(Shop shop) {
|
||||
|
||||
Location loc = shop.getLocation();
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
shop.removeHologram();
|
||||
shopLocation.remove(r.getLocation());
|
||||
shopLocation.remove(l.getLocation());
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
shopLocation.remove(shop.getLocation());
|
||||
|
||||
}
|
||||
private static HashMap<Location, Shop> shopLocation = new HashMap<>();
|
||||
|
||||
public static Shop getShop(Location location) {
|
||||
|
||||
Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
|
||||
if (shopLocation.containsKey(newLocation)) {
|
||||
return shopLocation.get(newLocation);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean isShop(Location location) {
|
||||
|
||||
Location newLocation = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
|
||||
|
||||
return shopLocation.containsKey(newLocation);
|
||||
|
||||
}
|
||||
|
||||
public static Shop[] getShops() {
|
||||
|
||||
ArrayList<Shop> shops = new ArrayList<>();
|
||||
|
||||
for (Shop shop : shopLocation.values()) {
|
||||
shops.add(shop);
|
||||
}
|
||||
|
||||
return shops.toArray(new Shop[shops.size()]);
|
||||
|
||||
}
|
||||
|
||||
public static void addShop(Shop shop) {
|
||||
|
||||
Location loc = shop.getLocation();
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
shopLocation.put(r.getLocation(), shop);
|
||||
shopLocation.put(l.getLocation(), shop);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
shopLocation.put(shop.getLocation(), shop);
|
||||
|
||||
}
|
||||
|
||||
public static void removeShop(Shop shop) {
|
||||
|
||||
Location loc = shop.getLocation();
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
Chest c = (Chest) b.getState();
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
if (ih instanceof DoubleChest) {
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
shop.removeHologram();
|
||||
shopLocation.remove(r.getLocation());
|
||||
shopLocation.remove(l.getLocation());
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,75 +1,74 @@
|
||||
package de.epiceric.shopchest.utils;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
public enum UpdateCheckerResult {
|
||||
TRUE,
|
||||
FALSE,
|
||||
ERROR;
|
||||
}
|
||||
|
||||
private ShopChest plugin;
|
||||
private String url;
|
||||
private String version;
|
||||
private String link;
|
||||
|
||||
public UpdateChecker(ShopChest plugin, String url) {
|
||||
this.plugin = plugin;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public UpdateCheckerResult updateNeeded() {
|
||||
try {
|
||||
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");
|
||||
|
||||
Document doc = con.get();
|
||||
|
||||
version = doc.text().split("\\|")[0];
|
||||
link = url + "download?version=" + doc.text().split("\\|")[1];
|
||||
|
||||
if(plugin.getDescription().getVersion().equals(version))
|
||||
return UpdateCheckerResult.FALSE;
|
||||
else
|
||||
return UpdateCheckerResult.TRUE;
|
||||
|
||||
} catch (Exception | Error e) {
|
||||
return UpdateCheckerResult.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getBroadcast() {
|
||||
try {
|
||||
Connection con = Jsoup.connect("http://textuploader.com/5b51f/raw");
|
||||
con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");
|
||||
|
||||
Document doc = con.get();
|
||||
|
||||
String broadcast = doc.text();
|
||||
|
||||
String[] messages = broadcast.split("#n");
|
||||
|
||||
if (!broadcast.equals("/"))
|
||||
return messages;
|
||||
|
||||
} catch (Exception | Error e) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
private ShopChest plugin;
|
||||
private String url;
|
||||
private String version;
|
||||
private String link;
|
||||
public UpdateChecker(ShopChest plugin, String url) {
|
||||
this.plugin = plugin;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public UpdateCheckerResult updateNeeded() {
|
||||
try {
|
||||
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");
|
||||
|
||||
Document doc = con.get();
|
||||
|
||||
version = doc.text().split("\\|")[0];
|
||||
link = url + "download?version=" + doc.text().split("\\|")[1];
|
||||
|
||||
if (plugin.getDescription().getVersion().equals(version))
|
||||
return UpdateCheckerResult.FALSE;
|
||||
else
|
||||
return UpdateCheckerResult.TRUE;
|
||||
|
||||
} catch (Exception | Error e) {
|
||||
return UpdateCheckerResult.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getBroadcast() {
|
||||
try {
|
||||
Connection con = Jsoup.connect("http://textuploader.com/5b51f/raw");
|
||||
con.userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");
|
||||
|
||||
Document doc = con.get();
|
||||
|
||||
String broadcast = doc.text();
|
||||
|
||||
String[] messages = broadcast.split("#n");
|
||||
|
||||
if (!broadcast.equals("/"))
|
||||
return messages;
|
||||
|
||||
} catch (Exception | Error e) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public enum UpdateCheckerResult {
|
||||
TRUE,
|
||||
FALSE,
|
||||
ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user