mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-12-23 01:21:47 +00:00
parent
49530f806d
commit
103c96bc2f
@ -17,9 +17,7 @@ import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R1;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R2;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R3;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
|
||||
import de.epiceric.shopchest.utils.ClickType;
|
||||
import de.epiceric.shopchest.utils.ClickType.EnumClickType;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
@ -181,9 +179,10 @@ public class Commands extends BukkitCommand {
|
||||
|
||||
JsonBuilder jb;
|
||||
switch (Utils.getVersion(plugin.getServer())) {
|
||||
case "v1_8_R1": jb = new JsonBuilder_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R2": jb = new JsonBuilder_R2(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R3": jb = new JsonBuilder_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
default: return;
|
||||
}
|
||||
jb.sendJson(player);
|
||||
|
@ -27,17 +27,13 @@ import de.epiceric.shopchest.event.RegenerateShopItem;
|
||||
import de.epiceric.shopchest.event.RegenerateShopItemAfterRemove;
|
||||
import de.epiceric.shopchest.event.UpdateHolograms;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.utils.Utils_R1;
|
||||
import de.epiceric.shopchest.interfaces.utils.Utils_R2;
|
||||
import de.epiceric.shopchest.interfaces.utils.Utils_R3;
|
||||
import de.epiceric.shopchest.interfaces.utils.*;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.sql.SQLite;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R1;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R2;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R3;
|
||||
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;
|
||||
@ -150,11 +146,12 @@ public class ShopChest extends JavaPlugin{
|
||||
|
||||
switch (Utils.getVersion(getServer())) {
|
||||
|
||||
case "v1_8_R1": utils = new Utils_R1(); break;
|
||||
case "v1_8_R2": utils = new Utils_R2(); break;
|
||||
case "v1_8_R3": utils = new Utils_R3(); break;
|
||||
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;
|
||||
default:
|
||||
logger.severe("Incompatible Server Version!");
|
||||
logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
@ -194,9 +191,10 @@ public class ShopChest extends JavaPlugin{
|
||||
if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
|
||||
JsonBuilder jb;
|
||||
switch (Utils.getVersion(getServer())) {
|
||||
case "v1_8_R1": jb = new JsonBuilder_R1(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
case "v1_8_R2": jb = new JsonBuilder_R2(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
case "v1_8_R3": jb = new JsonBuilder_R3(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break;
|
||||
default: return;
|
||||
}
|
||||
jb.sendJson(p);
|
||||
|
@ -16,7 +16,6 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
@ -248,9 +247,7 @@ public class InteractShop implements Listener{
|
||||
|
||||
sqlite.removeShop(shop);
|
||||
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
shop.getHologram().hidePlayer(player);
|
||||
}
|
||||
shop.removeHologram();
|
||||
|
||||
executor.sendMessage(Config.shop_removed());
|
||||
|
||||
|
@ -8,9 +8,7 @@ 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.JsonBuilder_R1;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R2;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R3;
|
||||
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction;
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction;
|
||||
@ -32,9 +30,10 @@ public class NotifyUpdate implements Listener {
|
||||
JsonBuilder jb;
|
||||
|
||||
switch (Utils.getVersion(ShopChest.getInstance().getServer())) {
|
||||
case "v1_8_R1": jb = new JsonBuilder_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R2": jb = new JsonBuilder_R2(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R3": jb = new JsonBuilder_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break;
|
||||
default: return;
|
||||
}
|
||||
jb.sendJson(p);
|
||||
|
@ -31,7 +31,7 @@ public class ProtectChest implements Listener {
|
||||
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();
|
||||
|
||||
@ -40,23 +40,28 @@ public class ProtectChest implements Listener {
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) {
|
||||
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;
|
||||
}
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
Shop newShop = new Shop(ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.isInfinite());
|
||||
newShop.createHologram();
|
||||
newShop.createItem();
|
||||
ShopUtils.addShop(newShop);
|
||||
ShopChest.sqlite.addShop(newShop);
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.server.v1_8_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
public class Hologram_R1 implements Hologram {
|
||||
public class Hologram_1_8_R1 implements Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
@ -24,13 +24,13 @@ public class Hologram_R1 implements Hologram {
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_R1(String[] text, Location location) {
|
||||
public Hologram_1_8_R1(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_R1(String text, Location location) {
|
||||
public Hologram_1_8_R1(String text, Location location) {
|
||||
this.text = new String[] {text};
|
||||
this.location = location;
|
||||
create();
|
@ -14,7 +14,7 @@ import net.minecraft.server.v1_8_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
public class Hologram_R2 implements Hologram {
|
||||
public class Hologram_1_8_R2 implements Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
@ -24,13 +24,13 @@ public class Hologram_R2 implements Hologram {
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_R2(String[] text, Location location) {
|
||||
public Hologram_1_8_R2(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_R2(String text, Location location) {
|
||||
public Hologram_1_8_R2(String text, Location location) {
|
||||
this.text = new String[] {text};
|
||||
this.location = location;
|
||||
create();
|
@ -14,7 +14,7 @@ import net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
public class Hologram_R3 implements Hologram {
|
||||
public class Hologram_1_8_R3 implements Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
@ -24,13 +24,13 @@ public class Hologram_R3 implements Hologram {
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_R3(String[] text, Location location) {
|
||||
public Hologram_1_8_R3(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_R3(String text, Location location) {
|
||||
public Hologram_1_8_R3(String text, Location location) {
|
||||
this.text = new String[] {text};
|
||||
this.location = location;
|
||||
create();
|
@ -0,0 +1,87 @@
|
||||
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;
|
||||
|
||||
public class Hologram_1_9_R1 implements Hologram {
|
||||
|
||||
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.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, true);
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -13,20 +13,20 @@ import net.minecraft.server.v1_8_R1.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
|
||||
|
||||
|
||||
public class JsonBuilder_R1 implements JsonBuilder {
|
||||
public class JsonBuilder_1_8_R1 implements JsonBuilder {
|
||||
|
||||
/* JsonBuilder by FisheyLP */
|
||||
|
||||
private List<String> extras = new ArrayList<String>();
|
||||
|
||||
|
||||
public JsonBuilder_R1(String... text) {
|
||||
public JsonBuilder_1_8_R1(String... text) {
|
||||
for(String extra : text)
|
||||
parse(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 parse(String text) {
|
||||
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()) {
|
||||
@ -47,34 +47,34 @@ public class JsonBuilder_R1 implements JsonBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withText(String text) {
|
||||
public JsonBuilder_1_8_R1 withText(String text) {
|
||||
extras.add("{text:\"" + text + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withColor(ChatColor color) {
|
||||
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_R1 withColor(String color) {
|
||||
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_R1 withClickEvent(ClickAction action, String value) {
|
||||
public JsonBuilder_1_8_R1 withClickEvent(ClickAction action, String value) {
|
||||
addSegment("clickEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withHoverEvent(HoverAction action, String value) {
|
||||
public JsonBuilder_1_8_R1 withHoverEvent(HoverAction action, String value) {
|
||||
addSegment("hoverEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
@ -13,20 +13,20 @@ import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
|
||||
|
||||
|
||||
public class JsonBuilder_R2 implements JsonBuilder {
|
||||
public class JsonBuilder_1_8_R2 implements JsonBuilder {
|
||||
|
||||
/* JsonBuilder by FisheyLP */
|
||||
|
||||
private List<String> extras = new ArrayList<String>();
|
||||
|
||||
|
||||
public JsonBuilder_R2(String... text) {
|
||||
public JsonBuilder_1_8_R2(String... text) {
|
||||
for(String extra : text)
|
||||
parse(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 parse(String text) {
|
||||
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()) {
|
||||
@ -47,34 +47,34 @@ public class JsonBuilder_R2 implements JsonBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withText(String text) {
|
||||
public JsonBuilder_1_8_R2 withText(String text) {
|
||||
extras.add("{text:\"" + text + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withColor(ChatColor color) {
|
||||
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_R2 withColor(String color) {
|
||||
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_R2 withClickEvent(ClickAction action, String value) {
|
||||
public JsonBuilder_1_8_R2 withClickEvent(ClickAction action, String value) {
|
||||
addSegment("clickEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withHoverEvent(HoverAction action, String value) {
|
||||
public JsonBuilder_1_8_R2 withHoverEvent(HoverAction action, String value) {
|
||||
addSegment("hoverEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
@ -13,20 +13,20 @@ import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
|
||||
|
||||
public class JsonBuilder_R3 implements JsonBuilder {
|
||||
public class JsonBuilder_1_8_R3 implements JsonBuilder {
|
||||
|
||||
/* JsonBuilder by FisheyLP */
|
||||
|
||||
private List<String> extras = new ArrayList<String>();
|
||||
|
||||
|
||||
public JsonBuilder_R3(String... text) {
|
||||
public JsonBuilder_1_8_R3(String... text) {
|
||||
for(String extra : text)
|
||||
parse(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 parse(String text) {
|
||||
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()) {
|
||||
@ -47,34 +47,34 @@ public class JsonBuilder_R3 implements JsonBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withText(String text) {
|
||||
public JsonBuilder_1_8_R3 withText(String text) {
|
||||
extras.add("{text:\"" + text + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withColor(ChatColor color) {
|
||||
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_R3 withColor(String color) {
|
||||
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_R3 withClickEvent(ClickAction action, String value) {
|
||||
public JsonBuilder_1_8_R3 withClickEvent(ClickAction action, String value) {
|
||||
addSegment("clickEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withHoverEvent(HoverAction action, String value) {
|
||||
public JsonBuilder_1_8_R3 withHoverEvent(HoverAction action, String value) {
|
||||
addSegment("hoverEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
@ -0,0 +1,109 @@
|
||||
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.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
|
||||
|
||||
|
||||
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);
|
||||
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));
|
||||
} 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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_8_R1.EntityArmorStand;
|
||||
|
||||
public class Utils_R1 extends Utils {
|
||||
public class Utils_1_8_R1 extends Utils {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@ -19,7 +19,7 @@ public class Utils_R1 extends Utils {
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
@ -75,7 +75,7 @@ public class Utils_R1 extends Utils {
|
||||
}
|
||||
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_8_R2.EntityArmorStand;
|
||||
|
||||
public class Utils_R2 extends Utils {
|
||||
public class Utils_1_8_R2 extends Utils {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@ -20,7 +20,7 @@ public class Utils_R2 extends Utils {
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
@ -78,7 +78,7 @@ public class Utils_R2 extends Utils {
|
||||
}
|
||||
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||
|
||||
public class Utils_R3 extends Utils {
|
||||
public class Utils_1_8_R3 extends Utils {
|
||||
|
||||
@Override
|
||||
public void reload(Player player) {
|
||||
@ -19,7 +19,7 @@ public class Utils_R3 extends Utils {
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
@ -76,7 +76,7 @@ public class Utils_R3 extends Utils {
|
||||
}
|
||||
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
86
src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R1.java
Normal file
86
src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R1.java
Normal file
@ -0,0 +1,86 @@
|
||||
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.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_9_R1.EntityArmorStand;
|
||||
|
||||
public class Utils_1_9_R1 extends Utils {
|
||||
|
||||
@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 (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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -10,6 +10,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -20,9 +21,7 @@ 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.Hologram_R1;
|
||||
import de.epiceric.shopchest.interfaces.hologram.Hologram_R2;
|
||||
import de.epiceric.shopchest.interfaces.hologram.Hologram_R3;
|
||||
import de.epiceric.shopchest.interfaces.hologram.*;
|
||||
import de.epiceric.shopchest.utils.ItemNames;
|
||||
|
||||
public class Shop {
|
||||
@ -47,6 +46,12 @@ public class Shop {
|
||||
this.infinite = infinite;
|
||||
}
|
||||
|
||||
public void removeHologram() {
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
getHologram().hidePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void createItem() {
|
||||
|
||||
Item item;
|
||||
@ -141,9 +146,10 @@ public class Shop {
|
||||
else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice);
|
||||
|
||||
switch (Utils.getVersion(plugin.getServer())) {
|
||||
case "v1_8_R1": hologram = new Hologram_R1(holoText, holoLocation); break;
|
||||
case "v1_8_R2": hologram = new Hologram_R2(holoText, holoLocation); break;
|
||||
case "v1_8_R3": hologram = new Hologram_R3(holoText, holoLocation); break;
|
||||
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;
|
||||
default: return;
|
||||
}
|
||||
|
||||
@ -181,4 +187,8 @@ public class Shop {
|
||||
return item;
|
||||
}
|
||||
|
||||
public boolean hasItem() {
|
||||
return item != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public abstract class Database {
|
||||
int id = getShopID(shop);
|
||||
if (id == 0) return;
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
|
@ -91,7 +91,8 @@ public class ShopUtils {
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
|
||||
shop.getItem().remove();
|
||||
if (shop.hasItem()) shop.getItem().remove();
|
||||
shop.removeHologram();
|
||||
shopLocation.remove(r.getLocation());
|
||||
shopLocation.remove(l.getLocation());
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user