Plugin Help!

Discussion in 'Plugin Development' started by Wither_Style, Jun 12, 2015.

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

    Wither_Style

    Hey, I need help with one of my plugins
    here is the code:
    Code:
    package me.wither.killreward;
    
    import org.bukkit.Achievement;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.FireworkEffect.Type;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.Potion;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Main  extends JavaPlugin implements Listener
    {
      public void onEnable()
      {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
        Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "VP " + ChatColor.RESET + "is now enabled.");
      }
    
      public void onDisable()
      {
        Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "VP " + ChatColor.RESET + "is now disabled.");
      }
    
      @EventHandler
      public void PlayerDeath(PlayerDeathEvent e)
      {
        Player p = e.getEntity().getPlayer();
        if (p.getKiller().hasPermission("vheal.reward")) {
          if ((p instanceof Player)){
              if ((p.getKiller() instanceof Player))
            p.getKiller().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 10, 3));
            p.sendMessage(ChatColor.YELLOW + "[VP] " + ChatColor.WHITE + "and you have received regeneration for 10 seconds.");
            p.sendMessage(ChatColor.WHITE + "Also, you've received " + ChatColor.YELLOW + " 5" + ChatColor.RESET + " instant healing potions!." );
            Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "[VP]" + ChatColor.WHITE + " Player %player% Have Been Healead".replace("%player%", p.getName()));     }
            for (int i = 0; i < 5; i++) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.POTION) });
             
              
              
        }
          
      }
        else {
            if (p.getKiller() != null);
        Bukkit.getServer().getConsoleSender().sendMessage("Player died by natural causes");
        Bukkit.broadcastMessage(p.getName() + "has died.");}
      
        }
    }
    
    Okay, let me explain the problems:
    I am trying to find a way to give splash potions of healling II where it says Material.POTION. How can that be done?
    And last question, when a player dies from fall damage for example, the console goes crazy because it couldnt find who the killer was. How can I make it so when a player dies to a mob/fall damage it doesnt do anything, and the plugin activates only if the player dies by an other player?
    Thanks in advance :D
    PS: I'm new to coding, so dont judge :D
     
    Last edited: Jun 12, 2015
  2. Offline

    Suppressing

    First, to fix the player dieing from fall damage I believe you can add this:
    Code:
    if (p.getKiller == null){
        //code
    }
    For the potion question, I'm not to sure what you're asking, but if you want to add a potion effect to the killer when he kills someone add this:

    Code:
    p.getKiller.addPotionEffect(new PotionEffect(PotionEfffectType.<type>, <duration>, <amplifier>
     
  3. Offline

    Wither_Style

    Thank you for the reply. I didnt manage to fix the console error thing, because i've no idea where to add the part of the code you mentioned. Now for the potion part. I just want to be able to give a potion , not the effect, the item to a player. I've no idea how to achieve that, since MATERIAL.Potion doesnt really seem to work.
     
  4. Offline

    Suppressing

    @Wither_Style

    Add this:
    Code:
    if (p.getKiller == null){
        return true;
    }
    Above this:
    Code:
    if (p.getKiller().hasPermission("vheal.reward"))
    Adding a potion:
    Code:
    p.getInventory().addItem(new ItemStack(Material.POTION, 1, (short) 16421));
    16421 is the potion ID. For example 373:16421 is splash potion of healing.
     
    Last edited: Jun 12, 2015
Thread Status:
Not open for further replies.

Share This Page