Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Changes -> Added /np toggle command
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Jul 15, 2023
1 parent e879bc3 commit 427df9c
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,32 @@ public void onTabComplete(TabCompleteEvent event) {

if(instance.getCore().isSetup()){
tabListOne.add("ipanic");
tabListOne.add("toggle");
tabListOne.add("debugtool");
tabListOne.add("analytics");
tabListOne.add("setgameshield");
tabListOne.add("setbackend");

if (cursorSplit.length >= 2 && cursorSplit[1].equalsIgnoreCase("debugTool")) {
for (int i = 10; i <= 100; i = i + 10) {
for (int i = 10; i <= 90; i = i + 10) {
tabListTwo.add(String.valueOf(i));
}
tabListTwo.add("cancel");
}

if (cursorSplit.length >= 2 && cursorSplit[1].equalsIgnoreCase("toggle")) {
tabListTwo.add("antiVPN");
tabListTwo.add("anycast");
tabListTwo.add("motdCache");
tabListTwo.add("blockForge");
tabListTwo.add("ipWhitelist");
tabListTwo.add("ipBlacklist");
tabListTwo.add("secureProfiles");
tabListTwo.add("advancedAntiBot");
}
}

event.getSuggestions().addAll(completer(false, cursor, commands, tabListOne, tabListTwo));
event.getSuggestions().addAll(completer(true, cursor, commands, tabListOne, tabListTwo));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ private void command(ExecutorBuilder executorBuilder) {
break;
}

case "toggle": {
toggle(args);
break;
}

case "debugtool": {
debugTool(args);
break;
Expand Down Expand Up @@ -132,6 +137,27 @@ private void iPanic(String[] args) {
}
}

private void toggle(String[] args) {
if (args.length != 2) {
instance.sendMessage(sender, localization.get("usage.toggle"));
} else {
int response = instance.getCore().getRestAPI().toggle(args[1]);

if(response == 403){
instance.sendMessage(sender, localization.get("err.upgrade-plan"));
return;
}

if(response == 429){
instance.sendMessage(sender, localization.get("err.rate-limit"));
return;
}

instance.sendMessage(sender, localization.get("command.toggle", args[1],
localization.get(response == 1 ? "utils.activated" : "utils.deactivated")));
}
}

private void analytics() {
instance.sendMessage(sender, "§7§l-------- §bAnalytics §7§l--------");
JSONObject analytics = instance.getCore().getRestAPI().getAnalytics();
Expand Down Expand Up @@ -178,7 +204,7 @@ private void debugTool(String[] args) {
if(args[1].equals("cancel")){
debugTimer.cancel();
instance.getCore().setDebugRunning(false);
instance.sendMessage(sender, "Debug tool stopped");
instance.sendMessage(sender, localization.get("debug.cancelled"));
return;
}

Expand Down Expand Up @@ -360,6 +386,7 @@ private void showHelp() {
instance.sendMessage(sender, " - /np setup");
instance.sendMessage(sender, " - /np ipanic");
instance.sendMessage(sender, " - /np analytics");
instance.sendMessage(sender, " - /np toggle (option)");
instance.sendMessage(sender, " - /np debugTool (cancel / amount)");
instance.sendMessage(sender, " - /np setgameshield");
instance.sendMessage(sender, " - /np setbackend");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean checkCode(int code){
return Objects.equals(this.code, code);
}

private int getCode(){
public int getCode(){
try{
return response.code();
}catch (Exception ex){
Expand All @@ -57,7 +57,7 @@ public JSONObject getResponseBodyObject() {
public JSONArray getResponseBodyArray() {
try {
return new JSONArray(responseBody);
}catch (JSONException ignored){}
} catch (JSONException ignored){}
return new JSONArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ public boolean togglePanicMode(){
}
}

public int toggle(String mode){
JSONObject settings = rest.request(RequestType.GET_GAMESHIELD_INFO, null, Config.getGameShieldID()).getResponseBodyObject().getJSONObject("gameShieldSettings");
boolean mitigationSensitivity = settings.getBoolean(mode);

if(mitigationSensitivity){
int code = rest.request(RequestType.POST_GAMESHIELD_UPDATE,
RequestBody.create(MediaType.parse("application/json"), settings.put(mode, false).toString()),
Config.getGameShieldID()).getCode();

return code == 200 ? 0 : code;
}else {
int code = rest.request(RequestType.POST_GAMESHIELD_UPDATE,
RequestBody.create(MediaType.parse("application/json"), settings.put(mode, true).toString()),
Config.getGameShieldID()).getCode();

return code == 200 ? 1 : code;
}
}

public List<Gameshield> getGameshields(){
List<Gameshield> list = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
List<String> list = new ArrayList<>();
List<String> completorList = new ArrayList<>();

if (args.length == 2 && args[0].equalsIgnoreCase("toggle")) {
completorList.add("antiVPN");
completorList.add("anycast");
completorList.add("motdCache");
completorList.add("blockForge");
completorList.add("ipWhitelist");
completorList.add("ipBlacklist");
completorList.add("secureProfiles");
completorList.add("advancedAntiBot");
return completorList;
}

if (args.length != 1) {
return completorList;
}
Expand All @@ -30,6 +42,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman

if(instance.getCore().isSetup()){
list.add("ipanic");
list.add("toggle");
list.add("analytics");
list.add("setgameshield");
list.add("setbackend");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,21 @@ public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
}
completorList.add("cancel");
}
if (args[0].equalsIgnoreCase("toggle")) {
completorList.add("antiVPN");
completorList.add("anycast");
completorList.add("motdCache");
completorList.add("blockForge");
completorList.add("ipWhitelist");
completorList.add("ipBlacklist");
completorList.add("secureProfiles");
completorList.add("advancedAntiBot");
}
return completorList;
}



if (args.length > 1) {
return completorList;
}
Expand All @@ -71,6 +83,7 @@ public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
list.add("analytics");
list.add("debugTool");
list.add("ipanic");
list.add("toggle");
}

for (String tab : list) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/language_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ available.commands=Verfügbare Befehle:
console.command=Sie können diesen Befehl nicht über die Konsole ausführen. Bitte führe diesen Befehl in-game aus.
command.setup=Geben Sie nun den API-KEY im Chat ein
command.ipanic=Der Panikmodus wurde {0}
command.toggle={0} wurde {1}

usage.debug=Bitte geben Sie /np debugTool (cancel / zahl) ein
usage.ipanic=Bitte geben Sie /np ipanic ein
usage.toggle=Bitte geben Sie /np toggle (Option) ein
usage.setbackend=Bitte geben Sie /np setbackend ein
usage.setgameshield=Bitte geben Sie /np setgameshield ein

Expand All @@ -36,8 +38,12 @@ utils.deactivated=§cdeaktiviert

plugin.outdated.message=§cDas Plugin {0} ist veraltet, bitte downloade die aktuelle Version {1}
debug.spigot=Dieser Befehl ist nur für Proxy-Server verfügbar
debug.running=§cDebug-Tool läuft aktuell bereits
debug.starting=§aDebug-Tool wird gestartet...
debug.running=§cDebug-Tool läuft aktuell bereits
debug.cancelled=§cDebug-Tool wurde abgebrochen
debug.sendingPackets=§aSenden von KeepAlivePackets
debug.finished.first=§aDebug-Datei wurde erstellt
debug.finished.second=§aDie Datei finden Sie hier -> §7

err.upgrade-plan=§cBitte upgrade deinen Plan um dieses Feature nutzen zu können
err.rate-limit=§cBitte wartet bevor du diesen command erneut benutzt
8 changes: 7 additions & 1 deletion src/main/resources/language_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ available.commands=Available commands:
console.command=You cannot execute this command via the console. Please run this command in-game.
command.setup=Now enter the API-KEY in the Chat
command.ipanic=Panic mode has been {0}
command.toggle={0} has been {1}

usage.debug=Please type /np debugTool (cancel / amount)
usage.ipanic=Please type /np ipanic
usage.toggle=Please type /np toggle (option)
usage.setbackend=Please type /np setbackend
usage.setgameshield=Please enter /np setgameshield

Expand All @@ -36,8 +38,12 @@ utils.deactivated=§cdeactivated

plugin.outdated.message=§cThe plugin {0} is outdated, please download the latest version {1}
debug.spigot=This command is only available for proxy-server
debug.running=§cDebug tool is progressing right now
debug.starting=§aStarting debug tool...
debug.running=§cDebug tool is progressing right now
debug.cancelled=§cDebug tool has been cancelled
debug.sendingPackets=§aSending KeepAlivePackets
debug.finished.first=§aDebug file has been created
debug.finished.second=§aFile can be found here -> §7

err.upgrade-plan=§cPlease upgrade your plan to use this feature
err.rate-limit=§cPlease wait before using this command again

0 comments on commit 427df9c

Please sign in to comment.