adding events together

Discussion in 'Plugin Development' started by nitrousspark, Jun 2, 2012.

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

    nitrousspark

    i need to add an event to another and it hard to explain. like when a player dies, for the rest of the time the players on, he cant break blocks, but thats two events? how do i make that work
     
  2. Offline

    Tzeentchful

    i would have three listeners player death, block break and player disconnect.
    i would then have a array list of players that have died. the death listener would check is the player is already in the list; if he isn't it would add him. then the block break event would check to see if the player is in the list. if the player is it cancels the event. and the disconnect even would remove the player from the list.
     
    ZeusAllMighty11 likes this.
  3. Offline

    ZeusAllMighty11

    I think the way to go about this would be:

    Before any player has died, let that be known. (somehow, maybe stats reset or something idk)

    When a player dies, add them to a list.
    If a player is in a list, they can not break blocks

    Simple to explain, may cause you troubles. Just post any issues you have.
     
  4. Offline

    nitrousspark

    then how would i list the dead players and the alive players?
     
  5. Offline

    Sir Savary

    To do this you need to know a few things:
    • How to make lists
    • How to add objects to lists, check to see if an object is in a list and how to remove objects from lists
    • Cancel events
    So, to do what you want it would go something like this:

    When a player dies, add the to a list.
    When a player breaks a block, check the list.
    If they are in it, cancel the event. If not, do not cancel the event.
    When a player disconnects, check the list.
    If they are in it, remove them. If not, do nothing.

    If you have any more questions just ask.
     
  6. Offline

    Tzeentchful

    here is what i would do (the player will still stay on the list when they disconnect with this)
    Code:
        List<Player> playerlist = new ArrayList<Player>();
     
     
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void PlayerDeath(EntityDeathEvent event){
            if(event.getEntityType().equals(EntityType.PLAYER)){//if the dead enity is a player
            if(!playerlist.contains(event.getEntity())){//checks to see if the player is allready in the list
                playerlist.add((Player) event.getEntity());//adds the player to the list
            }
        }
        }
     
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void BreakEvent(BlockBreakEvent event){
            if(playerlist.contains(event.getPlayer())){//checks if the player is in the list
                event.setCancelled(true);//cancels the block break
        }
        }
     
  7. Offline

    nitrousspark

    im having some problems if someone can help
    it keeps saying event.getPlayer() is wrong. arrows point to errors

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
    Player player = event.getPlayer(); <-----
    Killer killer = event.getKiller(); <----
    org.bukkit.World world = player.getWorld();
    Location location = player.getLocation();
    if (!playerlist.contains (event.getPlayer())) { <------
    playerlist.add (event.getPlayer()); <------
    world.strikeLightning(location);
    Bukkit.broadcastMessage(ChatColor.RED + player.getName()
    + " was slain by " + killer.getDisplayName());
    player.setDisplayName(ChatColor.RED + "[DEAD] "
    + player.getName() + ChatColor.WHITE);
    player.setGameMode(GameMode.CREATIVE);
     
  8. Offline

    Sir Savary

    What is the issue?
     
  9. Offline

    nitrousspark

    i dont think the event is working properly. i think it thinks its lookibng for an entity because whenever i do anything that involves player it gives me an error
     
  10. Offline

    Sir Savary

    You are making the assumption that killer is a player.

    Also, Killer isn't a class, unless you made a class for it.
     
Thread Status:
Not open for further replies.

Share This Page