- Added config options to change messages you get when receiving an armored elytra and when you are not allowed to wear a certain tier of elytra. Changing the messages to "NONE" will cause no message to be printed.

- You can now give armored elytras to players from the console using the command: /armoredelytra <player> <armor>
This commit is contained in:
Pim van der Loos 2017-09-23 23:39:23 +02:00
parent b7059d4544
commit 9fb779f495
5 changed files with 145 additions and 22 deletions

View File

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

View File

@ -1,12 +1,14 @@
package nl.pim16aap2.armoredElytra;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
@ -25,18 +27,46 @@ public class ArmoredElytra extends JavaPlugin implements Listener
private int IRON_TO_FULL;
private int DIAMONDS_TO_FULL;
private String[] allowedEnchants;
private String usageDeniedMessage;
private String elytraReceivedMessage;
@Override
public void onEnable()
{
FileConfiguration config = this.getConfig();
config.addDefault("leatherRepair", 6);
config.addDefault("goldRepair", 5);
config.addDefault("ironRepair", 4);
config.addDefault("diamondsRepair", 3);
config.addDefault("allowCurses", true);
config.addDefault("allowedEnchantments", new String[]{"DURABILITY","PROTECTION_FIRE","PROTECTION_EXPLOSIONS",
"PROTECTION_PROJECTILE","PROTECTION_ENVIRONMENTAL","THORNS"});
config.addDefault("usageDeniedMessage", "You do not have the required permission node for this armor tier!");
config.addDefault("elytraReceivedMessage", "An armored elytra has been bestowed upon you!");
saveDefaultConfig();
LEATHER_TO_FULL = this.getConfig().getInt("leatherRepair", 6);
GOLD_TO_FULL = this.getConfig().getInt("goldRepair", 5);
IRON_TO_FULL = this.getConfig().getInt("ironRepair", 4);
DIAMONDS_TO_FULL = this.getConfig().getInt("diamondsRepair", 3);
cursesAllowed = this.getConfig().getBoolean("allowCurses", true);
List<String> list = this.getConfig().getStringList("allowedEnchantments");
allowedEnchants = list.toArray(new String[0]);
LEATHER_TO_FULL = config.getInt("leatherRepair", 6);
GOLD_TO_FULL = config.getInt("goldRepair", 5);
IRON_TO_FULL = config.getInt("ironRepair", 4);
DIAMONDS_TO_FULL = config.getInt("diamondsRepair", 3);
cursesAllowed = config.getBoolean("allowCurses", true);
List<String> list = config.getStringList("allowedEnchantments");
allowedEnchants = list.toArray(new String[0]);
usageDeniedMessage = config.getString("usageDeniedMessage");
elytraReceivedMessage = config.getString("elytraReceivedMessage");
if (Objects.equals(usageDeniedMessage, new String("NONE")))
{
usageDeniedMessage = null;
}
if (Objects.equals(elytraReceivedMessage, new String("NONE")))
{
elytraReceivedMessage = null;
}
config.options().copyDefaults(true);
saveConfig();
Bukkit.getLogger().log(Level.INFO, "["+this.getName()+"] "+"Allowed enchantments:");
for (String s : allowedEnchants)
@ -46,7 +76,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
if (compatibleMCVer())
{
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor, cursesAllowed, LEATHER_TO_FULL, GOLD_TO_FULL, IRON_TO_FULL, DIAMONDS_TO_FULL, allowedEnchants), this);
Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor, cursesAllowed, LEATHER_TO_FULL, GOLD_TO_FULL, IRON_TO_FULL, DIAMONDS_TO_FULL, allowedEnchants, usageDeniedMessage), this);
} else {
Bukkit.getLogger().log(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft!");
}
@ -55,22 +85,26 @@ public class ArmoredElytra extends JavaPlugin implements Listener
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
Player player;
if (sender instanceof Player)
{
Player player = (Player) sender;
player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("ArmoredElytra"))
{
if (args.length == 1)
{
ItemStack newElytra = null;
String tier = args[0];
// Leather armor.
if (tier.equalsIgnoreCase("leather"))
{
if (player.hasPermission("armoredelytra.give.leather"))
{
player.sendMessage("Giving you an armored elytra of the leather armor tier!");
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 1);
} else
{
@ -82,7 +116,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener
{
if (player.hasPermission("armoredelytra.give.gold"))
{
player.sendMessage("Giving you an armored elytra of the gold armor tier!");
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 2);
} else
{
@ -94,7 +131,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener
{
if (player.hasPermission("armoredelytra.give.chain"))
{
player.sendMessage("Giving you an armored elytra of the chain armor tier!");
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 3);
} else
{
@ -106,7 +146,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener
{
if (player.hasPermission("armoredelytra.give.iron"))
{
player.sendMessage("Giving you an armored elytra of the iron armor tier!");
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 4);
} else
{
@ -118,7 +161,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener
{
if (player.hasPermission("armoredelytra.give.diamond"))
{
player.sendMessage("Giving you an armored elytra of the diamond armor tier!");
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 5);
} else
{
@ -133,6 +179,70 @@ public class ArmoredElytra extends JavaPlugin implements Listener
return true;
}
}
} else
{
if (args.length == 2)
{
ItemStack newElytra = null;
String tier = args[1];
if (Bukkit.getPlayer(args[0]) != null)
{
player = Bukkit.getPlayer(args[0]);
// Leather armor tier.
if (tier.equalsIgnoreCase("leather"))
{
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
Bukkit.getLogger().log(Level.INFO, "Giving an armored elytra of the leather armor tier to player "+player.getName());
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 1);
// Gold armor tier.
} else if (tier.equalsIgnoreCase("gold"))
{
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
Bukkit.getLogger().log(Level.INFO, "Giving an armored elytra of the gold armor tier to player "+player.getName());
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 2);
// Chain armor tier.
} else if (tier.equalsIgnoreCase("chain"))
{
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
Bukkit.getLogger().log(Level.INFO, "Giving an armored elytra of the chain armor tier to player "+player.getName());
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 3);
// Iron armor tier.
} else if (tier.equalsIgnoreCase("iron"))
{
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
Bukkit.getLogger().log(Level.INFO, "Giving an armored elytra of the iron armor tier to player "+player.getName());
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 4);
// Diamond armor tier.
} else if (tier.equalsIgnoreCase("diamond"))
{
if (elytraReceivedMessage != null)
{
player.sendMessage(elytraReceivedMessage);
}
Bukkit.getLogger().log(Level.INFO, "Giving an armored elytra of the armor armor tier to player "+player.getName());
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 5);
}
giveArmoredElytraToPlayer(player, newElytra);
return true;
} else
{
Bukkit.getLogger().log(Level.INFO, "Player "+args[1]+" not found!");
return true;
}
}
}
return false;
}

