Added Spigot 1.20.4 support
This commit is contained in:
parent
8206cb403b
commit
89cbc9b8be
5 changed files with 42 additions and 39 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
package tech.sbdevelopment.mapreflectionapi.api;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -33,7 +34,6 @@ import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Ref;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -43,6 +43,7 @@ import static tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtils.*;
|
|||
/**
|
||||
* A {@link MapWrapper} wraps one image.
|
||||
*/
|
||||
@Getter
|
||||
public class MapWrapper extends AbstractMapWrapper {
|
||||
private static final String REFERENCE_METADATA = "MAP_WRAPPER_REF";
|
||||
protected ArrayImage content;
|
||||
|
@ -108,7 +109,8 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
|
||||
@Override
|
||||
public void update(@NotNull ArrayImage content) {
|
||||
MapContentUpdateEvent event = new MapContentUpdateEvent(MapWrapper.this, content);
|
||||
boolean async = !MapReflectionAPI.getInstance().getServer().isPrimaryThread();
|
||||
MapContentUpdateEvent event = new MapContentUpdateEvent(MapWrapper.this, content, async);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (Configuration.getInstance().isImageCache()) {
|
||||
|
@ -165,27 +167,25 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
}
|
||||
|
||||
String inventoryMenuName;
|
||||
if (supports(20)) { //1.20
|
||||
inventoryMenuName = PATCH_NUMBER == 2 ? "bR" : "bQ"; //1.20.2 = bR, 1.20(.1) = bQ
|
||||
} else if (supports(19)) { //1.19
|
||||
inventoryMenuName = PATCH_NUMBER == 3 ? "bO" : "bT"; //1.19.4 = bO, >= 1.19.3 = bT
|
||||
} else if (supports(18)) { //1.18
|
||||
inventoryMenuName = PATCH_NUMBER == 1 ? "bV" : "bU"; //1.18.1 = ap, 1.18(.2) = ao
|
||||
} else if (supports(17)) { //1.17, same as 1.18(.2)
|
||||
if (supports(20)) {
|
||||
//>= 1.20.2 = bR, 1.20(.1) = bQ
|
||||
inventoryMenuName = supports(20, 2) ? "bR" : "bQ";
|
||||
} else if (supports(19)) {
|
||||
//1.19.4 = bO, >= 1.19.3 = bT
|
||||
inventoryMenuName = supports(19, 3) ? "bO" : "bT";
|
||||
} else if (supports(18)) {
|
||||
//1.18.1 = ap, 1.18(.2) = ao
|
||||
inventoryMenuName = supports(18, 1) ? "bV" : "bU";
|
||||
} else if (supports(17)) {
|
||||
//1.17, same as 1.18(.2)
|
||||
inventoryMenuName = "bU";
|
||||
} else { //1.12-1.16
|
||||
} else {
|
||||
//1.12-1.16
|
||||
inventoryMenuName = "defaultContainer";
|
||||
}
|
||||
Object inventoryMenu = ReflectionUtil.getField(getHandle(player), inventoryMenuName);
|
||||
|
||||
ItemStack stack;
|
||||
if (supports(13)) {
|
||||
stack = new ItemStack(MAP_MATERIAL, 1);
|
||||
} else {
|
||||
stack = new ItemStack(MAP_MATERIAL, 1, (short) getMapId(player));
|
||||
}
|
||||
|
||||
Object nmsStack = createCraftItemStack(stack, (short) getMapId(player));
|
||||
Object nmsStack = asCraftItemStack(player);
|
||||
|
||||
Object packet;
|
||||
if (supports(17)) { //1.17+
|
||||
|
@ -298,6 +298,13 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
return null;
|
||||
}
|
||||
|
||||
private Object asCraftItemStack(Player player) {
|
||||
return createCraftItemStack(supports(13)
|
||||
? new ItemStack(MAP_MATERIAL, 1)
|
||||
: new ItemStack(MAP_MATERIAL, 1, (short) getMapId(player)
|
||||
), (short) getMapId(player));
|
||||
}
|
||||
|
||||
private Object createCraftItemStack(@NotNull ItemStack stack, int mapId) {
|
||||
if (mapId < 0) return null;
|
||||
|
||||
|
@ -310,7 +317,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
} else if (supports(19)) { //1.19
|
||||
nbtObjectName = "v";
|
||||
} else if (supports(18)) { //1.18
|
||||
nbtObjectName = PATCH_NUMBER == 1 ? "t" : "u"; //1.18.1 = t, 1.18(.2) = u
|
||||
nbtObjectName = supports(18, 1) ? "t" : "u"; //1.18.1 = t, 1.18(.2) = u
|
||||
} else { //1.13 - 1.17
|
||||
nbtObjectName = "getOrCreateTag";
|
||||
}
|
||||
|
@ -329,7 +336,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
} else if (supports(19)) { //1.19-1.19.2
|
||||
dataWatcherObjectName = "ao";
|
||||
} else if (supports(18)) { //1.18
|
||||
dataWatcherObjectName = PATCH_NUMBER == 1 ? "ap" : "ao"; //1.18.1 = ap, 1.18(.2) = ao
|
||||
dataWatcherObjectName = supports(18, 1) ? "ap" : "ao"; //1.18.1 = ap, 1.18(.2) = ao
|
||||
} else if (supports(17)) { //1.17
|
||||
dataWatcherObjectName = "ao";
|
||||
} else if (supports(14)) { //1.14 - 1.16
|
||||
|
@ -341,7 +348,7 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
}
|
||||
Object dataWatcherObject = ReflectionUtil.getDeclaredField(entityItemFrameClass, dataWatcherObjectName);
|
||||
|
||||
ReflectionUtil.ListParam list = new ReflectionUtil.ListParam<>();
|
||||
ReflectionUtil.ListParam<Object> list = new ReflectionUtil.ListParam<>();
|
||||
|
||||
Object packet;
|
||||
if (supports(19, 3)) { //1.19.3
|
||||
|
@ -379,13 +386,4 @@ public class MapWrapper extends AbstractMapWrapper {
|
|||
sendPacketSync(player, packet);
|
||||
}
|
||||
};
|
||||
|
||||
public ArrayImage getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapController getController() {
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ import java.util.regex.Pattern;
|
|||
* A useful resource used to compare mappings is <a href="https://minidigger.github.io/MiniMappingViewer/#/spigot">Mini's Mapping Viewer</a>
|
||||
*
|
||||
* @author Crypto Morin
|
||||
* @version 7.1.0
|
||||
* @version 7.1.0.0.1
|
||||
*/
|
||||
public final class ReflectionUtils {
|
||||
/**
|
||||
|
@ -106,8 +106,13 @@ public final class ReflectionUtils {
|
|||
*/
|
||||
public static final int MINOR_NUMBER;
|
||||
/**
|
||||
* The raw patch version number.
|
||||
* E.g. {@code 1.19.2} to {@code 2}
|
||||
* The raw patch version number. Refers to the <a href="https://en.wikipedia.org/wiki/Software_versioning">major.minor.patch version scheme</a>.
|
||||
* E.g.
|
||||
* <ul>
|
||||
* <li>{@code v1.20.4} to {@code 4}</li>
|
||||
* <li>{@code v1.18.2} to {@code 2}</li>
|
||||
* <li>{@code v1.19.1} to {@code 1}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* I'd not recommend developers to support individual patches at all. You should always support the latest patch.
|
||||
* For example, between v1.14.0, v1.14.1, v1.14.2, v1.14.3 and v1.14.4 you should only support v1.14.4
|
||||
|
@ -195,7 +200,7 @@ public final class ReflectionUtils {
|
|||
/* 17 */ 1,// \_!_/
|
||||
/* 18 */ 2,
|
||||
/* 19 */ 4,
|
||||
/* 20 */ 2,
|
||||
/* 20 */ 4,
|
||||
};
|
||||
|
||||
if (minorVersion > patches.length) return null;
|
||||
|
@ -558,4 +563,4 @@ public final class ReflectionUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue