Before you start: this is for real 525's not z525 or 508's with 525 cache. Also not sure if this still works a user here found it on a diffrent site but it was hard to read so i rewrite it.
Alright lets start. save this as
punishHandler.java
Put punishHandler class in Server525\src\com\rs2hd\model
Code:
package com.rs2hd.model;
import java.util.*;
import java.io.*;
import org.apache.mina.common.IoSession;
import com.rs2hd.io.XStreamPlayerLoader;
public class punishHandler
{
public static List<String> banned = new ArrayList<String>();
public static List<String> muted = new ArrayList<String>();
public static List<String> ipbanned = new ArrayList<String>();
public static List<String> ipmuted = new ArrayList<String>();
public punishHandler()
{
updateAll();
}
public static void updateAll()
{
banUpdate();
ipbanUpdate();
muteUpdate();
ipmuteUpdate();
}
public static void banUpdate()
{
banned.clear();
try
{
BufferedReader in = new BufferedReader(new FileReader("data/text/bans.txt"));
String inFile;
while ((inFile = in.readLine()) != null)
{
banned.add(inFile);
}
} catch (Exception e) {}
}
public static void ipmuteUpdate()
{
ipmuted.clear();
try
{
BufferedReader in = new BufferedReader(new FileReader("data/text/ipmutes.txt"));
String inFile;
while ((inFile = in.readLine()) != null)
{
ipmuted.add(inFile);
}
} catch (Exception e) {}
}
public static void muteUpdate()
{
muted.clear();
try
{
BufferedReader in = new BufferedReader(new FileReader("data/text/mutes.txt"));
String inFile;
while ((inFile = in.readLine()) != null)
{
muted.add(inFile);
}
} catch (Exception e) {}
}
public static void ipbanUpdate()
{
ipbanned.clear();
try
{
BufferedReader in = new BufferedReader(new FileReader("data/text/ipbans.txt"));
String inFile;
while ((inFile = in.readLine()) != null)
{
ipbanned.add(inFile);
}
} catch (Exception e) {}
}
public void writeTo(String name, String path)
{
BufferedWriter bw = null;
try
{
bw = new BufferedWriter(new FileWriter(path +".txt", true));
bw.write(name);
bw.newLine();
bw.flush();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
finally
{
if (bw != null)
{
try
{
bw.close();
} catch (IOException ioe2) {
System.out.println("Error writing system log.");
ioe2.printStackTrace();
}
}
}
updateAll();
}
public void deleteFrom(String name, String path)
{
if (name != null)
{
File file = new File(path + ".txt");
if (file.exists())
{
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
BufferedWriter out = new BufferedWriter(new FileWriter(file));
String inFile;
while ((inFile = in.readLine()) != null)
{
if (inFile.equalsIgnoreCase(name))
out.write(inFile);
}
} catch (Exception e) {}
}
}
updateAll();
}
public boolean isBanned(String name)
{
updateAll();
if (banned.contains(name))
return true;
return false;
}
public boolean isIpBanned(IoSession session)
{
String ip = session.getRemoteAddress().toString();
updateAll();
if (ipbanned.contains(ip))
return true;
return false;
}
public boolean isIpMuted(IoSession session)
{
String ip = session.getRemoteAddress().toString();
updateAll();
if (ipmuted.contains(ip))
return true;
return false;
}
public boolean isMuted(String name)
{
updateAll();
if (muted.contains(name))
return true;
return false;
}
}
Now download this folder it has two .java files in it put it in your util folder located:
Server525\src\com\rs2hd\util
Link: [Only registered and activated users can see links. ]
Banned.java
Put Banned class in Server525\src\com\rs2hd\model
Code:
package com.rs2hd.model;
import java.util.*;
import java.io.*;
import com.rs2hd.io.XStreamPlayerLoader;
import com.rs2hd.model.Player;
public class Banned
{
public static List<String> banned = new ArrayList<String>();
public void banUser(String name)
{
BufferedWriter bw = null;
try
{
bw = new BufferedWriter(new FileWriter("data/bans.txt", true));
bw.write(name);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null)
try
{
bw.close();
} catch (IOException ioe2) {
System.out.println("Error writing system log.");
ioe2.printStackTrace();
}
}
update();
}
public boolean isBanned(String name)
{
update();
if (banned.contains(name))
return true;
return false;
}
public void unBan(String name)
{
if (name != null)
{
File file = new File("data/bans.txt");
if (file.exists())
{
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
BufferedWriter out = new BufferedWriter(new FileWriter(file));
String inFile;
while ((inFile = in.readLine()) != null)
{
if (inFile.equalsIgnoreCase(name)) {}
else
out.write(inFile);
}
} catch (Exception e) {}
}
}
update();
}
public static void update()
{
banned.clear();
try
{
BufferedReader in = new BufferedReader(new FileReader("data/bans.txt"));
String inFile;
while ((inFile = in.readLine()) != null)
{
banned.add(inFile);
}
} catch (Exception e) {}
}
public Banned()
{
update();
}
}
Now add these commands located in: Server525\src\com\rs2hd\packethandler\commands
banuser.java
Code:
package com.rs2hd.packethandler.commands;
import com.rs2hd.model.Player;
import com.rs2hd.io.XStreamPlayerLoader;
import com.rs2hd.Constants;
import com.rs2hd.model.*;
import com.rs2hd.net.Packet;
public class banuser implements Command
{
@Override
public void execute(Player player, String command)
{
String ban = command.substring(;
XStreamPlayerLoader.punish.writeTo(ban, "/data/text/bans");
player.sm((new StringBuilder()).append("You have banned ").append(ban).toString());
for(Player p : World.getInstance().getPlayerList())
{
if(p.getUsername().equalsIgnoreCase(ban))
{
p.getActionSender().logout();
}
}
}
@Override
public int getRights()
{
return 2;
}
}
ipban.java
Code:
package com.rs2hd.packethandler.commands;
import com.rs2hd.model.Player;
import com.rs2hd.io.XStreamPlayerLoader;
import com.rs2hd.Constants;
import com.rs2hd.model.*;
import com.rs2hd.net.Packet;
public class ipban implements Command
{
@Override
public void execute(Player player, String command)
{
String ban = command.substring(6);
XStreamPlayerLoader.punish.writeTo(ban, "/data/text/ipbans");
player.sm((new StringBuilder()).append("You have ipbanned ").append(ban).toString());
for(Player p : World.getInstance().getPlayerList())
{
if(p.getUsername().equalsIgnoreCase(ban))
{
p.getActionSender().logout();
}
}
}
@Override
public int getRights()
{
return 2;
}
}
ipmute.java
Code:
package com.rs2hd.packethandler.commands;
import com.rs2hd.model.Player;
import com.rs2hd.io.XStreamPlayerLoader;
import com.rs2hd.Constants;
import com.rs2hd.model.*;
import com.rs2hd.net.Packet;
public class ipmute implements Command
{
@Override
public void execute(Player player, String command)
{
String ban = command.substring(7);
XStreamPlayerLoader.punish.writeTo(ban, "/data/text/ipmutes");
player.sm((new StringBuilder()).append("You have ipmuted ").append(ban).toString());
for(Player p : World.getInstance().getPlayerList())
{
if(p.getUsername().equalsIgnoreCase(ban))
{
p.getActionSender().logout();
}
}
}
@Override
public int getRights()
{
return 2;
}
}
mute.java
Code:
package com.rs2hd.packethandler.commands;
import com.rs2hd.model.Player;
import com.rs2hd.io.XStreamPlayerLoader;
public class mute implements Command
{
@Override
public void execute(Player player, String command)
{
String mute = command.substring(6);
XStreamPlayerLoader.punish.writeTo(mute, "/data/text/mutes");
player.sm((new StringBuilder()).append("You have muted ").append(mute).toString());
}
@Override
public int getRights()
{
return 1;
}
}
unban.java
Code:
package com.rs2hd.packethandler.commands;
import com.rs2hd.model.Player;
import com.rs2hd.io.XStreamPlayerLoader;
public class unban implements Command
{
@Override
public void execute(Player player, String command)
{
String ban = command.substring(6);
XStreamPlayerLoader.punish.deleteFrom(ban, "/data/text/mutes");
player.sm((new StringBuilder()).append("You have unbanned ").append(ban).toString());
}
@Override
public int getRights()
{
return 2;
}
}
unmute.java
Code:
package com.rs2hd.packethandler.commands;
import com.rs2hd.model.Player;
import com.rs2hd.io.XStreamPlayerLoader;
public class unmute implements Command
{
@Override
public void execute(Player player, String command)
{
String mute = command.substring(7);
XStreamPlayerLoader.punish.deleteFrom(mute, "/data/text/mutes");
player.sm((new StringBuilder()).append("You have unmuted ").append(mute).toString());
}
@Override
public int getRights()
{
return 1;
}
}
Alright now add these to your commmandmanager class file
Code:
commandMap.put("banuser", new banuser());
commandMap.put("unban", new unban());
commandMap.put("mute", new mute());
commandMap.put("unmute", new unmute());
commandMap.put("ipban", new ipban());
Alright now we need to modify XStreamPlayerLoader class
Add these imports
Lmao... you didn't make this `trey did all you did was give him a picture..
[Only registered and activated users can see links. ]
also you should learn to read... "i didnt ask for rep i don't give a shit about rep idc if i dont get any from this" i did it to help others."...
Look at the date of it. You obviously were desperate for a banning system now after looking for hours you feel like you accomplished something so you released it for credit.
Me and Trey made up and he deleted his thread. Don't judge over a illogical thread made 2 years ago. I didn't say say I made this, so YOU learn to read.
Either way it looks quite long for something simple like a ban system. This could be done with just a few lines of code instead of like 7 new classes or however many there are I cba counting.
If it works then good job to whoever created, I wont be using it though. It would also look nicer with proper conventions etc, maybe you should re-write again and clean it up a bit.
[Only registered and activated users can see links. ]
Either way it looks quite long for something simple like a ban system. This could be done with just a few lines of code instead of like 7 new classes or however many there are I cba counting.
If it works then good job to whoever created, I wont be using it though. It would also look nicer with proper conventions etc, maybe you should re-write again and clean it up a bit.
I agree, this can be written way easier; but still it's a start.