mcremove command is now fully functional for MySQL

This commit is contained in:
nossr50 2012-02-28 12:16:23 -08:00
parent 649ce1c147
commit 6cc22a3b63
16 changed files with 69 additions and 18 deletions

View File

@ -90,6 +90,21 @@ public class Users {
players.remove(player); 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){ public static PlayerProfile getProfile(Player player){
if(players.get(player) != null) if(players.get(player) != null)

View File

@ -10,7 +10,6 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;

View File

@ -10,7 +10,6 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;

View File

@ -10,7 +10,6 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;

View File

@ -10,7 +10,6 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;

View File

@ -10,7 +10,6 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;

View File

@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;

View File

@ -7,7 +7,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class MccCommand implements CommandExecutor { public class MccCommand implements CommandExecutor {

View File

@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;

View File

@ -1,11 +1,14 @@
package com.gmail.nossr50.commands.mc; package com.gmail.nossr50.commands.mc;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.locale.mcLocale; 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")); player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission"));
return true; return true;
} }
if (!(sender instanceof Player)) {
sender.sendMessage("This command does not support console useage.");
return true;
}
if(args.length == 0) if(args.length == 0)
{ {
sender.sendMessage("Correct usage is /mcremove [Player Name]"); sender.sendMessage("Correct usage is /mcremove [Player Name]");
return true;
} }
String playerName = args[0]; //Player that we are going to remove 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 the server is using MySQL
if(LoadProperties.useMySQL) 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 { } 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; return true;
} }
} }

View File

@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;

View File

@ -1210,4 +1210,8 @@ public class PlayerProfile
return null; return null;
} }
} }
public String getPlayerName()
{
return playerName;
}
} }