Player Kill?

Discussion in 'Plugin Development' started by Corymbus, Nov 15, 2014.

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

    Corymbus

    How to make it so player gets killed when they place it (Oh and that it dosnt place)
    Code:java
    1. package me.ichurchmax;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockPlaceEvent;
    9.  
    10. public class BlockListener implements Listener{
    11.  
    12. public BlockListener(ichurchmax plugin) {
    13. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    14. }
    15.  
    16. @EventHandler
    17. public void onBlockPlaced(BlockPlaceEvent e) {
    18.  
    19. Player player = e.getPlayer();
    20.  
    21. if e.getBlockPlaced().equals(Material.TNT);
    22. player.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "ichurchmax" + ChatColor.GRAY + "]" + ChatColor.RED + " Bad.");
    23. {
    24.  
    25. }
    26.  
    27. {
    28. }}}
    29.  
     
  2. Offline

    drpk

    ichurchmax Player#setHealth and Event#setCancelled
     
  3. Offline

    Corymbus

    Ok i now get a syntax error on the if?
    Code:java
    1. package me.ichurchmax;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockPlaceEvent;
    9.  
    10. public class BlockListener implements Listener{
    11.  
    12. public BlockListener(ichurchmax plugin) {
    13. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    14. }
    15.  
    16. @EventHandler
    17. public void onBlockPlaced(BlockPlaceEvent e) {
    18.  
    19. Player player = e.getPlayer();
    20.  
    21. if e.getBlockPlaced().equals(Material.TNT);
    22. player.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "ichurchmax" + ChatColor.GRAY + "]" + ChatColor.RED + " Bad.");
    23. player.setHealth(0);
    24. e.setCancelled(true);
    25. {
    26.  
    27. }
    28.  
    29. {
    30. }}}
    31.  
     
  4. Offline

    BeefySticks

    ichurchmax
    Please use { instead of ;

    Code:java
    1. if e.getBlockPlaced().equals(Material.TNT);
    2.  
    3. // Change that to
    4.  
    5. if e.getBlockPlaced().equals(Material.TNT) {


    Also try this, may work better.

    Code:java
    1. player.setHealth(0.0);
     
  5. Offline

    Corymbus

    BeefySticks
    Ok so it now looks like below however placing tnt does nothing?
    Code:java
    1. package me.ichurchmax;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockPlaceEvent;
    9.  
    10. public class BlockListener implements Listener{
    11.  
    12. public BlockListener(ichurchmax plugin) {
    13. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    14. }
    15.  
    16. @EventHandler
    17. public void onBlockPlaced(BlockPlaceEvent e) {
    18.  
    19. Player player = e.getPlayer();
    20.  
    21. if (e.getBlockPlaced().equals(Material.TNT)) {
    22. player.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "ichurchmax" + ChatColor.GRAY + "]" + ChatColor.RED + " Bad.");
    23. player.setHealth(0);
    24. e.setCancelled(true);
    25. {
    26.  
    27. }
    28.  
    29. {
    30. }}}}
    31.  
     
  6. Offline

    BeefySticks

    ichurchmax
    Maybe try registering the event from your main class instead of registering it from that class.

    Code:java
    1. PluginManager pm = Bukkit.getPluginManager();
    2. pm.registerEvents(new BlockListener(), this);
     
  7. Offline

    Avygeil

    ichurchmax Use Block#getType to compare Materials. Also fix your brackets.
     
  8. Offline

    Corymbus

    Avygeil How does one a) fix brackets
    b) compare materials?
     
  9. Offline

    BeefySticks

    ichurchmax
    What he is saying is to do this! Copy and paste it into your code!
    Code:java
    1. @EventHandler
    2. public void onBlockPlaced(BlockPlaceEvent e) {
    3.  
    4. Player player = e.getPlayer();
    5.  
    6. if (e.getBlockPlaced().getType() == Material.TNT) {
    7. player.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "ichurchmax" + ChatColor.GRAY + "]" + ChatColor.RED + " Bad.");
    8. player.setHealth(0);
    9. e.setCancelled(true);
    10.  
    11. }
    12. }
    13. }
     
  10. Offline

    Avygeil

    ichurchmax One learns Java and reads basic plugin tutorials.
     
    FerusGrim and BeefySticks like this.
  11. Offline

    teej107

    [​IMG]
     
    JordyPwner and Monkey_Swag like this.
  12. Offline

    ChipDev

    no need for pictures... *Kinda looks weirdtoo.
    Just give him a 'don't spoon feed please
     
  13. Offline

    teej107

    ChipDev Leave it to our own species to think that our own infants look weird. I already gave my comment about the spoonfeed. If you think it needs a
    then tag him and say it.
     
  14. Offline

    BeefySticks

    teej107
    LOL, I liked the pictures. I just wanted to help me out :p
     
Thread Status:
Not open for further replies.

Share This Page