示例#1
0
  private void onMouseMove(Player player, int dx, int dy, int x, int y) {
    // Mouse hasn't moved
    if (dx == 0 && dy == 0) {
      return;
    }

    Screen screen = getInputScreen();
    if (screen != null) {
      IntVector2 prev = new IntVector2(x - dx, y - dy);
      IntVector2 pos = new IntVector2(x, y);
      for (Widget w : screen.getWidgets()) {
        w.onMouseMoved(prev, pos, w == screen.getWidgetAt(x, y));
      }
    }

    // Mouse moved on x-axis
    if (!redirected) {
      if (dx != 0) {
        player.processCommand("dx", new ChatArguments(dx));
      }

      // Mouse moved on y-axis
      if (dy != 0) {
        player.processCommand("dy", new ChatArguments(dy));
      }
    }
  }
示例#2
0
  @Override
  public void handleServer(ServerSession session, PlayerChatMessage message) {
    if (!session.hasPlayer()) {
      return;
    }

    Player player = session.getPlayer();
    String text = message.getMessage().trim();
    if (text.length() > 100) {
      text = text.substring(0, 99);
    }

    String command;
    String[] args;

    if (text.startsWith("/")) {
      command = text.split(" ")[0].replaceFirst("/", "");
      int argsIndex = text.indexOf(" ") + 1;
      args = argsIndex > 0 ? text.substring(argsIndex).split(" ") : new String[0];
    } else {
      command = "say";
      args = text.split(" ");
    }

    player.processCommand(command, args);
  }
示例#3
0
 private void executeBindings(Set<Binding> bindings, Player player, boolean pressed) {
   ChatArguments args = new ChatArguments(pressed ? "+" : "-");
   // Queue up sync bindings first
   for (Binding binding : bindings) {
     if (!binding.isAsync()) {
       player
           .getEngine()
           .getScheduler()
           .scheduleSyncDelayedTask(null, new BindingTask(player, binding.getCommand(), args));
     }
   }
   // Execute async bindings
   for (Binding binding : bindings) {
     if (binding.isAsync()) {
       player.processCommand(binding.getCommand(), args);
     }
   }
 }
示例#4
0
 @Override
 public void run() {
   player.processCommand(command, arguments);
 }