From 6cc22a3b63f5c4f9c3165258f6defb4b294a7b9a Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 28 Feb 2012 12:16:23 -0800 Subject: [PATCH] mcremove command is now fully functional for MySQL --- src/main/java/com/gmail/nossr50/Users.java | 15 +++++ .../commands/general/AddlevelsCommand.java | 1 - .../commands/general/AddxpCommand.java | 1 - .../commands/general/McstatsCommand.java | 1 - .../commands/general/MmoeditCommand.java | 1 - .../commands/general/WhoisCommand.java | 1 - .../nossr50/commands/mc/McabilityCommand.java | 1 - .../gmail/nossr50/commands/mc/MccCommand.java | 1 - .../nossr50/commands/mc/McgodCommand.java | 1 - .../nossr50/commands/mc/McrefreshCommand.java | 1 - .../nossr50/commands/mc/McremoveCommand.java | 55 +++++++++++++++++-- .../nossr50/commands/party/AcceptCommand.java | 1 - .../nossr50/commands/party/InviteCommand.java | 1 - .../nossr50/commands/party/PartyCommand.java | 1 - .../nossr50/commands/party/PtpCommand.java | 1 - .../nossr50/datatypes/PlayerProfile.java | 4 ++ 16 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/Users.java b/src/main/java/com/gmail/nossr50/Users.java index 2d36024f7..4494b2e6e 100644 --- a/src/main/java/com/gmail/nossr50/Users.java +++ b/src/main/java/com/gmail/nossr50/Users.java @@ -90,6 +90,21 @@ public class Users { players.remove(player); } } + + public static void removeUserByName(String playerName) + { + Player target = null; + for(Player player : players.keySet()) + { + PlayerProfile PP = players.get(player); + if(PP.getPlayerName().equals(playerName)) + { + target = player; + } + } + + players.remove(target); + } public static PlayerProfile getProfile(Player player){ if(players.get(player) != null) diff --git a/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java b/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java index 5144652f1..41a990878 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/AddlevelsCommand.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.skills.Skills; diff --git a/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java b/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java index 46c9dc5fb..53857d8a4 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/AddxpCommand.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.skills.Skills; diff --git a/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java b/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java index 39acfe903..ee8853f0b 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/McstatsCommand.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; diff --git a/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java index c46d61b95..598254484 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.skills.Skills; diff --git a/src/main/java/com/gmail/nossr50/commands/general/WhoisCommand.java b/src/main/java/com/gmail/nossr50/commands/general/WhoisCommand.java index f89be5e8a..6085d9ca0 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/WhoisCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/WhoisCommand.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java index 929f346db..3ca7fbeae 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McabilityCommand.java @@ -8,7 +8,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java index 0fa67b661..b99943df2 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MccCommand.java @@ -7,7 +7,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.locale.mcLocale; public class MccCommand implements CommandExecutor { diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java index 621d54321..50d646493 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McgodCommand.java @@ -8,7 +8,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java index d01861b74..6036c7035 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java index 33a46b073..fe591cd0d 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java @@ -1,11 +1,14 @@ package com.gmail.nossr50.commands.mc; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import com.gmail.nossr50.Users; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.locale.mcLocale; @@ -23,15 +26,11 @@ public class McremoveCommand implements CommandExecutor { player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission")); return true; } - - if (!(sender instanceof Player)) { - sender.sendMessage("This command does not support console useage."); - return true; - } if(args.length == 0) { sender.sendMessage("Correct usage is /mcremove [Player Name]"); + return true; } String playerName = args[0]; //Player that we are going to remove @@ -39,12 +38,58 @@ public class McremoveCommand implements CommandExecutor { //If the server is using MySQL if(LoadProperties.useMySQL) { + int userId = mcMMO.database.GetInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'"); + //Remove user from tables + mcMMO.database.Write("DELETE FROM " + +LoadProperties.MySQLdbName+"." + +LoadProperties.MySQLtablePrefix+"users WHERE " + +LoadProperties.MySQLtablePrefix+"users.id="+userId); + mcMMO.database.Write("DELETE FROM " + +LoadProperties.MySQLdbName+"." + +LoadProperties.MySQLtablePrefix+"cooldowns WHERE " + +LoadProperties.MySQLtablePrefix+"cooldowns.user_id="+userId); + + mcMMO.database.Write("DELETE FROM " + +LoadProperties.MySQLdbName+"." + +LoadProperties.MySQLtablePrefix+"huds WHERE " + +LoadProperties.MySQLtablePrefix+"huds.user_id="+userId); + + mcMMO.database.Write("DELETE FROM " + +LoadProperties.MySQLdbName+"." + +LoadProperties.MySQLtablePrefix+"spawn WHERE " + +LoadProperties.MySQLtablePrefix+"spawn.user_id="+userId); + + mcMMO.database.Write("DELETE FROM " + +LoadProperties.MySQLdbName+"." + +LoadProperties.MySQLtablePrefix+"skills WHERE " + +LoadProperties.MySQLtablePrefix+"skills.user_id="+userId); + + mcMMO.database.Write("DELETE FROM " + +LoadProperties.MySQLdbName+"." + +LoadProperties.MySQLtablePrefix+"experience WHERE " + +LoadProperties.MySQLtablePrefix+"experience.user_id="+userId); + + System.out.println("User "+playerName+" removed from MySQL DB!"); } else { } + if(Bukkit.getServer().getPlayer(playerName) != null) + { + Player targetPlayer = Bukkit.getServer().getPlayer(playerName); + if(targetPlayer.isOnline()) + { + targetPlayer.kickPlayer("[mcMMO] Stats have been reset! Rejoin!"); + Users.removeUserByName(playerName); + } else { + Users.removeUser(targetPlayer); + } + } else { + Users.removeUserByName(playerName); + } + return true; } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/commands/party/AcceptCommand.java b/src/main/java/com/gmail/nossr50/commands/party/AcceptCommand.java index c3b39b9c0..e8d1c8eb2 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/AcceptCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/AcceptCommand.java @@ -8,7 +8,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; diff --git a/src/main/java/com/gmail/nossr50/commands/party/InviteCommand.java b/src/main/java/com/gmail/nossr50/commands/party/InviteCommand.java index b03d8101f..66ce858a9 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/InviteCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/InviteCommand.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java index 90dde6af7..e98bf9291 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; diff --git a/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java index c734eea99..6eaafa1bc 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; -import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index f3d3c9c81..1831572f5 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -1210,4 +1210,8 @@ public class PlayerProfile return null; } } + public String getPlayerName() + { + return playerName; + } }