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

Commit

Permalink
Change -> DebugTool now works for Velocity + time customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Jul 14, 2023
1 parent bacc4ae commit c271139
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NeoProtect
logs/
plugins/
ToDo.md

# User-specific stuff
.idea/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NeoProtectTabCompleter implements Listener {

Expand All @@ -21,34 +22,43 @@ public NeoProtectTabCompleter(NeoProtectPlugin instance) {
public void onTabComplete(TabCompleteEvent event) {

String cursor = event.getCursor().toLowerCase();
String[] cursorSplit = cursor.split(" ");
ArrayList<String> commands = new ArrayList<>();
ArrayList<String> tabListOne = new ArrayList<>();
ArrayList<String> tabListTwo= new ArrayList<>();

commands.add("/np");
commands.add("/neoprotect");
tabListOne.add("setup");

if(instance.getCore().isSetup()){
tabListOne.add("ipanic");
tabListOne.add("debugTool");
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) {
tabListTwo.add(String.valueOf(i));
}
tabListTwo.add("cancel");
}
}

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


@SafeVarargs
public static ArrayList<String> completer(boolean sort, String cursor, ArrayList<String> cmds, ArrayList<String>... tabLists) {
public static ArrayList<String> completer(boolean sort, String cursor, List<String> cmds, List<String>... tabLists) {

ArrayList<String> completions = new ArrayList<>();

int pos = 0;
String[] splitCursor = cursor.split(" ");

for (ArrayList<String> tabList : tabLists) {
for (List<String> tabList : tabLists) {
pos++;

if (sort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public class NeoProtectExecutor {

private static Timer debugTimer = new Timer();
private NeoProtectPlugin instance;
private Localization localization;

Expand Down Expand Up @@ -48,15 +49,15 @@ private void chatEvent(ExecutorBuilder executorBuilder) {

instance.sendMessage(sender, localization.get("apikey.valid"));

gameshieldSelector(sender);
gameshieldSelector();
}

private void command(ExecutorBuilder executorBuilder) {

initials(executorBuilder);

if (args.length == 0) {
showHelp(sender);
showHelp();
return;
}

Expand All @@ -68,17 +69,17 @@ private void command(ExecutorBuilder executorBuilder) {
switch (args[0].toLowerCase()) {

case "setup": {
setup(sender);
setup();
break;
}

case "ipanic": {
iPanic(sender, args);
iPanic(args);
break;
}

case "debugtool": {
debugTool();
debugTool(args);
break;
}

Expand All @@ -89,9 +90,9 @@ private void command(ExecutorBuilder executorBuilder) {

case "setgameshield": {
if (args.length == 1) {
gameshieldSelector(sender);
gameshieldSelector();
} else if (args.length == 2) {
setGameshield(sender, args);
setGameshield(args);
} else {
instance.sendMessage(sender, localization.get("usage.setgameshield"));
}
Expand All @@ -100,29 +101,29 @@ private void command(ExecutorBuilder executorBuilder) {

case "setbackend": {
if (args.length == 1) {
backendSelector(sender);
backendSelector();
} else if (args.length == 2) {
setBackend(sender, args);
setBackend(args);
} else {
instance.sendMessage(sender, localization.get("usage.setbackend"));
}
break;
}
default: {
showHelp(sender);
showHelp();
}
}
}


private void setup(Object sender) {
private void setup() {
instance.getCore().getPlayerInSetup().add(sender);
instance.sendMessage(sender, localization.get("command.setup") + localization.get("utils.click"),
"OPEN_URL", "https://panel.neoprotect.net/profile",
"SHOW_TEXT", localization.get("apikey.find"));
}

private void iPanic(Object sender, String[] args) {
private void iPanic(String[] args) {
if (args.length != 1) {
instance.sendMessage(sender, localization.get("usage.ipanic"));
} else {
Expand Down Expand Up @@ -166,16 +167,25 @@ private void analytics() {
}

@SuppressWarnings("ResultOfMethodCallIgnored")
private void debugTool() {
private void debugTool(String[] args) {

if (instance.getPluginType() == NeoProtectPlugin.PluginType.SPIGOT) {
instance.sendMessage(sender, localization.get("debug.spigot"));
return;
}

if (instance.getPluginType() == NeoProtectPlugin.PluginType.VELOCITY) {
instance.sendMessage(sender, "This command is currently not yet supported for Velocity");
return;
if (args.length == 2) {
if(args[1].equals("cancel")){
debugTimer.cancel();
instance.getCore().setDebugRunning(false);
instance.sendMessage(sender, "Debug tool stopped");
return;
}

if (!isInteger(args[1])) {
instance.sendMessage(sender, localization.get("usage.debug"));
return;
}
}

if (instance.getCore().isDebugRunning()) {
Expand All @@ -186,19 +196,22 @@ private void debugTool() {
instance.getCore().setDebugRunning(true);
instance.sendMessage(sender, localization.get("debug.starting"));

new Timer().schedule(new TimerTask() {
int amount = args.length == 2 ? (Integer.parseInt(args[1]) <= 0 ? 1 : Integer.parseInt(args[1])) : 5;

debugTimer = new Timer();

debugTimer.schedule(new TimerTask() {
int counter = 0;
@Override
public void run() {
counter++;
instance.getCore().getTimestampsMap().put(instance.sendKeepAliveMessage(new Random().nextInt(90) * 10000 + 1337), new Timestamp(System.currentTimeMillis()));
instance.sendMessage(sender, localization.get("debug.sendingPackets") + " (" + counter + "/5)");
if(counter >= 5)this.cancel();
instance.sendMessage(sender, localization.get("debug.sendingPackets") + " (" + counter + "/" + amount + ")");
if(counter >= amount) this.cancel();
}
},500, 2000);


new Timer().schedule(new TimerTask() {
debugTimer.schedule(new TimerTask() {
@Override
public void run() {
instance.getCore().getExecutorService().submit(() -> {
Expand Down Expand Up @@ -282,10 +295,10 @@ public void run() {
}
});
}
}, 2000 * 4 + 2500);
}, 2000L * (amount - 1) + 2500);
}

private void gameshieldSelector(Object sender) {
private void gameshieldSelector() {
instance.sendMessage(sender, localization.get("select.gameshield"));

List<Gameshield> gameshieldList = instance.getCore().getRestAPI().getGameshields();
Expand All @@ -297,7 +310,7 @@ private void gameshieldSelector(Object sender) {
}
}

private void setGameshield(Object sender, String[] args) {
private void setGameshield(String[] args) {

if (instance.getCore().getRestAPI().isGameshieldInvalid(args[1])) {
instance.sendMessage(sender, localization.get("invalid.gameshield", args[1]));
Expand All @@ -307,11 +320,11 @@ private void setGameshield(Object sender, String[] args) {
Config.setGameShieldID(args[1]);
instance.sendMessage(sender, localization.get("set.gameshield", args[1]));

backendSelector(sender);
backendSelector();
}


private void backendSelector(Object sender) {
private void backendSelector() {
instance.sendMessage(sender, localization.get("select.backend"));

List<Backend> backendList = instance.getCore().getRestAPI().getBackends();
Expand All @@ -323,7 +336,7 @@ private void backendSelector(Object sender) {
}
}

private void setBackend(Object sender, String[] args) {
private void setBackend(String[] args) {

if (instance.getCore().getRestAPI().isBackendInvalid(args[1])) {
instance.sendMessage(sender, localization.get("invalid.backend", args[1]));
Expand All @@ -340,12 +353,12 @@ private void setBackend(Object sender, String[] args) {
instance.getCore().getRestAPI().testCredentials();
}

private void showHelp(Object sender) {
private void showHelp() {
instance.sendMessage(sender, localization.get("available.commands"));
instance.sendMessage(sender, " - /np setup");
instance.sendMessage(sender, " - /np ipanic");
instance.sendMessage(sender, " - /np analytics");
instance.sendMessage(sender, " - /np debugTool");
instance.sendMessage(sender, " - /np debugTool (cancel / amount)");
instance.sendMessage(sender, " - /np setgameshield");
instance.sendMessage(sender, " - /np setbackend");
}
Expand Down Expand Up @@ -400,4 +413,13 @@ public String getMsg() {
return msg;
}
}

public static boolean isInteger(String input) {
try {
Integer.parseInt(input);
return true;
} catch (NumberFormatException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import de.cubeattack.neoprotect.core.Core;
import de.cubeattack.neoprotect.core.NeoProtectPlugin;
import de.cubeattack.neoprotect.core.Permission;
Expand Down Expand Up @@ -76,6 +78,9 @@ public void sendAdminMessage(Permission permission, String text, String clickAct
@Override
public void sendKeepAliveMessage(Object receiver, long id) {
if(receiver instanceof Player){
KeepAlive keepAlive = new KeepAlive();
keepAlive.setRandomId(id);
((ConnectedPlayer)receiver).getConnection().getChannel().writeAndFlush(keepAlive);
getCore().getPingMap().put(new KeepAliveResponseKey(((Player) receiver).getRemoteAddress(), id), System.currentTimeMillis());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
List<String> completorList = new ArrayList<>();
String[] args = invocation.arguments();


if (args.length == 2) {
System.out.println(args[0]);
if(args[0].equalsIgnoreCase("debugtool")){
for (int i = 10; i <= 100; i = i + 10) {
completorList.add(String.valueOf(i));
}
completorList.add("cancel");
}
return completorList;
}

if (args.length > 1) {
return completorList;
}
Expand Down
Loading

0 comments on commit c271139

Please sign in to comment.