I origionally posted this on rune-server and silabsoft. But ill re-post it here to get some flow in the forums
My New Alert System.::Video Result::.
First off You're going to have to add 2 classes to your
client files.
AlertHandler.javaimport java.util.ArrayList;
import java.util.List;
public class AlertHandler {
public boolean hovered = false;
public boolean close = false;
public boolean show = false;
public boolean remove = false;
public Alert alert = null;
public client c;
public AlertHandler(client c) {
this.c = c;
}
public void close() {
close = true;
}
public void processAlerts() {
if(alert == null)
return;
if (alert.active()) {
if (close) {
alert.close();
close = false;
}
if (!alert.isClosed() && alert.getOpacity() < 90 && alert.extraY > 0) {
alert.opacity += 5;
if(alert.extraY > 0)
alert.extraY -= (c.isFullScreen ? 10 : 5);
if(alert.extraY < 0)
alert.extraY = 0;
c.alertBack.drawSpriteOpacity(alert.getX(), alert.getY()+alert.extraY, alert.getOpacity());
} else if (alert.isClosed()) {
alert.extraY += 5;
if(alert.getOpacity() > 0)
alert.opacity -= 5;
else {
remove = true;
show = false;
alert.active = false;
}
c.alertBack.drawSpriteOpacity(alert.getX(), alert.getY()+alert.extraY, alert.getOpacity());
} else {
if(alert.getOpacity() < 90)
alert.opacity = 90;
if (show) {
c.alertBack.drawSpriteOpacity(alert.getX(), alert.getY(), hovered ? alert.getOpacity()+25 : alert.getOpacity());
if(hovered)
c.alertBorderH.drawSprite(alert.getX(), alert.getY());
else
c.alertBorder.drawSprite(alert.getX(), alert.getY());
}
c.aTextDrawingArea_1271.drawText(0, alert.getTitle(), alert.getY()+16, alert.getX()+243);
c.aTextDrawingArea_1271.drawText(alert.getTitleColor(), alert.getTitle(), alert.getY()+15, alert.getX()+242);
c.smallText.drawText(0, alert.getLine(1), alert.getY()+36, alert.getX()+243);
c.smallText.drawText(alert.getColor(2), alert.getLine(1), alert.getY()+35, alert.getX()+242);
c.smallText.drawText(0, alert.getLine(2), alert.getY()+56, alert.getX()+243);
c.smallText.drawText(alert.getColor(2), alert.getLine(2), alert.getY()+55, alert.getX()+242);
show = true;
}
}
if (remove) {
alert = null;
remove = false;
}
}
public void processMouse(int x, int y) {
if(alert == null)
return;
if (alert.active()) {
hovered = (x >= alert.getX() && x <= alert.getX()+484 && y >= alert.getY() && y <= alert.getY()+79);
if(hovered) {
c.menuActionName[1] = "Dismiss";
c.menuActionID[1] = 476;
c.menuActionRow = 2;
}
}
}
}
Alert.java/**
* @Author Robgob
* Do whatever you want.
*/
public class Alert {
public Alert(String title, String line1, String line2) {
this.title = title;
this.line1 = line1;
this.line2 = line2;
titleColor = 0xff0000;
color1 = 0xffffff;
color2 = 0xffffff;
active = true;
}
public Alert(String title, String line1, String line2, int c1, int c2, int c3) {
this.title = title;
this.line1 = line1;
this.line2 = line2;
titleColor = c1;
color1 = c2;
color2 = c3;
active = true;
}
public String getTitle() {
return title;
}
public String getLine(int i) {
return (i == 1 ? line1 : line2);
}
public int getTitleColor() {
return titleColor;
}
public int getColor(int i) {
return (i == 1 ? color1 : color2);
}
public boolean active() {
return active;
}
public void close() {
closed = true;
}
public boolean opening() {
return open;
}
public int getOpacity() {
return opacity;
}
public boolean isClosed() {
return closed;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
/*
* Holds the text for the Notification
*/
private String title;
private String line1;
private String line2;
/*
* Holds the Colors for the Notification
*/
private int titleColor;
private int color1;
private int color2;
/*
* is the notification active; visible.
*/
public boolean active = false;
/*
* is the notification closed by the user?
*/
private boolean closed = false;
/*
* is the notification opening?
*/
public boolean open = true;
/*
* How visible the Notification is
* 0 = not at all || 50 = barely || 255 = fully visible
*/
public int opacity = 0;
/*
* Holds the Screen position
*/
private int x = 14;
private int y = 250;
public int extraX = 0;
public int extraY = 40;
}
After that you're going to need to add the Sprites

- save as: alertback.png

- save as: alertborder.png

- save as: alertborderh.png
Now for the coding; Open up your
client.javaadd this somewhere in:
public AlertHandler alertHandler;
public Sprite alertBack;
public Sprite alertBorder;
public Sprite alertBorderH;
Then search for:
void resetLogout()and under that line add:
alertHandler.alert = null;
then search for:
/* Null pointers for custom sprites */
add this under it:
alertBack = null;
alertBorder = null;
alertBorderH = null;
now search for:
void doAction(int i)and in that method where you see
if(l >= 2000)
l -= 2000;
add this right under it:
if (l == 476) {
alertHandler.close();
}
Now search for:
rightClickChatButtons();add this under it:
alertHandler.processMouse(super.mouseX, super.mouseY);
Now search for:
scrollBar2 = new Sprite(streamLoader_2, "scrollbar", 1);
and add this below it:
alertBack = new Sprite("alertback");
alertBorder = new Sprite("alertborder");
alertBorderH = new Sprite("alertborderh");
Next search for:
void draw3dScreen()
and add this right below it:
alertHandler.processAlerts();
Next search for:
case 253:It should look something like this..
case 253:
String s = inStream.readString();
if(s.endsWith(":tradereq:")) {
String s3 = s.substring(0, s.indexOf(":"));
long l17 = TextClass.longForName(s3);
boolean flag2 = false;
for(int j27 = 0; j27 < ignoreCount; j27++) {
if(ignoreListAsLongs[j27] != l17)
continue;
flag2 = true;
}
if(!flag2 && anInt1251 == 0)
pushMessage("wishes to trade with you.", 4, s3);
} else if(s.endsWith("#url#")) {
String link = s.substring(0, s.indexOf("#"));
pushMessage("Join us at: ", 9, link);
} else if(s.endsWith(":duelreq:")) {
String s4 = s.substring(0, s.indexOf(":"));
long l18 = TextClass.longForName(s4);
boolean flag3 = false;
for(int k27 = 0; k27 < ignoreCount; k27++) {
if(ignoreListAsLongs[k27] != l18)
continue;
flag3 = true;
}
if(!flag3 && anInt1251 == 0)
pushMessage("wishes to duel with you.", 8, s4);
} else if(s.endsWith(":chalreq:")) {
String s5 = s.substring(0, s.indexOf(":"));
long l19 = TextClass.longForName(s5);
boolean flag4 = false;
for(int l27 = 0; l27 < ignoreCount; l27++) {
if(ignoreListAsLongs[l27] != l19)
continue;
flag4 = true;
}
if(!flag4 && anInt1251 == 0) {
String s8 = s.substring(s.indexOf(":") + 1, s.length() - 9);
pushMessage(s8, 8, s5);
}
} else {
pushMessage(s, 0, "");
}
pktType = -1;
return true;
So right under where it says:
String s = inStream.readString();add this right below it:
if(s.startsWith("Alert##")) {
String[] args = s.split("##");
if (args.length == 3) {
alertHandler.alert = new Alert("Notification", args[1], args[2]);
} else if (args.length == 4) {
alertHandler.alert = new Alert(args[1], args[2], args[3]);
}
pktType = -1;
return true;
}Next search for:
public client() {(sometimes private client())
under that add:
alertHandler = new AlertHandler(this);
And the last part make sure that these variables have public access in the client
so change these:
private TextDrawingArea smallText;
private TextDrawingArea aTextDrawingArea_1271;
private String[] menuActionName;
private int[] menuActionID;
private int menuActionRow;
to these:
public TextDrawingArea smallText;
public TextDrawingArea aTextDrawingArea_1271;
public String[] menuActionName;
public int[] menuActionID;
public int menuActionRow;
So that should be about it for the client
Now in your server to get the alert to work you need a message to be sent.
For the welcome screen add this wherever your welcome message is initiated:
sendMessage("Alert##Welcome to YOUR SERVER NAME!##This is Robgob's new Alert system!##He's a sexy Beast ;]");
For an alert command[PI]:
if (playerCommand.startsWith("alert") && c.playerRights > 1) {
String msg = playerCommand.substring(6);
for (int i = 0; i < Config.MAX_PLAYERS; i++) {
if (Server.playerHandler.players[i] != null) {
c.sendMessage("Alert##Notification##" + msg + "##By: " + c.playerName);
}
}
}
For an alert command[Allstar]:
if (command.startsWith("alert") && playerRights > 1) {
String msg = playerCommand.substring(6);
PlayerHandler.messageToAll = "Alert##Notification##" + msg + "##By: " + playerName;
}
Here's your end result:
