mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-02 05:21:52 +01:00
Add spawn egg NMS for 1.9
This commit is contained in:
parent
767abe83f9
commit
65f2051e87
@ -121,6 +121,12 @@
|
|||||||
<version>2.0.1</version>
|
<version>2.0.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>1_9_R1SpawnEggProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
|||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import com.earth2me.essentials.utils.StringUtil;
|
import com.earth2me.essentials.utils.StringUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
|
import net.ess3.nms.v1_9_R1.SpawnEgg1_9;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.FireworkEffect;
|
import org.bukkit.FireworkEffect;
|
||||||
@ -145,11 +146,17 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
|
|||||||
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
||||||
}
|
}
|
||||||
} else if (mat == Material.MONSTER_EGG) {
|
} else if (mat == Material.MONSTER_EGG) {
|
||||||
|
EntityType type;
|
||||||
try {
|
try {
|
||||||
retval = new SpawnEgg(EntityType.fromId(metaData)).toItemStack();
|
type = EntityType.fromId(metaData);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs.");
|
throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs.");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
retval = new SpawnEgg1_9(type).toItemStack();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
retval = new SpawnEgg(type).toItemStack();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
retval.setDurability(metaData);
|
retval.setDurability(metaData);
|
||||||
}
|
}
|
||||||
|
30
nms/1_9_R1SpawnEggProvider/pom.xml
Normal file
30
nms/1_9_R1SpawnEggProvider/pom.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>EssentialsXParent</artifactId>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>1_9_R1SpawnEggProvider</artifactId>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.9-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,119 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*******************************************************************************/
|
||||||
|
package net.ess3.nms.v1_9_R1;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_9_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_9 {
|
||||||
|
private EntityType type;
|
||||||
|
|
||||||
|
public SpawnEgg1_9(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "SPAWN EGG{" + getSpawnedType() + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnEgg1_9 clone() {
|
||||||
|
return (SpawnEgg1_9) this.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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_9_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_9 fromItemStack(ItemStack item) {
|
||||||
|
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_9_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_9(type);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
pom.xml
1
pom.xml
@ -47,6 +47,7 @@
|
|||||||
<module>nms/1_8_R1Provider</module>
|
<module>nms/1_8_R1Provider</module>
|
||||||
<module>nms/1_8_R2Provider</module>
|
<module>nms/1_8_R2Provider</module>
|
||||||
<module>nms/LegacyProvider</module>
|
<module>nms/LegacyProvider</module>
|
||||||
|
<module>nms/1_9_R1SpawnEggProvider</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
Loading…
Reference in New Issue
Block a user