Added 1.10 Support (1.10_R1)

This commit is contained in:
Eric 2016-06-09 19:34:48 +02:00
parent 8a08dcb059
commit 8def855a43
8 changed files with 665 additions and 440 deletions

View File

@ -36,6 +36,7 @@ BOAT_DARK_OAK
BOAT_JUNGLE
BOAT_SPRUCE
BONE
BONE_BLOCK
BOOK
BOOK_AND_QUILL
BOOKSHELF
@ -238,6 +239,7 @@ LINGERING_POTION
LOG
LOG_2
LONG_GRASS
MAGMA
MAGMA_CREAM
MAP
MELON
@ -260,6 +262,7 @@ NETHER_BRICK_STAIRS
NETHER_FENCE
NETHER_STALK
NETHER_STAR
NETHER_WART_BLOCK
NETHER_WARTS
NETHERRACK
NOTE_BLOCK
@ -314,6 +317,7 @@ RECORD_7
RECORD_8
RECORD_9
RED_MUSHROOM
RED_NETHER_BRICK
RED_ROSE
RED_SANDSTONE
RED_SANDSTONE_STAIRS
@ -381,6 +385,7 @@ STONE_SWORD
STORAGE_MINECART
STRING
STRUCTURE_BLOCK
STRUCTURE_VOID
SUGAR
SUGAR_CANE
SUGAR_CANE_BLOCK

View File

@ -2,7 +2,6 @@ package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.utils.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.utils.ClickType;
@ -10,6 +9,7 @@ import de.epiceric.shopchest.utils.ClickType.EnumClickType;
import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
@ -153,6 +153,9 @@ public class Commands extends BukkitCommand {
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion));
break;
case "v1_10_R1":
jb = new JsonBuilder_1_10_R1(Config.update_available(ShopChest.latestVersion));
break;
default:
return;
}

View File

@ -3,7 +3,6 @@ package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.event.*;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.utils.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType;
@ -16,6 +15,7 @@ import de.epiceric.shopchest.utils.Metrics.Plotter;
import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
@ -78,6 +78,20 @@ public class ShopChest extends JavaPlugin {
return;
}
switch (Utils.getVersion(getServer())) {
case "v1_8_R1":
case "v1_8_R2":
case "v1_8_R3":
case "v1_9_R1":
case "v1_9_R2":
case "v1_10_R1":
break;
default:
logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!");
getServer().getPluginManager().disablePlugin(this);
return;
}
try {
Metrics metrics = new Metrics(this);
Graph shopType = metrics.createGraph("Shop Type");
@ -153,20 +167,6 @@ public class ShopChest extends JavaPlugin {
database = new MySQL(this);
}
switch (Utils.getVersion(getServer())) {
case "v1_8_R1":
case "v1_8_R2":
case "v1_8_R3":
case "v1_9_R1":
case "v1_9_R2":
break;
default:
logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!");
getServer().getPluginManager().disablePlugin(this);
return;
}
lockette = getServer().getPluginManager().getPlugin("Lockette") != null;
lwc = getServer().getPluginManager().getPlugin("LWC") != null;
@ -203,6 +203,9 @@ public class ShopChest extends JavaPlugin {
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(Config.update_available(latestVersion));
break;
case "v1_10_R1":
jb = new JsonBuilder_1_10_R1(Config.update_available(latestVersion));
break;
default:
return;
}

View File

@ -3,8 +3,8 @@ 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.utils.Utils;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -43,6 +43,9 @@ public class NotifyUpdate implements Listener {
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion));
break;
case "v1_10_R1":
jb = new JsonBuilder_1_10_R1(Config.update_available(ShopChest.latestVersion));
break;
default:
return;
}

View File

@ -0,0 +1,94 @@
package de.epiceric.shopchest.interfaces.hologram;
import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_10_R1.EntityArmorStand;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_10_R1.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_10_R1 implements Hologram {
private boolean exists = false;
private int count;
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
private String[] text;
private Location location;
private double DISTANCE = 0.25D;
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
public Hologram_1_10_R1(String[] text, Location location) {
this.text = 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.setNoGravity(true);
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);
}
count = 0;
exists = true;
}
public boolean exists() {
return exists;
}
public void remove() {
for (EntityArmorStand e : entitylist) {
e.die();
}
exists = false;
}
}

View File

@ -0,0 +1,111 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_10_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_10_R1 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
public JsonBuilder_1_10_R1(String... text) {
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_10_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_10_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_10_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_10_R1 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_10_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_10_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -3,9 +3,9 @@ package de.epiceric.shopchest.shop;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.utils.Utils;
import de.epiceric.shopchest.interfaces.hologram.*;
import de.epiceric.shopchest.utils.ItemNames;
import de.epiceric.shopchest.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -178,8 +178,9 @@ public class Shop {
case "v1_9_R2":
hologram = new Hologram_1_9_R2(holoText, holoLocation);
break;
default:
return;
case "v1_10_R1":
hologram = new Hologram_1_10_R1(holoText, holoLocation);
break;
}
}
@ -218,7 +219,7 @@ public class Shop {
public enum ShopType {
NORMAL,
ADMIN;
ADMIN
}
}

View File

@ -312,6 +312,11 @@ public class ItemNames {
.put("210", "Repeating Command Block")
.put("211", "Chain Command Block")
.put("212", "Frosted Ice")
.put("213", "Magma Block")
.put("214", "Nether Wart Block")
.put("215", "Red Nether Brick")
.put("216", "Bone Block")
.put("217", "Structure Void")
.put("255", "Structure Block")
.put("256", "Iron Shovel")
.put("257", "Iron Pickaxe")