Advertisement
Straiker123

SCR Remaster - Warp command

Apr 9th, 2022
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. CommandStructure.create(CommandSender.class, PERMS_CHECKER, (s, structure, args) -> { // cmd
  2.     List<WarpHolder> warps = WarpManager.availableWarps(s);
  3.     StringBuilder warpNames = new StringBuilder();
  4.     for(WarpHolder warp : warps) {
  5.         if(warpNames.length()!=0)
  6.             warpNames.append(Loader.translations.getString(configSection()+".list_split"));
  7.         warpNames.append(warp.name());
  8.     }
  9.     msgConfig(s, configSection()+".list", warpNames);
  10. }).argument(null, (s, structure, args) -> { // cmd [any string]
  11.     if(!(s instanceof Player)) { //must be player
  12.         help(s, 0);
  13.         return;
  14.     }
  15.    
  16.     WarpHolder warp = WarpManager.find(args[0]);
  17.     if(warp == null) {
  18.         msgConfig(s, "warp.notFound", args[0]);
  19.         return;
  20.     }
  21.     int teleportResult;
  22.     if((teleportResult=warp.canTeleport((Player)s)) != 0) {
  23.         String reason = teleportResult == 1 ? "perms" : "money";
  24.         msgConfig(s, "warp.cannot_teleport."+reason, args[0]);
  25.         return;
  26.     }
  27.     ((Player)s).teleport(warp.location());
  28.     msgConfig(s, configSection()+".warp.self", warp.name());
  29. }).argument("-s", (s, structure, args) -> { // cmd [any string] -s
  30.     if(!(s instanceof Player)) { //must be player
  31.         help(s, 0);
  32.         return;
  33.     }
  34.    
  35.     WarpHolder warp = WarpManager.find(args[0]);
  36.     if(warp == null) {
  37.         msgConfig(s, "warp.notFound", args[0]);
  38.         return;
  39.     }
  40.     int teleportResult;
  41.     if((teleportResult=warp.canTeleport((Player)s)) != 0) {
  42.         String reason = teleportResult == 1 ? "perms" : "money";
  43.         msgConfig(s, "warp.cannot_teleport."+reason, args[0]);
  44.         return;
  45.     }
  46.     ((Player)s).teleport(warp.location());
  47. }).parent()
  48. .selector(Selector.ENTITY_SELECTOR, (s, structure, args) -> { // cmd [any string] [entity_selector]
  49.     WarpHolder warp = WarpManager.find(args[0]);
  50.     if(warp == null) {
  51.         msgConfig(s, "warp.notFound", args[0]);
  52.         return;
  53.     }
  54.     for(Player p : playerSelectors(s, args[0])) {
  55.         int teleportResult;
  56.         if((teleportResult=warp.canTeleport(p)) != 0) {
  57.             String reason = teleportResult == 1 ? "perms" : "money";
  58.             msgConfig(s, "warp.cannot_teleport."+reason, args[0]);
  59.             return;
  60.         }
  61.         p.teleport(warp.location());
  62.         msgConfig(s, configSection()+".warp.other.sender", warp.name(), p.getName());
  63.         msgConfig(p, configSection()+".warp.other.target", warp.name(), p.getName());
  64.     }
  65. }).argument("-s", (s, structure, args) -> { // cmd [any string] [entity_selector] -s
  66.     WarpHolder warp = WarpManager.find(args[0]);
  67.     if(warp == null) {
  68.         msgConfig(s, "warp.notFound", args[0]);
  69.         return;
  70.     }
  71.     for(Player p : playerSelectors(s, args[0])) {
  72.         int teleportResult;
  73.         if((teleportResult=warp.canTeleport(p)) != 0) {
  74.             String reason = teleportResult == 1 ? "perms" : "money";
  75.             msgConfig(s, "warp.cannot_teleport."+reason, args[0]);
  76.             return;
  77.         }
  78.         p.teleport(warp.location());
  79.     }
  80. }).build().register(cmds.remove(0), cmds.toArray(new String[0]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement