mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
commit
10e9879a64
@ -231,6 +231,26 @@ public class Enchantments {
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
|
||||
|
||||
try { // 1.14
|
||||
Enchantment multishot = Enchantment.getByName("MULTISHOT");
|
||||
if (multishot != null) {
|
||||
ENCHANTMENTS.put("multishot", multishot);
|
||||
ALIASENCHANTMENTS.put("tripleshot", multishot);
|
||||
}
|
||||
Enchantment quickCharge = Enchantment.getByName("QUICK_CHARGE");
|
||||
if (quickCharge != null) {
|
||||
ENCHANTMENTS.put("quickcharge", quickCharge);
|
||||
ALIASENCHANTMENTS.put("quickdraw", quickCharge);
|
||||
ALIASENCHANTMENTS.put("fastcharge", quickCharge);
|
||||
ALIASENCHANTMENTS.put("fastdraw", quickCharge);
|
||||
}
|
||||
Enchantment piercing = Enchantment.getByName("PIERCING");
|
||||
if (piercing != null) {
|
||||
ENCHANTMENTS.put("piercing", piercing);
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
|
||||
try {
|
||||
Class<?> namespacedKeyClass = Class.forName("org.bukkit.NamespacedKey");
|
||||
Class<?> enchantmentClass = Class.forName("org.bukkit.enchantments.Enchantment");
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
@ -77,12 +77,19 @@ public enum Mob {
|
||||
PARROT("Parrot", Enemies.NEUTRAL, "PARROT"),
|
||||
TURTLE("Turtle", Enemies.NEUTRAL, "TURTLE"),
|
||||
PHANTOM("Phantom", Enemies.ENEMY, "PHANTOM"),
|
||||
COD("Cod", Enemies.NEUTRAL, "COD"),
|
||||
SALMON("Salmon", Enemies.NEUTRAL, "SALMON"),
|
||||
PUFFERFISH("Pufferfish", Enemies.NEUTRAL, "PUFFERFISH"),
|
||||
TROPICAL_FISH("TropicalFish", Enemies.NEUTRAL, "TROPICAL_FISH"),
|
||||
COD("Cod", Enemies.NEUTRAL, "", "COD"),
|
||||
SALMON("Salmon", Enemies.NEUTRAL, "", "SALMON"),
|
||||
PUFFERFISH("Pufferfish", Enemies.NEUTRAL, "", "PUFFERFISH"),
|
||||
TROPICAL_FISH("TropicalFish", Enemies.NEUTRAL, "", "TROPICAL_FISH"),
|
||||
DROWNED("Drowned", Enemies.ENEMY, "DROWNED"),
|
||||
DOLPHIN("Dolphin", Enemies.NEUTRAL, "DOLPHIN"),
|
||||
CAT("Cat", Enemies.FRIENDLY, "CAT"),
|
||||
FOX("Fox", Enemies.FRIENDLY, "es", "FOX"),
|
||||
PANDA("Panda", Enemies.NEUTRAL, "PANDA"),
|
||||
PILLAGER("Pillager", Enemies.ENEMY, "PILLAGER"),
|
||||
RAVAGER("Ravager", Enemies.ENEMY, "RAVAGER"),
|
||||
TRADER_LLAMA("TraderLlama", Enemies.FRIENDLY, "TRADER_LLAMA"),
|
||||
WANDERING_TRADER("WanderingTrader", Enemies.FRIENDLY, "WANDERING_TRADER")
|
||||
;
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Essentials");
|
||||
@ -100,16 +107,17 @@ public enum Mob {
|
||||
this.bukkitType = type;
|
||||
}
|
||||
|
||||
Mob(String n, Enemies en, String s, String typeName) {
|
||||
this.suffix = s;
|
||||
this.name = n;
|
||||
this.type = en;
|
||||
bukkitType = EnumUtil.getEntityType(typeName);
|
||||
}
|
||||
|
||||
Mob(String n, Enemies en, String typeName) {
|
||||
this.name = n;
|
||||
this.type = en;
|
||||
EntityType entityType;
|
||||
try {
|
||||
entityType = EntityType.valueOf(typeName);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
entityType = null;
|
||||
}
|
||||
bukkitType = entityType;
|
||||
bukkitType = EnumUtil.getEntityType(typeName);
|
||||
}
|
||||
|
||||
public String suffix = "s";
|
||||
|
224
Essentials/src/com/earth2me/essentials/MobCompat.java
Normal file
224
Essentials/src/com/earth2me/essentials/MobCompat.java
Normal file
@ -0,0 +1,224 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static com.earth2me.essentials.utils.EnumUtil.getEntityType;
|
||||
|
||||
public class MobCompat {
|
||||
|
||||
// Constants for mobs added in later versions
|
||||
public static final EntityType LLAMA = getEntityType("LLAMA");
|
||||
public static final EntityType PARROT = getEntityType("PARROT");
|
||||
public static final EntityType TROPICAL_FISH = getEntityType("TROPICAL_FISH");
|
||||
public static final EntityType PANDA = getEntityType("PANDA");
|
||||
public static final EntityType TRADER_LLAMA = getEntityType("TRADER_LLAMA");
|
||||
|
||||
// Constants for mobs that have changed since earlier versions
|
||||
public static final EntityType CAT = getEntityType("CAT", "OCELOT");
|
||||
|
||||
public enum CatType {
|
||||
// These are (loosely) Mojang names for the cats
|
||||
SIAMESE("SIAMESE", "SIAMESE_CAT"),
|
||||
WHITE("WHITE", "SIAMESE_CAT"),
|
||||
RED("RED", "RED_CAT"),
|
||||
TABBY("TABBY", "RED_CAT"),
|
||||
TUXEDO("BLACK", "BLACK_CAT"),
|
||||
BRITISH_SHORTHAIR("BRITISH_SHORTHAIR", "SIAMESE_CAT"),
|
||||
CALICO("CALICO", "RED_CAT"),
|
||||
PERSIAN("PERSIAN", "RED_CAT"),
|
||||
RAGDOLL("RAGDOLL", "SIAMESE_CAT"),
|
||||
JELLIE("JELLIE", "SIAMESE_CAT"),
|
||||
BLACK("ALL_BLACK", "BLACK_CAT"),
|
||||
;
|
||||
|
||||
private final String catTypeName;
|
||||
private final String ocelotTypeName;
|
||||
|
||||
CatType(final String catTypeName, final String ocelotTypeName) {
|
||||
this.catTypeName = catTypeName;
|
||||
this.ocelotTypeName = ocelotTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
public enum VillagerProfession {
|
||||
// These are 1.14+ villager professions mapped to their respective pre-V&P profession and career
|
||||
NONE("FARMER", "FARMER", "NONE"),
|
||||
ARMORER("BLACKSMITH", "ARMORER"),
|
||||
BUTCHER("FARMER", "BUTCHER"),
|
||||
CARTOGRAPHER("LIBRARIAN", "CARTOGRAPHER"),
|
||||
CLERIC("PRIEST", "CLERIC"),
|
||||
FARMER("FARMER", "FARMER"),
|
||||
FISHERMAN("FARMER", "FISHERMAN"),
|
||||
FLETCHER("FARMER", "FLETCHER"),
|
||||
LEATHERWORKER("BUTCHER", "LEATHERWORKER"),
|
||||
LIBRARIAN("LIBRARIAN", "LIBRARIAN"),
|
||||
MASON(null, null, "MASON"),
|
||||
NITWIT("NITWIT", "NITWIT"),
|
||||
SHEPHERD("FARMER", "SHEPHERD"),
|
||||
TOOLSMITH("BLACKSMITH", "TOOL_SMITH", "TOOLSMITH"),
|
||||
WEAPONSMITH("BLACKSMITH", "WEAPON_SMITH", "WEAPONSMITH")
|
||||
;
|
||||
|
||||
private String oldProfession;
|
||||
private String oldCareer;
|
||||
private String newProfession;
|
||||
|
||||
VillagerProfession(final String oldProfession, final String career) {
|
||||
this.oldProfession = oldProfession;
|
||||
this.oldCareer = career;
|
||||
this.newProfession = career;
|
||||
}
|
||||
|
||||
VillagerProfession(final String oldProfession, final String oldCareer, final String newProfession) {
|
||||
this.oldProfession = oldProfession;
|
||||
this.oldCareer = oldCareer;
|
||||
this.newProfession = newProfession;
|
||||
}
|
||||
|
||||
private Villager.Profession asEnum() {
|
||||
return EnumUtil.valueOf(Villager.Profession.class, newProfession, oldProfession);
|
||||
}
|
||||
}
|
||||
|
||||
// Older cats are Ocelots, whereas 1.14+ cats are Cats
|
||||
private static Class catClass = ReflUtil.getClassCached("org.bukkit.entity.Cat");
|
||||
private static Class catTypeClass = ReflUtil.getClassCached("org.bukkit.entity.Cat.Type");
|
||||
private static Method catSetTypeMethod = (catClass == null || catTypeClass == null) ? null : ReflUtil.getMethodCached(catClass, "setCatType", catTypeClass);
|
||||
|
||||
private static boolean isNewCat() {
|
||||
return (catClass != null && catTypeClass != null && catSetTypeMethod != null);
|
||||
}
|
||||
|
||||
public static void setCatType(final Entity entity, final CatType type) {
|
||||
if (isNewCat()) {
|
||||
try {
|
||||
catSetTypeMethod.invoke(entity, EnumUtil.valueOf(catTypeClass, type.catTypeName));
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
((Ocelot) entity).setCatType(Ocelot.Type.valueOf(type.ocelotTypeName));
|
||||
}
|
||||
}
|
||||
|
||||
// Older villagers have professions and careers, 1.14+ villagers only have professions
|
||||
private static Class villagerCareerClass = ReflUtil.getClassCached("org.bukkit.entity.Villager.Career");
|
||||
private static Method villagerSetCareerMethod = (villagerCareerClass == null) ? null : ReflUtil.getMethodCached(Villager.class, "setCareer", villagerCareerClass);
|
||||
|
||||
private static boolean isCareerVillager() {
|
||||
return (villagerCareerClass != null && villagerSetCareerMethod != null);
|
||||
}
|
||||
|
||||
public static void setVillagerProfession(final Entity entity, final VillagerProfession profession) {
|
||||
if (!isCareerVillager()) {
|
||||
((Villager) entity).setProfession(profession.asEnum());
|
||||
} else {
|
||||
((Villager) entity).setProfession(profession.asEnum());
|
||||
try {
|
||||
villagerSetCareerMethod.invoke(entity, EnumUtil.valueOf(villagerCareerClass, profession.oldCareer));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only 1.14+ villagers have biome variants
|
||||
public static void setVillagerType(final Entity entity, final String type) {
|
||||
Class typeEnum = ReflUtil.getClassCached("org.bukkit.entity.Villager.Type");
|
||||
if (typeEnum == null) return;
|
||||
|
||||
Method villagerSetTypeMethod = ReflUtil.getMethodCached(Villager.class, "setVillagerType", typeEnum);
|
||||
try {
|
||||
villagerSetTypeMethod.invoke(entity, EnumUtil.valueOf(typeEnum, type));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Llamas only exist in 1.11+
|
||||
public static void setLlamaColor(final Entity entity, final String color) {
|
||||
Class llamaClass = ReflUtil.getClassCached("org.bukkit.entity.Llama");
|
||||
if (llamaClass == null) return;
|
||||
|
||||
Class colorEnum = ReflUtil.getClassCached("org.bukkit.entity.Llama.Color");
|
||||
Method setVariantMethod = ReflUtil.getMethodCached(llamaClass, "setColor");
|
||||
|
||||
try {
|
||||
setVariantMethod.invoke(entity, EnumUtil.valueOf(colorEnum, color));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Parrots only exist in 1.12+
|
||||
public static void setParrotVariant(final Entity entity, final String variant) {
|
||||
Class parrotClass = ReflUtil.getClassCached("org.bukkit.entity.Parrot");
|
||||
if (parrotClass == null) return;
|
||||
|
||||
Class variantEnum = ReflUtil.getClassCached("org.bukkit.entity.Parrot.Variant");
|
||||
Method setVariantMethod = ReflUtil.getMethodCached(parrotClass, "setVariant");
|
||||
try {
|
||||
setVariantMethod.invoke(entity, EnumUtil.valueOf(variantEnum, variant));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Tropical fish only exist in 1.13+
|
||||
public static void setTropicalFishPattern(final Entity entity, final String pattern) {
|
||||
Class tropicalFishClass = ReflUtil.getClassCached("org.bukkit.entity.TropicalFish");
|
||||
if (tropicalFishClass == null) return;
|
||||
|
||||
Class patternEnum = ReflUtil.getClassCached("org.bukkit.entity.TropicalFish.Pattern");
|
||||
Method setPatternMethod = ReflUtil.getMethodCached(tropicalFishClass, "setPattern");
|
||||
try {
|
||||
setPatternMethod.invoke(entity, EnumUtil.valueOf(patternEnum, pattern));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Mushroom cow variant API only exists in 1.14+
|
||||
public static void setMooshroomVariant(final Entity entity, final String variant) {
|
||||
Class mushroomCowClass = ReflUtil.getClassCached("org.bukkit.entity.MushroomCow");
|
||||
Class variantEnum = ReflUtil.getClassCached("org.bukkit.entity.MushroomCow.Variant");
|
||||
if (mushroomCowClass == null || variantEnum == null) return;
|
||||
|
||||
Method setVariantMethod = ReflUtil.getMethodCached(mushroomCowClass, "setVariant");
|
||||
try {
|
||||
setVariantMethod.invoke(entity, EnumUtil.valueOf(variantEnum, variant));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Pandas only exists in 1.14+
|
||||
public static void setPandaGene(final Entity entity, final String gene, final boolean mainGene) {
|
||||
Class pandaClass = ReflUtil.getClassCached("org.bukkit.entity.Panda");
|
||||
if (pandaClass == null) return;
|
||||
|
||||
Class geneEnum = ReflUtil.getClassCached("org.bukkit.entity.Panda.Gene");
|
||||
Method setGeneMethod;
|
||||
|
||||
if (mainGene) {
|
||||
setGeneMethod = ReflUtil.getMethodCached(pandaClass, "setMainGene");
|
||||
} else {
|
||||
setGeneMethod = ReflUtil.getMethodCached(pandaClass, "setHiddenGene");
|
||||
}
|
||||
|
||||
try {
|
||||
setGeneMethod.invoke(entity, EnumUtil.valueOf(geneEnum, gene));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -17,8 +17,10 @@ import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
||||
public enum MobData {
|
||||
|
||||
BABY_AGEABLE("baby", Ageable.class, Data.BABY, true),
|
||||
ADULT_AGEABLE("adult", Ageable.class, Data.ADULT, true),
|
||||
BABY_CAT("kitten", MobCompat.CAT, Data.BABY, false),
|
||||
BABY_PIG("piglet", EntityType.PIG, Data.BABY, false),
|
||||
BABY_WOLF("puppy", EntityType.WOLF, Data.BABY, false),
|
||||
BABY_CHICKEN("chick", EntityType.CHICKEN, Data.BABY, false),
|
||||
@ -57,13 +59,19 @@ public enum MobData {
|
||||
GOLD_ARMOR_HORSE("goldarmor", EntityType.HORSE, EnumUtil.getMaterial("GOLDEN_HORSE_ARMOR", "GOLD_BARDING"), true),
|
||||
DIAMOND_ARMOR_HORSE("diamondarmor", EntityType.HORSE, EnumUtil.getMaterial("DIAMOND_HORSE_ARMOR", "DIAMOND_BARDING"), true),
|
||||
ARMOR_HORSE("armor", EntityType.HORSE, EnumUtil.getMaterial("IRON_HORSE_ARMOR", "IRON_BARDING"), true),
|
||||
SIAMESE_CAT("siamese", EntityType.OCELOT, Ocelot.Type.SIAMESE_CAT, true),
|
||||
WHITE_CAT("white", EntityType.OCELOT, Ocelot.Type.SIAMESE_CAT, false),
|
||||
RED_CAT("red", EntityType.OCELOT, Ocelot.Type.RED_CAT, true),
|
||||
ORANGE_CAT("orange", EntityType.OCELOT, Ocelot.Type.RED_CAT, false),
|
||||
TABBY_CAT("tabby", EntityType.OCELOT, Ocelot.Type.RED_CAT, false),
|
||||
BLACK_CAT("black", EntityType.OCELOT, Ocelot.Type.BLACK_CAT, true),
|
||||
TUXEDO_CAT("tuxedo", EntityType.OCELOT, Ocelot.Type.BLACK_CAT, false),
|
||||
SIAMESE_CAT("siamese", MobCompat.CAT, MobCompat.CatType.SIAMESE, true),
|
||||
WHITE_CAT("white", MobCompat.CAT, MobCompat.CatType.WHITE, false),
|
||||
RED_CAT("red", MobCompat.CAT, MobCompat.CatType.RED, true),
|
||||
ORANGE_CAT("orange", MobCompat.CAT, MobCompat.CatType.RED, false),
|
||||
TABBY_CAT("tabby", MobCompat.CAT, MobCompat.CatType.TABBY, true),
|
||||
BLACK_CAT("black", MobCompat.CAT, MobCompat.CatType.BLACK, true),
|
||||
TUXEDO_CAT("tuxedo", MobCompat.CAT, MobCompat.CatType.TUXEDO, true),
|
||||
BRITISH_SHORTHAIR_CAT("britishshorthair", MobCompat.CAT, MobCompat.CatType.BRITISH_SHORTHAIR, true),
|
||||
CALICO_CAT("calico", MobCompat.CAT, MobCompat.CatType.CALICO, true),
|
||||
PERSIAN_CAT("persian", MobCompat.CAT, MobCompat.CatType.PERSIAN, true),
|
||||
RAGDOLL_CAT("ragdoll", MobCompat.CAT, MobCompat.CatType.RAGDOLL, true),
|
||||
JELLIE_CAT("jellie", MobCompat.CAT, MobCompat.CatType.JELLIE, true),
|
||||
ALL_BLACK_CAT("allblack", MobCompat.CAT, MobCompat.CatType.BLACK, true),
|
||||
BABY_ZOMBIE("baby", EntityType.ZOMBIE.getEntityClass(), Data.BABYZOMBIE, true),
|
||||
ADULT_ZOMBIE("adult", EntityType.ZOMBIE.getEntityClass(), Data.ADULTZOMBIE, true),
|
||||
DIAMOND_SWORD_ZOMBIE("diamondsword", EntityType.ZOMBIE.getEntityClass(), Material.DIAMOND_SWORD, true),
|
||||
@ -83,31 +91,69 @@ public enum MobData {
|
||||
SADDLE_PIG("saddle", EntityType.PIG, Data.PIGSADDLE, true),
|
||||
ANGRY_WOLF("angry", EntityType.WOLF, Data.ANGRY, true),
|
||||
RABID_WOLF("rabid", EntityType.WOLF, Data.ANGRY, false),
|
||||
FARMER_VILLAGER("farmer", EntityType.VILLAGER, Villager.Profession.FARMER, true),
|
||||
LIBRARIAN_VILLAGER("librarian", EntityType.VILLAGER, Villager.Profession.LIBRARIAN, true),
|
||||
PRIEST_VILLAGER("priest", EntityType.VILLAGER, Villager.Profession.PRIEST, true),
|
||||
FATHER_VILLAGER("father", EntityType.VILLAGER, Villager.Profession.PRIEST, false),
|
||||
SMITH_VILLAGER("smith", EntityType.VILLAGER, Villager.Profession.BLACKSMITH, true),
|
||||
BUTCHER_VILLAGER("butcher", EntityType.VILLAGER, Villager.Profession.BUTCHER, true),
|
||||
VILLAGER("villager", EntityType.VILLAGER, MobCompat.VillagerProfession.NONE, true),
|
||||
ARMORER_VILLAGER("armorer", EntityType.VILLAGER, MobCompat.VillagerProfession.ARMORER, true),
|
||||
BUTCHER_VILLAGER("butcher", EntityType.VILLAGER, MobCompat.VillagerProfession.BUTCHER, true),
|
||||
CARTOGRAPHER_VILLAGER("cartographer", EntityType.VILLAGER, MobCompat.VillagerProfession.CARTOGRAPHER, true),
|
||||
CLERIC_VILLAGER("cleric", EntityType.VILLAGER, MobCompat.VillagerProfession.CLERIC, true),
|
||||
FARMER_VILLAGER("farmer", EntityType.VILLAGER, MobCompat.VillagerProfession.FARMER, true),
|
||||
FISHERMAN_VILLAGER("fisherman", EntityType.VILLAGER, MobCompat.VillagerProfession.FISHERMAN, true),
|
||||
FLETCHER_VILLAGER("fletcher", EntityType.VILLAGER, MobCompat.VillagerProfession.FLETCHER, true),
|
||||
LEATHERWORKER_VILLAGER("leatherworker", EntityType.VILLAGER, MobCompat.VillagerProfession.LEATHERWORKER, true),
|
||||
LIBRARIAN_VILLAGER("librarian", EntityType.VILLAGER, MobCompat.VillagerProfession.LIBRARIAN, true),
|
||||
MASON_VILLAGER("mason", EntityType.VILLAGER, MobCompat.VillagerProfession.MASON, true),
|
||||
NITWIT_VILLAGER("nitwit", EntityType.VILLAGER, MobCompat.VillagerProfession.NITWIT, true),
|
||||
SHEPHERD_VILLAGER("shepherd", EntityType.VILLAGER, MobCompat.VillagerProfession.SHEPHERD, true),
|
||||
TOOLSMITH_VILLAGER("toolsmith", EntityType.VILLAGER, MobCompat.VillagerProfession.TOOLSMITH, true),
|
||||
WEAPONSMITH_VILLAGER("weaponsmith", EntityType.VILLAGER, MobCompat.VillagerProfession.WEAPONSMITH, true),
|
||||
DESERT_VILLAGER("desert", EntityType.VILLAGER, "villagertype:DESERT", true),
|
||||
JUNGLE_VILLAGER("jungle", EntityType.VILLAGER, "villagertype:JUNGLE", true),
|
||||
PLAINS_VILLAGER("plains", EntityType.VILLAGER, "villagertype:PLAINS", true),
|
||||
SAVANNA_VILLAGER("savanna", EntityType.VILLAGER, "villagertype:SAVANNA", true),
|
||||
SNOWY_VILLAGER("snowy", EntityType.VILLAGER, "villagertype:SNOWY", true),
|
||||
SWAMP_VILLAGER("swamp", EntityType.VILLAGER, "villagertype:SWAMP", true),
|
||||
TAIGA_VILLAGER("taiga", EntityType.VILLAGER, "villagertype:TAIGA", true),
|
||||
SIZE_SLIME("", "<1-100>", EntityType.SLIME.getEntityClass(), Data.SIZE, true),
|
||||
NUM_EXPERIENCE_ORB("", "<1-2000000000>", EntityType.EXPERIENCE_ORB, Data.EXP, true),
|
||||
RED_PARROT("red", EntityType.PARROT, Parrot.Variant.RED, true),
|
||||
GREEN_PARROT("green", EntityType.PARROT, Parrot.Variant.GREEN, true),
|
||||
BLUE_PARROT("blue", EntityType.PARROT, Parrot.Variant.BLUE, true),
|
||||
CYAN_PARROT("cyan", EntityType.PARROT, Parrot.Variant.CYAN, true),
|
||||
GRAY_PARROT("gray", EntityType.PARROT, Parrot.Variant.GRAY, true),
|
||||
KOB_TROPICAL_FISH("kob", EntityType.TROPICAL_FISH, TropicalFish.Pattern.KOB, true),
|
||||
SUNSTREAK_TROPICAL_FISH("sunstreak", EntityType.TROPICAL_FISH, TropicalFish.Pattern.SUNSTREAK, true),
|
||||
SNOOPER_TROPICAL_FISH("snooper", EntityType.TROPICAL_FISH, TropicalFish.Pattern.SNOOPER, true),
|
||||
DASHER_TROPICAL_FISH("dasher", EntityType.TROPICAL_FISH, TropicalFish.Pattern.DASHER, true),
|
||||
BRINELY_TROPICAL_FISH("brinely", EntityType.TROPICAL_FISH, TropicalFish.Pattern.BRINELY, true),
|
||||
SPOTTY_TROPICAL_FISH("spotty", EntityType.TROPICAL_FISH, TropicalFish.Pattern.SPOTTY, true),
|
||||
FLOPPER_TROPICAL_FISH("flopper", EntityType.TROPICAL_FISH, TropicalFish.Pattern.FLOPPER, true),
|
||||
STRIPEY_TROPICAL_FISH("stripey", EntityType.TROPICAL_FISH, TropicalFish.Pattern.STRIPEY, true),
|
||||
GLITTER_TROPICAL_FISH("glitter", EntityType.TROPICAL_FISH, TropicalFish.Pattern.GLITTER, true),
|
||||
BLOCKFISH_TROPICAL_FISH("blockfish", EntityType.TROPICAL_FISH, TropicalFish.Pattern.BLOCKFISH, true),
|
||||
BETTY_TROPICAL_FISH("betty", EntityType.TROPICAL_FISH, TropicalFish.Pattern.BETTY, true),
|
||||
CLAYFISH_TROPICAL_FISH("clayfish", EntityType.TROPICAL_FISH, TropicalFish.Pattern.CLAYFISH, true);
|
||||
RED_PARROT("red", MobCompat.PARROT, "parrot:RED", true),
|
||||
GREEN_PARROT("green", MobCompat.PARROT, "parrot:GREEN", true),
|
||||
BLUE_PARROT("blue", MobCompat.PARROT, "parrot:BLUE", true),
|
||||
CYAN_PARROT("cyan", MobCompat.PARROT, "parrot:CYAN", true),
|
||||
GRAY_PARROT("gray", MobCompat.PARROT, "parrot:GRAY", true),
|
||||
KOB_TROPICAL_FISH("kob", MobCompat.TROPICAL_FISH, "tropicalfish:KOB", true),
|
||||
SUNSTREAK_TROPICAL_FISH("sunstreak", MobCompat.TROPICAL_FISH, "tropicalfish:SUNSTREAK", true),
|
||||
SNOOPER_TROPICAL_FISH("snooper", MobCompat.TROPICAL_FISH, "tropicalfish:SNOOPER", true),
|
||||
DASHER_TROPICAL_FISH("dasher", MobCompat.TROPICAL_FISH, "tropicalfish:DASHER", true),
|
||||
BRINELY_TROPICAL_FISH("brinely", MobCompat.TROPICAL_FISH, "tropicalfish:BRINELY", true),
|
||||
SPOTTY_TROPICAL_FISH("spotty", MobCompat.TROPICAL_FISH, "tropicalfish:SPOTTY", true),
|
||||
FLOPPER_TROPICAL_FISH("flopper", MobCompat.TROPICAL_FISH, "tropicalfish:FLOPPER", true),
|
||||
STRIPEY_TROPICAL_FISH("stripey", MobCompat.TROPICAL_FISH, "tropicalfish:STRIPEY", true),
|
||||
GLITTER_TROPICAL_FISH("glitter", MobCompat.TROPICAL_FISH, "tropicalfish:GLITTER", true),
|
||||
BLOCKFISH_TROPICAL_FISH("blockfish", MobCompat.TROPICAL_FISH, "tropicalfish:BLOCKFISH", true),
|
||||
BETTY_TROPICAL_FISH("betty", MobCompat.TROPICAL_FISH, "tropicalfish:BETTY", true),
|
||||
CLAYFISH_TROPICAL_FISH("clayfish", MobCompat.TROPICAL_FISH, "tropicalfish:CLAYFISH", true),
|
||||
BROWN_MUSHROOM_COW("brown", EntityType.MUSHROOM_COW, "mooshroom:BROWN", true),
|
||||
RED_MUSHROOM_COW("red", EntityType.MUSHROOM_COW, "mooshroom:RED", true),
|
||||
AGGRESSIVE_PANDA_MAIN("aggressive", MobCompat.PANDA, "pandamain:AGGRESSIVE", true),
|
||||
LAZY_PANDA_MAIN("lazy", MobCompat.PANDA, "pandamain:LAZY", true),
|
||||
WORRIED_PANDA_MAIN("worried", MobCompat.PANDA, "pandamain:WORRIED", true),
|
||||
PLAYFUL_PANDA_MAIN("playful", MobCompat.PANDA, "pandamain:PLAYFUL", true),
|
||||
BROWN_PANDA_MAIN("brown", MobCompat.PANDA, "pandamain:BROWN", true),
|
||||
WEAK_PANDA_MAIN("weak", MobCompat.PANDA, "pandamain:WEAK", true),
|
||||
AGGRESSIVE_PANDA_HIDDEN("aggressive_hidden", MobCompat.PANDA, "pandahidden:AGGRESSIVE", true),
|
||||
LAZY_PANDA_HIDDEN("lazy_hidden", MobCompat.PANDA, "pandahidden:LAZY", true),
|
||||
WORRIED_PANDA_HIDDEN("worried_hidden", MobCompat.PANDA, "pandahidden:WORRIED", true),
|
||||
PLAYFUL_PANDA_HIDDEN("playful_hidden", MobCompat.PANDA, "pandahidden:PLAYFUL", true),
|
||||
BROWN_PANDA_HIDDEN("brown_hidden", MobCompat.PANDA, "pandahidden:BROWN", true),
|
||||
WEAK_PANDA_HIDDEN("weak_hidden", MobCompat.PANDA, "pandahidden:WEAK", true),
|
||||
CREAMY_LLAMA("creamy", MobCompat.LLAMA, "llama:CREAMY", true),
|
||||
WHITE_LLAMA("white", MobCompat.LLAMA, "llama:WHITE", true),
|
||||
BROWN_LLAMA("brown", MobCompat.LLAMA, "llama:BROWN", true),
|
||||
GRAY_LLAMA("gray", MobCompat.LLAMA, "llama:GRAY", true),
|
||||
CREAMY_TRADER_LLAMA("creamy", MobCompat.TRADER_LLAMA, "llama:CREAMY", true),
|
||||
WHITE_TRADER_LLAMA("white", MobCompat.TRADER_LLAMA, "llama:WHITE", true),
|
||||
BROWN_TRADER_LLAMA("brown", MobCompat.TRADER_LLAMA, "llama:BROWN", true),
|
||||
GRAY_TRADER_LLAMA("gray", MobCompat.TRADER_LLAMA, "llama:GRAY", true)
|
||||
;
|
||||
|
||||
|
||||
@ -127,6 +173,8 @@ public enum MobData {
|
||||
SIZE
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Essentials");
|
||||
|
||||
MobData(String n, Object type, Object value, boolean isPublic) {
|
||||
@ -157,9 +205,11 @@ public enum MobData {
|
||||
public static LinkedHashMap<String, MobData> getPossibleData(final Entity spawned, boolean publicOnly) {
|
||||
LinkedHashMap<String, MobData> mobList = new LinkedHashMap<String, MobData>();
|
||||
for (MobData data : MobData.values()) {
|
||||
if (data.type instanceof EntityType && spawned.getType().equals(data.type) && ((publicOnly && data.isPublic) || !publicOnly)) {
|
||||
if (data.type == null || (publicOnly && !data.isPublic)) continue;
|
||||
|
||||
if (data.type instanceof EntityType && spawned.getType().equals(data.type)) {
|
||||
mobList.put(data.nickname.toLowerCase(Locale.ENGLISH), data);
|
||||
} else if (data.type instanceof Class && ((Class) data.type).isAssignableFrom(spawned.getClass()) && ((publicOnly && data.isPublic) || !publicOnly)) {
|
||||
} else if (data.type instanceof Class && ((Class) data.type).isAssignableFrom(spawned.getClass())) {
|
||||
mobList.put(data.nickname.toLowerCase(Locale.ENGLISH), data);
|
||||
}
|
||||
}
|
||||
@ -250,10 +300,10 @@ public enum MobData {
|
||||
((Horse) spawned).setColor((Horse.Color) this.value);
|
||||
} else if (this.value instanceof Horse.Style) {
|
||||
((Horse) spawned).setStyle((Horse.Style) this.value);
|
||||
} else if (this.value instanceof Ocelot.Type) {
|
||||
((Ocelot) spawned).setCatType((Ocelot.Type) this.value);
|
||||
} else if (this.value instanceof Villager.Profession) {
|
||||
((Villager) spawned).setProfession((Villager.Profession) this.value);
|
||||
} else if (this.value instanceof MobCompat.CatType) {
|
||||
MobCompat.setCatType(spawned, (MobCompat.CatType) this.value);
|
||||
} else if (this.value instanceof MobCompat.VillagerProfession) {
|
||||
MobCompat.setVillagerProfession(spawned, (MobCompat.VillagerProfession) this.value);
|
||||
} else if (this.value instanceof Material) {
|
||||
if (this.type.equals(EntityType.HORSE)) {
|
||||
((Horse) spawned).setTamed(true);
|
||||
@ -263,10 +313,33 @@ public enum MobData {
|
||||
InventoryWorkaround.setItemInMainHand(invent, new ItemStack((Material) this.value, 1));
|
||||
InventoryWorkaround.setItemInMainHandDropChance(invent, 0.1f);
|
||||
}
|
||||
} else if (this.value instanceof Parrot.Variant) {
|
||||
((Parrot) spawned).setVariant((Parrot.Variant) this.value);
|
||||
} else if (this.value instanceof TropicalFish.Pattern) {
|
||||
((TropicalFish) spawned).setPattern((TropicalFish.Pattern) this.value);
|
||||
} else if (this.value instanceof String) {
|
||||
final String[] split = ((String) this.value).split(":");
|
||||
switch (split[0]) {
|
||||
case "parrot":
|
||||
MobCompat.setParrotVariant(spawned, split[1]);
|
||||
break;
|
||||
case "tropicalfish":
|
||||
MobCompat.setTropicalFishPattern(spawned, split[1]);
|
||||
break;
|
||||
case "mooshroom":
|
||||
MobCompat.setMooshroomVariant(spawned, split[1]);
|
||||
break;
|
||||
case "pandamain":
|
||||
MobCompat.setPandaGene(spawned, split[1], true);
|
||||
break;
|
||||
case "pandahidden":
|
||||
MobCompat.setPandaGene(spawned, split[1], false);
|
||||
break;
|
||||
case "llama":
|
||||
MobCompat.setLlamaColor(spawned, split[1]);
|
||||
break;
|
||||
case "villagertype":
|
||||
MobCompat.setVillagerType(spawned, split[1]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
logger.warning("Unknown mob data type: " + this.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.conversations.Conversation;
|
||||
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.memory.MemoryKey;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.*;
|
||||
@ -23,6 +24,7 @@ import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@ -162,6 +164,11 @@ public class OfflinePlayer implements Player {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pose getPose() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performCommand(String string) {
|
||||
return false;
|
||||
@ -1335,6 +1342,16 @@ public class OfflinePlayer implements Player {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getMemory(MemoryKey<T> memoryKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setMemory(MemoryKey<T> memoryKey, T t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Projectile> T launchProjectile(Class<? extends T> type, Vector vector) {
|
||||
return null;
|
||||
@ -1614,4 +1631,13 @@ public class OfflinePlayer implements Player {
|
||||
@Override
|
||||
public void updateCommands() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBook(ItemStack book) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentDataContainer getPersistentDataContainer() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ import com.earth2me.essentials.Mob;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Tameable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -18,16 +22,7 @@ public class Commandkittycannon extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final Mob cat = Mob.OCELOT;
|
||||
final Ocelot ocelot = (Ocelot) cat.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
|
||||
if (ocelot == null) {
|
||||
return;
|
||||
}
|
||||
final int i = random.nextInt(Ocelot.Type.values().length);
|
||||
ocelot.setCatType(Ocelot.Type.values()[i]);
|
||||
ocelot.setTamed(true);
|
||||
ocelot.setBaby();
|
||||
ocelot.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
|
||||
final Entity ocelot = Mob.CAT.getType() == null ? spawnOcelot(user.getWorld(), server, user) : spawnCat(user.getWorld(), server, user);
|
||||
|
||||
class KittyCannonExplodeTask implements Runnable {
|
||||
@Override
|
||||
@ -40,4 +35,32 @@ public class Commandkittycannon extends EssentialsCommand {
|
||||
ess.scheduleSyncDelayedTask(new KittyCannonExplodeTask(), 20);
|
||||
|
||||
}
|
||||
|
||||
private static Ocelot spawnOcelot(World world, Server server, User user) throws Mob.MobException {
|
||||
final Ocelot ocelot = (Ocelot) Mob.OCELOT.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
|
||||
if (ocelot == null) {
|
||||
return null;
|
||||
}
|
||||
final int i = random.nextInt(Ocelot.Type.values().length);
|
||||
ocelot.setCatType(Ocelot.Type.values()[i]);
|
||||
((Tameable) ocelot).setTamed(true);
|
||||
ocelot.setBaby();
|
||||
ocelot.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
|
||||
|
||||
return ocelot;
|
||||
}
|
||||
|
||||
private static Entity spawnCat(World world, Server server, User user) throws Mob.MobException {
|
||||
final Cat cat = (Cat) Mob.CAT.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
|
||||
if (cat == null) {
|
||||
return null;
|
||||
}
|
||||
final int i = random.nextInt(Cat.Type.values().length);
|
||||
cat.setCatType(Cat.Type.values()[i]);
|
||||
cat.setTamed(true);
|
||||
cat.setBaby();
|
||||
cat.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
|
||||
|
||||
return cat;
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class FakeWorld implements World {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
public boolean unloadChunk(int i, int i1, boolean bln, boolean bln1) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class FakeWorld implements World {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
public boolean unloadChunkRequest(int i, int i1, boolean bln) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@ -168,7 +168,7 @@ public class FakeWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Arrow> T spawnArrow(Location location, Vector vector, float v, float v1, Class<T> aClass) {
|
||||
public <T extends AbstractArrow> T spawnArrow(Location location, Vector direction, float speed, float spread, Class<T> clazz) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.items;
|
||||
|
||||
import com.earth2me.essentials.ManagedFile;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
@ -70,7 +71,7 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
allAliases.clear();
|
||||
}
|
||||
|
||||
public void loadJSON(String source) {
|
||||
private void loadJSON(String source) {
|
||||
JsonObject map = (new JsonParser()).parse(source).getAsJsonObject();
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : map.entrySet()) {
|
||||
@ -191,11 +192,11 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getLegacyId(Material material) throws Exception {
|
||||
public int getLegacyId(Material material) {
|
||||
throw new UnsupportedOperationException("Legacy IDs aren't supported on this version.");
|
||||
}
|
||||
|
||||
public ItemData lookup(ItemStack item) {
|
||||
private ItemData lookup(ItemStack item) {
|
||||
Material type = item.getType();
|
||||
|
||||
if (MaterialUtil.isPotion(type) && item.getItemMeta() instanceof PotionMeta) {
|
||||
@ -217,20 +218,21 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
}
|
||||
|
||||
public static class ItemData {
|
||||
private final Material material;
|
||||
private Material material;
|
||||
private String[] fallbacks = null;
|
||||
private PotionData potionData = null;
|
||||
private EntityType entity = null;
|
||||
|
||||
public ItemData(Material material) {
|
||||
ItemData(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public ItemData(Material material, PotionData potionData) {
|
||||
ItemData(Material material, PotionData potionData) {
|
||||
this.material = material;
|
||||
this.potionData = potionData;
|
||||
}
|
||||
|
||||
public ItemData(Material material, EntityType entity) {
|
||||
ItemData(Material material, EntityType entity) {
|
||||
this.material = material;
|
||||
this.entity = entity;
|
||||
}
|
||||
@ -249,10 +251,15 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
return false;
|
||||
}
|
||||
ItemData that = (ItemData) o;
|
||||
return this.material == that.getMaterial() && potionDataEquals(that) && entityEquals(that);
|
||||
return this.getMaterial() == that.getMaterial() && potionDataEquals(that) && entityEquals(that);
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
if (material == null && fallbacks != null) {
|
||||
material = EnumUtil.getMaterial(fallbacks);
|
||||
fallbacks = null; // If fallback fails, don't keep trying to look up fallbacks
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.earth2me.essentials.metrics;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
@ -186,24 +187,24 @@ public class Metrics {
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
public JsonObject getPluginData() {
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName().replace("Essentials", "EssentialsX");
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
data.addProperty("pluginName", pluginName); // Append the name of the plugin
|
||||
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JsonArray customCharts = new JsonArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
JsonObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
data.add("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -213,7 +214,7 @@ public class Metrics {
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
private JsonObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
@ -228,6 +229,7 @@ public class Metrics {
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
String bukkitName = Bukkit.getName();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
@ -236,19 +238,20 @@ public class Metrics {
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
JsonObject data = new JsonObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
data.addProperty("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("bukkitVersion", bukkitVersion);
|
||||
data.addProperty("playerAmount", playerAmount);
|
||||
data.addProperty("onlineMode", onlineMode);
|
||||
data.addProperty("bukkitVersion", bukkitVersion);
|
||||
data.addProperty("bukkitName", bukkitName);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
data.addProperty("javaVersion", javaVersion);
|
||||
data.addProperty("osName", osName);
|
||||
data.addProperty("osArch", osArch);
|
||||
data.addProperty("osVersion", osVersion);
|
||||
data.addProperty("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -257,9 +260,9 @@ public class Metrics {
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
final JsonObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
JsonArray pluginData = new JsonArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
@ -267,26 +270,43 @@ public class Metrics {
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
|
||||
if (plugin instanceof JsonObject) {
|
||||
pluginData.add((JsonObject) plugin);
|
||||
} else { // old bstats version compatibility
|
||||
try {
|
||||
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
|
||||
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
|
||||
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
|
||||
jsonStringGetter.setAccessible(true);
|
||||
String jsonString = (String) jsonStringGetter.invoke(plugin);
|
||||
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
|
||||
pluginData.add(object);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
// minecraft version 1.14+
|
||||
if (logFailedRequests) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
|
||||
}
|
||||
continue; // continue looping since we cannot do any other thing.
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
data.add("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@ -299,7 +319,7 @@ public class Metrics {
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
@ -382,16 +402,16 @@ public class Metrics {
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
private JsonObject getRequestJsonObject() {
|
||||
JsonObject chart = new JsonObject();
|
||||
chart.addProperty("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
JsonObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
chart.add("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
@ -401,7 +421,7 @@ public class Metrics {
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
protected abstract JsonObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@ -424,14 +444,14 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
data.addProperty("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -455,9 +475,9 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
@ -469,13 +489,13 @@ public class Metrics {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
values.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -499,9 +519,9 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
public JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
@ -509,22 +529,22 @@ public class Metrics {
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JSONObject value = new JSONObject();
|
||||
JsonObject value = new JsonObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.put(entryValues.getKey(), value);
|
||||
values.add(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -548,14 +568,14 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
data.addProperty("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -580,9 +600,9 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
@ -594,13 +614,13 @@ public class Metrics {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
values.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -625,20 +645,20 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
JsonArray categoryValues = new JsonArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
values.add(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -663,9 +683,9 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
protected JsonObject getChartData() throws Exception {
|
||||
JsonObject data = new JsonObject();
|
||||
JsonObject values = new JsonObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
@ -677,17 +697,17 @@ public class Metrics {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
JsonArray categoryValues = new JsonArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
values.add(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
data.add("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.*;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
@ -13,6 +13,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -26,7 +27,6 @@ import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
||||
public class EssentialsSign {
|
||||
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
|
||||
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
||||
protected static final BigDecimal MINTRANSACTION = new BigDecimal("0.01");
|
||||
protected transient final String signName;
|
||||
@ -206,16 +206,15 @@ public class EssentialsSign {
|
||||
|
||||
protected static boolean checkIfBlockBreaksSigns(final Block block) {
|
||||
final Block sign = block.getRelative(BlockFace.UP);
|
||||
if (sign.getType() == SIGN_POST && isValidSign(new BlockSign(sign))) {
|
||||
if (MaterialUtil.isSignPost(sign.getType()) && isValidSign(new BlockSign(sign))) {
|
||||
return true;
|
||||
}
|
||||
final BlockFace[] directions = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace blockFace : directions) {
|
||||
final Block signblock = block.getRelative(blockFace);
|
||||
if (signblock.getType() == Material.WALL_SIGN) {
|
||||
final Block signBlock = block.getRelative(blockFace);
|
||||
if (MaterialUtil.isWallSign(signBlock.getType())) {
|
||||
try {
|
||||
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) signblock.getState().getData();
|
||||
if (signMat != null && signMat.getFacing() == blockFace && isValidSign(new BlockSign(signblock))) {
|
||||
if (getWallSignFacing(signBlock) == blockFace && isValidSign(new BlockSign(signBlock))) {
|
||||
return true;
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
@ -445,6 +444,16 @@ public class EssentialsSign {
|
||||
ess.showError(sender, exception, "\\ sign: " + signName);
|
||||
}
|
||||
|
||||
private static BlockFace getWallSignFacing(Block block) {
|
||||
try {
|
||||
final WallSign signData = (WallSign) block.getState().getBlockData();
|
||||
return signData.getFacing();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) block.getState().getData();
|
||||
return signMat.getFacing();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class EventSign implements ISign {
|
||||
private final transient SignChangeEvent event;
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.I18n;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -22,8 +23,6 @@ import java.util.logging.Logger;
|
||||
|
||||
public class SignBlockListener implements Listener {
|
||||
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
||||
private static final Material WALL_SIGN = Material.WALL_SIGN;
|
||||
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public SignBlockListener(IEssentials ess) {
|
||||
@ -55,7 +54,7 @@ public class SignBlockListener implements Listener {
|
||||
}
|
||||
|
||||
final Material mat = block.getType();
|
||||
if (mat == SIGN_POST || mat == WALL_SIGN) {
|
||||
if (MaterialUtil.isSign(mat)) {
|
||||
final Sign csign = (Sign) block.getState();
|
||||
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
||||
@ -143,12 +142,12 @@ public class SignBlockListener implements Listener {
|
||||
}
|
||||
|
||||
final Block against = event.getBlockAgainst();
|
||||
if ((against.getType() == WALL_SIGN || against.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(against))) {
|
||||
if (MaterialUtil.isSign(against.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(against))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
if (block.getType() == WALL_SIGN || block.getType() == SIGN_POST) {
|
||||
if (MaterialUtil.isSign(block.getType())) {
|
||||
return;
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns()) {
|
||||
@ -167,7 +166,7 @@ public class SignBlockListener implements Listener {
|
||||
}
|
||||
|
||||
final Block block = event.getBlock();
|
||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -187,7 +186,7 @@ public class SignBlockListener implements Listener {
|
||||
}
|
||||
|
||||
final Block block = event.getBlock();
|
||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -207,7 +206,7 @@ public class SignBlockListener implements Listener {
|
||||
}
|
||||
|
||||
for (Block block : event.getBlocks()) {
|
||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -232,7 +231,7 @@ public class SignBlockListener implements Listener {
|
||||
final Block[] affectedBlocks = new Block[]{pistonBaseBlock, pistonBaseBlock.getRelative(event.getDirection()), event.getRetractLocation().getBlock()};
|
||||
|
||||
for (Block block : affectedBlocks) {
|
||||
if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -13,7 +14,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class SignEntityListener implements Listener {
|
||||
|
||||
private static final Material SIGN_POST = EnumUtil.getMaterial("SIGN", "SIGN_POST");
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public SignEntityListener(final IEssentials ess) {
|
||||
@ -28,7 +28,7 @@ public class SignEntityListener implements Listener {
|
||||
}
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (((block.getType() == Material.WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class SignEntityListener implements Listener {
|
||||
}
|
||||
|
||||
final Block block = event.getBlock();
|
||||
if (((block.getType() == Material.WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
if ((MaterialUtil.isSign(block.getType()) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class SignProtection extends EssentialsSign {
|
||||
final Block sign = entry.getKey().getBlock();
|
||||
if (!hasAdjacentBlock(sign, block)) {
|
||||
block.setType(Material.AIR);
|
||||
final Trade trade = new Trade(new ItemStack(Material.SIGN, 1), ess);
|
||||
final Trade trade = new Trade(new ItemStack(sign.getType(), 1), ess);
|
||||
trade.pay(player, OverflowType.DROP);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
@ -78,4 +79,7 @@ public class EnumUtil {
|
||||
return valueOf(Statistic.class, names);
|
||||
}
|
||||
|
||||
public static EntityType getEntityType(String... names) {
|
||||
return valueOf(EntityType.class, names);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ public class MaterialUtil {
|
||||
// includes TIPPED_ARROW which also has potion effects
|
||||
private static final Set<Material> PLAYER_HEADS;
|
||||
private static final Set<Material> POTIONS;
|
||||
private static final Set<Material> SIGNS;
|
||||
private static final Set<Material> SIGN_POSTS;
|
||||
private static final Set<Material> WALL_SIGNS;
|
||||
|
||||
public static final Material SPAWNER = EnumUtil.getMaterial("MOB_SPAWNER", "SPAWNER");
|
||||
|
||||
@ -55,7 +56,14 @@ public class MaterialUtil {
|
||||
POTIONS = EnumUtil.getAllMatching(Material.class, "POTION", "SPLASH_POTION",
|
||||
"LINGERING_POTION", "TIPPED_ARROW");
|
||||
|
||||
SIGNS = EnumUtil.getAllMatching(Material.class, "SIGN", "SIGN_POST", "WALL_SIGN");
|
||||
SIGN_POSTS = EnumUtil.getAllMatching(Material.class, "SIGN", "SIGN_POST",
|
||||
"ACACIA_SIGN", "BIRCH_SIGN",
|
||||
"DARK_OAK_SIGN", "JUNGLE_SIGN",
|
||||
"OAK_SIGN", "SPRUCE_SIGN");
|
||||
|
||||
WALL_SIGNS = EnumUtil.getAllMatching(Material.class, "WALL_SIGN",
|
||||
"ACACIA_WALL_SIGN", "BIRCH_WALL_SIGN", "DARK_OAK_WALL_SIGN", "JUNGLE_WALL_SIGN",
|
||||
"OAK_WALL_SIGN", "SPRUCE_WALL_SIGN");
|
||||
}
|
||||
|
||||
public static boolean isBed(Material material) {
|
||||
@ -94,8 +102,16 @@ public class MaterialUtil {
|
||||
return POTIONS.contains(material);
|
||||
}
|
||||
|
||||
public static boolean isSignPost(Material material) {
|
||||
return SIGN_POSTS.contains(material);
|
||||
}
|
||||
|
||||
public static boolean isWallSign(Material material) {
|
||||
return WALL_SIGNS.contains(material);
|
||||
}
|
||||
|
||||
public static boolean isSign(Material material) {
|
||||
return SIGNS.contains(material);
|
||||
return isSignPost(material) || isWallSign(material);
|
||||
}
|
||||
|
||||
public static boolean isSkull(Material material) {
|
||||
@ -108,7 +124,7 @@ public class MaterialUtil {
|
||||
try {
|
||||
return Bukkit.getUnsafe().fromLegacy(new MaterialData(material, damage));
|
||||
} catch (NoSuchMethodError error) {
|
||||
return material;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,11 @@ public class VersionUtil {
|
||||
public static final BukkitVersion v1_12_2_R01 = BukkitVersion.fromString("1.12.2-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_13_0_R01 = BukkitVersion.fromString("1.13.0-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_13_2_R01 = BukkitVersion.fromString("1.13.2-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_14_R01 = BukkitVersion.fromString("1.14-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_14_1_R01 = BukkitVersion.fromString("1.14.1-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_14_2_R01 = BukkitVersion.fromString("1.14.2-R0.1-SNAPSHOT");
|
||||
|
||||
private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01);
|
||||
private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_2_R01);
|
||||
|
||||
private static BukkitVersion serverVersion = null;
|
||||
|
||||
@ -37,10 +40,11 @@ public class VersionUtil {
|
||||
}
|
||||
|
||||
public static class BukkitVersion implements Comparable<BukkitVersion> {
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.?([0-9]*)-R([\\d.]+)(?:-SNAPSHOT)?");
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.?([0-9]*)?-(?:pre(\\d))?-?R?([\\d.]+)?(?:-SNAPSHOT)?");
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int prerelease;
|
||||
private final int patch;
|
||||
private final double revision;
|
||||
|
||||
@ -51,26 +55,30 @@ public class VersionUtil {
|
||||
if (!Bukkit.getName().equals("Essentials Fake Server")) {
|
||||
throw new IllegalArgumentException(string + " is not in valid version format. e.g. 1.8.8-R0.1");
|
||||
}
|
||||
matcher = VERSION_PATTERN.matcher(v1_13_2_R01.toString());
|
||||
matcher = VERSION_PATTERN.matcher(v1_14_R01.toString());
|
||||
Preconditions.checkArgument(matcher.matches(), string + " is not in valid version format. e.g. 1.8.8-R0.1");
|
||||
}
|
||||
|
||||
return from(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4));
|
||||
return from(matcher.group(1), matcher.group(2), matcher.group(3), matcher.groupCount() < 5 ? "" : matcher.group(5), matcher.group(4));
|
||||
}
|
||||
|
||||
private static BukkitVersion from(String major, String minor, String patch, String revision) {
|
||||
if (patch.isEmpty()) patch = "0";
|
||||
private static BukkitVersion from(String major, String minor, String patch, String revision, String prerelease) {
|
||||
if (patch == null || patch.isEmpty()) patch = "0";
|
||||
if (revision == null || revision.isEmpty()) revision = "0";
|
||||
if (prerelease == null || prerelease.isEmpty()) prerelease = "-1";
|
||||
return new BukkitVersion(Integer.parseInt(major),
|
||||
Integer.parseInt(minor),
|
||||
Integer.parseInt(patch),
|
||||
Double.parseDouble(revision));
|
||||
Double.parseDouble(revision),
|
||||
Integer.parseInt(prerelease));
|
||||
}
|
||||
|
||||
private BukkitVersion(int major, int minor, int patch, double revision) {
|
||||
private BukkitVersion(int major, int minor, int patch, double revision, int prerelease) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.revision = revision;
|
||||
this.prerelease = prerelease;
|
||||
}
|
||||
|
||||
public boolean isHigherThan(BukkitVersion o) {
|
||||
@ -105,6 +113,10 @@ public class VersionUtil {
|
||||
return revision;
|
||||
}
|
||||
|
||||
public int getPrerelease() {
|
||||
return prerelease;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@ -115,19 +127,27 @@ public class VersionUtil {
|
||||
}
|
||||
BukkitVersion that = (BukkitVersion) o;
|
||||
return major == that.major &&
|
||||
minor == that.minor &&
|
||||
patch == that.patch &&
|
||||
revision == that.revision;
|
||||
minor == that.minor &&
|
||||
patch == that.patch &&
|
||||
revision == that.revision &&
|
||||
prerelease == that.prerelease;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(major, minor, patch, revision);
|
||||
return Objects.hashCode(major, minor, patch, revision, prerelease);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return major + "." + minor + "." + patch + "-R" + revision;
|
||||
StringBuilder sb = new StringBuilder(major + "." + minor);
|
||||
if (patch != 0) {
|
||||
sb.append(".").append(patch);
|
||||
}
|
||||
if (prerelease != -1) {
|
||||
sb.append("-pre").append(prerelease);
|
||||
}
|
||||
return sb.append("-R").append(revision).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,7 +167,13 @@ public class VersionUtil {
|
||||
} else if (patch > o.patch) {
|
||||
return 1;
|
||||
} else { // equal patch
|
||||
return Double.compare(revision, o.revision);
|
||||
if (prerelease < o.prerelease) {
|
||||
return -1;
|
||||
} else if (prerelease > o.prerelease) {
|
||||
return 1;
|
||||
} else { // equal prerelease
|
||||
return Double.compare(revision, o.revision);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ package net.ess3.api.events;
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.signs.EssentialsSign.ISign;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -19,7 +20,7 @@ public class SignEvent extends Event implements Cancellable {
|
||||
IUser user;
|
||||
|
||||
public SignEvent(final ISign sign, final EssentialsSign essSign, final IUser user) {
|
||||
super();
|
||||
super(!Bukkit.getServer().isPrimaryThread());
|
||||
this.sign = sign;
|
||||
this.essSign = essSign;
|
||||
this.user = user;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ess3.api.events;
|
||||
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
|
||||
@ -11,8 +12,7 @@ public class StatusChangeEvent extends StateChangeEvent implements Cancellable {
|
||||
private boolean newValue;
|
||||
|
||||
public StatusChangeEvent(IUser affected, IUser controller, boolean value) {
|
||||
super(affected, controller);
|
||||
this.newValue = value;
|
||||
this(!Bukkit.getServer().isPrimaryThread(), affected, controller, value);
|
||||
}
|
||||
|
||||
public StatusChangeEvent(boolean isAsync, IUser affected, IUser controller, boolean value) {
|
||||
|
@ -2,6 +2,7 @@ package net.ess3.api.events;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -16,6 +17,7 @@ public class UserBalanceUpdateEvent extends Event {
|
||||
private BigDecimal balance;
|
||||
|
||||
public UserBalanceUpdateEvent(Player player, BigDecimal originalBalance, BigDecimal balance) {
|
||||
super(!Bukkit.getServer().isPrimaryThread());
|
||||
this.player = player;
|
||||
this.originalBalance = originalBalance;
|
||||
this.balance = balance;
|
||||
|
@ -2,6 +2,7 @@ package net.ess3.api.events;
|
||||
|
||||
import com.earth2me.essentials.Trade;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
@ -18,7 +19,8 @@ public class UserWarpEvent extends Event implements Cancellable {
|
||||
private boolean cancelled = false;
|
||||
|
||||
|
||||
public UserWarpEvent(IUser user, String warp, Trade trade){
|
||||
public UserWarpEvent(IUser user, String warp, Trade trade) {
|
||||
super(!Bukkit.getServer().isPrimaryThread());
|
||||
this.user = user;
|
||||
this.warp = warp;
|
||||
this.trade = trade;
|
||||
|
@ -91,16 +91,6 @@ public class FakeServer implements Server {
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return "Test Server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerId() {
|
||||
return "Test Server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int broadcastMessage(String string) {
|
||||
int i = 0;
|
||||
@ -884,7 +874,7 @@ public class FakeServer implements Server {
|
||||
|
||||
@Override
|
||||
public boolean isPrimaryThread() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
return true; // Can be set to true or false, just needs to return for AFK status test to pass.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -197,10 +197,24 @@ public class UtilTest extends TestCase {
|
||||
assertEquals(v.getMinor(), 13);
|
||||
assertEquals(v.getPatch(), 2);
|
||||
assertEquals(v.getRevision(), 0.1);
|
||||
v = VersionUtil.BukkitVersion.fromString("1.9-R1.4");
|
||||
assertEquals(v.getPrerelease(), -1);
|
||||
v = VersionUtil.BukkitVersion.fromString("1.9-R1.4"); // not real
|
||||
assertEquals(v.getMajor(), 1);
|
||||
assertEquals(v.getMinor(), 9);
|
||||
assertEquals(v.getPatch(), 0);
|
||||
assertEquals(v.getRevision(), 1.4);
|
||||
assertEquals(v.getPrerelease(), -1);
|
||||
v = VersionUtil.BukkitVersion.fromString("1.14-pre5");
|
||||
assertEquals(v.getMajor(), 1);
|
||||
assertEquals(v.getMinor(), 14);
|
||||
assertEquals(v.getPatch(), 0);
|
||||
assertEquals(v.getRevision(), 0.0);
|
||||
assertEquals(v.getPrerelease(), 5);
|
||||
v = VersionUtil.BukkitVersion.fromString("1.13.2-pre1-R0.1"); // not real
|
||||
assertEquals(v.getMajor(), 1);
|
||||
assertEquals(v.getMinor(), 13);
|
||||
assertEquals(v.getPatch(), 2);
|
||||
assertEquals(v.getRevision(), 0.1);
|
||||
assertEquals(v.getPrerelease(), 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user