Solved Plugin Problem

Discussion in 'Plugin Development' started by lon_chaney, Jul 11, 2014.

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

    lon_chaney

    I have been trying to make a plugin where if a player sneaks, they will become invisible, but I keep getting this error while coding.
    Code:
    package me.lonchaney.ChestDisplay;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffectType;
     
    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
        }
       
        @EventHandler
        public void onEvent(PlayerEvent event){
            Player player = event.getPlayer();
            if(player.isSneaking()){
            player.addPotionEffect(PotionEffectType.INVISIBILITY);
            }
        }
    }
     
  2. Offline

    Wizehh

    I figured out your error on my own, but please specify it next time!

    Anyway, the addPotionEffect method takes a PotionEffect instance as a parameter, and the PotionEffect constructor needs 3 parameters: the PotionEffectType (an enum, like you already have), the duration of the potion effect, and the amplifier of the potion effect.
    For example, you might do this:
    Code:java
    1. addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, 1));
     
  3. Offline

    lon_chaney

    Ok, I tried that and everything looked alright until I started up my server...
    http://pastebin.com/vvzGgp8g
     
  4. Offline

    drtshock

  5. Offline

    lon_chaney

    drtshock Like this?
    Code:
    @EventHandler
        public void onPlayerToggleSneakEvent(PlayerEvent event){
            Player player = event.getPlayer();
            if(player.isSneaking()){
            player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, 1));
    EDIT: Not working :( Sorry, but I'm a beginner.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    MinezBombz

    Code:java
    1. @EventHandler
    2. public void onSneak(PlayerToggleSneakEvent event) {
    3. Player player = event.getPlayer();
    4. if (!player.isSneaking()) {
    5. player.addPotionEffect(new PotionEffect(
    6. PotionEffectType.INVISIBILITY, 1000000, 1));
    7. }else if(player.isSneaking()){
    8. player.removePotionEffect(PotionEffectType.INVISIBILITY);
    9.  
    10. }

    lon_chaney I made this, when you sneak it gives you invisibility forever, then when you un-sneak it takes it away.
    If you can't get it to work click here.
     
  7. Offline

    ArsenArsen

    Remove else or do somethong else in elsr, amateur MinezBombz
     
  8. Offline

    MinezBombz

    ArsenArsen Removing the else makes it not remove the potion when you un-sneak, so if you don't mind i'll keep it unless you would be so kind as to helping me out and telling me the proper way as to do it rather than hurdling abuse at me.

    EDIT: Also having the 'else' allows expandability later on.
     
    ZodiacTheories likes this.
  9. Offline

    ArsenArsen

    Wait, [dirt] Readed wrong part ur right.
    Too bumped to think right now.
     
  10. Offline

    lon_chaney

  11. Offline

    MinezBombz

    lon_chaney No problem, make sure you mark the thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page