mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-03 18:43:43 +01:00 
			
		
		
		
	This is a much better way to delete things.
This commit is contained in:
		@@ -60,31 +60,7 @@ public class McremoveCommand implements CommandExecutor {
 | 
				
			|||||||
            userId = database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
 | 
					            userId = database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (userId > 0) {
 | 
					            if (userId > 0) {
 | 
				
			||||||
                database.write("DELETE FROM "
 | 
					                database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userId);
 | 
				
			||||||
                        + databaseName + "."
 | 
					 | 
				
			||||||
                        + tablePrefix + "users WHERE "
 | 
					 | 
				
			||||||
                        + tablePrefix + "users.id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                        + databaseName + "."
 | 
					 | 
				
			||||||
                        + tablePrefix + "cooldowns WHERE "
 | 
					 | 
				
			||||||
                        + tablePrefix + "cooldowns.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                        + databaseName + "."
 | 
					 | 
				
			||||||
                        + tablePrefix + "huds WHERE "
 | 
					 | 
				
			||||||
                        + tablePrefix + "huds.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                        + databaseName + "."
 | 
					 | 
				
			||||||
                        + tablePrefix + "skills WHERE "
 | 
					 | 
				
			||||||
                        + tablePrefix + "skills.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                        + databaseName + "."
 | 
					 | 
				
			||||||
                        + tablePrefix + "experience WHERE "
 | 
					 | 
				
			||||||
                        + tablePrefix + "experience.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                sender.sendMessage(success);
 | 
					                sender.sendMessage(success);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,7 +57,9 @@ public class UserPurgeTask implements Runnable {
 | 
				
			|||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            deleteFromSQL(userId, playerName);
 | 
					            database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userId);
 | 
				
			||||||
 | 
					            profileCleanup(playerName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            purgedUsers++;
 | 
					            purgedUsers++;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -84,31 +86,7 @@ public class UserPurgeTask implements Runnable {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        HashMap<Integer, ArrayList<String>> usernames = database.read("SELECT user FROM " + tablePrefix + "users WHERE id IN " + userIdString);
 | 
					        HashMap<Integer, ArrayList<String>> usernames = database.read("SELECT user FROM " + tablePrefix + "users WHERE id IN " + userIdString);
 | 
				
			||||||
 | 
					        database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userIdString);
 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "users WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "users.id IN " + userIdString);
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "cooldowns WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "cooldowns.user_id IN " + userIdString);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "huds WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "huds.user_id IN " + userIdString);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "skills WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "skills.user_id IN " + userIdString);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "experience WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "experience.user_id IN " + userIdString);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = 1; i <= usernames.size(); i++) {
 | 
					        for (int i = 1; i <= usernames.size(); i++) {
 | 
				
			||||||
            String playerName = usernames.get(i).get(0);
 | 
					            String playerName = usernames.get(i).get(0);
 | 
				
			||||||
@@ -141,7 +119,9 @@ public class UserPurgeTask implements Runnable {
 | 
				
			|||||||
            long loginDifference = currentTime - lastLoginTime;
 | 
					            long loginDifference = currentTime - lastLoginTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (loginDifference > 2630000000L) {
 | 
					            if (loginDifference > 2630000000L) {
 | 
				
			||||||
                deleteFromSQL(userId, playerName);
 | 
					                database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userId);
 | 
				
			||||||
 | 
					                profileCleanup(playerName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                purgedUsers++;
 | 
					                purgedUsers++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -149,35 +129,6 @@ public class UserPurgeTask implements Runnable {
 | 
				
			|||||||
        plugin.getLogger().info("Purged " + purgedUsers + " users from the database.");
 | 
					        plugin.getLogger().info("Purged " + purgedUsers + " users from the database.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void deleteFromSQL(int userId, String playerName) {
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "users WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "users.id=" + userId);
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "cooldowns WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "cooldowns.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "huds WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "huds.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "skills WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "skills.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        database.write("DELETE FROM "
 | 
					 | 
				
			||||||
                + databaseName + "."
 | 
					 | 
				
			||||||
                + tablePrefix + "experience WHERE "
 | 
					 | 
				
			||||||
                + tablePrefix + "experience.user_id=" + userId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        profileCleanup(playerName);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void profileCleanup(String playerName) {
 | 
					    private void profileCleanup(String playerName) {
 | 
				
			||||||
        McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName);
 | 
					        McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,15 +77,20 @@ public class Database {
 | 
				
			|||||||
     * Attempt to create the database structure.
 | 
					     * Attempt to create the database structure.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void createStructure() {
 | 
					    public void createStructure() {
 | 
				
			||||||
        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` (`user_id` int(10) unsigned NOT NULL,"
 | 
					        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` ("
 | 
				
			||||||
                + "`hudtype` varchar(50) NOT NULL DEFAULT 'STANDARD',"
 | 
					                + "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
 | 
				
			||||||
                + "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
					 | 
				
			||||||
        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
 | 
					 | 
				
			||||||
                + "`user` varchar(40) NOT NULL,"
 | 
					                + "`user` varchar(40) NOT NULL,"
 | 
				
			||||||
                + "`lastlogin` int(32) unsigned NOT NULL,"
 | 
					                + "`lastlogin` int(32) unsigned NOT NULL,"
 | 
				
			||||||
                + "PRIMARY KEY (`id`),"
 | 
					                + "PRIMARY KEY (`id`),"
 | 
				
			||||||
                + "UNIQUE KEY `user` (`user`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
 | 
					                + "UNIQUE KEY `user` (`user`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
 | 
				
			||||||
        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "cooldowns` (`user_id` int(10) unsigned NOT NULL,"
 | 
					        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` ("
 | 
				
			||||||
 | 
					                + "`user_id` int(10) unsigned NOT NULL,"
 | 
				
			||||||
 | 
					                + "`hudtype` varchar(50) NOT NULL DEFAULT 'STANDARD',"
 | 
				
			||||||
 | 
					                + "PRIMARY KEY (`user_id`)"
 | 
				
			||||||
 | 
					                + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)"
 | 
				
			||||||
 | 
					                + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
				
			||||||
 | 
					        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "cooldowns` ("
 | 
				
			||||||
 | 
					                + "`user_id` int(10) unsigned NOT NULL,"
 | 
				
			||||||
                + "`taming` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`taming` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`mining` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`mining` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`woodcutting` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`woodcutting` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
@@ -98,8 +103,11 @@ public class Database {
 | 
				
			|||||||
                + "`axes` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`axes` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
					                + "PRIMARY KEY (`user_id`)"
 | 
				
			||||||
        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` (`user_id` int(10) unsigned NOT NULL,"
 | 
					                + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)"
 | 
				
			||||||
 | 
					                + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
				
			||||||
 | 
					        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` ("
 | 
				
			||||||
 | 
					                + "`user_id` int(10) unsigned NOT NULL,"
 | 
				
			||||||
                + "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
@@ -111,8 +119,11 @@ public class Database {
 | 
				
			|||||||
                + "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
					                + "PRIMARY KEY (`user_id`)"
 | 
				
			||||||
        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "experience` (`user_id` int(10) unsigned NOT NULL,"
 | 
					                + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)"
 | 
				
			||||||
 | 
					                + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
				
			||||||
 | 
					        write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "experience` ("
 | 
				
			||||||
 | 
					                + "`user_id` int(10) unsigned NOT NULL,"
 | 
				
			||||||
                + "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
@@ -124,7 +135,9 @@ public class Database {
 | 
				
			|||||||
                + "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
					                + "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
 | 
				
			||||||
                + "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
					                + "PRIMARY KEY (`user_id`)"
 | 
				
			||||||
 | 
					                + "FOREIGN KEY (`user_id`) REFERENCES `" + tablePrefix + "users`)"
 | 
				
			||||||
 | 
					                + "ON DELETE CASCADE) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        checkDatabaseStructure(DatabaseUpdate.FISHING);
 | 
					        checkDatabaseStructure(DatabaseUpdate.FISHING);
 | 
				
			||||||
        checkDatabaseStructure(DatabaseUpdate.BLAST_MINING);
 | 
					        checkDatabaseStructure(DatabaseUpdate.BLAST_MINING);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user