Plugin Help User To Spawn In With Potion Effect.

Discussion in 'Plugin Help/Development/Requests' started by Tomw787, Jan 9, 2016.

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

    Tomw787

    I'm wondering if anyone can help me with the following code, I'm just wanting a user to spawn in with a potion effect and an item. Help will be greatly appreciated. :)

    Code:
    package com.tomplays.nightvision;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class MainClass extends JavaPlugin{
    
        public void onEnable(){
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
            logger.info(pdfFile.getName() + " Has been enabled (V. " + pdfFile.getVersion() + ")");
           
        }
    
        public void onDisable(){
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
           
            logger.info(pdfFile.getName() + " Has been disabled (V. " + pdfFile.getVersion() + ")");
           
        }
       
    
       
    
            @EventHandler
            public void onPlayerJoin (PlayerJoinEvent e) {
               
                Player player = e.getPlayer();
               
                e.setJoinMessage(ChatColor.AQUA + "Welcome!");
               
                player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 100000, 100 ));
       
                player.getInventory().addItem(new ItemStack(Material.APPLE, 1));
    } }
    
     
  2. Dont forget to use "player.getDisplayName" to set the JoinMessage

    Maybe this works:

    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
          
            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 99999, 2));
          
            e.setJoinMessage(ChatColor.GREEN + "+ " + ChatColor.WHITE + p.getDisplayName());
        }
     
  3. Offline

    Tomw787

    Hey, This still ain't working, any suggestions?
     
  4. Offline

    oceantheskatr

    @Tomw787 Do you get any errors? Which parts work on your server? Do you get the welcome message/apple still?
     
  5. Offline

    Tomw787

    Nope, Nothing is working at all on server
     
  6. Offline

    ZP18

    Hi @oceantheskatr, remember me? :p

    Anyway it is because you haven't implemented Listener and registered the event
     
    oceantheskatr and Tomw787 like this.
  7. Offline

    Tomw787

    Thanks! It works now!
     
Thread Status:
Not open for further replies.

Share This Page