Beispiel #1
0
  @EventHandler(priority = EventPriority.HIGHEST, canVeto = true)
  public boolean onPM(PMEvent event) {
    IRC config = plugin.getConfigManager().getConfig("irc");

    if (FontFormat.stripColor(event.getFrom()).contains(FontFormat.stripColor(config.IngameName))) {
      Messages messages = plugin.getConfigManager().getConfig("messages");

      // Check if there is a " " in the name
      String ircNick;
      if (event.getFrom().contains(config.IngameName)) {
        ircNick = FontFormat.stripColor(event.getFrom().replace(config.IngameName, ""));
      } else {
        ircNick =
            FontFormat.stripColor(event.getMessage().replace(config.IngameName, "").split(" ")[0]);
      }

      ProxiedPlayer sen = plugin.getProxy().getPlayer(event.getTo());

      if (sen == null) {
        ircModule.getIrcBot().sendToChannel("Player " + event.getTo() + " is offline", ircNick);
        return true;
      }

      if (ircModule.getIrcBot().getIrcManager().hasPmSession(ircNick)) {
        PMSession pmSession = ircModule.getIrcBot().getIrcManager().getPmSession(ircNick);
        pmSession.setTo(sen.getName());
      } else {
        ircModule.getIrcBot().getIrcManager().newPMSession(ircNick);
        PMSession pmSession = ircModule.getIrcBot().getIrcManager().getPmSession(ircNick);
        pmSession.setTo(sen.getName());
      }

      playerManager.get(sen.getName()).Reply = FontFormat.stripColor(config.IngameName) + ircNick;
      MessageBuilder messageBuilder = new MessageBuilder();
      messageBuilder.setText(
          FontFormat.translateString(
              messages.Message_Receiver.replace("%sender", config.IngameName + ircNick)
                  .replace("%message", event.getMessage().replace(ircNick + " ", ""))));
      messageBuilder.send(sen);

      plugin
          .getPluginLogger()
          .info(
              event.getFrom()
                  + " -> "
                  + event.getTo()
                  + ": "
                  + event.getMessage().replace(ircNick + " ", ""));

      return true;
    }

    return false;
  }
Beispiel #2
0
  @Override
  public boolean execute(IRCSender sender, String[] args) {
    Messages messages = plugin.getConfigManager().getConfig("messages");

    // Check for Permissions
    if (!ircModule.getPermissions().has(sender.getRawNick(), "command.scmd")) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughPermission.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    if (args.length < 2) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughArguments.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    // Check for Server and command permission
    String server = args[0];
    String command = args[1];

    if (!ircModule.getPermissions().has(sender.getRawNick(), "command.scmd.server." + server)) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughPermissionForServer.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    if (!ircModule.getPermissions().has(sender.getRawNick(), "command.scmd.command." + command)) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughPermissionForCommand.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    // Check if there is a Player online on the wanted Server
    if (!server.equals("bungee")) {
      ServerInfo serverInfo = plugin.getProxy().getServerInfo(server);
      if (serverInfo == null) {
        ircModule
            .getIrcBot()
            .sendToChannel(
                MCToIrcFormat.translateString(
                    messages.IRC_Command_Scmd_InvalidServer.replace("%nick", sender.getRawNick())),
                sender.getChannel());
        return true;
      }

      if (serverInfo.getPlayers().size() == 0) {
        ircModule
            .getIrcBot()
            .sendToChannel(
                MCToIrcFormat.translateString(
                    messages.IRC_Command_Scmd_ServerIsEmpty.replace("%nick", sender.getRawNick())),
                sender.getChannel());
        return true;
      }

      // Create a new SCMD Session
      String scommand = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
      plugin
          .getPluginLogger()
          .info("Issuing SCMD '" + scommand + "' on " + args[0] + " for " + sender.getNick());
      Integer sessionId =
          ircModule
              .getIrcBot()
              .getIrcManager()
              .newScmdSession(sender.getRawNick(), sender.getChannel(), scommand);

      DispatchScmdMessage dispatchScmdMessage = new DispatchScmdMessage(scommand, sessionId);
      plugin
          .getPluginMessageManager("CloudChat")
          .sendPluginMessage(serverInfo.getPlayers().iterator().next(), dispatchScmdMessage);
    } else {
      String scommand = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
      plugin
          .getPluginLogger()
          .info("Issuing SCMD '" + scommand + "' on " + args[0] + " for " + sender.getNick());
      plugin
          .getProxy()
          .getPluginManager()
          .dispatchCommand(new CloudChatCommandSender(ircModule, sender), scommand);
    }

    ircModule
        .getIrcBot()
        .sendToChannel(
            MCToIrcFormat.translateString(
                messages.IRC_Command_Scmd_CommandIssued.replace("%nick", sender.getRawNick())),
            sender.getChannel());
    return true;
  }