- Added uninstaller.
- Code cleanup - Added option to disable durability penalty during flight. - Added support for version 1.10.x of Minecraft.
This commit is contained in:
parent
404eb20c4c
commit
80317b4b4e
35
pom.xml
35
pom.xml
@ -3,7 +3,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>1.9-SNAPSHOT</version>
|
<version>1.11.9-SNAPSHOT</version>
|
||||||
|
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -23,16 +23,23 @@
|
|||||||
<!--Spigot API -->
|
<!--Spigot API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--bStats -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.2</version>
|
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -43,6 +50,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Bukkit API -->
|
<!--Bukkit API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>craftbukkit</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
@ -56,6 +70,13 @@
|
|||||||
<version>1.12-R0.1-SNAPSHOT</version>
|
<version>1.12-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--bStats -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,19 +5,21 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import nl.pim16aap2.armoredElytra.handlers.CommandHandler;
|
||||||
import nl.pim16aap2.armoredElytra.handlers.EventHandlers;
|
import nl.pim16aap2.armoredElytra.handlers.EventHandlers;
|
||||||
|
import nl.pim16aap2.armoredElytra.handlers.FlyDurabilityHandler;
|
||||||
import nl.pim16aap2.armoredElytra.handlers.LoginHandler;
|
import nl.pim16aap2.armoredElytra.handlers.LoginHandler;
|
||||||
|
import nl.pim16aap2.armoredElytra.handlers.Uninstaller;
|
||||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||||
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_10_R1;
|
||||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_11_R1;
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_11_R1;
|
||||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_12_R1;
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_12_R1;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
import nl.pim16aap2.armoredElytra.util.ConfigLoader;
|
import nl.pim16aap2.armoredElytra.util.ConfigLoader;
|
||||||
import nl.pim16aap2.armoredElytra.util.Metrics;
|
import nl.pim16aap2.armoredElytra.util.Metrics;
|
||||||
import nl.pim16aap2.armoredElytra.util.Update;
|
import nl.pim16aap2.armoredElytra.util.Update;
|
||||||
@ -25,39 +27,43 @@ import nl.pim16aap2.armoredElytra.util.Update;
|
|||||||
public class ArmoredElytra extends JavaPlugin implements Listener
|
public class ArmoredElytra extends JavaPlugin implements Listener
|
||||||
{
|
{
|
||||||
private NBTEditor nbtEditor;
|
private NBTEditor nbtEditor;
|
||||||
|
private ConfigLoader config;
|
||||||
|
|
||||||
private String usageDeniedMessage;
|
private String usageDeniedMessage;
|
||||||
private String elytraReceivedMessage;
|
private String elytraReceivedMessage;
|
||||||
private String elytraName;
|
private String elytraName;
|
||||||
private String elytraLore;
|
private String elytraLore;
|
||||||
private boolean upToDate;
|
private boolean upToDate;
|
||||||
|
private boolean uninstallMode;
|
||||||
private ConfigLoader config;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
|
// Load the settings from the config file.
|
||||||
config = new ConfigLoader(this);
|
config = new ConfigLoader(this);
|
||||||
|
|
||||||
// Replace color codes by the corresponding colors.
|
// Replace color codes by the corresponding colors.
|
||||||
usageDeniedMessage = config.getString("usageDeniedMessage").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
usageDeniedMessage = config.getString("usageDeniedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
elytraReceivedMessage = config.getString("elytraReceivedMessage").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
elytraReceivedMessage = config.getString("elytraReceivedMessage").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
elytraName = config.getString("elytraName").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
elytraName = config.getString("elytraName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
elytraLore = config.getString("elytraLore").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
elytraLore = config.getString("elytraLore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
|
||||||
// Change the string to null if it says "NONE".
|
// Change the string to null if it says "NONE".
|
||||||
usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage);
|
usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage );
|
||||||
elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage);
|
elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage);
|
||||||
elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore);
|
elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore );
|
||||||
|
|
||||||
|
// Check if the plugin should go into uninstall mode.
|
||||||
|
uninstallMode = config.getBool("uninstallMode");
|
||||||
|
|
||||||
|
|
||||||
|
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor, uninstallMode));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Check if the user allows checking for updates.
|
// Check if the user allows checking for updates.
|
||||||
if (config.getBool("checkForUpdates"))
|
if (config.getBool("checkForUpdates"))
|
||||||
{
|
{
|
||||||
// Load the loginHandler to show messages to the user when they join.
|
|
||||||
Bukkit.getPluginManager().registerEvents(new LoginHandler(this), this);
|
|
||||||
|
|
||||||
Update update = new Update(278437, this);
|
Update update = new Update(278437, this);
|
||||||
|
|
||||||
String latestVersion = update.getLatestVersion();
|
String latestVersion = update.getLatestVersion();
|
||||||
@ -67,14 +73,25 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
|
|
||||||
if (updateStatus > 0)
|
if (updateStatus > 0)
|
||||||
{
|
{
|
||||||
myLogger(Level.INFO, "Plugin out of date! You are using version "+thisVersion+" but the latest version is version "+latestVersion+"!");
|
// TODO: Insert download link to latest version.
|
||||||
|
// TODO: Add auto update option?
|
||||||
|
|
||||||
|
// Load the loginHandler to show messages to the user when they join.
|
||||||
|
Bukkit.getPluginManager().registerEvents(new LoginHandler(this, "The Armored Elytra plugin is out of date!"), this);
|
||||||
|
myLogger(Level.INFO, "Plugin out of date! You are using version " + thisVersion + " but the latest version is version " + latestVersion + "!");
|
||||||
this.upToDate = false;
|
this.upToDate = false;
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
this.upToDate = true;
|
this.upToDate = true;
|
||||||
myLogger(Level.INFO, "You seem to be using the latest version of this plugin!");
|
myLogger(Level.INFO, "You seem to be using the latest version of this plugin!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
myLogger(Level.INFO, "Plugin update checking not enabled! You will not receive any messages about new updates for this plugin. Please consider turning this on in the config.");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Are stats allowed?
|
// Are stats allowed?
|
||||||
if (config.getBool("allowStats"))
|
if (config.getBool("allowStats"))
|
||||||
@ -82,10 +99,41 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
myLogger(Level.INFO, "Enabling stats!");
|
myLogger(Level.INFO, "Enabling stats!");
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
// Y u do dis? :(
|
// Y u do dis? :(
|
||||||
myLogger(Level.INFO, "Stats disabled, not laoding stats :(");
|
myLogger(Level.INFO, "Stats disabled, not laoding stats :(");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Load the files for the correct version of Minecraft.
|
||||||
|
if (compatibleMCVer())
|
||||||
|
{
|
||||||
|
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Load the plugin normally if not in uninstall mode.
|
||||||
|
if (!uninstallMode)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// Check if the user wants to disable durability penalty for flying with an armored elytra.
|
||||||
|
if (config.getBool("noFlightDurability"))
|
||||||
|
{
|
||||||
|
Bukkit.getPluginManager().registerEvents(new FlyDurabilityHandler(nbtEditor), this);
|
||||||
|
myLogger(Level.INFO, "Durability penalty for flying disabled!");
|
||||||
|
} else
|
||||||
|
myLogger(Level.INFO, "Durability penalty for flying enabled!");
|
||||||
|
|
||||||
|
|
||||||
// Log all allowed enchantments.
|
// Log all allowed enchantments.
|
||||||
myLogger(Level.INFO, ("Allowed enchantments:"));
|
myLogger(Level.INFO, ("Allowed enchantments:"));
|
||||||
for (String s : config.getStringList("allowedEnchantments"))
|
for (String s : config.getStringList("allowedEnchantments"))
|
||||||
@ -94,13 +142,11 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
}
|
}
|
||||||
// Log whether or not curses are allowed.
|
// Log whether or not curses are allowed.
|
||||||
myLogger(Level.INFO, "Curses on armored elytras are " + (config.getBool("allowCurses") ? "" : "not " + "allowed!"));
|
myLogger(Level.INFO, "Curses on armored elytras are " + (config.getBool("allowCurses") ? "" : "not " + "allowed!"));
|
||||||
|
}
|
||||||
// Load the files for the correct version of Minecraft.
|
else
|
||||||
if (compatibleMCVer())
|
|
||||||
{
|
{
|
||||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
myLogger(Level.WARNING, "Plugin in uninstall mode!");
|
||||||
} else {
|
Bukkit.getPluginManager().registerEvents(new Uninstaller(this, nbtEditor), this);
|
||||||
myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,36 +174,8 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
messagePlayer(player, ChatColor.WHITE, s);
|
messagePlayer(player, ChatColor.WHITE, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert int of armorTier to its string.
|
|
||||||
public String armorTierToString(int armorTier)
|
|
||||||
{
|
|
||||||
String armorTierName = null;
|
|
||||||
switch(armorTier)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
armorTierName = "Unarmored";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
armorTierName = "Leather";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
armorTierName = "Gold";
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
armorTierName = "Chain";
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
armorTierName = "Iron";
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
armorTierName = "Diamond";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return armorTierName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the usageDeniedMessage message to the player.
|
// Send the usageDeniedMessage message to the player.
|
||||||
public void usageDeniedMessage(Player player, int armorTier)
|
public void usageDeniedMessage(Player player, ArmorTier armorTier)
|
||||||
{
|
{
|
||||||
if (usageDeniedMessage != null)
|
if (usageDeniedMessage != null)
|
||||||
{
|
{
|
||||||
@ -167,7 +185,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the elytraReceivedMessage message to the player.
|
// Send the elytraReceivedMessage message to the player.
|
||||||
public void elytraReceivedMessage(Player player, int armorTier)
|
public void elytraReceivedMessage(Player player, ArmorTier armorTier)
|
||||||
{
|
{
|
||||||
if (elytraReceivedMessage != null)
|
if (elytraReceivedMessage != null)
|
||||||
{
|
{
|
||||||
@ -177,158 +195,30 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replace %ARMOR_TIER% by the name of that armor tier in a string.
|
// Replace %ARMOR_TIER% by the name of that armor tier in a string.
|
||||||
public String fillInArmorTierInString(String string, int armorTier)
|
public String fillInArmorTierInString(String string, ArmorTier armorTier)
|
||||||
{
|
{
|
||||||
String armorTierName = armorTierToString(armorTier);
|
return string.replace("%ARMOR_TIER%", ArmorTier.getArmorName(armorTier));
|
||||||
String replaced = string.replace("%ARMOR_TIER%", armorTierName);
|
|
||||||
return replaced;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print a string to the log.
|
// Print a string to the log.
|
||||||
public void myLogger(Level level, String s)
|
public void myLogger(Level level, String str)
|
||||||
{
|
{
|
||||||
Bukkit.getLogger().log(level, "["+this.getName()+"] " + s);
|
Bukkit.getLogger().log(level, "[" + this.getName() + "] " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Log message that only gets printed when debugging is enabled in the config file.
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
public void debugMsg(Level level, String str)
|
||||||
{
|
{
|
||||||
Player player;
|
if (config.getBool("enableDebug"))
|
||||||
|
myLogger(level, str);
|
||||||
if (sender instanceof Player)
|
|
||||||
{
|
|
||||||
player = (Player) sender;
|
|
||||||
if (cmd.getName().equalsIgnoreCase("ArmoredElytra"))
|
|
||||||
{
|
|
||||||
if (args.length == 1 || args.length == 2)
|
|
||||||
{
|
|
||||||
ItemStack newElytra = null;
|
|
||||||
String tier = null;
|
|
||||||
Player receiver;
|
|
||||||
boolean allowed = false;
|
|
||||||
int armorTier = 0;
|
|
||||||
if (args.length == 1)
|
|
||||||
{
|
|
||||||
receiver = player;
|
|
||||||
tier = args[0];
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
receiver = Bukkit.getPlayer(args[0]);
|
|
||||||
if (receiver == null)
|
|
||||||
{
|
|
||||||
messagePlayer(player, ChatColor.RED, "Player \""+args[0]+"\" not found!");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
tier = args[1];
|
|
||||||
}
|
|
||||||
// Leather armor.
|
|
||||||
if (tier.equalsIgnoreCase("leather"))
|
|
||||||
{
|
|
||||||
armorTier = 1;
|
|
||||||
if (player.hasPermission("armoredelytra.give.leather"))
|
|
||||||
allowed = true;
|
|
||||||
|
|
||||||
// Gold armor.
|
|
||||||
} else if (tier.equalsIgnoreCase("gold"))
|
|
||||||
{
|
|
||||||
armorTier = 2;
|
|
||||||
if (player.hasPermission("armoredelytra.give.gold"))
|
|
||||||
allowed = true;
|
|
||||||
|
|
||||||
// Chain armor.
|
|
||||||
} else if (tier.equalsIgnoreCase("chain"))
|
|
||||||
{
|
|
||||||
armorTier = 3;
|
|
||||||
if (player.hasPermission("armoredelytra.give.chain"))
|
|
||||||
allowed = true;
|
|
||||||
|
|
||||||
// Iron armor.
|
|
||||||
} else if (tier.equalsIgnoreCase("iron"))
|
|
||||||
{
|
|
||||||
armorTier = 4;
|
|
||||||
if (player.hasPermission("armoredelytra.give.iron"))
|
|
||||||
allowed = true;
|
|
||||||
|
|
||||||
// Diamond armor.
|
|
||||||
} else if (tier.equalsIgnoreCase("diamond"))
|
|
||||||
{
|
|
||||||
armorTier = 5;
|
|
||||||
if (player.hasPermission("armoredelytra.give.diamond"))
|
|
||||||
allowed = true;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
messagePlayer(player, "Not a supported armor tier! Try one of these: leather, gold, chain, iron, diamond.");
|
|
||||||
}
|
|
||||||
if (allowed)
|
|
||||||
{
|
|
||||||
elytraReceivedMessage(receiver, armorTier);
|
|
||||||
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier);
|
|
||||||
giveArmoredElytraToPlayer(receiver, newElytra);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
messagePlayer(player, "You do not have the required permission node to give "+ armorTierToString(armorTier) + " armored elytras.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (args.length == 2)
|
|
||||||
{
|
|
||||||
ItemStack newElytra = null;
|
|
||||||
String tier = args[1];
|
|
||||||
if (Bukkit.getPlayer(args[0]) != null)
|
|
||||||
{
|
|
||||||
player = Bukkit.getPlayer(args[0]);
|
|
||||||
int armorTier = 0;
|
|
||||||
|
|
||||||
// Leather armor tier.
|
|
||||||
if (tier.equalsIgnoreCase("leather"))
|
|
||||||
{
|
|
||||||
armorTier = 1;
|
|
||||||
// Gold armor tier.
|
|
||||||
} else if (tier.equalsIgnoreCase("gold"))
|
|
||||||
{
|
|
||||||
armorTier = 2;
|
|
||||||
// Chain armor tier.
|
|
||||||
} else if (tier.equalsIgnoreCase("chain"))
|
|
||||||
{
|
|
||||||
armorTier = 3;
|
|
||||||
// Iron armor tier.
|
|
||||||
} else if (tier.equalsIgnoreCase("iron"))
|
|
||||||
{
|
|
||||||
armorTier = 4;
|
|
||||||
// Diamond armor tier.
|
|
||||||
} else if (tier.equalsIgnoreCase("diamond"))
|
|
||||||
{
|
|
||||||
armorTier = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
elytraReceivedMessage(player, armorTier);
|
|
||||||
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier);
|
|
||||||
giveArmoredElytraToPlayer(player, newElytra);
|
|
||||||
myLogger(Level.INFO, ("Giving an armored elytra of the "+ armorTierToString(armorTier) +" armor tier to player "+player.getName()));
|
|
||||||
return true;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
myLogger(Level.INFO, ("Player "+args[1]+" not found!"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Give the provided player the provided item.
|
// Give the provided player the provided item.
|
||||||
public void giveArmoredElytraToPlayer(Player player, ItemStack item)
|
public void giveArmoredElytraToPlayer(Player player, ItemStack item)
|
||||||
{
|
{
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
|
||||||
player.getInventory().addItem(item);
|
player.getInventory().addItem(item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Check + initialize for the correct version of Minecraft.
|
// Check + initialize for the correct version of Minecraft.
|
||||||
public boolean compatibleMCVer()
|
public boolean compatibleMCVer()
|
||||||
@ -338,19 +228,18 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||||
} catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException)
|
}
|
||||||
|
catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version.equals("v1_11_R1"))
|
if (version.equals("v1_10_R1"))
|
||||||
{
|
nbtEditor = new NBTEditor_V1_10_R1(elytraName, elytraLore, this);
|
||||||
|
else if (version.equals("v1_11_R1"))
|
||||||
nbtEditor = new NBTEditor_V1_11_R1(elytraName, elytraLore, this);
|
nbtEditor = new NBTEditor_V1_11_R1(elytraName, elytraLore, this);
|
||||||
|
else if (version.equals("v1_12_R1"))
|
||||||
} else if (version.equals("v1_12_R1"))
|
|
||||||
{
|
|
||||||
nbtEditor = new NBTEditor_V1_12_R1(elytraName, elytraLore, this);
|
nbtEditor = new NBTEditor_V1_12_R1(elytraName, elytraLore, this);
|
||||||
}
|
|
||||||
// Return true if compatible.
|
// Return true if compatible.
|
||||||
return nbtEditor != null;
|
return nbtEditor != null;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,176 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.handlers;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
|
public class CommandHandler implements CommandExecutor
|
||||||
|
{
|
||||||
|
ArmoredElytra plugin;
|
||||||
|
NBTEditor nbtEditor;
|
||||||
|
boolean uninstallMode;
|
||||||
|
|
||||||
|
public CommandHandler(ArmoredElytra plugin, NBTEditor nbtEditor, boolean uninstallMode)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.nbtEditor = nbtEditor;
|
||||||
|
this.uninstallMode = uninstallMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||||
|
{
|
||||||
|
Player player;
|
||||||
|
|
||||||
|
if (sender instanceof Player)
|
||||||
|
{
|
||||||
|
player = (Player) sender;
|
||||||
|
|
||||||
|
if (uninstallMode)
|
||||||
|
{
|
||||||
|
plugin.messagePlayer(player, "Plugin in uninstall mode! New Armored Elytras are not allowed!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (cmd.getName().equalsIgnoreCase("ArmoredElytra"))
|
||||||
|
{
|
||||||
|
if (args.length == 1 || args.length == 2)
|
||||||
|
{
|
||||||
|
ItemStack newElytra = null;
|
||||||
|
String tier = null;
|
||||||
|
Player receiver;
|
||||||
|
boolean allowed = false;
|
||||||
|
ArmorTier armorTier = ArmorTier.NONE;
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
receiver = player;
|
||||||
|
tier = args[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
receiver = Bukkit.getPlayer(args[0]);
|
||||||
|
if (receiver == null)
|
||||||
|
{
|
||||||
|
plugin.messagePlayer(player, ChatColor.RED, "Player \"" + args[0] + "\" not found!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
tier = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Use armorTier name from ArmorTier struct.
|
||||||
|
// Also, use AT-name for permission node verification.
|
||||||
|
|
||||||
|
|
||||||
|
// Leather armor.
|
||||||
|
if (tier.equalsIgnoreCase("leather"))
|
||||||
|
{
|
||||||
|
armorTier = ArmorTier.LEATHER;
|
||||||
|
if (player.hasPermission("armoredelytra.give.leather"))
|
||||||
|
allowed = true;
|
||||||
|
|
||||||
|
// Gold armor.
|
||||||
|
}
|
||||||
|
else if (tier.equalsIgnoreCase("gold"))
|
||||||
|
{
|
||||||
|
armorTier = ArmorTier.GOLD;
|
||||||
|
if (player.hasPermission("armoredelytra.give.gold"))
|
||||||
|
allowed = true;
|
||||||
|
|
||||||
|
// Chain armor.
|
||||||
|
}
|
||||||
|
else if (tier.equalsIgnoreCase("chain"))
|
||||||
|
{
|
||||||
|
armorTier = ArmorTier.CHAIN;
|
||||||
|
if (player.hasPermission("armoredelytra.give.chain"))
|
||||||
|
allowed = true;
|
||||||
|
|
||||||
|
// Iron armor.
|
||||||
|
}
|
||||||
|
else if (tier.equalsIgnoreCase("iron"))
|
||||||
|
{
|
||||||
|
armorTier = ArmorTier.IRON;
|
||||||
|
if (player.hasPermission("armoredelytra.give.iron"))
|
||||||
|
allowed = true;
|
||||||
|
|
||||||
|
// Diamond armor.
|
||||||
|
}
|
||||||
|
else if (tier.equalsIgnoreCase("diamond"))
|
||||||
|
{
|
||||||
|
armorTier = ArmorTier.DIAMOND;
|
||||||
|
if (player.hasPermission("armoredelytra.give.diamond"))
|
||||||
|
allowed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
plugin.messagePlayer(player, "Not a supported armor tier! Try one of these: leather, gold, chain, iron, diamond.");
|
||||||
|
|
||||||
|
if (allowed)
|
||||||
|
{
|
||||||
|
plugin.elytraReceivedMessage(receiver, armorTier);
|
||||||
|
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||||
|
plugin.giveArmoredElytraToPlayer(receiver, newElytra);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
plugin.messagePlayer(player, "You do not have the required permission node to give " + ArmorTier.getArmorName(armorTier) + " armored elytras.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (uninstallMode)
|
||||||
|
{
|
||||||
|
plugin.myLogger(Level.INFO, "Plugin in uninstall mode! New Armored Elytras are not allowed!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
ItemStack newElytra = null;
|
||||||
|
String tier = args[1];
|
||||||
|
if (Bukkit.getPlayer(args[0]) != null)
|
||||||
|
{
|
||||||
|
player = Bukkit.getPlayer(args[0]);
|
||||||
|
ArmorTier armorTier = ArmorTier.NONE;
|
||||||
|
|
||||||
|
// TODO: Again, use the ArmorTier struct for tier retrieval.
|
||||||
|
|
||||||
|
if (tier.equalsIgnoreCase("leather"))
|
||||||
|
armorTier = ArmorTier.LEATHER;
|
||||||
|
else if (tier.equalsIgnoreCase("gold"))
|
||||||
|
armorTier = ArmorTier.GOLD;
|
||||||
|
else if (tier.equalsIgnoreCase("chain"))
|
||||||
|
armorTier = ArmorTier.CHAIN;
|
||||||
|
else if (tier.equalsIgnoreCase("iron"))
|
||||||
|
armorTier = ArmorTier.IRON;
|
||||||
|
else if (tier.equalsIgnoreCase("diamond"))
|
||||||
|
armorTier = ArmorTier.DIAMOND;
|
||||||
|
// TODO: Catch user requesting non-existent tier.
|
||||||
|
|
||||||
|
plugin.elytraReceivedMessage(player, armorTier);
|
||||||
|
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||||
|
plugin.giveArmoredElytraToPlayer(player, newElytra);
|
||||||
|
plugin.myLogger(Level.INFO, ("Giving an armored elytra of the " + ArmorTier.getArmor(armorTier) + " armor tier to player " + player.getName()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.myLogger(Level.INFO, ("Player " + args[1] + " not found!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -24,6 +25,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.Util;
|
||||||
|
|
||||||
public class EventHandlers implements Listener
|
public class EventHandlers implements Listener
|
||||||
{
|
{
|
||||||
@ -57,7 +60,7 @@ public class EventHandlers implements Listener
|
|||||||
public void cleanAnvil(AnvilInventory anvilInventory)
|
public void cleanAnvil(AnvilInventory anvilInventory)
|
||||||
{
|
{
|
||||||
anvilInventory.getItem(0).setAmount(0);
|
anvilInventory.getItem(0).setAmount(0);
|
||||||
anvilInventory.getItem(1).setAmount(anvilInventory.getItem(1).getAmount()-1);
|
anvilInventory.getItem(1).setAmount(anvilInventory.getItem(1).getAmount() - 1);
|
||||||
anvilInventory.getItem(2).setAmount(0);
|
anvilInventory.getItem(2).setAmount(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,15 +68,10 @@ public class EventHandlers implements Listener
|
|||||||
public boolean isAllowedEnchantment(Enchantment enchant)
|
public boolean isAllowedEnchantment(Enchantment enchant)
|
||||||
{
|
{
|
||||||
for (String s : allowedEnchantments)
|
for (String s : allowedEnchantments)
|
||||||
{
|
|
||||||
if (Enchantment.getByName(s) != null)
|
if (Enchantment.getByName(s) != null)
|
||||||
{
|
|
||||||
if (Enchantment.getByName(s).equals(enchant))
|
if (Enchantment.getByName(s).equals(enchant))
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,19 +79,10 @@ public class EventHandlers implements Listener
|
|||||||
public boolean isCursedEnchantment(Enchantment enchant)
|
public boolean isCursedEnchantment(Enchantment enchant)
|
||||||
{
|
{
|
||||||
for (String s : cursedEnchantments)
|
for (String s : cursedEnchantments)
|
||||||
{
|
|
||||||
if (Enchantment.getByName(s).equals(enchant))
|
if (Enchantment.getByName(s).equals(enchant))
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the elytra being checked is an armored one.
|
return false;
|
||||||
public boolean isArmoredElytra(ItemStack elytra)
|
|
||||||
{
|
|
||||||
return (nbtEditor.getArmorTier(elytra) == 0 ? false : true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy enchants of 2 items to one item.
|
// Copy enchants of 2 items to one item.
|
||||||
@ -108,18 +97,15 @@ public class EventHandlers implements Listener
|
|||||||
Map<Enchantment, Integer> enchantments1 = itemTwo.getEnchantments();
|
Map<Enchantment, Integer> enchantments1 = itemTwo.getEnchantments();
|
||||||
|
|
||||||
for (Map.Entry<Enchantment, Integer> entry : enchantmentsTemp.entrySet())
|
for (Map.Entry<Enchantment, Integer> entry : enchantmentsTemp.entrySet())
|
||||||
{
|
|
||||||
// Check if the enchantment is allowed or if it is a cursed enchantment while it's allowed.
|
// Check if the enchantment is allowed or if it is a cursed enchantment while it's allowed.
|
||||||
if (isAllowedEnchantment(entry.getKey()) || (cursesAllowed && isCursedEnchantment(entry.getKey())))
|
if (isAllowedEnchantment(entry.getKey()) || (cursesAllowed && isCursedEnchantment(entry.getKey())))
|
||||||
{
|
|
||||||
enchantments0.put(entry.getKey(), entry.getValue());
|
enchantments0.put(entry.getKey(), entry.getValue());
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add the enchantments copied from itemOne to the resulting item.
|
// Add the enchantments copied from itemOne to the resulting item.
|
||||||
result.addUnsafeEnchantments(enchantments0);
|
result.addUnsafeEnchantments(enchantments0);
|
||||||
|
|
||||||
// Enchants from enchanted books have to be access in a different way.
|
// Enchants from enchanted books have to be access in a different way.
|
||||||
if (itemTwo.getType() == Material.ENCHANTED_BOOK && isArmoredElytra(itemOne))
|
if (itemTwo.getType() == Material.ENCHANTED_BOOK && (nbtEditor.getArmorTier(itemOne) != ArmorTier.NONE))
|
||||||
{
|
{
|
||||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemTwo.getItemMeta();
|
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemTwo.getItemMeta();
|
||||||
enchantments1 = meta.getStoredEnchants();
|
enchantments1 = meta.getStoredEnchants();
|
||||||
@ -129,17 +115,16 @@ public class EventHandlers implements Listener
|
|||||||
if (enchantments1!=null)
|
if (enchantments1!=null)
|
||||||
{
|
{
|
||||||
// Loop through the enchantments of item1.
|
// Loop through the enchantments of item1.
|
||||||
for (Map.Entry<Enchantment, Integer> entry : enchantments1.entrySet())
|
for (Map.Entry<Enchantment, Integer > entry : enchantments1.entrySet())
|
||||||
{
|
{
|
||||||
// If the enchantment is a curse and if the result does not already have it.
|
// If the enchantment is a curse and if the result does not already have it.
|
||||||
if (isCursedEnchantment(entry.getKey()) && !result.containsEnchantment(entry.getKey()))
|
if (isCursedEnchantment(entry.getKey()) && !result.containsEnchantment(entry.getKey()))
|
||||||
{
|
{
|
||||||
// If curses are allowed, apply the curse to the result.
|
// If curses are allowed, apply the curse to the result.
|
||||||
if (cursesAllowed)
|
if (cursesAllowed)
|
||||||
{
|
|
||||||
result.addEnchantment(entry.getKey(), entry.getValue());
|
result.addEnchantment(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
} else if (isAllowedEnchantment(entry.getKey()))
|
else if (isAllowedEnchantment(entry.getKey()))
|
||||||
{
|
{
|
||||||
int enchantLevel = entry.getValue();
|
int enchantLevel = entry.getValue();
|
||||||
// If item0 and item1 both have the same enchantment at the same level, result has level+1.
|
// If item0 and item1 both have the same enchantment at the same level, result has level+1.
|
||||||
@ -147,21 +132,18 @@ public class EventHandlers implements Listener
|
|||||||
if (enchantments0 != null)
|
if (enchantments0 != null)
|
||||||
{
|
{
|
||||||
// Loop through the enchantments of item0 (which are already on the result).
|
// Loop through the enchantments of item0 (which are already on the result).
|
||||||
for (Map.Entry<Enchantment, Integer> rentry : enchantments0.entrySet())
|
for (Map.Entry<Enchantment, Integer > rentry : enchantments0.entrySet())
|
||||||
{
|
{
|
||||||
if (entry.getKey().getName() == rentry.getKey().getName())
|
if (entry.getKey().getName() == rentry.getKey().getName())
|
||||||
{
|
{
|
||||||
// If they both have the same level of the same enchantment, the result will have that enchantment 1 level higher (if possible).
|
// If they both have the same level of the same enchantment, the result will have that enchantment 1 level higher (if possible).
|
||||||
if (entry.getValue() == rentry.getValue() && entry.getValue() < entry.getKey().getMaxLevel())
|
if (entry.getValue() == rentry.getValue() && entry.getValue() < entry.getKey().getMaxLevel())
|
||||||
{
|
enchantLevel = entry.getValue() + 1;
|
||||||
enchantLevel = entry.getValue()+1;
|
else if (entry.getValue() < rentry.getValue())
|
||||||
} else if (entry.getValue() < rentry.getValue())
|
|
||||||
{
|
|
||||||
enchantLevel = rentry.getValue();
|
enchantLevel = rentry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
result.addUnsafeEnchantment(entry.getKey(), enchantLevel);
|
result.addUnsafeEnchantment(entry.getKey(), enchantLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,25 +160,20 @@ public class EventHandlers implements Listener
|
|||||||
// Get the multiplier for the repair items.
|
// Get the multiplier for the repair items.
|
||||||
double mult = 0.01;
|
double mult = 0.01;
|
||||||
if (two.getType() == Material.LEATHER)
|
if (two.getType() == Material.LEATHER)
|
||||||
{
|
|
||||||
mult *= (100/LEATHER_TO_FULL);
|
mult *= (100/LEATHER_TO_FULL);
|
||||||
|
|
||||||
} else if (two.getType() == Material.GOLD_INGOT)
|
else if (two.getType() == Material.GOLD_INGOT)
|
||||||
{
|
|
||||||
mult *= (100/GOLD_TO_FULL);
|
mult *= (100/GOLD_TO_FULL);
|
||||||
|
|
||||||
} else if (two.getType() == Material.IRON_INGOT)
|
else if (two.getType() == Material.IRON_INGOT)
|
||||||
{
|
|
||||||
mult *= (100/IRON_TO_FULL);
|
mult *= (100/IRON_TO_FULL);
|
||||||
|
|
||||||
} else if (two.getType() == Material.DIAMOND)
|
else if (two.getType() == Material.DIAMOND)
|
||||||
{
|
|
||||||
mult *= (100/DIAMONDS_TO_FULL);
|
mult *= (100/DIAMONDS_TO_FULL);
|
||||||
}
|
|
||||||
|
|
||||||
int maxDurability = one.getType().getMaxDurability();
|
int maxDurability = one.getType().getMaxDurability();
|
||||||
int durability = one.getDurability();
|
int durability = one.getDurability();
|
||||||
int newDurability = (int) (durability - (maxDurability*mult));
|
int newDurability = (int) (durability - (maxDurability * mult));
|
||||||
result.setDurability((short) (newDurability <= 0 ? 0 : newDurability));
|
result.setDurability((short) (newDurability <= 0 ? 0 : newDurability));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -211,7 +188,21 @@ public class EventHandlers implements Listener
|
|||||||
Player p = (Player) e.getWhoClicked();
|
Player p = (Player) e.getWhoClicked();
|
||||||
if (e.getView().getType() == InventoryType.ANVIL)
|
if (e.getView().getType() == InventoryType.ANVIL)
|
||||||
{
|
{
|
||||||
AnvilInventory anvilInventory = (AnvilInventory) e.getInventory(); // Inventory type
|
AnvilInventory anvilInventory;
|
||||||
|
|
||||||
|
// Try to cast inventory being used in the event to an anvil inventory.
|
||||||
|
// This will throw a ClassCastException when a CraftInventoryCustom is used.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
anvilInventory = (AnvilInventory) e.getInventory();
|
||||||
|
}
|
||||||
|
catch (ClassCastException exception)
|
||||||
|
{
|
||||||
|
// Print warning to console and exit onInventoryClick event (no support for custom inventories as they are usually used for GUI's)).
|
||||||
|
plugin.debugMsg(Level.WARNING, "Could not cast inventory to anvilInventory for player " + p.getName() + "! Armored Elytras cannot be crafted!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int slot = e.getRawSlot(); // Get slot
|
int slot = e.getRawSlot(); // Get slot
|
||||||
|
|
||||||
if (slot == 2 && anvilInventory.getItem(2) != null)
|
if (slot == 2 && anvilInventory.getItem(2) != null)
|
||||||
@ -221,12 +212,9 @@ public class EventHandlers implements Listener
|
|||||||
if (anvilInventory.getItem(2).getType() == Material.ELYTRA && anvilInventory.getItem(0) != null && anvilInventory.getItem(1) != null)
|
if (anvilInventory.getItem(2).getType() == Material.ELYTRA && anvilInventory.getItem(0) != null && anvilInventory.getItem(1) != null)
|
||||||
{
|
{
|
||||||
if (e.isShiftClick())
|
if (e.isShiftClick())
|
||||||
{
|
|
||||||
p.getInventory().addItem(anvilInventory.getItem(2));
|
p.getInventory().addItem(anvilInventory.getItem(2));
|
||||||
} else
|
else
|
||||||
{
|
|
||||||
p.setItemOnCursor(anvilInventory.getItem(2));
|
p.setItemOnCursor(anvilInventory.getItem(2));
|
||||||
}
|
|
||||||
// Clean the anvil's inventory after transferring the items.
|
// Clean the anvil's inventory after transferring the items.
|
||||||
cleanAnvil(anvilInventory);
|
cleanAnvil(anvilInventory);
|
||||||
}
|
}
|
||||||
@ -237,7 +225,6 @@ public class EventHandlers implements Listener
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
|
||||||
ItemStack itemA = anvilInventory.getItem(0);
|
ItemStack itemA = anvilInventory.getItem(0);
|
||||||
ItemStack itemB = anvilInventory.getItem(1);
|
ItemStack itemB = anvilInventory.getItem(1);
|
||||||
ItemStack result = null;
|
ItemStack result = null;
|
||||||
@ -259,19 +246,8 @@ public class EventHandlers implements Listener
|
|||||||
// Check if the first input slot contains an elytra.
|
// Check if the first input slot contains an elytra.
|
||||||
if (itemA.getType() == Material.ELYTRA)
|
if (itemA.getType() == Material.ELYTRA)
|
||||||
{
|
{
|
||||||
int armorTier = 0;
|
ArmorTier armorTier = ArmorTier.NONE;
|
||||||
int currentArmorTier = 0;
|
ArmorTier currentArmorTier = nbtEditor.getArmorTier(itemA);
|
||||||
if (isArmoredElytra(itemA))
|
|
||||||
{
|
|
||||||
currentArmorTier = nbtEditor.getArmorTier(itemA);
|
|
||||||
}
|
|
||||||
/* 0 = No Armor.
|
|
||||||
* 1 = Leather Armor.
|
|
||||||
* 2 = Gold Armor.
|
|
||||||
* 3 = Chain Armor.
|
|
||||||
* 4 = Iron Armor.
|
|
||||||
* 5 = Diamond Armor.
|
|
||||||
*/
|
|
||||||
// Check if the second input slot contains a diamond chestplate.
|
// Check if the second input slot contains a diamond chestplate.
|
||||||
if (itemB.getType() == Material.LEATHER_CHESTPLATE ||
|
if (itemB.getType() == Material.LEATHER_CHESTPLATE ||
|
||||||
itemB.getType() == Material.GOLD_CHESTPLATE ||
|
itemB.getType() == Material.GOLD_CHESTPLATE ||
|
||||||
@ -281,50 +257,41 @@ public class EventHandlers implements Listener
|
|||||||
{
|
{
|
||||||
// Combine the enchantments of the two items in the input slots.
|
// Combine the enchantments of the two items in the input slots.
|
||||||
result = addEnchants(itemA, itemB, p);
|
result = addEnchants(itemA, itemB, p);
|
||||||
|
|
||||||
if (itemB.getType() == Material.LEATHER_CHESTPLATE)
|
if (itemB.getType() == Material.LEATHER_CHESTPLATE)
|
||||||
{
|
armorTier = ArmorTier.LEATHER;
|
||||||
armorTier = 1;
|
else if (itemB.getType() == Material.GOLD_CHESTPLATE)
|
||||||
} else if (itemB.getType() == Material.GOLD_CHESTPLATE)
|
armorTier = ArmorTier.GOLD;
|
||||||
{
|
else if (itemB.getType() == Material.CHAINMAIL_CHESTPLATE)
|
||||||
armorTier = 2;
|
armorTier = ArmorTier.CHAIN;
|
||||||
} else if (itemB.getType() == Material.CHAINMAIL_CHESTPLATE)
|
else if (itemB.getType() == Material.IRON_CHESTPLATE)
|
||||||
{
|
armorTier = ArmorTier.IRON;
|
||||||
armorTier = 3;
|
else if (itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
||||||
} else if (itemB.getType() == Material.IRON_CHESTPLATE)
|
armorTier = ArmorTier.DIAMOND;
|
||||||
{
|
|
||||||
armorTier = 4;
|
short durability = (short) (- itemA.getType().getMaxDurability() - itemA.getDurability() - itemB.getDurability());
|
||||||
} else if (itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
|
||||||
{
|
|
||||||
armorTier = 5;
|
|
||||||
}
|
|
||||||
short durability = (short) (-itemA.getType().getMaxDurability() - itemA.getDurability() - itemB.getDurability());
|
|
||||||
durability = durability < 0 ? 0 : durability;
|
durability = durability < 0 ? 0 : durability;
|
||||||
result.setDurability(durability);
|
result.setDurability(durability);
|
||||||
}
|
}
|
||||||
// If the player tries to repair an armored elytra. Check if the armor tier and the repair item match.
|
// If the player tries to repair an armored elytra. Check if the armor tier and the repair item match.
|
||||||
// If the repair item is leather it can only repair
|
// If the repair item is leather it can only repair
|
||||||
else if ((itemB.getType() == Material.LEATHER && isArmoredElytra(itemA) && currentArmorTier == 1) ||
|
else if ((itemB.getType() == Material.LEATHER && currentArmorTier == ArmorTier.LEATHER) ||
|
||||||
(itemB.getType() == Material.GOLD_INGOT && isArmoredElytra(itemA) && currentArmorTier == 2) ||
|
(itemB.getType() == Material.GOLD_INGOT && currentArmorTier == ArmorTier.GOLD ) ||
|
||||||
(itemB.getType() == Material.IRON_INGOT && isArmoredElytra(itemA) && currentArmorTier == 3) ||
|
(itemB.getType() == Material.IRON_INGOT && currentArmorTier == ArmorTier.IRON ) ||
|
||||||
(itemB.getType() == Material.IRON_INGOT && isArmoredElytra(itemA) && currentArmorTier == 4) ||
|
(itemB.getType() == Material.IRON_INGOT && currentArmorTier == ArmorTier.CHAIN ) ||
|
||||||
(itemB.getType() == Material.DIAMOND && isArmoredElytra(itemA) && currentArmorTier == 5))
|
(itemB.getType() == Material.DIAMOND && currentArmorTier == ArmorTier.DIAMOND))
|
||||||
{
|
{
|
||||||
// Repair the item in the first input slot with items from the second input slot.
|
// Repair the item in the first input slot with items from the second input slot.
|
||||||
result = repairItem(itemA, itemB);
|
result = repairItem(itemA, itemB);
|
||||||
}
|
}
|
||||||
// Check if it is an enchanted book for itemB.
|
// Check if it is an enchanted book for itemB.
|
||||||
else if (itemB.getType() == Material.ENCHANTED_BOOK)
|
else if (itemB.getType() == Material.ENCHANTED_BOOK)
|
||||||
{
|
|
||||||
result = addEnchants(itemA, itemB, p);
|
result = addEnchants(itemA, itemB, p);
|
||||||
}
|
|
||||||
// Otherwise, remove the item in the result slot (slot2).
|
// Otherwise, remove the item in the result slot (slot2).
|
||||||
else
|
else if (anvilInventory.getItem(2) != null)
|
||||||
{
|
|
||||||
if (anvilInventory.getItem(2)!=null)
|
|
||||||
{
|
|
||||||
anvilInventory.getItem(2).setAmount(0);
|
anvilInventory.getItem(2).setAmount(0);
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
@ -335,11 +302,13 @@ public class EventHandlers implements Listener
|
|||||||
itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
||||||
{
|
{
|
||||||
// Add the NBT Tags for the elytra, to give it diamond_chestplate tier of armor protection.
|
// Add the NBT Tags for the elytra, to give it diamond_chestplate tier of armor protection.
|
||||||
result = nbtEditor.addArmorNBTTags(result, armorTier);
|
result = nbtEditor.addArmorNBTTags(result, armorTier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||||
} else if (isArmoredElytra(itemA) && !isArmoredElytra(result))
|
}
|
||||||
|
else if ((nbtEditor.getArmorTier(itemA) != ArmorTier.NONE) &&
|
||||||
|
(nbtEditor.getArmorTier(result) != ArmorTier.NONE))
|
||||||
{
|
{
|
||||||
armorTier = nbtEditor.getArmorTier(itemA);
|
armorTier = nbtEditor.getArmorTier(itemA);
|
||||||
result = nbtEditor.addArmorNBTTags(result, armorTier);
|
result = nbtEditor.addArmorNBTTags(result, armorTier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||||
}
|
}
|
||||||
anvilInventory.setItem(2, result);
|
anvilInventory.setItem(2, result);
|
||||||
}
|
}
|
||||||
@ -347,14 +316,10 @@ public class EventHandlers implements Listener
|
|||||||
}
|
}
|
||||||
// Check if either itemA or itemB is unoccupied.
|
// Check if either itemA or itemB is unoccupied.
|
||||||
if (itemA == null || itemB == null)
|
if (itemA == null || itemB == null)
|
||||||
{
|
|
||||||
// If Item2 is occupied despite Item1 not being occupied.
|
// If Item2 is occupied despite Item1 not being occupied.
|
||||||
if (anvilInventory.getItem(2) != null)
|
if (anvilInventory.getItem(2) != null)
|
||||||
{
|
|
||||||
// Then set the amount to 0.
|
// Then set the amount to 0.
|
||||||
anvilInventory.getItem(2).setAmount(0);
|
anvilInventory.getItem(2).setAmount(0);
|
||||||
}
|
|
||||||
}
|
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
}
|
}
|
||||||
}.runTaskLater(this.plugin, 1);
|
}.runTaskLater(this.plugin, 1);
|
||||||
@ -362,57 +327,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.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDamage(EntityDamageEvent e)
|
|
||||||
{
|
|
||||||
if(e.getEntity() instanceof Player)
|
|
||||||
{
|
|
||||||
Player p = (Player) e.getEntity();
|
|
||||||
if (p.getInventory().getChestplate()!=null)
|
|
||||||
{
|
|
||||||
if (p.getInventory().getChestplate().getType() == Material.ELYTRA && isArmoredElytra(p.getInventory().getChestplate()))
|
|
||||||
{
|
|
||||||
DamageCause cause = e.getCause();
|
|
||||||
if (cause!=DamageCause.DROWNING && cause!=DamageCause.STARVATION && cause!=DamageCause.SUFFOCATION &&
|
|
||||||
cause!=DamageCause.SUICIDE && cause!=DamageCause.FLY_INTO_WALL && cause!=DamageCause.POISON)
|
|
||||||
{
|
|
||||||
|
|
||||||
int durability = p.getInventory().getChestplate().getDurability();
|
|
||||||
int maxDurability = p.getInventory().getChestplate().getType().getMaxDurability();
|
|
||||||
int newDurability = (int) (durability + ((int)(e.getDamage()/4) > 1 ? (int)(e.getDamage()/4) : 1));
|
|
||||||
// If the elytra has the durability enchantment.
|
|
||||||
if (p.getInventory().getChestplate().containsEnchantment(Enchantment.DURABILITY)) {
|
|
||||||
Random r = new Random();
|
|
||||||
// Get a random int between 0 and 100
|
|
||||||
int randomInt = r.nextInt(101);
|
|
||||||
int enchantLevel = p.getInventory().getChestplate().getEnchantmentLevel(Enchantment.DURABILITY);
|
|
||||||
int durabilityDelta = (100/(enchantLevel+1)) < randomInt ? 0 : 1;
|
|
||||||
if (durability>=maxDurability)
|
|
||||||
{
|
|
||||||
unenquipChestPlayer(p);
|
|
||||||
} else
|
|
||||||
newDurability = durability+durabilityDelta;
|
|
||||||
}
|
|
||||||
// If the item should be broken, make sure it really is broken and unequip it.
|
|
||||||
if (newDurability >= maxDurability)
|
|
||||||
{
|
|
||||||
newDurability = maxDurability;
|
|
||||||
unenquipChestPlayer(p);
|
|
||||||
}
|
|
||||||
p.getInventory().getChestplate().setDurability((short) (newDurability));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove item from player's chestplate slot and puts it in their normal inventory.
|
|
||||||
public void unenquipChestPlayer(Player p)
|
|
||||||
{
|
|
||||||
p.getInventory().addItem(p.getInventory().getChestplate());
|
|
||||||
p.getInventory().getChestplate().setAmount(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the player tries to equip armor by richt clicking it.
|
// Check if the player tries to equip armor by richt clicking it.
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -424,22 +338,20 @@ public class EventHandlers implements Listener
|
|||||||
ItemStack item = player.getItemInHand();
|
ItemStack item = player.getItemInHand();
|
||||||
|
|
||||||
if (item != null)
|
if (item != null)
|
||||||
|
if (item.getType() == Material.ELYTRA && (nbtEditor.getArmorTier(item) != ArmorTier.NONE))
|
||||||
{
|
{
|
||||||
if (item.getType() == Material.ELYTRA && isArmoredElytra(item))
|
ArmorTier armorTier = nbtEditor.getArmorTier(item);
|
||||||
{
|
if ((armorTier == ArmorTier.LEATHER && !player.hasPermission("armoredelytra.wear.leather")) ||
|
||||||
int armorTier = nbtEditor.getArmorTier(item);
|
(armorTier == ArmorTier.GOLD && !player.hasPermission("armoredelytra.wear.gold")) ||
|
||||||
if ((armorTier == 1 && !player.hasPermission("armoredelytra.wear.leather")) ||
|
(armorTier == ArmorTier.CHAIN && !player.hasPermission("armoredelytra.wear.chain")) ||
|
||||||
(armorTier == 2 && !player.hasPermission("armoredelytra.wear.gold")) ||
|
(armorTier == ArmorTier.IRON && !player.hasPermission("armoredelytra.wear.iron")) ||
|
||||||
(armorTier == 3 && !player.hasPermission("armoredelytra.wear.chain")) ||
|
(armorTier == ArmorTier.DIAMOND && !player.hasPermission("armoredelytra.wear.diamond")))
|
||||||
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
|
|
||||||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
|
|
||||||
{
|
{
|
||||||
plugin.usageDeniedMessage(player, armorTier);
|
plugin.usageDeniedMessage(player, armorTier);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Player closes their inventory. Also checks for whether they are allowed to wear the armored elytra they are wearing.
|
// Player closes their inventory. Also checks for whether they are allowed to wear the armored elytra they are wearing.
|
||||||
// This is done again here because there are ways to bypass permission check when equipping.
|
// This is done again here because there are ways to bypass permission check when equipping.
|
||||||
@ -457,27 +369,80 @@ public class EventHandlers implements Listener
|
|||||||
if (player.getInventory().getChestplate() != null)
|
if (player.getInventory().getChestplate() != null)
|
||||||
{
|
{
|
||||||
// If that chestplate is an (armored) elytra.
|
// If that chestplate is an (armored) elytra.
|
||||||
if (chestplate.getType() == Material.ELYTRA && isArmoredElytra(chestplate))
|
if (chestplate.getType() == Material.ELYTRA && (nbtEditor.getArmorTier(chestplate) != ArmorTier.NONE))
|
||||||
{
|
{
|
||||||
int armorTier = nbtEditor.getArmorTier(chestplate);
|
ArmorTier armorTier = nbtEditor.getArmorTier(chestplate);
|
||||||
if ((chestplate.getDurability() >= chestplate.getType().getMaxDurability()))
|
if ((chestplate.getDurability() >= chestplate.getType().getMaxDurability()))
|
||||||
{
|
{
|
||||||
plugin.messagePlayer(player, ChatColor.RED + "You cannot equip this elytra! Please repair it in an anvil first.");
|
plugin.messagePlayer(player, ChatColor.RED + "You cannot equip this elytra! Please repair it in an anvil first.");
|
||||||
unenquipChestPlayer(player);
|
Util.unenquipChestPlayer(player);
|
||||||
} else if ((armorTier == 1 && !player.hasPermission("armoredelytra.wear.leather")) ||
|
}
|
||||||
(armorTier == 2 && !player.hasPermission("armoredelytra.wear.gold")) ||
|
else if ((armorTier == ArmorTier.LEATHER && !player.hasPermission("armoredelytra.wear.leather")) ||
|
||||||
(armorTier == 3 && !player.hasPermission("armoredelytra.wear.chain")) ||
|
(armorTier == ArmorTier.GOLD && !player.hasPermission("armoredelytra.wear.gold" )) ||
|
||||||
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
|
(armorTier == ArmorTier.CHAIN && !player.hasPermission("armoredelytra.wear.chain" )) ||
|
||||||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
|
(armorTier == ArmorTier.IRON && !player.hasPermission("armoredelytra.wear.iron" )) ||
|
||||||
|
(armorTier == ArmorTier.DIAMOND && !player.hasPermission("armoredelytra.wear.diamond")))
|
||||||
{
|
{
|
||||||
plugin.usageDeniedMessage(player, armorTier);
|
plugin.usageDeniedMessage(player, armorTier);
|
||||||
unenquipChestPlayer(player);
|
Util.unenquipChestPlayer(player);
|
||||||
}
|
}
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because the armored elytra doesn't actually give any armor, the damage received by players wearing an armored elytra is calculated here.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDamage(EntityDamageEvent e)
|
||||||
|
{
|
||||||
|
if(e.getEntity() instanceof Player)
|
||||||
|
{
|
||||||
|
Player p = (Player) e.getEntity();
|
||||||
|
// If the player didn't die from the damage.
|
||||||
|
if ((p.getHealth() - e.getFinalDamage()) > 0)
|
||||||
|
{
|
||||||
|
if (p.getInventory().getChestplate()!=null)
|
||||||
|
{
|
||||||
|
if (p.getInventory().getChestplate().getType() == Material.ELYTRA &&
|
||||||
|
nbtEditor.getArmorTier(p.getInventory().getChestplate()) != ArmorTier.NONE)
|
||||||
|
{
|
||||||
|
ItemStack elytra = p.getInventory().getChestplate();
|
||||||
|
DamageCause cause = e.getCause();
|
||||||
|
|
||||||
|
// The elytra doesn't receive any damage for these causes:
|
||||||
|
if (cause != DamageCause.DROWNING && cause != DamageCause.STARVATION && cause != DamageCause.SUFFOCATION &&
|
||||||
|
cause != DamageCause.SUICIDE && cause != DamageCause.FLY_INTO_WALL && cause != DamageCause.POISON)
|
||||||
|
{
|
||||||
|
int durability = p.getInventory().getChestplate().getDurability();
|
||||||
|
int maxDurability = p.getInventory().getChestplate().getType().getMaxDurability();
|
||||||
|
int newDurability = (int) (durability + ((int) (e.getDamage() / 4) > 1 ? (int) (e.getDamage() / 4) : 1));
|
||||||
|
|
||||||
|
// If the elytra has the durability enchantment, we calculate the durability loss ourselves.
|
||||||
|
if (p.getInventory().getChestplate().containsEnchantment(Enchantment.DURABILITY)) {
|
||||||
|
|
||||||
|
// Get a random int between 0 and 100
|
||||||
|
Random r = new Random();
|
||||||
|
int randomInt = r.nextInt(101);
|
||||||
|
int enchantLevel = p.getInventory().getChestplate().getEnchantmentLevel(Enchantment.DURABILITY);
|
||||||
|
int durabilityDelta = (100/(enchantLevel+1)) < randomInt ? 0 : 1;
|
||||||
|
if (durability >= maxDurability)
|
||||||
|
Util.unenquipChestPlayer(p);
|
||||||
|
else
|
||||||
|
newDurability = durability + durabilityDelta;
|
||||||
|
}
|
||||||
|
// If the item should be broken, make sure it really is broken and unequip it.
|
||||||
|
if (newDurability >= maxDurability)
|
||||||
|
{
|
||||||
|
newDurability = maxDurability;
|
||||||
|
Util.unenquipChestPlayer(p);
|
||||||
|
}
|
||||||
|
elytra.setDurability((short) (newDurability));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.handlers;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||||
|
|
||||||
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
|
public class FlyDurabilityHandler implements Listener
|
||||||
|
{
|
||||||
|
private NBTEditor nbtEditor;
|
||||||
|
|
||||||
|
public FlyDurabilityHandler(NBTEditor nbtEditor)
|
||||||
|
{
|
||||||
|
this.nbtEditor = nbtEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not decrease elytra durability while flying.
|
||||||
|
// This also cancels durability decrease when it should while flying, but that shouldn't really matter.
|
||||||
|
@EventHandler
|
||||||
|
public void onItemDamage(PlayerItemDamageEvent e)
|
||||||
|
{
|
||||||
|
if (e.getItem().getType() == Material.ELYTRA)
|
||||||
|
if (nbtEditor.getArmorTier(e.getItem()) != ArmorTier.NONE)
|
||||||
|
if (e.getPlayer().isFlying())
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
@ -9,27 +9,31 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
|
||||||
public class LoginHandler implements Listener {
|
public class LoginHandler implements Listener
|
||||||
|
{
|
||||||
|
|
||||||
ArmoredElytra plugin;
|
ArmoredElytra plugin;
|
||||||
|
String message;
|
||||||
|
|
||||||
public LoginHandler(ArmoredElytra plugin)
|
public LoginHandler(ArmoredElytra plugin, String message)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogin(PlayerLoginEvent event)
|
public void onLogin(PlayerLoginEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission("armoredElytra.admin") && !plugin.isUpToDate())
|
if (player.hasPermission("armoredElytra.admin"))
|
||||||
{
|
{
|
||||||
|
// Slight delay so the player actually receives the message;
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
plugin.messagePlayer(player, ChatColor.AQUA, "The Armored Elytra plugin is out of date!");
|
plugin.messagePlayer(player, ChatColor.AQUA, message);
|
||||||
}
|
}
|
||||||
}.runTaskLater(this.plugin, 10);
|
}.runTaskLater(this.plugin, 10);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.handlers;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
|
public class Uninstaller implements Listener
|
||||||
|
{
|
||||||
|
ArmoredElytra plugin;
|
||||||
|
NBTEditor nbtEditor;
|
||||||
|
|
||||||
|
public Uninstaller(ArmoredElytra plugin, NBTEditor nbtEditor)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.nbtEditor = nbtEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int removeArmoredElytras(Inventory inv)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (ItemStack is : inv)
|
||||||
|
if (is != null)
|
||||||
|
if (is.getType() == Material.ELYTRA)
|
||||||
|
if (nbtEditor.getArmorTier(is) != ArmorTier.NONE)
|
||||||
|
{
|
||||||
|
Bukkit.broadcastMessage("An armored elytra even! Removing now!");
|
||||||
|
inv.remove(is);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChestOpen(InventoryOpenEvent event)
|
||||||
|
{
|
||||||
|
if (event.getInventory().getType().equals(InventoryType.CHEST))
|
||||||
|
{
|
||||||
|
// Slight delay so the inventory has time to get loaded.
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Inventory inv = event.getInventory();
|
||||||
|
int removed = removeArmoredElytras(inv);
|
||||||
|
if (removed != 0)
|
||||||
|
plugin.messagePlayer((Player) (event.getPlayer()), ChatColor.RED, "Removed " + removed + " armored elytras from your chest!");
|
||||||
|
}
|
||||||
|
}.runTaskLater(this.plugin, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLogin(PlayerLoginEvent event)
|
||||||
|
{
|
||||||
|
// Slight delay so the inventory has time to get loaded.
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Inventory inv = event.getPlayer().getInventory();
|
||||||
|
int removed = removeArmoredElytras(inv);
|
||||||
|
if (removed != 0)
|
||||||
|
plugin.messagePlayer((Player) (event.getPlayer()), ChatColor.RED, "Removed " + removed + " armored elytras from your inventory!");
|
||||||
|
}
|
||||||
|
}.runTaskLater(this.plugin, 20);
|
||||||
|
}
|
||||||
|
}
|
@ -2,9 +2,11 @@ package nl.pim16aap2.armoredElytra.nms;
|
|||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
public interface NBTEditor
|
public interface NBTEditor
|
||||||
{
|
{
|
||||||
public ItemStack addArmorNBTTags(ItemStack item, int armorTier);
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable);
|
||||||
|
|
||||||
public int getArmorTier(ItemStack item);
|
public ArmorTier getArmorTier(ItemStack item);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,116 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.nms;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTTagByte;
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTTagInt;
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_10_R1.NBTTagString;
|
||||||
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
|
public class NBTEditor_V1_10_R1 implements NBTEditor
|
||||||
|
{
|
||||||
|
String elytraName;
|
||||||
|
String elytraLore;
|
||||||
|
ArmoredElytra plugin;
|
||||||
|
|
||||||
|
// Get the names and lores for every tier of armor.
|
||||||
|
public NBTEditor_V1_10_R1(String elytraName, String elytraLore, ArmoredElytra plugin)
|
||||||
|
{
|
||||||
|
this.elytraName = elytraName;
|
||||||
|
this.elytraLore = elytraLore;
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add armor to the supplied item, based on the armorTier.
|
||||||
|
@Override
|
||||||
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
|
{
|
||||||
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
|
int armorProtection = ArmorTier.getArmor (armorTier);
|
||||||
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
|
ChatColor color = ArmorTier.getColor (armorTier);
|
||||||
|
|
||||||
|
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
||||||
|
if (elytraLore != null)
|
||||||
|
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInString(elytraLore, armorTier)));
|
||||||
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
|
net.minecraft.server.v1_10_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(armorProtection));
|
||||||
|
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(armorToughness));
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (unbreakable)
|
||||||
|
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
||||||
|
|
||||||
|
compound.set("AttributeModifiers", modifiers);
|
||||||
|
item = CraftItemStack.asBukkitCopy(nmsStack);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the armor tier of the supplied item.
|
||||||
|
@Override
|
||||||
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
|
{
|
||||||
|
// Get the NBT tags from the item.
|
||||||
|
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
||||||
|
if (compound == null)
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
String nbtTags = compound.toString();
|
||||||
|
|
||||||
|
// Check if the item has the generic.armor attribute.
|
||||||
|
// Format = <level>,Slot:"chest",AttributeName:"generic.armor so get pos of char before
|
||||||
|
// The start of the string, as that's the value of the generic.armor attribute.
|
||||||
|
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||||
|
int armorValue = 0;
|
||||||
|
if (pos > 0)
|
||||||
|
{
|
||||||
|
// If so, get the value of the generic.armor attribute.
|
||||||
|
pos--;
|
||||||
|
String stringAtPos = nbtTags.substring(pos, pos+1);
|
||||||
|
armorValue = Integer.parseInt(stringAtPos);
|
||||||
|
} else
|
||||||
|
// Otherwise, the item has no armor, so return 0;
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
|
switch (armorValue)
|
||||||
|
{
|
||||||
|
case 3:
|
||||||
|
return ArmorTier.LEATHER;
|
||||||
|
case 5:
|
||||||
|
return ArmorTier.GOLD;
|
||||||
|
case 6:
|
||||||
|
return ArmorTier.IRON;
|
||||||
|
case 8:
|
||||||
|
return ArmorTier.DIAMOND;
|
||||||
|
default:
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,11 +7,13 @@ import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_11_R1.NBTTagByte;
|
||||||
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
import net.minecraft.server.v1_11_R1.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_11_R1.NBTTagInt;
|
import net.minecraft.server.v1_11_R1.NBTTagInt;
|
||||||
import net.minecraft.server.v1_11_R1.NBTTagList;
|
import net.minecraft.server.v1_11_R1.NBTTagList;
|
||||||
import net.minecraft.server.v1_11_R1.NBTTagString;
|
import net.minecraft.server.v1_11_R1.NBTTagString;
|
||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
public class NBTEditor_V1_11_R1 implements NBTEditor
|
public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||||
{
|
{
|
||||||
@ -29,46 +31,12 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
|||||||
|
|
||||||
// Add armor to the supplied item, based on the armorTier.
|
// Add armor to the supplied item, based on the armorTier.
|
||||||
@Override
|
@Override
|
||||||
public ItemStack addArmorNBTTags(ItemStack item, int armorTier)
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
{
|
{
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
ChatColor color = ChatColor.WHITE;
|
int armorProtection = ArmorTier.getArmor (armorTier);
|
||||||
int armorProtection = 0;
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
int armorToughness = 0;
|
ChatColor color = ArmorTier.getColor (armorTier);
|
||||||
/* 0 = No Armor.
|
|
||||||
* 1 = Leather Armor.
|
|
||||||
* 2 = Gold Armor.
|
|
||||||
* 3 = Chain Armor.
|
|
||||||
* 4 = Iron Armor.
|
|
||||||
* 5 = Diamond Armor.
|
|
||||||
*/
|
|
||||||
// Give the name the correct color.
|
|
||||||
switch (armorTier)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
color = ChatColor.DARK_GREEN;
|
|
||||||
armorProtection = 3;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
color = ChatColor.YELLOW;
|
|
||||||
armorProtection = 5;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
color = ChatColor.DARK_GRAY;
|
|
||||||
armorProtection = 5;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
color = ChatColor.GRAY;
|
|
||||||
armorProtection = 6;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
color = ChatColor.AQUA;
|
|
||||||
armorProtection = 8;
|
|
||||||
armorToughness = 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
color = ChatColor.WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
||||||
if (elytraLore != null)
|
if (elytraLore != null)
|
||||||
@ -98,6 +66,9 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
|||||||
armorTough.set("Slot", new NBTTagString("chest"));
|
armorTough.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armorTough);
|
modifiers.add(armorTough);
|
||||||
|
|
||||||
|
if (unbreakable)
|
||||||
|
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
||||||
|
|
||||||
compound.set("AttributeModifiers", modifiers);
|
compound.set("AttributeModifiers", modifiers);
|
||||||
item = CraftItemStack.asBukkitCopy(nmsStack);
|
item = CraftItemStack.asBukkitCopy(nmsStack);
|
||||||
return item;
|
return item;
|
||||||
@ -105,21 +76,19 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
|||||||
|
|
||||||
// Get the armor tier of the supplied item.
|
// Get the armor tier of the supplied item.
|
||||||
@Override
|
@Override
|
||||||
public int getArmorTier(ItemStack item)
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
{
|
{
|
||||||
int armorTier = 0;
|
|
||||||
int armorValue = 0;
|
|
||||||
|
|
||||||
// Get the NBT tags from the item.
|
// Get the NBT tags from the item.
|
||||||
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
||||||
if (compound == null)
|
if (compound == null)
|
||||||
return 0;
|
return ArmorTier.NONE;
|
||||||
String nbtTags = compound.toString();
|
String nbtTags = compound.toString();
|
||||||
|
|
||||||
// Check if the item has the generic.armor attribute.
|
// Check if the item has the generic.armor attribute.
|
||||||
// Format = <level>,Slot:"chest",AttributeName:"generic.armor so get pos of char before
|
// Format = <level>,Slot:"chest",AttributeName:"generic.armor so get pos of char before
|
||||||
// The start of the string, as that's the value of the generic.armor attribute.
|
// The start of the string, as that's the value of the generic.armor attribute.
|
||||||
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||||
|
int armorValue = 0;
|
||||||
if (pos > 0)
|
if (pos > 0)
|
||||||
{
|
{
|
||||||
// If so, get the value of the generic.armor attribute.
|
// If so, get the value of the generic.armor attribute.
|
||||||
@ -128,23 +97,20 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
|||||||
armorValue = Integer.parseInt(stringAtPos);
|
armorValue = Integer.parseInt(stringAtPos);
|
||||||
} else
|
} else
|
||||||
// Otherwise, the item has no armor, so return 0;
|
// Otherwise, the item has no armor, so return 0;
|
||||||
return 0;
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
switch (armorValue)
|
switch (armorValue)
|
||||||
{
|
{
|
||||||
case 3:
|
case 3:
|
||||||
armorTier = 1;
|
return ArmorTier.LEATHER;
|
||||||
break;
|
|
||||||
case 5:
|
case 5:
|
||||||
armorTier = 2;
|
return ArmorTier.GOLD;
|
||||||
break;
|
|
||||||
case 6:
|
case 6:
|
||||||
armorTier = 4;
|
return ArmorTier.IRON;
|
||||||
break;
|
|
||||||
case 8:
|
case 8:
|
||||||
armorTier = 5;
|
return ArmorTier.DIAMOND;
|
||||||
break;
|
default:
|
||||||
|
return ArmorTier.NONE;
|
||||||
}
|
}
|
||||||
return armorTier;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,13 @@ import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_12_R1.NBTTagByte;
|
||||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_12_R1.NBTTagInt;
|
import net.minecraft.server.v1_12_R1.NBTTagInt;
|
||||||
import net.minecraft.server.v1_12_R1.NBTTagList;
|
import net.minecraft.server.v1_12_R1.NBTTagList;
|
||||||
import net.minecraft.server.v1_12_R1.NBTTagString;
|
import net.minecraft.server.v1_12_R1.NBTTagString;
|
||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
public class NBTEditor_V1_12_R1 implements NBTEditor
|
public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||||
{
|
{
|
||||||
@ -29,46 +31,12 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
|||||||
|
|
||||||
// Add armor to the supplied item, based on the armorTier.
|
// Add armor to the supplied item, based on the armorTier.
|
||||||
@Override
|
@Override
|
||||||
public ItemStack addArmorNBTTags(ItemStack item, int armorTier)
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
{
|
{
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
ChatColor color = ChatColor.WHITE;
|
int armorProtection = ArmorTier.getArmor (armorTier);
|
||||||
int armorProtection = 0;
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
int armorToughness = 0;
|
ChatColor color = ArmorTier.getColor (armorTier);
|
||||||
/* 0 = No Armor.
|
|
||||||
* 1 = Leather Armor.
|
|
||||||
* 2 = Gold Armor.
|
|
||||||
* 3 = Chain Armor.
|
|
||||||
* 4 = Iron Armor.
|
|
||||||
* 5 = Diamond Armor.
|
|
||||||
*/
|
|
||||||
// Give the name the correct color.
|
|
||||||
switch (armorTier)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
color = ChatColor.DARK_GREEN;
|
|
||||||
armorProtection = 3;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
color = ChatColor.YELLOW;
|
|
||||||
armorProtection = 5;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
color = ChatColor.DARK_GRAY;
|
|
||||||
armorProtection = 5;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
color = ChatColor.GRAY;
|
|
||||||
armorProtection = 6;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
color = ChatColor.AQUA;
|
|
||||||
armorProtection = 8;
|
|
||||||
armorToughness = 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
color = ChatColor.WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
itemmeta.setDisplayName(color+plugin.fillInArmorTierInString(elytraName, armorTier));
|
||||||
if (elytraLore != null)
|
if (elytraLore != null)
|
||||||
@ -98,6 +66,9 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
|||||||
armorTough.set("Slot", new NBTTagString("chest"));
|
armorTough.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armorTough);
|
modifiers.add(armorTough);
|
||||||
|
|
||||||
|
if (unbreakable)
|
||||||
|
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
||||||
|
|
||||||
compound.set("AttributeModifiers", modifiers);
|
compound.set("AttributeModifiers", modifiers);
|
||||||
item = CraftItemStack.asBukkitCopy(nmsStack);
|
item = CraftItemStack.asBukkitCopy(nmsStack);
|
||||||
return item;
|
return item;
|
||||||
@ -105,19 +76,19 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
|||||||
|
|
||||||
// Get the armor tier of the supplied item.
|
// Get the armor tier of the supplied item.
|
||||||
@Override
|
@Override
|
||||||
public int getArmorTier(ItemStack item)
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
{
|
{
|
||||||
int armorTier = 0;
|
|
||||||
int armorValue = 0;
|
|
||||||
|
|
||||||
// Get the NBT tags from the item.
|
// Get the NBT tags from the item.
|
||||||
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
||||||
if (compound == null)
|
if (compound == null)
|
||||||
return 0;
|
return ArmorTier.NONE;
|
||||||
String nbtTags = compound.toString();
|
String nbtTags = compound.toString();
|
||||||
|
|
||||||
// Check if the item has the generic.armor attribute.
|
// Check if the item has the generic.armor attribute.
|
||||||
|
// Format = <level>,Slot:"chest",AttributeName:"generic.armor so get pos of char before
|
||||||
|
// The start of the string, as that's the value of the generic.armor attribute.
|
||||||
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||||
|
int armorValue = 0;
|
||||||
if (pos > 0)
|
if (pos > 0)
|
||||||
{
|
{
|
||||||
// If so, get the value of the generic.armor attribute.
|
// If so, get the value of the generic.armor attribute.
|
||||||
@ -126,23 +97,20 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
|||||||
armorValue = Integer.parseInt(stringAtPos);
|
armorValue = Integer.parseInt(stringAtPos);
|
||||||
} else
|
} else
|
||||||
// Otherwise, the item has no armor, so return 0;
|
// Otherwise, the item has no armor, so return 0;
|
||||||
return 0;
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
switch (armorValue)
|
switch (armorValue)
|
||||||
{
|
{
|
||||||
case 3:
|
case 3:
|
||||||
armorTier = 1;
|
return ArmorTier.LEATHER;
|
||||||
break;
|
|
||||||
case 5:
|
case 5:
|
||||||
armorTier = 2;
|
return ArmorTier.GOLD;
|
||||||
break;
|
|
||||||
case 6:
|
case 6:
|
||||||
armorTier = 4;
|
return ArmorTier.IRON;
|
||||||
break;
|
|
||||||
case 8:
|
case 8:
|
||||||
armorTier = 5;
|
return ArmorTier.DIAMOND;
|
||||||
break;
|
default:
|
||||||
|
return ArmorTier.NONE;
|
||||||
}
|
}
|
||||||
return armorTier;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
47
src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java
Normal file
47
src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.util;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public enum ArmorTier
|
||||||
|
{
|
||||||
|
// Tier: tier armor-value, tier armor-toughness, tier name color , tier name.
|
||||||
|
NONE (0 , 0 , ChatColor.WHITE , "Unarmored"),
|
||||||
|
LEATHER (3 , 0 , ChatColor.DARK_GREEN, "Leather" ),
|
||||||
|
GOLD (5 , 0 , ChatColor.YELLOW , "Gold" ),
|
||||||
|
CHAIN (5 , 0 , ChatColor.DARK_GRAY , "Chain" ),
|
||||||
|
IRON (6 , 0 , ChatColor.GRAY , "Iron" ),
|
||||||
|
DIAMOND (8 , 2 , ChatColor.AQUA , "Diamond" );
|
||||||
|
|
||||||
|
private int armor;
|
||||||
|
private int toughness;
|
||||||
|
private ChatColor color;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
// Create a new chip with the given face and suit
|
||||||
|
private ArmorTier (int armor, int toughness, ChatColor color, String name)
|
||||||
|
{
|
||||||
|
this.armor = armor;
|
||||||
|
this.color = color;
|
||||||
|
this.toughness = toughness;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the armor value of a tier.
|
||||||
|
public static int getArmor (ArmorTier item) { return item.armor; }
|
||||||
|
|
||||||
|
// return the armor toughness of a tier.
|
||||||
|
public static int getToughness (ArmorTier item) { return item.toughness; }
|
||||||
|
|
||||||
|
// return the color of a tier.
|
||||||
|
public static ChatColor getColor (ArmorTier item) { return item.color; }
|
||||||
|
|
||||||
|
// return the name of a tier.
|
||||||
|
public static String getArmorName (ArmorTier item) { return item.name; }
|
||||||
|
|
||||||
|
public static ArmorTier tierFromMat(Material type)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,8 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
|||||||
|
|
||||||
public class ConfigLoader
|
public class ConfigLoader
|
||||||
{
|
{
|
||||||
|
private boolean unbreakable;
|
||||||
|
private boolean noFlightDurability;
|
||||||
private int LEATHER_TO_FULL;
|
private int LEATHER_TO_FULL;
|
||||||
private int GOLD_TO_FULL;
|
private int GOLD_TO_FULL;
|
||||||
private int IRON_TO_FULL;
|
private int IRON_TO_FULL;
|
||||||
@ -25,10 +27,18 @@ public class ConfigLoader
|
|||||||
private String elytraReceivedMessage;
|
private String elytraReceivedMessage;
|
||||||
private boolean checkForUpdates;
|
private boolean checkForUpdates;
|
||||||
private boolean allowStats;
|
private boolean allowStats;
|
||||||
|
private boolean enableDebug;
|
||||||
|
private boolean uninstallMode;
|
||||||
private String elytraName;
|
private String elytraName;
|
||||||
private String elytraLore;
|
private String elytraLore;
|
||||||
|
|
||||||
// All the comments for the various config options.
|
// All the comments for the various config options.
|
||||||
|
private String[] unbreakableComment =
|
||||||
|
{"Setting this to true will cause armored elytras to be unbreakable.",
|
||||||
|
"Changing this to false will NOT make unbreakable elytras breakable again!"};
|
||||||
|
private String[] flyDurabilityComment =
|
||||||
|
{"Setting this to true will cause armored elytras to not lose any durability while flying.",
|
||||||
|
"This is not a permanent option and will affect ALL elytras."};
|
||||||
private String[] repairComment =
|
private String[] repairComment =
|
||||||
{"Amount of items it takes to fully repair an armored elytra",
|
{"Amount of items it takes to fully repair an armored elytra",
|
||||||
"Repair cost for every tier of armored elytra in number of items to repair 100%."};
|
"Repair cost for every tier of armored elytra in number of items to repair 100%."};
|
||||||
@ -53,6 +63,13 @@ public class ConfigLoader
|
|||||||
{"Allow this plugin to check for updates on startup. It will not download new versions!"};
|
{"Allow this plugin to check for updates on startup. It will not download new versions!"};
|
||||||
private String[] bStatsComment =
|
private String[] bStatsComment =
|
||||||
{"Allow this plugin to send (anonymised) stats using bStats."};
|
{"Allow this plugin to send (anonymised) stats using bStats."};
|
||||||
|
private String[] debugComment =
|
||||||
|
{"Print debug messages to console. You will most likely never need this."};
|
||||||
|
private String[] uninstallComment =
|
||||||
|
{"Setting this to true will disable this plugin and remove any armored elytras it can find.",
|
||||||
|
"It will check player's inventories and their end chest upon login and any regular chest when it is opened.",
|
||||||
|
"This means it will take a while for all armored elytras to be removed from your server, but it doesn't take up ",
|
||||||
|
"a lot of resources, so you can just leave it installed and ignore it."};
|
||||||
|
|
||||||
private ArrayList<ConfigOption> configOptionsList;
|
private ArrayList<ConfigOption> configOptionsList;
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
@ -71,34 +88,42 @@ public class ConfigLoader
|
|||||||
|
|
||||||
// Read all the options from the config, then put them in a configOption with their name, value and comment.
|
// Read all the options from the config, then put them in a configOption with their name, value and comment.
|
||||||
// THen put all configOptions into an ArrayList.
|
// THen put all configOptions into an ArrayList.
|
||||||
LEATHER_TO_FULL = config.getInt("leatherRepair", 6);
|
unbreakable = config.getBoolean("unbreakable", false);
|
||||||
|
configOptionsList.add(new ConfigOption ("unbreakable", unbreakable, unbreakableComment));
|
||||||
|
noFlightDurability = config.getBoolean("noFlightDurability", false);
|
||||||
|
configOptionsList.add(new ConfigOption ("noFlightDurability", noFlightDurability, flyDurabilityComment));
|
||||||
|
|
||||||
|
LEATHER_TO_FULL = config.getInt ("leatherRepair", 6);
|
||||||
configOptionsList.add(new ConfigOption("leatherRepair", LEATHER_TO_FULL, repairComment));
|
configOptionsList.add(new ConfigOption("leatherRepair", LEATHER_TO_FULL, repairComment));
|
||||||
GOLD_TO_FULL = config.getInt("goldRepair", 5);
|
GOLD_TO_FULL = config.getInt ("goldRepair", 5);
|
||||||
configOptionsList.add(new ConfigOption("goldRepair", GOLD_TO_FULL));
|
configOptionsList.add(new ConfigOption("goldRepair", GOLD_TO_FULL));
|
||||||
IRON_TO_FULL = config.getInt("ironRepair", 4);
|
IRON_TO_FULL = config.getInt ("ironRepair", 4);
|
||||||
configOptionsList.add(new ConfigOption("ironRepair", IRON_TO_FULL));
|
configOptionsList.add(new ConfigOption("ironRepair", IRON_TO_FULL));
|
||||||
DIAMONDS_TO_FULL = config.getInt("diamondsRepair", 3);
|
DIAMONDS_TO_FULL = config.getInt ("diamondsRepair", 3);
|
||||||
configOptionsList.add(new ConfigOption("diamondsRepair", DIAMONDS_TO_FULL));
|
configOptionsList.add(new ConfigOption("diamondsRepair", DIAMONDS_TO_FULL));
|
||||||
|
|
||||||
cursesAllowed = config.getBoolean("allowCurses", true);
|
cursesAllowed = config.getBoolean ("allowCurses", true);
|
||||||
configOptionsList.add(new ConfigOption("allowCurses", cursesAllowed, cursesComment));
|
configOptionsList.add(new ConfigOption ("allowCurses", cursesAllowed, cursesComment));
|
||||||
allowedEnchantments = config.getStringList("allowedEnchantments");
|
allowedEnchantments = config.getStringList("allowedEnchantments");
|
||||||
|
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment));
|
||||||
configOptionsList.add(new ConfigOption("allowedEnchantments", allowedEnchantments, enchantmentsComment));
|
|
||||||
|
|
||||||
usageDeniedMessage = config.getString("usageDeniedMessage");
|
usageDeniedMessage = config.getString("usageDeniedMessage");
|
||||||
configOptionsList.add(new ConfigOption("usageDeniedMessage", usageDeniedMessage, usageDeniedComment));
|
configOptionsList.add(new ConfigOption ("usageDeniedMessage", usageDeniedMessage, usageDeniedComment));
|
||||||
elytraReceivedMessage = config.getString("elytraReceivedMessage");
|
elytraReceivedMessage = config.getString("elytraReceivedMessage");
|
||||||
configOptionsList.add(new ConfigOption("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
configOptionsList.add(new ConfigOption ("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
||||||
elytraName = config.getString("elytraName");
|
elytraName = config.getString("elytraName");
|
||||||
configOptionsList.add(new ConfigOption("elytraName", elytraName, elytraNameComment));
|
configOptionsList.add(new ConfigOption ("elytraName", elytraName, elytraNameComment));
|
||||||
elytraLore = config.getString("elytraLore");
|
elytraLore = config.getString("elytraLore");
|
||||||
configOptionsList.add(new ConfigOption("elytraLore", elytraLore, elytraLoreComment));
|
configOptionsList.add(new ConfigOption ("elytraLore", elytraLore, elytraLoreComment));
|
||||||
|
|
||||||
checkForUpdates = config.getBoolean("checkForUpdates");
|
checkForUpdates = config.getBoolean("checkForUpdates", true);
|
||||||
configOptionsList.add(new ConfigOption("checkForUpdates", checkForUpdates, updateComment));
|
configOptionsList.add(new ConfigOption ("checkForUpdates", checkForUpdates, updateComment));
|
||||||
allowStats = config.getBoolean("allowStats");
|
allowStats = config.getBoolean("allowStats", true);
|
||||||
configOptionsList.add(new ConfigOption("allowStats", allowStats, bStatsComment));
|
configOptionsList.add(new ConfigOption ("allowStats", allowStats, bStatsComment));
|
||||||
|
enableDebug = config.getBoolean("enableDebug", false);
|
||||||
|
configOptionsList.add(new ConfigOption ("enableDebug", enableDebug, debugComment));
|
||||||
|
uninstallMode = config.getBoolean("uninstallMode", false);
|
||||||
|
configOptionsList.add(new ConfigOption ("uninstallMode", uninstallMode, uninstallComment));
|
||||||
|
|
||||||
writeConfig();
|
writeConfig();
|
||||||
}
|
}
|
||||||
|
@ -75,30 +75,11 @@ public class ConfigOption
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName() { return optionName; }
|
||||||
{
|
public List<String> getStringList() { return listVal ; }
|
||||||
return optionName;
|
public int getInt() { return intVal ; }
|
||||||
}
|
public boolean getBool() { return boolVal ; }
|
||||||
|
public String getString() { return stringVal ; }
|
||||||
public List<String> getStringList()
|
|
||||||
{
|
|
||||||
return listVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInt()
|
|
||||||
{
|
|
||||||
return intVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBool()
|
|
||||||
{
|
|
||||||
return boolVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString()
|
|
||||||
{
|
|
||||||
return stringVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
13
src/main/java/nl/pim16aap2/armoredElytra/util/Util.java
Normal file
13
src/main/java/nl/pim16aap2/armoredElytra/util/Util.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.util;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Util
|
||||||
|
{
|
||||||
|
// Remove item from player's chestplate slot and puts it in their normal inventory.
|
||||||
|
public static void unenquipChestPlayer(Player p)
|
||||||
|
{
|
||||||
|
p.getInventory().addItem(p.getInventory().getChestplate());
|
||||||
|
p.getInventory().getChestplate().setAmount(0);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
|
|
||||||
|
# Setting this to true will cause armored elytras to be unbreakable.
|
||||||
|
unbreakable: false
|
||||||
|
|
||||||
# Amount of items it takes to fully repair an armored elytra
|
# Amount of items it takes to fully repair an armored elytra
|
||||||
# Repair cost for every tier of armored elytra in number of items to repair 100%.
|
# Repair cost for every tier of armored elytra in number of items to repair 100%.
|
||||||
leatherRepair: 6
|
leatherRepair: 6
|
||||||
@ -40,3 +44,9 @@ checkForUpdates: true
|
|||||||
|
|
||||||
# Allow this plugin to send (anonymised) stats using bStats.
|
# Allow this plugin to send (anonymised) stats using bStats.
|
||||||
allowStats: true
|
allowStats: true
|
||||||
|
|
||||||
|
# Setting this to true will disable this plugin and remove any armored elytras it can find.
|
||||||
|
# It will check player's inventories and their end chest upon login and any regular chest when it is opened.
|
||||||
|
# This means it will take a while for all armored elytras to be removed from your server, but it doesn't take up
|
||||||
|
# a lot of resources, so you can just leave it installed and ignore it.
|
||||||
|
uninstall: false
|
@ -1,6 +1,6 @@
|
|||||||
name: ArmoredElytra
|
name: ArmoredElytra
|
||||||
main: nl.pim16aap2.armoredElytra.ArmoredElytra
|
main: nl.pim16aap2.armoredElytra.ArmoredElytra
|
||||||
version: 1.9
|
version: 1.11.9
|
||||||
author: Pim
|
author: Pim
|
||||||
commands:
|
commands:
|
||||||
ArmoredElytra:
|
ArmoredElytra:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user