-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a debug command and some logging to the RC anchors reloading #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.mitchej123.hodgepodge.core.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.util.ChatComponentText; | ||
|
||
import com.mitchej123.hodgepodge.core.util.AnchorAlarm; | ||
|
||
public class DebugCommand extends CommandBase { | ||
@Override | ||
public String getCommandName() { | ||
return "hp"; | ||
} | ||
|
||
@Override | ||
public String getCommandUsage(ICommandSender sender) { | ||
return "Usage: hp <subcommand>. Valid subcommands are: toggle, anchor."; | ||
} | ||
private void printHelp(ICommandSender sender) { | ||
sender.addChatMessage(new ChatComponentText("Usage: hp <toggle|anchor>")); | ||
sender.addChatMessage(new ChatComponentText("\"toggle anchordebug\" - toggles RC anchor debugging")); | ||
sender.addChatMessage(new ChatComponentText("\"anchor list <player>\" - list RC anchors placed by the player (empty for current player)")); | ||
} | ||
@Override | ||
public List addTabCompletionOptions(ICommandSender sender, String[] ss) { | ||
List<String> l = new ArrayList<>(); | ||
String test = ss.length == 0 ? "" : ss[0].trim(); | ||
if (ss.length == 0 || ss.length == 1 && (test.isEmpty() || Stream.of("toggle", "anchor").anyMatch(s -> s.startsWith(test)))) { | ||
Stream.of("toggle", "anchor") | ||
.filter(s -> test.isEmpty() || s.startsWith(test)) | ||
.forEach(l::add); | ||
} else if (test.equals("toggle")) { | ||
String test1 = ss[1].trim(); | ||
if (test1.isEmpty() || "anchordebug".startsWith(test1)) | ||
l.add("anchordebug"); | ||
} else if (test.equals("anchor")) { | ||
String test1 = ss[1].trim(); | ||
if (test1.isEmpty() || "list".startsWith(test1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a check for situation, where admin types FYI use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
l.add("list"); | ||
} | ||
return l; | ||
} | ||
@Override | ||
public void processCommand(ICommandSender sender, String[] strings) { | ||
if (strings.length < 1) { | ||
printHelp(sender); | ||
return; | ||
} | ||
switch (strings[0]) { | ||
case "toggle": | ||
if (strings.length < 2 || !strings[1].equals("anchordebug")) { | ||
printHelp(sender); | ||
return; | ||
} | ||
AnchorAlarm.AnchorDebug = !AnchorAlarm.AnchorDebug; | ||
sender.addChatMessage(new ChatComponentText("Anchor debugging: " + AnchorAlarm.AnchorDebug)); | ||
break; | ||
case "anchor": | ||
if (strings.length < 2 || !strings[1].equals("list")) { | ||
printHelp(sender); | ||
return; | ||
} | ||
String playerName = strings.length > 2 ? strings[2] : sender.getCommandSenderName(); | ||
if (!AnchorAlarm.listSavedAnchors(playerName, sender.getEntityWorld())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getAllUsernames literally calls serverConfigurationManager |
||
sender.addChatMessage(new ChatComponentText("No such player entity in the current world : " + playerName)); | ||
else | ||
sender.addChatMessage(new ChatComponentText("Saved anchors dumped to the log for player: " + playerName)); | ||
break; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could have been
"\"anchor list [player]\" - list RC anchors placed by the player (empty for current player)"