228 lines
7.9 KiB
Java
228 lines
7.9 KiB
Java
/*
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
|
* Copyright (C) 2016-2023 ViaVersion and contributors
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.viaversion.viaversion;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.google.gson.JsonObject;
|
|
import com.viaversion.viaversion.api.Via;
|
|
import com.viaversion.viaversion.api.ViaAPI;
|
|
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
|
import com.viaversion.viaversion.api.platform.PlatformTask;
|
|
import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
|
|
import com.viaversion.viaversion.api.platform.ViaServerProxyPlatform;
|
|
import com.viaversion.viaversion.bungee.commands.BungeeCommand;
|
|
import com.viaversion.viaversion.bungee.commands.BungeeCommandHandler;
|
|
import com.viaversion.viaversion.bungee.commands.BungeeCommandSender;
|
|
import com.viaversion.viaversion.bungee.platform.BungeeViaAPI;
|
|
import com.viaversion.viaversion.bungee.platform.BungeeViaConfig;
|
|
import com.viaversion.viaversion.bungee.platform.BungeeViaInjector;
|
|
import com.viaversion.viaversion.bungee.platform.BungeeViaLoader;
|
|
import com.viaversion.viaversion.bungee.platform.BungeeViaTask;
|
|
import com.viaversion.viaversion.bungee.service.ProtocolDetectorService;
|
|
import com.viaversion.viaversion.dump.PluginInfo;
|
|
import com.viaversion.viaversion.unsupported.UnsupportedServerSoftware;
|
|
import com.viaversion.viaversion.util.GsonUtil;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.TimeUnit;
|
|
import net.md_5.bungee.api.ProxyServer;
|
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
import net.md_5.bungee.api.plugin.Listener;
|
|
import net.md_5.bungee.api.plugin.Plugin;
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
|
|
|
public class BungeePlugin extends Plugin implements ViaServerProxyPlatform<ProxiedPlayer>, Listener {
|
|
private final ProtocolDetectorService protocolDetectorService = new ProtocolDetectorService();
|
|
private BungeeViaAPI api;
|
|
private BungeeViaConfig config;
|
|
|
|
@Override
|
|
public void onLoad() {
|
|
try {
|
|
ProtocolConstants.class.getField("MINECRAFT_1_19_4");
|
|
} catch (NoSuchFieldException e) {
|
|
getLogger().warning(" / \\");
|
|
getLogger().warning(" / \\");
|
|
getLogger().warning(" / | \\");
|
|
getLogger().warning(" / | \\ BUNGEECORD IS OUTDATED");
|
|
getLogger().warning(" / \\ VIAVERSION MAY NOT WORK AS INTENDED");
|
|
getLogger().warning(" / o \\");
|
|
getLogger().warning("/_____________\\");
|
|
}
|
|
|
|
api = new BungeeViaAPI();
|
|
config = new BungeeViaConfig(getDataFolder());
|
|
BungeeCommandHandler commandHandler = new BungeeCommandHandler();
|
|
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
|
|
|
|
// Init platform
|
|
Via.init(ViaManagerImpl.builder()
|
|
.platform(this)
|
|
.injector(new BungeeViaInjector())
|
|
.loader(new BungeeViaLoader(this))
|
|
.commandHandler(commandHandler)
|
|
.build());
|
|
}
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
final ViaManagerImpl manager = (ViaManagerImpl) Via.getManager();
|
|
manager.init();
|
|
manager.onServerLoaded();
|
|
}
|
|
|
|
@Override
|
|
public String getPlatformName() {
|
|
return getProxy().getName();
|
|
}
|
|
|
|
@Override
|
|
public String getPlatformVersion() {
|
|
return getProxy().getVersion();
|
|
}
|
|
|
|
@Override
|
|
public boolean isProxy() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public String getPluginVersion() {
|
|
return getDescription().getVersion();
|
|
}
|
|
|
|
@Override
|
|
public PlatformTask runAsync(Runnable runnable) {
|
|
return new BungeeViaTask(getProxy().getScheduler().runAsync(this, runnable));
|
|
}
|
|
|
|
@Override
|
|
public PlatformTask runRepeatingAsync(final Runnable runnable, final long ticks) {
|
|
return new BungeeViaTask(getProxy().getScheduler().schedule(this, runnable, 0, ticks * 50, TimeUnit.MILLISECONDS));
|
|
}
|
|
|
|
@Override
|
|
public PlatformTask runSync(Runnable runnable) {
|
|
return runAsync(runnable);
|
|
}
|
|
|
|
@Override
|
|
public PlatformTask runSync(Runnable runnable, long delay) {
|
|
return new BungeeViaTask(getProxy().getScheduler().schedule(this, runnable, delay * 50, TimeUnit.MILLISECONDS));
|
|
}
|
|
|
|
@Override
|
|
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
|
return runRepeatingAsync(runnable, period);
|
|
}
|
|
|
|
@Override
|
|
public ViaCommandSender[] getOnlinePlayers() {
|
|
Collection<ProxiedPlayer> players = getProxy().getPlayers();
|
|
ViaCommandSender[] array = new ViaCommandSender[players.size()];
|
|
int i = 0;
|
|
for (ProxiedPlayer player : players) {
|
|
array[i++] = new BungeeCommandSender(player);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
@Override
|
|
public void sendMessage(UUID uuid, String message) {
|
|
getProxy().getPlayer(uuid).sendMessage(message);
|
|
}
|
|
|
|
@Override
|
|
public boolean kickPlayer(UUID uuid, String message) {
|
|
ProxiedPlayer player = getProxy().getPlayer(uuid);
|
|
if (player != null) {
|
|
player.disconnect(message);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isPluginEnabled() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public ViaAPI<ProxiedPlayer> getApi() {
|
|
return api;
|
|
}
|
|
|
|
@Override
|
|
public BungeeViaConfig getConf() {
|
|
return config;
|
|
}
|
|
|
|
@Override
|
|
public void onReload() {
|
|
// Injector prints a message <3
|
|
}
|
|
|
|
@Override
|
|
public JsonObject getDump() {
|
|
JsonObject platformSpecific = new JsonObject();
|
|
|
|
List<PluginInfo> plugins = new ArrayList<>();
|
|
for (Plugin p : ProxyServer.getInstance().getPluginManager().getPlugins())
|
|
plugins.add(new PluginInfo(
|
|
true,
|
|
p.getDescription().getName(),
|
|
p.getDescription().getVersion(),
|
|
p.getDescription().getMain(),
|
|
Collections.singletonList(p.getDescription().getAuthor())
|
|
));
|
|
|
|
platformSpecific.add("plugins", GsonUtil.getGson().toJsonTree(plugins));
|
|
platformSpecific.add("servers", GsonUtil.getGson().toJsonTree(protocolDetectorService.detectedProtocolVersions()));
|
|
return platformSpecific;
|
|
}
|
|
|
|
@Override
|
|
public boolean isOldClientsAllowed() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
|
|
final Collection<UnsupportedSoftware> list = new ArrayList<>(ViaServerProxyPlatform.super.getUnsupportedSoftwareClasses());
|
|
list.add(new UnsupportedServerSoftware.Builder()
|
|
.name("FlameCord")
|
|
.addClassName("dev._2lstudios.flamecord.FlameCord")
|
|
.reason(UnsupportedServerSoftware.Reason.BREAKING_PROXY_SOFTWARE)
|
|
.build());
|
|
return ImmutableList.copyOf(list);
|
|
}
|
|
|
|
@Override
|
|
public boolean hasPlugin(final String name) {
|
|
return getProxy().getPluginManager().getPlugin(name) != null;
|
|
}
|
|
|
|
@Override
|
|
public ProtocolDetectorService protocolDetectorService() {
|
|
return protocolDetectorService;
|
|
}
|
|
}
|