- 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
37
pom.xml
37
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.pim16aap2</groupId>
|
||||
<artifactId>ArmoredElytra</artifactId>
|
||||
<version>1.9-SNAPSHOT</version>
|
||||
<version>1.11.9-SNAPSHOT</version>
|
||||
|
||||
|
||||
<repositories>
|
||||
@ -21,6 +21,20 @@
|
||||
|
||||
<dependencies>
|
||||
<!--Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
@ -28,13 +42,6 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--bStats -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
@ -43,6 +50,13 @@
|
||||
</dependency>
|
||||
|
||||
<!--Bukkit API -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
@ -56,6 +70,13 @@
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--bStats -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@ -5,59 +5,65 @@ 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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import nl.pim16aap2.armoredElytra.handlers.CommandHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.EventHandlers;
|
||||
import nl.pim16aap2.armoredElytra.handlers.FlyDurabilityHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.LoginHandler;
|
||||
import nl.pim16aap2.armoredElytra.handlers.Uninstaller;
|
||||
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_12_R1;
|
||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
import nl.pim16aap2.armoredElytra.util.ConfigLoader;
|
||||
import nl.pim16aap2.armoredElytra.util.Metrics;
|
||||
import nl.pim16aap2.armoredElytra.util.Update;
|
||||
|
||||
public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
{
|
||||
private NBTEditor nbtEditor;
|
||||
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private boolean upToDate;
|
||||
|
||||
private NBTEditor nbtEditor;
|
||||
private ConfigLoader config;
|
||||
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private boolean upToDate;
|
||||
private boolean uninstallMode;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
config = new ConfigLoader(this);
|
||||
public void onEnable()
|
||||
{
|
||||
// Load the settings from the config file.
|
||||
config = new ConfigLoader(this);
|
||||
|
||||
// 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");
|
||||
elytraName = config.getString("elytraName").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||
elytraLore = config.getString("elytraLore").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");
|
||||
|
||||
// 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);
|
||||
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.
|
||||
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);
|
||||
|
||||
String latestVersion = update.getLatestVersion();
|
||||
@ -67,14 +73,25 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
|
||||
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;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
this.upToDate = true;
|
||||
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?
|
||||
if (config.getBool("allowStats"))
|
||||
@ -82,26 +99,55 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
myLogger(Level.INFO, "Enabling stats!");
|
||||
@SuppressWarnings("unused")
|
||||
Metrics metrics = new Metrics(this);
|
||||
} else
|
||||
}
|
||||
else
|
||||
// Y u do dis? :(
|
||||
myLogger(Level.INFO, "Stats disabled, not laoding stats :(");
|
||||
|
||||
// Log all allowed enchantments.
|
||||
myLogger(Level.INFO, ("Allowed enchantments:"));
|
||||
for (String s : config.getStringList("allowedEnchantments"))
|
||||
{
|
||||
myLogger(Level.INFO, " - " + s);
|
||||
}
|
||||
// Log whether or not curses are allowed.
|
||||
myLogger(Level.INFO, "Curses on armored elytras are " + (config.getBool("allowCurses") ? "" : "not " + "allowed!"));
|
||||
|
||||
|
||||
|
||||
// Load the files for the correct version of Minecraft.
|
||||
if (compatibleMCVer())
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
||||
} else {
|
||||
}
|
||||
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.
|
||||
myLogger(Level.INFO, ("Allowed enchantments:"));
|
||||
for (String s : config.getStringList("allowedEnchantments"))
|
||||
{
|
||||
myLogger(Level.INFO, " - " + s);
|
||||
}
|
||||
// Log whether or not curses are allowed.
|
||||
myLogger(Level.INFO, "Curses on armored elytras are " + (config.getBool("allowCurses") ? "" : "not " + "allowed!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
myLogger(Level.WARNING, "Plugin in uninstall mode!");
|
||||
Bukkit.getPluginManager().registerEvents(new Uninstaller(this, nbtEditor), this);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if this is the latest version of this plugin.
|
||||
@ -128,36 +174,8 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
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.
|
||||
public void usageDeniedMessage(Player player, int armorTier)
|
||||
public void usageDeniedMessage(Player player, ArmorTier armorTier)
|
||||
{
|
||||
if (usageDeniedMessage != null)
|
||||
{
|
||||
@ -167,7 +185,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
}
|
||||
|
||||
// Send the elytraReceivedMessage message to the player.
|
||||
public void elytraReceivedMessage(Player player, int armorTier)
|
||||
public void elytraReceivedMessage(Player player, ArmorTier armorTier)
|
||||
{
|
||||
if (elytraReceivedMessage != null)
|
||||
{
|
||||
@ -177,159 +195,31 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
}
|
||||
|
||||
// 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);
|
||||
String replaced = string.replace("%ARMOR_TIER%", armorTierName);
|
||||
return replaced;
|
||||
return string.replace("%ARMOR_TIER%", ArmorTier.getArmorName(armorTier));
|
||||
}
|
||||
|
||||
// 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
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||
{
|
||||
Player player;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Log message that only gets printed when debugging is enabled in the config file.
|
||||
public void debugMsg(Level level, String str)
|
||||
{
|
||||
if (config.getBool("enableDebug"))
|
||||
myLogger(level, str);
|
||||
}
|
||||
|
||||
// Give the provided player the provided item.
|
||||
public void giveArmoredElytraToPlayer(Player player, ItemStack item)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check + initialize for the correct version of Minecraft.
|
||||
public boolean compatibleMCVer()
|
||||
{
|
||||
@ -338,19 +228,18 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
||||
try
|
||||
{
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
} catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException)
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException whatVersionAreYouUsingException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version.equals("v1_11_R1"))
|
||||
{
|
||||
nbtEditor = new NBTEditor_V1_11_R1(elytraName, elytraLore, this);
|
||||
|
||||
} else if (version.equals("v1_12_R1"))
|
||||
{
|
||||
nbtEditor = new NBTEditor_V1_12_R1(elytraName, elytraLore, this);
|
||||
}
|
||||
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);
|
||||
else if (version.equals("v1_12_R1"))
|
||||
nbtEditor = new NBTEditor_V1_12_R1(elytraName, elytraLore, this);
|
||||
// Return true if compatible.
|
||||
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.Map;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -24,6 +25,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
|
||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
import nl.pim16aap2.armoredElytra.util.Util;
|
||||
|
||||
public class EventHandlers implements Listener
|
||||
{
|
||||
@ -57,45 +60,31 @@ public class EventHandlers implements Listener
|
||||
public void cleanAnvil(AnvilInventory anvilInventory)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Check if the enchantment is allowed on elytras.
|
||||
public boolean isAllowedEnchantment(Enchantment enchant)
|
||||
{
|
||||
for (String s : allowedEnchantments)
|
||||
{
|
||||
if (Enchantment.getByName(s) != null)
|
||||
{
|
||||
if (Enchantment.getByName(s).equals(enchant))
|
||||
{
|
||||
for (String s : allowedEnchantments)
|
||||
if (Enchantment.getByName(s) != null)
|
||||
if (Enchantment.getByName(s).equals(enchant))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the enchantment is a curse.
|
||||
public boolean isCursedEnchantment(Enchantment enchant)
|
||||
{
|
||||
for (String s : cursedEnchantments)
|
||||
{
|
||||
if (Enchantment.getByName(s).equals(enchant))
|
||||
{
|
||||
for (String s : cursedEnchantments)
|
||||
if (Enchantment.getByName(s).equals(enchant))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the elytra being checked is an armored one.
|
||||
public boolean isArmoredElytra(ItemStack elytra)
|
||||
{
|
||||
return (nbtEditor.getArmorTier(elytra) == 0 ? false : true);
|
||||
}
|
||||
|
||||
// Copy enchants of 2 items to one item.
|
||||
public ItemStack addEnchants(ItemStack itemOne, ItemStack itemTwo, Player player)
|
||||
{
|
||||
@ -104,22 +93,19 @@ public class EventHandlers implements Listener
|
||||
|
||||
// Get the enchantments of the first and second item in the anvil.
|
||||
Map<Enchantment, Integer> enchantmentsTemp = itemOne.getEnchantments();
|
||||
Map<Enchantment, Integer> enchantments0 = new HashMap<Enchantment, Integer>();
|
||||
Map<Enchantment, Integer> enchantments1 = itemTwo.getEnchantments();
|
||||
Map<Enchantment, Integer> enchantments0 = new HashMap<Enchantment, Integer>();
|
||||
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.
|
||||
if (isAllowedEnchantment(entry.getKey()) || (cursesAllowed && isCursedEnchantment(entry.getKey())))
|
||||
{
|
||||
enchantments0.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// Add the enchantments copied from itemOne to the resulting item.
|
||||
result.addUnsafeEnchantments(enchantments0);
|
||||
|
||||
// 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();
|
||||
enchantments1 = meta.getStoredEnchants();
|
||||
@ -129,17 +115,16 @@ public class EventHandlers implements Listener
|
||||
if (enchantments1!=null)
|
||||
{
|
||||
// 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 (isCursedEnchantment(entry.getKey()) && !result.containsEnchantment(entry.getKey()))
|
||||
{
|
||||
// If curses are allowed, apply the curse to the result.
|
||||
if (cursesAllowed)
|
||||
{
|
||||
result.addEnchantment(entry.getKey(), entry.getValue());
|
||||
}
|
||||
} else if (isAllowedEnchantment(entry.getKey()))
|
||||
}
|
||||
else if (isAllowedEnchantment(entry.getKey()))
|
||||
{
|
||||
int enchantLevel = entry.getValue();
|
||||
// If item0 and item1 both have the same enchantment at the same level, result has level+1.
|
||||
@ -147,18 +132,15 @@ public class EventHandlers implements Listener
|
||||
if (enchantments0 != null)
|
||||
{
|
||||
// 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 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())
|
||||
{
|
||||
enchantLevel = entry.getValue()+1;
|
||||
} else if (entry.getValue() < rentry.getValue())
|
||||
{
|
||||
enchantLevel = entry.getValue() + 1;
|
||||
else if (entry.getValue() < rentry.getValue())
|
||||
enchantLevel = rentry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,25 +160,20 @@ public class EventHandlers implements Listener
|
||||
// Get the multiplier for the repair items.
|
||||
double mult = 0.01;
|
||||
if (two.getType() == Material.LEATHER)
|
||||
{
|
||||
mult *= (100/LEATHER_TO_FULL);
|
||||
|
||||
} else if (two.getType() == Material.GOLD_INGOT)
|
||||
{
|
||||
|
||||
else if (two.getType() == Material.GOLD_INGOT)
|
||||
mult *= (100/GOLD_TO_FULL);
|
||||
|
||||
} else if (two.getType() == Material.IRON_INGOT)
|
||||
{
|
||||
|
||||
else if (two.getType() == Material.IRON_INGOT)
|
||||
mult *= (100/IRON_TO_FULL);
|
||||
|
||||
} else if (two.getType() == Material.DIAMOND)
|
||||
{
|
||||
|
||||
else if (two.getType() == Material.DIAMOND)
|
||||
mult *= (100/DIAMONDS_TO_FULL);
|
||||
}
|
||||
|
||||
int maxDurability = one.getType().getMaxDurability();
|
||||
int durability = one.getDurability();
|
||||
int newDurability = (int) (durability - (maxDurability*mult));
|
||||
int newDurability = (int) (durability - (maxDurability * mult));
|
||||
result.setDurability((short) (newDurability <= 0 ? 0 : newDurability));
|
||||
return result;
|
||||
}
|
||||
@ -211,7 +188,21 @@ public class EventHandlers implements Listener
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
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
|
||||
|
||||
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 (e.isShiftClick())
|
||||
{
|
||||
p.getInventory().addItem(anvilInventory.getItem(2));
|
||||
} else
|
||||
{
|
||||
else
|
||||
p.setItemOnCursor(anvilInventory.getItem(2));
|
||||
}
|
||||
// Clean the anvil's inventory after transferring the items.
|
||||
cleanAnvil(anvilInventory);
|
||||
}
|
||||
@ -236,8 +224,7 @@ public class EventHandlers implements Listener
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
{
|
||||
ItemStack itemA = anvilInventory.getItem(0);
|
||||
ItemStack itemB = anvilInventory.getItem(1);
|
||||
ItemStack result = null;
|
||||
@ -259,19 +246,8 @@ public class EventHandlers implements Listener
|
||||
// Check if the first input slot contains an elytra.
|
||||
if (itemA.getType() == Material.ELYTRA)
|
||||
{
|
||||
int armorTier = 0;
|
||||
int currentArmorTier = 0;
|
||||
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.
|
||||
*/
|
||||
ArmorTier armorTier = ArmorTier.NONE;
|
||||
ArmorTier currentArmorTier = nbtEditor.getArmorTier(itemA);
|
||||
// Check if the second input slot contains a diamond chestplate.
|
||||
if (itemB.getType() == Material.LEATHER_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.
|
||||
result = addEnchants(itemA, itemB, p);
|
||||
if (itemB.getType() == Material.LEATHER_CHESTPLATE)
|
||||
{
|
||||
armorTier = 1;
|
||||
} else if (itemB.getType() == Material.GOLD_CHESTPLATE)
|
||||
{
|
||||
armorTier = 2;
|
||||
} else if (itemB.getType() == Material.CHAINMAIL_CHESTPLATE)
|
||||
{
|
||||
armorTier = 3;
|
||||
} else if (itemB.getType() == Material.IRON_CHESTPLATE)
|
||||
{
|
||||
armorTier = 4;
|
||||
} else if (itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
||||
{
|
||||
armorTier = 5;
|
||||
}
|
||||
short durability = (short) (-itemA.getType().getMaxDurability() - itemA.getDurability() - itemB.getDurability());
|
||||
|
||||
if (itemB.getType() == Material.LEATHER_CHESTPLATE)
|
||||
armorTier = ArmorTier.LEATHER;
|
||||
else if (itemB.getType() == Material.GOLD_CHESTPLATE)
|
||||
armorTier = ArmorTier.GOLD;
|
||||
else if (itemB.getType() == Material.CHAINMAIL_CHESTPLATE)
|
||||
armorTier = ArmorTier.CHAIN;
|
||||
else if (itemB.getType() == Material.IRON_CHESTPLATE)
|
||||
armorTier = ArmorTier.IRON;
|
||||
else if (itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
||||
armorTier = ArmorTier.DIAMOND;
|
||||
|
||||
short durability = (short) (- itemA.getType().getMaxDurability() - itemA.getDurability() - itemB.getDurability());
|
||||
durability = durability < 0 ? 0 : 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 repair item is leather it can only repair
|
||||
else if ((itemB.getType() == Material.LEATHER && isArmoredElytra(itemA) && currentArmorTier == 1) ||
|
||||
(itemB.getType() == Material.GOLD_INGOT && isArmoredElytra(itemA) && currentArmorTier == 2) ||
|
||||
(itemB.getType() == Material.IRON_INGOT && isArmoredElytra(itemA) && currentArmorTier == 3) ||
|
||||
(itemB.getType() == Material.IRON_INGOT && isArmoredElytra(itemA) && currentArmorTier == 4) ||
|
||||
(itemB.getType() == Material.DIAMOND && isArmoredElytra(itemA) && currentArmorTier == 5))
|
||||
else if ((itemB.getType() == Material.LEATHER && currentArmorTier == ArmorTier.LEATHER) ||
|
||||
(itemB.getType() == Material.GOLD_INGOT && currentArmorTier == ArmorTier.GOLD ) ||
|
||||
(itemB.getType() == Material.IRON_INGOT && currentArmorTier == ArmorTier.IRON ) ||
|
||||
(itemB.getType() == Material.IRON_INGOT && currentArmorTier == ArmorTier.CHAIN ) ||
|
||||
(itemB.getType() == Material.DIAMOND && currentArmorTier == ArmorTier.DIAMOND))
|
||||
{
|
||||
// Repair the item in the first input slot with items from the second input slot.
|
||||
result = repairItem(itemA, itemB);
|
||||
}
|
||||
// Check if it is an enchanted book for itemB.
|
||||
else if (itemB.getType() == Material.ENCHANTED_BOOK)
|
||||
{
|
||||
result = addEnchants(itemA, itemB, p);
|
||||
}
|
||||
|
||||
// Otherwise, remove the item in the result slot (slot2).
|
||||
else
|
||||
{
|
||||
if (anvilInventory.getItem(2)!=null)
|
||||
{
|
||||
anvilInventory.getItem(2).setAmount(0);
|
||||
}
|
||||
}
|
||||
else if (anvilInventory.getItem(2) != null)
|
||||
anvilInventory.getItem(2).setAmount(0);
|
||||
|
||||
// Put the created item in the second slot of the anvil.
|
||||
if (result!=null)
|
||||
{
|
||||
@ -335,11 +302,13 @@ public class EventHandlers implements Listener
|
||||
itemB.getType() == Material.DIAMOND_CHESTPLATE)
|
||||
{
|
||||
// Add the NBT Tags for the elytra, to give it diamond_chestplate tier of armor protection.
|
||||
result = nbtEditor.addArmorNBTTags(result, armorTier);
|
||||
} else if (isArmoredElytra(itemA) && !isArmoredElytra(result))
|
||||
result = nbtEditor.addArmorNBTTags(result, armorTier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||
}
|
||||
else if ((nbtEditor.getArmorTier(itemA) != ArmorTier.NONE) &&
|
||||
(nbtEditor.getArmorTier(result) != ArmorTier.NONE))
|
||||
{
|
||||
armorTier = nbtEditor.getArmorTier(itemA);
|
||||
result = nbtEditor.addArmorNBTTags(result, armorTier);
|
||||
result = nbtEditor.addArmorNBTTags(result, armorTier, plugin.getConfigLoader().getBool("unbreakable"));
|
||||
}
|
||||
anvilInventory.setItem(2, result);
|
||||
}
|
||||
@ -347,72 +316,17 @@ public class EventHandlers implements Listener
|
||||
}
|
||||
// Check if either itemA or itemB is unoccupied.
|
||||
if (itemA == null || itemB == null)
|
||||
{
|
||||
// If Item2 is occupied despite Item1 not being occupied.
|
||||
if (anvilInventory.getItem(2) != null)
|
||||
{
|
||||
// Then set the amount to 0.
|
||||
anvilInventory.getItem(2).setAmount(0);
|
||||
}
|
||||
}
|
||||
p.updateInventory();
|
||||
}
|
||||
}.runTaskLater(this.plugin, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -423,22 +337,20 @@ public class EventHandlers implements Listener
|
||||
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
if (item.getType() == Material.ELYTRA && isArmoredElytra(item))
|
||||
if (item != null)
|
||||
if (item.getType() == Material.ELYTRA && (nbtEditor.getArmorTier(item) != ArmorTier.NONE))
|
||||
{
|
||||
int armorTier = nbtEditor.getArmorTier(item);
|
||||
if ((armorTier == 1 && !player.hasPermission("armoredelytra.wear.leather")) ||
|
||||
(armorTier == 2 && !player.hasPermission("armoredelytra.wear.gold")) ||
|
||||
(armorTier == 3 && !player.hasPermission("armoredelytra.wear.chain")) ||
|
||||
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
|
||||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
|
||||
ArmorTier armorTier = nbtEditor.getArmorTier(item);
|
||||
if ((armorTier == ArmorTier.LEATHER && !player.hasPermission("armoredelytra.wear.leather")) ||
|
||||
(armorTier == ArmorTier.GOLD && !player.hasPermission("armoredelytra.wear.gold")) ||
|
||||
(armorTier == ArmorTier.CHAIN && !player.hasPermission("armoredelytra.wear.chain")) ||
|
||||
(armorTier == ArmorTier.IRON && !player.hasPermission("armoredelytra.wear.iron")) ||
|
||||
(armorTier == ArmorTier.DIAMOND && !player.hasPermission("armoredelytra.wear.diamond")))
|
||||
{
|
||||
plugin.usageDeniedMessage(player, armorTier);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Player closes their inventory. Also checks for whether they are allowed to wear the armored elytra they are wearing.
|
||||
@ -457,27 +369,80 @@ public class EventHandlers implements Listener
|
||||
if (player.getInventory().getChestplate() != null)
|
||||
{
|
||||
// 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()))
|
||||
{
|
||||
plugin.messagePlayer(player, ChatColor.RED + "You cannot equip this elytra! Please repair it in an anvil first.");
|
||||
unenquipChestPlayer(player);
|
||||
} else if ((armorTier == 1 && !player.hasPermission("armoredelytra.wear.leather")) ||
|
||||
(armorTier == 2 && !player.hasPermission("armoredelytra.wear.gold")) ||
|
||||
(armorTier == 3 && !player.hasPermission("armoredelytra.wear.chain")) ||
|
||||
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
|
||||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
|
||||
Util.unenquipChestPlayer(player);
|
||||
}
|
||||
else if ((armorTier == ArmorTier.LEATHER && !player.hasPermission("armoredelytra.wear.leather")) ||
|
||||
(armorTier == ArmorTier.GOLD && !player.hasPermission("armoredelytra.wear.gold" )) ||
|
||||
(armorTier == ArmorTier.CHAIN && !player.hasPermission("armoredelytra.wear.chain" )) ||
|
||||
(armorTier == ArmorTier.IRON && !player.hasPermission("armoredelytra.wear.iron" )) ||
|
||||
(armorTier == ArmorTier.DIAMOND && !player.hasPermission("armoredelytra.wear.diamond")))
|
||||
{
|
||||
plugin.usageDeniedMessage(player, armorTier);
|
||||
unenquipChestPlayer(player);
|
||||
Util.unenquipChestPlayer(player);
|
||||
}
|
||||
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).
|
||||
@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;
|
||||
|
||||
public class LoginHandler implements Listener {
|
||||
public class LoginHandler implements Listener
|
||||
{
|
||||
|
||||
ArmoredElytra plugin;
|
||||
String message;
|
||||
|
||||
public LoginHandler(ArmoredElytra plugin)
|
||||
public LoginHandler(ArmoredElytra plugin, String message)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.plugin = plugin;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(PlayerLoginEvent event)
|
||||
{
|
||||
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()
|
||||
{
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
@ -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 nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
|
||||
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.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.NBTTagInt;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagList;
|
||||
import net.minecraft.server.v1_11_R1.NBTTagString;
|
||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
|
||||
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.
|
||||
@Override
|
||||
public ItemStack addArmorNBTTags(ItemStack item, int armorTier)
|
||||
{
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ChatColor color = ChatColor.WHITE;
|
||||
int armorProtection = 0;
|
||||
int armorToughness = 0;
|
||||
/* 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;
|
||||
}
|
||||
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)
|
||||
@ -76,28 +44,31 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
net.minecraft.server.v1_11_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||
NBTTagList modifiers = new NBTTagList();
|
||||
NBTTagCompound armor = new NBTTagCompound();
|
||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||
armor.set("Name", new NBTTagString("generic.armor"));
|
||||
armor.set("Amount", new NBTTagInt(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"));
|
||||
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();
|
||||
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"));
|
||||
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;
|
||||
@ -105,21 +76,19 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||
|
||||
// Get the armor tier of the supplied item.
|
||||
@Override
|
||||
public int getArmorTier(ItemStack item)
|
||||
{
|
||||
int armorTier = 0;
|
||||
int armorValue = 0;
|
||||
|
||||
public ArmorTier getArmorTier(ItemStack item)
|
||||
{
|
||||
// Get the NBT tags from the item.
|
||||
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
||||
if (compound == null)
|
||||
return 0;
|
||||
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.
|
||||
@ -128,23 +97,20 @@ public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||
armorValue = Integer.parseInt(stringAtPos);
|
||||
} else
|
||||
// Otherwise, the item has no armor, so return 0;
|
||||
return 0;
|
||||
return ArmorTier.NONE;
|
||||
|
||||
switch (armorValue)
|
||||
{
|
||||
case 3:
|
||||
armorTier = 1;
|
||||
break;
|
||||
return ArmorTier.LEATHER;
|
||||
case 5:
|
||||
armorTier = 2;
|
||||
break;
|
||||
return ArmorTier.GOLD;
|
||||
case 6:
|
||||
armorTier = 4;
|
||||
break;
|
||||
return ArmorTier.IRON;
|
||||
case 8:
|
||||
armorTier = 5;
|
||||
break;
|
||||
return ArmorTier.DIAMOND;
|
||||
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.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.NBTTagInt;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagList;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagString;
|
||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||
|
||||
public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||
{
|
||||
@ -29,75 +31,44 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||
|
||||
// Add armor to the supplied item, based on the armorTier.
|
||||
@Override
|
||||
public ItemStack addArmorNBTTags(ItemStack item, int armorTier)
|
||||
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||
{
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ChatColor color = ChatColor.WHITE;
|
||||
int armorProtection = 0;
|
||||
int armorToughness = 0;
|
||||
/* 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 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_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||
NBTTagList modifiers = new NBTTagList();
|
||||
NBTTagCompound armor = new NBTTagCompound();
|
||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||
armor.set("Name", new NBTTagString("generic.armor"));
|
||||
armor.set("Amount", new NBTTagInt(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"));
|
||||
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();
|
||||
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"));
|
||||
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;
|
||||
@ -105,19 +76,19 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||
|
||||
// Get the armor tier of the supplied item.
|
||||
@Override
|
||||
public int getArmorTier(ItemStack item)
|
||||
{
|
||||
int armorTier = 0;
|
||||
int armorValue = 0;
|
||||
|
||||
public ArmorTier getArmorTier(ItemStack item)
|
||||
{
|
||||
// Get the NBT tags from the item.
|
||||
NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag();
|
||||
if (compound == null)
|
||||
return 0;
|
||||
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.
|
||||
@ -126,23 +97,20 @@ public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||
armorValue = Integer.parseInt(stringAtPos);
|
||||
} else
|
||||
// Otherwise, the item has no armor, so return 0;
|
||||
return 0;
|
||||
return ArmorTier.NONE;
|
||||
|
||||
switch (armorValue)
|
||||
{
|
||||
case 3:
|
||||
armorTier = 1;
|
||||
break;
|
||||
return ArmorTier.LEATHER;
|
||||
case 5:
|
||||
armorTier = 2;
|
||||
break;
|
||||
return ArmorTier.GOLD;
|
||||
case 6:
|
||||
armorTier = 4;
|
||||
break;
|
||||
return ArmorTier.IRON;
|
||||
case 8:
|
||||
armorTier = 5;
|
||||
break;
|
||||
return ArmorTier.DIAMOND;
|
||||
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,44 +15,61 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||
|
||||
public class ConfigLoader
|
||||
{
|
||||
private int LEATHER_TO_FULL;
|
||||
private int GOLD_TO_FULL;
|
||||
private int IRON_TO_FULL;
|
||||
private int DIAMONDS_TO_FULL;
|
||||
private boolean cursesAllowed;
|
||||
private boolean unbreakable;
|
||||
private boolean noFlightDurability;
|
||||
private int LEATHER_TO_FULL;
|
||||
private int GOLD_TO_FULL;
|
||||
private int IRON_TO_FULL;
|
||||
private int DIAMONDS_TO_FULL;
|
||||
private boolean cursesAllowed;
|
||||
private List<String> allowedEnchantments;
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private boolean checkForUpdates;
|
||||
private boolean allowStats;
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
private String usageDeniedMessage;
|
||||
private String elytraReceivedMessage;
|
||||
private boolean checkForUpdates;
|
||||
private boolean allowStats;
|
||||
private boolean enableDebug;
|
||||
private boolean uninstallMode;
|
||||
private String elytraName;
|
||||
private String elytraLore;
|
||||
|
||||
// All the comments for the various config options.
|
||||
private String[] repairComment =
|
||||
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 =
|
||||
{"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%."};
|
||||
private String[] cursesComment =
|
||||
private String[] cursesComment =
|
||||
{"Will curses (vanishing, binding) be transferred when creating armored elytras?"};
|
||||
private String[] enchantmentsComment =
|
||||
private String[] enchantmentsComment =
|
||||
{"List of enchantments that are allowed to be put on an armored elytra.",
|
||||
"If you do not want to allow any enchantments, remove them all and add \"NONE\"",
|
||||
"You can find supported enchantments here:",
|
||||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html"};
|
||||
private String[] usageDeniedComment =
|
||||
private String[] usageDeniedComment =
|
||||
{"Message players receive when they lack the required permissions to wear a certain armor tier. \"NONE\" = no message. ",
|
||||
"%ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] elytraReceivedComment =
|
||||
{"Message players receive when they are given an armored elytra using commands. \"NONE\" = no message. ",
|
||||
"%ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] elytraNameComment =
|
||||
private String[] elytraNameComment =
|
||||
{"The name of armored elytras. %ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] elytraLoreComment =
|
||||
private String[] elytraLoreComment =
|
||||
{"The lore of armored elytras. \"NONE\" = no lore. %ARMOR_TIER% is replaced by the name of the armor tier."};
|
||||
private String[] updateComment =
|
||||
private String[] updateComment =
|
||||
{"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."};
|
||||
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 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.
|
||||
// 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));
|
||||
GOLD_TO_FULL = config.getInt("goldRepair", 5);
|
||||
GOLD_TO_FULL = config.getInt ("goldRepair", 5);
|
||||
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));
|
||||
DIAMONDS_TO_FULL = config.getInt("diamondsRepair", 3);
|
||||
DIAMONDS_TO_FULL = config.getInt ("diamondsRepair", 3);
|
||||
configOptionsList.add(new ConfigOption("diamondsRepair", DIAMONDS_TO_FULL));
|
||||
|
||||
cursesAllowed = config.getBoolean("allowCurses", true);
|
||||
configOptionsList.add(new ConfigOption("allowCurses", cursesAllowed, cursesComment));
|
||||
allowedEnchantments = config.getStringList("allowedEnchantments");
|
||||
cursesAllowed = config.getBoolean ("allowCurses", true);
|
||||
configOptionsList.add(new ConfigOption ("allowCurses", cursesAllowed, cursesComment));
|
||||
allowedEnchantments = config.getStringList("allowedEnchantments");
|
||||
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment));
|
||||
|
||||
configOptionsList.add(new ConfigOption("allowedEnchantments", allowedEnchantments, enchantmentsComment));
|
||||
|
||||
usageDeniedMessage = config.getString("usageDeniedMessage");
|
||||
configOptionsList.add(new ConfigOption("usageDeniedMessage", usageDeniedMessage, usageDeniedComment));
|
||||
configOptionsList.add(new ConfigOption ("usageDeniedMessage", usageDeniedMessage, usageDeniedComment));
|
||||
elytraReceivedMessage = config.getString("elytraReceivedMessage");
|
||||
configOptionsList.add(new ConfigOption("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
||||
configOptionsList.add(new ConfigOption ("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
||||
elytraName = config.getString("elytraName");
|
||||
configOptionsList.add(new ConfigOption("elytraName", elytraName, elytraNameComment));
|
||||
configOptionsList.add(new ConfigOption ("elytraName", elytraName, elytraNameComment));
|
||||
elytraLore = config.getString("elytraLore");
|
||||
configOptionsList.add(new ConfigOption("elytraLore", elytraLore, elytraLoreComment));
|
||||
|
||||
checkForUpdates = config.getBoolean("checkForUpdates");
|
||||
configOptionsList.add(new ConfigOption("checkForUpdates", checkForUpdates, updateComment));
|
||||
allowStats = config.getBoolean("allowStats");
|
||||
configOptionsList.add(new ConfigOption("allowStats", allowStats, bStatsComment));
|
||||
configOptionsList.add(new ConfigOption ("elytraLore", elytraLore, elytraLoreComment));
|
||||
|
||||
checkForUpdates = config.getBoolean("checkForUpdates", true);
|
||||
configOptionsList.add(new ConfigOption ("checkForUpdates", checkForUpdates, updateComment));
|
||||
allowStats = config.getBoolean("allowStats", true);
|
||||
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();
|
||||
}
|
||||
@ -123,7 +148,7 @@ public class ConfigLoader
|
||||
saveTo.delete();
|
||||
saveTo.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(saveTo, true);
|
||||
FileWriter fw = new FileWriter(saveTo, true);
|
||||
PrintWriter pw = new PrintWriter(fw);
|
||||
|
||||
for (ConfigOption configOption : configOptionsList)
|
||||
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
public class ConfigOption
|
||||
{
|
||||
private String optionName;
|
||||
List<String> listVal = null;
|
||||
private Integer intVal = null;
|
||||
private Boolean boolVal = null;
|
||||
private String stringVal = null;
|
||||
private String[] comment;
|
||||
List<String> listVal = null;
|
||||
private Integer intVal = null;
|
||||
private Boolean boolVal = null;
|
||||
private String stringVal = null;
|
||||
private String[] comment;
|
||||
|
||||
public ConfigOption(String optionName, int value, String[] comment)
|
||||
{
|
||||
@ -75,30 +75,11 @@ public class ConfigOption
|
||||
return string;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return optionName;
|
||||
}
|
||||
|
||||
public List<String> getStringList()
|
||||
{
|
||||
return listVal;
|
||||
}
|
||||
|
||||
public int getInt()
|
||||
{
|
||||
return intVal;
|
||||
}
|
||||
|
||||
public boolean getBool()
|
||||
{
|
||||
return boolVal;
|
||||
}
|
||||
|
||||
public String getString()
|
||||
{
|
||||
return stringVal;
|
||||
}
|
||||
public String getName() { return optionName; }
|
||||
public List<String> getStringList() { return listVal ; }
|
||||
public int getInt() { return intVal ; }
|
||||
public boolean getBool() { return boolVal ; }
|
||||
public String getString() { return stringVal ; }
|
||||
|
||||
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
|
||||
# Repair cost for every tier of armored elytra in number of items to repair 100%.
|
||||
leatherRepair: 6
|
||||
@ -39,4 +43,10 @@ elytraLore: 'Elytra with %ARMOR_TIER% level protection'
|
||||
checkForUpdates: true
|
||||
|
||||
# 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
|
||||
main: nl.pim16aap2.armoredElytra.ArmoredElytra
|
||||
version: 1.9
|
||||
version: 1.11.9
|
||||
author: Pim
|
||||
commands:
|
||||
ArmoredElytra:
|
||||
|
Loading…
x
Reference in New Issue
Block a user