QoL Improvements, bug fixes.
- Fixed 1.13 and 1.13.1/1.13.2 bug with armor value retrieval (nbt changed in 1.13). - Added en_US.txt as translation file for easier translation stuff. - Moved more strings to translation file. - Added 1.13.1 and 1.13.2 support.
This commit is contained in:
parent
c3546c777c
commit
e35c251827
8
pom.xml
8
pom.xml
@ -2,7 +2,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>nl.pim16aap2</groupId>
|
<groupId>nl.pim16aap2</groupId>
|
||||||
<artifactId>ArmoredElytra</artifactId>
|
<artifactId>ArmoredElytra</artifactId>
|
||||||
<version>2.4.2-SNAPSHOT</version>
|
<version>2.4.6-SNAPSHOT</version>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@ -40,6 +40,12 @@
|
|||||||
<version>1.13-R0.1-SNAPSHOT</version>
|
<version>1.13-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-1.13.1</artifactId>
|
||||||
|
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--bStats -->
|
<!--bStats -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -20,234 +20,243 @@ 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.nms.NBTEditor_V1_13_R1;
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_13_R1;
|
||||||
|
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_13_R2;
|
||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
import nl.pim16aap2.armoredElytra.util.ConfigLoader;
|
import nl.pim16aap2.armoredElytra.util.ConfigLoader;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.Messages;
|
||||||
import nl.pim16aap2.armoredElytra.util.Metrics;
|
import nl.pim16aap2.armoredElytra.util.Metrics;
|
||||||
import nl.pim16aap2.armoredElytra.util.Update;
|
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 Messages messages;
|
||||||
|
private ConfigLoader config;
|
||||||
|
|
||||||
private String usageDeniedMessage;
|
private String leatherName, ironName, goldName, chainName, diamondName;
|
||||||
private String elytraReceivedMessage;
|
private String elytraReceivedMessage;
|
||||||
private String elytraLore;
|
private String usageDeniedMessage;
|
||||||
private boolean upToDate;
|
private boolean uninstallMode;
|
||||||
private boolean uninstallMode;
|
private String elytraLore;
|
||||||
private String leatherName, ironName, goldName, chainName, diamondName;
|
private boolean upToDate;
|
||||||
|
private String locale;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
readConfigValues();
|
this.readConfigValues();
|
||||||
|
this.messages = new Messages(this);
|
||||||
|
this.readMessages();
|
||||||
|
|
||||||
// Check if the user allows checking for updates.
|
// Check if the user allows checking for updates.
|
||||||
if (config.getBool("checkForUpdates"))
|
if (config.getBool("checkForUpdates"))
|
||||||
{
|
{
|
||||||
// Check for updates in a new thread, so the server won't hang when it cannot contact the update servers.
|
// Check for updates in a new thread, so the server won't hang when it cannot contact the update servers.
|
||||||
Thread thread = new Thread(new Runnable()
|
Thread thread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ArmoredElytra plugin = getPlugin();
|
ArmoredElytra plugin = getPlugin();
|
||||||
Update update = new Update(278437, plugin);
|
Update update = new Update(278437, plugin);
|
||||||
String latestVersion = update.getLatestVersion();
|
String latestVersion = update.getLatestVersion();
|
||||||
|
|
||||||
if (latestVersion == null)
|
if (latestVersion == null)
|
||||||
plugin.myLogger(Level.WARNING, "Encountered problem contacting update servers! Please check manually! The error above does not affect the plugin!");
|
plugin.myLogger(Level.WARNING, "Encountered problem contacting update servers! Please check manually! The error above does not affect the plugin!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String thisVersion = plugin.getDescription().getVersion();
|
String thisVersion = plugin.getDescription().getVersion();
|
||||||
// Check if this is the latest version or not.
|
// Check if this is the latest version or not.
|
||||||
int updateStatus = update.versionCompare(latestVersion, thisVersion);
|
int updateStatus = update.versionCompare(latestVersion, thisVersion);
|
||||||
|
|
||||||
if (updateStatus > 0)
|
if (updateStatus > 0)
|
||||||
{
|
{
|
||||||
// TODO: Insert download link to latest version.
|
// Load the loginHandler to show messages to the user when they join.
|
||||||
// TODO: Use Spiget as backup?
|
Bukkit.getPluginManager().registerEvents(new LoginHandler(plugin, "The Armored Elytra plugin is out of date!"), plugin);
|
||||||
// TODO: Add auto update option?
|
plugin.myLogger(Level.INFO, "Plugin out of date! You are using version " + thisVersion + " but the latest version is version " + latestVersion + "!");
|
||||||
|
plugin.setUpToDate(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.setUpToDate(true);
|
||||||
|
plugin.myLogger(Level.INFO, "You seem to be using the latest version of this plugin!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load the loginHandler to show messages to the user when they join.
|
});
|
||||||
Bukkit.getPluginManager().registerEvents(new LoginHandler(plugin, "The Armored Elytra plugin is out of date!"), plugin);
|
thread.start();
|
||||||
plugin.myLogger(Level.INFO, "Plugin out of date! You are using version " + thisVersion + " but the latest version is version " + latestVersion + "!");
|
}
|
||||||
plugin.setUpToDate(false);
|
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.");
|
||||||
else
|
|
||||||
{
|
|
||||||
plugin.setUpToDate(true);
|
|
||||||
plugin.myLogger(Level.INFO, "You seem to be using the latest version of this plugin!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
// Are stats allowed?
|
||||||
thread.start();
|
if (config.getBool("allowStats"))
|
||||||
}
|
{
|
||||||
else
|
myLogger(Level.INFO, "Enabling stats! Thanks, it really helps!");
|
||||||
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.");
|
@SuppressWarnings("unused")
|
||||||
|
Metrics metrics = new Metrics(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// Y u do dis? :(
|
||||||
|
myLogger(Level.INFO, "Stats disabled, not laoding stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!");
|
||||||
|
|
||||||
|
this.locale = config.getString("languageFile");
|
||||||
|
|
||||||
|
|
||||||
|
// Load the files for the correct version of Minecraft.
|
||||||
|
if (compatibleMCVer())
|
||||||
|
{
|
||||||
|
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
||||||
|
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft! This plugin will NOT be enabled!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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!");
|
||||||
|
|
||||||
// Are stats allowed?
|
// Log all allowed enchantments.
|
||||||
if (config.getBool("allowStats"))
|
myLogger(Level.INFO, ("Allowed enchantments:"));
|
||||||
{
|
for (String s : config.getStringList("allowedEnchantments"))
|
||||||
myLogger(Level.INFO, "Enabling stats! Thanks, it really helps!");
|
myLogger(Level.INFO, " - " + s);
|
||||||
@SuppressWarnings("unused")
|
}
|
||||||
Metrics metrics = new Metrics(this);
|
else
|
||||||
}
|
{
|
||||||
else
|
myLogger(Level.WARNING, "Plugin in uninstall mode!");
|
||||||
// Y u do dis? :(
|
Bukkit.getPluginManager().registerEvents(new Uninstaller(this, nbtEditor), this);
|
||||||
myLogger(Level.INFO, "Stats disabled, not laoding stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!");
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readConfigValues()
|
||||||
|
{
|
||||||
|
// Load the settings from the config file.
|
||||||
|
this.config = new ConfigLoader(this);
|
||||||
|
|
||||||
|
// Check if the plugin should go into uninstall mode.
|
||||||
|
this.uninstallMode = config.getBool("uninstallMode");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Messages getMyMessages()
|
||||||
|
{
|
||||||
|
return this.messages;
|
||||||
|
}
|
||||||
|
|
||||||
// Load the files for the correct version of Minecraft.
|
private void readMessages()
|
||||||
if (compatibleMCVer())
|
{
|
||||||
{
|
// Replace color codes by the corresponding colors.
|
||||||
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor), this);
|
this.usageDeniedMessage = this.getMyMessages().getString("MESSAGES.UsageDenied" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor));
|
this.elytraReceivedMessage = this.getMyMessages().getString("MESSAGES.ElytraReceived").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
}
|
this.elytraLore = this.getMyMessages().getString("MESSAGES.Lore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
else
|
|
||||||
{
|
|
||||||
myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft! This plugin will NOT be enabled!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.leatherName = this.getMyMessages().getString("TIER.Leather" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
this.goldName = this.getMyMessages().getString("TIER.Gold" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
this.chainName = this.getMyMessages().getString("TIER.Chain" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
this.ironName = this.getMyMessages().getString("TIER.Iron" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
this.diamondName = this.getMyMessages().getString("TIER.Diamond" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
|
||||||
|
// Change the string to null if it says "NONE".
|
||||||
|
this.usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage );
|
||||||
|
this.elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage);
|
||||||
|
this.elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if this is the latest version of this plugin.
|
||||||
|
public boolean isUpToDate()
|
||||||
|
{
|
||||||
|
return upToDate;
|
||||||
|
}
|
||||||
|
|
||||||
// Load the plugin normally if not in uninstall mode.
|
// Get this.
|
||||||
if (!uninstallMode)
|
public ArmoredElytra getPlugin()
|
||||||
{
|
{
|
||||||
// Check if the user wants to disable durability penalty for flying with an armored elytra.
|
return this;
|
||||||
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!");
|
|
||||||
|
|
||||||
|
// Returns the config handler.
|
||||||
|
public ConfigLoader getConfigLoader()
|
||||||
|
{
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
// Log all allowed enchantments.
|
// Send a message to a player in a specific color.
|
||||||
myLogger(Level.INFO, ("Allowed enchantments:"));
|
public void messagePlayer(Player player, ChatColor color, String str)
|
||||||
for (String s : config.getStringList("allowedEnchantments"))
|
{
|
||||||
myLogger(Level.INFO, " - " + s);
|
player.sendMessage(color + str);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
myLogger(Level.WARNING, "Plugin in uninstall mode!");
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Uninstaller(this, nbtEditor), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readConfigValues()
|
// Send a message to a player.
|
||||||
{
|
public void messagePlayer(Player player, String str)
|
||||||
// Load the settings from the config file.
|
{
|
||||||
this.config = new ConfigLoader(this);
|
messagePlayer(player, ChatColor.WHITE, str);
|
||||||
|
}
|
||||||
|
|
||||||
// Replace color codes by the corresponding colors.
|
// Send the usageDeniedMessage message to the player.
|
||||||
this.usageDeniedMessage = config.getString("usageDeniedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
public void usageDeniedMessage(Player player, ArmorTier armorTier)
|
||||||
this.elytraReceivedMessage = config.getString("elytraReceivedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
{
|
||||||
this.elytraLore = config.getString("elytraLore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
if (usageDeniedMessage != null)
|
||||||
|
{
|
||||||
|
String message = fillInArmorTierInStringNoColor(usageDeniedMessage, armorTier);
|
||||||
|
messagePlayer(player, ChatColor.RED, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.leatherName = config.getString("leatherName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
// Send the elytraReceivedMessage message to the player.
|
||||||
this.goldName = config.getString("goldName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
public void elytraReceivedMessage(Player player, ArmorTier armorTier)
|
||||||
this.chainName = config.getString("chainName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
{
|
||||||
this.ironName = config.getString("ironName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
if (elytraReceivedMessage != null)
|
||||||
this.diamondName = config.getString("diamondName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
{
|
||||||
|
String message = fillInArmorTierInStringNoColor(elytraReceivedMessage, armorTier);
|
||||||
|
messagePlayer(player, ChatColor.GREEN, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Change the string to null if it says "NONE".
|
// Replace %ARMOR_TIER% by the name of that armor tier in a string, but strip %ARMOR_TIER% of its color.
|
||||||
this.usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage );
|
public String fillInArmorTierInStringNoColor(String string, ArmorTier armorTier)
|
||||||
this.elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage);
|
{
|
||||||
this.elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore );
|
return string.replace("%ARMOR_TIER%", ChatColor.stripColor(getArmoredElytrName(armorTier)));
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the plugin should go into uninstall mode.
|
public String getLocale()
|
||||||
this.uninstallMode = config.getBool("uninstallMode");
|
{
|
||||||
}
|
return locale == null ? "en_US" : locale;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns true if this is the latest version of this plugin.
|
// Print a string to the log.
|
||||||
public boolean isUpToDate()
|
public void myLogger(Level level, String str)
|
||||||
{
|
{
|
||||||
return upToDate;
|
Bukkit.getLogger().log(level, "[" + this.getName() + "] " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get this.
|
// Log message that only gets printed when debugging is enabled in the config file.
|
||||||
public ArmoredElytra getPlugin()
|
public void debugMsg(Level level, String str)
|
||||||
{
|
{
|
||||||
return this;
|
if (config.getBool("enableDebug"))
|
||||||
}
|
myLogger(level, str);
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the config handler.
|
// Give the provided player the provided item.
|
||||||
public ConfigLoader getConfigLoader()
|
public void giveArmoredElytraToPlayer(Player player, ItemStack item)
|
||||||
{
|
{
|
||||||
return config;
|
if (item != null)
|
||||||
}
|
player.getInventory().addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
// Send a message to a player in a specific color.
|
// Check + initialize for the correct version of Minecraft.
|
||||||
public void messagePlayer(Player player, ChatColor color, String s)
|
public boolean compatibleMCVer()
|
||||||
{
|
{
|
||||||
player.sendMessage(color + s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a message to a player.
|
|
||||||
public void messagePlayer(Player player, String s)
|
|
||||||
{
|
|
||||||
messagePlayer(player, ChatColor.WHITE, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the usageDeniedMessage message to the player.
|
|
||||||
public void usageDeniedMessage(Player player, ArmorTier armorTier)
|
|
||||||
{
|
|
||||||
if (usageDeniedMessage != null)
|
|
||||||
{
|
|
||||||
String message = fillInArmorTierInStringNoColor(usageDeniedMessage, armorTier);
|
|
||||||
messagePlayer(player, ChatColor.RED, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the elytraReceivedMessage message to the player.
|
|
||||||
public void elytraReceivedMessage(Player player, ArmorTier armorTier)
|
|
||||||
{
|
|
||||||
if (elytraReceivedMessage != null)
|
|
||||||
{
|
|
||||||
String message = fillInArmorTierInStringNoColor(elytraReceivedMessage, armorTier);
|
|
||||||
messagePlayer(player, ChatColor.GREEN, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace %ARMOR_TIER% by the name of that armor tier in a string, but strip %ARMOR_TIER% of its color.
|
|
||||||
public String fillInArmorTierInStringNoColor(String string, ArmorTier armorTier)
|
|
||||||
{
|
|
||||||
return string.replace("%ARMOR_TIER%", ChatColor.stripColor(getArmoredElytrName(armorTier)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print a string to the log.
|
|
||||||
public void myLogger(Level level, String str)
|
|
||||||
{
|
|
||||||
Bukkit.getLogger().log(level, "[" + this.getName() + "] " + str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
{
|
|
||||||
String version;
|
String version;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -260,75 +269,76 @@ public class ArmoredElytra extends JavaPlugin implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version.equals("v1_10_R1"))
|
if (version.equals("v1_10_R1"))
|
||||||
nbtEditor = new NBTEditor_V1_10_R1(this);
|
nbtEditor = new NBTEditor_V1_10_R1(this);
|
||||||
else if (version.equals("v1_11_R1"))
|
else if (version.equals("v1_11_R1"))
|
||||||
nbtEditor = new NBTEditor_V1_11_R1(this);
|
nbtEditor = new NBTEditor_V1_11_R1(this);
|
||||||
else if (version.equals("v1_12_R1"))
|
else if (version.equals("v1_12_R1"))
|
||||||
nbtEditor = new NBTEditor_V1_12_R1(this);
|
nbtEditor = new NBTEditor_V1_12_R1(this);
|
||||||
else if (version.equals("v1_13_R1"))
|
else if (version.equals("v1_13_R1"))
|
||||||
nbtEditor = new NBTEditor_V1_13_R1(this);
|
nbtEditor = new NBTEditor_V1_13_R1(this);
|
||||||
|
else if (version.equals("v1_13_R2"))
|
||||||
|
nbtEditor = new NBTEditor_V1_13_R2(this);
|
||||||
// Return true if compatible.
|
// Return true if compatible.
|
||||||
return nbtEditor != null;
|
return nbtEditor != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getElytraLore()
|
public String getElytraLore()
|
||||||
{
|
{
|
||||||
return this.elytraLore;
|
return this.elytraLore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArmoredElytrName(ArmorTier tier)
|
public String getArmoredElytrName(ArmorTier tier)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
switch(tier)
|
switch(tier)
|
||||||
{
|
{
|
||||||
case LEATHER:
|
case LEATHER:
|
||||||
ret = this.leatherName;
|
ret = this.leatherName;
|
||||||
break;
|
break;
|
||||||
case GOLD:
|
case GOLD:
|
||||||
ret = this.goldName;
|
ret = this.goldName;
|
||||||
break;
|
break;
|
||||||
case CHAIN:
|
case CHAIN:
|
||||||
ret = this.chainName;
|
ret = this.chainName;
|
||||||
break;
|
break;
|
||||||
case IRON:
|
case IRON:
|
||||||
ret = this.ironName;
|
ret = this.ironName;
|
||||||
break;
|
break;
|
||||||
case DIAMOND:
|
case DIAMOND:
|
||||||
ret = this.diamondName;
|
ret = this.diamondName;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = "NONE";
|
ret = "NONE";
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean playerHasCraftPerm(Player player, ArmorTier tier)
|
public boolean playerHasCraftPerm(Player player, ArmorTier tier)
|
||||||
{
|
{
|
||||||
switch (tier)
|
switch (tier)
|
||||||
{
|
{
|
||||||
case LEATHER:
|
case LEATHER:
|
||||||
return player.hasPermission("armoredelytra.craft.leather");
|
return player.hasPermission("armoredelytra.craft.leather");
|
||||||
case GOLD:
|
case GOLD:
|
||||||
return player.hasPermission("armoredelytra.craft.gold");
|
return player.hasPermission("armoredelytra.craft.gold");
|
||||||
case CHAIN:
|
case CHAIN:
|
||||||
return player.hasPermission("armoredelytra.craft.chain");
|
return player.hasPermission("armoredelytra.craft.chain");
|
||||||
case IRON:
|
case IRON:
|
||||||
return player.hasPermission("armoredelytra.craft.iron");
|
return player.hasPermission("armoredelytra.craft.iron");
|
||||||
case DIAMOND:
|
case DIAMOND:
|
||||||
return player.hasPermission("armoredelytra.craft.diamond");
|
return player.hasPermission("armoredelytra.craft.diamond");
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUpToDate(boolean upToDate)
|
||||||
|
{
|
||||||
|
this.upToDate = upToDate;
|
||||||
|
}
|
||||||
|
|
||||||
public void setUpToDate(boolean upToDate)
|
public boolean getUninstallMode()
|
||||||
{
|
{
|
||||||
this.upToDate = upToDate;
|
return uninstallMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUninstallMode()
|
|
||||||
{
|
|
||||||
return uninstallMode;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -17,13 +17,13 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class CommandHandler implements CommandExecutor
|
public class CommandHandler implements CommandExecutor
|
||||||
{
|
{
|
||||||
ArmoredElytra plugin;
|
ArmoredElytra plugin;
|
||||||
NBTEditor nbtEditor;
|
NBTEditor nbtEditor;
|
||||||
|
|
||||||
public CommandHandler(ArmoredElytra plugin, NBTEditor nbtEditor)
|
public CommandHandler(ArmoredElytra plugin, NBTEditor nbtEditor)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.nbtEditor = nbtEditor;
|
this.nbtEditor = nbtEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,7 +37,7 @@ public class CommandHandler implements CommandExecutor
|
|||||||
|
|
||||||
if (plugin.getUninstallMode())
|
if (plugin.getUninstallMode())
|
||||||
{
|
{
|
||||||
plugin.messagePlayer(player, "Plugin in uninstall mode! New Armored Elytras are not allowed!");
|
plugin.messagePlayer(player, plugin.getMyMessages().getString("MESSAGES.UninstallMode"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +67,6 @@ public class CommandHandler implements CommandExecutor
|
|||||||
tier = args[1];
|
tier = args[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use armorTier name from ArmorTier struct.
|
|
||||||
// Also, use AT-name for permission node verification.
|
|
||||||
|
|
||||||
|
|
||||||
// Leather armor.
|
// Leather armor.
|
||||||
if (tier.equalsIgnoreCase("leather"))
|
if (tier.equalsIgnoreCase("leather"))
|
||||||
{
|
{
|
||||||
@ -111,7 +107,7 @@ public class CommandHandler implements CommandExecutor
|
|||||||
allowed = true;
|
allowed = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
plugin.messagePlayer(player, "Not a supported armor tier! Try one of these: leather, gold, chain, iron, diamond.");
|
plugin.messagePlayer(player, plugin.getMyMessages().getString("MESSAGES.UnsupportedTier"));
|
||||||
|
|
||||||
if (allowed)
|
if (allowed)
|
||||||
{
|
{
|
||||||
@ -120,7 +116,7 @@ public class CommandHandler implements CommandExecutor
|
|||||||
plugin.giveArmoredElytraToPlayer(receiver, newElytra);
|
plugin.giveArmoredElytraToPlayer(receiver, newElytra);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
plugin.messagePlayer(player, "You do not have the required permission node to give " + plugin.getArmoredElytrName(armorTier));
|
plugin.messagePlayer(player, plugin.fillInArmorTierInStringNoColor(plugin.getMyMessages().getString("MESSAGES.UnsupportedTier"), armorTier));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,8 +138,6 @@ public class CommandHandler implements CommandExecutor
|
|||||||
player = Bukkit.getPlayer(args[0]);
|
player = Bukkit.getPlayer(args[0]);
|
||||||
ArmorTier armorTier = ArmorTier.NONE;
|
ArmorTier armorTier = ArmorTier.NONE;
|
||||||
|
|
||||||
// TODO: Again, use the ArmorTier struct for tier retrieval.
|
|
||||||
|
|
||||||
if (tier.equalsIgnoreCase("leather"))
|
if (tier.equalsIgnoreCase("leather"))
|
||||||
armorTier = ArmorTier.LEATHER;
|
armorTier = ArmorTier.LEATHER;
|
||||||
else if (tier.equalsIgnoreCase("gold"))
|
else if (tier.equalsIgnoreCase("gold"))
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -12,30 +12,30 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
|||||||
public class LoginHandler implements Listener
|
public class LoginHandler implements Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
ArmoredElytra plugin;
|
ArmoredElytra plugin;
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
public LoginHandler(ArmoredElytra plugin, String message)
|
public LoginHandler(ArmoredElytra plugin, String message)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.message = message;
|
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"))
|
if (player.hasPermission("armoredElytra.admin"))
|
||||||
{
|
{
|
||||||
// Slight delay so the player actually receives the message;
|
// 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, message);
|
plugin.messagePlayer(player, ChatColor.AQUA, message);
|
||||||
}
|
}
|
||||||
}.runTaskLater(this.plugin, 10);
|
}.runTaskLater(this.plugin, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nl.pim16aap2.armoredElytra.handlers;
|
package nl.pim16aap2.armoredElytra.handlers;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -19,64 +18,63 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class Uninstaller implements Listener
|
public class Uninstaller implements Listener
|
||||||
{
|
{
|
||||||
ArmoredElytra plugin;
|
ArmoredElytra plugin;
|
||||||
NBTEditor nbtEditor;
|
NBTEditor nbtEditor;
|
||||||
|
|
||||||
public Uninstaller(ArmoredElytra plugin, NBTEditor nbtEditor)
|
public Uninstaller(ArmoredElytra plugin, NBTEditor nbtEditor)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.nbtEditor = nbtEditor;
|
this.nbtEditor = nbtEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int removeArmoredElytras(Inventory inv)
|
public int removeArmoredElytras(Inventory inv)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (ItemStack is : inv)
|
for (ItemStack is : inv)
|
||||||
if (is != null)
|
if (is != null)
|
||||||
if (is.getType() == Material.ELYTRA)
|
if (is.getType() == Material.ELYTRA)
|
||||||
if (nbtEditor.getArmorTier(is) != ArmorTier.NONE)
|
if (nbtEditor.getArmorTier(is) != ArmorTier.NONE)
|
||||||
{
|
{
|
||||||
Bukkit.broadcastMessage("An armored elytra even! Removing now!");
|
inv.remove(is);
|
||||||
inv.remove(is);
|
++count;
|
||||||
++count;
|
}
|
||||||
}
|
return count;
|
||||||
return count;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChestOpen(InventoryOpenEvent event)
|
public void onChestOpen(InventoryOpenEvent event)
|
||||||
{
|
{
|
||||||
if (event.getInventory().getType().equals(InventoryType.CHEST))
|
if (event.getInventory().getType().equals(InventoryType.CHEST))
|
||||||
{
|
{
|
||||||
// Slight delay so the inventory has time to get loaded.
|
// Slight delay so the inventory has time to get loaded.
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Inventory inv = event.getInventory();
|
Inventory inv = event.getInventory();
|
||||||
int removed = removeArmoredElytras(inv);
|
int removed = removeArmoredElytras(inv);
|
||||||
if (removed != 0)
|
if (removed != 0)
|
||||||
plugin.messagePlayer((Player) (event.getPlayer()), ChatColor.RED, "Removed " + removed + " armored elytras from your chest!");
|
plugin.messagePlayer((Player) (event.getPlayer()), ChatColor.RED, "Removed " + removed + " armored elytras from your chest!");
|
||||||
}
|
}
|
||||||
}.runTaskLater(this.plugin, 20);
|
}.runTaskLater(this.plugin, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLogin(PlayerLoginEvent event)
|
public void onPlayerLogin(PlayerLoginEvent event)
|
||||||
{
|
{
|
||||||
// Slight delay so the inventory has time to get loaded.
|
// Slight delay so the inventory has time to get loaded.
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Inventory inv = event.getPlayer().getInventory();
|
Inventory inv = event.getPlayer().getInventory();
|
||||||
int removed = removeArmoredElytras(inv);
|
int removed = removeArmoredElytras(inv);
|
||||||
if (removed != 0)
|
if (removed != 0)
|
||||||
plugin.messagePlayer((Player) (event.getPlayer()), ChatColor.RED, "Removed " + removed + " armored elytras from your inventory!");
|
plugin.messagePlayer((Player) (event.getPlayer()), ChatColor.RED, "Removed " + removed + " armored elytras from your inventory!");
|
||||||
}
|
}
|
||||||
}.runTaskLater(this.plugin, 20);
|
}.runTaskLater(this.plugin, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,100 +17,101 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class NBTEditor_V1_10_R1 implements NBTEditor
|
public class NBTEditor_V1_10_R1 implements NBTEditor
|
||||||
{
|
{
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
|
|
||||||
// Get the names and lores for every tier of armor.
|
// Get the names and lores for every tier of armor.
|
||||||
public NBTEditor_V1_10_R1(ArmoredElytra plugin)
|
public NBTEditor_V1_10_R1(ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, ArmorTier armorTier, boolean unbreakable)
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
{
|
{
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
int armorProtection = ArmorTier.getArmor(armorTier);
|
||||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
|
|
||||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||||
if (plugin.getElytraLore() != null)
|
if (plugin.getElytraLore() != null)
|
||||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||||
item.setItemMeta(itemmeta);
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
net.minecraft.server.v1_10_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
net.minecraft.server.v1_10_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||||
NBTTagList modifiers = new NBTTagList();
|
NBTTagList modifiers = new NBTTagList();
|
||||||
NBTTagCompound armor = new NBTTagCompound();
|
NBTTagCompound armor = new NBTTagCompound();
|
||||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||||
armor.set("Name", new NBTTagString("generic.armor"));
|
armor.set("Name", new NBTTagString("generic.armor"));
|
||||||
armor.set("Amount", new NBTTagInt(armorProtection));
|
armor.set("Amount", new NBTTagInt(armorProtection));
|
||||||
armor.set("Operation", new NBTTagInt(0));
|
armor.set("Operation", new NBTTagInt(0));
|
||||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armor.set("Slot", new NBTTagString("chest"));
|
armor.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armor);
|
modifiers.add(armor);
|
||||||
|
|
||||||
NBTTagCompound armorTough = new NBTTagCompound();
|
NBTTagCompound armorTough = new NBTTagCompound();
|
||||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
||||||
armorTough.set("Operation", new NBTTagInt(0));
|
armorTough.set("Operation", new NBTTagInt(0));
|
||||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armorTough.set("Slot", new NBTTagString("chest"));
|
armorTough.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armorTough);
|
modifiers.add(armorTough);
|
||||||
|
|
||||||
if (unbreakable)
|
if (unbreakable)
|
||||||
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the armor tier of the supplied item.
|
// Get the armor tier of the supplied item.
|
||||||
@Override
|
@Override
|
||||||
public ArmorTier getArmorTier(ItemStack item)
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
if (item.getType() != Material.ELYTRA)
|
if (item.getType() != Material.ELYTRA)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
// 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 ArmorTier.NONE;
|
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;
|
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.
|
||||||
pos--;
|
pos--;
|
||||||
String stringAtPos = nbtTags.substring(pos, pos+1);
|
String stringAtPos = nbtTags.substring(pos, pos + 1);
|
||||||
armorValue = Integer.parseInt(stringAtPos);
|
armorValue = Integer.parseInt(stringAtPos);
|
||||||
} else
|
}
|
||||||
// Otherwise, the item has no armor, so return 0;
|
else
|
||||||
return ArmorTier.NONE;
|
// Otherwise, the item has no armor, so return 0;
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
switch (armorValue)
|
switch (armorValue)
|
||||||
{
|
{
|
||||||
case 3:
|
case 3:
|
||||||
return ArmorTier.LEATHER;
|
return ArmorTier.LEATHER;
|
||||||
case 5:
|
case 5:
|
||||||
return ArmorTier.GOLD;
|
return ArmorTier.GOLD;
|
||||||
case 6:
|
case 6:
|
||||||
return ArmorTier.IRON;
|
return ArmorTier.IRON;
|
||||||
case 8:
|
case 8:
|
||||||
return ArmorTier.DIAMOND;
|
return ArmorTier.DIAMOND;
|
||||||
default:
|
default:
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,100 +17,101 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class NBTEditor_V1_11_R1 implements NBTEditor
|
public class NBTEditor_V1_11_R1 implements NBTEditor
|
||||||
{
|
{
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
|
|
||||||
// Get the names and lores for every tier of armor.
|
// Get the names and lores for every tier of armor.
|
||||||
public NBTEditor_V1_11_R1(ArmoredElytra plugin)
|
public NBTEditor_V1_11_R1(ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, ArmorTier armorTier, boolean unbreakable)
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
{
|
{
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
int armorProtection = ArmorTier.getArmor(armorTier);
|
||||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
|
|
||||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||||
if (plugin.getElytraLore() != null)
|
if (plugin.getElytraLore() != null)
|
||||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||||
item.setItemMeta(itemmeta);
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
net.minecraft.server.v1_11_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
net.minecraft.server.v1_11_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||||
NBTTagList modifiers = new NBTTagList();
|
NBTTagList modifiers = new NBTTagList();
|
||||||
NBTTagCompound armor = new NBTTagCompound();
|
NBTTagCompound armor = new NBTTagCompound();
|
||||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||||
armor.set("Name", new NBTTagString("generic.armor"));
|
armor.set("Name", new NBTTagString("generic.armor"));
|
||||||
armor.set("Amount", new NBTTagInt(armorProtection));
|
armor.set("Amount", new NBTTagInt(armorProtection));
|
||||||
armor.set("Operation", new NBTTagInt(0));
|
armor.set("Operation", new NBTTagInt(0));
|
||||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armor.set("Slot", new NBTTagString("chest"));
|
armor.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armor);
|
modifiers.add(armor);
|
||||||
|
|
||||||
NBTTagCompound armorTough = new NBTTagCompound();
|
NBTTagCompound armorTough = new NBTTagCompound();
|
||||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
||||||
armorTough.set("Operation", new NBTTagInt(0));
|
armorTough.set("Operation", new NBTTagInt(0));
|
||||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armorTough.set("Slot", new NBTTagString("chest"));
|
armorTough.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armorTough);
|
modifiers.add(armorTough);
|
||||||
|
|
||||||
if (unbreakable)
|
if (unbreakable)
|
||||||
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the armor tier of the supplied item.
|
// Get the armor tier of the supplied item.
|
||||||
@Override
|
@Override
|
||||||
public ArmorTier getArmorTier(ItemStack item)
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
if (item.getType() != Material.ELYTRA)
|
if (item.getType() != Material.ELYTRA)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
// 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 ArmorTier.NONE;
|
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;
|
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.
|
||||||
pos--;
|
pos--;
|
||||||
String stringAtPos = nbtTags.substring(pos, pos+1);
|
String stringAtPos = nbtTags.substring(pos, pos + 1);
|
||||||
armorValue = Integer.parseInt(stringAtPos);
|
armorValue = Integer.parseInt(stringAtPos);
|
||||||
} else
|
}
|
||||||
// Otherwise, the item has no armor, so return 0;
|
else
|
||||||
return ArmorTier.NONE;
|
// Otherwise, the item has no armor, so return 0;
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
switch (armorValue)
|
switch (armorValue)
|
||||||
{
|
{
|
||||||
case 3:
|
case 3:
|
||||||
return ArmorTier.LEATHER;
|
return ArmorTier.LEATHER;
|
||||||
case 5:
|
case 5:
|
||||||
return ArmorTier.GOLD;
|
return ArmorTier.GOLD;
|
||||||
case 6:
|
case 6:
|
||||||
return ArmorTier.IRON;
|
return ArmorTier.IRON;
|
||||||
case 8:
|
case 8:
|
||||||
return ArmorTier.DIAMOND;
|
return ArmorTier.DIAMOND;
|
||||||
default:
|
default:
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,100 +17,101 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class NBTEditor_V1_12_R1 implements NBTEditor
|
public class NBTEditor_V1_12_R1 implements NBTEditor
|
||||||
{
|
{
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
|
|
||||||
// Get the names and lores for every tier of armor.
|
// Get the names and lores for every tier of armor.
|
||||||
public NBTEditor_V1_12_R1(ArmoredElytra plugin)
|
public NBTEditor_V1_12_R1(ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, ArmorTier armorTier, boolean unbreakable)
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
{
|
{
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
int armorProtection = ArmorTier.getArmor(armorTier);
|
||||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
|
|
||||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||||
if (plugin.getElytraLore() != null)
|
if (plugin.getElytraLore() != null)
|
||||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||||
item.setItemMeta(itemmeta);
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||||
NBTTagList modifiers = new NBTTagList();
|
NBTTagList modifiers = new NBTTagList();
|
||||||
NBTTagCompound armor = new NBTTagCompound();
|
NBTTagCompound armor = new NBTTagCompound();
|
||||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||||
armor.set("Name", new NBTTagString("generic.armor"));
|
armor.set("Name", new NBTTagString("generic.armor"));
|
||||||
armor.set("Amount", new NBTTagInt(armorProtection));
|
armor.set("Amount", new NBTTagInt(armorProtection));
|
||||||
armor.set("Operation", new NBTTagInt(0));
|
armor.set("Operation", new NBTTagInt(0));
|
||||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armor.set("Slot", new NBTTagString("chest"));
|
armor.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armor);
|
modifiers.add(armor);
|
||||||
|
|
||||||
NBTTagCompound armorTough = new NBTTagCompound();
|
NBTTagCompound armorTough = new NBTTagCompound();
|
||||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
||||||
armorTough.set("Operation", new NBTTagInt(0));
|
armorTough.set("Operation", new NBTTagInt(0));
|
||||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armorTough.set("Slot", new NBTTagString("chest"));
|
armorTough.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armorTough);
|
modifiers.add(armorTough);
|
||||||
|
|
||||||
if (unbreakable)
|
if (unbreakable)
|
||||||
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the armor tier of the supplied item.
|
// Get the armor tier of the supplied item.
|
||||||
@Override
|
@Override
|
||||||
public ArmorTier getArmorTier(ItemStack item)
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
if (item.getType() != Material.ELYTRA)
|
if (item.getType() != Material.ELYTRA)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
// 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 ArmorTier.NONE;
|
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;
|
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.
|
||||||
pos--;
|
pos--;
|
||||||
String stringAtPos = nbtTags.substring(pos, pos+1);
|
String stringAtPos = nbtTags.substring(pos, pos + 1);
|
||||||
armorValue = Integer.parseInt(stringAtPos);
|
armorValue = Integer.parseInt(stringAtPos);
|
||||||
} else
|
}
|
||||||
// Otherwise, the item has no armor, so return 0;
|
else
|
||||||
return ArmorTier.NONE;
|
// Otherwise, the item has no armor, so return 0;
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
switch (armorValue)
|
switch (armorValue)
|
||||||
{
|
{
|
||||||
case 3:
|
case 3:
|
||||||
return ArmorTier.LEATHER;
|
return ArmorTier.LEATHER;
|
||||||
case 5:
|
case 5:
|
||||||
return ArmorTier.GOLD;
|
return ArmorTier.GOLD;
|
||||||
case 6:
|
case 6:
|
||||||
return ArmorTier.IRON;
|
return ArmorTier.IRON;
|
||||||
case 8:
|
case 8:
|
||||||
return ArmorTier.DIAMOND;
|
return ArmorTier.DIAMOND;
|
||||||
default:
|
default:
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,100 +17,105 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
|||||||
|
|
||||||
public class NBTEditor_V1_13_R1 implements NBTEditor
|
public class NBTEditor_V1_13_R1 implements NBTEditor
|
||||||
{
|
{
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
|
|
||||||
// Get the names and lores for every tier of armor.
|
// Get the names and lores for every tier of armor.
|
||||||
public NBTEditor_V1_13_R1(ArmoredElytra plugin)
|
public NBTEditor_V1_13_R1(ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, ArmorTier armorTier, boolean unbreakable)
|
public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable)
|
||||||
{
|
{
|
||||||
ItemMeta itemmeta = item.getItemMeta();
|
ItemMeta itemmeta = item.getItemMeta();
|
||||||
int armorProtection = ArmorTier.getArmor (armorTier);
|
int armorProtection = ArmorTier.getArmor(armorTier);
|
||||||
int armorToughness = ArmorTier.getToughness(armorTier);
|
int armorToughness = ArmorTier.getToughness(armorTier);
|
||||||
|
|
||||||
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||||
if (plugin.getElytraLore() != null)
|
if (plugin.getElytraLore() != null)
|
||||||
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||||
item.setItemMeta(itemmeta);
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
net.minecraft.server.v1_13_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
net.minecraft.server.v1_13_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||||
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
|
||||||
NBTTagList modifiers = new NBTTagList();
|
NBTTagList modifiers = new NBTTagList();
|
||||||
NBTTagCompound armor = new NBTTagCompound();
|
NBTTagCompound armor = new NBTTagCompound();
|
||||||
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
armor.set("AttributeName", new NBTTagString("generic.armor"));
|
||||||
armor.set("Name", new NBTTagString("generic.armor"));
|
armor.set("Name", new NBTTagString("generic.armor"));
|
||||||
armor.set("Amount", new NBTTagInt(armorProtection));
|
armor.set("Amount", new NBTTagInt(armorProtection));
|
||||||
armor.set("Operation", new NBTTagInt(0));
|
armor.set("Operation", new NBTTagInt(0));
|
||||||
armor.set("UUIDLeast", new NBTTagInt(894654));
|
armor.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armor.set("UUIDMost", new NBTTagInt(2872));
|
armor.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armor.set("Slot", new NBTTagString("chest"));
|
armor.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armor);
|
modifiers.add(armor);
|
||||||
|
|
||||||
NBTTagCompound armorTough = new NBTTagCompound();
|
NBTTagCompound armorTough = new NBTTagCompound();
|
||||||
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
armorTough.set("AttributeName", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
armorTough.set("Name", new NBTTagString("generic.armorToughness"));
|
||||||
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
armorTough.set("Amount", new NBTTagInt(armorToughness));
|
||||||
armorTough.set("Operation", new NBTTagInt(0));
|
armorTough.set("Operation", new NBTTagInt(0));
|
||||||
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
armorTough.set("UUIDLeast", new NBTTagInt(894654));
|
||||||
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
armorTough.set("UUIDMost", new NBTTagInt(2872));
|
||||||
armorTough.set("Slot", new NBTTagString("chest"));
|
armorTough.set("Slot", new NBTTagString("chest"));
|
||||||
modifiers.add(armorTough);
|
modifiers.add(armorTough);
|
||||||
|
|
||||||
if (unbreakable)
|
if (unbreakable)
|
||||||
compound.set("Unbreakable", new NBTTagByte((byte) 1));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the armor tier of the supplied item.
|
// Get the armor tier of the supplied item.
|
||||||
@Override
|
@Override
|
||||||
public ArmorTier getArmorTier(ItemStack item)
|
public ArmorTier getArmorTier(ItemStack item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
if (item.getType() != Material.ELYTRA)
|
if (item.getType() != Material.ELYTRA)
|
||||||
return ArmorTier.NONE;
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
// 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 ArmorTier.NONE;
|
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\"");
|
// The level is now formatted as x.xd, e.g. 6.0d.
|
||||||
int armorValue = 0;
|
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||||
if (pos > 0)
|
int armorValue = 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)
|
if (pos <= 0)
|
||||||
{
|
return ArmorTier.NONE;
|
||||||
case 3:
|
|
||||||
return ArmorTier.LEATHER;
|
try
|
||||||
case 5:
|
{
|
||||||
return ArmorTier.GOLD;
|
String stringAtPos = nbtTags.substring(pos - 4, pos - 1);
|
||||||
case 6:
|
armorValue = (int) Double.parseDouble(stringAtPos);
|
||||||
return ArmorTier.IRON;
|
}
|
||||||
case 8:
|
catch (Exception e)
|
||||||
return ArmorTier.DIAMOND;
|
{
|
||||||
default:
|
armorValue = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,121 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.nms;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_13_R2.NBTTagByte;
|
||||||
|
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_13_R2.NBTTagInt;
|
||||||
|
import net.minecraft.server.v1_13_R2.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_13_R2.NBTTagString;
|
||||||
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.armoredElytra.util.ArmorTier;
|
||||||
|
|
||||||
|
public class NBTEditor_V1_13_R2 implements NBTEditor
|
||||||
|
{
|
||||||
|
private ArmoredElytra plugin;
|
||||||
|
|
||||||
|
// Get the names and lores for every tier of armor.
|
||||||
|
public NBTEditor_V1_13_R2(ArmoredElytra plugin)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier));
|
||||||
|
if (plugin.getElytraLore() != null)
|
||||||
|
itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier)));
|
||||||
|
item.setItemMeta(itemmeta);
|
||||||
|
|
||||||
|
net.minecraft.server.v1_13_R2.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)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
if (item.getType() != Material.ELYTRA)
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// The level is now formatted as x.xd, e.g. 6.0d.
|
||||||
|
int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\"");
|
||||||
|
int armorValue = 0;
|
||||||
|
|
||||||
|
if (pos <= 0)
|
||||||
|
return ArmorTier.NONE;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String stringAtPos = nbtTags.substring(pos - 4, pos - 1);
|
||||||
|
armorValue = (int) Double.parseDouble(stringAtPos);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
armorValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,9 +12,9 @@ public enum ArmorTier
|
|||||||
IRON (6 , 0 , Material.IRON_INGOT),
|
IRON (6 , 0 , Material.IRON_INGOT),
|
||||||
DIAMOND (8 , 2 , Material.DIAMOND );
|
DIAMOND (8 , 2 , Material.DIAMOND );
|
||||||
|
|
||||||
private int armor;
|
private int armor;
|
||||||
private int toughness;
|
private int toughness;
|
||||||
private Material repair;
|
private Material repair;
|
||||||
|
|
||||||
private ArmorTier (int armor, int toughness, Material repair)
|
private ArmorTier (int armor, int toughness, Material repair)
|
||||||
{
|
{
|
||||||
|
@ -12,197 +12,186 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
import nl.pim16aap2.bigDoors.util.ConfigOption;
|
||||||
|
|
||||||
public class ConfigLoader
|
public class ConfigLoader
|
||||||
{
|
{
|
||||||
private boolean unbreakable;
|
private boolean allowStats;
|
||||||
private boolean noFlightDurability;
|
private boolean unbreakable;
|
||||||
private int LEATHER_TO_FULL;
|
private boolean enableDebug;
|
||||||
private int GOLD_TO_FULL;
|
private String languageFile;
|
||||||
private int IRON_TO_FULL;
|
private int GOLD_TO_FULL;
|
||||||
private int DIAMONDS_TO_FULL;
|
private int IRON_TO_FULL;
|
||||||
private String leatherName;
|
private boolean uninstallMode;
|
||||||
private String goldName;
|
private boolean checkForUpdates;
|
||||||
private String chainName;
|
private int LEATHER_TO_FULL;
|
||||||
private String ironName;
|
private int DIAMONDS_TO_FULL;
|
||||||
private String diamondName;
|
private boolean noFlightDurability;
|
||||||
private String elytraLore;
|
private List<String> allowedEnchantments;
|
||||||
private List<String> allowedEnchantments;
|
|
||||||
private String usageDeniedMessage;
|
|
||||||
private String elytraReceivedMessage;
|
|
||||||
private boolean checkForUpdates;
|
|
||||||
private boolean allowStats;
|
|
||||||
private boolean enableDebug;
|
|
||||||
private boolean uninstallMode;
|
|
||||||
|
|
||||||
// All the comments for the various config options.
|
private ArrayList<ConfigOption> configOptionsList;
|
||||||
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[] tierNameComment =
|
|
||||||
{"Name for every armored elytra tier."};
|
|
||||||
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 at all, remove them all and add \"NONE\"",
|
|
||||||
"You can find supported enchantments here:",
|
|
||||||
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html",
|
|
||||||
"Note that only 1 protection enchantment (PROTECTION_FIRE, PROTECTION_ENVIRONMENTAL etc) can be active on an elytra."};
|
|
||||||
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[] elytraLoreComment =
|
|
||||||
{"The lore of armored elytras. \"NONE\" = no lore. %ARMOR_TIER% is replaced by the name of the armor tier."};
|
|
||||||
private String[] updateComment =
|
|
||||||
{"Allow this plugin to check for updates on startup. It will not download new versions!"};
|
|
||||||
private String[] bStatsComment =
|
|
||||||
{"Allow this plugin to send (anonymised) stats using bStats. Please consider keeping it enabled.",
|
|
||||||
"It has a negligible impact on performance and more users on stats keeps me more motivated to support this plugin!"};
|
|
||||||
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.",
|
|
||||||
"Please do not forget to MAKE A BACKUP before enabling this option!"};
|
|
||||||
|
|
||||||
private ArrayList<ConfigOption> configOptionsList;
|
|
||||||
private ArmoredElytra plugin;
|
private ArmoredElytra plugin;
|
||||||
|
|
||||||
public ConfigLoader(ArmoredElytra plugin)
|
public ConfigLoader(ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
configOptionsList = new ArrayList<ConfigOption>();
|
configOptionsList = new ArrayList<ConfigOption>();
|
||||||
makeConfig();
|
makeConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the current config, the make a new one based on the old one or default values, whichever is applicable.
|
// Read the current config, the make a new one based on the old one or default values, whichever is applicable.
|
||||||
public void makeConfig()
|
public void makeConfig()
|
||||||
{
|
{
|
||||||
FileConfiguration config = plugin.getConfig();
|
// All the comments for the various config options.
|
||||||
|
String[] unbreakableComment =
|
||||||
|
{
|
||||||
|
"Setting this to true will cause armored elytras to be unbreakable.",
|
||||||
|
"Changing this to false will NOT make unbreakable elytras breakable again!"
|
||||||
|
};
|
||||||
|
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."
|
||||||
|
};
|
||||||
|
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%."
|
||||||
|
};
|
||||||
|
String[] enchantmentsComment =
|
||||||
|
{
|
||||||
|
"List of enchantments that are allowed to be put on an armored elytra.",
|
||||||
|
"If you do not want to allow any enchantments at all, remove them all and add \"NONE\"",
|
||||||
|
"You can find supported enchantments here:",
|
||||||
|
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html",
|
||||||
|
"Note that only 1 protection enchantment (PROTECTION_FIRE, PROTECTION_ENVIRONMENTAL etc) can be active on an elytra."
|
||||||
|
};
|
||||||
|
String[] updateComment =
|
||||||
|
{
|
||||||
|
"Allow this plugin to check for updates on startup. It will not download new versions!"
|
||||||
|
};
|
||||||
|
String[] bStatsComment =
|
||||||
|
{
|
||||||
|
"Allow this plugin to send (anonymised) stats using bStats. Please consider keeping it enabled.",
|
||||||
|
"It has a negligible impact on performance and more users on stats keeps me more motivated to support this plugin!"
|
||||||
|
};
|
||||||
|
String[] debugComment =
|
||||||
|
{
|
||||||
|
"Print debug messages to console. You will most likely never need this."
|
||||||
|
};
|
||||||
|
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.",
|
||||||
|
"Please do not forget to MAKE A BACKUP before enabling this option!"
|
||||||
|
};
|
||||||
|
String[] languageFileComment =
|
||||||
|
{
|
||||||
|
"Specify a language file to be used. Note that en_US.txt will get regenerated!"
|
||||||
|
};
|
||||||
|
|
||||||
// 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.
|
|
||||||
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);
|
|
||||||
configOptionsList.add(new ConfigOption ("goldRepair" , GOLD_TO_FULL));
|
|
||||||
IRON_TO_FULL = config.getInt ("ironRepair" , 4);
|
|
||||||
configOptionsList.add(new ConfigOption ("ironRepair" , IRON_TO_FULL));
|
|
||||||
DIAMONDS_TO_FULL = config.getInt ("diamondsRepair", 3);
|
|
||||||
configOptionsList.add(new ConfigOption ("diamondsRepair", DIAMONDS_TO_FULL));
|
|
||||||
|
|
||||||
leatherName = config.getString ("leatherName", "&2Leather Armored Elytra" );
|
FileConfiguration config = plugin.getConfig();
|
||||||
configOptionsList.add(new ConfigOption ("leatherName", leatherName, tierNameComment));
|
|
||||||
goldName = config.getString ("goldName" , "&EGolden Armored Elytra" );
|
|
||||||
configOptionsList.add(new ConfigOption ("goldName" , goldName ));
|
|
||||||
chainName = config.getString ("chainName" , "&8Chain Armored Elytra" );
|
|
||||||
configOptionsList.add(new ConfigOption ("chainName" , chainName ));
|
|
||||||
ironName = config.getString ("ironName" , "&7Iron Armored Elytra" );
|
|
||||||
configOptionsList.add(new ConfigOption ("ironName" , ironName ));
|
|
||||||
diamondName = config.getString ("diamondName", "&BDiamond Armored Elytra" );
|
|
||||||
configOptionsList.add(new ConfigOption ("diamondName", diamondName ));
|
|
||||||
|
|
||||||
elytraLore = config.getString ("elytraLore");
|
// Read all the options from the config, then put them in a configOption with their name, value and comment.
|
||||||
configOptionsList.add(new ConfigOption ("elytraLore", elytraLore, elytraLoreComment));
|
// THen put all configOptions into an ArrayList.
|
||||||
|
unbreakable = config.getBoolean ("unbreakable" , false);
|
||||||
|
configOptionsList.add(new ConfigOption ("unbreakable" , unbreakable , unbreakableComment ));
|
||||||
|
noFlightDurability = config.getBoolean ("noFlightDurability", false);
|
||||||
|
configOptionsList.add(new ConfigOption ("noFlightDurability", noFlightDurability, flyDurabilityComment));
|
||||||
|
|
||||||
usageDeniedMessage = config.getString ("usageDeniedMessage" );
|
LEATHER_TO_FULL = config.getInt ("leatherRepair" , 6);
|
||||||
configOptionsList.add(new ConfigOption ("usageDeniedMessage" , usageDeniedMessage , usageDeniedComment ));
|
configOptionsList.add(new ConfigOption ("leatherRepair" , LEATHER_TO_FULL, repairComment));
|
||||||
elytraReceivedMessage = config.getString ("elytraReceivedMessage" );
|
GOLD_TO_FULL = config.getInt ("goldRepair" , 5);
|
||||||
configOptionsList.add(new ConfigOption ("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
|
configOptionsList.add(new ConfigOption ("goldRepair" , GOLD_TO_FULL));
|
||||||
|
IRON_TO_FULL = config.getInt ("ironRepair" , 4);
|
||||||
|
configOptionsList.add(new ConfigOption ("ironRepair" , IRON_TO_FULL));
|
||||||
|
DIAMONDS_TO_FULL = config.getInt ("diamondsRepair", 3);
|
||||||
|
configOptionsList.add(new ConfigOption ("diamondsRepair", DIAMONDS_TO_FULL));
|
||||||
|
|
||||||
allowedEnchantments = config.getStringList("allowedEnchantments");
|
allowedEnchantments = config.getStringList("allowedEnchantments");
|
||||||
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment ));
|
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment));
|
||||||
|
|
||||||
checkForUpdates = config.getBoolean("checkForUpdates", true );
|
checkForUpdates = config.getBoolean ("checkForUpdates", true );
|
||||||
configOptionsList.add(new ConfigOption ("checkForUpdates", checkForUpdates, updateComment));
|
configOptionsList.add(new ConfigOption ("checkForUpdates", checkForUpdates, updateComment));
|
||||||
allowStats = config.getBoolean("allowStats" , true );
|
allowStats = config.getBoolean ("allowStats" , true );
|
||||||
configOptionsList.add(new ConfigOption ("allowStats" , allowStats, bStatsComment));
|
configOptionsList.add(new ConfigOption ("allowStats" , allowStats, bStatsComment));
|
||||||
enableDebug = config.getBoolean("enableDebug" , false);
|
enableDebug = config.getBoolean ("enableDebug" , false);
|
||||||
configOptionsList.add(new ConfigOption ("enableDebug" , enableDebug, debugComment));
|
configOptionsList.add(new ConfigOption ("enableDebug" , enableDebug, debugComment));
|
||||||
uninstallMode = config.getBoolean("uninstallMode" , false);
|
uninstallMode = config.getBoolean ("uninstallMode" , false);
|
||||||
configOptionsList.add(new ConfigOption ("uninstallMode" , uninstallMode, uninstallComment));
|
configOptionsList.add(new ConfigOption ("uninstallMode" , uninstallMode, uninstallComment));
|
||||||
|
languageFile = config.getString ("languageFile" , "en_US");
|
||||||
|
configOptionsList.add(new ConfigOption ("languageFile" , languageFile, languageFileComment));
|
||||||
|
|
||||||
writeConfig();
|
writeConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write new config file.
|
// Write new config file.
|
||||||
public void writeConfig()
|
public void writeConfig()
|
||||||
{
|
{
|
||||||
// Write all the config options to the config.yml.
|
// Write all the config options to the config.yml.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File dataFolder = plugin.getDataFolder();
|
File dataFolder = plugin.getDataFolder();
|
||||||
if (!dataFolder.exists())
|
if (!dataFolder.exists())
|
||||||
dataFolder.mkdir();
|
dataFolder.mkdir();
|
||||||
|
|
||||||
File saveTo = new File(plugin.getDataFolder(), "config.yml");
|
File saveTo = new File(plugin.getDataFolder(), "config.yml");
|
||||||
if (!saveTo.exists())
|
if (!saveTo.exists())
|
||||||
saveTo.createNewFile();
|
saveTo.createNewFile();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
saveTo.delete();
|
saveTo.delete();
|
||||||
saveTo.createNewFile();
|
saveTo.createNewFile();
|
||||||
}
|
}
|
||||||
FileWriter fw = new FileWriter(saveTo, true);
|
FileWriter fw = new FileWriter(saveTo, true);
|
||||||
PrintWriter pw = new PrintWriter(fw);
|
PrintWriter pw = new PrintWriter(fw);
|
||||||
|
|
||||||
for (ConfigOption configOption : configOptionsList)
|
for (ConfigOption configOption : configOptionsList)
|
||||||
pw.println(configOption.toString());
|
pw.println(configOption.toString());
|
||||||
|
|
||||||
pw.flush();
|
pw.flush();
|
||||||
pw.close();
|
pw.close();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save config.yml! Please contact pim16aap2 and show him the following code:");
|
Bukkit.getLogger().log(Level.SEVERE, "Could not save config.yml! Please contact pim16aap2 and show him the following code:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getInt(String path)
|
public Integer getInt(String path)
|
||||||
{
|
{
|
||||||
for (ConfigOption configOption : configOptionsList)
|
for (ConfigOption configOption : configOptionsList)
|
||||||
if (configOption.getName().equals(path))
|
if (configOption.getName().equals(path))
|
||||||
return configOption.getInt();
|
return configOption.getInt();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getBool(String path)
|
public Boolean getBool(String path)
|
||||||
{
|
{
|
||||||
for (ConfigOption configOption : configOptionsList)
|
for (ConfigOption configOption : configOptionsList)
|
||||||
if (configOption.getName().equals(path))
|
if (configOption.getName().equals(path))
|
||||||
return configOption.getBool();
|
return configOption.getBool();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String path)
|
public String getString(String path)
|
||||||
{
|
{
|
||||||
for (ConfigOption configOption : configOptionsList)
|
for (ConfigOption configOption : configOptionsList)
|
||||||
if (configOption.getName().equals(path))
|
if (configOption.getName().equals(path))
|
||||||
return configOption.getString();
|
return configOption.getString();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getStringList(String path)
|
public List<String> getStringList(String path)
|
||||||
{
|
{
|
||||||
for (ConfigOption configOption : configOptionsList)
|
for (ConfigOption configOption : configOptionsList)
|
||||||
if (configOption.getName().equals(path))
|
if (configOption.getName().equals(path))
|
||||||
return configOption.getStringList();
|
return configOption.getStringList();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,103 +4,102 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ConfigOption
|
public class ConfigOption
|
||||||
{
|
{
|
||||||
private String optionName;
|
private String optionName;
|
||||||
List<String> listVal = null;
|
List<String> listVal = null;
|
||||||
private Integer intVal = null;
|
private Integer intVal = null;
|
||||||
private Boolean boolVal = null;
|
private Boolean boolVal = null;
|
||||||
private String stringVal = null;
|
private String stringVal = null;
|
||||||
private String[] comment;
|
private String[] comment;
|
||||||
|
|
||||||
public ConfigOption(String optionName, int value, String[] comment)
|
public ConfigOption(String optionName, int value, String[] comment)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.intVal = value;
|
this.intVal = value;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, int value)
|
public ConfigOption(String optionName, int value)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.intVal = value;
|
this.intVal = value;
|
||||||
this.comment = null;
|
this.comment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, boolean value, String[] comment)
|
public ConfigOption(String optionName, boolean value, String[] comment)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.boolVal = value;
|
this.boolVal = value;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, boolean value)
|
public ConfigOption(String optionName, boolean value)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.boolVal = value;
|
this.boolVal = value;
|
||||||
this.comment = null;
|
this.comment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, String value, String[] comment)
|
public ConfigOption(String optionName, String value, String[] comment)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.stringVal = value;
|
this.stringVal = value;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, String value)
|
public ConfigOption(String optionName, String value)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.stringVal = value;
|
this.stringVal = value;
|
||||||
this.comment = null;
|
this.comment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, List<String> value, String[] comment)
|
public ConfigOption(String optionName, List<String> value, String[] comment)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.listVal = value;
|
this.listVal = value;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigOption(String optionName, List<String> value)
|
public ConfigOption(String optionName, List<String> value)
|
||||||
{
|
{
|
||||||
this.optionName = optionName;
|
this.optionName = optionName;
|
||||||
this.listVal = value;
|
this.listVal = value;
|
||||||
this.comment = null;
|
this.comment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String stringListToString()
|
public String stringListToString()
|
||||||
{
|
{
|
||||||
String string = "";
|
String string = "";
|
||||||
for (String s : listVal)
|
for (String s : listVal)
|
||||||
string += " - " + s + "\n";
|
string += " - " + s + "\n";
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() { return optionName; }
|
public String getName() { return optionName; }
|
||||||
public List<String> getStringList() { return listVal ; }
|
public List<String> getStringList() { return listVal ; }
|
||||||
public int getInt() { return intVal ; }
|
public int getInt() { return intVal ; }
|
||||||
public boolean getBool() { return boolVal ; }
|
public boolean getBool() { return boolVal ; }
|
||||||
public String getString() { return stringVal ; }
|
public String getString() { return stringVal ; }
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
String string = "";
|
String string = "";
|
||||||
|
|
||||||
// Print the comments, if there are any.
|
// Print the comments, if there are any.
|
||||||
if (comment != null)
|
if (comment != null)
|
||||||
{
|
{
|
||||||
string += "\n";
|
string += "\n";
|
||||||
for (String comLine : comment)
|
for (String comLine : comment)
|
||||||
// Prefix every line by a comment-sign (#).
|
// Prefix every line by a comment-sign (#).
|
||||||
string += "# " + comLine + "\n";
|
string += "# " + comLine + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then add the name of the option followed by its value (if it is an int/bool/String/String[]).
|
// Then add the name of the option followed by its value (if it is an int/bool/String/String[]).
|
||||||
string += optionName + ": " +
|
string += optionName + ": " +
|
||||||
(intVal != null ? intVal :
|
(intVal != null ? intVal :
|
||||||
boolVal != null ? boolVal :
|
boolVal != null ? boolVal :
|
||||||
stringVal != null ? "\'" + stringVal + "\'" :
|
stringVal != null ? "\'" + stringVal + "\'" :
|
||||||
listVal != null ? "\n" + stringListToString() : null);
|
listVal != null ? "\n" + stringListToString() : null);
|
||||||
|
return string;
|
||||||
return string;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
79
src/main/java/nl/pim16aap2/armoredElytra/util/Messages.java
Normal file
79
src/main/java/nl/pim16aap2/armoredElytra/util/Messages.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package nl.pim16aap2.armoredElytra.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
|
||||||
|
public class Messages
|
||||||
|
{
|
||||||
|
private Map<String, String> messageMap = new HashMap<String, String>();
|
||||||
|
private ArmoredElytra plugin;
|
||||||
|
private String locale;
|
||||||
|
private File textFile;
|
||||||
|
|
||||||
|
public Messages(ArmoredElytra plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.locale = plugin.getLocale();
|
||||||
|
textFile = new File(plugin.getDataFolder(), locale + ".txt");
|
||||||
|
readFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read locale file.
|
||||||
|
private void readFile()
|
||||||
|
{
|
||||||
|
// Load the default en_US from the resources.
|
||||||
|
plugin.saveResource("en_US.txt", true);
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(this.textFile)))
|
||||||
|
{
|
||||||
|
String sCurrentLine;
|
||||||
|
|
||||||
|
while ((sCurrentLine = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String key, value;
|
||||||
|
String[] parts = sCurrentLine.split("=", 2);
|
||||||
|
key = parts[0];
|
||||||
|
value = parts[1].replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1");
|
||||||
|
String[] newLineSplitter = value.split("\\\\n"); // Wut? Can I haz more backslash?
|
||||||
|
|
||||||
|
String values = newLineSplitter[0];
|
||||||
|
|
||||||
|
for (int idx = 1; idx < newLineSplitter.length; ++idx)
|
||||||
|
values += "\n" + newLineSplitter[idx];
|
||||||
|
|
||||||
|
this.messageMap.put(key, values);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e)
|
||||||
|
{
|
||||||
|
plugin.myLogger(Level.SEVERE, "Locale file " + this.locale + ".txt does not exist!");
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
plugin.myLogger(Level.SEVERE, "Could not read locale file! (" + this.locale + ".txt)");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a string from a key. Returns "null" if null.
|
||||||
|
public String getString(String key)
|
||||||
|
{
|
||||||
|
String value = null;
|
||||||
|
value = this.messageMap.get(key);
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
value = "BigDoors: Translation not found! Contact server admin!";
|
||||||
|
plugin.myLogger(Level.WARNING, "Failed to get translation for key " + key);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
@ -31,17 +31,22 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
*
|
*
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
* Check out https://bStats.org/ to learn more about bStats!
|
||||||
*/
|
*/
|
||||||
public class Metrics {
|
public class Metrics
|
||||||
|
{
|
||||||
|
|
||||||
static {
|
static
|
||||||
|
{
|
||||||
// You can use the property to disable the check in your test environment
|
// You can use the property to disable the check in your test environment
|
||||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false"))
|
||||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
{
|
||||||
final String defaultPackage = new String(
|
// Maven's Relocate is clever and changes strings, too. So we have to use this
|
||||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
// little "trick" ... :D
|
||||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
final String defaultPackage = new String(new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't' });
|
||||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
final String examplePackage = new String(new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' });
|
||||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
// We want to make sure nobody just copy & pastes the example and use the wrong
|
||||||
|
// package names
|
||||||
|
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage))
|
||||||
|
{
|
||||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,8 +75,10 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param plugin The plugin which stats should be submitted.
|
* @param plugin The plugin which stats should be submitted.
|
||||||
*/
|
*/
|
||||||
public Metrics(JavaPlugin plugin) {
|
public Metrics(JavaPlugin plugin)
|
||||||
if (plugin == null) {
|
{
|
||||||
|
if (plugin == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||||
}
|
}
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -82,7 +89,8 @@ public class Metrics {
|
|||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
// Check if the config file exists
|
// Check if the config file exists
|
||||||
if (!config.isSet("serverUuid")) {
|
if (!config.isSet("serverUuid"))
|
||||||
|
{
|
||||||
|
|
||||||
// Add default values
|
// Add default values
|
||||||
config.addDefault("enabled", true);
|
config.addDefault("enabled", true);
|
||||||
@ -92,15 +100,14 @@ public class Metrics {
|
|||||||
config.addDefault("logFailedRequests", false);
|
config.addDefault("logFailedRequests", false);
|
||||||
|
|
||||||
// Inform the server owners about bStats
|
// Inform the server owners about bStats
|
||||||
config.options().header(
|
config.options().header("bStats collects some data for plugin authors like how many servers are using their plugins.\n" + "To honor their work, you should not disable it.\n" + "This has nearly no effect on the server performance!\n" + "Check out https://bStats.org/ to learn more :)").copyDefaults(true);
|
||||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
try
|
||||||
"To honor their work, you should not disable it.\n" +
|
{
|
||||||
"This has nearly no effect on the server performance!\n" +
|
|
||||||
"Check out https://bStats.org/ to learn more :)"
|
|
||||||
).copyDefaults(true);
|
|
||||||
try {
|
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (IOException ignored) { }
|
}
|
||||||
|
catch (IOException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the data
|
// Load the data
|
||||||
@ -108,16 +115,22 @@ public class Metrics {
|
|||||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
// Search for all other bStats Metrics classes to see if we are the first one
|
// Search for all other bStats Metrics classes to see if we are the first one
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
for (Class<?> service : Bukkit.getServicesManager().getKnownServices())
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||||
found = true; // We aren't the first
|
found = true; // We aren't the first
|
||||||
break;
|
break;
|
||||||
} catch (NoSuchFieldException ignored) { }
|
}
|
||||||
|
catch (NoSuchFieldException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Register our service
|
// Register our service
|
||||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||||
if (!found) {
|
if (!found)
|
||||||
|
{
|
||||||
// We are the first!
|
// We are the first!
|
||||||
startSubmitting();
|
startSubmitting();
|
||||||
}
|
}
|
||||||
@ -126,38 +139,48 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Starts the Scheduler which submits our data every 30 minutes.
|
* Starts the Scheduler which submits our data every 30 minutes.
|
||||||
*/
|
*/
|
||||||
private void startSubmitting() {
|
private void startSubmitting()
|
||||||
|
{
|
||||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
timer.scheduleAtFixedRate(new TimerTask()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
{
|
||||||
|
if (!plugin.isEnabled())
|
||||||
|
{ // Plugin was disabled
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
// Nevertheless we want our code to run in the Bukkit main thread, so we have to
|
||||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
// use the Bukkit scheduler
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
// Don't be afraid! The connection to the bStats server is still async, only the
|
||||||
|
// stats collection is sync ;)
|
||||||
|
Bukkit.getScheduler().runTask(plugin, new Runnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
|
{
|
||||||
submitData();
|
submitData();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 1000*60*5, 1000*60*30);
|
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
// Submit the data every 30 minutes, first time after 5 minutes to give other
|
||||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
// plugins enough time to start
|
||||||
|
// WARNING: Changing the frequency has no effect but your plugin WILL be
|
||||||
|
// blocked/deleted!
|
||||||
// WARNING: Just don't do it!
|
// WARNING: Just don't do it!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the plugin specific data.
|
* Gets the plugin specific data. This method is called using Reflection.
|
||||||
* This method is called using Reflection.
|
|
||||||
*
|
*
|
||||||
* @return The plugin specific data.
|
* @return The plugin specific data.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public JSONObject getPluginData() {
|
public JSONObject getPluginData()
|
||||||
|
{
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
|
|
||||||
String pluginName = plugin.getDescription().getName();
|
String pluginName = plugin.getDescription().getName();
|
||||||
@ -166,10 +189,12 @@ public class Metrics {
|
|||||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||||
JSONArray customCharts = new JSONArray();
|
JSONArray customCharts = new JSONArray();
|
||||||
for (CustomChart customChart : charts) {
|
for (CustomChart customChart : charts)
|
||||||
|
{
|
||||||
// Add the data of the custom charts
|
// Add the data of the custom charts
|
||||||
JSONObject chart = customChart.getRequestJsonObject();
|
JSONObject chart = customChart.getRequestJsonObject();
|
||||||
if (chart == null) { // If the chart is null, we skip it
|
if (chart == null)
|
||||||
|
{ // If the chart is null, we skip it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
customCharts.add(chart);
|
customCharts.add(chart);
|
||||||
@ -185,17 +210,20 @@ public class Metrics {
|
|||||||
* @return The server specific data.
|
* @return The server specific data.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private JSONObject getServerData() {
|
private JSONObject getServerData()
|
||||||
|
{
|
||||||
// Minecraft specific data
|
// Minecraft specific data
|
||||||
int playerAmount;
|
int playerAmount;
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
// This fixes java.lang.NoSuchMethodError:
|
||||||
|
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size() : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
}
|
||||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
catch (Exception e)
|
||||||
} catch (Exception e) {
|
{
|
||||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||||
}
|
}
|
||||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||||
@ -230,35 +258,52 @@ public class Metrics {
|
|||||||
* Collects the data and sends it afterwards.
|
* Collects the data and sends it afterwards.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void submitData() {
|
private void submitData()
|
||||||
|
{
|
||||||
final JSONObject data = getServerData();
|
final JSONObject data = getServerData();
|
||||||
|
|
||||||
JSONArray pluginData = new JSONArray();
|
JSONArray pluginData = new JSONArray();
|
||||||
// Search for all other bStats Metrics classes to get their plugin data
|
// Search for all other bStats Metrics classes to get their plugin data
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
for (Class<?> service : Bukkit.getServicesManager().getKnownServices())
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||||
|
|
||||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service))
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
}
|
||||||
|
catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException ignored) { }
|
}
|
||||||
|
catch (NoSuchFieldException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.put("plugins", pluginData);
|
data.put("plugins", pluginData);
|
||||||
|
|
||||||
// Create a new thread for the connection to the bStats server
|
// Create a new thread for the connection to the bStats server
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
// Send the data
|
// Send the data
|
||||||
sendData(data);
|
sendData(data);
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
// Something went wrong! :(
|
// Something went wrong! :(
|
||||||
if (logFailedRequests) {
|
if (logFailedRequests)
|
||||||
|
{
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,11 +317,14 @@ public class Metrics {
|
|||||||
* @param data The data to send.
|
* @param data The data to send.
|
||||||
* @throws Exception If the request failed.
|
* @throws Exception If the request failed.
|
||||||
*/
|
*/
|
||||||
private static void sendData(JSONObject data) throws Exception {
|
private static void sendData(JSONObject data) throws Exception
|
||||||
if (data == null) {
|
{
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Data cannot be null!");
|
throw new IllegalArgumentException("Data cannot be null!");
|
||||||
}
|
}
|
||||||
if (Bukkit.isPrimaryThread()) {
|
if (Bukkit.isPrimaryThread())
|
||||||
|
{
|
||||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||||
}
|
}
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||||
@ -310,8 +358,10 @@ public class Metrics {
|
|||||||
* @return The gzipped String.
|
* @return The gzipped String.
|
||||||
* @throws IOException If the compression failed.
|
* @throws IOException If the compression failed.
|
||||||
*/
|
*/
|
||||||
private static byte[] compress(final String str) throws IOException {
|
private static byte[] compress(final String str) throws IOException
|
||||||
if (str == null) {
|
{
|
||||||
|
if (str == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
@ -324,7 +374,8 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Represents a custom chart.
|
* Represents a custom chart.
|
||||||
*/
|
*/
|
||||||
public static abstract class CustomChart {
|
public static abstract class CustomChart
|
||||||
|
{
|
||||||
|
|
||||||
// The id of the chart
|
// The id of the chart
|
||||||
final String chartId;
|
final String chartId;
|
||||||
@ -334,32 +385,41 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param chartId The id of the chart.
|
* @param chartId The id of the chart.
|
||||||
*/
|
*/
|
||||||
CustomChart(String chartId) {
|
CustomChart(String chartId)
|
||||||
if (chartId == null || chartId.isEmpty()) {
|
{
|
||||||
|
if (chartId == null || chartId.isEmpty())
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||||
}
|
}
|
||||||
this.chartId = chartId;
|
this.chartId = chartId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private JSONObject getRequestJsonObject() {
|
private JSONObject getRequestJsonObject()
|
||||||
|
{
|
||||||
JSONObject chart = new JSONObject();
|
JSONObject chart = new JSONObject();
|
||||||
chart.put("chartId", chartId);
|
chart.put("chartId", chartId);
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
JSONObject data = getChartData();
|
JSONObject data = getChartData();
|
||||||
if (data == null) {
|
if (data == null)
|
||||||
|
{
|
||||||
// If the data is null we don't send the chart.
|
// If the data is null we don't send the chart.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
chart.put("data", data);
|
chart.put("data", data);
|
||||||
} catch (Throwable t) {
|
}
|
||||||
if (logFailedRequests) {
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
if (logFailedRequests)
|
||||||
|
{
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return chart;
|
return chart;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract JSONObject getChartData() throws Exception;
|
protected abstract JSONObject getChartData() throws Exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import org.json.simple.JSONValue;
|
|||||||
|
|
||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
import nl.pim16aap2.armoredElytra.ArmoredElytra;
|
||||||
|
|
||||||
|
|
||||||
public class Update
|
public class Update
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ public class Update
|
|||||||
|
|
||||||
// Static information for querying the API
|
// Static information for querying the API
|
||||||
private static final String API_QUERY = "/servermods/files?projectIds=";
|
private static final String API_QUERY = "/servermods/files?projectIds=";
|
||||||
private static final String API_HOST = "https://api.curseforge.com";
|
private static final String API_HOST = "https://api.curseforge.com";
|
||||||
|
|
||||||
private String versionName;
|
private String versionName;
|
||||||
ArmoredElytra plugin;
|
ArmoredElytra plugin;
|
||||||
@ -36,7 +35,8 @@ public class Update
|
|||||||
/**
|
/**
|
||||||
* Check for updates anonymously (keyless)
|
* Check for updates anonymously (keyless)
|
||||||
*
|
*
|
||||||
* @param projectID The BukkitDev Project ID, found in the "Facts" panel on the right-side of your project page.
|
* @param projectID The BukkitDev Project ID, found in the "Facts" panel on the
|
||||||
|
* right-side of your project page.
|
||||||
*/
|
*/
|
||||||
public Update(int projectID, ArmoredElytra plugin)
|
public Update(int projectID, ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
@ -46,8 +46,10 @@ public class Update
|
|||||||
/**
|
/**
|
||||||
* Check for updates using your Curse account (with key)
|
* Check for updates using your Curse account (with key)
|
||||||
*
|
*
|
||||||
* @param projectID The BukkitDev Project ID, found in the "Facts" panel on the right-side of your project page.
|
* @param projectID The BukkitDev Project ID, found in the "Facts" panel on the
|
||||||
* @param apiKey Your ServerMods API key, found at https://dev.bukkit.org/home/servermods-apikey/
|
* right-side of your project page.
|
||||||
|
* @param apiKey Your ServerMods API key, found at
|
||||||
|
* https://dev.bukkit.org/home/servermods-apikey/
|
||||||
*/
|
*/
|
||||||
public Update(int projectID, String apiKey, ArmoredElytra plugin)
|
public Update(int projectID, String apiKey, ArmoredElytra plugin)
|
||||||
{
|
{
|
||||||
@ -58,8 +60,6 @@ public class Update
|
|||||||
query();
|
query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int versionCompare(String str1, String str2)
|
public int versionCompare(String str1, String str2)
|
||||||
{
|
{
|
||||||
String[] vals1 = str1.split("\\.");
|
String[] vals1 = str1.split("\\.");
|
||||||
@ -67,7 +67,7 @@ public class Update
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
// set index to first non-equal ordinal or length of shortest version string
|
// set index to first non-equal ordinal or length of shortest version string
|
||||||
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i]))
|
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i]))
|
||||||
i++;
|
i++;
|
||||||
// compare first non-equal ordinal number
|
// compare first non-equal ordinal number
|
||||||
if (i < vals1.length && i < vals2.length)
|
if (i < vals1.length && i < vals2.length)
|
||||||
{
|
{
|
||||||
@ -82,12 +82,11 @@ public class Update
|
|||||||
// Get the latest version of the plugin.
|
// Get the latest version of the plugin.
|
||||||
public String getLatestVersion()
|
public String getLatestVersion()
|
||||||
{
|
{
|
||||||
if (versionName == null)
|
if (versionName == null)
|
||||||
return null;
|
return null;
|
||||||
return versionName.replaceAll("Armored Elytra ", "");
|
return versionName.replaceAll("Armored Elytra ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the API to find the latest approved file's details.
|
* Query the API to find the latest approved file's details.
|
||||||
*/
|
*/
|
||||||
@ -140,8 +139,11 @@ public class Update
|
|||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
// There was an error reading the query.
|
// There was an error reading the query.
|
||||||
// Does not print stacktrace, so people won't see any errors from this plugin when Bukkit Dev's servers are down,
|
// Does not print stacktrace, so people won't see any errors from this plugin
|
||||||
// So people won't think the plugin is broken, while the actualy problem is much, much smaller. latestVersion will be null, though, which will prompt a warning in the log instead.
|
// when Bukkit Dev's servers are down,
|
||||||
|
// So people won't think the plugin is broken, while the actualy problem is
|
||||||
|
// much, much smaller. latestVersion will be null, though, which will prompt a
|
||||||
|
// warning in the log instead.
|
||||||
|
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
12
src/main/resources/en_US.txt
Normal file
12
src/main/resources/en_US.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
TIER.Leather=&2Leather Armored Elytra
|
||||||
|
TIER.Gold=&EGolden Armored Elytra
|
||||||
|
TIER.Chain=&8Chain Armored Elytra
|
||||||
|
TIER.Iron=&7Iron Armored Elytra
|
||||||
|
TIER.Diamond=&BDiamond Armored Elytra
|
||||||
|
MESSAGES.Lore=Elytra with %ARMOR_TIER% level protection
|
||||||
|
MESSAGES.UsageDenied=You do not have the required permissions to wear %ARMOR_TIER%!
|
||||||
|
MESSAGES.ElytraReceived=&2A(n) %ARMOR_TIER% has been bestowed upon you!
|
||||||
|
MESSAGES.UninstallMode=&cPlugin in uninstall mode! New Armored Elytras are not allowed!
|
||||||
|
MESSAGES.UnsupportedTier=&cNot a supported armor tier! Try one of these: leather, gold, chain, iron, diamond.
|
||||||
|
MESSAGES.NoGivePermission=&cYou do not have the required permission node to give %ARMOR_TIER%s.
|
||||||
|
MESSAGES.RepairNeeded=&cYou cannot equip this elytra! Please repair it in an anvil first.
|
@ -1,6 +1,6 @@
|
|||||||
name: ArmoredElytra
|
name: ArmoredElytra
|
||||||
main: nl.pim16aap2.armoredElytra.ArmoredElytra
|
main: nl.pim16aap2.armoredElytra.ArmoredElytra
|
||||||
version: 2.4.2
|
version: 2.4.6
|
||||||
author: Pim
|
author: Pim
|
||||||
commands:
|
commands:
|
||||||
ArmoredElytra:
|
ArmoredElytra:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user