Skip to content
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 ping command #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public void onEnable() {
this.getProxy().getCommandMap().registerCommand(new ServerPingCommand());
this.getProxy().getCommandMap().registerCommand(new AddServerCommand());
this.getProxy().getCommandMap().registerCommand(new RemoveServerCommand());
this.getProxy().getCommandMap().registerCommand(new PingCommand());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.waterdog.plugins.commands.commands;

import dev.waterdog.waterdogpe.ProxyServer;
import dev.waterdog.waterdogpe.command.Command;
import dev.waterdog.waterdogpe.command.CommandSender;
import dev.waterdog.waterdogpe.command.CommandSettings;
import dev.waterdog.waterdogpe.network.serverinfo.BedrockServerInfo;
import dev.waterdog.waterdogpe.player.ProxiedPlayer;

import java.net.InetSocketAddress;

public class PingCommand extends Command {

public PingCommand() {
super("ping", CommandSettings.builder()
.setDescription("See the current ping of a player")
.setUsageMessage("ping (name)")
.setPermission("waterdog.example.ping").build());
}

@Override
public boolean onExecute(CommandSender sender, String alias, String[] args) {
if (sender instanceof ProxiedPlayer) {
if (args.length < 1) {
sender.sendMessage("Your ping: " + ((ProxiedPlayer) sender).getPing() + "ms");
} else {
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
if (target == null) {
sender.sendMessage("§cA player with that name is not online right now");
} else {
sender.sendMessage("Ping of " + args[0] + ": " + target.getPing() + "ms");
}
}
} else {
ProxyServer.getInstance().getLogger().warning("§cUse this command ingame");
}
return true;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>dev.waterdog.waterdogpe</groupId>
<artifactId>waterdog</artifactId>
<version>1.1.5-SNAPSHOT</version>
<version>1.1.10-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down