mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
Added 1.9.4 Support (1.9_R2)
This commit is contained in:
parent
54b0f42eaf
commit
04636a7b01
@ -149,6 +149,7 @@ public class Commands extends BukkitCommand {
|
||||
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);
|
||||
|
@ -163,6 +163,7 @@ public class ShopChest extends JavaPlugin{
|
||||
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);
|
||||
@ -206,6 +207,7 @@ public class ShopChest extends JavaPlugin{
|
||||
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);
|
||||
|
@ -32,6 +32,7 @@ public class NotifyUpdate implements Listener {
|
||||
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);
|
||||
|
@ -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_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;
|
||||
|
||||
public class Hologram_1_9_R2 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_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.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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
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;
|
||||
|
||||
|
||||
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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
86
src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R2.java
Normal file
86
src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R2.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_R2.EntityArmorStand;
|
||||
|
||||
public class Utils_1_9_R2 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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -156,6 +156,7 @@ public class Shop {
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user