Skip to content

Instantly share code, notes, and snippets.

@securitygab
Created August 3, 2019 10:54
Show Gist options
  • Save securitygab/2e46ff9adb344989433491ac9c8c6948 to your computer and use it in GitHub Desktop.
Save securitygab/2e46ff9adb344989433491ac9c8c6948 to your computer and use it in GitHub Desktop.
Tutorial for Tyler.
Created by @KuroiSH
##Getting the banlist.##
There are two banlists that you can choose from: the Name banlist and the IP banlist.
The Name banlist will ban a user with a specific name. To get this banlist, you would use as next:
_> Bukkit.getBanList(Banlist.Type.NAME)
_> Bukkit.getBanList(Banlist.Type.IP)
Understand, this meant for getting the IP banlist, all you need to do is change "NAME" to "IP".
After you set up the banlist, you will need to use the "addBan" method to ban the player or IP.
The parameters for the method are "String [target], String [reason], Date [expires], String [source]".
[Target] Can either be the player's name or the player's IP.
[Reason] Is the message that will be displayed if they try to join the server while they are banned.
[Expires] Is the date the ban will be lifted. Set this to null if you want the player to be permanently banned.
[Source] Is the source of the ban. You can set this to null.
Here are some examples that I made for you Tyler, of how you can use it;
This will permanently ban the player, displaying the message "you were hacking" if they try to join the server:
//IP Tyler
BanList#addBan(target.getAddress().getHostName(),"You typed the wrong authentication", null, null);
//NAME TYLER
BanList#addBan(target.getName(),"Sorry, but you typed the wrong authentication", null, null);
If you want to temperately ban the player, you will have to create a new date object. For example,
if you wanted to ban the player for one hour, you would use the following date object instead:
Date date = new Date(System.currentTimeMillis()+60*60*1000);
//Tyler, and get this in your mind.
// Since there are 1000 miliseconds in one second, 60 seconds in one minute, and 60 minutes in an hour,
by adding 60*60*1000 to the current time,you are adding an hour to the bantime.
There are many ways to create the date object, but for this example we are using milliseconds to add an hour to ban time.
If you wanted to re-add this to the addBan method above, and making a bit code for u:
BanList#addBan(target,"The authentication is wrong",new Date(System.currentTimeMillis()+60*60*1000), null);
##Important Note:##
This will only ban the player, and will not kick them off the server.
If you want to kick the player off the server, use the following line Tyler:
player.kickPlayer("Reason");
And optimize this with your CODE LINE:
Where you will replace "reason" with the message you display to the player once they have been kicked.
It may be best to use the same message you use above.
Custom Ban reason.
The default ban message may not be what you want.
If you want to create your own custom ban message, you will need to create a "Bumper" to push the old ban reason off the screen.
For most screens, the following bumper should move the default message off the screen.
String bumper = org.apache.commons.lang.StringUtils.repeat("\n", 35);
After creating this object, you can add this before and after your custom reason in order to move the default message of the screen.
An example of this would be, to write again a line bit code for u, understand this is not a full code that I am writing but teaching u how todo it.
BanList#addBan(target.getName(),bumper+"You where hacking!"+bumper, null, null);
Example:
For the people who would want to see how to, as the title says, ban a player using just one line, this would be it:
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), org.apache.commons.lang.StringUtils.repeat("\n", 35)+" You have been banned by "+sender.getName()+" \nFor one hour"+org.apache.commons.lang.StringUtils.repeat("\n", 35)",new Date(System.currentTimeMillis()+60*60*1000),null);
What this will do is ban the player for one hour, and display the a custom ban message to the player.
And if u have a question about UUID safe.
It should UUID safe, You have to provide the player's name if you want to ban them. The UUID is stored along with the rest of the ban data, so it should be used
##(though you would need to look at the source code/test it if you want to be sure).##
And if you want to use essentials pardon methodd:
Bukkit.getBanList(BanList.Type.NAME).pardon(target);
I'd rather also for using MySQL, understand that using my mySQl will still get the same ban-files.
- Regards
Securitygab (KuroiSH#0001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment