Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2025-01-11 23:51:00 +01:00
Move Sponge to API 5, add legacy support module
Dieser Commit ist enthalten in:
Ursprung
64cde13ea7
Commit
2a1f0f812b
1
pom.xml
1
pom.xml
@ -21,6 +21,7 @@
|
||||
<module>bungee</module>
|
||||
<module>sponge</module>
|
||||
<module>jar</module>
|
||||
<module>sponge-legacy</module>
|
||||
</modules>
|
||||
|
||||
<prerequisites>
|
||||
|
73
sponge-legacy/pom.xml
Normale Datei
73
sponge-legacy/pom.xml
Normale Datei
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>1.0.0-ALPHA-modules</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>viaversion-sponge-legacy</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sponge</id>
|
||||
<url>http://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>templating-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>filter-src</id>
|
||||
<goals>
|
||||
<goal>filter-sources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Common Module -->
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Sponge API API 4 -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
package us.myles.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);
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge4;
|
||||
|
||||
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 us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaListener;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
||||
import us.myles.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 = new PacketWrapper(0x4B, 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.send(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;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge4;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.ItemGrabber;
|
||||
|
||||
public class Sponge4ItemGrabber implements ItemGrabber {
|
||||
@Override
|
||||
public ItemStack getItem(Player player) {
|
||||
return player.getItemInHand().orElse(null);
|
||||
}
|
||||
}
|
@ -60,13 +60,21 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Sponge API -->
|
||||
<!-- Sponge API 5 -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>LATEST</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Legacy Support -->
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-sponge-legacy</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -5,8 +5,11 @@ import org.spongepowered.api.command.CommandException;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.world.Location;
|
||||
import org.spongepowered.api.world.World;
|
||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -19,7 +22,10 @@ public class SpongeCommandHandler extends ViaCommandHandler implements CommandCa
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource commandSource, String s, @Nullable Location<World> location) throws CommandException {
|
||||
return getSuggestions(commandSource, s);
|
||||
}
|
||||
|
||||
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
|
||||
String[] args = arguments.length() > 0 ? arguments.split(" ") : new String[0];
|
||||
return onTabComplete(new SpongeCommandSender(source), args);
|
||||
@ -31,12 +37,12 @@ public class SpongeCommandHandler extends ViaCommandHandler implements CommandCa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(CommandSource source) {
|
||||
public Optional<Text> getShortDescription(CommandSource source) {
|
||||
return Optional.of(Text.of("Shows ViaVersion Version and more."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(CommandSource source) {
|
||||
public Optional<Text> getHelp(CommandSource source) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge4.Sponge4ItemGrabber;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge5.Sponge5ItemGrabber;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -18,6 +20,16 @@ public class HandItemCache implements Runnable {
|
||||
private static ConcurrentHashMap<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) {
|
||||
if (!handCache.containsKey(player))
|
||||
@ -30,7 +42,7 @@ public class HandItemCache implements Runnable {
|
||||
List<UUID> players = new ArrayList<>(handCache.keySet());
|
||||
|
||||
for (Player p : Sponge.getServer().getOnlinePlayers()) {
|
||||
handCache.put(p.getUniqueId(), convert(p.getItemInHand().orElse(null)));
|
||||
handCache.put(p.getUniqueId(), convert(grabber.getItem(p)));
|
||||
players.remove(p.getUniqueId());
|
||||
}
|
||||
// Remove offline players
|
||||
|
@ -1,9 +1,10 @@
|
||||
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8;
|
||||
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge5;
|
||||
|
||||
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.entity.DisplaceEntityEvent;
|
||||
import org.spongepowered.api.event.entity.MoveEntityEvent;
|
||||
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;
|
||||
@ -21,10 +22,10 @@ import us.myles.ViaVersion.sponge.listeners.ViaSpongeListener;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArmorListener extends ViaSpongeListener {
|
||||
public class Sponge5ArmorListener extends ViaSpongeListener {
|
||||
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||
|
||||
public ArmorListener(SpongePlugin plugin) {
|
||||
public Sponge5ArmorListener(SpongePlugin plugin) {
|
||||
super(plugin, Protocol1_9TO1_8.class);
|
||||
}
|
||||
|
||||
@ -77,8 +78,8 @@ public class ArmorListener extends ViaSpongeListener {
|
||||
|
||||
@Listener
|
||||
public void onInteract(InteractEvent event, @Root Player player) {
|
||||
if (player.getItemInHand().isPresent()) {
|
||||
if (ArmorType.isArmor(player.getItemInHand().get().getItem().getId()))
|
||||
if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
|
||||
if (ArmorType.isArmor(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getId()))
|
||||
sendDelayedArmorUpdate(player);
|
||||
}
|
||||
}
|
||||
@ -94,7 +95,7 @@ public class ArmorListener extends ViaSpongeListener {
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onWorldChange(DisplaceEntityEvent.Teleport e) {
|
||||
public void onWorldChange(MoveEntityEvent.Teleport e) {
|
||||
if (!(e.getTargetEntity() instanceof Player)) return;
|
||||
if (!e.getFromTransform().getExtent().getUniqueId().equals(e.getToTransform().getExtent().getUniqueId())) {
|
||||
sendArmorUpdate((Player) e.getTargetEntity());
|
@ -0,0 +1,13 @@
|
||||
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge5;
|
||||
|
||||
import org.spongepowered.api.data.type.HandTypes;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.ItemGrabber;
|
||||
|
||||
public class Sponge5ItemGrabber implements ItemGrabber {
|
||||
@Override
|
||||
public ItemStack getItem(Player player) {
|
||||
return player.getItemInHand(HandTypes.MAIN_HAND).orElse(null);
|
||||
}
|
||||
}
|
@ -13,7 +13,12 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
import us.myles.ViaVersion.sponge.listeners.ClientLeaveListener;
|
||||
import us.myles.ViaVersion.sponge.listeners.UpdateListener;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.*;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.BlockListener;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.CommandBlockListener;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.DeathListener;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.HandItemCache;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge4.Sponge4ArmorListener;
|
||||
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge5.Sponge5ArmorListener;
|
||||
import us.myles.ViaVersion.sponge.providers.SpongeViaBulkChunkTranslator;
|
||||
import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter;
|
||||
|
||||
@ -28,7 +33,12 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
||||
/* Base Protocol */
|
||||
Sponge.getEventManager().registerListeners(plugin, new ClientLeaveListener());
|
||||
/* 1.9 client to 1.8 server */
|
||||
new ArmorListener(plugin).register();
|
||||
try {
|
||||
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
|
||||
new Sponge4ArmorListener().register();
|
||||
} catch (ClassNotFoundException e) {
|
||||
new Sponge5ArmorListener(plugin).register();
|
||||
}
|
||||
new CommandBlockListener(plugin).register();
|
||||
new DeathListener(plugin).register();
|
||||
new BlockListener(plugin).register();
|
||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren