AlanGomes

Untitled

Feb 12th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. package com.brinedev.vip;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class VIP extends JavaPlugin
  11. {
  12.  
  13.   public void onEnable()
  14.   {
  15.     saveDefaultConfig();
  16.   }
  17.  
  18.   public  String serializeLocation(Location l) {
  19.         String s = "";
  20.         s += "@w;" + l.getWorld().getName();
  21.         s += ":@x;" + l.getBlockX();
  22.         s += ":@y;" + l.getBlockY();
  23.         s += ":@z;" + l.getBlockZ();
  24.         s += ":@p;" + l.getPitch();
  25.         s += ":@ya;" + l.getYaw();
  26.         return s;
  27.         }
  28.  
  29.     public  Location deserializeLocation(String s) {
  30.         try {
  31.         Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
  32.         String[] att = s.split(":");
  33.         for(String attribute : att) {
  34.         String[] split = attribute.split(";");
  35.         if(split[0].equalsIgnoreCase("@w"))
  36.         l.setWorld(Bukkit.getWorld(split[1]));
  37.         if(split[0].equalsIgnoreCase("@x"))
  38.         l.setX(Double.parseDouble(split[1]));
  39.         if(split[0].equalsIgnoreCase("@y"))
  40.         l.setY(Double.parseDouble(split[1]));
  41.         if(split[0].equalsIgnoreCase("@z"))
  42.         l.setZ(Double.parseDouble(split[1]));
  43.         if(split[0].equalsIgnoreCase("@p"))
  44.         l.setPitch(Float.parseFloat(split[1]));
  45.         if(split[0].equalsIgnoreCase("@ya"))
  46.         l.setYaw(Float.parseFloat(split[1]));
  47.          
  48.         }
  49.         return l;
  50.         } catch (Exception e) {
  51.             return null;
  52.         }
  53.     }
  54.    
  55.   public void onDisable() {
  56.   }
  57.  
  58.   public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  59.       if ((sender instanceof Player)==false) {
  60.             sender.sendMessage("§cApenas players!");
  61.             return true;
  62.           }
  63.       Player p = (Player)sender;
  64.     if (cmd.getName().equalsIgnoreCase("setvip")) {
  65.         if (!p.hasPermission("vip.setar")) {
  66.             sender.sendMessage("§cVoce nao tem permissao!");
  67.             return true;
  68.         }
  69.       getConfig().set("LugarVIP", serializeLocation(p.getLocation().clone()));
  70.       saveConfig();
  71.       sender.sendMessage("§aLugar VIP setado!");
  72.       return false;
  73.     } else if (cmd.getName().equalsIgnoreCase("vip")) {
  74.         if (!p.hasPermission("vip.ir")) {
  75.             sender.sendMessage("§cVoce nao tem permissao!");
  76.             return true;
  77.         }
  78.         if (!getConfig().contains("LugarVIP")) {
  79.             sender.sendMessage("§cLocal VIP nao setado, chame um admin!");
  80.             return false;
  81.         }
  82.         if (getConfig().getString("LugarVIP").equalsIgnoreCase("")) {
  83.             sender.sendMessage("§cLocal VIP nao setado, chame um admin!");
  84.             return false;
  85.         }
  86.         if (deserializeLocation(getConfig().getString("LugarVIP"))==null) {
  87.             sender.sendMessage("§cLocal VIP nao setado, chame um admin!");
  88.             return false;
  89.         }
  90.         p.teleport(deserializeLocation(getConfig().getString("LugarVIP")));
  91.         p.sendMessage(getConfig().getString("Mensagem").replace("&", "§"));
  92.         return false;
  93.     }
  94.  
  95.     return false;
  96.   }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment