- Final clean up.

This commit is contained in:
Pim van der Loos 2017-09-06 15:56:55 +02:00
parent cbc0fd4b79
commit 52c391d025
5 changed files with 4 additions and 46 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>nl.pim16aap2</groupId> <groupId>nl.pim16aap2</groupId>
<artifactId>ArmoredElytra</artifactId> <artifactId>ArmoredElytra</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>

View File

@ -4,9 +4,6 @@ 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 com.rit.sucy.EnchantmentAPI;
import nl.pim16aap2.armoredElytra.enchantments.DiamondArmor;
public class ArmoredElytra extends EnchantPlugin implements Listener { public class ArmoredElytra extends EnchantPlugin implements Listener {
@ -14,10 +11,4 @@ public class ArmoredElytra extends EnchantPlugin implements Listener {
public void onEnable() { public void onEnable() {
Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this); Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this);
} }
// TODO: Remove this after updating elytras on my server.
@Override
public void registerEnchantments() {
EnchantmentAPI.registerCustomEnchantment(new DiamondArmor());
}
} }

View File

@ -47,7 +47,6 @@ public class EventHandlers implements Listener {
} }
// Clear the anvil's inventory (destroy all the items in all 3 slots (second slot is not emptied, when repairing you can safely give multiple items)). // Clear the anvil's inventory (destroy all the items in all 3 slots (second slot is not emptied, when repairing you can safely give multiple items)).
public void cleanAnvil(AnvilInventory anvilInventory){ public void cleanAnvil(AnvilInventory anvilInventory){
anvilInventory.getItem(0).setAmount(0); anvilInventory.getItem(0).setAmount(0);
@ -56,7 +55,6 @@ public class EventHandlers implements Listener {
} }
// Check if the enchantment is allowed on elytras. // Check if the enchantment is allowed on elytras.
public boolean isAllowedEnchantment(Enchantment enchant) { public boolean isAllowedEnchantment(Enchantment enchant) {
for (String s : allowedEnchantments) { for (String s : allowedEnchantments) {
@ -68,7 +66,6 @@ public class EventHandlers implements Listener {
} }
// Check if the enchantment is "special", i.e. cannot be enchanted by the EnchantmentAPI. // Check if the enchantment is "special", i.e. cannot be enchanted by the EnchantmentAPI.
public boolean isSpecialEnchantment(Enchantment enchant) { public boolean isSpecialEnchantment(Enchantment enchant) {
for (String s : specialEnchantments) { for (String s : specialEnchantments) {
@ -80,7 +77,6 @@ public class EventHandlers implements Listener {
} }
// Check if the elytra being checked is an armored one. // Check if the elytra being checked is an armored one.
public boolean isArmoredElytra(ItemStack elytra) { public boolean isArmoredElytra(ItemStack elytra) {
if (elytra.hasItemMeta() && elytra.getType() == Material.ELYTRA) if (elytra.hasItemMeta() && elytra.getType() == Material.ELYTRA)
@ -92,12 +88,10 @@ public class EventHandlers implements Listener {
} }
// Copy enchants of 2 items to one item. // Copy enchants of 2 items to one item.
public ItemStack addEnchants(ItemStack itemOne, ItemStack itemTwo, Player p) { public ItemStack addEnchants(ItemStack itemOne, ItemStack itemTwo, Player p) {
// Create the resulting item and apply the diamond armor tier enchantment to it. // Create the resulting item and apply the diamond armor tier enchantment to it.
ItemStack result = itemOne.clone(); ItemStack result = itemOne.clone();
// Get the enchantments of the first and second item in the anvil. // Get the enchantments of the first and second item in the anvil.
Map<Enchantment, Integer> enchantments0 = itemOne.getEnchantments(); Map<Enchantment, Integer> enchantments0 = itemOne.getEnchantments();
Map<Enchantment, Integer> enchantments1 = itemTwo.getEnchantments(); Map<Enchantment, Integer> enchantments1 = itemTwo.getEnchantments();
@ -106,7 +100,6 @@ public class EventHandlers implements Listener {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemTwo.getItemMeta(); EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemTwo.getItemMeta();
enchantments1 = meta.getStoredEnchants(); enchantments1 = meta.getStoredEnchants();
} }
// Copy enchantments from item1 to result. // Copy enchantments from item1 to result.
if (enchantments1!=null) { if (enchantments1!=null) {
for (Map.Entry<Enchantment, Integer> entry : enchantments1.entrySet()) { for (Map.Entry<Enchantment, Integer> entry : enchantments1.entrySet()) {
@ -133,12 +126,10 @@ public class EventHandlers implements Listener {
} }
} }
} }
return result; return result;
} }
// Copy enchants of 2 items to one item. // Copy enchants of 2 items to one item.
public ItemStack repairItem(ItemStack one, ItemStack two) { public ItemStack repairItem(ItemStack one, ItemStack two) {
// Create the resulting item. // Create the resulting item.
@ -154,7 +145,6 @@ public class EventHandlers implements Listener {
} }
// Handle the anvil related parts. // Handle the anvil related parts.
@EventHandler @EventHandler
public void onInventoryClick(InventoryClickEvent e) { public void onInventoryClick(InventoryClickEvent e) {
@ -176,8 +166,7 @@ public class EventHandlers implements Listener {
// Clean the anvil's inventory after transferring the items. // Clean the anvil's inventory after transferring the items.
cleanAnvil(anvilInventory); cleanAnvil(anvilInventory);
} }
} }
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
@ -260,7 +249,6 @@ public class EventHandlers implements Listener {
} }
// Because the armored elytra doesn't actually give any armor, the damage received by players wearing an armored elytra is calculated here. // Because the armored elytra doesn't actually give any armor, the damage received by players wearing an armored elytra is calculated here.
@EventHandler @EventHandler
public void onPlayerDamage (EntityDamageEvent e) { public void onPlayerDamage (EntityDamageEvent e) {
@ -270,12 +258,11 @@ public class EventHandlers implements Listener {
if (p.getInventory().getChestplate().getType() == Material.ELYTRA && isArmoredElytra(p.getInventory().getChestplate())) { if (p.getInventory().getChestplate().getType() == Material.ELYTRA && isArmoredElytra(p.getInventory().getChestplate())) {
DamageCause cause = e.getCause(); DamageCause cause = e.getCause();
if (cause!=DamageCause.DROWNING && cause!=DamageCause.STARVATION && cause!=DamageCause.SUFFOCATION && if (cause!=DamageCause.DROWNING && cause!=DamageCause.STARVATION && cause!=DamageCause.SUFFOCATION &&
cause!=DamageCause.SUICIDE && cause!=DamageCause.FLY_INTO_WALL && cause!=DamageCause.POISON) { cause!=DamageCause.SUICIDE && cause!=DamageCause.FLY_INTO_WALL && cause!=DamageCause.POISON) {
int durability = p.getInventory().getChestplate().getDurability(); int durability = p.getInventory().getChestplate().getDurability();
int maxDurability = p.getInventory().getChestplate().getType().getMaxDurability(); int maxDurability = p.getInventory().getChestplate().getType().getMaxDurability();
int newDurability = (int) (durability + ((int)(e.getDamage()/4) > 1 ? (int)(e.getDamage()/4) : 1)); int newDurability = (int) (durability + ((int)(e.getDamage()/4) > 1 ? (int)(e.getDamage()/4) : 1));
// If the elytra has the durability enchantment. // If the elytra has the durability enchantment.
if (p.getInventory().getChestplate().containsEnchantment(Enchantment.DURABILITY)) { if (p.getInventory().getChestplate().containsEnchantment(Enchantment.DURABILITY)) {
Random r = new Random(); Random r = new Random();
@ -301,7 +288,6 @@ public class EventHandlers implements Listener {
} }
// Remove item from player's chestplate slot and puts it in their normal inventory. // Remove item from player's chestplate slot and puts it in their normal inventory.
public void enquipChestPlayer(Player p) { public void enquipChestPlayer(Player p) {
p.getInventory().addItem(p.getInventory().getChestplate()); p.getInventory().addItem(p.getInventory().getChestplate());
@ -309,7 +295,6 @@ public class EventHandlers implements Listener {
} }
// Check if the player is trying to equip a broken elytra (and prevent that). // Check if the player is trying to equip a broken elytra (and prevent that).
@EventHandler @EventHandler
public void playerEquipsArmor(InventoryClickEvent e){ public void playerEquipsArmor(InventoryClickEvent e){

View File

@ -1,18 +0,0 @@
package nl.pim16aap2.armoredElytra.enchantments;
import org.bukkit.Material;
import com.rit.sucy.CustomEnchantment;
public class DiamondArmor extends CustomEnchantment {
// List of items to enchant onto through an enchanting table
static final Material[] DIAMOND_ARMOR_ITEMS = new Material[] {Material.STICK};
static final String name = "Diamond Armor Tier";
public DiamondArmor() {
super(name, DIAMOND_ARMOR_ITEMS, 0);
this.max = 1;
}
}

View File

@ -1,6 +1,6 @@
name: ArmoredElytra name: ArmoredElytra
main: nl.pim16aap2.armoredElytra.ArmoredElytra main: nl.pim16aap2.armoredElytra.ArmoredElytra
version: 0.1 version: 1.0
author: Pim author: Pim
softdepend: softdepend:
- EnchantmentAPI - EnchantmentAPI