Mattie

Untitled

Jun 14th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.31 KB | None | 0 0
  1. package nl.Matthijs.Mattie.Sacrifice;
  2.  
  3. import java.util.Random;
  4. import java.util.logging.Logger;
  5.  
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Material;
  8. import org.bukkit.Server;
  9. import org.bukkit.World;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.block.BlockFace;
  12. import org.bukkit.block.Sign;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.block.Action;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.event.player.PlayerListener;
  17. import org.bukkit.inventory.ItemStack;
  18.  
  19. public class SacrificePlayerListener extends PlayerListener
  20. {
  21.  
  22.     private final Sacrifice plugin;
  23.     private final Server    server;
  24.     final Logger            logger  = Logger.getLogger("Minecraft");
  25.     private Material        m       = Material.IRON_BLOCK;
  26.     private Random          r       = new Random();
  27.     private final int       HATCHID = 0;
  28.  
  29.     public SacrificePlayerListener(Sacrifice instance)
  30.     {
  31.         this.plugin = instance;
  32.         this.server = plugin.getServer();
  33.     }
  34.  
  35.     public void setDay(World w, Long time, PlayerInteractEvent event)
  36.     {
  37.         w.setTime(time + 24000L);
  38.         server.broadcastMessage("The gods give you " + ChatColor.RED + "daylight " + ChatColor.WHITE + "as reward for your sacrifice");
  39.         event.setCancelled(true);
  40.         //cancle event so blocks places will be removed again
  41.         return;
  42.     }
  43.  
  44.     public void setNight(World w, Long time, PlayerInteractEvent event)
  45.     {
  46.         w.setTime(time + 37700L);
  47.         server.broadcastMessage("The gods give you " + ChatColor.RED + "darkness " + ChatColor.WHITE + "as reward for your sacrifice");
  48.         event.setCancelled(true);
  49.         //cancle event so blocks places will be removed again
  50.         return;
  51.     }
  52.  
  53.     public void setSun(World w, PlayerInteractEvent event)
  54.     {
  55.         w.setStorm(false);
  56.         server.broadcastMessage("The gods give you " + ChatColor.RED + "SUN " + ChatColor.WHITE + "as reward for your sacrifice");
  57.         event.setCancelled(true);
  58.         return;
  59.     }
  60.  
  61.     public void setRain(World w, PlayerInteractEvent event)
  62.     {
  63.         w.setStorm(true);
  64.         server.broadcastMessage("The gods give you " + ChatColor.RED + "RAIN " + ChatColor.WHITE + "as reward for your sacrifice");
  65.         event.setCancelled(true);
  66.         return;
  67.     }
  68.  
  69.     public void setSomething(World w, Long time, PlayerInteractEvent event, Sign s)
  70.     {
  71.         if (s.getLine(2).equalsIgnoreCase("night"))
  72.         {
  73.             setNight(w, time, event);
  74.         }
  75.         else if (s.getLine(2).equalsIgnoreCase("sun"))
  76.         {
  77.             setSun(w, event);
  78.         }
  79.         else if (s.getLine(2).equalsIgnoreCase("rain"))
  80.         {
  81.             setRain(w, event);
  82.         }
  83.         else
  84.         // so: day or nothing
  85.         {
  86.             setDay(w, time, event);
  87.         }
  88.     }
  89.  
  90.     public void noGoodOfferTable(Player p, PlayerInteractEvent event)
  91.     {
  92.         p.sendMessage(ChatColor.RED + "OOPS JE OFFER TAFEL IS NIET GOED! DIT ACCEPTEREN DE GODEN NIET!");
  93.         event.setCancelled(true);
  94.     }
  95.  
  96.     public void onPlayerInteract(PlayerInteractEvent event)
  97.     {
  98.         if (/* (event.getAction() != Action.LEFT_CLICK_BLOCK) && */(event.getAction() != Action.RIGHT_CLICK_BLOCK))
  99.         {
  100.             return;
  101.         }
  102.  
  103.         Block b = event.getClickedBlock();
  104.         if (b.getType() == Material.SIGN_POST)
  105.         {
  106.             Sign s = (Sign) b.getState();
  107.             if (b.getType() == Material.SIGN_POST)
  108.             {
  109. //              System.out.println("line0: " + s.getLine(0));
  110. //              System.out.println("line1: " + s.getLine(1));
  111. //              System.out.println("line2: " + s.getLine(2));
  112. //              System.out.println("line3: " + s.getLine(3));
  113.  
  114.                 if (!s.getLine(1).equalsIgnoreCase("[offer]"))
  115.                 {
  116.                     return;
  117.                 }
  118. //              else if (!s.getLine(2).equalsIgnoreCase("day") || !s.getLine(2).equalsIgnoreCase("night"))
  119. //              {
  120. //                  return;
  121. //              }
  122.                 else
  123.                 {
  124.                     b = event.getClickedBlock();
  125.                     World w = b.getWorld();
  126.                     long time = w.getTime();
  127.                     time -= time % 24000L;
  128.  
  129.                     Player p = event.getPlayer();
  130.  
  131.                     Block north = b.getRelative(BlockFace.NORTH);
  132.                     Block east = b.getRelative(BlockFace.EAST);
  133.                     Block south = b.getRelative(BlockFace.SOUTH);
  134.                     Block west = b.getRelative(BlockFace.WEST);
  135.                     Block down = b.getRelative(BlockFace.DOWN);
  136.                     Block up = b.getRelative(BlockFace.UP);
  137.  
  138.                     if (north.getType() == m && east.getType() == m && south.getType() == m && west.getType() == m)//alles NAAST het sign
  139.                     {
  140.                         if (down.getType() == Material.GOLD_BLOCK)//alles ONDER het sign
  141.                         {
  142.                             if (up.getType() == Material.TRAP_DOOR) //alles BOVEN het sign
  143.                             {
  144.                                 Block naastHatch = up;
  145.                                 //kijk of er naast het hatch wel een gold block ERGENS staat
  146.                                 if (up.getRelative(BlockFace.NORTH).getType() == Material.GOLD_BLOCK || up.getRelative(BlockFace.EAST).getType() == Material.GOLD_BLOCK
  147.                                         || up.getRelative(BlockFace.SOUTH).getType() == Material.GOLD_BLOCK || up.getRelative(BlockFace.WEST).getType() == Material.GOLD_BLOCK)
  148.                                 {
  149.  
  150.                                     ItemStack i = p.getItemInHand();
  151.  
  152.                                     int aantal = i.getAmount();
  153.                                     int kansaantal = aantal * 2;
  154.                                     int base = 10;
  155.                                     if (aantal == 0)
  156.                                         base = 8;//goed voor een config item -> hoe streng met niks
  157.                                     int random = r.nextInt(base + kansaantal);
  158.  
  159.                                     System.out.println("random: " + random);
  160.                                     server.broadcastMessage("het random getal: " + random);
  161.  
  162.                                     if (random <= 4)//goed voor een config item -> hoe streng
  163.                                     {
  164.                                         if (i.getType() == Material.AIR)
  165.                                         {
  166.                                             System.out.println(i.getType());
  167.                                             server.broadcastMessage("The gods are " + ChatColor.RED + "NOT" + ChatColor.WHITE + " pleased with the offering of NOTHING!!!!!!!!");
  168.                                         }
  169.                                         else
  170.                                         {
  171.                                             System.out.println("niks");
  172.                                             server.broadcastMessage("The gods are " + ChatColor.RED + "NOT" + ChatColor.WHITE + " pleased with the offering of "
  173.                                                     + p.getDisplayName() + " therefore:");
  174.                                         }
  175.                                         server.broadcastMessage(ChatColor.RED + "Player: " + p.getDisplayName() + ChatColor.RED + " just made the ultimate sacrifice to the gods!");
  176.  
  177.                                         i.setAmount(0);
  178.                                         p.setHealth(0);
  179.  
  180.                                         //make (and execute) a check to see what to change
  181.                                         setSomething(w, time, event, s);
  182.  
  183.                                     }
  184.                                     else
  185.                                     {
  186.                                         if (i.getType() == Material.AIR)
  187.                                         {
  188.                                             server.broadcastMessage("Player: " + p.getDisplayName() + " just offered nothing(!) in an attempt to please the gods!");
  189.                                         }
  190.                                         else
  191.                                         {
  192.                                             server.broadcastMessage("Player: " + p.getDisplayName() + " just offered " + aantal + " " + i.getType()
  193.                                                     + " in an attempt to please the gods!");
  194.  
  195.                                         }
  196.                                         i.setAmount(0);
  197.                                         p.setItemInHand(null);
  198.  
  199.                                         //make (and execute) a check to see what to change
  200.                                         setSomething(w, time, event, s);
  201.  
  202.                                     }
  203.                                     byte data = (byte) (up.getData() + 4);
  204.                                     up.setData(data);
  205.  
  206.                                 }
  207.                                 else
  208.                                 //offer table not in the correct format
  209.                                 {
  210.                                     noGoodOfferTable(p, event);
  211.                                 }
  212.                             }
  213.                             else
  214.                             //offer table not in the correct format
  215.                             {
  216.                                 noGoodOfferTable(p, event);
  217.                             }
  218.                         }
  219.                         else
  220.                         //offer table not in the correct format
  221.                         {
  222.                             noGoodOfferTable(p, event);
  223.                         }
  224.                     }
  225.                     else
  226.                     //offer table not in the correct format
  227.                     {
  228.                         noGoodOfferTable(p, event);
  229.                     }
  230.                 }
  231.             }
  232.         }
  233.  
  234. //      System.out.println(event.getEventName() + "\n" + event.getAction());
  235. //      System.out.println("de data: " + event.getClickedBlock().getData());
  236.     }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment