Guest User

Untitled

a guest
May 6th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.02 KB | None | 0 0
  1. package players.around;
  2.  
  3. import net.md_5.bungee.api.ChatColor;
  4.  
  5. import org.bukkit.Location;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10.  
  11. public class MainClass extends JavaPlugin{
  12.    
  13.     private final String COMMAND = "around";
  14.     private final String PERMUSE = "around.use";
  15.     private final String DISTANCE = "maxDistance";
  16.     private final String PERMALL = "around.*";
  17.    
  18.     @Override
  19.     public void onEnable() {
  20.         this.getLogger().info("PLAYERS AROUND duoc bat thanh cong!");
  21.         loadConfig();
  22.     }
  23.    
  24.     @Override
  25.     public void onDisable() {
  26.         this.getLogger().info("PLAYERS AROUND da bi vo hieu hoa!");
  27.     }
  28.    
  29.     public void loadConfig() {
  30.         this.getConfig().options().copyDefaults(true);
  31.         this.saveConfig();
  32.     }
  33.    
  34.     public void setDistance(double distance) {
  35.         this.getConfig().set(DISTANCE, distance);
  36.         this.saveConfig();
  37.     }
  38.    
  39.     public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
  40.        
  41.         if (cmd.getName().equalsIgnoreCase(COMMAND)) {
  42.            
  43.             if (args.length == 0) {
  44.                 sender.sendMessage("/around check   - Check yourself");
  45.                 if (!(sender instanceof Player) || sender.hasPermission(PERMALL)) {
  46.                     sender.sendMessage("/around check <PLAYER>   - Check PLAYER");
  47.                     sender.sendMessage("/around set <DISTANCE>   - Set the distance");
  48.                 }
  49.             }
  50.            
  51.             else {
  52.            
  53.             // Console command
  54.             if (!(sender instanceof Player)) {
  55.                 // Check someone
  56.                 if (args[0].equalsIgnoreCase("check")) {
  57.                     if (args.length == 1) {
  58.                         sender.sendMessage(ChatColor.YELLOW +  "Nhap ten mot nguoi choi");
  59.                     }
  60.                    
  61.                     else {
  62.                         Player p = getServer().getPlayer(args[1]);
  63.                         if (p == null) {
  64.                             sender.sendMessage("Nguoi choi offline hoac khong ton tai!");
  65.                         }
  66.                         else {
  67.                             Location pLocation = p.getLocation();
  68.                             double distance = this.getConfig().getDouble(DISTANCE);
  69.                             int i = 0;
  70.                            
  71.                             for (Player player : getServer().getOnlinePlayers()) {
  72.                                 Location targetLocation = player.getLocation();
  73.                                 double distanceX = Math.abs(targetLocation.getX() - pLocation.getX());
  74.                                 double distanceZ = Math.abs(targetLocation.getZ() - pLocation.getZ());
  75.                                 if ((distanceX <= distance || distanceZ <= distance) && player != p) {
  76.                                     i++;
  77.                                     sender.sendMessage(ChatColor.YELLOW + "" + i + ". " + player.getName());
  78.                                 }
  79.                             }
  80.                            
  81.                             sender.sendMessage(ChatColor.GREEN +  "Tong cong co " + i + " nguoi");
  82.                         }
  83.                     }
  84.                    
  85.                 }
  86.                 // Set distance
  87.                 if (args[0].equalsIgnoreCase("set")) {
  88.                     try {
  89.                         double distance = Double.parseDouble(args[1]);
  90.                         this.getConfig().set(DISTANCE, distance);
  91.                         this.saveConfig();
  92.                         sender.sendMessage(ChatColor.GREEN + "Da cap nhat thanh cong khoang cach la " + distance);
  93.                     }
  94.                     catch(Exception e) {
  95.                         sender.sendMessage(ChatColor.RED + "Xay ra loi!");
  96.                     }
  97.                    
  98.                    
  99.                    
  100.                 }
  101.                
  102.                 if (!args[0].equalsIgnoreCase("check") && !args[0].equalsIgnoreCase("set")) {
  103.                     sender.sendMessage(ChatColor.RED +  "Lenh khong ton tai!");
  104.                 }
  105.             }
  106.             ///////////////
  107.             ///////////////
  108.             // Player command
  109.             if (sender instanceof Player) {
  110.                 Player p = (Player) sender;
  111.                 if (args[0].equalsIgnoreCase("check") ) {
  112.                     //////////////////////
  113.                     if (args.length == 2 && p.hasPermission(PERMALL)) {
  114.                         Player pl = getServer().getPlayer(args[1]);
  115.                         if (pl == null) {
  116.                             sender.sendMessage(ChatColor.RED + "Người chơi offline hoặc không tồn tại");
  117.                         }
  118.                         else {
  119.                             Location pLocation = pl.getLocation();
  120.                             double distance = this.getConfig().getDouble(DISTANCE);
  121.                             int i = 0;
  122.                            
  123.                             for (Player player : getServer().getOnlinePlayers()) {
  124.                                 Location targetLocation = player.getLocation();
  125.                                 double distanceX = Math.abs(targetLocation.getX() - pLocation.getX());
  126.                                 double distanceZ = Math.abs(targetLocation.getZ() - pLocation.getZ());
  127.                                 if ((distanceX <= distance || distanceZ <= distance) && player != pl) {
  128.                                     i++;
  129.                                     p.sendMessage(ChatColor.YELLOW + "" + i + ". " + player.getName());
  130.                                 }
  131.                             }
  132.                            
  133.                             p.sendMessage(ChatColor.GREEN +  "Tổng cộng có " + i + " người");
  134.                         }
  135.                     }
  136.                    
  137.                     ////////////////////////
  138.                         else if (args.length == 1 && p.hasPermission(PERMUSE)){
  139.                             Location pLocation = p.getLocation();
  140.                             double distance = this.getConfig().getDouble(DISTANCE);
  141.                             //p.sendMessage(ChatColor.GREEN + "Những người chơi gần bạn:");
  142.                             int i = 0;
  143.                            
  144.                             for (Player player : getServer().getOnlinePlayers()) {
  145.                                 Location targetLocation = player.getLocation();
  146.                                 double distanceX = Math.abs(targetLocation.getX() - pLocation.getX());
  147.                                 double distanceZ = Math.abs(targetLocation.getZ() - pLocation.getZ());
  148.                                 if ((distanceX <= distance || distanceZ <= distance) && player != p) {
  149.                                     i++;
  150.                                     p.sendMessage(ChatColor.YELLOW + "" + i + ". " + player.getName());
  151.                                 }
  152.                             }
  153.                            
  154.                             sender.sendMessage(ChatColor.GREEN +  "Tổng cộng có " + i + " người");
  155.                            
  156.                         }
  157.                 }
  158.                    
  159.                    
  160.                    
  161.                
  162.                 else {
  163.                     p.sendMessage(ChatColor.RED + "Bạn không có quyền để sử dụng lệnh này hoặc lệnh không tồn tại!");
  164.                 }
  165.                
  166.                 // Set distance
  167.                 if (args[0].equalsIgnoreCase("set") && p.hasPermission(PERMALL)) {
  168.                     try {
  169.                         double distance = Double.parseDouble(args[1]);
  170.                         this.getConfig().set(DISTANCE, distance);
  171.                         this.saveConfig();
  172.                         p.sendMessage(ChatColor.GREEN + "Đã cập nhật thành công khoảng cách là " + distance);
  173.                     }
  174.                     catch(Exception e) {
  175.                         sender.sendMessage("Xảy ra lỗi!");
  176.                     }
  177.                    
  178.                    
  179.                    
  180.                 }
  181.                
  182.                 if (!args[0].equalsIgnoreCase("check") && !args[0].equalsIgnoreCase("set")) {
  183.                     sender.sendMessage(ChatColor.RED +  "Lệnh không tồn tại!");
  184.                 }
  185.             }
  186.         }
  187.            
  188.         }
  189.        
  190.         return false;
  191.    
  192.     }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment