[JAVA][BUKKIT] Execute MySQL queries on a command

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

[JAVA][BUKKIT] Execute MySQL queries on a command

Post by Helx »

Hi :)

I want to take advantage of the new MineBans 'execute on ban' thing. What I want to do is have a plugin that would alter an external DataBase to set a MySQL column to '1', without lagging the server. I know how to set up the structure of a plugin, and a tiny bit about entering information into MySQL. What I would like to know is how to set up the command, and how to set up config files... Oh and how to use permissions :)

The kind of command that I'm looking to do is: /mysql UPDATE `test` SET `banned`=1 WHERE `username`=%player_name%

The %player_name% would be filled out by MineBans :)

Oh, and don't worry about how the usernames would get into the DB in the first place, I already have that sorted out.

So... Could anyone help me out ? Sadly I have hardly touched base with Java, but I'm willing to learn :D

And if its just too long to help me in these amazing forums, I will make a tutorials suggestion, and see if anyone else upvotes it :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [JAVA][BUKKIT] Execute MySQL queries on a command

Post by jacek »

Well you can use the ban event that MineBans provides instead of the command thing
public void onPlayerBan(PlayerBanEvent event){
    String sql = "UPDATE `test` SET `banned` = 1 WHERE `username` = '" + event.getPlayerName() + "';
}
That should be all you need but there is also event.getType() which is either BanType.TEMP, BanType.LOCAL or BanType.GLOBAL, you may want to exclude temp bans for example.
Image
Post Reply