spenk

JailListener

Mar 15th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.HashMap;
  6.  
  7.  
  8. public class JailListener extends PluginListener{
  9.     JailDelay jd = new JailDelay();
  10.     HashMap<String , String> a = new HashMap<String , String>();
  11.     int i = 1;
  12.     double x1;
  13.     double y1;
  14.     double z1;
  15.     String directory = "plugins/config/Jail/Jailes/";
  16.     File names = new File("plugins/config/Jail/Jailnames.txt");
  17.     PropertiesFile mainj = new PropertiesFile(directory+"Mainjail.properties");
  18.  
  19. public boolean onCommand(Player player, String[] split){
  20.     if (split[0].equalsIgnoreCase("/jail")&&player.canUseCommand("/jailadmin")){
  21.         if (split.length == 1){
  22.             player.sendMessage("§cthe correct usage is '/jail player'");
  23.             return true;
  24.         }else
  25.         if (split.length == 2){
  26.             Player player2 = etc.getServer().matchPlayer(split[1]);
  27.             if (player2 == null){
  28.                 player.sendMessage("§cThis player does not exist or is currently not logged in.");
  29.                 return true;
  30.             }else{
  31.                  String[] split2 = a.get(player2.getName()).split(",");
  32.             if(!split2[0].equals(i)){
  33.                 if (mainj.containsKey(i+"")){
  34.                     if(!a.containsKey(player2.getName())){
  35.                      String[] split1 = mainj.getString(i+"").split(",");
  36.                        x1 = Double.parseDouble(split1[0]); y1 = Double.parseDouble(split1[1]); z1 = Double.parseDouble(split1[2]);
  37.                        a.put(player2.getName(),i+","+"Mainjail");
  38.                 player2.teleportTo(x1,y1+1,z1,0,0);
  39.                 player.sendMessage("§2Player jailed at cell "+i);
  40.                 player2.sendMessage("§4"+player.getName()+" Jailed you!");
  41.                 return true;
  42.                     }else{player.sendMessage("§cThis Player is already jailed"); return true;}
  43.             }else{
  44.                 player.sendMessage("§cThere are no available cells in the Mainjail anymore");
  45.                 return true;
  46.                 }
  47.         }
  48.             i++;
  49.         }
  50.             }
  51.     }
  52.         if (split.length == 3){
  53.           Player player2 = etc.getServer().matchPlayer(split[1]);
  54.           if (player2 == null){
  55.               player.sendMessage("§cThis player does not exist or is currently not logged in.");
  56.           return true;
  57.           }else{
  58.               if (isInList(split[2])){
  59.                   PropertiesFile jail = new PropertiesFile(directory+split[2]+".properties");
  60.                   if (!a.containsKey(player2.getName())){
  61.                       if (jail.containsKey(i+"")){
  62.                       String[] split2 = a.get(player2.getName()).split(",");
  63.                       if (!split2[0].equals(i)){
  64.                           String[] split1 = jail.getString(i+"").split(",");
  65.                            x1 = Double.parseDouble(split1[0]); y1 = Double.parseDouble(split1[1]); z1 = Double.parseDouble(split1[2]);
  66.                            a.put(player2.getName(),i+","+"Mainjail");
  67.                     player2.teleportTo(x1,y1+1,z1,0,0);
  68.                     player.sendMessage("§2Player jailed at cell "+i);
  69.                     player2.sendMessage("§4"+player.getName()+" Jailed you!");
  70.                     return true;
  71.                       }
  72.                   }
  73.                   }else{
  74.                       player.sendMessage("§cThis player is already jailed.");
  75.                       return true;
  76.                   }
  77.               }else{
  78.                   player.sendMessage("§cThis jail doesnt exist.");
  79.                   return true;
  80.               }
  81.           }
  82.         }
  83.     return false;
  84. }
  85. public boolean isInList(String s) {
  86.     try {
  87.       BufferedReader in = new BufferedReader(new FileReader(names));
  88.       String line = in.readLine();
  89.       while (line != null) {
  90.         if (line.equalsIgnoreCase(s)) {
  91.           in.close();
  92.           return true;
  93.         }
  94.         line = in.readLine();
  95.       }
  96.       in.close();
  97.     } catch (IOException localIOException) {
  98.     }
  99.     return false; }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment