nahbr0

Untitled

Oct 24th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package com.cometproject.server.game.commands;
  2.  
  3. import com.cometproject.server.config.Locale;
  4. import com.cometproject.server.network.messages.outgoing.notification.AlertMessageComposer;
  5. import com.cometproject.server.network.messages.outgoing.notification.NotificationMessageComposer;
  6. import com.cometproject.server.network.messages.outgoing.room.avatar.WhisperMessageComposer;
  7. import com.cometproject.server.network.sessions.Session;
  8.  
  9.  
  10. public abstract class ChatCommand {
  11. public static void sendNotif(String msg, Session session) {
  12. session.send(new NotificationMessageComposer("generic", msg));
  13. }
  14.  
  15. public static void sendAlert(String msg, Session session) {
  16. session.send(new AlertMessageComposer(msg));
  17. }
  18.  
  19. public static void sendWhisper(String msg, Session session) {
  20. session.send(new WhisperMessageComposer(session.getPlayer().getEntity().getId(), msg));
  21. }
  22.  
  23. public static void isExecuted(Session session) {
  24. session.send(new NotificationMessageComposer("up", Locale.getOrDefault("command.executed", "Command is executed succesfully.")));
  25. }
  26.  
  27. public abstract void execute(Session client, String[] params);
  28.  
  29. public abstract String getPermission();
  30.  
  31. public abstract String getParameter();
  32.  
  33. public abstract String getDescription();
  34.  
  35. public final String merge(String[] params) {
  36. final StringBuilder stringBuilder = new StringBuilder();
  37.  
  38. for (String s : params) {
  39. if (!params[params.length - 1].equals(s))
  40. stringBuilder.append(s).append(" ");
  41. else
  42. stringBuilder.append(s);
  43. }
  44.  
  45. return stringBuilder.toString();
  46. }
  47.  
  48. public String merge(String[] params, int begin) {
  49. final StringBuilder mergedParams = new StringBuilder();
  50.  
  51. for (int i = 0; i < params.length; i++) {
  52. if (i >= begin) {
  53. mergedParams.append(params[i]).append(" ");
  54. }
  55. }
  56.  
  57. return mergedParams.toString();
  58. }
  59.  
  60. public boolean isHidden() {
  61. return false;
  62. }
  63.  
  64. public boolean canDisable() {
  65. return false;
  66. }
  67.  
  68. public boolean isAsync() {
  69. return false;
  70. }
  71.  
  72. public boolean bypassFilter() {
  73. return false;
  74. }
  75.  
  76. public static class Execution implements Runnable {
  77. private ChatCommand command;
  78. private String[] params;
  79. private Session session;
  80.  
  81. public Execution(ChatCommand command, String[] params, Session session) {
  82. this.command = command;
  83. this.params = params;
  84. this.session = session;
  85. }
  86.  
  87. @Override
  88. public void run() {
  89. command.execute(session, params);
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment