forked from Oliver-makes-code/bta-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a featutes for connecting minecraft/discord accounts (probably …
…not working yet)
- Loading branch information
1 parent
1941562
commit 1ca1ec2
Showing
4 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/de/olivermakesco/bta_utils/core/PlayerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.olivermakesco.bta_utils.core; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
|
||
import com.badlogic.gdx.utils.Array; | ||
|
||
public class PlayerManager { | ||
ArrayList<Player> players = new ArrayList<Player>(); | ||
public PlayerManager() { | ||
init(); | ||
} | ||
|
||
public void init() { | ||
File files[] = DataManager.findFilesWithNameRecursively("perPlayer", "data"); | ||
for (File file : files) { | ||
Player player = new Player(file); | ||
players.add(player); | ||
} | ||
} | ||
|
||
} | ||
//Create new class Player containing username, isConnected and discordID | ||
class Player { | ||
public String username; | ||
public boolean isConnected; | ||
public String discordID; | ||
File file; | ||
public Player(String username, boolean isConnected, String discordID) { | ||
this.username = username; | ||
this.isConnected = isConnected; | ||
this.discordID = discordID; | ||
} | ||
public Player(File file) { | ||
this.file = file; | ||
this.username = DataManager.getString(file, "username"); | ||
this.isConnected = stringToBoolean(DataManager.getString(file, "connected")); | ||
this.discordID = DataManager.getString(file, "discordID"); | ||
} | ||
|
||
|
||
boolean stringToBoolean(String s) { | ||
return s.equals("true"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/de/olivermakesco/bta_utils/server/MinecraftDDisconnect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package de.olivermakesco.bta_utils.server; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import de.olivermakesco.bta_utils.core.DataManager; | ||
import net.minecraft.core.net.command.CommandHandler; | ||
import net.minecraft.core.net.command.CommandSender; | ||
import net.minecraft.core.net.command.ServerCommand; | ||
import net.minecraft.server.MinecraftServer; | ||
|
||
public class MinecraftDDisconnect extends ServerCommand { | ||
|
||
public MinecraftDDisconnect(MinecraftServer server) { | ||
super(server, "mdunpair", new String[0]); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { | ||
String username = sender.getPlayer().username; | ||
if (username.contains(".") || username.contains(";") || username.contains("/") || username.contains("\\")) { | ||
sender.sendMessage( | ||
"Did you know your username is Illegal? Yes, we are not wrong, the only characters you can use in Minecraft username are: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ so first change your username to normal, then try again."); | ||
return true; | ||
} | ||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
//if there one argument in args and ""confirm".equals(args[0])" | ||
if (args.length == 1 && "confirm".equals(args[0])) { | ||
executor.submit(() -> { | ||
try { | ||
File[] files = DataManager.findFilesWithNameRecursively("perPlayer", "data"); | ||
for (int i = 0; i < files.length; i++) { | ||
if (username.equals(DataManager.getString(files[i], "username"))) { | ||
if ("false".equals(DataManager.getString(files[i], "connected"))) { | ||
sender.sendMessage("this account is not paired with any Discord accounts!"); | ||
return false; | ||
} | ||
DataManager.setString(files[i], "connected", "false"); | ||
sender.sendMessage("Accounts unpaired!"); | ||
return false; | ||
} | ||
} | ||
} catch (Exception e) { | ||
sender.sendMessage("Error while initiating the connection."); | ||
} | ||
return false; | ||
}); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean opRequired(String[] var1) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { | ||
sender.sendMessage("/mdunpair confirm"); | ||
} | ||
} |