Skip to content

Commit

Permalink
Added a deleteplayer command to delete the account of a player
Browse files Browse the repository at this point in the history
  • Loading branch information
ad1tya2 committed Jan 20, 2022
1 parent 8c37dc0 commit 26fb2ff
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ad1tya2</groupId>
<artifactId>AdiAuth</artifactId>
<version>1.5</version>
<version>1.6</version>
<packaging>jar</packaging>

<name>AdiAuth</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ad1tya2/adiauth/Bungee/AdiAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public boolean isLoggable(LogRecord record) {
getProxy().getPluginManager().registerCommand(this, new converter());
getProxy().getPluginManager().registerCommand(this, new checkuserdata());
getProxy().getPluginManager().registerCommand(this, new changeplayermode());
getProxy().getPluginManager().registerCommand(this, new deleteplayer());
servers.serversStatusChecker();

}
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/ad1tya2/adiauth/Bungee/commands/deleteplayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ad1tya2.adiauth.Bungee.commands;

import ad1tya2.adiauth.Bungee.UserProfile;
import ad1tya2.adiauth.Bungee.data.storage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

public class deleteplayer extends Command {
public deleteplayer(){
super("deleteplayer", "adiauth.admin", "deleteuser");
}
@Override
public void execute(CommandSender sender, String[] args) {
if(args.length != 1){
sender.sendMessage(ChatColor.YELLOW+"Please use /deleteplayer <username>");
return;
}
String username = args[0];
UserProfile profile = storage.getPlayerMemory(username);
if(profile == null){
sender.sendMessage(ChatColor.YELLOW+"Player dosent exist");
} else {
profile.password = null;
profile.endSession();
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(profile.uuid);
if(p != null){
p.disconnect(ChatColor.RED+"Your Account has been deleted!");
}
storage.deletePlayer(profile);
sender.sendMessage("Successfully deleted "+profile.username);
}
}
}
9 changes: 5 additions & 4 deletions src/main/java/ad1tya2/adiauth/Bungee/commands/unregister.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ad1tya2.adiauth.Bungee.UserProfile;
import ad1tya2.adiauth.Bungee.data.storage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand All @@ -14,22 +15,22 @@ public unregister(){
@Override
public void execute(CommandSender sender, String[] args) {
if(args.length != 1){
sender.sendMessage("&ePlease use /unregister <username>");
sender.sendMessage(ChatColor.YELLOW+"Please use /unregister <username>");
return;
}
String username = args[0];
UserProfile profile = storage.getPlayerMemory(username);
if(profile == null){
sender.sendMessage("&ePlayer dosent exist");
sender.sendMessage(ChatColor.YELLOW+"Player dosent exist");
} else {
profile.password = null;
profile.endSession();
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(profile.uuid);
if(p != null){
p.disconnect("&cYou have been unregistered!");
p.disconnect(ChatColor.RED+"You have been unregistered!");
}
storage.updatePlayer(profile);
sender.sendMessage("&2Successfully unregistered &b"+username);
sender.sendMessage("Successfully unregistered "+username);
}
}
}
39 changes: 39 additions & 0 deletions src/main/java/ad1tya2/adiauth/Bungee/data/storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public static void addAccountToIpList(UserProfile profile){
}
profilesByIp.put(profile.lastIp, profiles);
}

public static void removeAccountFromIpList(UserProfile profile){
if(profile.lastIp == null){
return;
}
List<UserProfile> profiles = profilesByIp.get(profile.lastIp);
if(profiles == null){
profiles = new ArrayList<UserProfile>();
}
profiles.remove(profile);
profilesByIp.put(profile.lastIp, profiles);
}

public static void load(){
try {
tools.log("&eLoading Players...");
Expand Down Expand Up @@ -287,6 +300,32 @@ public static void updatePlayer(UserProfile player){
asyncUserProfileUpdate(player);
}

public static void deletePlayer(UserProfile profile){
if(profile.discordId!=null)
removePlayerFromDiscord(profile.discordId);

pMapByPremiumUuid.remove(profile.premiumUuid);
pMap.remove(profile.username);
removeAccountFromIpList(profile);

AdiAuth.instance.getProxy().getScheduler().runAsync(AdiAuth.instance, new Runnable() {
@Override
public void run() {
try {
Connection conn = database.getConnection();
PreparedStatement stmt = conn.prepareStatement(
"DELETE FROM auth_users WHERE uuid=?");
stmt.setString(1, profile.uuid.toString());
stmt.executeUpdate();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
});
}

public static UserProfile getPlayerByDiscord(String discordId){
return pMapByDiscord.get(discordId);
}
Expand Down

0 comments on commit 26fb2ff

Please sign in to comment.