help cmd, improve player fetch
All checks were successful
/ Auto-Build-App (push) Successful in 1m49s
All checks were successful
/ Auto-Build-App (push) Successful in 1m49s
This commit is contained in:
parent
b14ec35f42
commit
927fe8d065
4 changed files with 66 additions and 4 deletions
|
@ -39,6 +39,21 @@ public class TextCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
commands.put("help",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
|
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||||
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
MessagePacket packet;
|
||||||
|
packet = new MessagePacket("You have access to following commands:");
|
||||||
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
for (String cmd : commands.keySet()){
|
||||||
|
if (!has_perm(account.getUniqueId(),cmd))
|
||||||
|
continue;
|
||||||
|
packet = new MessagePacket(" - "+cmd);
|
||||||
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
}
|
||||||
|
});
|
||||||
commands.put("gpos",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("gpos",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
@ -85,14 +100,14 @@ public class TextCommands {
|
||||||
if (args.length==2) {
|
if (args.length==2) {
|
||||||
boolean a = has_perm(account.getUniqueId(), Setup.get_perm(args[1]));
|
boolean a = has_perm(account.getUniqueId(), Setup.get_perm(args[1]));
|
||||||
boolean b = has_perm(account.getUniqueId(), "setup.*");
|
boolean b = has_perm(account.getUniqueId(), "setup.*");
|
||||||
if (a || b)
|
|
||||||
started = Setup.start(account.getUniqueId(), args[1]);
|
|
||||||
if (args[1].equals("cancel"))
|
if (args[1].equals("cancel"))
|
||||||
Setup.cancel(account.getUniqueId());
|
Setup.cancel(account.getUniqueId());
|
||||||
|
else if (a || b)
|
||||||
|
started = Setup.start(account.getUniqueId(), args[1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup...");
|
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup... (There might be one running)");
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
packet.setupAndSend(channelHandlerContext);
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class MessagePacketMixin {
|
||||||
if (ply_msgs.containsKey(playerUniqueId)){
|
if (ply_msgs.containsKey(playerUniqueId)){
|
||||||
MessageInfo msg = ply_msgs.get(playerUniqueId);
|
MessageInfo msg = ply_msgs.get(playerUniqueId);
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if (msg.last_msg+msg.msg_delay>time || msg.last_msg_txt.equals(message)) {
|
if (msg.last_msg+msg.msg_delay>time || (msg.last_msg_txt.equals(message) && msg.last_msg+msg.msg_delay*2>time)) {
|
||||||
msg.msg_delay += 500;
|
msg.msg_delay += 500;
|
||||||
if (msg.msg_delay>10000)
|
if (msg.msg_delay>10000)
|
||||||
msg.msg_delay=10000;
|
msg.msg_delay=10000;
|
||||||
|
|
|
@ -18,6 +18,8 @@ public interface setupCreator {
|
||||||
Setup create();
|
Setup create();
|
||||||
|
|
||||||
static Setup get(String setupId) {
|
static Setup get(String setupId) {
|
||||||
|
if (!setupCreators.containsKey(setupId))
|
||||||
|
return null;
|
||||||
return setupId == null ? null : setupCreators.get(setupId).create();
|
return setupId == null ? null : setupCreators.get(setupId).create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package net.pietru.cookie_utils.utils;
|
package net.pietru.cookie_utils.utils;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import finalforeach.cosmicreach.accounts.Account;
|
||||||
|
import finalforeach.cosmicreach.chat.commands.Command;
|
||||||
|
import finalforeach.cosmicreach.entities.player.Player;
|
||||||
|
import finalforeach.cosmicreach.gamestates.InGame;
|
||||||
|
import finalforeach.cosmicreach.util.ArrayUtils;
|
||||||
import net.pietru.cookie_utils.api.Area;
|
import net.pietru.cookie_utils.api.Area;
|
||||||
import net.pietru.cookie_utils.permissions.PlayerAreaPerm;
|
import net.pietru.cookie_utils.permissions.PlayerAreaPerm;
|
||||||
|
|
||||||
|
@ -29,10 +35,49 @@ public class player_utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String get_player_id(String value){
|
public static String get_player_id(String value){
|
||||||
|
Player plr = parseAsPlayer(value);
|
||||||
|
if (plr!=null)
|
||||||
|
return plr.getAccount().getUniqueId();
|
||||||
if (usernames_to_ids.containsKey(value))
|
if (usernames_to_ids.containsKey(value))
|
||||||
return usernames_to_ids.get(value);
|
return usernames_to_ids.get(value);
|
||||||
if (usernames_to_ids.containsValue(value))
|
if (usernames_to_ids.containsValue(value))
|
||||||
return value;
|
return value;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Player parseAsPlayer(String arg) {
|
||||||
|
Array<Player> players = InGame.getWorld().players;
|
||||||
|
Player player = (Player) ArrayUtils.find(players, (p) -> {
|
||||||
|
Account account = p.getAccount();
|
||||||
|
return account != null && arg.equals(account.getUniqueId());
|
||||||
|
});
|
||||||
|
if (player != null) {
|
||||||
|
return player;
|
||||||
|
} else {
|
||||||
|
player = (Player)ArrayUtils.find(players, (p) -> {
|
||||||
|
Account account = p.getAccount();
|
||||||
|
return account != null && arg.equals(account.getUsername());
|
||||||
|
});
|
||||||
|
if (player != null) {
|
||||||
|
return player;
|
||||||
|
} else {
|
||||||
|
player = (Player)ArrayUtils.find(players, (p) -> {
|
||||||
|
Account account = p.getAccount();
|
||||||
|
return account != null && arg.equals(account.getDisplayName());
|
||||||
|
});
|
||||||
|
if (player != null) {
|
||||||
|
return player;
|
||||||
|
} else {
|
||||||
|
Array<Player> allMatches = new Array<>();
|
||||||
|
ArrayUtils.findAll(players, (p) -> {
|
||||||
|
Account account = p.getAccount();
|
||||||
|
String var10000 = account.getPrefix();
|
||||||
|
String combined = var10000 + ":" + arg;
|
||||||
|
return combined.equals(account.getUsername());
|
||||||
|
}, allMatches);
|
||||||
|
return allMatches.size == 1 ? (Player)allMatches.first() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue