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

Rework commands #384

Merged
merged 1 commit into from
Jan 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java adoptopenjdk-8.0.332+9
java openjdk-18.0.2.1
2 changes: 1 addition & 1 deletion modules/jutils/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</plugins>
</build>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@Deprecated
@AllArgsConstructor
public class LegacySpigotUserAdapter implements User {
public class LegacySpigotUserAdapter implements User<CommandSender> {

private CommandSender sender;

Expand Down Expand Up @@ -126,7 +126,7 @@ public void sendActionbarMessage(String text) {
}

@Override
public Object getOriginal() {
public CommandSender getOriginal() {
return sender;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Set;
import java.util.UUID;

public class VistasUser implements User {
public class VistasUser implements User<Object> {

private String name;
private UUID uuid;
Expand All @@ -34,15 +34,15 @@ public class VistasUser implements User {
@Getter private Instant offlineSince = Instant.now();
@Getter private Set<UUID> currentServers = new HashSet<>();
private boolean isSpigot = false;
private User original = null;
private User<?> original = null;

public VistasUser(String name, UUID uuid, String ip) {
this.name = name;
this.uuid = uuid;
this.ip = ip;
}

public VistasUser(String name, UUID uuid, User player) {
public VistasUser(String name, UUID uuid, User<?> player) {
this.name = name;
this.uuid = uuid;
this.isSpigot = true;
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/bash/data.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUM="1050"
BUILD_NUM="1056"
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public void onEnable() {

commandService.registerSubCommands(
new HelpSubCommand(),
new BungeePlayCommand(OpenAudioMc.getInstance()),
new BungeeStopCommand(OpenAudioMc.getInstance()),
new BungeeRegionCommand(),
new BungeeSpeakerCommand(),
new BungeeShowCommand(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.craftmend.openaudiomc.bungee.modules.commands.commands;

import com.craftmend.openaudiomc.OpenAudioMc;
import com.craftmend.openaudiomc.api.interfaces.Client;
import com.craftmend.openaudiomc.bungee.modules.player.objects.BungeePlayerSelector;

import com.craftmend.openaudiomc.generic.client.objects.ClientConnection;
import com.craftmend.openaudiomc.generic.commands.helpers.CommandMiddewareExecutor;
import com.craftmend.openaudiomc.generic.commands.interfaces.CommandMiddleware;
import com.craftmend.openaudiomc.generic.commands.middleware.CatchCrashMiddleware;
Expand All @@ -17,6 +19,8 @@
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

import java.util.Optional;

public class BungeeAudioCommand extends Command {

/**
Expand Down Expand Up @@ -58,8 +62,13 @@ public void execute(CommandSender sender, String[] args) {
return;
}

for (ProxiedPlayer player : new BungeePlayerSelector(args[0]).getPlayers(sender)) {
OpenAudioMc.getService(NetworkingService.class).getClient(player.getUniqueId()).getAuth().publishSessionUrl();
BungeePlayerSelector selector = new BungeePlayerSelector();
selector.setSender(new BungeeUserAdapter(sender));
selector.setString(args[0]);

for (User<CommandSender> result : selector.getResults()) {
Optional<Client> client = result.findClient();
client.ifPresent(value -> ((ClientConnection) value).getAuth().publishSessionUrl());
}
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
package com.craftmend.openaudiomc.bungee.modules.player.objects;

import com.craftmend.openaudiomc.generic.commands.selectors.SelectorTranslator;
import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger;
import lombok.AllArgsConstructor;
import com.craftmend.openaudiomc.generic.user.User;
import com.craftmend.openaudiomc.generic.user.adapters.BungeeUserAdapter;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;

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

@AllArgsConstructor
public class BungeePlayerSelector {
public class BungeePlayerSelector implements SelectorTranslator<CommandSender> {

private String selector;
private CommandSender sender;

@Override
public void setString(String selector) {
this.selector = selector;
}

@Override
public void setSender(User<CommandSender> sender) {
this.sender = sender.getOriginal();
}

@Override
public List<User<CommandSender>> getResults() {
List<ProxiedPlayer> players = getPlayers(sender);
List<User<CommandSender>> users = new ArrayList<>();
for (ProxiedPlayer player : players) {
users.add(new BungeeUserAdapter(player));
}
return users;
}

/**
* this turns selectors like @a[r=5] into a usable list, since
Expand All @@ -21,7 +43,7 @@ public class BungeePlayerSelector {
* @param commandSender the sender
* @return players following the selector
*/
public List<ProxiedPlayer> getPlayers(CommandSender commandSender) {
private List<ProxiedPlayer> getPlayers(CommandSender commandSender) {
List<ProxiedPlayer> players = new ArrayList<>();

if (selector.startsWith("@a")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

public class ClientConnection implements Authenticatable, Client, Serializable {

@Getter private transient final User user;
@Getter private transient final User<?> user;

@Getter private final SessionData session;
@Setter private ClientAuth auth;
Expand Down Expand Up @@ -233,7 +233,7 @@ public void onDestroy() {
}

@Override
public User getOwner() {
public User<?> getOwner() {
return this.getUser();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public CommandService() {
new ReloadSubCommand(),
new StateSubCommand(),
new ModulesSubCommand(),
new ClientsSubCommand()
new ClientsSubCommand(),
new StopSubCommand(),
new PlaySubCommand()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.craftmend.openaudiomc.OpenAudioMc;
import com.craftmend.openaudiomc.generic.commands.objects.CommandError;
import com.craftmend.openaudiomc.generic.commands.selectors.SelectorTranslator;
import com.craftmend.openaudiomc.generic.environment.MagicValue;
import com.craftmend.openaudiomc.generic.platform.Platform;
import com.craftmend.openaudiomc.generic.commands.objects.Argument;
Expand Down Expand Up @@ -147,6 +148,13 @@ protected <T extends Service> T getService(Class<T> service) {
return service.cast(OpenAudioMc.getInstance().getServiceManager().loadService(service));
}

protected List<User<?>> resolveSelector(User<?> sender, String selector) {
SelectorTranslator<?> translator = Platform.getSelectorTranslator();
translator.setString(selector);
translator.setSenderGeneric(sender);
return translator.getResultsGeneric();
}

@SneakyThrows
public int catchInt(String data) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.craftmend.openaudiomc.generic.commands.selectors;

import com.craftmend.openaudiomc.generic.user.User;

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

public interface SelectorTranslator<T> {

void setString(String selector);
void setSender(User<T> sender);
List<User<T>> getResults();

default void setSenderGeneric(User unknownSender) {
this.setSender((User<T>) unknownSender);
}

default List<User<?>> getResultsGeneric() {
// CONVERT TO GENERIC
List<User<T>> r = getResults();
List<User<?>> results = new ArrayList<>(r.size());
for (User<T> user : r) {
results.add(user);
}
return results;
}

}
Loading
Loading