How to set a potion effect if a player wears a certain armor

Discussion in 'Plugin Development' started by ToxicNeedsHelp, Feb 20, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    ToxicNeedsHelp

    Exactly what the title says

    Heres my code so far:

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    Player p = (Player) sender;
    if (commandLabel.equalsIgnoreCase("tank")) {
    if (!plugin.Tank.contains(p.getName())) {
    if (!plugin.kitused.contains(p.getName())) {
    if (p.hasPermission("tank.use")) {
    p.sendMessage(ChatColor.GREEN + "You have recieved the Tank kit");
    plugin.Archer.add(p.getName());
    p.getInventory().clear();
    ItemStack gHelm = new ItemStack(Material.GOLDEN_HELMET);
    gHelm.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,1);

    //I want the effect to be implemented in the GOLDEN HELMET
    p.getInventory().setHelmet(gHelm);
     
  2. Offline

    xpaintall

    well probably you would need to detect if the player wears a gold helmet so you would need to check the player's inventory,
    Code:
     if(p.getInventory // also something I forgot) {} 
    and then check if he wears a gold helmet.
    I cannot tell u how to make that since I am typing this on my phone, sorry
    OH SORRY THE PNG WAS NOT MEANT TO BE SENT (I did it on accident)
     

    Attached Files:

  3. Offline

    Strahan

    It's not quite as simple as that, and since he obviously knows how to get inventory since he does it in his code, your code snippet is pretty pointless as the relevant part would be in the "something I forgot" lol

    That aside, that's not how you would want to do it anyway. You need to monitor when they change their armor and act accordingly. You can write it from scratch, but I recommend using Borlea's ArmorEquipEvent instead. No need to reinvent the wheel. Then you just listen for an armor change and check to see what changed. If kit armor is removed, then you want to strip the enchants the kit provides. If kit armor is applied, then you apply the kit enchant.
     
Thread Status:
Not open for further replies.

Share This Page