diff --git a/pom.xml b/pom.xml
index c631f22ad..60a19b8c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,7 @@
bungee
sponge
jar
+ sponge-legacy
diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml
new file mode 100644
index 000000000..e0063d252
--- /dev/null
+++ b/sponge-legacy/pom.xml
@@ -0,0 +1,73 @@
+
+
+
+ viaversion-parent
+ us.myles
+ 1.0.0-ALPHA-modules
+
+ 4.0.0
+
+ viaversion-sponge-legacy
+ jar
+
+
+ 1.8
+ 1.8
+
+
+
+
+ sponge
+ http://repo.spongepowered.org/maven
+
+
+
+
+
+
+ .
+ true
+ src/main/resources/
+
+ *
+
+
+
+
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ filter-src
+
+ filter-sources
+
+
+
+
+
+
+
+
+
+
+ us.myles
+ viaversion-common
+ ${project.parent.version}
+ provided
+
+
+
+
+ org.spongepowered
+ spongeapi
+ 4.0.0-SNAPSHOT
+ provided
+
+
+
+
\ No newline at end of file
diff --git a/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/ItemGrabber.java b/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/ItemGrabber.java
new file mode 100644
index 000000000..8f1069caa
--- /dev/null
+++ b/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/ItemGrabber.java
@@ -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);
+}
diff --git a/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge4/Sponge4ArmorListener.java b/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge4/Sponge4ArmorListener.java
new file mode 100644
index 000000000..5b542bdb4
--- /dev/null
+++ b/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge4/Sponge4ArmorListener.java
@@ -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) {
+ 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;
+ }
+}
diff --git a/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge4/Sponge4ItemGrabber.java b/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge4/Sponge4ItemGrabber.java
new file mode 100644
index 000000000..17da6eb35
--- /dev/null
+++ b/sponge-legacy/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge4/Sponge4ItemGrabber.java
@@ -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);
+ }
+}
diff --git a/sponge/pom.xml b/sponge/pom.xml
index fb41d0443..f4a3ec61d 100644
--- a/sponge/pom.xml
+++ b/sponge/pom.xml
@@ -60,13 +60,21 @@
provided
-
+
org.spongepowered
spongeapi
- LATEST
+ 5.0.0-SNAPSHOT
provided
+
+
+
+ us.myles
+ viaversion-sponge-legacy
+ ${project.parent.version}
+ compile
+
\ No newline at end of file
diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java
index a28bcef55..109c56601 100644
--- a/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java
+++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java
@@ -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 getSuggestions(CommandSource commandSource, String s, @Nullable Location location) throws CommandException {
+ return getSuggestions(commandSource, s);
+ }
+
public List 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 getShortDescription(CommandSource source) {
return Optional.of(Text.of("Shows ViaVersion Version and more."));
}
@Override
- public Optional extends Text> getHelp(CommandSource source) {
+ public Optional getHelp(CommandSource source) {
return Optional.empty();
}
diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java
index 2a60aadcc..e2d61fcaa 100644
--- a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java
+++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java
@@ -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 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 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
diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/ArmorListener.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge5/Sponge5ArmorListener.java
similarity index 88%
rename from sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/ArmorListener.java
rename to sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge5/Sponge5ArmorListener.java
index 2b6460f99..6052e86b5 100644
--- a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/ArmorListener.java
+++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge5/Sponge5ArmorListener.java
@@ -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());
diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge5/Sponge5ItemGrabber.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge5/Sponge5ItemGrabber.java
new file mode 100644
index 000000000..f9128ec86
--- /dev/null
+++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/sponge5/Sponge5ItemGrabber.java
@@ -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);
+ }
+}
diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java
index 98f1d39d5..ebe1c398f 100644
--- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java
+++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java
@@ -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();