View File

@ -33,12 +33,13 @@ public class EventHandlers implements Listener
private boolean cursesAllowed;
private NBTEditor nbtEditor;
private final ArmoredElytra plugin;
private String usageDeniedMessage;
private String[] allowedEnchantments;
private String[] cursedEnchantments = {"MENDING",
"VANISHING_CURSE",
"BINDING_CURSE"};
public EventHandlers(ArmoredElytra plugin, NBTEditor nbtEditor, boolean allowCurses, int LEATHER_TO_FULL, int GOLD_TO_FULL, int IRON_TO_FULL, int DIAMONDS_TO_FULL, String[] allowedEnchantments)
public EventHandlers(ArmoredElytra plugin, NBTEditor nbtEditor, boolean allowCurses, int LEATHER_TO_FULL, int GOLD_TO_FULL, int IRON_TO_FULL, int DIAMONDS_TO_FULL, String[] allowedEnchantments, String usageDeniedMessage)
{
this.plugin = plugin;
this.nbtEditor = nbtEditor;
@ -48,6 +49,7 @@ public class EventHandlers implements Listener
this.LEATHER_TO_FULL = LEATHER_TO_FULL;
this.GOLD_TO_FULL = GOLD_TO_FULL;
this.IRON_TO_FULL = IRON_TO_FULL;
this.usageDeniedMessage = usageDeniedMessage;
}
@ -425,7 +427,10 @@ public class EventHandlers implements Listener
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
{
player.sendMessage(ChatColor.RED + "You do not have the required permission to wear this armor tier!.");
if (usageDeniedMessage != null)
{
player.sendMessage(ChatColor.RED + usageDeniedMessage);
}
event.setCancelled(true);
}
}
@ -463,7 +468,10 @@ public class EventHandlers implements Listener
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
{
player.sendMessage(ChatColor.RED + "You do not have the required permission to wear this armor tier!.");
if (usageDeniedMessage != null)
{
player.sendMessage(ChatColor.RED + usageDeniedMessage);
}
unenquipChestPlayer(player);
}
player.updateInventory();

View File

@ -16,5 +16,10 @@ allowedEnchantments:
- PROTECTION_EXPLOSIONS
- PROTECTION_PROJECTILE
- PROTECTION_ENVIRONMENTAL
- DIAMOND_ARMOR_ITEMS
- THORNS
- THORNS
# Message players receive when they lack the required permissions to wear a certain armor tier. "NONE" = no message
usageDeniedMessage: "You do not have the required permission node for this armor tier!"
# Message players receive when they are given an armored elytra using commands. "NONE" = no message
elytraReceivedMessage: "An armored elytra has been bestowed upon you!"

View File

@ -1,6 +1,6 @@
name: ArmoredElytra
main: nl.pim16aap2.armoredElytra.ArmoredElytra
version: 1.4.0
version: 1.5.0
author: Pim
commands:
ArmoredElytra: