banner



How To Add A Potion Effect With A Player Respawns

Thread Status:
Non open for further replies.
  1. My Issues:
    I am trying to make a plugin where the world border decreases after dying and the died actor gets set up into Spectator style and gets some effects. It turned out that I need a tiny delay.
    Afterward googling about delaying something in Bukkit I found this thing called "Scheduler". I tried using it and it showed an error that I tin't fix.

    In Eclipse is Looks similar that:

                              Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {                          @Override                         public void run() {                             //Testing if Scheduler is working                             Bukkit.getServer().broadcastMessage(ChatColor.RED+"Scheduler is working! YAY! :D");                             //Trying to add together a PotionEffect                             actor.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 999, 255));                         }                                 }, 20L);
    And "scheduleSyncDelayedTask" in the first (line 36 in whole class) line is underlined with the error:

    After I tested information technology anyways on a examination server there was this error after clicking the respawn push button:

    My Questions:
    How tin I fix this mistake?
    or
    Is in that location another mode to requite a player some effects after respawning?

    My Code:

    parcel de.Stephan.MiniVaro;  //importing stuff import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.entity.Histrion; import org.bukkit.event.EventHandler; import org.bukkit.upshot.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.coffee.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType;    public form Eventlistener implements Listener {             public Eventlistener (JavaPlugin plugin){         plugin.getServer().getPluginManager().registerEvents(this, plugin);     }         //Calculation a PlayerDeath checker     @EventHandler     public void onPlayerDeath (PlayerDeathEvent tod){         //Checking if Round was started         if(Variables.Round==1){             //Checking if there are more than 1 thespian online             if(Variables.OnlinePlayers>1){                 //Checking if died Actor was in SurvivalMode                 if(tod.getEntity().getGameMode()==GameMode.SURVIVAL){                     //Decreasing WorldBorder size                     Variables.b.setSize(Bukkit.getWorld("world").getWorldBorder().getSize()-ten,10);                     //Telling everyone that the WorldBorder is decreasing size                     Bukkit.getServer().broadcastMessage(ChatColor.AQUA+"The worldborder is shrinking 10 blocks.");                     //setting GameMode of died player to SPECTATOR                     tod.getEntity().setGameMode(GameMode.SPECTATOR);                 }             }         }     }         //Adding a PlayerRespwn checker     @EventHandler     public void onPlayerSpawn(PlayerRespawnEvent spawn){         //Testing if it works         Bukkit.getServer().broadcastMessage("onPlayerSpawn is working! YAY :D");         Player player = spawn.getPlayer();         //Checking if Round was started         if(Variables.Round==1){             //Checking if there are more than one histrion online             if(Variables.OnlinePlayers>1){                 //Checking if respawned Player is in SECTATOR mode                 if(player.getGameMode()==GameMode.SPECTATOR){                     //Trying to add together a PotionEffect                     player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 999, 255));                                         //Trying to give the PotionEffect 5sek afterwards                     Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {                          @Override                         public void run() {                             //Testing if Scheduler is working                             Bukkit.getServer().broadcastMessage(ChatColor.Reddish+"Scheduler is working! YAY! :D");                             //Trying to add a PotionEffect                             player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 999, 255));                         }                                 }, 20L);                                     }             }         }     }     }
  2. @stivi313131
    The trouble is that you put in your eventlistener form every bit a Plugin, but you need to put in your Main class (the one which extends javaplugin).
  3. scheduleSyncDelayedTask: the first statement needs to be the case of your main class (extending JavaPlugin)
  4. OK, now the Schedule fault is gone thanks for that.
    But at present I got many token errors in Eclipse and server:
    (line 36
    line 45: public void onPlayerSpawn ( PlayerRespawnEvent spawn ) {
    line 65
    line 67: } , 20L) ;
    /* TODO:      + Custom Spawns      + Schematics      + Teams      + Countdown      + optimize plugin.yml      + /MiniVaro-info */ bundle de.Stephan.MiniVaro; //importing stuff import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.control.Command; import org.bukkit.control.CommandSender; import org.bukkit.entity.Player; import org.bukkit.upshot.EventHandler; import org.bukkit.event.actor.PlayerRespawnEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType;    public grade MiniVaro extends JavaPlugin{              @Override     public void onEnable() {         super.onEnable();                new Eventlistener(this);         //set up WorldBordersize to 100         Variables.b.setSize(100);         }        //Trying to give the PotionEffect 5sek later     Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {          @Override         public void run() {             //Calculation a PlayerRespwn checker             @EventHandler             public void onPlayerSpawn(PlayerRespawnEvent spawn){                 //Testing if information technology works                 Bukkit.getServer().broadcastMessage("onPlayerSpawn is working! YAY :D");                 Player histrion = spawn.getPlayer();                 //Checking if Round was started                 if(Variables.Round==1){                     //Checking if there are more than one actor online                     if(Variables.OnlinePlayers>1){                         //Checking if respawned Player is in SECTATOR mode                         if(thespian.getGameMode()==GameMode.SPECTATOR){                             //Testing if Scheduler is working                             Bukkit.getServer().broadcastMessage(ChatColor.Ruddy+"Scheduler is working! YAY! :D");                             //Trying to add a PotionEffect                             actor.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 999, 255));                                                    }                     }                 }             }          }      }, 20L);        //Commands     @Override     public boolean onCommand(CommandSender sender, Control control, String characterization, Cord[] args) {                //Command /MiniVaro         if(control.getName().equalsIgnoreCase("MiniVaro")){                 //send some text to the sender of the Control /MiniVaro                 sender.sendMessage(ChatColor.Yellow+"Usage:");                 sender.sendMessage(ChatColor.Yellow+"Enter "+ChatColor.Scarlet+"\"/MiniVaro-start\""+ChatColor.Yellow+" to start a new Round." );                 sender.sendMessage(ChatColor.YELLOW+"Enter "+ChatColor.Ruby+"\"/MiniVaro-stop\""+ChatColor.YELLOW+" to stop a Round." );                 sender.sendMessage(ChatColor.Xanthous+"Enter "+ChatColor.RED+"\"/MiniVaro-info\""+ChatColor.Xanthous+" to get info about the MiniVaro plugin." );         }                //Control /MiniVaro-kickoff         if(command.getName().equalsIgnoreCase("MiniVaro-start")){             //start a Round past setting Round to i             Variables.Round=1;;             //Checking if setting Round to one has worked             if(Variables.Circular==1){                 sender.sendMessage("Runde gestartet");             }         }                //Command /MiniVaro-finish         if(command.getName().equalsIgnoreCase("MiniVaro-stop")){             //Stopping a Round by setting Round to 0             Variables.Round=0;             if(Variables.Round==0){                 //Checking if setting Round to 0 has worked                 sender.sendMessage("Runde gestoppt");             }         }return false;                          }        }
  5. @stivi313131
    You cannot create a new method inside another method! What you need to practice is make the eventhandler, and within that, call your delayed task.
  6. Thanks.
    I don't know why I changed that *facepalm*
Thread Status:
Not open for further replies.

Share This Page

How To Add A Potion Effect With A Player Respawns,

Source: https://bukkit.org/threads/adding-a-potion-effect-to-a-player-after-respawning.426479/

Posted by: joneskinesen.blogspot.com

0 Response to "How To Add A Potion Effect With A Player Respawns"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel