Re-add support for Minecraft 1.8 - 1.12.2

This commit is contained in:
Eric 2018-07-25 16:43:23 +02:00
parent 3d60b5b49c
commit 4cb59b18de
15 changed files with 3853 additions and 195 deletions

View File

@ -151,6 +151,14 @@ public class ShopChest extends JavaPlugin {
} }
switch (Utils.getServerVersion()) { 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": case "v1_13_R1":
break; break;
default: default:
@ -353,7 +361,10 @@ public class ShopChest extends JavaPlugin {
getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this); getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this);
getServer().getPluginManager().registerEvents(new NotifyPlayerOnJoinListener(this), this); getServer().getPluginManager().registerEvents(new NotifyPlayerOnJoinListener(this), this);
getServer().getPluginManager().registerEvents(new ChestProtectListener(this, worldGuard), this); getServer().getPluginManager().registerEvents(new ChestProtectListener(this, worldGuard), this);
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
if (!Utils.getServerVersion().equals("v1_8_R1")) {
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
}
if (hasWorldGuard()) { if (hasWorldGuard()) {
getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this); getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this);

View File

@ -5,6 +5,8 @@ import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.sql.Database; import de.epiceric.shopchest.sql.Database;
import de.epiceric.shopchest.utils.ItemUtils; import de.epiceric.shopchest.utils.ItemUtils;
import de.epiceric.shopchest.utils.ShopUpdater; import de.epiceric.shopchest.utils.ShopUpdater;
import de.epiceric.shopchest.utils.Utils;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -543,14 +545,16 @@ public class Config {
langConfig = new LanguageConfiguration(plugin, showMessages); langConfig = new LanguageConfiguration(plugin, showMessages);
File langFolder = new File(plugin.getDataFolder(), "lang"); File langFolder = new File(plugin.getDataFolder(), "lang");
if (!(new File(langFolder, "en_US.lang")).exists()) String legacy = Utils.getMajorVersion() < 13 ? "-legacy" : "";
plugin.saveResource("lang/en_US.lang", false);
if (!(new File(langFolder, "de_DE.lang")).exists()) if (!(new File(langFolder, "en_US" + legacy + ".lang")).exists())
plugin.saveResource("lang/de_DE.lang", false); plugin.saveResource("lang/en_US" + legacy + ".lang", false);
if (!(new File(langFolder, "de_DE" + legacy + ".lang")).exists())
plugin.saveResource("lang/de_DE" + legacy + ".lang", false);
File langConfigFile = new File(langFolder, languageFile + ".lang"); File langConfigFile = new File(langFolder, languageFile + legacy + ".lang");
File langDefaultFile = new File(langFolder, "en_US.lang"); File langDefaultFile = new File(langFolder, "en_US" + legacy + ".lang");
if (!langConfigFile.exists()) { if (!langConfigFile.exists()) {
if (!langDefaultFile.exists()) { if (!langDefaultFile.exists()) {
@ -558,8 +562,8 @@ public class Config {
Reader r = getTextResource("lang/" + langConfigFile.getName(), showMessages); Reader r = getTextResource("lang/" + langConfigFile.getName(), showMessages);
if (r == null) { if (r == null) {
r = getTextResource("lang/en_US.lang", showMessages); r = getTextResource("lang/en_US" + legacy + ".lang", showMessages);
if (showMessages) plugin.getLogger().info("Using locale \"en_US\" (Streamed from jar file)"); if (showMessages) plugin.getLogger().info("Using locale \"en_US" + legacy + "\" (Streamed from jar file)");
} else { } else {
if (showMessages) if (showMessages)
plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\" (Streamed from jar file)"); 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 { } else {
try { try {
langConfig.load(langDefaultFile); 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) { } catch (IOException | InvalidConfigurationException e) {
if (showMessages) { if (showMessages) {
plugin.getLogger().warning("Using default language values"); plugin.getLogger().warning("Using default language values");

View File

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

View File

@ -5,10 +5,16 @@ import org.bukkit.Material;
public class ItemName { public class ItemName {
private Material material; private Material material;
private int subId;
private String localizedName; private String localizedName;
public ItemName(Material material, String localizedName) { public ItemName(Material material, String localizedName) {
this(material, 0, localizedName);
}
public ItemName(Material material, int subId, String localizedName) {
this.material = material; this.material = material;
this.subId = subId;
this.localizedName = localizedName; this.localizedName = localizedName;
} }
@ -19,6 +25,13 @@ public class ItemName {
return material; return material;
} }
/**
* @return Sub ID linked to the name
*/
public int getSubId() {
return subId;
}
/** /**
* @return Name linked to the item * @return Name linked to the item
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import pl.islandworld.api.IslandWorldApi; import pl.islandworld.api.IslandWorldApi;
import us.talabrek.ultimateskyblock.api.IslandInfo; import us.talabrek.ultimateskyblock.api.IslandInfo;
@ -129,142 +130,164 @@ 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) @EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) { public void onBlockPlace(BlockPlaceEvent e) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final Block b = e.getBlockPlaced(); 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(); }
org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();
Chest c = (Chest) b.getState();
if (data.getType() != Type.SINGLE) { Block b2;
BlockFace neighborFacing = getNeighborFacing(data.getType(), data.getFacing());
Block b2 = b.getRelative(neighborFacing);
if (shopUtils.isShop(b.getLocation()) || shopUtils.isShop(b2.getLocation())) {
final Shop shop = shopUtils.getShop(b2.getLocation());
plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
boolean externalPluginsAllowed = true;
if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, WorldGuardShopFlag.CREATE_SHOP);
}
if (externalPluginsAllowed && plugin.hasTowny() && Config.enableTownyIntegration) {
TownBlock townBlock = TownyUniverse.getTownBlock(b.getLocation());
if (townBlock != null) {
try {
Town town = townBlock.getTown();
for (Resident resident : town.getResidents()) {
if (resident.getName().equals(p.getName())) {
if (resident.isMayor()) {
externalPluginsAllowed = (Config.townyShopPlotsMayor.contains(townBlock.getType().name()));
} else if (resident.isKing()) {
externalPluginsAllowed = (Config.townyShopPlotsKing.contains(townBlock.getType().name()));
} else {
externalPluginsAllowed = (Config.townyShopPlotsResidents.contains(townBlock.getType().name()));
}
break;
}
}
} catch (Exception ex) {
plugin.debug(ex);
}
}
}
if (externalPluginsAllowed && plugin.hasPlotSquared() && Config.enablePlotsquaredIntegration) {
com.intellectualcrafters.plot.object.Location loc =
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
externalPluginsAllowed = Utils.isFlagAllowedOnPlot(loc.getOwnedPlot(), PlotSquaredShopFlag.CREATE_SHOP, p);
}
if (externalPluginsAllowed && plugin.hasUSkyBlock() && Config.enableUSkyblockIntegration) {
IslandInfo islandInfo = plugin.getUSkyBlock().getIslandInfo(b.getLocation());
if (islandInfo != null) {
externalPluginsAllowed = islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName());
}
}
if (externalPluginsAllowed && plugin.hasASkyBlock() && Config.enableASkyblockIntegration) {
Island island = ASkyBlockAPI.getInstance().getIslandAt(b.getLocation());
if (island != null) {
if (island.getOwner() == null) {
externalPluginsAllowed = island.getMembers().contains(p.getUniqueId());
} else {
externalPluginsAllowed = island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId());
}
}
}
if (externalPluginsAllowed && plugin.hasIslandWorld() && Config.enableIslandWorldIntegration && IslandWorldApi.isInitialized()) {
if (b.getWorld().getName().equals(IslandWorldApi.getIslandWorld().getName())) {
externalPluginsAllowed = IslandWorldApi.canBuildOnLocation(p, b.getLocation(), true);
}
}
if (externalPluginsAllowed && plugin.hasGriefPrevention() && Config.enableGriefPreventionIntegration) {
Claim claim = plugin.getGriefPrevention().dataStore.getClaimAt(b.getLocation(), false, null);
if (claim != null) {
externalPluginsAllowed = claim.allowContainers(p) == null;
}
}
if (externalPluginsAllowed || p.hasPermission(Permissions.EXTEND_PROTECTED)) {
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.EXTEND_OTHER)) {
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
@Override
public void onResult(Void result) {
newShop.create(true);
shopUtils.addShop(newShop, true);
plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
for (Player player : shop.getLocation().getWorld().getPlayers()) {
shopUtils.updateShops(player, true);
}
}
});
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
}
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_OTHERS));
}
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
}
}
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) {
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());
plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
boolean externalPluginsAllowed = true;
if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, WorldGuardShopFlag.CREATE_SHOP);
}
if (externalPluginsAllowed && plugin.hasTowny() && Config.enableTownyIntegration) {
TownBlock townBlock = TownyUniverse.getTownBlock(b.getLocation());
if (townBlock != null) {
try {
Town town = townBlock.getTown();
for (Resident resident : town.getResidents()) {
if (resident.getName().equals(p.getName())) {
if (resident.isMayor()) {
externalPluginsAllowed = (Config.townyShopPlotsMayor.contains(townBlock.getType().name()));
} else if (resident.isKing()) {
externalPluginsAllowed = (Config.townyShopPlotsKing.contains(townBlock.getType().name()));
} else {
externalPluginsAllowed = (Config.townyShopPlotsResidents.contains(townBlock.getType().name()));
}
break;
}
}
} catch (Exception ex) {
plugin.debug(ex);
}
}
}
if (externalPluginsAllowed && plugin.hasPlotSquared() && Config.enablePlotsquaredIntegration) {
com.intellectualcrafters.plot.object.Location loc =
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
externalPluginsAllowed = Utils.isFlagAllowedOnPlot(loc.getOwnedPlot(), PlotSquaredShopFlag.CREATE_SHOP, p);
}
if (externalPluginsAllowed && plugin.hasUSkyBlock() && Config.enableUSkyblockIntegration) {
IslandInfo islandInfo = plugin.getUSkyBlock().getIslandInfo(b.getLocation());
if (islandInfo != null) {
externalPluginsAllowed = islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName());
}
}
if (externalPluginsAllowed && plugin.hasASkyBlock() && Config.enableASkyblockIntegration) {
Island island = ASkyBlockAPI.getInstance().getIslandAt(b.getLocation());
if (island != null) {
if (island.getOwner() == null) {
externalPluginsAllowed = island.getMembers().contains(p.getUniqueId());
} else {
externalPluginsAllowed = island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId());
}
}
}
if (externalPluginsAllowed && plugin.hasIslandWorld() && Config.enableIslandWorldIntegration && IslandWorldApi.isInitialized()) {
if (b.getWorld().getName().equals(IslandWorldApi.getIslandWorld().getName())) {
externalPluginsAllowed = IslandWorldApi.canBuildOnLocation(p, b.getLocation(), true);
}
}
if (externalPluginsAllowed && plugin.hasGriefPrevention() && Config.enableGriefPreventionIntegration) {
Claim claim = plugin.getGriefPrevention().dataStore.getClaimAt(b.getLocation(), false, null);
if (claim != null) {
externalPluginsAllowed = claim.allowContainers(p) == null;
}
}
if (externalPluginsAllowed || p.hasPermission(Permissions.EXTEND_PROTECTED)) {
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.EXTEND_OTHER)) {
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
@Override
public void onResult(Void result) {
newShop.create(true);
shopUtils.addShop(newShop, true);
plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
for (Player player : shop.getLocation().getWorld().getPlayers()) {
shopUtils.updateShops(player, true);
}
}
});
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
}
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_OTHERS));
}
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
}
} }
} }

View File

@ -47,20 +47,29 @@ public class ArmorStandWrapper {
.newInstance(nmsWorld, location.getX(), location.getY(), location.getZ()); .newInstance(nmsWorld, location.getX(), location.getY(), location.getZ());
if (customName != null && !customName.trim().isEmpty()) { if (customName != null && !customName.trim().isEmpty()) {
Object chatMessage = chatMessageClass.getConstructor(String.class, Object[].class) if (Utils.getMajorVersion() < 13) {
.newInstance(customName, new Object[0]); 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("setCustomName", iChatBaseComponentClass).invoke(entity, chatMessage);
}
entityArmorStandClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, true); entityArmorStandClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, true);
} }
entityArmorStandClass.getMethod("setNoGravity", 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); entityArmorStandClass.getMethod("setInvisible", boolean.class).invoke(entity, true);
// Adds the entity to some lists so it can call interact events // Adds the entity to some lists so it can call interact events
// It will also automatically load/unload it when far away // It will also automatically load/unload it when far away
if (interactable) { if (interactable) {
Method addEntityMethod = worldServerClass.getDeclaredMethod("b", entityClass); Method addEntityMethod = worldServerClass.getDeclaredMethod(Utils.getMajorVersion() == 8 ? "a" : "b", entityClass);
addEntityMethod.setAccessible(true); addEntityMethod.setAccessible(true);
addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity); addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity);
} }
@ -117,13 +126,24 @@ public class ArmorStandWrapper {
try { try {
if (customName != null && !customName.isEmpty()) { if (customName != null && !customName.isEmpty()) {
Object chatMessage = chatMessageClass.getConstructor(String.class, Object[].class) if (Utils.getMajorVersion() < 13) {
.newInstance(customName, new Object[0]); 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("setCustomName", iChatBaseComponentClass).invoke(entity, chatMessage);
}
entityClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, true); entityClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, true);
} else { } else {
entityClass.getMethod("setCustomName", String.class).invoke(entity, ""); 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); entityClass.getMethod("setCustomNameVisible", boolean.class).invoke(entity, false);
} }
@ -150,7 +170,7 @@ public class ArmorStandWrapper {
try { try {
// Removes the entity from the lists it was added to for interaction // 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.setAccessible(true);
addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity); addEntityMethod.invoke(worldServerClass.cast(nmsWorld), entity);
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {

View 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);
}
}
}

View File

@ -17,11 +17,17 @@ public class JsonBuilder {
private Class<?> iChatBaseComponentClass = Utils.getNMSClass("IChatBaseComponent"); private Class<?> iChatBaseComponentClass = Utils.getNMSClass("IChatBaseComponent");
private Class<?> packetPlayOutChatClass = Utils.getNMSClass("PacketPlayOutChat"); 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) { public JsonBuilder(ShopChest plugin, String text, String hoverText, String downloadLink) {
this.plugin = plugin; 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 iChatBaseComponentClass, packetPlayOutChatClass, chatSerializerClass
}; };

View 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());
}
}
}

View File

@ -182,7 +182,11 @@ public class Shop {
doubleChest = false; doubleChest = false;
} }
face = ((Directional) chests[0].getBlockData()).getFacing(); if (Utils.getMajorVersion() < 13) {
face = ((org.bukkit.material.Directional) chests[0].getData()).getFacing();
} else {
face = ((Directional) chests[0].getBlockData()).getFacing();
}
String[] holoText = getHologramText(); String[] holoText = getHologramText();
Location holoLocation = getHologramLocation(doubleChest, chests, face); Location holoLocation = getHologramLocation(doubleChest, chests, face);

View File

@ -5,6 +5,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import java.util.Map; import java.util.Map;
@ -22,7 +23,11 @@ public class ItemUtils {
public static PotionType getPotionEffect(ItemStack itemStack) { public static PotionType getPotionEffect(ItemStack itemStack) {
if (itemStack.getItemMeta() instanceof PotionMeta) { if (itemStack.getItemMeta() instanceof PotionMeta) {
return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType(); if (Utils.getMajorVersion() < 9) {
return Potion.fromItemStack(itemStack).getType();
} else {
return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType();
}
} }
return null; return null;
@ -30,8 +35,11 @@ public class ItemUtils {
public static boolean isExtendedPotion(ItemStack itemStack) { public static boolean isExtendedPotion(ItemStack itemStack) {
if (itemStack.getItemMeta() instanceof PotionMeta) { if (itemStack.getItemMeta() instanceof PotionMeta) {
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); if (Utils.getMajorVersion() < 9) {
return potionMeta.getBasePotionData().isExtended(); return Potion.fromItemStack(itemStack).hasExtendedDuration();
} else {
return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().isExtended();
}
} }
return false; return false;

View File

@ -4,6 +4,8 @@ import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.nms.CustomBookMeta;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
@ -42,8 +44,16 @@ public class Utils {
BookMeta bookMeta1 = (BookMeta) itemStack1.getItemMeta(); BookMeta bookMeta1 = (BookMeta) itemStack1.getItemMeta();
BookMeta bookMeta2 = (BookMeta) itemStack2.getItemMeta(); BookMeta bookMeta2 = (BookMeta) itemStack2.getItemMeta();
if (bookMeta1.getGeneration() == null) bookMeta1.setGeneration(BookMeta.Generation.ORIGINAL); if ((getMajorVersion() == 9 && getRevision() == 1) || getMajorVersion() == 8) {
if (bookMeta2.getGeneration() == null) bookMeta2.setGeneration(BookMeta.Generation.ORIGINAL); 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); itemStack1.setItemMeta(bookMeta1);
itemStack2.setItemMeta(bookMeta2); itemStack2.setItemMeta(bookMeta2);
@ -66,7 +76,12 @@ public class Utils {
if (inventory instanceof PlayerInventory) { if (inventory instanceof PlayerInventory) {
for (int i = 0; i < 37; i++) { 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)); inventoryItems.add(inventory.getItem(i));
} }
} else { } else {
@ -96,7 +111,12 @@ public class Utils {
if (inventory instanceof PlayerInventory) { if (inventory instanceof PlayerInventory) {
for (int i = 0; i < 37; i++) { 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); ItemStack item = inventory.getItem(i);
if (item == null || item.getType() == Material.AIR) { 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 * @return {@link ItemStack} in his main hand, or {@code null} if he doesn't hold one
*/ */
public static ItemStack getItemInMainHand(Player p) { 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) if (p.getInventory().getItemInMainHand().getType() == Material.AIR)
return null; return null;
else 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 * @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) { 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; return null;
else else
return p.getInventory().getItemInOffHand(); return p.getInventory().getItemInOffHand();
@ -160,7 +189,9 @@ public class Utils {
* if he doesn't have one in both hands * if he doesn't have one in both hands
*/ */
public static ItemStack getPreferredItemInHand(Player p) { public static ItemStack getPreferredItemInHand(Player p) {
if (getItemInMainHand(p) != null) if (getMajorVersion() < 9)
return getItemInMainHand(p);
else if (getItemInMainHand(p) != null)
return getItemInMainHand(p); return getItemInMainHand(p);
else else
return getItemInOffHand(p); return getItemInOffHand(p);
@ -171,14 +202,18 @@ public class Utils {
* @return Whether a player has an axe in one of his hands * @return Whether a player has an axe in one of his hands
*/ */
public static boolean hasAxeInHand(Player p) { 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); ItemStack item = getItemInMainHand(p);
if (item == null || !axes.contains(item.getType())) { if (item == null || !axes.contains(item.getType().toString())) {
item = getItemInOffHand(p); item = getItemInOffHand(p);
} }
return item != null && axes.contains(item.getType()); return item != null && axes.contains(item.getType().toString());
} }
/** /**

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff