mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
Re-add support for Minecraft 1.8 - 1.12.2
This commit is contained in:
parent
3d60b5b49c
commit
4cb59b18de
@ -151,6 +151,14 @@ public class ShopChest extends JavaPlugin {
|
||||
}
|
||||
|
||||
switch (Utils.getServerVersion()) {
|
||||
case "v1_8_R1":
|
||||
case "v1_8_R2":
|
||||
case "v1_8_R3":
|
||||
case "v1_9_R1":
|
||||
case "v1_9_R2":
|
||||
case "v1_10_R1":
|
||||
case "v1_11_R1":
|
||||
case "v1_12_R1":
|
||||
case "v1_13_R1":
|
||||
break;
|
||||
default:
|
||||
@ -353,7 +361,10 @@ public class ShopChest extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new NotifyPlayerOnJoinListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new ChestProtectListener(this, worldGuard), this);
|
||||
|
||||
if (!Utils.getServerVersion().equals("v1_8_R1")) {
|
||||
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
|
||||
}
|
||||
|
||||
if (hasWorldGuard()) {
|
||||
getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this);
|
||||
|
@ -5,6 +5,8 @@ import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.sql.Database;
|
||||
import de.epiceric.shopchest.utils.ItemUtils;
|
||||
import de.epiceric.shopchest.utils.ShopUpdater;
|
||||
import de.epiceric.shopchest.utils.Utils;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -543,14 +545,16 @@ public class Config {
|
||||
langConfig = new LanguageConfiguration(plugin, showMessages);
|
||||
File langFolder = new File(plugin.getDataFolder(), "lang");
|
||||
|
||||
if (!(new File(langFolder, "en_US.lang")).exists())
|
||||
plugin.saveResource("lang/en_US.lang", false);
|
||||
String legacy = Utils.getMajorVersion() < 13 ? "-legacy" : "";
|
||||
|
||||
if (!(new File(langFolder, "de_DE.lang")).exists())
|
||||
plugin.saveResource("lang/de_DE.lang", false);
|
||||
if (!(new File(langFolder, "en_US" + legacy + ".lang")).exists())
|
||||
plugin.saveResource("lang/en_US" + legacy + ".lang", false);
|
||||
|
||||
File langConfigFile = new File(langFolder, languageFile + ".lang");
|
||||
File langDefaultFile = new File(langFolder, "en_US.lang");
|
||||
if (!(new File(langFolder, "de_DE" + legacy + ".lang")).exists())
|
||||
plugin.saveResource("lang/de_DE" + legacy + ".lang", false);
|
||||
|
||||
File langConfigFile = new File(langFolder, languageFile + legacy + ".lang");
|
||||
File langDefaultFile = new File(langFolder, "en_US" + legacy + ".lang");
|
||||
|
||||
if (!langConfigFile.exists()) {
|
||||
if (!langDefaultFile.exists()) {
|
||||
@ -558,8 +562,8 @@ public class Config {
|
||||
Reader r = getTextResource("lang/" + langConfigFile.getName(), showMessages);
|
||||
|
||||
if (r == null) {
|
||||
r = getTextResource("lang/en_US.lang", showMessages);
|
||||
if (showMessages) plugin.getLogger().info("Using locale \"en_US\" (Streamed from jar file)");
|
||||
r = getTextResource("lang/en_US" + legacy + ".lang", showMessages);
|
||||
if (showMessages) plugin.getLogger().info("Using locale \"en_US" + legacy + "\" (Streamed from jar file)");
|
||||
} else {
|
||||
if (showMessages)
|
||||
plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\" (Streamed from jar file)");
|
||||
@ -593,7 +597,7 @@ public class Config {
|
||||
} else {
|
||||
try {
|
||||
langConfig.load(langDefaultFile);
|
||||
if (showMessages) plugin.getLogger().info("Using locale \"en_US\"");
|
||||
if (showMessages) plugin.getLogger().info("Using locale \"en_US" + legacy + "\"");
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
if (showMessages) {
|
||||
plugin.getLogger().warning("Using default language values");
|
||||
|
@ -1,13 +1,13 @@
|
||||
package de.epiceric.shopchest.language;
|
||||
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import de.epiceric.shopchest.nms.CustomBookMeta;
|
||||
|
||||
public class BookGenerationName {
|
||||
|
||||
private String localizedName;
|
||||
private BookMeta.Generation generation;
|
||||
private CustomBookMeta.Generation generation;
|
||||
|
||||
public BookGenerationName(BookMeta.Generation generation, String localizedName) {
|
||||
public BookGenerationName(CustomBookMeta.Generation generation, String localizedName) {
|
||||
this.generation = generation;
|
||||
this.localizedName = localizedName;
|
||||
}
|
||||
@ -15,7 +15,7 @@ public class BookGenerationName {
|
||||
/**
|
||||
* @return Generation linked to the name
|
||||
*/
|
||||
public BookMeta.Generation getGeneration() {
|
||||
public CustomBookMeta.Generation getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,16 @@ import org.bukkit.Material;
|
||||
public class ItemName {
|
||||
|
||||
private Material material;
|
||||
private int subId;
|
||||
private String localizedName;
|
||||
|
||||
public ItemName(Material material, String localizedName) {
|
||||
this(material, 0, localizedName);
|
||||
}
|
||||
|
||||
public ItemName(Material material, int subId, String localizedName) {
|
||||
this.material = material;
|
||||
this.subId = subId;
|
||||
this.localizedName = localizedName;
|
||||
}
|
||||
|
||||
@ -19,6 +25,13 @@ public class ItemName {
|
||||
return material;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Sub ID linked to the name
|
||||
*/
|
||||
public int getSubId() {
|
||||
return subId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name linked to the item
|
||||
*/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import pl.islandworld.api.IslandWorldApi;
|
||||
import us.talabrek.ultimateskyblock.api.IslandInfo;
|
||||
@ -129,34 +130,61 @@ public class ChestProtectListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private BlockFace getNeighborFacing(Type chestType, BlockFace facing) {
|
||||
switch (facing) {
|
||||
case NORTH:
|
||||
return chestType == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
|
||||
case EAST:
|
||||
return chestType == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
|
||||
case SOUTH:
|
||||
return chestType == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
|
||||
case WEST:
|
||||
return chestType == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
final Block b = e.getBlockPlaced();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
if (!b.getType().equals(Material.CHEST) && !b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Chest c = (Chest) b.getState();
|
||||
Block b2;
|
||||
|
||||
if (Utils.getMajorVersion() < 13) {
|
||||
InventoryHolder ih = c.getInventory().getHolder();
|
||||
if (!(ih instanceof DoubleChest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DoubleChest dc = (DoubleChest) ih;
|
||||
Chest l = (Chest) dc.getLeftSide();
|
||||
Chest r = (Chest) dc.getRightSide();
|
||||
|
||||
if (b.getLocation().equals(l.getLocation())) {
|
||||
b2 = r.getBlock();
|
||||
} else {
|
||||
b2 = l.getBlock();
|
||||
}
|
||||
} else {
|
||||
org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();
|
||||
|
||||
if (data.getType() != Type.SINGLE) {
|
||||
BlockFace neighborFacing = getNeighborFacing(data.getType(), data.getFacing());
|
||||
Block b2 = b.getRelative(neighborFacing);
|
||||
if (data.getType() == Type.SINGLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockFace neighborFacing;
|
||||
|
||||
switch (data.getFacing()) {
|
||||
case NORTH:
|
||||
neighborFacing = data.getType() == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
|
||||
break;
|
||||
case EAST:
|
||||
neighborFacing = data.getType() == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
neighborFacing = data.getType() == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
|
||||
break;
|
||||
case WEST:
|
||||
neighborFacing = data.getType() == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
|
||||
break;
|
||||
default:
|
||||
neighborFacing = null;
|
||||
}
|
||||
|
||||
b2 = b.getRelative(neighborFacing);
|
||||
}
|
||||
|
||||
if (shopUtils.isShop(b.getLocation()) || shopUtils.isShop(b2.getLocation())) {
|
||||
final Shop shop = shopUtils.getShop(b2.getLocation());
|
||||
@ -260,11 +288,6 @@ public class ChestProtectListener implements Listener {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,20 +47,29 @@ public class ArmorStandWrapper {
|
||||
.newInstance(nmsWorld, location.getX(), location.getY(), location.getZ());
|
||||
|
||||
if (customName != null && !customName.trim().isEmpty()) {
|
||||
if (Utils.getMajorVersion() < 13) {
|
||||
entityArmorStandClass.getMethod("setCustomName", String.class).invoke(entity, customName);
|
||||
} else {
|
||||
Object chatMessage = chatMessageClass.getConstructor(String.class, Object[].class)
|
||||
.newInstance(customName, new Object[0]);
|
||||
|
||||
entityArmorStandClass.getMethod("setCustomName", iChatBaseComponentClass).invoke(entity, chatMessage);
|
||||
}
|
||||
entityArmorStandClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, true);
|
||||
}
|
||||
|
||||
if (Utils.getMajorVersion() < 10) {
|
||||
entityArmorStandClass.getMethod("setGravity", boolean.class).invoke(entity, false);
|
||||
} else {
|
||||
entityArmorStandClass.getMethod("setNoGravity", boolean.class).invoke(entity, true);
|
||||
}
|
||||
|
||||
entityArmorStandClass.getMethod("setInvisible", boolean.class).invoke(entity, true);
|
||||
|
||||
// Adds the entity to some lists so it can call interact events
|
||||
// It will also automatically load/unload it when far away
|
||||
if (interactable) {
|
||||
Method addEntityMethod = worldServerClass.getDeclaredMethod("b", entityClass);
|
||||
Method addEntityMethod = worldServerClass.getDeclaredMethod(Utils.getMajorVersion() == 8 ? "a" : "b", entityClass);
|
||||
addEntityMethod.setAccessible(true);
|
||||
addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity);
|
||||
}
|
||||
@ -117,13 +126,24 @@ public class ArmorStandWrapper {
|
||||
|
||||
try {
|
||||
if (customName != null && !customName.isEmpty()) {
|
||||
if (Utils.getMajorVersion() < 13) {
|
||||
entityClass.getMethod("setCustomName", String.class).invoke(entity, customName);
|
||||
} else {
|
||||
Object chatMessage = chatMessageClass.getConstructor(String.class, Object[].class)
|
||||
.newInstance(customName, new Object[0]);
|
||||
|
||||
entityClass.getMethod("setCustomName", iChatBaseComponentClass).invoke(entity, chatMessage);
|
||||
}
|
||||
entityClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, true);
|
||||
} else {
|
||||
if (Utils.getMajorVersion() < 13) {
|
||||
entityClass.getMethod("setCustomName", String.class).invoke(entity, "");
|
||||
} else {
|
||||
Object chatMessage = chatMessageClass.getConstructor(String.class, Object[].class)
|
||||
.newInstance("", new Object[0]);
|
||||
|
||||
entityClass.getMethod("setCustomName", iChatBaseComponentClass).invoke(entity, chatMessage);
|
||||
}
|
||||
entityClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, false);
|
||||
}
|
||||
|
||||
@ -150,7 +170,7 @@ public class ArmorStandWrapper {
|
||||
|
||||
try {
|
||||
// Removes the entity from the lists it was added to for interaction
|
||||
Method addEntityMethod = worldServerClass.getDeclaredMethod("c", entityClass);
|
||||
Method addEntityMethod = worldServerClass.getDeclaredMethod(Utils.getMajorVersion() == 8 ? "b" : "c", entityClass);
|
||||
addEntityMethod.setAccessible(true);
|
||||
addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
|
90
src/main/java/de/epiceric/shopchest/nms/CustomBookMeta.java
Normal file
90
src/main/java/de/epiceric/shopchest/nms/CustomBookMeta.java
Normal file
@ -0,0 +1,90 @@
|
||||
package de.epiceric.shopchest.nms;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.utils.Utils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
// For versions below 1.9.4, since Bukkit's BookMeta
|
||||
// didn't have generations in those versions
|
||||
|
||||
public class CustomBookMeta {
|
||||
|
||||
public enum Generation {
|
||||
ORIGINAL,
|
||||
COPY_OF_ORIGINAL,
|
||||
COPY_OF_COPY,
|
||||
TATTERED
|
||||
}
|
||||
|
||||
public static Generation getGeneration(ItemStack book) {
|
||||
try {
|
||||
Class<?> craftItemStackClass = Utils.getCraftClass("inventory.CraftItemStack");
|
||||
|
||||
if (craftItemStackClass == null) {
|
||||
ShopChest.getInstance().debug("Failed to get NBTGeneration: Could not find CraftItemStack class");
|
||||
return null;
|
||||
}
|
||||
|
||||
Object nmsStack = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, book);
|
||||
|
||||
Object nbtTagCompound = nmsStack.getClass().getMethod("getTag").invoke(nmsStack);
|
||||
if (nbtTagCompound == null) {
|
||||
ShopChest.getInstance().debug("Failed to get NBTGeneration: getTag returned null");
|
||||
return null;
|
||||
}
|
||||
|
||||
Object generationObject = nbtTagCompound.getClass().getMethod("getInt", String.class).invoke(nbtTagCompound, "generation");
|
||||
if (generationObject == null) {
|
||||
ShopChest.getInstance().debug("Failed to get NBTGeneration: getInt returned null");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (generationObject instanceof Integer) {
|
||||
int generation = (Integer) generationObject;
|
||||
|
||||
if (generation > 3) generation = 3;
|
||||
|
||||
return Generation.values()[generation];
|
||||
}
|
||||
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
ShopChest.getInstance().getLogger().severe("Failed to get NBTEntityID with reflection");
|
||||
ShopChest.getInstance().debug("Failed to get NBTEntityID with reflection");
|
||||
ShopChest.getInstance().debug(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setGeneration(ItemStack book, Generation generation) {
|
||||
try {
|
||||
Class<?> craftItemStackClass = Utils.getCraftClass("inventory.CraftItemStack");
|
||||
|
||||
if (craftItemStackClass == null) {
|
||||
ShopChest.getInstance().debug("Failed to get NBTGeneration: Could not find CraftItemStack class");
|
||||
return;
|
||||
}
|
||||
|
||||
Object nmsStack = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, book);
|
||||
|
||||
Object nbtTagCompound = nmsStack.getClass().getMethod("getTag").invoke(nmsStack);
|
||||
if (nbtTagCompound == null) {
|
||||
ShopChest.getInstance().debug("Failed to get NBTGeneration: getTag returned null");
|
||||
return;
|
||||
}
|
||||
|
||||
nbtTagCompound.getClass().getMethod("setInt", String.class, int.class)
|
||||
.invoke(nbtTagCompound, "generation", generation.ordinal());
|
||||
|
||||
nmsStack.getClass().getMethod("setTag", nbtTagCompound.getClass()).invoke(nmsStack, nbtTagCompound);
|
||||
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
ShopChest.getInstance().getLogger().severe("Failed to get NBTEntityID with reflection");
|
||||
ShopChest.getInstance().debug("Failed to get NBTEntityID with reflection");
|
||||
ShopChest.getInstance().debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -17,11 +17,17 @@ public class JsonBuilder {
|
||||
|
||||
private Class<?> iChatBaseComponentClass = Utils.getNMSClass("IChatBaseComponent");
|
||||
private Class<?> packetPlayOutChatClass = Utils.getNMSClass("PacketPlayOutChat");
|
||||
private Class<?> chatSerializerClass = Utils.getNMSClass("IChatBaseComponent$ChatSerializer");;
|
||||
private Class<?> chatSerializerClass;
|
||||
|
||||
public JsonBuilder(ShopChest plugin, String text, String hoverText, String downloadLink) {
|
||||
this.plugin = plugin;
|
||||
|
||||
if (Utils.getServerVersion().equals("v1_8_R1")) {
|
||||
chatSerializerClass = Utils.getNMSClass("ChatSerializer");
|
||||
} else {
|
||||
chatSerializerClass = Utils.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
}
|
||||
|
||||
Class<?>[] requiredClasses = new Class<?>[] {
|
||||
iChatBaseComponentClass, packetPlayOutChatClass, chatSerializerClass
|
||||
};
|
||||
|
89
src/main/java/de/epiceric/shopchest/nms/SpawnEggMeta.java
Normal file
89
src/main/java/de/epiceric/shopchest/nms/SpawnEggMeta.java
Normal file
@ -0,0 +1,89 @@
|
||||
package de.epiceric.shopchest.nms;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.utils.Utils;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class SpawnEggMeta {
|
||||
|
||||
private static String getNBTEntityID(ShopChest plugin, ItemStack stack) {
|
||||
try {
|
||||
Class<?> craftItemStackClass = Utils.getCraftClass("inventory.CraftItemStack");
|
||||
|
||||
if (craftItemStackClass == null) {
|
||||
plugin.debug("Failed to get NBTEntityID: Could not find CraftItemStack class");
|
||||
return null;
|
||||
}
|
||||
|
||||
Object nmsStack = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, stack);
|
||||
|
||||
Object nbtTagCompound = nmsStack.getClass().getMethod("getTag").invoke(nmsStack);
|
||||
if (nbtTagCompound == null) return null;
|
||||
|
||||
Object entityTagCompound = nbtTagCompound.getClass().getMethod("getCompound", String.class).invoke(nbtTagCompound, "EntityTag");
|
||||
if (entityTagCompound == null) return null;
|
||||
|
||||
Object id = entityTagCompound.getClass().getMethod("getString", String.class).invoke(entityTagCompound, "id");
|
||||
if (id instanceof String) return (String) id;
|
||||
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
plugin.getLogger().severe("Failed to get NBTEntityID with reflection");
|
||||
plugin.debug("Failed to get NBTEntityID with reflection");
|
||||
plugin.debug(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack {@link ItemStack} (Spawn Egg) of which the Entity should be gotten
|
||||
* @return The {@link EntityType} the Spawn Egg will spawn or <b>null</b> if <i>nbtEntityID</i> is null
|
||||
*/
|
||||
public static EntityType getEntityTypeFromItemStack(ShopChest plugin, ItemStack stack) {
|
||||
if (Utils.getMajorVersion() == 8) {
|
||||
EntityType type = null;
|
||||
|
||||
for (EntityType entityType : EntityType.values()) {
|
||||
if (entityType.getTypeId() == stack.getDurability()) {
|
||||
type = entityType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
String nbtEntityID = getNBTEntityID(plugin, stack);
|
||||
|
||||
if (nbtEntityID == null) return null;
|
||||
|
||||
if (Utils.getMajorVersion() >= 11) {
|
||||
if (nbtEntityID.contains(":")) nbtEntityID = nbtEntityID.split(":")[1];
|
||||
return EntityType.fromName(nbtEntityID);
|
||||
}
|
||||
|
||||
switch (nbtEntityID) {
|
||||
case "PigZombie":
|
||||
return EntityType.PIG_ZOMBIE;
|
||||
case "CaveSpider":
|
||||
return EntityType.CAVE_SPIDER;
|
||||
case "LavaSlime":
|
||||
return EntityType.MAGMA_CUBE;
|
||||
case "MushroomCow":
|
||||
return EntityType.MUSHROOM_COW;
|
||||
case "EntityHorse":
|
||||
return EntityType.HORSE;
|
||||
case "PolarBear":
|
||||
return EntityType.POLAR_BEAR;
|
||||
case "Ozelot":
|
||||
return EntityType.OCELOT;
|
||||
default:
|
||||
return EntityType.valueOf(nbtEntityID.toUpperCase());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -182,7 +182,11 @@ public class Shop {
|
||||
doubleChest = false;
|
||||
}
|
||||
|
||||
if (Utils.getMajorVersion() < 13) {
|
||||
face = ((org.bukkit.material.Directional) chests[0].getData()).getFacing();
|
||||
} else {
|
||||
face = ((Directional) chests[0].getBlockData()).getFacing();
|
||||
}
|
||||
|
||||
String[] holoText = getHologramText();
|
||||
Location holoLocation = getHologramLocation(doubleChest, chests, face);
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import java.util.Map;
|
||||
@ -22,16 +23,23 @@ public class ItemUtils {
|
||||
|
||||
public static PotionType getPotionEffect(ItemStack itemStack) {
|
||||
if (itemStack.getItemMeta() instanceof PotionMeta) {
|
||||
if (Utils.getMajorVersion() < 9) {
|
||||
return Potion.fromItemStack(itemStack).getType();
|
||||
} else {
|
||||
return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isExtendedPotion(ItemStack itemStack) {
|
||||
if (itemStack.getItemMeta() instanceof PotionMeta) {
|
||||
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
||||
return potionMeta.getBasePotionData().isExtended();
|
||||
if (Utils.getMajorVersion() < 9) {
|
||||
return Potion.fromItemStack(itemStack).hasExtendedDuration();
|
||||
} else {
|
||||
return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().isExtended();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -4,6 +4,8 @@ import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
|
||||
import de.epiceric.shopchest.nms.CustomBookMeta;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -42,8 +44,16 @@ public class Utils {
|
||||
BookMeta bookMeta1 = (BookMeta) itemStack1.getItemMeta();
|
||||
BookMeta bookMeta2 = (BookMeta) itemStack2.getItemMeta();
|
||||
|
||||
if ((getMajorVersion() == 9 && getRevision() == 1) || getMajorVersion() == 8) {
|
||||
CustomBookMeta.Generation generation1 = CustomBookMeta.getGeneration(itemStack1);
|
||||
CustomBookMeta.Generation generation2 = CustomBookMeta.getGeneration(itemStack2);
|
||||
|
||||
if (generation1 == null) CustomBookMeta.setGeneration(itemStack1, CustomBookMeta.Generation.ORIGINAL);
|
||||
if (generation2 == null) CustomBookMeta.setGeneration(itemStack2, CustomBookMeta.Generation.ORIGINAL);
|
||||
} else {
|
||||
if (bookMeta1.getGeneration() == null) bookMeta1.setGeneration(BookMeta.Generation.ORIGINAL);
|
||||
if (bookMeta2.getGeneration() == null) bookMeta2.setGeneration(BookMeta.Generation.ORIGINAL);
|
||||
}
|
||||
|
||||
itemStack1.setItemMeta(bookMeta1);
|
||||
itemStack2.setItemMeta(bookMeta2);
|
||||
@ -66,7 +76,12 @@ public class Utils {
|
||||
|
||||
if (inventory instanceof PlayerInventory) {
|
||||
for (int i = 0; i < 37; i++) {
|
||||
if (i == 36) i = 40;
|
||||
if (i == 36) {
|
||||
if (getMajorVersion() < 9) {
|
||||
break;
|
||||
}
|
||||
i = 40;
|
||||
}
|
||||
inventoryItems.add(inventory.getItem(i));
|
||||
}
|
||||
} else {
|
||||
@ -96,7 +111,12 @@ public class Utils {
|
||||
|
||||
if (inventory instanceof PlayerInventory) {
|
||||
for (int i = 0; i < 37; i++) {
|
||||
if (i == 36) i = 40;
|
||||
if (i == 36) {
|
||||
if (getMajorVersion() < 9) {
|
||||
break;
|
||||
}
|
||||
i = 40;
|
||||
}
|
||||
|
||||
ItemStack item = inventory.getItem(i);
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
@ -137,6 +157,13 @@ public class Utils {
|
||||
* @return {@link ItemStack} in his main hand, or {@code null} if he doesn't hold one
|
||||
*/
|
||||
public static ItemStack getItemInMainHand(Player p) {
|
||||
if (getMajorVersion() < 9) {
|
||||
if (p.getItemInHand().getType() == Material.AIR)
|
||||
return null;
|
||||
else
|
||||
return p.getItemInHand();
|
||||
}
|
||||
|
||||
if (p.getInventory().getItemInMainHand().getType() == Material.AIR)
|
||||
return null;
|
||||
else
|
||||
@ -148,7 +175,9 @@ public class Utils {
|
||||
* @return {@link ItemStack} in his off hand, or {@code null} if he doesn't hold one or the server version is below 1.9
|
||||
*/
|
||||
public static ItemStack getItemInOffHand(Player p) {
|
||||
if (p.getInventory().getItemInOffHand().getType() == Material.AIR)
|
||||
if (getMajorVersion() < 9)
|
||||
return null;
|
||||
else if (p.getInventory().getItemInOffHand().getType() == Material.AIR)
|
||||
return null;
|
||||
else
|
||||
return p.getInventory().getItemInOffHand();
|
||||
@ -160,7 +189,9 @@ public class Utils {
|
||||
* if he doesn't have one in both hands
|
||||
*/
|
||||
public static ItemStack getPreferredItemInHand(Player p) {
|
||||
if (getItemInMainHand(p) != null)
|
||||
if (getMajorVersion() < 9)
|
||||
return getItemInMainHand(p);
|
||||
else if (getItemInMainHand(p) != null)
|
||||
return getItemInMainHand(p);
|
||||
else
|
||||
return getItemInOffHand(p);
|
||||
@ -171,14 +202,18 @@ public class Utils {
|
||||
* @return Whether a player has an axe in one of his hands
|
||||
*/
|
||||
public static boolean hasAxeInHand(Player p) {
|
||||
List<Material> axes = Arrays.asList(Material.WOODEN_AXE, Material.STONE_AXE, Material.IRON_AXE, Material.GOLDEN_AXE, Material.DIAMOND_AXE);
|
||||
List<String> axes;
|
||||
if (Utils.getMajorVersion() < 13)
|
||||
axes = Arrays.asList("WOOD_AXE", "STONE_AXE", "IRON_AXE", "GOLD_AXE", "DIAMOND_AXE");
|
||||
else
|
||||
axes = Arrays.asList("WOODEN_AXE", "STONE_AXE", "IRON_AXE", "GOLDEN_AXE", "DIAMOND_AXE");
|
||||
|
||||
ItemStack item = getItemInMainHand(p);
|
||||
if (item == null || !axes.contains(item.getType())) {
|
||||
if (item == null || !axes.contains(item.getType().toString())) {
|
||||
item = getItemInOffHand(p);
|
||||
}
|
||||
|
||||
return item != null && axes.contains(item.getType());
|
||||
return item != null && axes.contains(item.getType().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
1045
src/main/resources/lang/de_DE-legacy.lang
Normal file
1045
src/main/resources/lang/de_DE-legacy.lang
Normal file
File diff suppressed because it is too large
Load Diff
1292
src/main/resources/lang/en_US-legacy.lang
Normal file
1292
src/main/resources/lang/en_US-legacy.lang
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user