SteamWar/BungeeCore
Archiviert
13
2

Update TutorialCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-06-16 12:15:50 +02:00
Ursprung 8a21d5c93d
Commit 9e867a7457

Datei anzeigen

@ -26,7 +26,9 @@ import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Tutorial; import de.steamwar.bungeecore.sql.Tutorial;
import net.md_5.bungee.api.CommandSender; import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -38,38 +40,26 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class TutorialCommand extends BasicCommand { public class TutorialCommand extends SWCommand {
public TutorialCommand() { public TutorialCommand() {
super("tutorial", null); super("tutorial", null);
addDefaultHelpMessage("TUTORIAL_CREATE_HELP");
addDefaultHelpMessage("TUTORIAL_OWN_HELP");
} }
@Override @Register
public void execute(CommandSender sender, String[] args) { public void genericCommand(ProxiedPlayer player) {
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length == 0) {
openInventory(player, true, false); openInventory(player, true, false);
return;
} }
switch(args[0].toLowerCase()) { @Register("rate")
case "rate": public void rate(ProxiedPlayer player) {
if(args.length < 2) {
player.chat("/tutorial rate"); player.chat("/tutorial rate");
return;
}
int id;
try {
id = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with non number: " + args[1]);
return;
} }
@Register("rate")
public void rate(ProxiedPlayer player, int id) {
Tutorial tutorial = Tutorial.get(id); Tutorial tutorial = Tutorial.get(id);
if(tutorial == null) { if(tutorial == null) {
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with nonexistent id: " + id); BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with nonexistent id: " + id);
@ -77,27 +67,36 @@ public class TutorialCommand extends BasicCommand {
} }
rate(player, tutorial); rate(player, tutorial);
break;
case "create":
if(args.length < 3) {
Message.send("TUTORIAL_CREATE_HELP", player);
return;
} }
create(player, Arrays.stream(args).skip(2).collect(Collectors.joining(" ")), args[1].toUpperCase()); @Register(value = "create", description = "TUTORIAL_CREATE_HELP")
break; public void create(ProxiedPlayer player, String material, String... name) {
case "own": create(player, String.join(" ", name), material.toUpperCase());
}
@Register("own")
public void own(ProxiedPlayer player) {
openInventory(player, false, true); openInventory(player, false, true);
break; }
case "unreleased":
if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) { @Register("unreleased")
public void unreleased(@Guard("unreleased") ProxiedPlayer player) {
openInventory(player, false, false); openInventory(player, false, false);
break;
} }
default:
Message.send("TUTORIAL_CREATE_HELP", player); @Guard("unreleased")
Message.send("TUTORIAL_OWN_HELP", player); public GuardChecker unreleasedChecker() {
return (commandSender, guardCheckType, previousArguments, s) -> {
if (commandSender instanceof ProxiedPlayer) {
if (SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup().isTeamGroup()) {
return GuardResult.ALLOWED;
} else {
return GuardResult.DENIED_WITH_HELP;
} }
} else {
return GuardResult.ALLOWED;
}
};
} }
private void openInventory(ProxiedPlayer player, boolean released, boolean own) { private void openInventory(ProxiedPlayer player, boolean released, boolean own) {