public void onPlayerChat(PlayerChatEvent event) { String eventplayer = event.getPlayer().getName(); if (admin.freeze.contains(eventplayer)) { // player in hashmap chats String msg = event.getMessage(); admin.tellAdmin(ChatColor.DARK_AQUA + "Blocked message by " + eventplayer + ": " + msg); Random rand = new Random(); int number; number = 1 + rand.nextInt(10); if (number == 1) { event.setMessage("Lolz."); } else if (number == 2) { event.setMessage("This is funny!"); } else if (number == 3) { event.setMessage("I wish i was a cool server-owner! :3"); } else if (number == 4) { event.setMessage("Turtles are round"); } else if (number == 5) { event.setMessage("I'm a kitty! purr :3"); } else if (number == 6) { event.setMessage("This place is great!"); } else if (number == 7) { event.setMessage("Hurr Durr"); } else if (number == 8) { event.setMessage("How did i get here?"); } else if (number == 9) { event.setMessage("My friends are lions"); } else if (number == 10) { event.setMessage("<('_'<) (>'_')>"); } else { // error lolz event.getPlayer().sendMessage("error lolz."); admin.logInfo("ZOMG THERE WAS A JAVA ERROR! ERROR: failed to generate random number(lolz)"); } } else { // nothing. } }
@Override public void onPlayerChat(final PlayerChatEvent event) { if (isAborted(event)) { return; } /** * This file should handle detection of the local chat features... if local chat is enabled, we * need to handle it here */ final User user = ess.getUser(event.getPlayer()); final String chatType = getChatType(event.getMessage()); long radius = ess.getSettings().getChatRadius(); if (radius < 1) { return; } radius *= radius; try { if (event.getMessage().length() > 0 && chatType.length() > 0) { StringBuilder permission = new StringBuilder(); permission.append("essentials.chat.").append(chatType); StringBuilder command = new StringBuilder(); command.append("chat-").append(chatType); StringBuilder format = new StringBuilder(); format.append(chatType).append("Format"); StringBuilder errorMsg = new StringBuilder(); errorMsg .append("notAllowedTo") .append(chatType.substring(0, 1).toUpperCase()) .append(chatType.substring(1)); if (user.isAuthorized(permission.toString())) { charge(user, command.toString()); event.setMessage(event.getMessage().substring(1)); event.setFormat(Util.format(format.toString(), event.getFormat())); return; } user.sendMessage(Util.i18n(errorMsg.toString())); event.setCancelled(true); return; } } catch (ChargeException ex) { ess.showError(user, ex, "Shout"); event.setCancelled(true); return; } sendLocalChat(user, radius, event); }
/*** * The main function which replaces chat with matched replacements. * @param e * @return */ @EventHandler(priority = EventPriority.LOWEST) public void replaceChat(PlayerChatEvent e) { if (e.isCancelled()) return; try { ScriptEnvironment env = new ScriptEnvironment(); { env.setCommandSender(e.getPlayer()); env.setServer(e.getPlayer().getServer()); } ArrayList<ReplacementPair> preparedEffects = new ArrayList<ReplacementPair>(); //holds all effects until all replacements done for (ReplacementPair rp : pairs) { StringBuffer sb = new StringBuffer(); Matcher m = rp.getRegex().matcher(e.getMessage()); if (!m.find()) continue; env.setMatcher(m); if (rp.playerWillVanish()) { //the player will vanish as a result of this, special handling int cutlen = CommandsEX.getConf().getInt("replacements.cutoff.length", 1); String cuttext = CommandsEX.getConf().getString("replacements.cutoff.indicator", "--*"); String rep = m.group().substring(0, cutlen).concat(cuttext); m.appendReplacement(sb, rep); e.setMessage(sb.toString()); //e.setCancelled(true); //e.getPlayer().chat(sb.toString()); //chat first rp.executeEffects(env); //then execute the replacement return; } //loop through with find/replace do { //use do while, due to the find() invocation above // test if it is all upper, and replace with all upper (if we have this set up in the regex itself - in config file) if (rp.getSameOutputCase() && allUpper && m.group().toUpperCase().equals(m.group())) { m.appendReplacement(sb, rp.executeString(env).toUpperCase()); } else { m.appendReplacement(sb, rp.executeString(env)); } } while (m.find()); m.appendTail(sb); if (!preparedEffects.contains(rp)) { preparedEffects.add(rp); } e.setMessage(sb.toString()); } //after all replacements are in: execute the effects if (!preparedEffects.isEmpty()) { //e.setCancelled(true); //e.getPlayer().chat(sb.toString()); //chat first env.setMatcher(null); for (ReplacementPair rp : preparedEffects){ rp.executeEffects(env); } } } catch (Exception ex){ LogHelper.logSevere("[CommandsEX] " + _("cmdOrChatreplacementFailed", "")); LogHelper.logDebug("Message: " + ex.getMessage() + ", cause: " + ex.getCause()); } }