Advertisement
Guest User

PlayerListener.class

a guest
Aug 11th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package me.codebucket.survivalchests;
  2.  
  3. import java.util.List;
  4.  
  5. import org.bukkit.Location;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.block.Action;
  10. import org.bukkit.event.player.PlayerInteractEvent;
  11. import org.bukkit.inventory.Inventory;
  12. import org.mcsg.survivalgames.api.PlayerJoinArenaEvent;
  13. import org.mcsg.survivalgames.api.PlayerLeaveArenaEvent;
  14.  
  15. public class PlayerListener implements Listener
  16. {
  17.     Main plugin;
  18.    
  19.     public PlayerListener(Main plugin)
  20.     {
  21.         this.plugin = plugin;
  22.     }
  23.    
  24.     @EventHandler
  25.     public void playerOpenChestEvent(PlayerInteractEvent e)
  26.     {
  27.         Player p = e.getPlayer();
  28.        
  29.         List<?> worlds = plugin.getConfig().getList("Config.Worlds");
  30.        
  31.         if(worlds.contains(p.getWorld().getName()))
  32.         {
  33.             if(e.getAction() == Action.RIGHT_CLICK_BLOCK )
  34.             {
  35.                 if(e.getClickedBlock().getType().getId() == 33 && e.getClickedBlock().getData() == 6)
  36.                 {
  37.                     Inventory inv = plugin.Chests.get(e.getClickedBlock().getLocation());
  38.                    
  39.                     if(inv == null)
  40.                     {
  41.                         plugin.createChest(e.getClickedBlock().getLocation(), p);
  42.                     }
  43.                     else
  44.                     {
  45.                         p.openInventory(inv);
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.     }
  51.    
  52.     @EventHandler
  53.     public void arenaLeaveEvent(PlayerLeaveArenaEvent e)
  54.     {
  55.         int size = e.getGame().getAllPlayers().size();
  56.        
  57.         if(size <= 1)
  58.         {
  59.             String w = e.getPlayer().getWorld().getName();
  60.            
  61.             for(Location loc : plugin.Locations)
  62.             {
  63.                 if(loc.getWorld().getName().equalsIgnoreCase(w))
  64.                 {
  65.                     plugin.Chests.remove(loc);
  66.                 }
  67.             }
  68.         }
  69.     }
  70.    
  71.     @EventHandler
  72.     public void arenaJoinEvent(PlayerJoinArenaEvent e)
  73.     {
  74.         int size = e.getGame().getAllPlayers().size();
  75.        
  76.         if(size == 0)
  77.         {
  78.             String w = e.getPlayer().getWorld().getName();
  79.            
  80.             for(Location loc : plugin.Locations)
  81.             {
  82.                 if(loc.getWorld().getName().equalsIgnoreCase(w))
  83.                 {
  84.                     plugin.Chests.remove(loc);
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement