russelburgraymond

addclas

Mar 7th, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | Source Code | 0 0
  1. package busstation.busstation.commands;
  2.  
  3. import busstation.busstation.BusStation;
  4. import busstation.busstation.util.ConfigUtilities;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandExecutor;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12.  
  13. public class addBus implements CommandExecutor {
  14. private BusStation plugin;
  15.  
  16. public addBus(BusStation pl) {
  17. plugin = pl;
  18. }
  19.  
  20. @Override
  21. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  22. ConfigUtilities config = new ConfigUtilities(plugin, "coords.yml");
  23. Player player = (Player) sender;
  24. Location loc = player.getLocation();
  25. String world = player.getWorld().getName();
  26. if (sender instanceof Player) {
  27. if (args.length == 2) {
  28. boolean addstop = false;
  29. if (!(config.getConfig().getConfigurationSection("stops." + args[0]) == null)) {
  30. sender.sendMessage(ChatColor.RED + "That location name is already used on the server.");
  31. return false;
  32. } // location isn't already in coords.yml
  33. else {
  34. for (String key : config.getConfig().getConfigurationSection("stops").getKeys(false)) {
  35. String cworld = config.getConfig().getString("stops." + key + ".Location.world");
  36. if (world.equalsIgnoreCase(config.getConfig().getString("stops." + key + ".Location.world"))) {
  37. Location locb = (Location) config.getConfig().getLocation("stops." + key + ".Location");
  38. int mindis = plugin.getConfig().getInt("minStopDist");
  39. if (loc.distance(locb) < mindis) {
  40. addstop = true;
  41.  
  42. } // minimum distance
  43. }// if world equals world.
  44. } // end string loop.
  45. } // end else location not in config.
  46. if (addstop) {
  47. sender.sendMessage("Not Adding Location");
  48. } else {
  49. sender.sendMessage("Adding location");
  50. }
  51. return true;
  52. } // args length
  53. } // instance of player
  54. return true;
  55. } // methods
  56. } // class
  57.  
Advertisement
Add Comment
Please, Sign In to add comment