Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Reflector Main Class and add API framework.
Dieser Commit ist enthalten in:
Ursprung
8ceee31299
Commit
bd46c3f5a0
@ -8,18 +8,31 @@ import io.netty.channel.socket.SocketChannel;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
|
import us.myles.ViaVersion.api.ViaVersionAPI;
|
||||||
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Core extends JavaPlugin {
|
public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
||||||
|
|
||||||
|
private final Set<UUID> portedPlayers = Collections.newSetFromMap(new ConcurrentHashMap<UUID, Boolean>());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
ViaVersion.setInstance(this);
|
||||||
System.out.println("ViaVersion enabled, injecting. (Allows 1.8 to be accessed via 1.9)");
|
System.out.println("ViaVersion enabled, injecting. (Allows 1.8 to be accessed via 1.9)");
|
||||||
try {
|
try {
|
||||||
injectPacketHandler();
|
injectPacketHandler();
|
||||||
@ -30,6 +43,12 @@ public class Core extends JavaPlugin {
|
|||||||
System.out.println("Unable to inject handlers, are you on 1.8? ");
|
System.out.println("Unable to inject handlers, are you on 1.8? ");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
|
setPorted(e.getPlayer().getUniqueId(), false);
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectPacketHandler() throws Exception {
|
public void injectPacketHandler() throws Exception {
|
||||||
@ -51,10 +70,22 @@ public class Core extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPorted(Player player) {
|
||||||
|
return portedPlayers.contains(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPorted(UUID id, boolean value) {
|
||||||
|
if (value) {
|
||||||
|
portedPlayers.add(id);
|
||||||
|
} else {
|
||||||
|
portedPlayers.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Entity getEntity(final UUID player, final int id) {
|
public static Entity getEntity(final UUID player, final int id) {
|
||||||
try {
|
try {
|
||||||
return Bukkit.getScheduler().callSyncMethod(getPlugin(Core.class), new Callable<Entity>() {
|
return Bukkit.getScheduler().callSyncMethod(getPlugin(ViaVersionPlugin.class), new Callable<Entity>() {
|
||||||
@Override
|
@Override
|
||||||
public Entity call() throws Exception {
|
public Entity call() throws Exception {
|
||||||
Player p = Bukkit.getPlayer(player);
|
Player p = Bukkit.getPlayer(player);
|
||||||
@ -76,7 +107,7 @@ public class Core extends JavaPlugin {
|
|||||||
|
|
||||||
public static ItemStack getHandItem(final ConnectionInfo info) {
|
public static ItemStack getHandItem(final ConnectionInfo info) {
|
||||||
try {
|
try {
|
||||||
return Bukkit.getScheduler().callSyncMethod(getPlugin(Core.class), new Callable<ItemStack>() {
|
return Bukkit.getScheduler().callSyncMethod(getPlugin(ViaVersionPlugin.class), new Callable<ItemStack>() {
|
||||||
@Override
|
@Override
|
||||||
public ItemStack call() throws Exception {
|
public ItemStack call() throws Exception {
|
||||||
if (info.getPlayer() != null) {
|
if (info.getPlayer() != null) {
|
17
src/main/java/us/myles/ViaVersion/api/ViaVersion.java
Normale Datei
17
src/main/java/us/myles/ViaVersion/api/ViaVersion.java
Normale Datei
@ -0,0 +1,17 @@
|
|||||||
|
package us.myles.ViaVersion.api;
|
||||||
|
|
||||||
|
public class ViaVersion {
|
||||||
|
|
||||||
|
private static ViaVersionAPI INSTANCE;
|
||||||
|
|
||||||
|
public static void setInstance(ViaVersionAPI api) {
|
||||||
|
if (INSTANCE != null) {
|
||||||
|
throw new IllegalStateException("Instance already set.");
|
||||||
|
}
|
||||||
|
INSTANCE = api;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViaVersionAPI getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
8
src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java
Normale Datei
8
src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java
Normale Datei
@ -0,0 +1,8 @@
|
|||||||
|
package us.myles.ViaVersion.api;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface ViaVersionAPI {
|
||||||
|
|
||||||
|
boolean isPorted(Player player);
|
||||||
|
}
|
@ -178,7 +178,7 @@ public class IncomingTransformer {
|
|||||||
output.writeByte(face);
|
output.writeByte(face);
|
||||||
int hand = PacketUtil.readVarInt(input);
|
int hand = PacketUtil.readVarInt(input);
|
||||||
|
|
||||||
ItemStack inHand = Core.getHandItem(info);
|
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
||||||
Object item = null;
|
Object item = null;
|
||||||
try {
|
try {
|
||||||
Method m = ReflectionUtil.obc("inventory.CraftItemStack").getDeclaredMethod("asNMSCopy", ItemStack.class);
|
Method m = ReflectionUtil.obc("inventory.CraftItemStack").getDeclaredMethod("asNMSCopy", ItemStack.class);
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
||||||
import org.spacehq.mc.protocol.util.NetUtil;
|
import org.spacehq.mc.protocol.util.NetUtil;
|
||||||
import us.myles.ViaVersion.*;
|
import us.myles.ViaVersion.*;
|
||||||
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
|
||||||
import us.myles.ViaVersion.metadata.MetaIndex;
|
import us.myles.ViaVersion.metadata.MetaIndex;
|
||||||
import us.myles.ViaVersion.metadata.NewType;
|
import us.myles.ViaVersion.metadata.NewType;
|
||||||
@ -29,6 +30,7 @@ public class OutgoingTransformer {
|
|||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private final ConnectionInfo info;
|
private final ConnectionInfo info;
|
||||||
private final ViaVersionInitializer init;
|
private final ViaVersionInitializer init;
|
||||||
|
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
private Map<Integer, UUID> uuidMap = new HashMap<Integer, UUID>();
|
private Map<Integer, UUID> uuidMap = new HashMap<Integer, UUID>();
|
||||||
|
|
||||||
@ -177,7 +179,9 @@ public class OutgoingTransformer {
|
|||||||
if (packet == PacketType.LOGIN_SUCCESS) {
|
if (packet == PacketType.LOGIN_SUCCESS) {
|
||||||
String uu = PacketUtil.readString(input);
|
String uu = PacketUtil.readString(input);
|
||||||
PacketUtil.writeString(uu, output);
|
PacketUtil.writeString(uu, output);
|
||||||
info.setUUID(UUID.fromString(uu));
|
UUID uniqueId = UUID.fromString(uu);
|
||||||
|
info.setUUID(uniqueId);
|
||||||
|
plugin.setPorted(uniqueId, true);
|
||||||
output.writeBytes(input);
|
output.writeBytes(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -205,7 +209,7 @@ public class OutgoingTransformer {
|
|||||||
try {
|
try {
|
||||||
List dw = ReflectionUtil.get(info.getLastPacket(), "b", List.class);
|
List dw = ReflectionUtil.get(info.getLastPacket(), "b", List.class);
|
||||||
// get entity via entityID, not preferred but we need it.
|
// get entity via entityID, not preferred but we need it.
|
||||||
Entity entity = Core.getEntity(info.getUUID(), id);
|
Entity entity = ViaVersionPlugin.getEntity(info.getUUID(), id);
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
transformMetadata(entity, dw, output);
|
transformMetadata(entity, dw, output);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
name: ViaVersion
|
name: ViaVersion
|
||||||
main: us.myles.ViaVersion.Core
|
main: us.myles.ViaVersion.ViaVersionPlugin
|
||||||
author: _MylesC
|
author: _MylesC
|
||||||
version: 0.3.4
|
version: 0.3.4
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren