- Added support for version 1.12 of Minecraft. Probably.
This commit is contained in:
parent
9610958e28
commit
73e548bd16
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ hs_err_pid*
|
||||
|
||||
# Mac Files #
|
||||
**/.DS_Store
|
||||
/target/
|
||||
|
12
pom.xml
12
pom.xml
@ -17,6 +17,12 @@
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Bukkit API-->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
@ -24,6 +30,12 @@
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -1,14 +1,55 @@
|
||||
package nl.pim16aap2.armoredElytra;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.rit.sucy.EnchantPlugin;
|
||||
|
||||
public class ArmoredElytra extends EnchantPlugin implements Listener {
|
||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||
import nl.pim16aap2.armoredElytra.nms.V1_11_R1;
|
||||
import nl.pim16aap2.armoredElytra.nms.V1_12_R1;
|
||||
|
||||
public class ArmoredElytra extends EnchantPlugin implements Listener
|
||||
{
|
||||
private NBTEditor nbtEditor;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this);
|
||||
public void onEnable()
|
||||
{
|
||||
if (compatibleMCVer())
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
||||
} else {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft!");
|
||||
}
|
||||
}
|
||||
|
||||
// Check + initialize for the correct version of Minecraft.
|
||||
public boolean compatibleMCVer()
|
||||
{
|
||||
String version;
|
||||
|
||||
try
|
||||
{
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
} catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version.equals("v1_11_R1"))
|
||||
{
|
||||
nbtEditor = new V1_11_R1();
|
||||
|
||||
} else if (version.equals("v1_12_R1"))
|
||||
{
|
||||
nbtEditor = new V1_12_R1();
|
||||
}
|
||||
// Return true if compatible.
|
||||
return nbtEditor != null;
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.*;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||
|
||||
import com.rit.sucy.EnchantmentAPI;
|
||||
|
||||
@ -30,6 +32,7 @@ public class EventHandlers implements Listener {
|
||||
|
||||
private int DIAMONDS_TO_FULL = 3;
|
||||
private int LEATHER_TO_FULL = 4;
|
||||
private NBTEditor nbtEditor;
|
||||
private final ArmoredElytra plugin;
|
||||
private String[] allowedEnchantments = {"DURABILITY",
|
||||
"PROTECTION_FIRE",
|
||||
@ -38,12 +41,13 @@ public class EventHandlers implements Listener {
|
||||
"PROTECTION_ENVIRONMENTAL",
|
||||
"DIAMOND_ARMOR_ITEMS",
|
||||
"THORNS"};
|
||||
private String[] specialEnchantments = {"MENDING",
|
||||
"VANISHING_CURSE",
|
||||
"BINDING_CURSE"};
|
||||
private String[] specialEnchantments = {"MENDING",
|
||||
"VANISHING_CURSE",
|
||||
"BINDING_CURSE"};
|
||||
|
||||
public EventHandlers(ArmoredElytra plugin) {
|
||||
public EventHandlers(ArmoredElytra plugin, NBTEditor nbtEditor) {
|
||||
this.plugin = plugin;
|
||||
this.nbtEditor = nbtEditor;
|
||||
}
|
||||
|
||||
|
||||
@ -198,35 +202,9 @@ public class EventHandlers implements Listener {
|
||||
// Put the created item in the second slot of the anvil.
|
||||
if (result!=null) {
|
||||
if (anvilInventory.getItem(1).getType() == Material.DIAMOND_CHESTPLATE) {
|
||||
ItemMeta itemmeta = result.getItemMeta();
|
||||
itemmeta.setDisplayName(ChatColor.AQUA+"Armored Elytra");
|
||||
itemmeta.setLore(Arrays.asList("This is an armored Elytra."));
|
||||
result.setItemMeta(itemmeta);
|
||||
net.minecraft.server.v1_11_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(result);
|
||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||
NBTTagList modifiers = new NBTTagList();
|
||||
NBTTagCompound armor = new NBTTagCompound();
|
||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||
armor.set("Name", new NBTTagString("generic.armor"));
|
||||
armor.set("Amount", new NBTTagInt(8));
|
||||
armor.set("Operation", new NBTTagInt(0));
|
||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||
armor.set("Slot", new NBTTagString("chest"));
|
||||
modifiers.add(armor);
|
||||
NBTTagCompound armorTough = new NBTTagCompound();
|
||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||
armorTough.set("Amount", new NBTTagInt(2));
|
||||
armorTough.set("Operation", new NBTTagInt(0));
|
||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||
armorTough.set("Slot", new NBTTagString("chest"));
|
||||
modifiers.add(armorTough);
|
||||
compound.set("AttributeModifiers", modifiers);
|
||||
result = CraftItemStack.asBukkitCopy(nmsStack);
|
||||
result = nbtEditor.addNBTTags(result);
|
||||
}
|
||||
anvilInventory.setItem(2, result);
|
||||
anvilInventory.setItem(2, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package nl.pim16aap2.armoredElytra.nms;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface NBTEditor
|
||||
{
|
||||
public ItemStack addNBTTags(ItemStack item);
|
||||
}
|
50
src/main/java/nl/pim16aap2/armoredElytra/nms/V1_11_R1.java
Normal file
50
src/main/java/nl/pim16aap2/armoredElytra/nms/V1_11_R1.java
Normal file
@ -0,0 +1,50 @@
|
||||
package nl.pim16aap2.armoredElytra.nms;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagInt;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagList;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagString;
|
||||
|
||||
public class V1_11_R1 implements NBTEditor
|
||||
{
|
||||
|
||||
@Override
|
||||
public ItemStack addNBTTags(ItemStack item)
|
||||
{
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
itemmeta.setDisplayName(ChatColor.AQUA+"Armored Elytra");
|
||||
itemmeta.setLore(Arrays.asList("This is an armored Elytra."));
|
||||
item.setItemMeta(itemmeta);
|
||||
net.minecraft.server.v1_11_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||
NBTTagList modifiers = new NBTTagList();
|
||||
NBTTagCompound armor = new NBTTagCompound();
|
||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||
armor.set("Name", new NBTTagString("generic.armor"));
|
||||
armor.set("Amount", new NBTTagInt(8));
|
||||
armor.set("Operation", new NBTTagInt(0));
|
||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||
armor.set("Slot", new NBTTagString("chest"));
|
||||
modifiers.add(armor);
|
||||
NBTTagCompound armorTough = new NBTTagCompound();
|
||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||
armorTough.set("Amount", new NBTTagInt(2));
|
||||
armorTough.set("Operation", new NBTTagInt(0));
|
||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||
armorTough.set("Slot", new NBTTagString("chest"));
|
||||
modifiers.add(armorTough);
|
||||
compound.set("AttributeModifiers", modifiers);
|
||||
item = CraftItemStack.asBukkitCopy(nmsStack);
|
||||
return item;
|
||||
}
|
||||
}
|
49
src/main/java/nl/pim16aap2/armoredElytra/nms/V1_12_R1.java
Normal file
49
src/main/java/nl/pim16aap2/armoredElytra/nms/V1_12_R1.java
Normal file
@ -0,0 +1,49 @@
|
||||
package nl.pim16aap2.armoredElytra.nms;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagInt;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagList;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagString;
|
||||
|
||||
public class V1_12_R1 implements NBTEditor
|
||||
{
|
||||
@Override
|
||||
public ItemStack addNBTTags(ItemStack item)
|
||||
{
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
itemmeta.setDisplayName(ChatColor.AQUA+"Armored Elytra");
|
||||
itemmeta.setLore(Arrays.asList("This is an armored Elytra."));
|
||||
item.setItemMeta(itemmeta);
|
||||
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||
NBTTagList modifiers = new NBTTagList();
|
||||
NBTTagCompound armor = new NBTTagCompound();
|
||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||
armor.set("Name", new NBTTagString("generic.armor"));
|
||||
armor.set("Amount", new NBTTagInt(8));
|
||||
armor.set("Operation", new NBTTagInt(0));
|
||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||
armor.set("Slot", new NBTTagString("chest"));
|
||||
modifiers.add(armor);
|
||||
NBTTagCompound armorTough = new NBTTagCompound();
|
||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||
armorTough.set("Amount", new NBTTagInt(2));
|
||||
armorTough.set("Operation", new NBTTagInt(0));
|
||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||
armorTough.set("Slot", new NBTTagString("chest"));
|
||||
modifiers.add(armorTough);
|
||||
compound.set("AttributeModifiers", modifiers);
|
||||
item = CraftItemStack.asBukkitCopy(nmsStack);
|
||||
return item;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user