Add SendCommand

This commit is contained in:
2024-08-06 08:59:28 +02:00
parent b210d1265c
commit 2c43ba1cda
2 changed files with 81 additions and 0 deletions

View File

@@ -170,6 +170,7 @@ public class VelocityCore implements ReloadablePlugin {
teamCommand = new TeamCommand();
new ServerTeamchatCommand();
new DevCommand();
new SendCommand();
new EventCommand();
new EventreloadCommand();
new EventRescheduleCommand();

View File

@@ -0,0 +1,80 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.velocitycore.commands;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.PlayerChatter;
import de.steamwar.persistent.Servertype;
import de.steamwar.persistent.Subserver;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class SendCommand extends SWCommand {
public SendCommand() {
super("send", UserPerm.TEAM);
}
@Register
public void sendToServer(PlayerChatter sender, Player send, Subserver server) {
send.createConnectionRequest(server.getRegisteredServer()).fireAndForget();
}
@ClassMapper(value = Subserver.class, local = true)
public TypeMapper<Subserver> subserverTypeMapper() {
return new TypeMapper<>() {
@Override
public Subserver map(Chatter sender, PreviousArguments previousArguments, String s) {
List<Subserver> subservers = Subserver.getServerList();
for (Subserver subserver : subservers) {
if (subserver.getServer().getName().replace(' ', '_').equals(s)) {
return subserver;
}
}
return null;
}
@Override
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
SteamwarUser user = sender.user();
List<Subserver> subservers = Subserver.getServerList();
List<String> tabCompletes = new ArrayList<>();
for (Subserver subserver : subservers) {
if (subserver.getType() == Servertype.BAUSERVER) continue;
if (subserver.getType() == Servertype.ARENA && (user.hasPerm(UserPerm.MODERATION) || user.hasPerm(UserPerm.ADMINISTRATION))) {
tabCompletes.add(subserver.getServer().getName().replace(' ', '_'));
}
if (subserver.getType() == Servertype.BUILDER && user.hasPerm(UserPerm.BUILD)) {
tabCompletes.add(subserver.getServer().getName().replace(' ', '_'));
}
}
return tabCompletes;
}
};
}
}