Ejemplo n.º 1
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onScreenOpen(final ScreenOpenEvent event) {
   if (!event.isCancelled() && event.getScreenType() == ScreenType.CHAT_SCREEN) {
     Color black = new Color(0f, 0f, 0f, 0.5f), white = new Color(1f, 1f, 1f, 0.5f);
     SpoutPlayer player = event.getPlayer();
     Widget label, bar = chatbar.get(player);
     if (bar == null) {
       bar =
           new GenericContainer(
                   label =
                       new GenericLabel(
                               ChatColor.GRAY
                                   + Herochat.getChatterManager()
                                       .getChatter(player)
                                       .getActiveChannel()
                                       .getName())
                           .setResize(true)
                           .setFixed(true)
                           .setMargin(3, 3, 0, 3),
                   new GenericGradient(black).setPriority(RenderPriority.Highest),
                   new GenericGradient(white)
                       .setMaxWidth(1)
                       .setPriority(RenderPriority.High)
                       .setVisible(false),
                   new GenericGradient(white)
                       .setMaxWidth(1)
                       .setMarginLeft(label.getWidth() + 5)
                       .setPriority(RenderPriority.High),
                   new GenericGradient(white).setMaxHeight(1).setPriority(RenderPriority.High))
               .setLayout(ContainerType.OVERLAY)
               .setAnchor(WidgetAnchor.BOTTOM_LEFT)
               .setY(-27)
               .setX(4)
               .setHeight(13)
               .setWidth(label.getWidth() + 6);
       chatbar.put(player, bar);
       player.getMainScreen().attachWidget(this, bar);
     }
     bar.setVisible(true);
   }
 }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onChannelChatEvent(ChannelChatEvent event) {
    Resident resident = CivGlobal.getResident(event.getSender().getName());
    if (resident == null) {
      event.setResult(Result.FAIL);
      return;
    }

    if (!resident.isInteractiveMode()) {
      if (resident.isMuted()) {
        event.setResult(Result.MUTED);
        return;
      }
    }

    if (event.getChannel().getDistance() > 0) {
      for (String name : Resident.allchatters) {
        Player player;
        try {
          player = CivGlobal.getPlayer(name);
        } catch (CivException e) {
          continue;
        }

        Chatter you = Herochat.getChatterManager().getChatter(player);
        if (!event.getSender().isInRange(you, event.getChannel().getDistance())) {
          player.sendMessage(
              CivColor.White
                  + event.getSender().getName()
                  + CivSettings.localize.localizedString("hc_prefix_far")
                  + " "
                  + event.getMessage());
        }
      }
    }
  }
 protected static void handleMessage(
     final Player player, final IRCChannel c, final String message) {
   if (player != null) {
     if (MonsterIRC.getHandleManager().getPermissionsHandler().hasNode(player, "irc.nochat")
         && !player.isOp()
         && !MonsterIRC.getHandleManager().getPermissionsHandler().hasNode(player, "*")) {
       player.sendMessage("You are blocked from sending messages to irc!");
       return;
     }
   }
   if (c.getBlockedEvents().contains("game_chat")) {
     return;
   }
   if (player == null) {
     final StringBuffer result2 = new StringBuffer();
     result2.append(
         Variables.ircformat
             .replace("{HCchannelColor}", "&f")
             .replace("{heroChatTag}", "[Console]")
             .replace("{heroChatName}", "[Console]")
             .replace("{prefix}", StringUtils.getPrefix("Console"))
             .replace("{name}", StringUtils.getDisplayName("Console"))
             .replace("{displayName}", StringUtils.getDisplayName("Console"))
             .replace("{suffix}", StringUtils.getSuffix("Console"))
             .replace("{groupPrefix}", StringUtils.getGroupPrefix("Console"))
             .replace("{groupSuffix}", StringUtils.getGroupSuffix("Console"))
             .replace("{message}", message)
             .replace("{mvWorld}", StringUtils.getMvWorldAlias("console"))
             .replace("{mvColor}", StringUtils.getMvWorldColor("console"))
             .replace("{world}", StringUtils.getWorld("Console")));
     Variables.linesToIrc++;
     IRC.sendMessageToChannel(c, ColorUtils.formatGametoIRC(result2.toString()));
     return;
   }
   final StringBuffer result = new StringBuffer();
   if (c.getChatType() == ChatType.MCMMOADMINCHAT) {
     if (Bukkit.getServer().getPluginManager().getPlugin("mcMMO") != null) {
       if (Users.getProfile(player.getName()).getAdminChatMode()) {
         result.append(
             Variables.ircformat
                 .replace("{HCchannelColor}", "")
                 .replace("{heroChatTag}", "")
                 .replace("{prefix}", StringUtils.getPrefix(player.getName()))
                 .replace("{name}", StringUtils.getDisplayName(player.getName()))
                 .replace("{displayName}", StringUtils.getDisplayName(player.getDisplayName()))
                 .replace("{suffix}", StringUtils.getSuffix(player.getName()))
                 .replace("{groupPrefix}", StringUtils.getGroupPrefix(player.getName()))
                 .replace("{groupSuffix}", StringUtils.getGroupSuffix(player.getName()))
                 .replace("{message}", " " + message)
                 .replace("{mvWorld}", StringUtils.getMvWorldAlias(player.getWorld().getName()))
                 .replace("{mvColor}", StringUtils.getMvWorldColor(player.getWorld().getName()))
                 .replace("{world}", StringUtils.getWorld(player.getWorld().getName())));
         Variables.linesToIrc++;
         IRC.sendMessageToChannel(c, ColorUtils.formatGametoIRC(result.toString()));
       }
     }
   } else if (c.getChatType() == ChatType.HEROCHAT) {
     if (Bukkit.getServer().getPluginManager().getPlugin("mcMMO") != null) {
       if (Users.getProfile(player.getName()).getAdminChatMode()) {
         return;
       }
       if (Users.getProfile(player.getName()).getPartyChatMode()) {
         return;
       }
     }
     if (c.getHeroChatChannel() != null) {
       if ((Herochat.getChatterManager().getChatter(player).getActiveChannel()
                   == c.getHeroChatChannel()
               || c.isHeroChatListenChannel(
                   Herochat.getChatterManager()
                       .getChatter(player.getName())
                       .getActiveChannel()
                       .getName()))
           && !Herochat.getChatterManager().getChatter(player.getName()).isMuted()) {
         result.append(
             Variables.ircformat
                 .replace(
                     "{heroChatTag}",
                     Herochat.getChatterManager().getChatter(player).getActiveChannel().getColor()
                         + "["
                         + Herochat.getChatterManager()
                             .getChatter(player)
                             .getActiveChannel()
                             .getNick()
                         + "]"
                         + ColorUtils.NORMAL.getIRCColor()
                         + "")
                 .replace(
                     "{heroChatName}",
                     Herochat.getChatterManager().getChatter(player).getActiveChannel().getColor()
                         + "["
                         + Herochat.getChatterManager()
                             .getChatter(player)
                             .getActiveChannel()
                             .getName()
                         + "]"
                         + ColorUtils.NORMAL.getIRCColor()
                         + "")
                 .replace("{prefix}", StringUtils.getPrefix(player.getName()))
                 .replace("{name}", StringUtils.getDisplayName(player.getName()))
                 .replace("{displayName}", StringUtils.getDisplayName(player.getDisplayName()))
                 .replace("{suffix}", StringUtils.getSuffix(player.getName()))
                 .replace("{groupPrefix}", StringUtils.getGroupPrefix(player.getName()))
                 .replace("{groupSuffix}", StringUtils.getGroupSuffix(player.getName()))
                 .replace(
                     "{HCchannelColor}",
                     Herochat.getChatterManager()
                         .getChatter(player)
                         .getActiveChannel()
                         .getColor()
                         .toString())
                 .replace("{message}", " " + message)
                 .replace("{mvWorld}", StringUtils.getMvWorldAlias(player.getWorld().getName()))
                 .replace("{mvColor}", StringUtils.getMvWorldColor(player.getWorld().getName()))
                 .replace("{world}", StringUtils.getWorld(player.getWorld().getName())));
         Variables.linesToIrc++;
         IRC.sendMessageToChannel(c.getChannel(), ColorUtils.formatGametoIRC(result.toString()));
       }
     } else {
       IRC.log("Invalid herochat channel detected for " + c.getChannel());
     }
   } else if (c.getChatType() == ChatType.GLOBAL) {
     if (Bukkit.getServer().getPluginManager().getPlugin("mcMMO") != null) {
       if (Users.getProfile(player.getName()).getAdminChatMode()) {
         return;
       }
       if (Users.getProfile(player.getName()).getPartyChatMode()) {
         return;
       }
     }
     result.append(
         Variables.ircformat
             .replace("{HCchannelColor}", "&f")
             .replace("{heroChatTag}", "")
             .replace("{heroChatName}", "")
             .replace("{prefix}", StringUtils.getPrefix(player.getName()))
             .replace("{name}", StringUtils.getDisplayName(player.getName()))
             .replace("{displayName}", StringUtils.getDisplayName(player.getDisplayName()))
             .replace("{suffix}", StringUtils.getSuffix(player.getName()))
             .replace("{groupPrefix}", StringUtils.getGroupPrefix(player.getName()))
             .replace("{groupSuffix}", StringUtils.getGroupSuffix(player.getName()))
             .replace("{message}", " " + message)
             .replace("{mvWorld}", StringUtils.getMvWorldAlias(player.getWorld().getName()))
             .replace("{mvColor}", StringUtils.getMvWorldColor(player.getWorld().getName()))
             .replace("{world}", StringUtils.getWorld(player.getWorld().getName())));
     Variables.linesToIrc++;
     IRC.sendMessageToChannel(c, ColorUtils.formatGametoIRC(result.toString()));
   }
 }