- Joined
- Sep 25, 2014
- Messages
- 38
- Reaction score
- 7
This is a simple system to allow GMs to view any unresolved player @gm messages that were sent either while no GM was online or that GMs simply missed. It also allows GMs to delete messages once they have been resolved. It can initialize or save any unresolved messages on start-up and shutdown. SQL has not been included, but its easy enough to make a table. I won't tell you where to put everything, but it shouldn't be too difficult to figure out. Overall, certainly can still be improved and prettied up, but too lazy. Hopefully someone finds it useful. Enjoy.
Screenshots
Code:
package net.sf.odinms.client;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import net.sf.odinms.database.DatabaseConnection;
/**
*
* @author Navi
*/
public class GMMessage {
private static GMMessage instance = null;
private static final List<GMMessageEntry> messages = new ArrayList<>();
private static boolean open;
public static GMMessage getInstance() {
if (instance == null) {
instance = new GMMessage();
}
return instance;
}
public GMMessage() {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM `gmmessage` ORDER BY `when` DESC");
ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
messages.add(new GMMessageEntry(rs.getString("cname"), rs.getString("message"), rs.getLong("when")));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void saveToDB() {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `gmmessage`")) {
ps.executeUpdate();
} catch (SQLException s) {
s.printStackTrace();
}
if (messages.size() > 0) {
try (PreparedStatement ps = con.prepareStatement("INSERT INTO gmmessage(`cname`, `message`,`when`) VALUES(?, ?, ?)")) {
for (GMMessageEntry m : messages) {
ps.setString(1, m.getCName());
ps.setString(2, m.getMessage());
ps.setLong(3, m.getMillis());
ps.addBatch();
}
ps.executeBatch();
} catch(SQLException s) {
s.printStackTrace();
}
}
}
public static List<GMMessageEntry> getMessages() {
return messages;
}
public static boolean sessionOpen() {
return open;
}
public static void setSession(boolean tf) {
open = tf;
}
public static void addMessage(String name, String message) {
messages.add(new GMMessageEntry(name, message, System.currentTimeMillis()));
}
public static void removeMessage(int index) {
messages.remove(index);
}
public static class GMMessageEntry{
private final String cname;
private final String message;
private final long millis;
public GMMessageEntry(String cname, String message, long timestamp) {
this.cname = cname;
this.message = message;
this.millis = timestamp;
}
public String getCName() {
return cname;
}
public String getMessage() {
return message;
}
public String getTimestamp() {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy kk:mm:ss");
Date d = new Date(millis);
return sdf.format(d);
}
public long getMillis() {
return millis;
}
}
}
Code:
/*
help.js - Maple Admin(@gm)
Coded by Navi for MapleLegends
*/
importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.tools);
var status = -1;
var amount;
var selected;
var open = false;
var messages;
function start() {
status = -1;
action(1,0,0);
}
function action(mode,type,selection) {
if (mode == -1) {
if (open) {
GMMessage.setSession(false);
}
cm.dispose();
} else if (mode == 0 && status <= 2) {
if (open) {
GMMessage.setSession(false);
}
cm.dispose();
} else {
if (mode == 1) {
status++;
} else {
status--;
}
if (status == 0) {
if (!cm.getPlayer().isGM()) {
cm.sendGetText("Hello! Do you have a question, comment, or suggestion? Please type it in the space provided.");
} else {
if (!GMMessage.sessionOpen()) {
open = true;
GMMessage.setSession(true);
cm.sendGetNumber("Would you like to check the recent GM Messages? How many messages would you like to see?", 1, 1, 50); //too many may crash it?
} else {
//GMMessage.setSession(false); //to debug if needed
cm.sendOk("Another GM is currently checking GM Messages. Please try again later.");
cm.dispose();
}
}
} else if(status == 1){
if (!cm.getPlayer().isGM()) {
if (cm.getText().length() > 0) {
GMMessage.addMessage(cm.getPlayer().getName(), cm.getText());
cm.getClient().getChannelServer().getWorldInterface().broadcastGMMessage(null, MaplePacketCreator.serverNotice(6, "[GM MESSAGE - " + cm.getPlayer().getName() + "] " + cm.getText()).getBytes());
cm.sendOk("An in-game message has been sent to all online game moderators.");
cm.dispose();
} else {
status = -1;
cm.sendOk("You did not enter a message.");
}
} else {
amount = selection;
cm.sendNext("We are pulling up the "+amount+" most recent GM messages...");
}
} else if (status == 2) {
messages = GMMessage.getMessages();
if (messages.size() > 0) {
var str = "Here are all of the unresolved GM Messages. Click on a message if it has been resolved:"
for (var i=0; i<Math.min(amount, messages.size()); i++) {
str+="\r\n#L"+i+"##e"+messages.get(i).getCName()+"#n #r("+messages.get(i).getTimestamp()+")#k\r\n#b"+messages.get(i).getMessage()+"#k";
}
cm.sendSimple(str);
} else {
GMMessage.setSession(false);
cm.sendOk("There are no new GM Messages.");
cm.dispose();
}
} else if (status == 3) {
selected = selection;
cm.sendYesNo("Would you like to delete the following GM Message?\r\n#e"+messages.get(selected).getCName()+"#n #r("+messages.get(selected).getTimestamp()+")#k\r\n#b"+messages.get(selected).getMessage()+"#k");
} else if (status == 4) {
status = 1;
GMMessage.removeMessage(selected);
cm.sendOk("This message has been deleted");
}
}
}
Screenshots

