Advertisement
Guest User

blockEventListener

a guest
Mar 15th, 2015
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.52 KB | None | 0 0
  1. @EventHandler
  2.     public void onBlockPlaceGame(BlockPlaceEvent ev)
  3.     {      
  4.         identifier(ev.getBlock(), ev.getPlayer(), true);
  5.  
  6.     }
  7.    
  8.     //loops through all locations to identify if a placed block has to trigger an action
  9.     public void identifier(Block b, Player p, Boolean bp)
  10.     {
  11.         File worlds = new File("plugins/ColorKeyBattle/config/worlds.yml");
  12.         YamlConfiguration worlds2 = YamlConfiguration.loadConfiguration(worlds);
  13.         File locs = new File("plugins/ColorKeyBattle/config/" + worlds2.getString(p.getWorld().getName()) + ".yml");
  14.         YamlConfiguration locations = YamlConfiguration.loadConfiguration(locs);
  15.         String[] slot = {"Baseslots", "Basespawners"};
  16.         String[] color = {/*0*/"Red",/*1*/"RedBlue",/*2*/"RedGreen",/*3*/"RedBlack",/*4*/"Blue",/*5*/"BlueRed",/*6*/"BlueGreen",/*7*/"BlueBlack",/*8*/"Green",/*9*/"GreenRed",/*10*/"GreenBlue",/*11*/"GreenBlack",/*12*/"Black",/*13*/"BlackRed",/*14*/"BlackBlue",/*15*/"BlackGreen"};
  17.         for(String x: slot)
  18.         {
  19.             for(String y: color)
  20.             {
  21.                 if(locations.getInt(p.getWorld().getName() + "."+ x + "." + y + ".loc1.X") == b.getX() || locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc2.X") == b.getX() || locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.X") - (locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.X") - locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc2.X"))*0.5 == b.getX())
  22.                 {
  23.                     if(locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.Y") == b.getY() || locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc2.Y") == b.getY() || locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.Y") - (locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.Y") - locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc2.Y"))*0.5 == b.getY() )
  24.                     {
  25.                         if(locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.Z") == b.getZ() || locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc2.Z") == b.getZ() || locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.Z") - (locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc1.Z") - locations.getInt(p.getWorld().getName() + "." + x + "." + y + ".loc2.Z"))*0.5 == b.getZ() )
  26.                         {
  27.                             blockAction(x, y, bp, p.getWorld(), p, b);
  28.                         }  
  29.                     }  
  30.                 }
  31.             }
  32.         }
  33.     }
  34.  
  35.     // The action a placed block triggers selected by the data from identifier()
  36.  
  37.     public void blockAction(String slotId, String colorId, Boolean bp, World world, Player p, Block b)
  38.     {
  39.         File worlds = new File("plugins/ColorKeyBattle/config/worlds.yml");
  40.         YamlConfiguration worlds2 = YamlConfiguration.loadConfiguration(worlds);
  41.         File locs = new File("plugins/ColorKeyBattle/config/" + worlds2.getString(p.getWorld().getName()) + ".yml");
  42.         YamlConfiguration locations = YamlConfiguration.loadConfiguration(locs);
  43.         if(slotId.equals("Baseslots"))
  44.         {                      
  45.             Location loc = new Location(world, locations.getInt(p.getWorld().getName() + ".Beaconspots." + colorId + ".loc1.X"), locations.getInt(p.getWorld().getName() + ".Beaconspots." + colorId + ".loc1.Y"), locations.getInt(p.getWorld().getName() + ".Beaconspots." + colorId + ".loc1.Z"));          
  46.             if(bp == true)
  47.             {
  48.                 if(blocks.get("Baseslots" + colorId) == null)
  49.                 {
  50.                     blocks.put("Baseslots" + colorId, 0);
  51.                 }
  52.                 blocks.put("Baseslots" + colorId, blocks.get("Baseslots" + colorId)+1);            
  53.                 if(blocks.get("Baseslots" + colorId) == 1 && b.getType().equals(Material.WOOL))
  54.                     if(colorId.startsWith("Red") && DyeColor.getByWoolData(b.getData()) == DyeColor.RED)
  55.                     {
  56.                         loc.getBlock().setType(Material.BEACON);
  57.                        
  58.                         TimerClass.callTimer(p, "Red", "base", world.getName());
  59.                     }
  60.                     else if(colorId.startsWith("Blue") && DyeColor.getByWoolData(b.getData()) == DyeColor.BLUE)
  61.                     {
  62.                         loc.getBlock().setType(Material.BEACON);
  63.                     }
  64.                     else if(colorId.startsWith("Green") && DyeColor.getByWoolData(b.getData()) == DyeColor.LIME)
  65.                     {
  66.                         loc.getBlock().setType(Material.BEACON);
  67.                     }
  68.                     else if(colorId.startsWith("Black") && DyeColor.getByWoolData(b.getData()) == DyeColor.BLACK)
  69.                     {
  70.                         loc.getBlock().setType(Material.BEACON);
  71.  
  72.                     }
  73.  
  74.  
  75.             }
  76.             else if(bp == false)
  77.             {
  78.                 if(blocks.get("Baseslots" + colorId) == null)
  79.                 {
  80.                     blocks.put("Baseslots" + colorId, 0);
  81.                 }
  82.                 blocks.put("Baseslots" + colorId, blocks.get("Baseslots" + colorId)-1);
  83.                 if(blocks.get("Baseslots" + colorId) == 0)
  84.                 {
  85.                     loc.getBlock().setType(Material.AIR);
  86.                 }
  87.             }
  88.         }
  89.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement