Solved Simple but can't figure it out. Beginner

Discussion in 'Plugin Development' started by mista_ninja_3, Dec 29, 2013.

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

    mista_ninja_3

    It pretty simple, but I cant figure it out.

    Code:
    public class BlockListener implements Listener {

    @EventHandler
    public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) {
    return;
    }

    if (event.getBlock().getType() == Material.TNT) {
    event.setCancelled(true);
    event.getPlayer().sendMessage(
    ChatColor.DARK_GRAY + "[" + ChatColor.RED + "*" + ChatColor.DARK_GRAY + "] " + ChatColor.RED
    + "You cannot place this block.");

    Player player = (event.getPlayer());

    if (MistaCoreMain.players.contains(player.getName())) {
    event.setCancelled(false);
    event.getPlayer().sendMessage("You have placed TNT");
    }
    }
    }
    Currently, the top message appears as well as the bottom message when the player places the TNT. (this is the player in the array)

    How do I stop the top message from sending? (When the player is in the array)

    Thanks. Mista.
     
  2. Offline

    BillyGalbreath

    Code:java
    1.  
    2. public class BlockListener implements Listener {
    3.  
    4. @EventHandler(ignoreCancelled = true)
    5. public void onBlockPlace(BlockPlaceEvent event) {
    6. if (event.getBlock().getType() != Material.TNT)
    7. return;
    8. Player player = event.getPlayer();
    9. if (MistaCoreMain.players.contains(player.getName())) {
    10. player.sendMessage("You have placed TNT");
    11. return;
    12. }
    13. player.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "*" + ChatColor.DARK_GRAY + "] " + ChatColor.RED + "You cannot place this block.");
    14. event.setCancelled(true);
    15. }
    16.  
    17. }
    18.  
     
    mista_ninja_3 likes this.
  3. Offline

    mista_ninja_3

    Thanks you so much!
     
Thread Status:
Not open for further replies.

Share This Page