Initial copy from other repository (nothing is fixed here)

This commit is contained in:
2025-11-22 23:08:48 +01:00
parent e343d044ff
commit f9faa9b296
249 changed files with 15806 additions and 1 deletions
@@ -0,0 +1,34 @@
/*
* 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/>.
*/
plugins {
steamwar.java
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
implementation(project(":CommandFramework:CommandFrameworkBase", "default"))
annotationProcessor(libs.velocityapi)
compileOnly(libs.velocity)
}
@@ -0,0 +1,152 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.command;
import de.steamwar.command.mapper.ProxiedPlayerMapper;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Level;
public class VelocityCommand extends AbstractCommand<CommandSender> {
static {
CommandUtils.addMapper(ProxiedPlayer.class, new ProxiedPlayerMapper());
addExecutorMapper(VelocityCommand.class, CommandSender.class, Function.identity());
}
private Command command;
private List<String> defaultHelpMessages = new ArrayList<>();
public VelocityCommand(String command, Consumer<CommandLoader<CommandSender>> initializer, String... aliases) {
super(command, initializer, aliases);
}
public VelocityCommand(String command, String permission, Consumer<CommandLoader<CommandSender>> initializer, String... aliases) {
super(command, permission, initializer, aliases);
}
private abstract static class TabCompletableCommand extends Command implements TabExecutor {
public TabCompletableCommand(String name, String permission, String... aliases) {
super(name, permission, aliases);
}
}
@Override
protected synchronized void initCommand() {
if (command != null) return;
command = new TabCompletableCommand(VelocityCommand.super.command, permission, aliases) {
@Override
public void execute(CommandSender commandSender, String[] strings) {
VelocityCommand.this.execute(commandSender, null, strings);
}
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
return VelocityCommand.this.tabComplete(commandSender, null, strings);
}
};
}
@Override
public void unregister() {
VelocityCommandRegistering.unregister(command);
}
@Override
public void register() {
VelocityCommandRegistering.register(command);
}
@Override
protected void commandSystemError(CommandSender sender, CommandFrameworkException e) {
ProxyServer.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
// TODO: ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR");
}
public void addDefaultHelpMessage(String message) {
defaultHelpMessages.add(message);
}
@Override
protected void sendMessage(CommandSender sender, String message, Object[] args) {
// TODO: ChatSender.of(sender).system(message, args);
sender.sendMessage(MessageFormat.format(message, args));
}
/* TODO
@Register(noTabComplete = true)
public void internalHelp(ProxiedPlayer p, String... args) {
ChatSender chatSender = ChatSender.of(p);
try {
chatSender.prefixless("COMMAND_HELP_HEAD", command.getName());
defaultHelpMessages.forEach(chatSender::prefixless);
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e);
return;
}
AtomicInteger atomicInteger = new AtomicInteger();
if (args.length != 0) {
commandList.forEach(subCommand -> {
List<String> tabCompletes = subCommand.tabComplete(p, args);
if (tabCompletes == null || tabCompletes.isEmpty()) {
atomicInteger.incrementAndGet();
return;
}
boolean hasTabCompletes = tabCompletes.stream()
.anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase()));
if (hasTabCompletes) {
send(chatSender, subCommand);
} else {
atomicInteger.incrementAndGet();
}
});
}
if (args.length == 0 || atomicInteger.get() == commandList.size()) {
commandList.forEach(subCommand -> {
if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) {
send(chatSender, subCommand);
}
});
}
}
private void send(ChatSender chatSender, SubCommand<CommandSender> subCommand) {
try {
for (String s : subCommand.description) {
String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand);
String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand);
chatSender.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest));
}
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e);
}
}
*/
}
@@ -0,0 +1,29 @@
/*
* 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.command;
import com.velocitypowered.api.plugin.Plugin;
@Plugin(
id = "commandframework",
name = "CommandFramework"
)
public class VelocityCommandFrameworkPlugin {
}
@@ -0,0 +1,39 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.command;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin;
@UtilityClass
class VelocityCommandRegistering {
private static final Plugin plugin = ProxyServer.getInstance().getPluginManager().getPlugins().iterator().next();
static void unregister(Command command) {
ProxyServer.getInstance().getPluginManager().unregisterCommand(command);
}
static void register(Command command) {
ProxyServer.getInstance().getPluginManager().registerCommand(plugin, command);
}
}
@@ -0,0 +1,25 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.command;
import net.md_5.bungee.api.CommandSender;
public interface VelocityTypeMapper<T> extends AbstractTypeMapper<CommandSender, T> {
}
@@ -0,0 +1,25 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.command;
import net.md_5.bungee.api.CommandSender;
public interface VelocityTypeSupplier<T> extends AbstractTypeSupplier<CommandSender, T> {
}
@@ -0,0 +1,25 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.command;
import net.md_5.bungee.api.CommandSender;
public interface VelocityTypeValidator<T> extends AbstractTypeValidator<CommandSender, T> {
}
@@ -0,0 +1,44 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.command.mapper;
import de.steamwar.command.VelocityTypeMapper;
import de.steamwar.command.PreviousArguments;
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.Collection;
import java.util.stream.Collectors;
public class ProxiedPlayerMapper implements VelocityTypeMapper<ProxiedPlayer> {
@Override
public ProxiedPlayer map(CommandSender sender, PreviousArguments previousArguments, String s) {
return ProxyServer.getInstance().getPlayer(s);
}
@Override
public Collection<String> tabComplete(CommandSender sender, PreviousArguments previousArguments, String s) {
return ProxyServer.getInstance().getPlayers().stream()
.map(ProxiedPlayer::getName)
.collect(Collectors.toList());
}
}
@@ -0,0 +1,4 @@
name: CommandFramework
main: de.steamwar.command.BungeeCommandFrameworkPlugin
version: 1.0
author: YoyoNow