diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 2eec4f0eb..43cc02414 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -145,6 +145,18 @@ + + net.ess3 + 1_10_R1Provider + 2.0.1 + compile + + + org.bukkit + craftbukkit + + + diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 32823f5c0..e7b897330 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -42,6 +42,7 @@ import net.ess3.nms.updatedmeta.BasePotionDataProvider; import net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider; import net.ess3.nms.legacy.LegacySpawnEggProvider; import net.ess3.nms.legacy.LegacySpawnerProvider; +import net.ess3.nms.v1_10_R1.v1_10_R1SpawnEggProvider; import net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider; import net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider; import net.ess3.nms.v1_9_R1.v1_9_R1SpawnEggProvider; @@ -215,6 +216,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { ), "mob spawner").getProvider(); spawnEggProvider = new ProviderFactory<>(getLogger(), Arrays.asList( + v1_10_R1SpawnEggProvider.class, v1_9_R2SpawnEggProvider.class, v1_9_R1SpawnEggProvider.class, LegacySpawnEggProvider.class diff --git a/nms/1_10_R1Provider/pom.xml b/nms/1_10_R1Provider/pom.xml new file mode 100644 index 000000000..b949710de --- /dev/null +++ b/nms/1_10_R1Provider/pom.xml @@ -0,0 +1,35 @@ + + + + EssentialsXParent + net.ess3 + 2.0.1 + ../../pom.xml + + 4.0.0 + + 1_10_R1Provider + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + org.bukkit + craftbukkit + 1.10-R0.1-SNAPSHOT + provided + + + net.ess3 + NMSProvider + 2.0.1 + + + \ No newline at end of file diff --git a/nms/1_10_R1Provider/src/net/ess3/nms/v1_10_R1/SpawnEgg1_10_R1.java b/nms/1_10_R1Provider/src/net/ess3/nms/v1_10_R1/SpawnEgg1_10_R1.java new file mode 100644 index 000000000..cf1349fa3 --- /dev/null +++ b/nms/1_10_R1Provider/src/net/ess3/nms/v1_10_R1/SpawnEgg1_10_R1.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * This file is part of ASkyBlock. + *

+ * ASkyBlock is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * ASkyBlock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with ASkyBlock. If not, see . + *******************************************************************************/ +package net.ess3.nms.v1_10_R1; + +import net.minecraft.server.v1_10_R1.NBTTagCompound; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +/** + * Represents a spawn egg that can be used to spawn mobs. Only for V1.9 servers + * + * @author tastybento + */ +public class SpawnEgg1_10_R1 { + private EntityType type; + + public SpawnEgg1_10_R1(EntityType type) { + this.type = type; + } + + /** + * Get the type of entity this egg will spawn. + * + * @return The entity type. + */ + public EntityType getSpawnedType() { + return type; + } + + /** + * Set the type of entity this egg will spawn. + * + * @param type The entity type. + */ + public void setSpawnedType(EntityType type) { + if (type.isAlive()) { + this.type = type; + } + } + + @Override + public String toString() { + return "SPAWN EGG{" + getSpawnedType() + "}"; + } + + /** + * Get an ItemStack of one spawn egg + * @return ItemStack + */ + public ItemStack toItemStack() { + return toItemStack(1); + } + + /** + * Get an itemstack of spawn eggs + * @param amount + * @return ItemStack of spawn eggs + */ + @SuppressWarnings("deprecation") + public ItemStack toItemStack(int amount) { + ItemStack item = new ItemStack(Material.MONSTER_EGG, amount); + net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); + NBTTagCompound tagCompound = stack.getTag(); + if (tagCompound == null) { + tagCompound = new NBTTagCompound(); + } + NBTTagCompound id = new NBTTagCompound(); + id.setString("id", type.getName()); + tagCompound.set("EntityTag", id); + stack.setTag(tagCompound); + return CraftItemStack.asBukkitCopy(stack); + } + + /** + * Converts from an item stack to a spawn egg 1.9 + * @param item - ItemStack, quantity is disregarded + * @return SpawnEgg 1.9 + */ + public static SpawnEgg1_10_R1 fromItemStack(ItemStack item) throws IllegalArgumentException { + if (item == null) + throw new IllegalArgumentException("Item cannot be null"); + if (item.getType() != Material.MONSTER_EGG) + throw new IllegalArgumentException("Item is not a monster egg"); + net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); + NBTTagCompound tagCompound = stack.getTag(); + if (tagCompound != null) { + @SuppressWarnings("deprecation") + EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id")); + if (type != null) { + return new SpawnEgg1_10_R1(type); + } else { + throw new IllegalArgumentException("Unable to parse type from item"); + } + } else { + throw new IllegalArgumentException("Item is lacking tag compound"); + } + } +} + diff --git a/nms/1_10_R1Provider/src/net/ess3/nms/v1_10_R1/v1_10_R1SpawnEggProvider.java b/nms/1_10_R1Provider/src/net/ess3/nms/v1_10_R1/v1_10_R1SpawnEggProvider.java new file mode 100644 index 000000000..b15ae4c88 --- /dev/null +++ b/nms/1_10_R1Provider/src/net/ess3/nms/v1_10_R1/v1_10_R1SpawnEggProvider.java @@ -0,0 +1,22 @@ +package net.ess3.nms.v1_10_R1; + +import net.ess3.nms.SpawnEggProvider; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +public class v1_10_R1SpawnEggProvider extends SpawnEggProvider { + @Override + public ItemStack createEggItem(EntityType type) throws IllegalArgumentException { + return new SpawnEgg1_10_R1(type).toItemStack(); + } + + @Override + public EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException { + return SpawnEgg1_10_R1.fromItemStack(eggItem).getSpawnedType(); + } + + @Override + public String getHumanName() { + return "CraftBukkit 1.10 NMS-based provider"; + } +} diff --git a/pom.xml b/pom.xml index 3a42b071b..fe503402b 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ nms/LegacyProvider nms/1_9_R1Provider nms/1_9_R2Provider + nms/1_10_R1Provider