@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { String langid = "en_US"; SFTranslation t = SFTranslation.getInstance(); SFPlayer sfp = null; if (sender instanceof Player) { sfp = new SFPlayer((Player) sender); langid = sfp.getLanguage(); } int page = 1; if (args.length > 0) { try { page = Integer.parseInt(args[0]); } catch (NumberFormatException ex) { sender.sendMessage( ChatColor.RED + t.translateKeyFormat("read.invalidnumber", langid, args[0])); return false; } } List<SFMail> msgs; msgs = plugin .getDatabase() .find(SFMail.class) .where() .ieq("toPlayer", sender.getName()) .orderBy("timestamp DESC") .findList(); if (sfp != null) { if (sfp.hasClientMod() && sfp.getClientModVersion() > 0.2) { sfp.showMailboxGui(msgs); return true; } } if (msgs.isEmpty()) { sender.sendMessage(ChatColor.RED + t.translateKey("read.emptymailbox", langid)); return true; } else { final int start = (page - 1) * 5; final int pages = msgs.size() / 5 + (msgs.size() % 5 > 0 ? 1 : 0); sender.sendMessage( ChatColor.GREEN + t.translateKey("general.page", langid) + " " + page + "/" + pages); for (int i = start; i < msgs.size() && i < start + 5; i++) { OfflinePlayer op = plugin.getServer().getOfflinePlayer(msgs.get(i).getFromPlayer()); String dispName = ChatColor.YELLOW + op.getName() + ChatColor.WHITE; if (op.isOp()) { dispName = (ChatColor.AQUA + op.getName() + ChatColor.WHITE); } else { dispName = (ChatColor.GREEN + op.getName() + ChatColor.WHITE); } sender.sendMessage( ChatColor.GRAY + ((new SimpleDateFormat("dd.MM")).format(new Date(msgs.get(i).getTimestamp()))) + " " + dispName + ": " + msgs.get(i).getMessage()); } sender.sendMessage(ChatColor.AQUA + t.translateKey("read.usecleartoempty", langid)); return true; } }
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { SFPlayer sfp = SFPlayer.getSFPlayer(player); if (channel.equalsIgnoreCase("simplefeatures")) { JSONObject json = (JSONObject) JSONValue.parse(new String(message)); String id = ((String) json.get("id")); if (id.equalsIgnoreCase("login")) { double version = (Double) json.get("version"); String lang = (String) json.get("lang"); if (lang == null) { lang = "en_US"; } SFPlugin.clientAddons.put(player.getName(), version); SFPlugin.playerLangs.put(player.getName(), lang); SFPlugin.log( Level.INFO, player.getName() + " has the SFClientMod version " + version + ", using language " + lang); } else if (id.equalsIgnoreCase("sendmail")) { if (!player.hasPermission(new Permission("sfp.msg", PermissionDefault.TRUE))) { player.sendMessage(ChatColor.RED + sfp.translateString("general.nopermission")); return; } String pname = ((String) json.get("to")); OfflinePlayer target = SFPlugin.getOfflinePlayer(player, pname, plugin); if (target != null) { player.sendMessage( sfp.translateStringFormat("Mail sent to %s: %s", target.getName(), json.get("mail"))); SFMail save = new SFMail(); save.newMail(player.getName(), target.getName(), ((String) json.get("mail"))); plugin.getDatabase().save(save); Player p = plugin.getServer().getPlayer(target.getName()); if (p != null) { p.sendMessage( ChatColor.AQUA + SFPlayer.getSFPlayer(p).translateString("mail.newmailnotify")); } return; } } else if (id.equalsIgnoreCase("clearmailbox")) { List<SFMail> msgs; msgs = plugin .getDatabase() .find(SFMail.class) .where() .ieq("toPlayer", player.getName()) .findList(); if (msgs.isEmpty()) { player.sendMessage(ChatColor.RED + sfp.translateString("clear.nothingtoclear")); return; } else { int i = 0; for (SFMail msg : msgs) { plugin.getDatabase().delete(msg); i++; } player.sendMessage(ChatColor.YELLOW + sfp.translateStringFormat("clear.success", i)); return; } } else if (id.equalsIgnoreCase("deletemail")) { SFMail msg = plugin .getDatabase() .find(SFMail.class) .where() .ieq("toPlayer", player.getName()) .ieq("id", json.get("mailid").toString()) .findUnique(); if (msg == null) { player.sendMessage(ChatColor.RED + sfp.translateString("delete.nothingtodelete")); return; } else { player.sendMessage( ChatColor.YELLOW + sfp.translateStringFormat("delete.success", msg.getFromPlayer())); plugin.getDatabase().delete(msg); return; } } else { SFPlugin.log(Level.INFO, "Unknown SFPacket! Contents: " + new String(message)); } } }
public BListener(SFPlugin parent) { plugin = parent; plugin.getServer().getPluginManager().registerEvents(this, plugin); }