1.7 spectator bug fixed.

Placeholderapi is no longer a requirement.
/f showclaims lag fixed
Scoreboard is now off by default, can be turned on in config.
Issue with Flight AutoEnabling when disabled has been fixed.
1.7 itemflag bug fixed
This commit is contained in:
Naman 2018-06-21 14:16:55 -05:00
parent 969b281b44
commit f70cc119df
24 changed files with 1790 additions and 19 deletions

View File

@ -49,6 +49,10 @@ public class P extends MPlugin {
public static Permission perms = null;
public boolean PlaceholderApi;
ItemStack item = new ItemStack(Material.CAKE);
// Persistence related
private boolean locked = false;
@ -100,6 +104,7 @@ public class P extends MPlugin {
public boolean mc17 = false;
public boolean mc18 = false;
public boolean factionsFlight = false;
@Override
@ -160,6 +165,10 @@ public class P extends MPlugin {
mc18 = true;
}
if (P.p.getConfig().getBoolean("enable-faction-flight")) {
factionsFlight = true;
}
// Register Event Handlers
getServer().getPluginManager().registerEvents(new FactionsPlayerListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsChatListener(this), this);
@ -187,8 +196,13 @@ public class P extends MPlugin {
if (clip != null && clip.isEnabled()) {
this.clipPlaceholderAPIManager = new ClipPlaceholderAPIManager();
if (this.clipPlaceholderAPIManager.register()) {
PlaceholderApi = true;
log(Level.INFO, "Successfully registered placeholders with PlaceholderAPI.");
} else {
PlaceholderApi = false;
}
} else {
PlaceholderApi = false;
}
Plugin mvdw = getServer().getPluginManager().getPlugin("MVdWPlaceholderAPI");

View File

@ -47,8 +47,10 @@ public class CmdFly extends FCommand {
if (!player.isFlying()) {
continue;
}
if (player.getGameMode() == GameMode.SPECTATOR){
continue;
if (!P.p.mc17) {
if (player.getGameMode() == GameMode.SPECTATOR){
continue;
}
}
if (FPlayers.getInstance().getByPlayer(player).isVanished()){
continue;

View File

@ -40,11 +40,16 @@ public class CmdShowClaims extends FCommand{
}
for (String world : chunkMap.keySet()){
String message = TL.COMMAND_SHOWCLAIMS_FORMAT.toString().replace("{world}",world);
sendMessage(message.replace("{chunks}","")); // made {chunks} blank as I removed the placeholder and people wont update their config :shrug:
StringBuilder chunks = new StringBuilder("");
for (String chunkString : chunkMap.get(world)){
chunks.append(chunkString + ", ");
if (chunks.toString().length() >= 2000 ) {
sendMessage(chunks.toString());
chunks.setLength(0);
}
}
sendMessage(message.replace("{chunks}",chunks));
sendMessage("");
}

View File

@ -408,6 +408,12 @@ public class FactionsPlayerListener implements Listener {
}
}
if (!P.p.factionsFlight) {
return;
}
// enable fly :)
if (me.hasFaction() && !me.isFlying()) {
if (factionTo == me.getFaction()) {

View File

@ -170,8 +170,10 @@ public class FTeamWrapper {
Team team = teams.get(fboard);
String prefix = TL.DEFAULT_PREFIX.toString();
prefix = PlaceholderAPI.setPlaceholders(fplayer.getPlayer(),prefix);
prefix = PlaceholderAPI.setBracketPlaceholders(fplayer.getPlayer(),prefix);
if (P.p.PlaceholderApi) {
prefix = PlaceholderAPI.setPlaceholders(fplayer.getPlayer(),prefix);
prefix = PlaceholderAPI.setBracketPlaceholders(fplayer.getPlayer(),prefix);
}
prefix = prefix.replace("{relationcolor}", faction.getRelationTo(fplayer).getColor().toString());
prefix = prefix.replace("{faction}", faction.getTag().substring(0, Math.min("{faction}".length() + 16 - prefix.length(), faction.getTag().length())));
if (team.getPrefix() == null || !team.getPrefix().equals(prefix)) {

View File

@ -1,5 +1,7 @@
package com.massivecraft.factions.zcore.util;
package com.massivecraft.factions.util;
import com.massivecraft.factions.zcore.nbtapi.NBTItem;
import com.massivecraft.factions.zcore.nbtapi.NBTType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -7,6 +9,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
import java.util.Set;
public class InventoryUtil {
@ -44,6 +47,16 @@ public class InventoryUtil {
}
}
/*
NBTItem nbtItem = new NBTItem(is);
Set<String> nbtKeySet = nbtItem.getKeys();
for (String nbtKey : nbtKeySet) {
serializedItemStack.append(":n@" + nbtKey + "@" + nbtItem.getType(nbtKey).getId() + "@" + )
}
*/
// serialization += i + "#" + serializedItemStack + ";";
serialization.append(i + "#" + serializedItemStack + ";");
}
@ -87,4 +100,8 @@ public class InventoryUtil {
return deserializedInventory;
}
}

View File

@ -237,7 +237,7 @@ public class FUpgradesGUI implements Listener {
ItemStack expItem = P.p.createItem(expMaterial, expAmt, expData, expName, expLore);
if (expLevel >= 1) {
ItemMeta itemMeta = expItem.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
if (!P.p.mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); }
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
expItem.setItemMeta(itemMeta);
}
@ -275,7 +275,7 @@ public class FUpgradesGUI implements Listener {
cropItem.getItemMeta().setLore(cropLore);
if (cropLevel >= 1) {
ItemMeta itemMeta = cropItem.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
if (!P.p.mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); }
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
cropItem.setItemMeta(itemMeta);
}
@ -288,7 +288,7 @@ public class FUpgradesGUI implements Listener {
spawnerItem.getItemMeta().setLore(spawnerLore);
if (spawnerLevel >= 1) {
ItemMeta itemMeta = spawnerItem.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
if (!P.p.mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); }
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
spawnerItem.setItemMeta(itemMeta);
}
@ -314,7 +314,7 @@ public class FUpgradesGUI implements Listener {
if (chestlevel >= 1) {
ItemMeta itemMeta = chestItem.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
if (!P.p.mc17) { itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); }
itemMeta.addEnchant(Enchantment.DURABILITY, 3, true);
chestItem.setItemMeta(itemMeta);
}

View File

@ -0,0 +1,193 @@
package com.massivecraft.factions.zcore.nbtapi;
import java.util.Set;
import com.massivecraft.factions.zcore.nbtapi.utils.MinecraftVersion;
public class NBTCompound {
private String compundName;
private NBTCompound parent;
protected NBTCompound(NBTCompound owner, String name) {
this.compundName = name;
this.parent = owner;
}
public String getName() {
return compundName;
}
protected Object getCompound() {
return parent.getCompound();
}
protected void setCompound(Object compound) {
parent.setCompound(compound);
}
public NBTCompound getParent() {
return parent;
}
public void mergeCompound(NBTCompound comp){
NBTReflectionUtil.addOtherNBTCompound(this, comp);
}
public void setString(String key, String value) {
NBTReflectionUtil.setString(this, key, value);
}
public String getString(String key) {
return NBTReflectionUtil.getString(this, key);
}
protected String getContent(String key) {
return NBTReflectionUtil.getContent(this, key);
}
public void setInteger(String key, Integer value) {
NBTReflectionUtil.setInt(this, key, value);
}
public Integer getInteger(String key) {
return NBTReflectionUtil.getInt(this, key);
}
public void setDouble(String key, Double value) {
NBTReflectionUtil.setDouble(this, key, value);
}
public Double getDouble(String key) {
return NBTReflectionUtil.getDouble(this, key);
}
public void setByte(String key, Byte value) {
NBTReflectionUtil.setByte(this, key, value);
}
public Byte getByte(String key) {
return NBTReflectionUtil.getByte(this, key);
}
public void setShort(String key, Short value) {
NBTReflectionUtil.setShort(this, key, value);
}
public Short getShort(String key) {
return NBTReflectionUtil.getShort(this, key);
}
public void setLong(String key, Long value) {
NBTReflectionUtil.setLong(this, key, value);
}
public Long getLong(String key) {
return NBTReflectionUtil.getLong(this, key);
}
public void setFloat(String key, Float value) {
NBTReflectionUtil.setFloat(this, key, value);
}
public Float getFloat(String key) {
return NBTReflectionUtil.getFloat(this, key);
}
public void setByteArray(String key, byte[] value) {
NBTReflectionUtil.setByteArray(this, key, value);
}
public byte[] getByteArray(String key) {
return NBTReflectionUtil.getByteArray(this, key);
}
public void setIntArray(String key, int[] value) {
NBTReflectionUtil.setIntArray(this, key, value);
}
public int[] getIntArray(String key) {
return NBTReflectionUtil.getIntArray(this, key);
}
public void setBoolean(String key, Boolean value) {
NBTReflectionUtil.setBoolean(this, key, value);
}
protected void set(String key, Object val) {
NBTReflectionUtil.set(this, key, val);
}
public Boolean getBoolean(String key) {
return NBTReflectionUtil.getBoolean(this, key);
}
public void setObject(String key, Object value) {
NBTReflectionUtil.setObject(this, key, value);
}
public <T> T getObject(String key, Class<T> type) {
return NBTReflectionUtil.getObject(this, key, type);
}
public Boolean hasKey(String key) {
return NBTReflectionUtil.hasKey(this, key);
}
public void removeKey(String key) {
NBTReflectionUtil.remove(this, key);
}
public Set<String> getKeys() {
return NBTReflectionUtil.getKeys(this);
}
public NBTCompound addCompound(String name) {
NBTReflectionUtil.addNBTTagCompound(this, name);
return getCompound(name);
}
public NBTCompound getCompound(String name) {
NBTCompound next = new NBTCompound(this, name);
if (NBTReflectionUtil.valideCompound(next)) return next;
return null;
}
public NBTList getList(String name, NBTType type) {
return NBTReflectionUtil.getList(this, name, type);
}
public NBTType getType(String name) {
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) return NBTType.NBTTagEnd;
return NBTType.valueOf(NBTReflectionUtil.getType(this, name));
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
for (String key : getKeys()) {
result.append(toString(key));
}
return result.toString();
}
public String toString(String key) {
StringBuilder result = new StringBuilder();
NBTCompound compound = this;
while (compound.getParent() != null) {
result.append(" ");
compound = compound.getParent();
}
if (this.getType(key) == NBTType.NBTTagCompound) {
return this.getCompound(key).toString();
} else {
return result + "-" + key + ": " + getContent(key) + System.lineSeparator();
}
}
public String asNBTString(){
return NBTReflectionUtil.gettoCompount(getCompound(), this).toString();
}
}

View File

@ -0,0 +1,35 @@
package com.massivecraft.factions.zcore.nbtapi;
public class NBTContainer extends NBTCompound{
private Object nbt;
public NBTContainer() {
super(null, null);
nbt = NBTReflectionUtil.getNewNBTTag();
}
protected NBTContainer(Object nbt){
super(null, null);
this.nbt = nbt;
}
public NBTContainer(String nbtString) throws IllegalArgumentException {
super(null, null);
try{
nbt = NBTReflectionUtil.parseNBT(nbtString);
}catch(Exception ex){
ex.printStackTrace();
throw new IllegalArgumentException("Malformed Json: " + ex.getMessage());
}
}
protected Object getCompound() {
return nbt;
}
protected void setCompound(Object tag) {
nbt = tag;
}
}

View File

@ -0,0 +1,22 @@
package com.massivecraft.factions.zcore.nbtapi;
import org.bukkit.entity.Entity;
public class NBTEntity extends NBTCompound {
private final Entity ent;
public NBTEntity(Entity entity) {
super(null, null);
ent = entity;
}
protected Object getCompound() {
return NBTReflectionUtil.getEntityNBTTagCompound(NBTReflectionUtil.getNMSEntity(ent));
}
protected void setCompound(Object compound) {
NBTReflectionUtil.setEntityNBTTag(compound, NBTReflectionUtil.getNMSEntity(ent));
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.zcore.nbtapi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class NBTFile extends NBTCompound {
private final File file;
private Object nbt;
public NBTFile(File file) throws IOException {
super(null, null);
this.file = file;
if (file.exists()) {
FileInputStream inputsteam = new FileInputStream(file);
nbt = NBTReflectionUtil.readNBTFile(inputsteam);
} else {
nbt = NBTReflectionUtil.getNewNBTTag();
save();
}
}
public void save() throws IOException {
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
NBTReflectionUtil.saveNBTFile(nbt, outStream);
}
public File getFile() {
return file;
}
protected Object getCompound() {
return nbt;
}
protected void setCompound(Object compound) {
nbt = compound;
}
}

View File

@ -0,0 +1,38 @@
package com.massivecraft.factions.zcore.nbtapi;
import org.bukkit.inventory.ItemStack;
public class NBTItem extends NBTCompound {
private ItemStack bukkitItem;
public NBTItem(ItemStack item) {
super(null, null);
bukkitItem = item.clone();
}
protected Object getCompound() {
return NBTReflectionUtil.getItemRootNBTTagCompound(NBTReflectionUtil.getNMSItemStack(bukkitItem));
}
protected void setCompound(Object compound) {
bukkitItem = NBTReflectionUtil.getBukkitItemStack(NBTReflectionUtil.setNBTTag(compound, NBTReflectionUtil.getNMSItemStack(bukkitItem)));
}
public ItemStack getItem() {
return bukkitItem;
}
protected void setItem(ItemStack item) {
bukkitItem = item;
}
public static NBTContainer convertItemtoNBT(ItemStack item){
return NBTReflectionUtil.convertNMSItemtoNBTCompound(NBTReflectionUtil.getNMSItemStack(item));
}
public static ItemStack convertNBTtoItem(NBTCompound comp){
return NBTReflectionUtil.getBukkitItemStack(NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
}
}

View File

@ -0,0 +1,127 @@
package com.massivecraft.factions.zcore.nbtapi;
import com.massivecraft.factions.zcore.nbtapi.utils.MethodNames;
import java.lang.reflect.Method;
public class NBTList {
private String listName;
private NBTCompound parent;
private NBTType type;
private Object listObject;
protected NBTList(NBTCompound owner, String name, NBTType type, Object list) {
parent = owner;
listName = name;
this.type = type;
this.listObject = list;
if (!(type == NBTType.NBTTagString || type == NBTType.NBTTagCompound)) {
System.err.println("List types != String/Compound are currently not implemented!");
}
}
protected void save() {
parent.set(listName, listObject);
}
public NBTListCompound addCompound() {
if (type != NBTType.NBTTagCompound) {
new Throwable("Using Compound method on a non Compound list!").printStackTrace();
return null;
}
try {
Method method = listObject.getClass().getMethod("add", NBTReflectionUtil.getNBTBase());
Object compound = NBTReflectionUtil.getNBTTagCompound().newInstance();
method.invoke(listObject, compound);
return new NBTListCompound(this, compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public NBTListCompound getCompound(int id) {
if (type != NBTType.NBTTagCompound) {
new Throwable("Using Compound method on a non Compound list!").printStackTrace();
return null;
}
try {
Method method = listObject.getClass().getMethod("get", int.class);
Object compound = method.invoke(listObject, id);
return new NBTListCompound(this, compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public String getString(int i) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return null;
}
try {
Method method = listObject.getClass().getMethod("getString", int.class);
return (String) method.invoke(listObject, i);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@SuppressWarnings("unchecked")
public void addString(String s) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return;
}
try {
Method method = listObject.getClass().getMethod("add", NBTReflectionUtil.getNBTBase());
method.invoke(listObject, NBTReflectionUtil.getNBTTagString().getConstructor(String.class).newInstance(s));
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public void setString(int i, String s) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return;
}
try {
Method method = listObject.getClass().getMethod("a", int.class, NBTReflectionUtil.getNBTBase());
method.invoke(listObject, i, NBTReflectionUtil.getNBTTagString().getConstructor(String.class).newInstance(s));
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void remove(int i) {
try {
Method method = listObject.getClass().getMethod(MethodNames.getRemoveMethodName(), int.class);
method.invoke(listObject, i);
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int size() {
try {
Method method = listObject.getClass().getMethod("size");
return (int) method.invoke(listObject);
} catch (Exception ex) {
ex.printStackTrace();
}
return -1;
}
public NBTType getType() {
return type;
}
}

View File

@ -0,0 +1,102 @@
package com.massivecraft.factions.zcore.nbtapi;
import java.util.HashSet;
import java.util.Set;
public class NBTListCompound {
private NBTList owner;
private Object compound;
protected NBTListCompound(NBTList parent, Object obj) {
owner = parent;
compound = obj;
}
public void setString(String key, String value) {
if (value == null) {
remove(key);
return;
}
try {
compound.getClass().getMethod("setString", String.class, String.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setInteger(String key, int value) {
try {
compound.getClass().getMethod("setInt", String.class, int.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int getInteger(String value) {
try {
return (int) compound.getClass().getMethod("getInt", String.class).invoke(compound, value);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public void setDouble(String key, double value) {
try {
compound.getClass().getMethod("setDouble", String.class, double.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public double getDouble(String key) {
try {
return (double) compound.getClass().getMethod("getDouble", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public String getString(String key) {
try {
return (String) compound.getClass().getMethod("getString", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
public boolean hasKey(String key) {
try {
return (boolean) compound.getClass().getMethod("hasKey", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
@SuppressWarnings("unchecked")
public Set<String> getKeys() {
try {
return (Set<String>) compound.getClass().getMethod("c").invoke(compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return new HashSet<>();
}
public void remove(String key) {
try {
compound.getClass().getMethod("remove", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,982 @@
package com.massivecraft.factions.zcore.nbtapi;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.Stack;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import com.massivecraft.factions.zcore.nbtapi.utils.GsonWrapper;
import com.massivecraft.factions.zcore.nbtapi.utils.MethodNames;
import com.massivecraft.factions.zcore.nbtapi.utils.MinecraftVersion;
// TODO: finish codestyle cleanup -sgdc3
public class NBTReflectionUtil {
private static final String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
@SuppressWarnings("rawtypes")
private static Class getCraftItemStack() {
try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
private static Class getCraftEntity() {
try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getNBTBase() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTBase");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getNBTTagString() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagString");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getNMSItemStack() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".ItemStack");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getNBTTagCompound() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getNBTCompressedStreamTools() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getMojangsonParser() {
try {
Class c = Class.forName("net.minecraft.server." + version + ".MojangsonParser");
return c;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getTileEntity() {
try {
Class clazz = Class.forName("net.minecraft.server." + version + ".TileEntity");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
@SuppressWarnings("rawtypes")
protected static Class getCraftWorld() {
try {
Class clazz = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
return clazz;
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
public static Object getNewNBTTag() {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
try {
@SuppressWarnings("rawtypes")
Class c = Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
return c.newInstance();
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
private static Object getNewBlockPosition(int x, int y, int z) {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
try {
@SuppressWarnings("rawtypes")
Class clazz = Class.forName("net.minecraft.server." + version + ".BlockPosition");
return clazz.getConstructor(int.class, int.class, int.class).newInstance(x, y, z);
} catch (Exception ex) {
System.out.println("Error in ItemNBTAPI! (Outdated plugin?)");
ex.printStackTrace();
return null;
}
}
public static Object setNBTTag(Object NBTTag, Object NMSItem) {
try {
Method method;
method = NMSItem.getClass().getMethod("setTag", NBTTag.getClass());
method.invoke(NMSItem, NBTTag);
return NMSItem;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@SuppressWarnings("unchecked")
public static Object getNMSItemStack(ItemStack item) {
@SuppressWarnings("rawtypes")
Class clazz = getCraftItemStack();
Method method;
try {
method = clazz.getMethod("asNMSCopy", ItemStack.class);
Object answer = method.invoke(clazz, item);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings("unchecked")
public static Object getNMSEntity(Entity entity) {
@SuppressWarnings("rawtypes")
Class clazz = getCraftEntity();
Method method;
try {
method = clazz.getMethod("getHandle");
return method.invoke(getCraftEntity().cast(entity));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object parseNBT(String json) {
@SuppressWarnings("rawtypes")
Class cis = getMojangsonParser();
Method method;
try {
method = cis.getMethod("parse", String.class);
return method.invoke(null, json);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object readNBTFile(FileInputStream stream) {
@SuppressWarnings("rawtypes")
Class clazz = getNBTCompressedStreamTools();
Method method;
try {
method = clazz.getMethod("a", InputStream.class);
return method.invoke(clazz, stream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object saveNBTFile(Object nbt, FileOutputStream stream) {
@SuppressWarnings("rawtypes")
Class clazz = getNBTCompressedStreamTools();
Method method;
try {
method = clazz.getMethod("a", getNBTTagCompound(), OutputStream.class);
return method.invoke(clazz, nbt, stream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static ItemStack getBukkitItemStack(Object item) {
@SuppressWarnings("rawtypes")
Class clazz = getCraftItemStack();
Method method;
try {
method = clazz.getMethod("asCraftMirror", item.getClass());
Object answer = method.invoke(clazz, item);
return (ItemStack) answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object getItemRootNBTTagCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class clazz = nmsitem.getClass();
Method method;
try {
method = clazz.getMethod("getTag");
Object answer = method.invoke(nmsitem);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
@SuppressWarnings("rawtypes")
Class clazz = getNMSItemStack();
try {
Object nmsstack = clazz.getConstructor(getNBTTagCompound()).newInstance(gettoCompount(nbtcompound.getCompound(), nbtcompound));
return nmsstack;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class clazz = nmsitem.getClass();
Method method;
try {
method = clazz.getMethod("save", getNBTTagCompound());
Object answer = method.invoke(nmsitem, getNewNBTTag());
return new NBTContainer(answer);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object getEntityNBTTagCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class c = nmsitem.getClass();
Method method;
try {
method = c.getMethod(MethodNames.getEntityNbtGetterMethodName(), getNBTTagCompound());
Object nbt = getNBTTagCompound().newInstance();
Object answer = method.invoke(nmsitem, nbt);
if (answer == null)
answer = nbt;
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object setEntityNBTTag(Object NBTTag, Object NMSItem) {
try {
Method method;
method = NMSItem.getClass().getMethod(MethodNames.getEntityNbtSetterMethodName(), getNBTTagCompound());
method.invoke(NMSItem, NBTTag);
return NMSItem;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Object getTileEntityNBTTagCompound(BlockState tile) {
Method method;
try {
Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ());
Object cworld = getCraftWorld().cast(tile.getWorld());
Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld);
Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos);
method = getTileEntity().getMethod(MethodNames.getTileDataMethodName(), getNBTTagCompound());
Object tag = getNBTTagCompound().newInstance();
Object answer = method.invoke(o, tag);
if (answer == null)
answer = tag;
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
Method method;
try {
Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ());
Object cworld = getCraftWorld().cast(tile.getWorld());
Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld);
Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos);
method = getTileEntity().getMethod("a", getNBTTagCompound());
method.invoke(o, comp);
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public static Object getSubNBTTagCompound(Object compound, String name) {
@SuppressWarnings("rawtypes")
Class c = compound.getClass();
Method method;
try {
method = c.getMethod("getCompound", String.class);
Object answer = method.invoke(compound, name);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void addNBTTagCompound(NBTCompound comp, String name) {
if (name == null) {
remove(comp, name);
return;
}
Object nbttag = comp.getCompound();
if (nbttag == null) {
nbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(nbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
method.invoke(workingtag, name, getNBTTagCompound().newInstance());
comp.setCompound(nbttag);
return;
} catch (Exception ex) {
ex.printStackTrace();
}
return;
}
public static Boolean valideCompound(NBTCompound comp) {
Object root = comp.getCompound();
if (root == null) {
root = getNewNBTTag();
}
return (gettoCompount(root, comp)) != null;
}
public static Object gettoCompount(Object nbttag, NBTCompound comp) {
Stack<String> structure = new Stack<>();
while (comp.getParent() != null) {
structure.add(comp.getName());
comp = comp.getParent();
}
while (!structure.isEmpty()) {
nbttag = getSubNBTTagCompound(nbttag, structure.pop());
if (nbttag == null) {
return null;
}
}
return nbttag;
}
public static void addOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("a", getNBTTagCompound());
method.invoke(workingtag, nbtcompound.getCompound());
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void setString(NBTCompound comp, String key, String text) {
if (text == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setString", String.class, String.class);
method.invoke(workingtag, key, text);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String getString(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getString", String.class);
return (String) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String getContent(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("get", String.class);
return method.invoke(workingtag, key).toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setInt(NBTCompound comp, String key, Integer i) {
if (i == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setInt", String.class, int.class);
method.invoke(workingtag, key, i);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Integer getInt(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getInt", String.class);
return (Integer) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setByteArray(NBTCompound comp, String key, byte[] b) {
if (b == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setByteArray", String.class, byte[].class);
method.invoke(workingtag, key, b);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
return;
}
public static byte[] getByteArray(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getByteArray", String.class);
return (byte[]) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setIntArray(NBTCompound comp, String key, int[] i) {
if (i == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setIntArray", String.class, int[].class);
method.invoke(workingtag, key, i);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static int[] getIntArray(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getIntArray", String.class);
return (int[]) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setFloat(NBTCompound comp, String key, Float f) {
if (f == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setFloat", String.class, float.class);
method.invoke(workingtag, key, (float) f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Float getFloat(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getFloat", String.class);
return (Float) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setLong(NBTCompound comp, String key, Long f) {
if (f == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setLong", String.class, long.class);
method.invoke(workingtag, key, (long) f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Long getLong(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getLong", String.class);
return (Long) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setShort(NBTCompound comp, String key, Short f) {
if (f == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setShort", String.class, short.class);
method.invoke(workingtag, key, (short) f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Short getShort(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getShort", String.class);
return (Short) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setByte(NBTCompound comp, String key, Byte f) {
if (f == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setByte", String.class, byte.class);
method.invoke(workingtag, key, (byte) f);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Byte getByte(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getByte", String.class);
return (Byte) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setDouble(NBTCompound comp, String key, Double d) {
if (d == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setDouble", String.class, double.class);
method.invoke(workingtag, key, d);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Double getDouble(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getDouble", String.class);
return (Double) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static byte getType(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return 0;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod(MethodNames.getTypeMethodName(), String.class);
return (byte) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public static void setBoolean(NBTCompound comp, String key, Boolean d) {
if (d == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("setBoolean", String.class, boolean.class);
method.invoke(workingtag, key, d);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Boolean getBoolean(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getBoolean", String.class);
return (Boolean) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void set(NBTCompound comp, String key, Object val) {
if (val == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) {
new Throwable("InvalideCompound").printStackTrace();
return;
}
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
method.invoke(workingtag, key, val);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static NBTList getList(NBTCompound comp, String key, NBTType type) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getList", String.class, int.class);
return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId()));
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setObject(NBTCompound comp, String key, Object value) {
if (!MinecraftVersion.hasGsonSupport()) return;
try {
String json = GsonWrapper.getString(value);
setString(comp, key, json);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static <T> T getObject(NBTCompound comp, String key, Class<T> type) {
if (!MinecraftVersion.hasGsonSupport()) return null;
String json = getString(comp, key);
if (json == null) {
return null;
}
return GsonWrapper.deserializeJson(json, type);
}
public static void remove(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("remove", String.class);
method.invoke(workingtag, key);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Boolean hasKey(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("hasKey", String.class);
return (Boolean) method.invoke(workingtag, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@SuppressWarnings("unchecked")
public static Set<String> getKeys(NBTCompound comp) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = getNewNBTTag();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("c");
return (Set<String>) method.invoke(workingtag);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,22 @@
package com.massivecraft.factions.zcore.nbtapi;
import org.bukkit.block.BlockState;
public class NBTTileEntity extends NBTCompound {
private final BlockState tile;
public NBTTileEntity(BlockState tile) {
super(null, null);
this.tile = tile;
}
protected Object getCompound() {
return NBTReflectionUtil.getTileEntityNBTTagCompound(tile);
}
protected void setCompound(Object compound) {
NBTReflectionUtil.setTileEntityNBTTagCompound(tile, compound);
}
}

View File

@ -0,0 +1,34 @@
package com.massivecraft.factions.zcore.nbtapi;
public enum NBTType {
NBTTagEnd(0),
NBTTagByte(1),
NBTTagShort(2),
NBTTagInt(3),
NBTTagLong(4),
NBTTagFloat(5),
NBTTagDouble(6),
NBTTagByteArray(7),
NBTTagIntArray(11),
NBTTagString(8),
NBTTagList(9),
NBTTagCompound(10);
NBTType(int i) {
id = i;
}
private final int id;
public int getId() {
return id;
}
public static NBTType valueOf(int id) {
for (NBTType t : values())
if (t.getId() == id)
return t;
return NBTType.NBTTagEnd;
}
}

View File

@ -0,0 +1,27 @@
package com.massivecraft.factions.zcore.nbtapi.utils;
import com.google.gson.Gson;
public class GsonWrapper {
private static final Gson gson = new Gson();
public static String getString(Object obj) {
return gson.toJson(obj);
}
public static <T> T deserializeJson(String json, Class<T> type) {
try {
if (json == null) {
return null;
}
T obj = gson.fromJson(json, type);
return type.cast(obj);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,36 @@
package com.massivecraft.factions.zcore.nbtapi.utils;
public class MethodNames {
private final static MinecraftVersion MINECRAFT_VERSION = MinecraftVersion.getVersion();
public static String getTileDataMethodName() {
if (MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3) {
return "b";
}
return "save";
}
public static String getTypeMethodName() {
if (MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3) {
return "b";
}
return "d";
}
public static String getEntityNbtGetterMethodName() {
return "b";
}
public static String getEntityNbtSetterMethodName() {
return "a";
}
public static String getRemoveMethodName() {
if (MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3) {
return "a";
}
return "remove";
}
}

View File

@ -0,0 +1,60 @@
package com.massivecraft.factions.zcore.nbtapi.utils;
import org.bukkit.Bukkit;
public enum MinecraftVersion {
Unknown(0),
MC1_7_R4(174),
MC1_8_R3(183),
MC1_9_R1(191),
MC1_9_R2(192),
MC1_10_R1(1101),
MC1_11_R1(1111),
MC1_12_R1(1121);
private static MinecraftVersion version;
private static Boolean hasGsonSupport;
private final int versionId;
MinecraftVersion(int versionId) {
this.versionId = versionId;
}
public int getVersionId() {
return versionId;
}
public static MinecraftVersion getVersion() {
if (version != null) {
return version;
}
final String ver = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
System.out.println("[NBTAPI] Found Spigot: " + ver + "! Trying to find NMS support");
try {
version = MinecraftVersion.valueOf(ver.replace("v", "MC"));
} catch (IllegalArgumentException ex) {
version = MinecraftVersion.Unknown;
}
if (version != Unknown) {
System.out.println("[NBTAPI] NMS support '" + version.name() + "' loaded!");
} else {
System.out.println("[NBTAPI] Wasn't able to find NMS Support! Some functions will not work!");
}
return version;
}
public static boolean hasGsonSupport() {
if (hasGsonSupport != null) {
return hasGsonSupport;
}
try {
System.out.println("Found Gson: " + Class.forName("com.google.gson.Gson"));
hasGsonSupport = true;
} catch (Exception ex) {
hasGsonSupport = false;
}
return hasGsonSupport;
}
}

View File

@ -28,8 +28,8 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import static com.massivecraft.factions.zcore.util.InventoryUtil.InventoryToString;
import static com.massivecraft.factions.zcore.util.InventoryUtil.StringToInventory;
import static com.massivecraft.factions.util.InventoryUtil.InventoryToString;
import static com.massivecraft.factions.util.InventoryUtil.StringToInventory;
public abstract class MemoryFaction implements Faction, EconomyParticipator {
protected String id = null;

View File

@ -617,7 +617,7 @@ public enum TL {
COMMAND_SHOW_NEEDFACTION("&cYou need to join a faction to view your own!"),
COMMAND_SHOWCLAIMS_HEADER("&8&m-------------&8<{faction}'s claims&8>&8&m-------------"),
COMMAND_SHOWCLAIMS_FORMAT("&8[{world}]: {chunks}"),
COMMAND_SHOWCLAIMS_FORMAT("&8[{world}]:"),
COMMAND_SHOWCLAIMS_CHUNKSFORMAT("&8(&c{x}&8,&c{z}&8)"),
COMMAND_SHOWCLAIMS_DESCRIPTION("show your factions claims!"),

View File

@ -1,7 +1,8 @@
# FactionsUUID by drtshock
# Report issues https://github.com/drtshock/Factions/issues?state=open
# Live support http://webchat.esper.net/?channels=factions&prompt=1
# Website https://www.spigotmc.org/resources/factionsuuid.1035/
# SavageFactions by ProSavage
# Report issues https://github.com/ProSavage/SavageFactions/issues/new
# Live support https://github.com/ProSavage/SavageFactions/issues/new
# Spigot Site: https://www.spigotmc.org/resources/savagefactions-factionsuuid-reimagined-1-7-1-12.52891/
# Website: https://www.prosavage.net/
# Made with love <3
@ -145,7 +146,7 @@ scoreboard:
# {maxPower} - player's max power.
# {powerBoost} - player's powerboost.
default-enabled: true # Default to false to keep original functionality.
default-enabled: false # Default to false to keep original functionality.
default-title: "&cSavageFactions" # Can use any of the values from above but this won't update once it's set (so don't set {balance}).
default-update-interval: 2 # in seconds.

View File

@ -1,5 +1,5 @@
name: Factions
version: ${project.version}-1.4-BETA-2
version: ${project.version}-1.4-BETA-4
main: com.massivecraft.factions.P
authors: [Olof Larsson, Brett Flannigan, drtshock, ProSavage]
softdepend: [CoreProtect, PlayerVaults, PlaceholderAPI, MVdWPlaceholderAPI, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap, FactionsTop]