mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
[Untested] [Experimental] [Need @drtshock to fix build server] Fully support all versions of Spigot and CraftBukkit from 1.8+
This commit is contained in:
parent
e4f6bb363d
commit
8793add589
19 changed files with 376 additions and 94 deletions
|
@ -28,8 +28,22 @@
|
||||||
<showDeprecation>false</showDeprecation>
|
<showDeprecation>false</showDeprecation>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>BOSEconomy</groupId>
|
<groupId>BOSEconomy</groupId>
|
||||||
|
@ -77,7 +91,45 @@
|
||||||
<groupId>net.milkbowl.vault</groupId>
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
<artifactId>Vault</artifactId>
|
<artifactId>Vault</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.5.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>NMSProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>BlockMetaProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>1_8_R1Provider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>LegacyProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
|
@ -30,13 +30,14 @@ import com.earth2me.essentials.textreader.IText;
|
||||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
import com.earth2me.essentials.utils.SpawnerUtil;
|
import com.earth2me.essentials.utils.SpawnerProviderFactory;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import net.ess3.api.*;
|
import net.ess3.api.*;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.ISettings;
|
import net.ess3.api.ISettings;
|
||||||
|
import net.ess3.nms.SpawnerProvider;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
@ -69,8 +70,6 @@ import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
|
@ -96,7 +95,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
private transient EssentialsTimer timer;
|
private transient EssentialsTimer timer;
|
||||||
private final transient List<String> vanishedPlayers = new ArrayList<>();
|
private final transient List<String> vanishedPlayers = new ArrayList<>();
|
||||||
private transient Method oldGetOnlinePlayers;
|
private transient Method oldGetOnlinePlayers;
|
||||||
private transient SpawnerUtil spawnerUtil;
|
private transient SpawnerProvider spawnerProvider;
|
||||||
|
|
||||||
public Essentials() {
|
public Essentials() {
|
||||||
}
|
}
|
||||||
|
@ -186,7 +185,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
execTimer.mark("Init(Worth/ItemDB)");
|
execTimer.mark("Init(Worth/ItemDB)");
|
||||||
jails = new Jails(this);
|
jails = new Jails(this);
|
||||||
confList.add(jails);
|
confList.add(jails);
|
||||||
spawnerUtil = new SpawnerUtil(this);
|
spawnerProvider = new SpawnerProviderFactory(this).getProvider();
|
||||||
reload();
|
reload();
|
||||||
} catch (YAMLException exception) {
|
} catch (YAMLException exception) {
|
||||||
if (pm.getPlugin("EssentialsUpdate") != null) {
|
if (pm.getPlugin("EssentialsUpdate") != null) {
|
||||||
|
@ -746,8 +745,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpawnerUtil getSpawnerUtil() {
|
public SpawnerProvider getSpawnerProvider() {
|
||||||
return spawnerUtil;
|
return spawnerProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EssentialsWorldListener implements Listener, Runnable {
|
private static class EssentialsWorldListener implements Listener, Runnable {
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class EssentialsBlockListener implements Listener {
|
||||||
final BlockState blockState = event.getBlockPlaced().getState();
|
final BlockState blockState = event.getBlockPlaced().getState();
|
||||||
if (blockState instanceof CreatureSpawner) {
|
if (blockState instanceof CreatureSpawner) {
|
||||||
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
||||||
final EntityType type = ess.getSpawnerUtil().getEntityType(event.getItemInHand());
|
final EntityType type = ess.getSpawnerProvider().getEntityType(event.getItemInHand());
|
||||||
if (type != null && Mob.fromBukkitType(type) != null) {
|
if (type != null && Mob.fromBukkitType(type) != null) {
|
||||||
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
|
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
|
||||||
spawner.setSpawnedType(type);
|
spawner.setSpawnedType(type);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.earth2me.essentials.api.IWarps;
|
||||||
import com.earth2me.essentials.metrics.Metrics;
|
import com.earth2me.essentials.metrics.Metrics;
|
||||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
import com.earth2me.essentials.register.payment.Methods;
|
||||||
import com.earth2me.essentials.utils.SpawnerUtil;
|
import net.ess3.nms.SpawnerProvider;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -98,5 +98,5 @@ public interface IEssentials extends Plugin {
|
||||||
|
|
||||||
Iterable<User> getOnlineUsers();
|
Iterable<User> getOnlineUsers();
|
||||||
|
|
||||||
SpawnerUtil getSpawnerUtil();
|
SpawnerProvider getSpawnerProvider();
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
|
||||||
retval.setAmount(mat.getMaxStackSize());
|
retval.setAmount(mat.getMaxStackSize());
|
||||||
if (mat == Material.MOB_SPAWNER) {
|
if (mat == Material.MOB_SPAWNER) {
|
||||||
try {
|
try {
|
||||||
ess.getSpawnerUtil().setEntityType(retval, EntityType.fromId(metaData));
|
ess.getSpawnerProvider().setEntityType(retval, EntityType.fromId(metaData));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.earth2me.essentials.utils;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.IEssentials;
|
||||||
|
import net.ess3.nms.SpawnerProvider;
|
||||||
|
import net.ess3.nms.blockmeta.BlockMetaSpawnerProvider;
|
||||||
|
import net.ess3.nms.legacy.LegacyProvider;
|
||||||
|
import net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SpawnerProviderFactory {
|
||||||
|
private IEssentials ess;
|
||||||
|
|
||||||
|
public SpawnerProviderFactory(IEssentials ess) {
|
||||||
|
this.ess = ess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnerProvider getProvider() {
|
||||||
|
List<SpawnerProvider> availableProviders = Arrays.asList(
|
||||||
|
new BlockMetaSpawnerProvider(),
|
||||||
|
new v1_8_R1SpawnerProvider(),
|
||||||
|
new LegacyProvider()
|
||||||
|
);
|
||||||
|
SpawnerProvider finalProvider = null;
|
||||||
|
for (SpawnerProvider provider : availableProviders) {
|
||||||
|
finalProvider = provider;
|
||||||
|
if (finalProvider.tryProvider()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert finalProvider != null;
|
||||||
|
ess.getLogger().info("Using " + finalProvider.getHumanName() + " as spawner provider.");
|
||||||
|
return finalProvider;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,80 +0,0 @@
|
||||||
package com.earth2me.essentials.utils;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import net.ess3.api.IEssentials;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.CreatureSpawner;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SpawnerUtil {
|
|
||||||
private boolean useMeta;
|
|
||||||
private Map<EntityType, String> entityToDisplayName = ImmutableMap.<EntityType, String>builder()
|
|
||||||
.put(EntityType.CAVE_SPIDER, "Cave Spider")
|
|
||||||
.put(EntityType.PIG_ZOMBIE, "Zombie Pigman")
|
|
||||||
.put(EntityType.MAGMA_CUBE, "Magma Cube")
|
|
||||||
.put(EntityType.ENDER_DRAGON, "Ender Dragon")
|
|
||||||
.put(EntityType.MUSHROOM_COW, "Mooshroom")
|
|
||||||
.put(EntityType.SNOWMAN, "Snow Golem")
|
|
||||||
.put(EntityType.OCELOT, "Ocelot")
|
|
||||||
.put(EntityType.IRON_GOLEM, "Iron Golem")
|
|
||||||
.put(EntityType.WITHER, "Wither")
|
|
||||||
.put(EntityType.HORSE, "Horse")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public SpawnerUtil(IEssentials ess) {
|
|
||||||
try {
|
|
||||||
ItemStack is = new ItemStack(Material.MOB_SPAWNER, 1);
|
|
||||||
ItemMeta meta = is.getItemMeta();
|
|
||||||
useMeta = meta instanceof BlockStateMeta;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
useMeta = false;
|
|
||||||
}
|
|
||||||
if (useMeta) {
|
|
||||||
ess.getLogger().info("Using BlockStateMeta for spawners");
|
|
||||||
} else {
|
|
||||||
ess.getLogger().warning("Using legacy item data for spawners");
|
|
||||||
ess.getLogger().warning(ChatColor.RED + "UPGRADE TO 1.8.3 OR HIGHER FOR WORKING SPAWNERS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack setEntityType(ItemStack is, EntityType type) throws IllegalArgumentException {
|
|
||||||
if (useMeta) {
|
|
||||||
// Supported in 1.8.3-R0.1-SNAPSHOT and above
|
|
||||||
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
|
|
||||||
BlockState bs = bsm.getBlockState();
|
|
||||||
((CreatureSpawner) bs).setSpawnedType(type);
|
|
||||||
bsm.setBlockState(bs);
|
|
||||||
is.setItemMeta(bsm);
|
|
||||||
} else {
|
|
||||||
// Legacy behavior
|
|
||||||
is.setDurability(type.getTypeId());
|
|
||||||
}
|
|
||||||
ItemMeta meta = is.getItemMeta();
|
|
||||||
String displayName;
|
|
||||||
if (entityToDisplayName.containsKey(type)) {
|
|
||||||
displayName = entityToDisplayName.get(type);
|
|
||||||
} else {
|
|
||||||
displayName = type.getName();
|
|
||||||
}
|
|
||||||
meta.setDisplayName(ChatColor.RESET + displayName + " Spawner");
|
|
||||||
is.setItemMeta(meta);
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityType getEntityType(ItemStack is) {
|
|
||||||
if (useMeta) {
|
|
||||||
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
|
|
||||||
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
|
|
||||||
return bs.getSpawnedType();
|
|
||||||
} else {
|
|
||||||
return EntityType.fromId((int) is.getData().getData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,8 +19,6 @@ EssentialsX is almost a completely drop-in replacement for Essentials. However,
|
||||||
|
|
||||||
* **EssentialsX requires Java 7.**
|
* **EssentialsX requires Java 7.**
|
||||||
|
|
||||||
* **EssentialsX requires Spigot/CraftBukkit 1.8, 1.8.3+ recommended (for spawner support)**
|
|
||||||
|
|
||||||
Building
|
Building
|
||||||
--------
|
--------
|
||||||
To build with Maven, use the command
|
To build with Maven, use the command
|
||||||
|
|
1
nms/1_8_R1Provider/.gitignore
vendored
Normal file
1
nms/1_8_R1Provider/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
craftbukkit-*.jar
|
1
nms/1_8_R1Provider/README.md
Normal file
1
nms/1_8_R1Provider/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Put a 1.8 Spigot/CraftBukkit JAR with filename `craftbukkit-1.8-R0.1-SNAPSHOT.jar` in `lib/org/bukkit/craftbukkit/1.8-R0.1-SNAPSHOT`.
|
36
nms/1_8_R1Provider/pom.xml
Normal file
36
nms/1_8_R1Provider/pom.xml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?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>EssentialsParent</artifactId>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>1_8_R1Provider</artifactId>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>project.local</id>
|
||||||
|
<name>local repo</name>
|
||||||
|
<url>file:${project.basedir}/lib</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>NMSProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,45 @@
|
||||||
|
package net.ess3.nms.v1_8_R1;
|
||||||
|
|
||||||
|
import net.ess3.nms.SpawnerProvider;
|
||||||
|
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class v1_8_R1SpawnerProvider extends SpawnerProvider {
|
||||||
|
@Override
|
||||||
|
public ItemStack setEntityType(ItemStack is, EntityType type) {
|
||||||
|
net.minecraft.server.v1_8_R1.ItemStack itemStack;
|
||||||
|
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
|
||||||
|
itemStack = CraftItemStack.asNMSCopy(craftStack);
|
||||||
|
NBTTagCompound tag = itemStack.getTag();
|
||||||
|
if (tag == null) {
|
||||||
|
tag = new NBTTagCompound();
|
||||||
|
itemStack.setTag(tag);
|
||||||
|
}
|
||||||
|
if (!tag.hasKey("BlockEntityTag")) {
|
||||||
|
tag.set("BlockEntityTag", new NBTTagCompound());
|
||||||
|
}
|
||||||
|
tag = itemStack.getTag().getCompound("BlockEntityTag");
|
||||||
|
tag.setString("EntityId", type.getName());
|
||||||
|
return CraftItemStack.asCraftMirror(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityType getEntityType(ItemStack is) {
|
||||||
|
net.minecraft.server.v1_8_R1.ItemStack itemStack;
|
||||||
|
CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
|
||||||
|
itemStack = CraftItemStack.asNMSCopy(craftStack);
|
||||||
|
NBTTagCompound tag = itemStack.getTag();
|
||||||
|
if (tag == null || !tag.hasKey("BlockEntityTag")) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
String name = tag.getCompound("BlockEntityTag").getString("EntityId");
|
||||||
|
return EntityType.fromName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHumanName() {
|
||||||
|
return "CraftBukkit 1.8 NMS-based provider";
|
||||||
|
}
|
||||||
|
}
|
35
nms/BlockMetaProvider/pom.xml
Normal file
35
nms/BlockMetaProvider/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>EssentialsParent</artifactId>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>BlockMetaProvider</artifactId>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>NMSProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.8.7-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,45 @@
|
||||||
|
package net.ess3.nms.blockmeta;
|
||||||
|
|
||||||
|
import net.ess3.nms.SpawnerProvider;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.CreatureSpawner;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class BlockMetaSpawnerProvider extends SpawnerProvider {
|
||||||
|
@Override
|
||||||
|
public ItemStack setEntityType(ItemStack is, EntityType type) {
|
||||||
|
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
|
||||||
|
BlockState bs = bsm.getBlockState();
|
||||||
|
((CreatureSpawner) bs).setSpawnedType(type);
|
||||||
|
bsm.setBlockState(bs);
|
||||||
|
is.setItemMeta(bsm);
|
||||||
|
// Legacy behavior
|
||||||
|
is.setDurability(type.getTypeId());
|
||||||
|
ItemMeta meta = is.getItemMeta();
|
||||||
|
String displayName;
|
||||||
|
if (entityToDisplayName.containsKey(type)) {
|
||||||
|
displayName = entityToDisplayName.get(type);
|
||||||
|
} else {
|
||||||
|
displayName = type.getName();
|
||||||
|
}
|
||||||
|
meta.setDisplayName(ChatColor.RESET + displayName + " Spawner");
|
||||||
|
is.setItemMeta(meta);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityType getEntityType(ItemStack is) {
|
||||||
|
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
|
||||||
|
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
|
||||||
|
return bs.getSpawnedType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHumanName() {
|
||||||
|
return "1.8.3+ BlockStateMeta provider";
|
||||||
|
}
|
||||||
|
}
|
22
nms/LegacyProvider/pom.xml
Normal file
22
nms/LegacyProvider/pom.xml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?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>EssentialsParent</artifactId>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>LegacyProvider</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<artifactId>NMSProvider</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,34 @@
|
||||||
|
package net.ess3.nms.legacy;
|
||||||
|
|
||||||
|
import net.ess3.nms.SpawnerProvider;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class LegacyProvider extends SpawnerProvider {
|
||||||
|
@Override
|
||||||
|
public ItemStack setEntityType(ItemStack is, EntityType type) {
|
||||||
|
is.getData().setData((byte) type.getTypeId());
|
||||||
|
ItemMeta meta = is.getItemMeta();
|
||||||
|
String displayName;
|
||||||
|
if (entityToDisplayName.containsKey(type)) {
|
||||||
|
displayName = entityToDisplayName.get(type);
|
||||||
|
} else {
|
||||||
|
displayName = type.getName();
|
||||||
|
}
|
||||||
|
meta.setDisplayName(ChatColor.RESET + displayName + " Spawner");
|
||||||
|
is.setItemMeta(meta);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityType getEntityType(ItemStack is) {
|
||||||
|
return EntityType.fromId((int) is.getData().getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHumanName() {
|
||||||
|
return "legacy item data provider";
|
||||||
|
}
|
||||||
|
}
|
14
nms/NMSProvider/pom.xml
Normal file
14
nms/NMSProvider/pom.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?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>EssentialsParent</artifactId>
|
||||||
|
<groupId>net.ess3</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>NMSProvider</artifactId>
|
||||||
|
</project>
|
38
nms/NMSProvider/src/net/ess3/nms/SpawnerProvider.java
Normal file
38
nms/NMSProvider/src/net/ess3/nms/SpawnerProvider.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package net.ess3.nms;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class SpawnerProvider {
|
||||||
|
protected Map<EntityType, String> entityToDisplayName = ImmutableMap.<EntityType, String>builder()
|
||||||
|
.put(EntityType.CAVE_SPIDER, "Cave Spider")
|
||||||
|
.put(EntityType.PIG_ZOMBIE, "Zombie Pigman")
|
||||||
|
.put(EntityType.MAGMA_CUBE, "Magma Cube")
|
||||||
|
.put(EntityType.ENDER_DRAGON, "Ender Dragon")
|
||||||
|
.put(EntityType.MUSHROOM_COW, "Mooshroom")
|
||||||
|
.put(EntityType.SNOWMAN, "Snow Golem")
|
||||||
|
.put(EntityType.OCELOT, "Ocelot")
|
||||||
|
.put(EntityType.IRON_GOLEM, "Iron Golem")
|
||||||
|
.put(EntityType.WITHER, "Wither")
|
||||||
|
.put(EntityType.HORSE, "Horse")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public abstract ItemStack setEntityType(ItemStack is, EntityType type) throws IllegalArgumentException;
|
||||||
|
public abstract EntityType getEntityType(ItemStack is) throws IllegalArgumentException;
|
||||||
|
public abstract String getHumanName();
|
||||||
|
|
||||||
|
public boolean tryProvider() {
|
||||||
|
try {
|
||||||
|
EntityType type = EntityType.CREEPER;
|
||||||
|
ItemStack is = setEntityType(new ItemStack(Material.MOB_SPAWNER), type);
|
||||||
|
EntityType readType = getEntityType(is);
|
||||||
|
return type == readType;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
pom.xml
8
pom.xml
|
@ -28,7 +28,7 @@
|
||||||
<url>http://repo.ess3.net/content/groups/public</url>
|
<url>http://repo.ess3.net/content/groups/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>bukkit-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
@ -41,6 +41,10 @@
|
||||||
<module>EssentialsProtect</module>
|
<module>EssentialsProtect</module>
|
||||||
<module>EssentialsSpawn</module>
|
<module>EssentialsSpawn</module>
|
||||||
<module>EssentialsXMPP</module>
|
<module>EssentialsXMPP</module>
|
||||||
|
<module>nms/NMSProvider</module>
|
||||||
|
<module>nms/BlockMetaProvider</module>
|
||||||
|
<module>nms/1_8_R1Provider</module>
|
||||||
|
<module>nms/LegacyProvider</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -48,6 +52,7 @@
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.8.7-R0.1-SNAPSHOT</version>
|
<version>1.8.7-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
@ -59,6 +64,7 @@
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.12.2</version>
|
<version>1.12.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue