Update Sponge module to API v8

This commit is contained in:
Nassim Jahnke 2022-01-09 18:30:51 +01:00
parent 2a1e82ac6d
commit 2704d70c1f
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
31 changed files with 175 additions and 947 deletions

View File

@ -6,7 +6,7 @@ plugins {
tasks {
// Variable replacements
processResources {
filesMatching(listOf("plugin.yml", "mcmod.info", "fabric.mod.json", "bungee.yml")) {
filesMatching(listOf("plugin.yml", "META-INF/sponge_plugins.json", "fabric.mod.json", "bungee.yml")) {
expand("version" to project.version, "description" to project.description)
}
}

View File

@ -22,7 +22,6 @@ import com.viaversion.viaversion.configuration.AbstractViaConfig;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -50,11 +49,6 @@ public class BukkitViaConfig extends AbstractViaConfig {
blockConnectionMethod = getString("blockconnection-method", "packet");
}
@Override
public URL getDefaultConfigURL() {
return BukkitViaConfig.class.getClassLoader().getResource("assets/viaversion/config.yml");
}
@Override
protected void handleConfig(Map<String, Object> config) {
}

View File

@ -22,7 +22,6 @@ import com.viaversion.viaversion.bungee.providers.BungeeVersionProvider;
import com.viaversion.viaversion.configuration.AbstractViaConfig;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -48,11 +47,6 @@ public class BungeeViaConfig extends AbstractViaConfig {
bungeeServerProtocols = get("bungee-servers", Map.class, new HashMap<>());
}
@Override
public URL getDefaultConfigURL() {
return BungeeViaConfig.class.getClassLoader().getResource("assets/viaversion/config.yml");
}
@Override
protected void handleConfig(Map<String, Object> config) {
// Parse servers

View File

@ -61,7 +61,9 @@ public abstract class Config implements ConfigurationProvider {
this.configFile = configFile;
}
public abstract URL getDefaultConfigURL();
public URL getDefaultConfigURL() {
return getClass().getClassLoader().getResource("assets/viaversion/config.yml");
}
public synchronized Map<String, Object> loadConfig(File location) {
List<String> unsupported = getUnsupportedOptions();

View File

@ -1,5 +1,5 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
projectVersion=4.1.2-SNAPSHOT
projectVersion=4.2.0-SNAPSHOT
# Gradle properties
org.gradle.daemon=true

View File

@ -21,7 +21,7 @@ checkerQual = "3.18.0"
paper = "1.16.5-R0.1-SNAPSHOT"
legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
bungee = "1.17-R0.1-SNAPSHOT"
sponge = "8.0.0-SNAPSHOT"
sponge = "8.0.0"
legacySponge = "4.0.0"
velocity = "3.0.0-SNAPSHOT"

View File

@ -38,7 +38,6 @@ setupViaSubproject("bukkit-legacy")
setupViaSubproject("bungee")
setupViaSubproject("velocity")
setupViaSubproject("sponge")
setupViaSubproject("sponge-legacy")
setupViaSubproject("fabric")
setupSubproject("viaversion") {

View File

@ -1,4 +0,0 @@
dependencies {
implementation(projects.viaversionCommon)
compileOnly(libs.legacySponge)
}

View File

@ -1,25 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.inventory.ItemStack;
public interface ItemGrabber {
public ItemStack getItem(Player player);
}

View File

@ -1,159 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8.sponge4;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.InteractEvent;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
import org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.transaction.SlotTransaction;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.ViaListener;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import java.lang.reflect.Field;
import java.util.Optional;
import java.util.UUID;
public class Sponge4ArmorListener extends ViaListener {
private static Field entityIdField;
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
public Sponge4ArmorListener() {
super(Protocol1_9To1_8.class);
}
//
public void sendArmorUpdate(Player player) {
// Ensure that the player is on our pipe
if (!isOnPipe(player.getUniqueId())) return;
int armor = 0;
armor += calculate(player.getHelmet());
armor += calculate(player.getChestplate());
armor += calculate(player.getLeggings());
armor += calculate(player.getBoots());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player.getUniqueId()));
try {
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
wrapper.write(Type.INT, 1); // only 1 property
wrapper.write(Type.STRING, "generic.armor");
wrapper.write(Type.DOUBLE, 0D); //default 0 armor
wrapper.write(Type.VAR_INT, 1); // 1 modifier
wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}
}
private int calculate(Optional<ItemStack> itemStack) {
if (itemStack.isPresent())
return ArmorType.findByType(itemStack.get().getItem().getType().getId()).getArmorPoints();
return 0;
}
@Listener
public void onInventoryClick(ClickInventoryEvent e, @Root Player player) {
for (SlotTransaction transaction : e.getTransactions()) {
if (ArmorType.isArmor(transaction.getFinal().getType().getId()) ||
ArmorType.isArmor(e.getCursorTransaction().getFinal().getType().getId())) {
sendDelayedArmorUpdate(player);
break;
}
}
}
@Listener
public void onInteract(InteractEvent event, @Root Player player) {
if (player.getItemInHand().isPresent()) {
if (ArmorType.isArmor(player.getItemInHand().get().getItem().getId()))
sendDelayedArmorUpdate(player);
}
}
@Listener
public void onJoin(ClientConnectionEvent.Join e) {
sendArmorUpdate(e.getTargetEntity());
}
@Listener
public void onRespawn(RespawnPlayerEvent e) {
sendDelayedArmorUpdate(e.getTargetEntity());
}
@Listener
public void onWorldChange(DisplaceEntityEvent.Teleport e) {
if (!(e.getTargetEntity() instanceof Player)) return;
if (!e.getFromTransform().getExtent().getUniqueId().equals(e.getToTransform().getExtent().getUniqueId())) {
sendArmorUpdate((Player) e.getTargetEntity());
}
}
public void sendDelayedArmorUpdate(final Player player) {
if (!isOnPipe(player.getUniqueId())) return; // Don't start a task if the player is not on the pipe
Via.getPlatform().runSync(new Runnable() {
@Override
public void run() {
sendArmorUpdate(player);
}
});
}
@Override
public void register() {
if (isRegistered()) return;
Sponge.getEventManager().registerListeners(Via.getPlatform(), this);
setRegistered(true);
}
protected int getEntityId(Player p) {
try {
if (entityIdField == null) {
entityIdField = p.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("field_145783_c");
entityIdField.setAccessible(true);
}
return entityIdField.getInt(p);
} catch (Exception e) {
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
e.printStackTrace();
}
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
return -1;
}
}

View File

@ -1,29 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8.sponge4;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.inventory.ItemStack;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.ItemGrabber;
public class Sponge4ItemGrabber implements ItemGrabber {
@Override
public ItemStack getItem(Player player) {
return player.getItemInHand().orElse(null);
}
}

View File

@ -1,5 +1,4 @@
dependencies {
implementation(projects.viaversionSpongeLegacy)
implementation(projects.viaversionCommon)
compileOnly(libs.sponge)
}

View File

@ -26,37 +26,39 @@ import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.api.platform.PlatformTask;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.sponge.commands.SpongeCommandHandler;
import com.viaversion.viaversion.sponge.commands.SpongeCommandSender;
import com.viaversion.viaversion.sponge.platform.SpongeViaTask;
import com.viaversion.viaversion.sponge.commands.SpongePlayer;
import com.viaversion.viaversion.sponge.platform.SpongeViaAPI;
import com.viaversion.viaversion.sponge.platform.SpongeViaConfig;
import com.viaversion.viaversion.sponge.platform.SpongeViaInjector;
import com.viaversion.viaversion.sponge.platform.SpongeViaLoader;
import com.viaversion.viaversion.sponge.platform.SpongeViaTask;
import com.viaversion.viaversion.sponge.util.LoggerWrapper;
import com.viaversion.viaversion.util.ChatColorUtil;
import com.viaversion.viaversion.util.GsonUtil;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.Server;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.builtin.jvm.Plugin;
import org.spongepowered.plugin.metadata.PluginMetadata;
import org.spongepowered.plugin.metadata.model.PluginContributor;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
@ -64,40 +66,46 @@ import java.util.stream.Collectors;
@Plugin("viaversion")
public class SpongePlugin implements ViaPlatform<Player> {
@Inject
private Game game;
@Inject
private PluginContainer container;
@Inject
@DefaultConfig(sharedRoot = false)
private File spongeConfig;
public static final LegacyComponentSerializer COMPONENT_SERIALIZER = LegacyComponentSerializer.builder().character(ChatColorUtil.COLOR_CHAR).extractUrls().build();
public static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.builder().extractUrls().build();
private final SpongeViaAPI api = new SpongeViaAPI();
private final PluginContainer container;
private final Game game;
@SuppressWarnings("SpongeLogging")
private final Logger logger;
private SpongeViaConfig conf;
private Logger logger;
@Inject
@ConfigDir(sharedRoot = false)
private Path configDir;
@SuppressWarnings("SpongeInjection")
@Inject
SpongePlugin(final PluginContainer container, final Game game, final org.apache.logging.log4j.Logger logger) {
this.container = container;
this.game = game;
this.logger = new LoggerWrapper(logger);
}
@Listener
public void onGameStart(GameInitializationEvent event) {
// Setup Logger
logger = new LoggerWrapper(container.logger());
public void constructPlugin(ConstructPluginEvent event) {
// Setup Plugin
conf = new SpongeViaConfig(container, spongeConfig.getParentFile());
SpongeCommandHandler commandHandler = new SpongeCommandHandler();
game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
conf = new SpongeViaConfig(configDir.toFile());
logger.info("ViaVersion " + getPluginVersion() + " is now loaded!");
// Init platform
Via.init(ViaManagerImpl.builder()
.platform(this)
.commandHandler(commandHandler)
.commandHandler(new SpongeCommandHandler())
.injector(new SpongeViaInjector())
.loader(new SpongeViaLoader(this))
.build());
}
@Listener
public void onServerStart(GameAboutToStartServerEvent event) {
public void onServerStart(StartingEngineEvent<Server> event) {
// Can't use the command register event for raw commands...
Sponge.server().commandManager().registrar(Command.Raw.class).get().register(container, (Command.Raw) Via.getManager().getCommandHandler(), "viaversion", "viaver", "vvsponge");
if (game.pluginManager().plugin("viabackwards").isPresent()) {
MappingDataLoader.enableMappingsCache();
}
@ -108,7 +116,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
}
@Listener
public void onServerStop(StoppingEngineEvent<?> event) {
public void onServerStop(StoppingEngineEvent<Server> event) {
((ViaManagerImpl) Via.getManager()).destroy();
}
@ -119,80 +127,58 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Override
public String getPlatformVersion() {
return readVersion(game.platform().container(Platform.Component.IMPLEMENTATION).metadata().version());
return game.platform().container(Platform.Component.IMPLEMENTATION).metadata().version().toString();
}
@Override
public String getPluginVersion() {
return readVersion(container.metadata().version());
}
private static String readVersion(ArtifactVersion version) {
String qualifier = version.getQualifier();
qualifier = (qualifier == null || qualifier.isEmpty()) ? "" : "-" + qualifier;
return version.getMajorVersion() + "." + version.getMinorVersion() + "." + version.getIncrementalVersion() + qualifier;
return container.metadata().version().toString();
}
@Override
public PlatformTask runAsync(Runnable runnable) {
return new SpongeViaTask(
Task.builder()
.execute(runnable)
.async()
.submit(this)
);
final Task task = Task.builder().plugin(container).execute(runnable).build();
return new SpongeViaTask(game.asyncScheduler().submit(task));
}
@Override
public PlatformTask runSync(Runnable runnable) {
return new SpongeViaTask(
Task.builder()
.execute(runnable)
.submit(this)
);
final Task task = Task.builder().plugin(container).execute(runnable).build();
return new SpongeViaTask(game.server().scheduler().submit(task));
}
@Override
public PlatformTask runSync(Runnable runnable, long ticks) {
return new SpongeViaTask(
Task.builder()
.execute(runnable)
.delayTicks(ticks)
.submit(this)
);
final Task task = Task.builder().plugin(container).execute(runnable).delay(Ticks.of(ticks)).build();
return new SpongeViaTask(game.server().scheduler().submit(task));
}
@Override
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
return new SpongeViaTask(
Task.builder()
.execute(runnable)
.intervalTicks(ticks)
.submit(this)
);
final Task task = Task.builder().plugin(container).execute(runnable).interval(Ticks.of(ticks)).build();
return new SpongeViaTask(game.server().scheduler().submit(task));
}
@Override
public ViaCommandSender[] getOnlinePlayers() {
ViaCommandSender[] array = new ViaCommandSender[game.server().onlinePlayers().size()];
Collection<ServerPlayer> players = game.server().onlinePlayers();
ViaCommandSender[] array = new ViaCommandSender[players.size()];
int i = 0;
for (Player player : game.server().onlinePlayers()) {
array[i++] = new SpongeCommandSender(player);
for (ServerPlayer player : players) {
array[i++] = new SpongePlayer(player);
}
return array;
}
@Override
public void sendMessage(UUID uuid, String message) {
String serialized = SpongePlugin.COMPONENT_SERIALIZER.serialize(SpongePlugin.COMPONENT_SERIALIZER.deserialize(message));
game.server().player(uuid).ifPresent(player -> player.sendMessage(TextSerializers.JSON.deserialize(serialized))); // Hacky way to fix links
game.server().player(uuid).ifPresent(player -> player.sendMessage(LEGACY_SERIALIZER.deserialize(message)));
}
@Override
public boolean kickPlayer(UUID uuid, String message) {
return game.server().player(uuid).map(player -> {
player.kick(TextSerializers.formattingCode(ChatColorUtil.COLOR_CHAR).deserialize(message));
player.kick(LegacyComponentSerializer.legacySection().deserialize(message));
return true;
}).orElse(false);
}
@ -209,12 +195,12 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Override
public File getDataFolder() {
return spongeConfig.getParentFile();
return configDir.toFile();
}
@Override
public void onReload() {
getLogger().severe("ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting.");
logger.severe("ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting.");
}
@Override
@ -222,14 +208,14 @@ public class SpongePlugin implements ViaPlatform<Player> {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> plugins = new ArrayList<>();
for (PluginContainer p : game.pluginManager().plugins()) {
PluginMetadata meta = p.metadata();
for (PluginContainer plugin : game.pluginManager().plugins()) {
PluginMetadata metadata = plugin.metadata();
plugins.add(new PluginInfo(
true,
meta.name().orElse("Unknown"),
readVersion(meta.version()),
p.instance() != null ? p.instance().getClass().getCanonicalName() : "Unknown",
meta.contributors().stream().map(PluginContributor::name).collect(Collectors.toList())
metadata.name().orElse("Unknown"),
metadata.version().toString(),
plugin.instance().getClass().getCanonicalName(),
metadata.contributors().stream().map(PluginContributor::name).collect(Collectors.toList())
));
}
platformSpecific.add("plugins", GsonUtil.getGson().toJsonTree(plugins));
@ -257,7 +243,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
return logger;
}
public PluginContainer getPluginContainer() {
public PluginContainer container() {
return container;
}

View File

@ -21,9 +21,9 @@ import com.viaversion.viaversion.commands.ViaCommandHandler;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.command.CommandCompletion;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.command.parameter.ArgumentReader;
import java.util.List;

View File

@ -19,6 +19,7 @@ package com.viaversion.viaversion.sponge.commands;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import net.kyori.adventure.identity.Identity;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.util.Identifiable;
@ -38,8 +39,7 @@ public class SpongeCommandSender implements ViaCommandSender {
@Override
public void sendMessage(String msg) {
String serialized = SpongePlugin.COMPONENT_SERIALIZER.serialize(SpongePlugin.COMPONENT_SERIALIZER.deserialize(msg));
source.sendMessage(TextSerializers.JSON.deserialize(serialized)); // Hacky way to fix links
source.sendMessage(Identity.nil(), SpongePlugin.LEGACY_SERIALIZER.deserialize(msg));
}
@Override

View File

@ -0,0 +1,52 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.commands;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import java.util.UUID;
public class SpongePlayer implements ViaCommandSender {
private final ServerPlayer player;
public SpongePlayer(ServerPlayer player) {
this.player = player;
}
@Override
public boolean hasPermission(String permission) {
return player.hasPermission(permission);
}
@Override
public void sendMessage(String msg) {
player.sendMessage(SpongePlugin.LEGACY_SERIALIZER.deserialize(msg));
}
@Override
public UUID getUUID() {
return player.uniqueId();
}
@Override
public String getName() {
return player.friendlyIdentifier().orElse(player.identifier());
}
}

View File

@ -23,6 +23,7 @@ import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
public class UpdateListener {
@Listener
public void onJoin(ServerSideConnectionEvent.Join join) {
if (join.player().hasPermission("viaversion.update") && Via.getConfig().isCheckForUpdates()) {

View File

@ -19,10 +19,8 @@ package com.viaversion.viaversion.sponge.listeners;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.ViaListener;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.Protocol;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import java.lang.reflect.Field;
@ -40,25 +38,7 @@ public class ViaSpongeListener extends ViaListener {
public void register() {
if (isRegistered()) return;
Sponge.eventManager().registerListeners(plugin.getPluginContainer(), this);
Sponge.eventManager().registerListeners(plugin.container(), this);
setRegistered(true);
}
// Hey sponge, please create a getEntityId method :'(
protected int getEntityId(Player p) {
try {
if (entityIdField == null) {
entityIdField = p.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("field_145783_c");
entityIdField.setAccessible(true);
}
return entityIdField.getInt(p);
} catch (Exception e) {
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
e.printStackTrace();
}
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
return -1;
}
}

View File

@ -1,55 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
import org.spongepowered.api.block.transaction.BlockTransaction;
import org.spongepowered.api.block.transaction.Operations;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.world.server.ServerLocation;
import java.util.Optional;
public class BlockListener extends ViaSpongeListener {
public BlockListener(SpongePlugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}
@Listener
public void placeBlock(ChangeBlockEvent.All e, @Root Player player) {
BlockTransaction transaction = e.transactions().get(0);
if (transaction.operation().equals(Operations.PLACE.get())) {
if (isOnPipe(player.uniqueId())) {
Optional<ServerLocation> optional = transaction.finalReplacement().location();
if (optional.isPresent()) {
ServerLocation loc = optional.get();
EntityTracker1_9 tracker = getUserConnection(player.uniqueId()).getEntityTracker(Protocol1_9To1_8.class);
tracker.addBlockInteraction(new Position(loc.blockX(), loc.blockY(), loc.blockZ()));
}
}
}
}
}

View File

@ -1,84 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.entity.DestructEntityEvent;
import org.spongepowered.api.world.World;
import java.util.Optional;
public class DeathListener extends ViaSpongeListener {
public DeathListener(SpongePlugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}
@Listener(order = Order.LAST)
public void onDeath(DestructEntityEvent.Death e) {
if (!(e.entity() instanceof Player))
return;
Player p = (Player) e.entity();
if (isOnPipe(p.uniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) {
sendPacket(p, PlainTextComponentSerializer.plainText().serialize(e.message()));
}
}
public boolean checkGamerule(World w) {
Optional<String> gamerule = w.gameRule("showDeathMessages");
if (gamerule.isPresent()) {
try {
return Boolean.parseBoolean(gamerule.get());
} catch (Exception e) {
return false;
}
}
return false;
}
private void sendPacket(final Player p, final String msg) {
Via.getPlatform().runSync(new Runnable() {
@Override
public void run() {
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.COMBAT_EVENT, null, getUserConnection(p.getUniqueId()));
try {
int entityId = getEntityId(p);
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
wrapper.write(Type.VAR_INT, entityId); // Player ID
wrapper.write(Type.INT, entityId); // Entity ID
Protocol1_9To1_8.FIX_JSON.write(wrapper, msg); // Message
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

View File

@ -1,111 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.sponge4.Sponge4ItemGrabber;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.sponge5.Sponge5ItemGrabber;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.inventory.ItemStack;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class HandItemCache implements Runnable {
public static boolean CACHE = false;
private static Map<UUID, Item> handCache = new ConcurrentHashMap<>();
private static Field GET_DAMAGE;
private static Method GET_ID;
private static ItemGrabber grabber;
static {
try {
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
grabber = new Sponge4ItemGrabber();
} catch (ClassNotFoundException e) {
grabber = new Sponge5ItemGrabber();
}
}
public static Item getHandItem(UUID player) {
return handCache.get(player);
}
@Override
public void run() {
List<UUID> players = new ArrayList<>(handCache.keySet());
for (Player p : Sponge.server().onlinePlayers()) {
handCache.put(p.uniqueId(), convert(grabber.getItem(p)));
players.remove(p.uniqueId());
}
// Remove offline players
for (UUID uuid : players) {
handCache.remove(uuid);
}
}
public static Item convert(ItemStack itemInHand) {
if (itemInHand == null) return new DataItem(0, (byte) 0, (short) 0, null);
if (GET_DAMAGE == null) {
try {
GET_DAMAGE = itemInHand.getClass().getDeclaredField("field_77991_e");
GET_DAMAGE.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
if (GET_ID == null) {
try {
GET_ID = Class.forName("net.minecraft.item.Item").getDeclaredMethod("func_150891_b", Class.forName("net.minecraft.item.Item"));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
int id = 0;
if (GET_ID != null) {
try {
id = (int) GET_ID.invoke(null, itemInHand.getItem());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
int damage = 0;
if (GET_DAMAGE != null) {
try {
damage = (int) GET_DAMAGE.get(itemInHand);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return new DataItem(id, (byte) itemInHand.quantity(), (short) damage, null);
}
}

View File

@ -1,135 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8.sponge5;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.InteractEvent;
import org.spongepowered.api.event.cause.entity.MovementTypes;
import org.spongepowered.api.event.entity.MoveEntityEvent;
import org.spongepowered.api.event.entity.living.player.RespawnPlayerEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.item.inventory.container.ClickContainerEvent;
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.transaction.SlotTransaction;
import java.util.UUID;
public class Sponge5ArmorListener extends ViaSpongeListener {
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
public Sponge5ArmorListener(SpongePlugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}
//
public void sendArmorUpdate(Player player) {
// Ensure that the player is on our pipe
if (!isOnPipe(player.uniqueId())) return;
int armor = 0;
armor += calculate(player.head());
armor += calculate(player.chest());
armor += calculate(player.legs());
armor += calculate(player.feet());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player.getUniqueId()));
try {
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
wrapper.write(Type.INT, 1); // only 1 property
wrapper.write(Type.STRING, "generic.armor");
wrapper.write(Type.DOUBLE, 0D); //default 0 armor
wrapper.write(Type.VAR_INT, 1); // 1 modifier
wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}
}
private int calculate(ItemStack itemStack) {
if (itemStack != null) {
// todo
return ArmorType.findByType(itemStack.type()).getArmorPoints();
}
return 0;
}
@Listener
public void onContainerClick(ClickContainerEvent e, @Root Player player) {
for (SlotTransaction transaction : e.transactions()) {
if (ArmorType.isArmor(transaction.finalReplacement().type()) ||
ArmorType.isArmor(e.cursorTransaction().finalReplacement().type())) {
sendDelayedArmorUpdate(player);
break;
}
}
}
@Listener
public void onInteract(InteractEvent event, @Root Player player) {
if (player.itemInHand(HandTypes.MAIN_HAND) != null) {
if (ArmorType.isArmor(player.itemInHand(HandTypes.MAIN_HAND).type()))
sendDelayedArmorUpdate(player);
}
}
@Listener
public void onJoin(ServerSideConnectionEvent.Join e) {
sendArmorUpdate(e.player());
}
@Listener
public void onRespawn(RespawnPlayerEvent e) {
sendDelayedArmorUpdate(e.entity());
}
@Listener
public void onWorldChange(MoveEntityEvent e) {
if (!(e.entity() instanceof Player)) return;
if (!e.cause().contains(MovementTypes.ENTITY_TELEPORT)) return; //todo: probably doesn't work
if (!e.originalDestinationPosition().getExtent().getUniqueId().equals(e.destinationPosition().getExtent().getUniqueId())) {
sendArmorUpdate((Player) e.entity());
}
}
public void sendDelayedArmorUpdate(final Player player) {
if (!isOnPipe(player.uniqueId())) return; // Don't start a task if the player is not on the pipe
Via.getPlatform().runSync(new Runnable() {
@Override
public void run() {
sendArmorUpdate(player);
}
});
}
}

View File

@ -1,30 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.listeners.protocol1_9to1_8.sponge5;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.ItemGrabber;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.inventory.ItemStack;
public class Sponge5ItemGrabber implements ItemGrabber {
@Override
public ItemStack getItem(Player player) {
return player.itemInHand(HandTypes.MAIN_HAND);
}
}

View File

@ -18,37 +18,22 @@
package com.viaversion.viaversion.sponge.platform;
import com.viaversion.viaversion.configuration.AbstractViaConfig;
import org.spongepowered.api.asset.Asset;
import org.spongepowered.plugin.PluginContainer;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class SpongeViaConfig extends AbstractViaConfig {
private static final List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval",
"bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers",
"quick-move-action-fix", "change-1_9-hitbox", "change-1_14-hitbox", "blockconnection-method");
private final PluginContainer pluginContainer;
public SpongeViaConfig(PluginContainer pluginContainer, File configFile) {
public SpongeViaConfig(File configFile) {
super(new File(configFile, "config.yml"));
this.pluginContainer = pluginContainer;
reloadConfig();
}
@Override
public URL getDefaultConfigURL() {
Optional<Asset> config = pluginContainer.getAsset("config.yml");
if (!config.isPresent()) {
throw new IllegalArgumentException("Default config is missing from jar");
}
return config.get().url();
}
@Override
protected void handleConfig(Map<String, Object> config) {
}

View File

@ -27,8 +27,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.MinecraftVersion;
import org.spongepowered.api.Sponge;
import java.lang.reflect.Method;
public class SpongeViaInjector extends LegacyViaInjector {
@Override
@ -40,15 +38,7 @@ public class SpongeViaInjector extends LegacyViaInjector {
@Override
protected @Nullable Object getServerConnection() throws ReflectiveOperationException {
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
for (Method method : serverClazz.getDeclaredMethods()) {
if (method.getReturnType().getSimpleName().equals("NetworkSystem") && method.getParameterTypes().length == 0) {
Object connection = method.invoke(Sponge.server());
if (connection != null) {
return connection;
}
}
}
return null;
return serverClazz.getDeclaredMethod("getConnection").invoke(Sponge.server());
}
@Override

View File

@ -18,21 +18,9 @@
package com.viaversion.viaversion.sponge.platform;
import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.platform.PlatformTask;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import com.viaversion.viaversion.sponge.listeners.UpdateListener;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.BlockListener;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.DeathListener;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.HandItemCache;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.sponge4.Sponge4ArmorListener;
import com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.sponge5.Sponge5ArmorListener;
import com.viaversion.viaversion.sponge.providers.SpongeViaMovementTransmitter;
import org.spongepowered.api.Sponge;
import java.util.HashSet;
@ -50,7 +38,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
}
private void registerListener(Object listener) {
Sponge.getEventManager().registerListeners(plugin, storeListener(listener));
Sponge.eventManager().registerListeners(plugin.container(), storeListener(listener));
}
private <T> T storeListener(T listener) {
@ -62,43 +50,11 @@ public class SpongeViaLoader implements ViaPlatformLoader {
public void load() {
// Update Listener
registerListener(new UpdateListener());
/* 1.9 client to 1.8 server */
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
try {
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
storeListener(new Sponge4ArmorListener()).register();
} catch (ClassNotFoundException e) {
storeListener(new Sponge5ArmorListener(plugin)).register();
}
storeListener(new DeathListener(plugin)).register();
storeListener(new BlockListener(plugin)).register();
if (plugin.getConf().isItemCache()) {
tasks.add(Via.getPlatform().runRepeatingSync(new HandItemCache(), 2L)); // Updates players items :)
HandItemCache.CACHE = true;
}
}
/* Providers */
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
@Override
public Item getHandItem(final UserConnection info) {
if (HandItemCache.CACHE) {
return HandItemCache.getHandItem(info.getProtocolInfo().getUuid());
} else {
return super.getHandItem(info);
}
}
});
}
}
public void unload() {
listeners.forEach(Sponge.getEventManager()::unregisterListeners);
listeners.forEach(Sponge.eventManager()::unregisterListeners);
listeners.clear();
tasks.forEach(PlatformTask::cancel);
tasks.clear();

View File

@ -18,17 +18,17 @@
package com.viaversion.viaversion.sponge.platform;
import com.viaversion.viaversion.api.platform.PlatformTask;
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.scheduler.ScheduledTask;
public class SpongeViaTask implements PlatformTask<Task> {
private final Task task;
public class SpongeViaTask implements PlatformTask<ScheduledTask> {
private final ScheduledTask task;
public SpongeViaTask(Task task) {
public SpongeViaTask(ScheduledTask task) {
this.task = task;
}
@Override
public Task getObject() {
public ScheduledTask getObject() {
return task;
}

View File

@ -1,62 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.sponge.providers;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import java.lang.reflect.Field;
public class SpongeViaMovementTransmitter extends MovementTransmitterProvider {
// Used for packet mode
private Object idlePacket;
private Object idlePacket2;
public SpongeViaMovementTransmitter() {
Class<?> idlePacketClass;
try {
idlePacketClass = Class.forName("net.minecraft.network.play.client.C03PacketPlayer");
} catch (ClassNotFoundException e) {
return; // We'll hope this is 1.9.4+
}
try {
idlePacket = idlePacketClass.newInstance();
idlePacket2 = idlePacketClass.newInstance();
Field flying = idlePacketClass.getDeclaredField("field_149474_g");
flying.setAccessible(true);
flying.set(idlePacket2, true);
} catch (NoSuchFieldException | InstantiationException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Couldn't make player idle packet, help!", e);
}
}
@Override
public Object getFlyingPacket() {
if (idlePacket == null)
throw new NullPointerException("Could not locate flying packet");
return idlePacket2;
}
@Override
public Object getGroundPacket() {
if (idlePacket == null)
throw new NullPointerException("Could not locate flying packet");
return idlePacket;
}
}

View File

@ -4,37 +4,33 @@
"version": "1.0"
},
"license": "GNU GPLv3",
"plugins": [
{
"id": "viaversion",
"name": "ViaVersion",
"global": {
"version": "${version}",
"description": "${description}",
"entrypoint": "com.viaversion.viaversion.SpongePlugin",
"branding": {
"logo": "assets/viaversion/textures/logo.png",
"icon": "assets/viaversion/textures/logo.png"
},
"links": {
"homepage": "https://www.spigotmc.org/resources/viaversion.19254/",
"homepage": "https://viaversion.com/",
"source": "https://github.com/ViaVersion/ViaVersion",
"issues": "https://github.com/ViaVersion/ViaVersion"
"issues": "https://github.com/ViaVersion/ViaVersion/issues"
},
"contributors": [
{
"name": "_MylesC"
"name": "_MylesC",
"description": "Maintainer"
},
{
"name": "creeper123123321"
"name": "creeper123123321",
"description": "Contributor"
},
{
"name": "Gerrygames"
"name": "Gerrygames",
"description": "Contributor"
},
{
"name": "kennytv"
"name": "kennytv",
"description": "Maintainer"
},
{
"name": "Matsv"
"name": "Matsv",
"description": "Contributor"
}
],
"dependencies": [
@ -42,7 +38,17 @@
"id": "spongeapi",
"version": "8.0.0"
}
]
],
"branding": {
"logo": "assets/viaversion/textures/logo.png"
}
},
"plugins": [
{
"id": "viaversion",
"name": "ViaVersion",
"entrypoint": "com.viaversion.viaversion.SpongePlugin",
"description": "${description}"
}
]
}

View File

@ -1,16 +0,0 @@
[
{
"modid": "viaversion",
"name": "ViaVersion",
"version": "${version}",
"description": "${description}",
"authorList": [
"_MylesC",
"creeper123123321",
"Gerrygames",
"kennytv",
"Matsv"
],
"logoFile": "assets/viaversion/textures/logo.png"
}
]

View File

@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.configuration.AbstractViaConfig;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -47,11 +46,6 @@ public class VelocityViaConfig extends AbstractViaConfig {
velocityServerProtocols = get("velocity-servers", Map.class, new HashMap<>());
}
@Override
public URL getDefaultConfigURL() {
return getClass().getClassLoader().getResource("assets/viaversion/config.yml");
}
@Override
protected void handleConfig(Map<String, Object> config) {
// Parse servers