Advertisement
MTM123

onInteract

Apr 19th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1. @EventHandler
  2.     public void onInteract(PlayerInteractEvent event){
  3.         if(event.getAction() != Action.PHYSICAL)
  4.             return;
  5.         Player player = event.getPlayer();
  6.         String playername = player.getName();
  7.         player.sendMessage(event.getClickedBlock().getType().toString() + "");
  8.         if(parkourMode.containsKey(playername) && checkpoints.containsKey(playername) &&event.getClickedBlock().getType() == Material.STONE_PLATE){
  9.            
  10.             try{
  11.                 List<String> data = checkpoints.get(playername);
  12.                 String region = data.get(0);
  13.                 File file = new File(plugin.getDataFolder() + "/courses/" + region + ".yml");
  14.                 FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  15.                 for(String key : cfg.getConfigurationSection("checkpoints").getKeys(false)){
  16.                     int x = cfg.getInt("checkpoints." + key + ".x");
  17.                     int y = cfg.getInt("checkpoints." + key + ".y");
  18.                     int z = cfg.getInt("checkpoints." + key + ".z");
  19.                     World world = Bukkit.getWorld(cfg.getString("name"));
  20.                     Location loc = new Location(world, x, y, z);
  21.                     if(loc.equals(event.getClickedBlock().getLocation())){
  22.                         data.set(1, key);
  23.                         checkpoints.put(playername, data);
  24.                         break;
  25.                     }
  26.                 }
  27.      
  28.             }catch(Exception e){
  29.                 e.printStackTrace();
  30.             }
  31.            
  32.         }else if(parkourMode.containsKey(playername) && event.getClickedBlock().getType() == Material.IRON_PLATE){
  33.             Location loc = event.getClickedBlock().getLocation();
  34.             for(CuboidSelection sel : selections){
  35.                 if(sel.contains(loc)){
  36.                     List<String> data = null;
  37.                     for(String reg : regions){
  38.                         try{
  39.                             File file = new File(plugin.getDataFolder() + "/courses/" + reg + ".yml");
  40.                             FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  41.                             World world = Bukkit.getWorld(cfg.getString("selection.world"));
  42.                             int x1 = cfg.getInt("selection.pos1.x");
  43.                             int y1 = cfg.getInt("selection.pos1.y");
  44.                             int z1 = cfg.getInt("selection.pos1.z");
  45.                             int x2 = cfg.getInt("selection.pos2.x");
  46.                             int y2 = cfg.getInt("selection.pos2.y");
  47.                             int z2 = cfg.getInt("selection.pos2.z");
  48.                             Location pos1 = new Location(world, x1, y1, z1);
  49.                             Location pos2 = new Location(world, x2, y2, z2);
  50.                             if(sel.getMinimumPoint().equals(pos1) && sel.getMaximumPoint().equals(pos2)){
  51.                                 data.set(0, cfg.getString("name"));
  52.                                 data.set(1, "start");
  53.                                 break;
  54.                             }
  55.                         }catch(Exception e){
  56.                            
  57.                         }
  58.                     }
  59.                     if(data != null){
  60.                         checkpoints.put(playername, data);
  61.                         break;
  62.                     }
  63.                 }
  64.             }
  65.            
  66.         }else if(parkourMode.containsKey(playername) && checkpoints.containsKey(playername) && event.getClickedBlock().getType() == Material.GOLD_PLATE){
  67.            
  68.             List<String> data = checkpoints.get(playername);
  69.             String region = data.get(0);
  70.             player.sendMessage(ChatColor.DARK_GREEN + "[Parkour] " + ChatColor.GREEN + region + "has been completed!");
  71.             parkourMode.remove(playername);
  72.             checkpoints.remove(playername);
  73.             Double x = LSMain.configs.getParkourConfig().getDouble("startpoint.x");
  74.             Double y = LSMain.configs.getParkourConfig().getDouble("startpoint.y");
  75.             Double z = LSMain.configs.getParkourConfig().getDouble("startpoint.z");
  76.             Location loc = new Location(player.getWorld(), x, y, z);
  77.             player.teleport(loc);
  78.            
  79.         }else{
  80.             player.sendMessage(ChatColor.GREEN + "doesnt work");
  81.             player.sendMessage(ChatColor.GREEN + "" + parkourMode.get(playername) + "");
  82.             player.sendMessage(ChatColor.GREEN + playername + "");
  83.             printState(player);
  84.         }
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement