Mattie

Untitled

Jun 13th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package nl.Matthijs.Mattie.Sacrifice;
  2.  
  3. import java.util.logging.Logger;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Material;
  7. import org.bukkit.Server;
  8. import org.bukkit.World;
  9. import org.bukkit.block.Block;
  10. import org.bukkit.block.BlockFace;
  11. import org.bukkit.block.Sign;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.block.Action;
  14. import org.bukkit.event.player.PlayerInteractEvent;
  15. import org.bukkit.event.player.PlayerListener;
  16. import org.bukkit.inventory.ItemStack;
  17.  
  18. public class SacrificePlayerListener extends PlayerListener
  19. {
  20.  
  21.     private final Sacrifice plugin;
  22.     private final Server    server;
  23.     final Logger            logger  = Logger.getLogger("Minecraft");
  24.     private Material        m       = Material.IRON_BLOCK;
  25.  
  26.     public SacrificePlayerListener(Sacrifice instance)
  27.     {
  28.         this.plugin = instance;
  29.         this.server = plugin.getServer();
  30.     }
  31.  
  32.     public void onPlayerInteract(PlayerInteractEvent event)
  33.     {
  34.         if ((event.getAction() != Action.LEFT_CLICK_BLOCK) && (event.getAction() != Action.RIGHT_CLICK_BLOCK))
  35.         {
  36.             return;
  37.         }
  38.  
  39.         Block b = event.getClickedBlock();
  40.         if (b.getType() == Material.SIGN_POST)
  41.         {
  42.             Sign s = (Sign) b.getState();
  43.             if (b.getType() == Material.SIGN_POST)
  44.             {
  45.                 System.out.println("line0: " + s.getLine(0));
  46.                 System.out.println("line1: " + s.getLine(1));
  47.                 System.out.println("line2: " + s.getLine(2));
  48.                 System.out.println("line3: " + s.getLine(3));
  49.  
  50.                 if (!s.getLine(1).equalsIgnoreCase("[offer]"))
  51.                 {
  52.                     return;
  53.                 }
  54. //              else if (!s.getLine(2).equalsIgnoreCase("day") || !s.getLine(2).equalsIgnoreCase("night"))
  55. //              {
  56. //                  return;
  57. //              }
  58.                 else
  59.                 {
  60.                     b = event.getClickedBlock();
  61.                     World w = b.getWorld();
  62.                     long time = w.getTime();
  63.                     time -= time % 24000L;
  64.  
  65.                     Player p = event.getPlayer();
  66.  
  67.                     Block north = b.getRelative(BlockFace.NORTH);
  68.                     Block east = b.getRelative(BlockFace.EAST);
  69.                     Block south = b.getRelative(BlockFace.SOUTH);
  70.                     Block west = b.getRelative(BlockFace.WEST);
  71.                     Block down = b.getRelative(BlockFace.DOWN);
  72.                     Block up = b.getRelative(BlockFace.UP);
  73.  
  74.                     if (north.getType() == m && east.getType() == m && south.getType() == m && west.getType() == m)
  75.                     {
  76.                         if (down.getType() == Material.GOLD_BLOCK)
  77.                         {
  78.                             ItemStack i = p.getItemInHand();
  79.                             int aantal = i.getAmount();
  80.                             if (aantal == 0)
  81.                             {
  82.                                 p.setHealth(0);
  83.                                 server.broadcastMessage(ChatColor.RED + "Player: " + p.getDisplayName() + ChatColor.RED + " probeerde zojuist NIETS te offeren -> STERRUF!");
  84.                             }
  85.                             else
  86.                             {
  87.                                 Block boven = event.getClickedBlock().getRelative(BlockFace.UP);
  88.                                 boven.setTypeId(0);
  89.                                 up.setType(Material.AIR);
  90.                                 up.setTypeId(0);
  91.                                 p.sendMessage("OK GEFELICITEERD U BENT GEOFFERT!");
  92.                                 server.broadcastMessage("Player: " + p.getDisplayName() + " heeft zojuist " + aantal + " " + i.getType() + " geofferd!");
  93.                                 i.setAmount(0);
  94.                                 p.setItemInHand(null);
  95.                                
  96.                                 Block b5 = up;
  97.                                 System.out.println("up: " + b5.getType());
  98.                                 if (s.getLine(2).equalsIgnoreCase("night"))
  99.                                 {
  100.                                     w.setTime(time + 37700L);
  101.                                     return;
  102.                                 }
  103.                                 else
  104.                                 {
  105.                                     w.setTime(time + 24000L);
  106.                                     return;
  107.                                 }
  108.                             }
  109.                         }
  110.                     }
  111.                 }
  112.             }
  113.         }
  114.  
  115.         System.out.println(event.getEventName() + "\n" + event.getAction());
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment