♻️ Improved the API
This commit is contained in:
parent
2c65469bfb
commit
bfaa99e5dd
29 changed files with 444 additions and 341 deletions
29
API/pom.xml
29
API/pom.xml
|
@ -1,4 +1,27 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ This file is part of MapReflectionAPI.
|
||||||
|
~ Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
~
|
||||||
|
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
~ of this software and associated documentation files (the "Software"), to deal
|
||||||
|
~ in the Software without restriction, including without limitation the rights
|
||||||
|
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
~ copies of the Software, and to permit persons to whom the Software is
|
||||||
|
~ furnished to do so, subject to the following conditions:
|
||||||
|
~
|
||||||
|
~ The above copyright notice and this permission notice shall be included in all
|
||||||
|
~ copies or substantial portions of the Software.
|
||||||
|
~
|
||||||
|
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
~ SOFTWARE.
|
||||||
|
-->
|
||||||
|
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
@ -62,6 +85,12 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
@ -61,15 +61,19 @@ public class MapReflectionAPI extends JavaPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info("Initializing the packet handler...");
|
try {
|
||||||
packetListener = PacketListener.construct();
|
packetListener = PacketListener.construct(this);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
packetListener.init(this);
|
packetListener.init(this);
|
||||||
|
|
||||||
getLogger().info("Initializing the map manager...");
|
|
||||||
try {
|
try {
|
||||||
mapManager = new MapManager();
|
mapManager = new MapManager(this);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
e.printStackTrace();
|
getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ package tech.sbdevelopment.mapreflectionapi.api;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
|
@ -41,10 +42,12 @@ public class MapManager {
|
||||||
private final List<MapWrapper> MANAGED_MAPS = new CopyOnWriteArrayList<>();
|
private final List<MapWrapper> MANAGED_MAPS = new CopyOnWriteArrayList<>();
|
||||||
private final Class<?> wrapperClass;
|
private final Class<?> wrapperClass;
|
||||||
|
|
||||||
public MapManager() throws IllegalStateException {
|
public MapManager(JavaPlugin plugin) throws IllegalStateException {
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
plugin.getLogger().info("Initializing the map manager for Minecraft version " + version + "...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Class<?> clazz = Class.forName("tech.sbdevelopment.mapreflectionapi.nms.MapWrapper_" + version);
|
final Class<?> clazz = Class.forName("tech.sbdevelopment.mapreflectionapi.nms.MapWrapper_" + version);
|
||||||
if (MapWrapper.class.isAssignableFrom(clazz)) {
|
if (MapWrapper.class.isAssignableFrom(clazz)) {
|
||||||
|
@ -53,7 +56,7 @@ public class MapManager {
|
||||||
throw new IllegalStateException("Plugin corrupted! Detected invalid MapWrapper class.");
|
throw new IllegalStateException("Plugin corrupted! Detected invalid MapWrapper class.");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new IllegalStateException("This Spigot version is not supported! Contact the developer to get support.");
|
throw new IllegalStateException("This Spigot version (" + version + ") is not supported! Contact the developer to get support.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +75,7 @@ public class MapManager {
|
||||||
|
|
||||||
private MapWrapper wrapNewImage(ArrayImage image) {
|
private MapWrapper wrapNewImage(ArrayImage image) {
|
||||||
try {
|
try {
|
||||||
MapWrapper wrapper = (MapWrapper) wrapperClass.getDeclaredConstructor().newInstance();
|
MapWrapper wrapper = (MapWrapper) wrapperClass.getDeclaredConstructor(ArrayImage.class).newInstance(image);
|
||||||
MANAGED_MAPS.add(wrapper);
|
MANAGED_MAPS.add(wrapper);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||||
|
|
|
@ -23,8 +23,16 @@
|
||||||
|
|
||||||
package tech.sbdevelopment.mapreflectionapi.api;
|
package tech.sbdevelopment.mapreflectionapi.api;
|
||||||
|
|
||||||
public interface MapWrapper {
|
public abstract class MapWrapper {
|
||||||
MapController getController();
|
protected ArrayImage content;
|
||||||
|
|
||||||
ArrayImage getContent();
|
public MapWrapper(ArrayImage image) {
|
||||||
|
this.content = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract MapController getController();
|
||||||
|
|
||||||
|
public ArrayImage getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,8 @@ public class MapInteractEvent extends Event implements Cancellable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemFrame getFrame() {
|
public ItemFrame getFrame() {
|
||||||
|
if (getMapWrapper() == null) return null;
|
||||||
|
|
||||||
if (frame == null) {
|
if (frame == null) {
|
||||||
frame = getMapWrapper().getController().getItemFrameById(player.getWorld(), entityID);
|
frame = getMapWrapper().getController().getItemFrameById(player.getWorld(), entityID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,26 +31,25 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public abstract class PacketListener implements Listener {
|
public abstract class PacketListener implements Listener {
|
||||||
protected JavaPlugin plugin;
|
protected JavaPlugin plugin;
|
||||||
|
|
||||||
public static PacketListener construct() {
|
public static PacketListener construct(JavaPlugin plugin) throws IllegalStateException {
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
plugin.getLogger().info("Initializing the packet handler for Minecraft version " + version + "...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Class<?> clazz = Class.forName("tech.sbdevelopment.mapreflectionapi.nms.MapWrapper_" + version);
|
final Class<?> clazz = Class.forName("tech.sbdevelopment.mapreflectionapi.nms.PacketListener_" + version);
|
||||||
if (MapWrapper.class.isAssignableFrom(clazz)) {
|
if (PacketListener.class.isAssignableFrom(clazz)) {
|
||||||
return (PacketListener) clazz.getDeclaredConstructor().newInstance();
|
return (PacketListener) clazz.getDeclaredConstructor().newInstance();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Plugin corrupted! Detected invalid MapWrapper class.");
|
throw new IllegalStateException("Plugin corrupted! Detected invalid PacketListener class.");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new IllegalStateException("This Spigot version is not supported! Contact the developer to get support.");
|
throw new IllegalStateException("This Minecraft version (" + version + ") is not supported! Contact the developer to get support.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,16 +82,4 @@ public abstract class PacketListener implements Listener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object getField(Object packet, String field) throws NoSuchFieldException, IllegalAccessException {
|
|
||||||
Field f = packet.getClass().getDeclaredField(field);
|
|
||||||
f.setAccessible(true);
|
|
||||||
return f.get(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setField(Object packet, String field, Object value) throws NoSuchFieldException, IllegalAccessException {
|
|
||||||
Field f = packet.getClass().getDeclaredField(field);
|
|
||||||
f.setAccessible(true);
|
|
||||||
f.set(packet, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* This file is part of MapReflectionAPI.
|
||||||
|
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package tech.sbdevelopment.mapreflectionapi.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class ReflectionUtil {
|
||||||
|
public static Object getField(Object packet, String field) throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field f = packet.getClass().getDeclaredField(field);
|
||||||
|
f.setAccessible(true);
|
||||||
|
return f.get(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getField(Class<?> clazz, String field) throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field f = clazz.getDeclaredField(field);
|
||||||
|
f.setAccessible(true);
|
||||||
|
return f.get(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setField(Object packet, String field, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field f = packet.getClass().getDeclaredField(field);
|
||||||
|
f.setAccessible(true);
|
||||||
|
f.set(packet, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getValue(Object packet, String method) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||||
|
Method m = packet.getClass().getDeclaredMethod(method, null);
|
||||||
|
m.setAccessible(true);
|
||||||
|
return m.invoke(packet, null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,13 +41,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_12_R1 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_12_R1 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -140,7 +139,7 @@ public class MapWrapper_v1_12_R1 implements MapWrapper {
|
||||||
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,23 +221,32 @@ public class MapWrapper_v1_12_R1 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getTag().setInt("map", mapId);
|
if (nmsStack.getTag() == null) nmsStack.setTag(new NBTTagCompound()); //No orCreate on 1.12.2!
|
||||||
|
nmsStack.getTag().setInt("map", mapId); //getTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.a(EntityItemFrame.class, DataWatcherRegistry.f), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.server.v1_12_R1.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.server.v1_12_R1.ItemStack>) getField(EntityItemFrame.class, "c");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_12_R1(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
public class PacketListener_v1_12_R1 extends PacketListener {
|
public class PacketListener_v1_12_R1 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
|
|
@ -41,13 +41,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_13_R2 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_13_R2 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -140,7 +139,7 @@ public class MapWrapper_v1_13_R2 implements MapWrapper {
|
||||||
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,23 +221,31 @@ public class MapWrapper_v1_13_R2 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().setInt("map", mapId);
|
nmsStack.getOrCreateTag().setInt("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.a(EntityItemFrame.class, DataWatcherRegistry.g), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.server.v1_13_R2.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.server.v1_13_R2.ItemStack>) getField(EntityItemFrame.class, "e");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_13_R2(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
public class PacketListener_v1_13_R2 extends PacketListener {
|
public class PacketListener_v1_13_R2 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
|
|
@ -41,13 +41,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_14_R1 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_14_R1 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -140,7 +139,7 @@ public class MapWrapper_v1_14_R1 implements MapWrapper {
|
||||||
net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,23 +221,31 @@ public class MapWrapper_v1_14_R1 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().setInt("map", mapId);
|
nmsStack.getOrCreateTag().setInt("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.a(EntityItemFrame.class, DataWatcherRegistry.g), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.server.v1_14_R1.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.server.v1_14_R1.ItemStack>) getField(EntityItemFrame.class, "ITEM");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_14_R1(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
public class PacketListener_v1_14_R1 extends PacketListener {
|
public class PacketListener_v1_14_R1 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
|
|
@ -41,12 +41,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_15_R1 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_15_R1 extends MapWrapper {
|
||||||
|
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
@ -140,7 +140,7 @@ public class MapWrapper_v1_15_R1 implements MapWrapper {
|
||||||
net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,23 +222,31 @@ public class MapWrapper_v1_15_R1 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().setInt("map", mapId);
|
nmsStack.getOrCreateTag().setInt("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.a(EntityItemFrame.class, DataWatcherRegistry.g), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.server.v1_15_R1.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.server.v1_15_R1.ItemStack>) getField(EntityItemFrame.class, "ITEM");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_15_R1(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
public class PacketListener_v1_15_R1 extends PacketListener {
|
public class PacketListener_v1_15_R1 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
|
|
@ -41,13 +41,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_16_R3 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_16_R3 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -140,7 +139,7 @@ public class MapWrapper_v1_16_R3 implements MapWrapper {
|
||||||
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, slot, nmsStack);
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,23 +221,31 @@ public class MapWrapper_v1_16_R3 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().setInt("map", mapId);
|
nmsStack.getOrCreateTag().setInt("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.a(EntityItemFrame.class, DataWatcherRegistry.g), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).playerConnection.sendPacket(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.server.v1_16_R3.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.server.v1_16_R3.ItemStack>) getField(EntityItemFrame.class, "ITEM");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_16_R3(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
public class PacketListener_v1_16_R3 extends PacketListener {
|
public class PacketListener_v1_16_R3 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
|
|
@ -1,4 +1,27 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ This file is part of MapReflectionAPI.
|
||||||
|
~ Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
~
|
||||||
|
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
~ of this software and associated documentation files (the "Software"), to deal
|
||||||
|
~ in the Software without restriction, including without limitation the rights
|
||||||
|
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
~ copies of the Software, and to permit persons to whom the Software is
|
||||||
|
~ furnished to do so, subject to the following conditions:
|
||||||
|
~
|
||||||
|
~ The above copyright notice and this permission notice shall be included in all
|
||||||
|
~ copies or substantial portions of the Software.
|
||||||
|
~
|
||||||
|
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
~ SOFTWARE.
|
||||||
|
-->
|
||||||
|
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
@ -26,43 +49,6 @@
|
||||||
<release>${jdk.version}</release>
|
<release>${jdk.version}</release>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>specialsource-maven-plugin</artifactId>
|
|
||||||
<version>1.2.3</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>remap</goal>
|
|
||||||
</goals>
|
|
||||||
<id>remap-obf</id>
|
|
||||||
<configuration>
|
|
||||||
<srgIn>org.spigotmc:minecraft-server:${NMSVersion}:txt:maps-mojang</srgIn>
|
|
||||||
<reverse>true</reverse>
|
|
||||||
<remappedDependencies>org.spigotmc:spigot:${NMSVersion}:jar:remapped-mojang
|
|
||||||
</remappedDependencies>
|
|
||||||
<remappedArtifactAttached>true</remappedArtifactAttached>
|
|
||||||
<remappedClassifierName>remapped-obf</remappedClassifierName>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>remap</goal>
|
|
||||||
</goals>
|
|
||||||
<id>remap-spigot</id>
|
|
||||||
<configuration>
|
|
||||||
<inputFile>
|
|
||||||
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
|
|
||||||
</inputFile>
|
|
||||||
<srgIn>org.spigotmc:minecraft-server:${NMSVersion}:csrg:maps-spigot</srgIn>
|
|
||||||
<remappedDependencies>org.spigotmc:spigot:${NMSVersion}:jar:remapped-obf
|
|
||||||
</remappedDependencies>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
@ -76,18 +62,11 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>minecraft-server</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>${NMSVersion}</version>
|
<version>${NMSVersion}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>${NMSVersion}</version>
|
|
||||||
<classifier>remapped-mojang</classifier>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>tech.sbdevelopment</groupId>
|
<groupId>tech.sbdevelopment</groupId>
|
||||||
<artifactId>MapReflectionAPI-API</artifactId>
|
<artifactId>MapReflectionAPI-API</artifactId>
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class MapSender_v1_17_R1 {
|
||||||
updateData
|
updateData
|
||||||
);
|
);
|
||||||
|
|
||||||
((CraftPlayer) player).getHandle().connection.send(packet);
|
((CraftPlayer) player).getHandle().b.sendPacket(packet); //connection send()
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ package tech.sbdevelopment.mapreflectionapi.nms;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
|
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
|
||||||
import net.minecraft.network.syncher.DataWatcher;
|
import net.minecraft.network.syncher.DataWatcher;
|
||||||
import net.minecraft.network.syncher.DataWatcherRegistry;
|
import net.minecraft.network.syncher.DataWatcherObject;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
@ -45,13 +44,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_17_R1 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_17_R1 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -138,14 +136,14 @@ public class MapWrapper_v1_17_R1 implements MapWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
int windowId = craftPlayer.getHandle().inventoryMenu.containerId;
|
int windowId = craftPlayer.getHandle().bU.j; //inventoryMenu containerId
|
||||||
int stateId = craftPlayer.getHandle().inventoryMenu.getStateId();
|
int stateId = craftPlayer.getHandle().bU.getStateId(); //inventoryMenu getStateId()
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(Material.MAP, 1);
|
ItemStack stack = new ItemStack(Material.MAP, 1);
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, stateId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, stateId, slot, nmsStack);
|
||||||
((EntityPlayer) player).connection.sendPacket(packet);
|
((CraftPlayer) player).getHandle().b.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -226,23 +224,31 @@ public class MapWrapper_v1_17_R1 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().setInt("map", mapId);
|
nmsStack.getOrCreateTag().setInt("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.a(EntityItemFrame.class, DataWatcherRegistry.ITEM_STACK), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).connection.sendPacket(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.world.item.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.world.item.ItemStack>) getField(EntityItemFrame.class, "ao");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().b.sendPacket(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_17_R1(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -43,6 +43,8 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.*;
|
||||||
|
|
||||||
public class PacketListener_v1_17_R1 extends PacketListener {
|
public class PacketListener_v1_17_R1 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
@ -51,7 +53,7 @@ public class PacketListener_v1_17_R1 extends PacketListener {
|
||||||
//On send packet
|
//On send packet
|
||||||
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
||||||
if (packet instanceof PacketPlayOutMap packetPlayOutMap) {
|
if (packet instanceof PacketPlayOutMap packetPlayOutMap) {
|
||||||
int id = packetPlayOutMap.b();
|
int id = (int) getField(packetPlayOutMap, "a");
|
||||||
|
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
//It's one of our maps, invert ID and let through!
|
//It's one of our maps, invert ID and let through!
|
||||||
|
@ -76,13 +78,14 @@ public class PacketListener_v1_17_R1 extends PacketListener {
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
||||||
if (packet instanceof PacketPlayInUseEntity packetPlayInUseEntity) {
|
if (packet instanceof PacketPlayInUseEntity packetPlayInUseEntity) {
|
||||||
int entityId = (int) getField(packetPlayInUseEntity, "a"); //entityId
|
int entityId = (int) getField(packetPlayInUseEntity, "a"); //entityId
|
||||||
Enum<?> action = (Enum<?>) getField(packetPlayInUseEntity, "b"); //action
|
Object action = getField(packetPlayInUseEntity, "b"); //action
|
||||||
EnumHand hand = (EnumHand) getField(action, "a"); //hand
|
Enum<?> actionEnum = (Enum<?>) getValue(action, "a"); //action type
|
||||||
|
EnumHand hand = hasField(action, "a") ? (EnumHand) getField(action, "a") : null; //hand
|
||||||
Vec3D pos = hasField(action, "b") ? (Vec3D) getField(action, "b") : null; //pos
|
Vec3D pos = hasField(action, "b") ? (Vec3D) getField(action, "b") : null; //pos
|
||||||
|
|
||||||
if (Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
if (Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||||
boolean async = !plugin.getServer().isPrimaryThread();
|
boolean async = !plugin.getServer().isPrimaryThread();
|
||||||
MapInteractEvent event = new MapInteractEvent(p, entityId, action.ordinal(), pos != null ? vec3DToVector(pos) : null, hand != null ? hand.ordinal() : 0, async);
|
MapInteractEvent event = new MapInteractEvent(p, entityId, actionEnum.ordinal(), pos != null ? vec3DToVector(pos) : null, hand != null ? hand.ordinal() : 0, async);
|
||||||
if (event.getFrame() != null && event.getMapWrapper() != null) {
|
if (event.getFrame() != null && event.getMapWrapper() != null) {
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
|
@ -105,19 +108,19 @@ public class PacketListener_v1_17_R1 extends PacketListener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ChannelPipeline pipeline = ((CraftPlayer) p).getHandle().connection.connection.channel.pipeline();
|
ChannelPipeline pipeline = ((CraftPlayer) p).getHandle().b.a.k.pipeline(); //connection connection channel
|
||||||
pipeline.addBefore("packet_handler", p.getName(), channelDuplexHandler);
|
pipeline.addBefore("packet_handler", p.getName(), channelDuplexHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removePlayer(Player p) {
|
public void removePlayer(Player p) {
|
||||||
Channel channel = ((CraftPlayer) p).getHandle().connection.connection.channel;
|
Channel channel = ((CraftPlayer) p).getHandle().b.a.k; //connection connection channel
|
||||||
channel.eventLoop().submit(() -> channel.pipeline().remove(p.getName()));
|
channel.eventLoop().submit(() -> channel.pipeline().remove(p.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Vector vec3DToVector(Object vec3d) {
|
protected Vector vec3DToVector(Object vec3d) {
|
||||||
if (!(vec3d instanceof Vec3D vec3dObj)) return new Vector(0, 0, 0);
|
if (!(vec3d instanceof Vec3D vec3dObj)) return new Vector(0, 0, 0);
|
||||||
return new Vector(vec3dObj.x, vec3dObj.y, vec3dObj.z);
|
return new Vector(vec3dObj.b, vec3dObj.c, vec3dObj.d); //x, y, z
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,27 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ This file is part of MapReflectionAPI.
|
||||||
|
~ Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
~
|
||||||
|
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
~ of this software and associated documentation files (the "Software"), to deal
|
||||||
|
~ in the Software without restriction, including without limitation the rights
|
||||||
|
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
~ copies of the Software, and to permit persons to whom the Software is
|
||||||
|
~ furnished to do so, subject to the following conditions:
|
||||||
|
~
|
||||||
|
~ The above copyright notice and this permission notice shall be included in all
|
||||||
|
~ copies or substantial portions of the Software.
|
||||||
|
~
|
||||||
|
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
~ SOFTWARE.
|
||||||
|
-->
|
||||||
|
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
@ -26,43 +49,6 @@
|
||||||
<release>${jdk.version}</release>
|
<release>${jdk.version}</release>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>specialsource-maven-plugin</artifactId>
|
|
||||||
<version>1.2.3</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>remap</goal>
|
|
||||||
</goals>
|
|
||||||
<id>remap-obf</id>
|
|
||||||
<configuration>
|
|
||||||
<srgIn>org.spigotmc:minecraft-server:${NMSVersion}:txt:maps-mojang</srgIn>
|
|
||||||
<reverse>true</reverse>
|
|
||||||
<remappedDependencies>org.spigotmc:spigot:${NMSVersion}:jar:remapped-mojang
|
|
||||||
</remappedDependencies>
|
|
||||||
<remappedArtifactAttached>true</remappedArtifactAttached>
|
|
||||||
<remappedClassifierName>remapped-obf</remappedClassifierName>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>remap</goal>
|
|
||||||
</goals>
|
|
||||||
<id>remap-spigot</id>
|
|
||||||
<configuration>
|
|
||||||
<inputFile>
|
|
||||||
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
|
|
||||||
</inputFile>
|
|
||||||
<srgIn>org.spigotmc:minecraft-server:${NMSVersion}:csrg:maps-spigot</srgIn>
|
|
||||||
<remappedDependencies>org.spigotmc:spigot:${NMSVersion}:jar:remapped-obf
|
|
||||||
</remappedDependencies>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
@ -76,18 +62,11 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>minecraft-server</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>${NMSVersion}</version>
|
<version>${NMSVersion}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>${NMSVersion}</version>
|
|
||||||
<classifier>remapped-mojang</classifier>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>tech.sbdevelopment</groupId>
|
<groupId>tech.sbdevelopment</groupId>
|
||||||
<artifactId>MapReflectionAPI-API</artifactId>
|
<artifactId>MapReflectionAPI-API</artifactId>
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class MapSender_v1_18_R2 {
|
||||||
updateData
|
updateData
|
||||||
);
|
);
|
||||||
|
|
||||||
((CraftPlayer) player).getHandle().connection.send(packet);
|
((CraftPlayer) player).getHandle().b.a(packet); //connection send()
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ package tech.sbdevelopment.mapreflectionapi.nms;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
|
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
|
||||||
import net.minecraft.network.syncher.DataWatcher;
|
import net.minecraft.network.syncher.DataWatcher;
|
||||||
import net.minecraft.network.syncher.DataWatcherRegistry;
|
import net.minecraft.network.syncher.DataWatcherObject;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
@ -45,13 +44,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_18_R2 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_18_R2 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -138,14 +136,14 @@ public class MapWrapper_v1_18_R2 implements MapWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
int windowId = craftPlayer.getHandle().inventoryMenu.containerId;
|
int windowId = craftPlayer.getHandle().bU.j; //inventoryMenu containerId
|
||||||
int stateId = craftPlayer.getHandle().inventoryMenu.getStateId();
|
int stateId = craftPlayer.getHandle().bU.j(); //inventoryMenu getStateId()
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(Material.MAP, 1);
|
ItemStack stack = new ItemStack(Material.MAP, 1);
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, stateId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, stateId, slot, nmsStack);
|
||||||
((EntityPlayer) player).connection.send(packet);
|
((CraftPlayer) player).getHandle().b.a(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,7 +214,7 @@ public class MapWrapper_v1_18_R2 implements MapWrapper {
|
||||||
public ItemFrame getItemFrameById(World world, int entityId) {
|
public ItemFrame getItemFrameById(World world, int entityId) {
|
||||||
CraftWorld craftWorld = (CraftWorld) world;
|
CraftWorld craftWorld = (CraftWorld) world;
|
||||||
|
|
||||||
Entity entity = craftWorld.getHandle().getEntity(entityId);
|
Entity entity = craftWorld.getHandle().a(entityId);
|
||||||
if (entity == null) return null;
|
if (entity == null) return null;
|
||||||
|
|
||||||
if (entity instanceof ItemFrame) return (ItemFrame) entity;
|
if (entity instanceof ItemFrame) return (ItemFrame) entity;
|
||||||
|
@ -226,23 +224,31 @@ public class MapWrapper_v1_18_R2 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().putInt("map", mapId);
|
nmsStack.u().a("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.defineId(EntityItemFrame.class, DataWatcherRegistry.ITEM_STACK), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).connection.send(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.world.item.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.world.item.ItemStack>) getField(EntityItemFrame.class, "ao");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_18_R2(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.*;
|
||||||
|
|
||||||
public class PacketListener_v1_18_R2 extends PacketListener {
|
public class PacketListener_v1_18_R2 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
@ -51,7 +53,7 @@ public class PacketListener_v1_18_R2 extends PacketListener {
|
||||||
//On send packet
|
//On send packet
|
||||||
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
||||||
if (packet instanceof PacketPlayOutMap packetPlayOutMap) {
|
if (packet instanceof PacketPlayOutMap packetPlayOutMap) {
|
||||||
int id = packetPlayOutMap.getMapId();
|
int id = (int) getField(packetPlayOutMap, "a");
|
||||||
|
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
//It's one of our maps, invert ID and let through!
|
//It's one of our maps, invert ID and let through!
|
||||||
|
@ -76,13 +78,14 @@ public class PacketListener_v1_18_R2 extends PacketListener {
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
||||||
if (packet instanceof PacketPlayInUseEntity packetPlayInUseEntity) {
|
if (packet instanceof PacketPlayInUseEntity packetPlayInUseEntity) {
|
||||||
int entityId = (int) getField(packetPlayInUseEntity, "a"); //entityId
|
int entityId = (int) getField(packetPlayInUseEntity, "a"); //entityId
|
||||||
Enum<?> action = (Enum<?>) getField(packetPlayInUseEntity, "b"); //action
|
Object action = getField(packetPlayInUseEntity, "b"); //action
|
||||||
EnumHand hand = (EnumHand) getField(action, "a"); //hand
|
Enum<?> actionEnum = (Enum<?>) getValue(action, "a"); //action type
|
||||||
|
EnumHand hand = hasField(action, "a") ? (EnumHand) getField(action, "a") : null; //hand
|
||||||
Vec3D pos = hasField(action, "b") ? (Vec3D) getField(action, "b") : null; //pos
|
Vec3D pos = hasField(action, "b") ? (Vec3D) getField(action, "b") : null; //pos
|
||||||
|
|
||||||
if (Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
if (Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||||
boolean async = !plugin.getServer().isPrimaryThread();
|
boolean async = !plugin.getServer().isPrimaryThread();
|
||||||
MapInteractEvent event = new MapInteractEvent(p, entityId, action.ordinal(), pos != null ? vec3DToVector(pos) : null, hand != null ? hand.ordinal() : 0, async);
|
MapInteractEvent event = new MapInteractEvent(p, entityId, actionEnum.ordinal(), pos != null ? vec3DToVector(pos) : null, hand != null ? hand.ordinal() : 0, async);
|
||||||
if (event.getFrame() != null && event.getMapWrapper() != null) {
|
if (event.getFrame() != null && event.getMapWrapper() != null) {
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
|
@ -90,8 +93,8 @@ public class PacketListener_v1_18_R2 extends PacketListener {
|
||||||
return false;
|
return false;
|
||||||
}).get(1, TimeUnit.SECONDS)) return;
|
}).get(1, TimeUnit.SECONDS)) return;
|
||||||
} else if (packet instanceof PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot) {
|
} else if (packet instanceof PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot) {
|
||||||
int slot = packetPlayInSetCreativeSlot.getSlotNum();
|
int slot = packetPlayInSetCreativeSlot.b();
|
||||||
ItemStack item = packetPlayInSetCreativeSlot.getItem();
|
ItemStack item = packetPlayInSetCreativeSlot.c();
|
||||||
|
|
||||||
boolean async = !plugin.getServer().isPrimaryThread();
|
boolean async = !plugin.getServer().isPrimaryThread();
|
||||||
CreateInventoryMapUpdateEvent event = new CreateInventoryMapUpdateEvent(p, slot, CraftItemStack.asBukkitCopy(item), async);
|
CreateInventoryMapUpdateEvent event = new CreateInventoryMapUpdateEvent(p, slot, CraftItemStack.asBukkitCopy(item), async);
|
||||||
|
@ -105,19 +108,19 @@ public class PacketListener_v1_18_R2 extends PacketListener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ChannelPipeline pipeline = ((CraftPlayer) p).getHandle().connection.connection.channel.pipeline();
|
ChannelPipeline pipeline = ((CraftPlayer) p).getHandle().b.a.m.pipeline(); //connection connection channel
|
||||||
pipeline.addBefore("packet_handler", p.getName(), channelDuplexHandler);
|
pipeline.addBefore("packet_handler", p.getName(), channelDuplexHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removePlayer(Player p) {
|
public void removePlayer(Player p) {
|
||||||
Channel channel = ((CraftPlayer) p).getHandle().connection.connection.channel;
|
Channel channel = ((CraftPlayer) p).getHandle().b.a.m; //connection connection channel
|
||||||
channel.eventLoop().submit(() -> channel.pipeline().remove(p.getName()));
|
channel.eventLoop().submit(() -> channel.pipeline().remove(p.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Vector vec3DToVector(Object vec3d) {
|
protected Vector vec3DToVector(Object vec3d) {
|
||||||
if (!(vec3d instanceof Vec3D vec3dObj)) return new Vector(0, 0, 0);
|
if (!(vec3d instanceof Vec3D vec3dObj)) return new Vector(0, 0, 0);
|
||||||
return new Vector(vec3dObj.x, vec3dObj.y, vec3dObj.z);
|
return new Vector(vec3dObj.b, vec3dObj.c, vec3dObj.d); //x, y, z
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,27 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ This file is part of MapReflectionAPI.
|
||||||
|
~ Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
~
|
||||||
|
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
~ of this software and associated documentation files (the "Software"), to deal
|
||||||
|
~ in the Software without restriction, including without limitation the rights
|
||||||
|
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
~ copies of the Software, and to permit persons to whom the Software is
|
||||||
|
~ furnished to do so, subject to the following conditions:
|
||||||
|
~
|
||||||
|
~ The above copyright notice and this permission notice shall be included in all
|
||||||
|
~ copies or substantial portions of the Software.
|
||||||
|
~
|
||||||
|
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
~ SOFTWARE.
|
||||||
|
-->
|
||||||
|
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
@ -26,43 +49,6 @@
|
||||||
<release>${jdk.version}</release>
|
<release>${jdk.version}</release>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>specialsource-maven-plugin</artifactId>
|
|
||||||
<version>1.2.3</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>remap</goal>
|
|
||||||
</goals>
|
|
||||||
<id>remap-obf</id>
|
|
||||||
<configuration>
|
|
||||||
<srgIn>org.spigotmc:minecraft-server:${NMSVersion}:txt:maps-mojang</srgIn>
|
|
||||||
<reverse>true</reverse>
|
|
||||||
<remappedDependencies>org.spigotmc:spigot:${NMSVersion}:jar:remapped-mojang
|
|
||||||
</remappedDependencies>
|
|
||||||
<remappedArtifactAttached>true</remappedArtifactAttached>
|
|
||||||
<remappedClassifierName>remapped-obf</remappedClassifierName>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>remap</goal>
|
|
||||||
</goals>
|
|
||||||
<id>remap-spigot</id>
|
|
||||||
<configuration>
|
|
||||||
<inputFile>
|
|
||||||
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
|
|
||||||
</inputFile>
|
|
||||||
<srgIn>org.spigotmc:minecraft-server:${NMSVersion}:csrg:maps-spigot</srgIn>
|
|
||||||
<remappedDependencies>org.spigotmc:spigot:${NMSVersion}:jar:remapped-obf
|
|
||||||
</remappedDependencies>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
@ -76,18 +62,11 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>minecraft-server</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>${NMSVersion}</version>
|
<version>${NMSVersion}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>${NMSVersion}</version>
|
|
||||||
<classifier>remapped-mojang</classifier>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>tech.sbdevelopment</groupId>
|
<groupId>tech.sbdevelopment</groupId>
|
||||||
<artifactId>MapReflectionAPI-API</artifactId>
|
<artifactId>MapReflectionAPI-API</artifactId>
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class MapSender_v1_19_R1 {
|
||||||
updateData
|
updateData
|
||||||
);
|
);
|
||||||
|
|
||||||
((CraftPlayer) player).getHandle().connection.send(packet);
|
((CraftPlayer) player).getHandle().b.a(packet); //connection send()
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ package tech.sbdevelopment.mapreflectionapi.nms;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
|
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
|
||||||
import net.minecraft.network.syncher.DataWatcher;
|
import net.minecraft.network.syncher.DataWatcher;
|
||||||
import net.minecraft.network.syncher.DataWatcherRegistry;
|
import net.minecraft.network.syncher.DataWatcherObject;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
import net.minecraft.world.entity.decoration.EntityItemFrame;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
@ -45,13 +44,12 @@ import tech.sbdevelopment.mapreflectionapi.api.MapController;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
import tech.sbdevelopment.mapreflectionapi.api.MapWrapper;
|
||||||
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
import tech.sbdevelopment.mapreflectionapi.exceptions.MapLimitExceededException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MapWrapper_v1_19_R1 implements MapWrapper {
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.getField;
|
||||||
protected ArrayImage content;
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.setField;
|
||||||
|
|
||||||
|
public class MapWrapper_v1_19_R1 extends MapWrapper {
|
||||||
protected MapController controller = new MapController() {
|
protected MapController controller = new MapController() {
|
||||||
private final Map<UUID, Integer> viewers = new HashMap<>();
|
private final Map<UUID, Integer> viewers = new HashMap<>();
|
||||||
|
|
||||||
|
@ -138,14 +136,14 @@ public class MapWrapper_v1_19_R1 implements MapWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
int windowId = craftPlayer.getHandle().inventoryMenu.containerId;
|
int windowId = craftPlayer.getHandle().bT.j; //inventoryMenu containerId
|
||||||
int stateId = craftPlayer.getHandle().inventoryMenu.getStateId();
|
int stateId = craftPlayer.getHandle().bT.j(); //inventoryMenu getStateId()
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(Material.MAP, 1);
|
ItemStack stack = new ItemStack(Material.MAP, 1);
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
|
|
||||||
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, stateId, slot, nmsStack);
|
PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(windowId, stateId, slot, nmsStack);
|
||||||
((EntityPlayer) player).connection.send(packet);
|
((CraftPlayer) player).getHandle().b.a(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,7 +214,7 @@ public class MapWrapper_v1_19_R1 implements MapWrapper {
|
||||||
public ItemFrame getItemFrameById(World world, int entityId) {
|
public ItemFrame getItemFrameById(World world, int entityId) {
|
||||||
CraftWorld craftWorld = (CraftWorld) world;
|
CraftWorld craftWorld = (CraftWorld) world;
|
||||||
|
|
||||||
Entity entity = craftWorld.getHandle().getEntity(entityId);
|
Entity entity = craftWorld.getHandle().a(entityId);
|
||||||
if (entity == null) return null;
|
if (entity == null) return null;
|
||||||
|
|
||||||
if (entity instanceof ItemFrame) return (ItemFrame) entity;
|
if (entity instanceof ItemFrame) return (ItemFrame) entity;
|
||||||
|
@ -226,23 +224,31 @@ public class MapWrapper_v1_19_R1 implements MapWrapper {
|
||||||
|
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||||
nmsStack.getOrCreateTag().putInt("map", mapId);
|
nmsStack.v().a("map", mapId); //getOrCreateTag putInt
|
||||||
|
|
||||||
DataWatcher watcher = new DataWatcher(null);
|
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, new DataWatcher(null), true);
|
||||||
watcher.set(DataWatcher.defineId(EntityItemFrame.class, DataWatcherRegistry.ITEM_STACK), nmsStack);
|
|
||||||
|
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entityId, watcher, true);
|
try {
|
||||||
((EntityPlayer) player).connection.send(packet);
|
List<DataWatcher.Item<?>> list = new ArrayList<>();
|
||||||
|
DataWatcherObject<net.minecraft.world.item.ItemStack> dataWatcherObject = (DataWatcherObject<net.minecraft.world.item.ItemStack>) getField(EntityItemFrame.class, "ao");
|
||||||
|
DataWatcher.Item<?> dataWatcherItem = new DataWatcher.Item<>(dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
setField(packet, "b", list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public MapWrapper_v1_19_R1(ArrayImage image) {
|
||||||
|
super(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapController getController() {
|
public MapController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayImage getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.mapreflectionapi.util.ReflectionUtil.*;
|
||||||
|
|
||||||
public class PacketListener_v1_19_R1 extends PacketListener {
|
public class PacketListener_v1_19_R1 extends PacketListener {
|
||||||
@Override
|
@Override
|
||||||
protected void injectPlayer(Player p) {
|
protected void injectPlayer(Player p) {
|
||||||
|
@ -51,7 +53,7 @@ public class PacketListener_v1_19_R1 extends PacketListener {
|
||||||
//On send packet
|
//On send packet
|
||||||
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
|
||||||
if (packet instanceof PacketPlayOutMap packetPlayOutMap) {
|
if (packet instanceof PacketPlayOutMap packetPlayOutMap) {
|
||||||
int id = packetPlayOutMap.getMapId();
|
int id = (int) getField(packetPlayOutMap, "a");
|
||||||
|
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
//It's one of our maps, invert ID and let through!
|
//It's one of our maps, invert ID and let through!
|
||||||
|
@ -76,13 +78,14 @@ public class PacketListener_v1_19_R1 extends PacketListener {
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
|
||||||
if (packet instanceof PacketPlayInUseEntity packetPlayInUseEntity) {
|
if (packet instanceof PacketPlayInUseEntity packetPlayInUseEntity) {
|
||||||
int entityId = (int) getField(packetPlayInUseEntity, "a"); //entityId
|
int entityId = (int) getField(packetPlayInUseEntity, "a"); //entityId
|
||||||
Enum<?> action = (Enum<?>) getField(packetPlayInUseEntity, "b"); //action
|
Object action = getField(packetPlayInUseEntity, "b"); //action
|
||||||
EnumHand hand = (EnumHand) getField(action, "a"); //hand
|
Enum<?> actionEnum = (Enum<?>) getValue(action, "a"); //action type
|
||||||
|
EnumHand hand = hasField(action, "a") ? (EnumHand) getField(action, "a") : null; //hand
|
||||||
Vec3D pos = hasField(action, "b") ? (Vec3D) getField(action, "b") : null; //pos
|
Vec3D pos = hasField(action, "b") ? (Vec3D) getField(action, "b") : null; //pos
|
||||||
|
|
||||||
if (Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
if (Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||||
boolean async = !plugin.getServer().isPrimaryThread();
|
boolean async = !plugin.getServer().isPrimaryThread();
|
||||||
MapInteractEvent event = new MapInteractEvent(p, entityId, action.ordinal(), pos != null ? vec3DToVector(pos) : null, hand != null ? hand.ordinal() : 0, async);
|
MapInteractEvent event = new MapInteractEvent(p, entityId, actionEnum.ordinal(), pos != null ? vec3DToVector(pos) : null, hand != null ? hand.ordinal() : 0, async);
|
||||||
if (event.getFrame() != null && event.getMapWrapper() != null) {
|
if (event.getFrame() != null && event.getMapWrapper() != null) {
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
|
@ -90,8 +93,8 @@ public class PacketListener_v1_19_R1 extends PacketListener {
|
||||||
return false;
|
return false;
|
||||||
}).get(1, TimeUnit.SECONDS)) return;
|
}).get(1, TimeUnit.SECONDS)) return;
|
||||||
} else if (packet instanceof PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot) {
|
} else if (packet instanceof PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot) {
|
||||||
int slot = packetPlayInSetCreativeSlot.getSlotNum();
|
int slot = packetPlayInSetCreativeSlot.b();
|
||||||
ItemStack item = packetPlayInSetCreativeSlot.getItem();
|
ItemStack item = packetPlayInSetCreativeSlot.c();
|
||||||
|
|
||||||
boolean async = !plugin.getServer().isPrimaryThread();
|
boolean async = !plugin.getServer().isPrimaryThread();
|
||||||
CreateInventoryMapUpdateEvent event = new CreateInventoryMapUpdateEvent(p, slot, CraftItemStack.asBukkitCopy(item), async);
|
CreateInventoryMapUpdateEvent event = new CreateInventoryMapUpdateEvent(p, slot, CraftItemStack.asBukkitCopy(item), async);
|
||||||
|
@ -105,19 +108,19 @@ public class PacketListener_v1_19_R1 extends PacketListener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ChannelPipeline pipeline = ((CraftPlayer) p).getHandle().connection.connection.channel.pipeline();
|
ChannelPipeline pipeline = ((CraftPlayer) p).getHandle().b.b.m.pipeline(); //connection connection channel
|
||||||
pipeline.addBefore("packet_handler", p.getName(), channelDuplexHandler);
|
pipeline.addBefore("packet_handler", p.getName(), channelDuplexHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removePlayer(Player p) {
|
public void removePlayer(Player p) {
|
||||||
Channel channel = ((CraftPlayer) p).getHandle().connection.connection.channel;
|
Channel channel = ((CraftPlayer) p).getHandle().b.b.m; //connection connection channel
|
||||||
channel.eventLoop().submit(() -> channel.pipeline().remove(p.getName()));
|
channel.eventLoop().submit(() -> channel.pipeline().remove(p.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Vector vec3DToVector(Object vec3d) {
|
protected Vector vec3DToVector(Object vec3d) {
|
||||||
if (!(vec3d instanceof Vec3D vec3dObj)) return new Vector(0, 0, 0);
|
if (!(vec3d instanceof Vec3D vec3dObj)) return new Vector(0, 0, 0);
|
||||||
return new Vector(vec3dObj.x, vec3dObj.y, vec3dObj.z);
|
return new Vector(vec3dObj.c, vec3dObj.d, vec3dObj.e); //x, y, z
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue