Page 1 of 1

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

Posted: Sat Aug 25, 2012 11:40 am
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 :)

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

Posted: Sun Aug 26, 2012 9:32 pm
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.