Support Minecraft 1.13

Drops support for older Minecraft verions (1.8 - 1.12.2)
This commit is contained in:
Eric 2018-07-23 17:51:04 +02:00
parent d7f464da2f
commit 94a51373b5
19 changed files with 3251 additions and 3222 deletions

30
pom.xml
View File

@ -145,7 +145,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -226,28 +226,14 @@
</distributionManagement>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>.</targetPath>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>.</targetPath>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>

View File

@ -151,14 +151,7 @@ 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:
debug("Server version not officially supported: " + Utils.getServerVersion() + "!");
@ -360,10 +353,7 @@ 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);
}
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
if (hasWorldGuard()) {
getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this);

View File

@ -1,13 +1,13 @@
package de.epiceric.shopchest.language;
import de.epiceric.shopchest.nms.CustomBookMeta;
import org.bukkit.inventory.meta.BookMeta;
public class BookGenerationName {
private String localizedName;
private CustomBookMeta.Generation generation;
private BookMeta.Generation generation;
public BookGenerationName(CustomBookMeta.Generation generation, String localizedName) {
public BookGenerationName(BookMeta.Generation generation, String localizedName) {
this.generation = generation;
this.localizedName = localizedName;
}
@ -15,7 +15,7 @@ public class BookGenerationName {
/**
* @return Generation linked to the name
*/
public CustomBookMeta.Generation getGeneration() {
public BookMeta.Generation getGeneration() {
return generation;
}

View File

@ -5,18 +5,10 @@ import org.bukkit.Material;
public class ItemName {
private Material material;
private int subID;
private String localizedName;
public ItemName(Material material, int subID, String localizedName) {
this.material = material;
this.subID = subID;
this.localizedName = localizedName;
}
public ItemName(Material material, String localizedName) {
this.material = material;
this.subID = 0;
this.localizedName = localizedName;
}
@ -27,13 +19,6 @@ 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

View File

@ -1,13 +1,13 @@
package de.epiceric.shopchest.language;
import org.bukkit.potion.PotionType;
import org.bukkit.potion.PotionEffectType;
public class PotionEffectName {
private PotionType effect;
private PotionEffectType effect;
private String localizedName;
public PotionEffectName(PotionType effect, String localizedName) {
public PotionEffectName(PotionEffectType effect, String localizedName) {
this.effect = effect;
this.localizedName = localizedName;
}
@ -15,7 +15,7 @@ public class PotionEffectName {
/**
* @return Potion Effect linked to the name
*/
public PotionType getEffect() {
public PotionEffectType getEffect() {
return effect;
}

View File

@ -25,7 +25,6 @@ import de.epiceric.shopchest.external.WorldGuardShopFlag;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.Message;
import de.epiceric.shopchest.language.Replacement;
import de.epiceric.shopchest.nms.CustomBookMeta;
import de.epiceric.shopchest.nms.Hologram;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType;
@ -65,7 +64,6 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.scheduler.BukkitRunnable;
import pl.islandworld.api.IslandWorldApi;
import us.talabrek.ultimateskyblock.api.IslandInfo;
@ -346,6 +344,9 @@ public class ShopInteractListener implements Listener {
Shop shop = shopUtils.getShop(b.getLocation());
if (shop != null || ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) {
switch (ClickType.getPlayerClickType(p).getClickType()) {
case CREATE:
break;
case INFO:
e.setCancelled(true);
@ -868,22 +869,8 @@ public class ShopInteractListener implements Listener {
}
if (type == Material.WRITTEN_BOOK) {
BookMeta meta = (BookMeta) shop.getProduct().getItemMeta();
CustomBookMeta.Generation generation = CustomBookMeta.Generation.TATTERED;
if ((Utils.getMajorVersion() == 9 && Utils.getRevision() == 1) || Utils.getMajorVersion() == 8) {
CustomBookMeta.Generation gen = CustomBookMeta.getGeneration(shop.getProduct());
generation = (gen == null ? CustomBookMeta.Generation.ORIGINAL : gen);
} else if (Utils.getMajorVersion() >= 10) {
if (meta.hasGeneration()) {
generation = CustomBookMeta.Generation.valueOf(meta.getGeneration().toString());
} else {
generation = CustomBookMeta.Generation.ORIGINAL;
}
}
bookGenerationString = LanguageUtils.getMessage(Message.SHOP_INFO_BOOK_GENERATION,
new Replacement(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(generation)));
new Replacement(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(shop.getProduct())));
}
String musicDiscName = LanguageUtils.getMusicDiscName(type);

View File

@ -64,6 +64,7 @@ public class WorldGuardListener implements Listener {
return query.testState(location, localPlayer, WorldGuardShopFlag.CREATE_SHOP);
case REMOVE:
case INFO:
case OPEN:
return true;
}
} else {

View File

@ -49,18 +49,13 @@ public class ArmorStandWrapper {
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("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((Utils.getMajorVersion() == 8 ? "a" : "b"), entityClass);
Method addEntityMethod = worldServerClass.getDeclaredMethod("b", entityClass);
addEntityMethod.setAccessible(true);
addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity);
}
@ -147,7 +142,7 @@ public class ArmorStandWrapper {
try {
// Removes the entity from the lists it was added to for interaction
Method addEntityMethod = worldServerClass.getDeclaredMethod((Utils.getMajorVersion() == 8 ? "b" : "c"), entityClass);
Method addEntityMethod = worldServerClass.getDeclaredMethod("c", entityClass);
addEntityMethod.setAccessible(true);
addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity);
} catch (ReflectiveOperationException e) {

View File

@ -1,90 +0,0 @@
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);
}
}
}

View File

@ -17,22 +17,16 @@ public class JsonBuilder {
private Class<?> iChatBaseComponentClass = Utils.getNMSClass("IChatBaseComponent");
private Class<?> packetPlayOutChatClass = Utils.getNMSClass("PacketPlayOutChat");
private Class<?> chatSerializerClass;
private Class<?> chatSerializerClass = Utils.getNMSClass("IChatBaseComponent$ChatSerializer");;
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[] {
Class<?>[] requiredClasses = new Class<?>[] {
iChatBaseComponentClass, packetPlayOutChatClass, chatSerializerClass
};
for (Class c : requiredClasses) {
for (Class<?> c : requiredClasses) {
if (c == null) {
plugin.debug("Failed to instantiate JsonBuilder: Could not find all required classes");
return;

View File

@ -1,89 +0,0 @@
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());
}
}
}

View File

@ -216,9 +216,9 @@ public class Shop {
requirements.put(HologramFormat.Requirement.BUY_PRICE, getBuyPrice());
requirements.put(HologramFormat.Requirement.SELL_PRICE, getSellPrice());
requirements.put(HologramFormat.Requirement.HAS_POTION_EFFECT, ItemUtils.getPotionEffect(getProduct()) != null);
requirements.put(HologramFormat.Requirement.IS_MUSIC_DISC, ItemUtils.isMusicDisc(getProduct()));
requirements.put(HologramFormat.Requirement.IS_MUSIC_DISC, getProduct().getType().isRecord());
requirements.put(HologramFormat.Requirement.IS_POTION_EXTENDED, ItemUtils.isExtendedPotion(getProduct()));
requirements.put(HologramFormat.Requirement.IS_WRITTEN_BOOK, ItemUtils.getBookGeneration(getProduct()) != null);
requirements.put(HologramFormat.Requirement.IS_WRITTEN_BOOK, getProduct().getType() == Material.WRITTEN_BOOK);
requirements.put(HologramFormat.Requirement.ADMIN_SHOP, getShopType() == ShopType.ADMIN);
requirements.put(HologramFormat.Requirement.NORMAL_SHOP, getShopType() == ShopType.NORMAL);
requirements.put(HologramFormat.Requirement.IN_STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct()));
@ -235,7 +235,7 @@ public class Shop {
placeholders.put(Placeholder.SELL_PRICE, getSellPrice());
placeholders.put(Placeholder.POTION_EFFECT, LanguageUtils.getPotionEffectName(getProduct()));
placeholders.put(Placeholder.MUSIC_TITLE, LanguageUtils.getMusicDiscName(getProduct().getType()));
placeholders.put(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(ItemUtils.getBookGeneration(getProduct())));
placeholders.put(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(getProduct()));
placeholders.put(Placeholder.STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct()));
placeholders.put(Placeholder.MAX_STACK, getProduct().getMaxStackSize());
placeholders.put(Placeholder.CHEST_SPACE, Utils.getFreeSpaceForItem(getInventoryHolder().getInventory(), getProduct()));

View File

@ -1,16 +1,12 @@
package de.epiceric.shopchest.utils;
import com.google.common.collect.Lists;
import de.epiceric.shopchest.nms.CustomBookMeta;
import org.bukkit.Material;
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.List;
import java.util.Map;
public class ItemUtils {
@ -26,11 +22,7 @@ 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 ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType();
}
return null;
@ -38,36 +30,13 @@ public class ItemUtils {
public static boolean isExtendedPotion(ItemStack itemStack) {
if (itemStack.getItemMeta() instanceof PotionMeta) {
if (Utils.getMajorVersion() >= 9) {
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
return potionMeta.getBasePotionData().isExtended();
} else {
Potion potion = Potion.fromItemStack(itemStack);
return potion.hasExtendedDuration();
}
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
return potionMeta.getBasePotionData().isExtended();
}
return false;
}
public static boolean isMusicDisc(ItemStack itemStack) {
List<Material> musicDiscMaterials = Lists.newArrayList(
Material.GOLD_RECORD, Material.GREEN_RECORD, Material.RECORD_3, Material.RECORD_4,
Material.RECORD_5, Material.RECORD_6, Material.RECORD_7, Material.RECORD_8,
Material.RECORD_9, Material.RECORD_10, Material.RECORD_11, Material.RECORD_12
);
return musicDiscMaterials.contains(itemStack.getType());
}
public static CustomBookMeta.Generation getBookGeneration(ItemStack itemStack) {
if (itemStack.getType() == Material.WRITTEN_BOOK) {
return CustomBookMeta.getGeneration(itemStack);
}
return null;
}
/**
* Get the {@link ItemStack} from a String
* @param item Serialized ItemStack e.g. {@code "STONE"} or {@code "STONE:1"}

View File

@ -51,7 +51,7 @@ public class UpdateChecker {
return UpdateCheckerResult.TRUE;
}
} catch (IOException e) {
} catch (Exception e) {
plugin.debug("Failed to check for updates");
plugin.debug(e);
return UpdateCheckerResult.ERROR;

View File

@ -4,7 +4,6 @@ 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;
@ -43,17 +42,8 @@ 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 (getMajorVersion() >= 10) {
if (bookMeta1.getGeneration() == null) bookMeta1.setGeneration(BookMeta.Generation.ORIGINAL);
if (bookMeta2.getGeneration() == null) bookMeta2.setGeneration(BookMeta.Generation.ORIGINAL);
}
if (bookMeta1.getGeneration() == null) bookMeta1.setGeneration(BookMeta.Generation.ORIGINAL);
if (bookMeta2.getGeneration() == null) bookMeta2.setGeneration(BookMeta.Generation.ORIGINAL);
itemStack1.setItemMeta(bookMeta1);
itemStack2.setItemMeta(bookMeta2);
@ -75,14 +65,10 @@ public class Utils {
ArrayList<ItemStack> inventoryItems = new ArrayList<>();
if (inventory instanceof PlayerInventory) {
if (getMajorVersion() >= 9) {
inventoryItems.add(inventory.getItem(40));
}
for (int i = 0; i < 36; i++) {
for (int i = 0; i < 37; i++) {
if (i == 36) i = 40;
inventoryItems.add(inventory.getItem(i));
}
} else {
for (int i = 0; i < inventory.getSize(); i++) {
inventoryItems.add(inventory.getItem(i));
@ -109,7 +95,9 @@ public class Utils {
HashMap<Integer, Integer> slotFree = new HashMap<>();
if (inventory instanceof PlayerInventory) {
for (int i = 0; i < 36; i++) {
for (int i = 0; i < 37; i++) {
if (i == 36) i = 40;
ItemStack item = inventory.getItem(i);
if (item == null || item.getType() == Material.AIR) {
slotFree.put(i, itemStack.getMaxStackSize());
@ -121,19 +109,6 @@ public class Utils {
}
}
}
if (getMajorVersion() >= 9) {
ItemStack item = inventory.getItem(40);
if (item == null || item.getType() == Material.AIR) {
slotFree.put(40, itemStack.getMaxStackSize());
} else {
if (isItemSimilar(item, itemStack)) {
int amountInSlot = item.getAmount();
int amountToFullStack = itemStack.getMaxStackSize() - amountInSlot;
slotFree.put(40, amountToFullStack);
}
}
}
} else {
for (int i = 0; i < inventory.getSize(); i++) {
ItemStack item = inventory.getItem(i);
@ -162,17 +137,10 @@ 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();
} else {
if (p.getInventory().getItemInMainHand().getType() == Material.AIR)
return null;
else
return p.getInventory().getItemInMainHand();
}
if (p.getInventory().getItemInMainHand().getType() == Material.AIR)
return null;
else
return p.getInventory().getItemInMainHand();
}
/**
@ -180,14 +148,10 @@ 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 (getMajorVersion() < 9) {
if (p.getInventory().getItemInOffHand().getType() == Material.AIR)
return null;
} else {
if (p.getInventory().getItemInOffHand().getType() == Material.AIR)
return null;
else
return p.getInventory().getItemInOffHand();
}
else
return p.getInventory().getItemInOffHand();
}
/**
@ -196,14 +160,10 @@ public class Utils {
* if he doesn't have one in both hands
*/
public static ItemStack getPreferredItemInHand(Player p) {
if (getMajorVersion() < 9) {
if (getItemInMainHand(p) != null)
return getItemInMainHand(p);
} else {
if (getItemInMainHand(p) != null)
return getItemInMainHand(p);
else
return getItemInOffHand(p);
}
else
return getItemInOffHand(p);
}
/**
@ -211,7 +171,7 @@ 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.WOOD_AXE, Material.STONE_AXE, Material.IRON_AXE, Material.GOLD_AXE, Material.DIAMOND_AXE);
List<Material> axes = Arrays.asList(Material.WOODEN_AXE, Material.STONE_AXE, Material.IRON_AXE, Material.GOLDEN_AXE, Material.DIAMOND_AXE);
ItemStack item = getItemInMainHand(p);
if (item == null || !axes.contains(item.getType())) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ website: ${project.url}
description: Create your own nice-looking chest shops and sell your stuff to other players!
softdepend: [WorldGuard, Towny, AuthMe, PlotSquared, uSkyBlock, ASkyBlock, IslandWorld, GriefPrevention, AreaShop, Multiverse-Core, MultiWorld]
depend: [Vault]
api-version: 1.13
permissions:
shopchest.*: