Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.HashMap;
  5.  
  6. public class MyListener extends PluginListener
  7. {
  8.     static final Gethome plugin = new Gethome();
  9.     HashMap<String, String> players = read("homes.txt");
  10.  
  11.     public boolean onCommand(Player player, String[] split) {
  12.         if ((split[0].equals(plugin.getCommandName())) && (player.canUseCommand(plugin.getCommandName()))) {
  13.             if (split.length == 1) {
  14.                 if (this.players.containsKey(player.getName()))
  15.                     player.notify("Votre home se trouve à " + (String)this.players.get(player.getName()));
  16.                 else
  17.                     player.notify("Vous n'avez pas enregistré d'home !");
  18.             }
  19.             else {
  20.                 player.notify("Syntaxe correcte : " + plugin.getCommandName() + " " + plugin.getCommandDesc());
  21.             }
  22.             return true;
  23.         }if ((split[0].equals("/sethome")) && (player.canUseCommand("/sethome"))) {
  24.             this.players = read("homes.txt");
  25.         }
  26.         return false;
  27.     }
  28.  
  29.     public static HashMap<String, String> read(String file) {
  30.         HashMap map = new HashMap();
  31.         try {
  32.             BufferedReader buff = new BufferedReader(new FileReader(file));
  33.             try
  34.             {
  35.                 String line;
  36.                 while ((line = buff.readLine()) != null)
  37.                 {
  38.                     String line;
  39.                     String[] split = line.split(":");
  40.                     float x = Float.parseFloat(split[1]); float y = Float.parseFloat(split[2]); float z = Float.parseFloat(split[3]);
  41.                     map.put(split[0], (int)x + ", " + (int)y + ", " + (int)z);
  42.                 }
  43.             } finally {
  44.                 buff.close();
  45.             }
  46.         } catch (IOException e) {
  47.             e.printStackTrace();
  48.         }
  49.         return map;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement