spenk

JailWand

Mar 15th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.Writer;
  7. import java.util.HashMap;
  8.  
  9.  
  10. public class JailWand extends PluginListener{
  11.     int i = 1;
  12.     File coords = new File("plugins/config/Jail/FileC.txt");
  13.     File names = new File("plugins/config/Jail/Jailnames.txt");
  14.     String directory = "plugins/config/Jail/Jailes/";
  15.     PropertiesFile props = new PropertiesFile("plugins/config/Jail/JailProps.properties");
  16.     HashMap<String,String> alist = new HashMap<String,String>();
  17.    
  18.     public boolean onCommand(Player player,String[] split){
  19.         if (split[0].equalsIgnoreCase("/jailwand")&&player.canUseCommand("/jailadmin")){
  20.             if (split.length <2|| split.length >2){
  21.                 player.sendMessage("§cThe correct usage is '/jailwand <jailname>'");
  22.                 return true;
  23.             }else{
  24.             if (isInList(split[1])){
  25.                 alist.put(player.getName(), split[1]);
  26.                 player.sendMessage("§2You can now select jails by rightklicking with your jailwand.");
  27.                 return true;
  28.             }else{
  29.                 player.sendMessage("§cThis jail doesnt exist.");
  30.                 return true;
  31.             }
  32.             }
  33.         }else{
  34.             if(split[0].equalsIgnoreCase("/stopwand")&&player.canUseCommand("/jailadmin")){
  35.                 alist.remove(player.getName());
  36.                 player.sendMessage("§2You stopped selecting cells.");
  37.                 return true;
  38.             }
  39.         }
  40.         return false;
  41.     }
  42.     Writer writer;
  43.     public boolean onBlockRightClick(Player player,Block block,Item iih){
  44.         if (alist.containsKey(player.getName())){
  45.             if (iih.getItemId() == props.getInt("Jail-Wand-Item")){
  46.                 String co = Math.floor(block.getX())+","+Math.floor(block.getY())+","+Math.floor(block.getZ())+","+player.getWorld();
  47.                 if (!isInListco(co)){
  48.                     try {
  49.                         writer = new FileWriter("plugins/config/Jail/FileC.txt", true);
  50.                         writer.write(co+"\n");
  51.                         writer.close();
  52.                     } catch (IOException e) {
  53.                     }
  54.                     PropertiesFile jail = new PropertiesFile(directory+alist.get(player.getName())+".properties");
  55.                     jail.setString(i+"",co);
  56.                     player.sendMessage("§2Cell "+i+" has been set.");
  57.                     i++;
  58.                     return false;
  59.                 }else{
  60.                     player.sendMessage("§cThese coördinates are already used by another jail or cell.");
  61.                     return true;
  62.                 }
  63.             }
  64.         }
  65.         return false;
  66.     }
  67.      public boolean isInList(String s) {
  68.             try {
  69.               BufferedReader in = new BufferedReader(new FileReader(names));
  70.               String line = in.readLine();
  71.               while (line != null) {
  72.                 if (line.equalsIgnoreCase(s)) {
  73.                   in.close();
  74.                   return true;
  75.                 }
  76.                 line = in.readLine();
  77.               }
  78.               in.close();
  79.             } catch (IOException localIOException) {
  80.             }
  81.             return false; }
  82.      
  83.      public boolean isInListco(String s) {
  84.             try {
  85.               BufferedReader in = new BufferedReader(new FileReader(coords));
  86.               String line = in.readLine();
  87.               while (line != null) {
  88.                 if (line.equalsIgnoreCase(s)) {
  89.                   in.close();
  90.                   return true;
  91.                 }
  92.                 line = in.readLine();
  93.               }
  94.               in.close();
  95.             } catch (IOException localIOException) {
  96.             }
  97.             return false; }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment