- Added support for version 1.12 of Minecraft. Probably.
This commit is contained in:
parent
9610958e28
commit
73e548bd16
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,4 +22,5 @@
|
|||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
# Mac Files #
|
# Mac Files #
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
|
/target/
|
||||||
|
12
pom.xml
12
pom.xml
@ -17,6 +17,12 @@
|
|||||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.12.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<!--Bukkit API-->
|
<!--Bukkit API-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
@ -24,6 +30,12 @@
|
|||||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.12-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -1,14 +1,55 @@
|
|||||||
package nl.pim16aap2.armoredElytra;
|
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.Bukkit;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import com.rit.sucy.EnchantPlugin;
|
import com.rit.sucy.EnchantPlugin;
|
||||||
|
|
||||||
|
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 {
|
public class ArmoredElytra extends EnchantPlugin implements Listener
|
||||||
|
{
|
||||||
|
private NBTEditor nbtEditor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable()
|
||||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this);
|
{
|
||||||
|
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 org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import net.minecraft.server.v1_11_R1.*;
|
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;
|
import com.rit.sucy.EnchantmentAPI;
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ public class EventHandlers implements Listener {
|
|||||||
|
|
||||||
private int DIAMONDS_TO_FULL = 3;
|
private int DIAMONDS_TO_FULL = 3;
|
||||||
private int LEATHER_TO_FULL = 4;
|
private int LEATHER_TO_FULL = 4;
|
||||||
|
private NBTEditor nbtEditor;
|
||||||
private final ArmoredElytra plugin;
|
private final ArmoredElytra plugin;
|
||||||
private String[] allowedEnchantments = {"DURABILITY",
|
private String[] allowedEnchantments = {"DURABILITY",
|
||||||
"PROTECTION_FIRE",
|
"PROTECTION_FIRE",
|
||||||
@ -38,12 +41,13 @@ public class EventHandlers implements Listener {
|
|||||||
"PROTECTION_ENVIRONMENTAL",
|
"PROTECTION_ENVIRONMENTAL",
|
||||||
"DIAMOND_ARMOR_ITEMS",
|
"DIAMOND_ARMOR_ITEMS",
|
||||||
"THORNS"};
|
"THORNS"};
|
||||||
private String[] specialEnchantments = {"MENDING",
|
private String[] specialEnchantments = {"MENDING",
|
||||||
"VANISHING_CURSE",
|
"VANISHING_CURSE",
|
||||||
"BINDING_CURSE"};
|
"BINDING_CURSE"};
|
||||||
|
|
||||||
public EventHandlers(ArmoredElytra plugin) {
|
public EventHandlers(ArmoredElytra plugin, NBTEditor nbtEditor) {
|
||||||
this.plugin = plugin;
|
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.
|
// Put the created item in the second slot of the anvil.
|
||||||
if (result!=null) {
|
if (result!=null) {
|
||||||
if (anvilInventory.getItem(1).getType() == Material.DIAMOND_CHESTPLATE) {
|
if (anvilInventory.getItem(1).getType() == Material.DIAMOND_CHESTPLATE) {
|
||||||
ItemMeta itemmeta = result.getItemMeta();
|
result = nbtEditor.addNBTTags(result);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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