mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-07-02 10:43:51 +00:00
1.9.4 spawn egg support
This commit is contained in:
parent
7c1a0ed719
commit
d0ea32dfa1
|
@ -126,6 +126,24 @@
|
||||||
<artifactId>1_9_R1Provider</artifactId>
|
<artifactId>1_9_R1Provider</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>2.0.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>1_9_R2Provider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
@ -45,6 +45,7 @@ import net.ess3.nms.legacy.LegacySpawnerProvider;
|
||||||
import net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider;
|
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_8_R2.v1_8_R2SpawnerProvider;
|
||||||
import net.ess3.nms.v1_9_R1.v1_9_R1SpawnEggProvider;
|
import net.ess3.nms.v1_9_R1.v1_9_R1SpawnEggProvider;
|
||||||
|
import net.ess3.nms.v1_9_R2.v1_9_R2SpawnEggProvider;
|
||||||
import net.ess3.providers.ProviderFactory;
|
import net.ess3.providers.ProviderFactory;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -214,6 +215,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
), "mob spawner").getProvider();
|
), "mob spawner").getProvider();
|
||||||
spawnEggProvider = new ProviderFactory<>(getLogger(),
|
spawnEggProvider = new ProviderFactory<>(getLogger(),
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
|
v1_9_R2SpawnEggProvider.class,
|
||||||
v1_9_R1SpawnEggProvider.class,
|
v1_9_R1SpawnEggProvider.class,
|
||||||
LegacySpawnEggProvider.class
|
LegacySpawnEggProvider.class
|
||||||
), "spawn egg").getProvider();
|
), "spawn egg").getProvider();
|
||||||
|
|
35
nms/1_9_R2Provider/pom.xml
Normal file
35
nms/1_9_R2Provider/pom.xml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?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_R2Provider</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.4-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>NMSProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
115
nms/1_9_R2Provider/src/net/ess3/nms/v1_9_R2/SpawnEgg1_9_R2.java
Normal file
115
nms/1_9_R2Provider/src/net/ess3/nms/v1_9_R2/SpawnEgg1_9_R2.java
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* This file is part of ASkyBlock.
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* <p>
|
||||||
|
* 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_R2;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_9_R2.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_R2 {
|
||||||
|
private EntityType type;
|
||||||
|
|
||||||
|
public SpawnEgg1_9_R2(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_9_R2.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_R2 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_9_R2.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_R2(type);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unable to parse type from item");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Item is lacking tag compound");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package net.ess3.nms.v1_9_R2;
|
||||||
|
|
||||||
|
import net.ess3.nms.SpawnEggProvider;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class v1_9_R2SpawnEggProvider extends SpawnEggProvider {
|
||||||
|
@Override
|
||||||
|
public ItemStack createEggItem(EntityType type) throws IllegalArgumentException {
|
||||||
|
return new SpawnEgg1_9_R2(type).toItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException {
|
||||||
|
return SpawnEgg1_9_R2.fromItemStack(eggItem).getSpawnedType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHumanName() {
|
||||||
|
return "CraftBukkit 1.9 NMS-based provider";
|
||||||
|
}
|
||||||
|
}
|
1
pom.xml
1
pom.xml
|
@ -47,6 +47,7 @@
|
||||||
<module>nms/1_8_R2Provider</module>
|
<module>nms/1_8_R2Provider</module>
|
||||||
<module>nms/LegacyProvider</module>
|
<module>nms/LegacyProvider</module>
|
||||||
<module>nms/1_9_R1Provider</module>
|
<module>nms/1_9_R1Provider</module>
|
||||||
|
<module>nms/1_9_R2Provider</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
Loading…
Reference in a new issue