static HtmlEmail setAuthentication(HtmlEmail email) { if (!(CommandsEX.getConf().getString("Email.Username").isEmpty() && CommandsEX.getConf().getString("Email.Password").isEmpty())) { email.setAuthentication( CommandsEX.getConf().getString("Email.Username"), CommandsEX.getConf().getString("Email.Password")); } return email; }
/*** * Loads existing chat replacements from the config file and activates event listeners. */ public Handler_replacechat() { // load replacement values from config file File playerChatFile = new File(CommandsEX.plugin.getDataFolder(), CommandsEX.getConf().getString("chatReplaceFile")); FileListHelper.checkListFile(playerChatFile, "playerchat.txt"); addReplacementPairs(FileListHelper.loadListFromFile(playerChatFile, FileListHelper.MatchingContext.Chat)); CommandsEX.plugin.getServer().getPluginManager().registerEvents(this, CommandsEX.plugin); }
/** * * INFO - displays text from info.txt * * @param sender * @param args * @return */ public static Boolean run(CommandSender sender, String alias, String[] args) { // Command Variables Player player = (Player) sender; String[] infos = CommandsEX.getConf() .getString("info") .replace("{playername}", player.getDisplayName()) .split("\\{newline\\}"); for (String info : infos) { player.sendMessage(Utils.replaceChatColors(info)); } return true; }
public static void compose(CommandSender sender, String type) { if (inProgress(sender.getName())) { LogHelper.showWarning("emailAlreadyInProgress", sender); return; } if (type.equalsIgnoreCase("simple")) { SimpleEmail email = new SimpleEmail(); email.setHostName(CommandsEX.getConf().getString("Email.Host")); try { email.setFrom(CommandsEX.getConf().getString("Email.From")); } catch (EmailException e) { sendErrorMessage(sender, e); return; } email = setAuthentication(email); simpleEmail.put(sender.getName(), email); } else if (type.equalsIgnoreCase("attachment")) { MultiPartEmail email = new MultiPartEmail(); email.setHostName(CommandsEX.getConf().getString("Email.Host")); try { email.setFrom(CommandsEX.getConf().getString("Email.From")); } catch (EmailException e) { sendErrorMessage(sender, e); return; } email = setAuthentication(email); multiEmail.put(sender.getName(), email); } else if (type.equalsIgnoreCase("html")) { HtmlEmail email = new HtmlEmail(); email.setHostName(CommandsEX.getConf().getString("Email.Host")); try { email.setFrom(CommandsEX.getConf().getString("Email.From")); } catch (EmailException e) { sendErrorMessage(sender, e); return; } email = setAuthentication(email); htmlEmail.put(sender.getName(), email); } LogHelper.showInfo("emailCreated", sender); }
/*** * 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()); } }