3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Initial update to api-8

Dieser Commit ist enthalten in:
Konicai 2021-12-23 14:46:24 -05:00 committet von Nassim Jahnke
Ursprung 755a69e912
Commit 2a1e82ac6d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
16 geänderte Dateien mit 187 neuen und 116 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -37,31 +37,32 @@ import com.viaversion.viaversion.sponge.platform.SpongeViaLoader;
import com.viaversion.viaversion.sponge.util.LoggerWrapper; import com.viaversion.viaversion.sponge.util.LoggerWrapper;
import com.viaversion.viaversion.util.ChatColorUtil; import com.viaversion.viaversion.util.ChatColorUtil;
import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.VersionInfo; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
import org.spongepowered.api.config.DefaultConfig; import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
import org.spongepowered.api.event.game.state.GameInitializationEvent; import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent; import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
@Plugin(id = "viaversion", @Plugin("viaversion")
name = "ViaVersion",
version = VersionInfo.VERSION,
authors = {"_MylesC", "creeper123123321", "Gerrygames", "kennytv", "Matsv"},
description = "Allow newer Minecraft versions to connect to an older server version."
)
public class SpongePlugin implements ViaPlatform<Player> { public class SpongePlugin implements ViaPlatform<Player> {
@Inject @Inject
private Game game; private Game game;
@ -79,7 +80,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Listener @Listener
public void onGameStart(GameInitializationEvent event) { public void onGameStart(GameInitializationEvent event) {
// Setup Logger // Setup Logger
logger = new LoggerWrapper(container.getLogger()); logger = new LoggerWrapper(container.logger());
// Setup Plugin // Setup Plugin
conf = new SpongeViaConfig(container, spongeConfig.getParentFile()); conf = new SpongeViaConfig(container, spongeConfig.getParentFile());
SpongeCommandHandler commandHandler = new SpongeCommandHandler(); SpongeCommandHandler commandHandler = new SpongeCommandHandler();
@ -97,7 +98,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Listener @Listener
public void onServerStart(GameAboutToStartServerEvent event) { public void onServerStart(GameAboutToStartServerEvent event) {
if (game.getPluginManager().getPlugin("viabackwards").isPresent()) { if (game.pluginManager().plugin("viabackwards").isPresent()) {
MappingDataLoader.enableMappingsCache(); MappingDataLoader.enableMappingsCache();
} }
@ -107,23 +108,30 @@ public class SpongePlugin implements ViaPlatform<Player> {
} }
@Listener @Listener
public void onServerStop(GameStoppingServerEvent event) { public void onServerStop(StoppingEngineEvent<?> event) {
((ViaManagerImpl) Via.getManager()).destroy(); ((ViaManagerImpl) Via.getManager()).destroy();
} }
@Override @Override
public String getPlatformName() { public String getPlatformName() {
return game.getPlatform().getImplementation().getName(); return game.platform().container(Platform.Component.IMPLEMENTATION).metadata().name().orElse("unknown");
} }
@Override @Override
public String getPlatformVersion() { public String getPlatformVersion() {
return game.getPlatform().getImplementation().getVersion().orElse("Unknown Version"); return readVersion(game.platform().container(Platform.Component.IMPLEMENTATION).metadata().version());
} }
@Override @Override
public String getPluginVersion() { public String getPluginVersion() {
return container.getVersion().orElse("Unknown Version"); 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;
} }
@Override @Override
@ -167,9 +175,9 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Override @Override
public ViaCommandSender[] getOnlinePlayers() { public ViaCommandSender[] getOnlinePlayers() {
ViaCommandSender[] array = new ViaCommandSender[game.getServer().getOnlinePlayers().size()]; ViaCommandSender[] array = new ViaCommandSender[game.server().onlinePlayers().size()];
int i = 0; int i = 0;
for (Player player : game.getServer().getOnlinePlayers()) { for (Player player : game.server().onlinePlayers()) {
array[i++] = new SpongeCommandSender(player); array[i++] = new SpongeCommandSender(player);
} }
return array; return array;
@ -178,12 +186,12 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Override @Override
public void sendMessage(UUID uuid, String message) { public void sendMessage(UUID uuid, String message) {
String serialized = SpongePlugin.COMPONENT_SERIALIZER.serialize(SpongePlugin.COMPONENT_SERIALIZER.deserialize(message)); String serialized = SpongePlugin.COMPONENT_SERIALIZER.serialize(SpongePlugin.COMPONENT_SERIALIZER.deserialize(message));
game.getServer().getPlayer(uuid).ifPresent(player -> player.sendMessage(TextSerializers.JSON.deserialize(serialized))); // Hacky way to fix links game.server().player(uuid).ifPresent(player -> player.sendMessage(TextSerializers.JSON.deserialize(serialized))); // Hacky way to fix links
} }
@Override @Override
public boolean kickPlayer(UUID uuid, String message) { public boolean kickPlayer(UUID uuid, String message) {
return game.getServer().getPlayer(uuid).map(player -> { return game.server().player(uuid).map(player -> {
player.kick(TextSerializers.formattingCode(ChatColorUtil.COLOR_CHAR).deserialize(message)); player.kick(TextSerializers.formattingCode(ChatColorUtil.COLOR_CHAR).deserialize(message));
return true; return true;
}).orElse(false); }).orElse(false);
@ -214,13 +222,14 @@ public class SpongePlugin implements ViaPlatform<Player> {
JsonObject platformSpecific = new JsonObject(); JsonObject platformSpecific = new JsonObject();
List<PluginInfo> plugins = new ArrayList<>(); List<PluginInfo> plugins = new ArrayList<>();
for (PluginContainer p : game.getPluginManager().getPlugins()) { for (PluginContainer p : game.pluginManager().plugins()) {
PluginMetadata meta = p.metadata();
plugins.add(new PluginInfo( plugins.add(new PluginInfo(
true, true,
p.getName(), meta.name().orElse("Unknown"),
p.getVersion().orElse("Unknown Version"), readVersion(meta.version()),
p.getInstance().isPresent() ? p.getInstance().get().getClass().getCanonicalName() : "Unknown", p.instance() != null ? p.instance().getClass().getCanonicalName() : "Unknown",
p.getAuthors() meta.contributors().stream().map(PluginContributor::name).collect(Collectors.toList())
)); ));
} }
platformSpecific.add("plugins", GsonUtil.getGson().toJsonTree(plugins)); platformSpecific.add("plugins", GsonUtil.getGson().toJsonTree(plugins));
@ -247,4 +256,9 @@ public class SpongePlugin implements ViaPlatform<Player> {
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
} }
public PluginContainer getPluginContainer() {
return container;
}
} }

Datei anzeigen

@ -18,53 +18,55 @@
package com.viaversion.viaversion.sponge.commands; package com.viaversion.viaversion.sponge.commands;
import com.viaversion.viaversion.commands.ViaCommandHandler; import com.viaversion.viaversion.commands.ViaCommandHandler;
import org.checkerframework.checker.nullness.qual.Nullable; import net.kyori.adventure.text.Component;
import org.spongepowered.api.command.CommandCallable; import org.jetbrains.annotations.NotNull;
import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.Command;
import org.spongepowered.api.command.CommandCompletion;
import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.text.Text; import org.spongepowered.api.command.parameter.ArgumentReader;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
public class SpongeCommandHandler extends ViaCommandHandler implements CommandCallable { public class SpongeCommandHandler extends ViaCommandHandler implements Command.Raw {
@Override @Override
public CommandResult process(CommandSource source, String arguments) throws CommandException { public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) {
String[] args = arguments.length() > 0 ? arguments.split(" ") : new String[0]; String[] args = arguments.input().length() > 0 ? arguments.input().split(" ") : new String[0];
onCommand(new SpongeCommandSender(source), args); onCommand(new SpongeCommandSender(cause), args);
return CommandResult.success(); return CommandResult.success();
} }
public List<String> getSuggestions(CommandSource commandSource, String s, @Nullable Location<World> location) throws CommandException { @Override
return getSuggestions(commandSource, s); public List<CommandCompletion> complete(CommandCause cause, ArgumentReader.Mutable arguments) {
} String[] args = arguments.input().split(" ", -1); // ViaCommandHandler handles empty String in array. -1: do not discard empty strings
return onTabComplete(new SpongeCommandSender(cause), args).stream().map(CommandCompletion::of).collect(Collectors.toList());
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
String[] args = arguments.split(" ", -1); // ViaCommandHandler handles empty String in array. -1: do not discard empty strings
return onTabComplete(new SpongeCommandSender(source), args);
} }
@Override @Override
public boolean testPermission(CommandSource source) { public boolean canExecute(CommandCause cause) {
return source.hasPermission("viaversion.admin"); return cause.hasPermission("viaversion.admin");
} }
@Override @Override
public Optional<Text> getShortDescription(CommandSource source) { public Optional<Component> shortDescription(CommandCause cause) {
return Optional.of(Text.of("Shows ViaVersion Version and more.")); return Optional.of(Component.text("Shows ViaVersion Version and more."));
} }
@Override @Override
public Optional<Text> getHelp(CommandSource source) { public Optional<Component> extendedDescription(CommandCause cause) {
return shortDescription(cause);
}
@Override
public Optional<Component> help(@NotNull CommandCause cause) {
return Optional.empty(); return Optional.empty();
} }
@Override @Override
public Text getUsage(CommandSource source) { public Component usage(CommandCause cause) {
return Text.of("Usage /viaversion"); return Component.text("Usage /viaversion");
} }
} }

Datei anzeigen

@ -19,16 +19,15 @@ package com.viaversion.viaversion.sponge.commands;
import com.viaversion.viaversion.SpongePlugin; import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaCommandSender;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Identifiable; import org.spongepowered.api.util.Identifiable;
import java.util.UUID; import java.util.UUID;
public class SpongeCommandSender implements ViaCommandSender { public class SpongeCommandSender implements ViaCommandSender {
private final CommandSource source; private final CommandCause source;
public SpongeCommandSender(CommandSource source) { public SpongeCommandSender(CommandCause source) {
this.source = source; this.source = source;
} }
@ -46,7 +45,7 @@ public class SpongeCommandSender implements ViaCommandSender {
@Override @Override
public UUID getUUID() { public UUID getUUID() {
if (source instanceof Identifiable) { if (source instanceof Identifiable) {
return ((Identifiable) source).getUniqueId(); return ((Identifiable) source).uniqueId();
} else { } else {
return UUID.fromString(getName()); return UUID.fromString(getName());
} }
@ -55,6 +54,6 @@ public class SpongeCommandSender implements ViaCommandSender {
@Override @Override
public String getName() { public String getName() {
return source.getName(); return source.friendlyIdentifier().orElse(source.identifier());
} }
} }

Datei anzeigen

@ -20,14 +20,13 @@ package com.viaversion.viaversion.sponge.listeners;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.update.UpdateUtil; import com.viaversion.viaversion.update.UpdateUtil;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ClientConnectionEvent; import org.spongepowered.api.event.network.ServerSideConnectionEvent;
public class UpdateListener { public class UpdateListener {
@Listener @Listener
public void onJoin(ClientConnectionEvent.Join join) { public void onJoin(ServerSideConnectionEvent.Join join) {
if (join.getTargetEntity().hasPermission("viaversion.update") if (join.player().hasPermission("viaversion.update") && Via.getConfig().isCheckForUpdates()) {
&& Via.getConfig().isCheckForUpdates()) { UpdateUtil.sendUpdateMessage(join.player().uniqueId());
UpdateUtil.sendUpdateMessage(join.getTargetEntity().getUniqueId());
} }
} }
} }

Datei anzeigen

@ -40,7 +40,7 @@ public class ViaSpongeListener extends ViaListener {
public void register() { public void register() {
if (isRegistered()) return; if (isRegistered()) return;
Sponge.getEventManager().registerListeners(plugin, this); Sponge.eventManager().registerListeners(plugin.getPluginContainer(), this);
setRegistered(true); setRegistered(true);
} }
@ -61,8 +61,4 @@ public class ViaSpongeListener extends ViaListener {
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github"); Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
return -1; return -1;
} }
public SpongePlugin getPlugin() {
return plugin;
}
} }

Datei anzeigen

@ -18,16 +18,19 @@
package com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8; package com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.SpongePlugin; import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.Position; 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.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener; 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.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent; import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.filter.cause.Root; import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.world.Location; import org.spongepowered.api.world.server.ServerLocation;
import java.util.Optional;
public class BlockListener extends ViaSpongeListener { public class BlockListener extends ViaSpongeListener {
@ -36,11 +39,17 @@ public class BlockListener extends ViaSpongeListener {
} }
@Listener @Listener
public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) { public void placeBlock(ChangeBlockEvent.All e, @Root Player player) {
if (isOnPipe(player.getUniqueId())) { BlockTransaction transaction = e.transactions().get(0);
Location loc = e.getTransactions().get(0).getFinal().getLocation().get(); if (transaction.operation().equals(Operations.PLACE.get())) {
EntityTracker1_9 tracker = getUserConnection(player.getUniqueId()).getEntityTracker(Protocol1_9To1_8.class); if (isOnPipe(player.uniqueId())) {
tracker.addBlockInteraction(new Position(loc.getBlockX(), (short) loc.getBlockY(), loc.getBlockZ())); 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()));
}
}
} }
} }
} }

Datei anzeigen

@ -24,6 +24,7 @@ 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.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener; 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.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order; import org.spongepowered.api.event.Order;
@ -39,17 +40,17 @@ public class DeathListener extends ViaSpongeListener {
@Listener(order = Order.LAST) @Listener(order = Order.LAST)
public void onDeath(DestructEntityEvent.Death e) { public void onDeath(DestructEntityEvent.Death e) {
if (!(e.getTargetEntity() instanceof Player)) if (!(e.entity() instanceof Player))
return; return;
Player p = (Player) e.getTargetEntity(); Player p = (Player) e.entity();
if (isOnPipe(p.getUniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) { if (isOnPipe(p.uniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) {
sendPacket(p, e.getMessage().toPlain()); sendPacket(p, PlainTextComponentSerializer.plainText().serialize(e.message()));
} }
} }
public boolean checkGamerule(World w) { public boolean checkGamerule(World w) {
Optional<String> gamerule = w.getGameRule("showDeathMessages"); Optional<String> gamerule = w.gameRule("showDeathMessages");
if (gamerule.isPresent()) { if (gamerule.isPresent()) {
try { try {

Datei anzeigen

@ -58,9 +58,9 @@ public class HandItemCache implements Runnable {
public void run() { public void run() {
List<UUID> players = new ArrayList<>(handCache.keySet()); List<UUID> players = new ArrayList<>(handCache.keySet());
for (Player p : Sponge.getServer().getOnlinePlayers()) { for (Player p : Sponge.server().onlinePlayers()) {
handCache.put(p.getUniqueId(), convert(grabber.getItem(p))); handCache.put(p.uniqueId(), convert(grabber.getItem(p)));
players.remove(p.getUniqueId()); players.remove(p.uniqueId());
} }
// Remove offline players // Remove offline players
for (UUID uuid : players) { for (UUID uuid : players) {
@ -105,7 +105,7 @@ public class HandItemCache implements Runnable {
e.printStackTrace(); e.printStackTrace();
} }
} }
return new DataItem(id, (byte) itemInHand.getQuantity(), (short) damage, null); return new DataItem(id, (byte) itemInHand.quantity(), (short) damage, null);
} }
} }

Datei anzeigen

@ -29,15 +29,15 @@ import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.InteractEvent; 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.MoveEntityEvent;
import org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent; import org.spongepowered.api.event.entity.living.player.RespawnPlayerEvent;
import org.spongepowered.api.event.filter.cause.Root; import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; import org.spongepowered.api.event.item.inventory.container.ClickContainerEvent;
import org.spongepowered.api.event.network.ClientConnectionEvent; import org.spongepowered.api.event.network.ServerSideConnectionEvent;
import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; import org.spongepowered.api.item.inventory.transaction.SlotTransaction;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class Sponge5ArmorListener extends ViaSpongeListener { public class Sponge5ArmorListener extends ViaSpongeListener {
@ -50,14 +50,14 @@ public class Sponge5ArmorListener extends ViaSpongeListener {
// //
public void sendArmorUpdate(Player player) { public void sendArmorUpdate(Player player) {
// Ensure that the player is on our pipe // Ensure that the player is on our pipe
if (!isOnPipe(player.getUniqueId())) return; if (!isOnPipe(player.uniqueId())) return;
int armor = 0; int armor = 0;
armor += calculate(player.getHelmet()); armor += calculate(player.head());
armor += calculate(player.getChestplate()); armor += calculate(player.chest());
armor += calculate(player.getLeggings()); armor += calculate(player.legs());
armor += calculate(player.getBoots()); armor += calculate(player.feet());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player.getUniqueId())); PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player.getUniqueId()));
try { try {
@ -76,18 +76,19 @@ public class Sponge5ArmorListener extends ViaSpongeListener {
} }
} }
private int calculate(Optional<ItemStack> itemStack) { private int calculate(ItemStack itemStack) {
if (itemStack.isPresent()) if (itemStack != null) {
return ArmorType.findByType(itemStack.get().getItem().getType().getId()).getArmorPoints(); // todo
return ArmorType.findByType(itemStack.type()).getArmorPoints();
}
return 0; return 0;
} }
@Listener @Listener
public void onInventoryClick(ClickInventoryEvent e, @Root Player player) { public void onContainerClick(ClickContainerEvent e, @Root Player player) {
for (SlotTransaction transaction : e.getTransactions()) { for (SlotTransaction transaction : e.transactions()) {
if (ArmorType.isArmor(transaction.getFinal().getType().getId()) || if (ArmorType.isArmor(transaction.finalReplacement().type()) ||
ArmorType.isArmor(e.getCursorTransaction().getFinal().getType().getId())) { ArmorType.isArmor(e.cursorTransaction().finalReplacement().type())) {
sendDelayedArmorUpdate(player); sendDelayedArmorUpdate(player);
break; break;
} }
@ -96,32 +97,34 @@ public class Sponge5ArmorListener extends ViaSpongeListener {
@Listener @Listener
public void onInteract(InteractEvent event, @Root Player player) { public void onInteract(InteractEvent event, @Root Player player) {
if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) { if (player.itemInHand(HandTypes.MAIN_HAND) != null) {
if (ArmorType.isArmor(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getId())) if (ArmorType.isArmor(player.itemInHand(HandTypes.MAIN_HAND).type()))
sendDelayedArmorUpdate(player); sendDelayedArmorUpdate(player);
} }
} }
@Listener @Listener
public void onJoin(ClientConnectionEvent.Join e) { public void onJoin(ServerSideConnectionEvent.Join e) {
sendArmorUpdate(e.getTargetEntity()); sendArmorUpdate(e.player());
} }
@Listener @Listener
public void onRespawn(RespawnPlayerEvent e) { public void onRespawn(RespawnPlayerEvent e) {
sendDelayedArmorUpdate(e.getTargetEntity()); sendDelayedArmorUpdate(e.entity());
} }
@Listener @Listener
public void onWorldChange(MoveEntityEvent.Teleport e) { public void onWorldChange(MoveEntityEvent e) {
if (!(e.getTargetEntity() instanceof Player)) return; if (!(e.entity() instanceof Player)) return;
if (!e.getFromTransform().getExtent().getUniqueId().equals(e.getToTransform().getExtent().getUniqueId())) { if (!e.cause().contains(MovementTypes.ENTITY_TELEPORT)) return; //todo: probably doesn't work
sendArmorUpdate((Player) e.getTargetEntity());
if (!e.originalDestinationPosition().getExtent().getUniqueId().equals(e.destinationPosition().getExtent().getUniqueId())) {
sendArmorUpdate((Player) e.entity());
} }
} }
public void sendDelayedArmorUpdate(final Player player) { public void sendDelayedArmorUpdate(final Player player) {
if (!isOnPipe(player.getUniqueId())) return; // Don't start a task if the player is not on the pipe if (!isOnPipe(player.uniqueId())) return; // Don't start a task if the player is not on the pipe
Via.getPlatform().runSync(new Runnable() { Via.getPlatform().runSync(new Runnable() {
@Override @Override
public void run() { public void run() {

Datei anzeigen

@ -25,6 +25,6 @@ import org.spongepowered.api.item.inventory.ItemStack;
public class Sponge5ItemGrabber implements ItemGrabber { public class Sponge5ItemGrabber implements ItemGrabber {
@Override @Override
public ItemStack getItem(Player player) { public ItemStack getItem(Player player) {
return player.getItemInHand(HandTypes.MAIN_HAND).orElse(null); return player.itemInHand(HandTypes.MAIN_HAND);
} }
} }

Datei anzeigen

@ -25,11 +25,11 @@ public class SpongeViaAPI extends ViaAPIBase<Player> {
@Override @Override
public int getPlayerVersion(Player player) { public int getPlayerVersion(Player player) {
return getPlayerVersion(player.getUniqueId()); return getPlayerVersion(player.uniqueId());
} }
@Override @Override
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException { public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
sendRawPacket(player.getUniqueId(), packet); sendRawPacket(player.uniqueId(), packet);
} }
} }

Datei anzeigen

@ -19,7 +19,7 @@ package com.viaversion.viaversion.sponge.platform;
import com.viaversion.viaversion.configuration.AbstractViaConfig; import com.viaversion.viaversion.configuration.AbstractViaConfig;
import org.spongepowered.api.asset.Asset; import org.spongepowered.api.asset.Asset;
import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.plugin.PluginContainer;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -46,7 +46,7 @@ public class SpongeViaConfig extends AbstractViaConfig {
if (!config.isPresent()) { if (!config.isPresent()) {
throw new IllegalArgumentException("Default config is missing from jar"); throw new IllegalArgumentException("Default config is missing from jar");
} }
return config.get().getUrl(); return config.get().url();
} }
@Override @Override

Datei anzeigen

@ -33,7 +33,7 @@ public class SpongeViaInjector extends LegacyViaInjector {
@Override @Override
public int getServerProtocolVersion() throws ReflectiveOperationException { public int getServerProtocolVersion() throws ReflectiveOperationException {
MinecraftVersion version = Sponge.getPlatform().getMinecraftVersion(); MinecraftVersion version = Sponge.platform().minecraftVersion();
return (int) version.getClass().getDeclaredMethod("getProtocol").invoke(version); return (int) version.getClass().getDeclaredMethod("getProtocol").invoke(version);
} }
@ -42,7 +42,7 @@ public class SpongeViaInjector extends LegacyViaInjector {
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer"); Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
for (Method method : serverClazz.getDeclaredMethods()) { for (Method method : serverClazz.getDeclaredMethods()) {
if (method.getReturnType().getSimpleName().equals("NetworkSystem") && method.getParameterTypes().length == 0) { if (method.getReturnType().getSimpleName().equals("NetworkSystem") && method.getParameterTypes().length == 0) {
Object connection = method.invoke(Sponge.getServer()); Object connection = method.invoke(Sponge.server());
if (connection != null) { if (connection != null) {
return connection; return connection;
} }

Datei anzeigen

@ -17,7 +17,7 @@
*/ */
package com.viaversion.viaversion.sponge.util; package com.viaversion.viaversion.sponge.util;
import org.slf4j.Logger; import org.apache.logging.log4j.Logger;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.logging.Level; import java.util.logging.Level;

Datei anzeigen

@ -0,0 +1,48 @@
{
"loader": {
"name": "java_plain",
"version": "1.0"
},
"license": "GNU GPLv3",
"plugins": [
{
"id": "viaversion",
"name": "ViaVersion",
"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/",
"source": "https://github.com/ViaVersion/ViaVersion",
"issues": "https://github.com/ViaVersion/ViaVersion"
},
"contributors": [
{
"name": "_MylesC"
},
{
"name": "creeper123123321"
},
{
"name": "Gerrygames"
},
{
"name": "kennytv"
},
{
"name": "Matsv"
}
],
"dependencies": [
{
"id": "spongeapi",
"version": "8.0.0"
}
]
}
]
}