Skip to content

Commit 6ff603e

Browse files
committed
Support 1.21
Signed-off-by: LSDog <LSDog@foxmail.com>
1 parent 9b6aa03 commit 6ff603e

7 files changed

Lines changed: 30 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ ___
1515
|:-------------------------:|----------------------------------------------------------|
1616
| ![logo](media/logo64.png) | CustomSprays <br> 花样喷漆 |
1717
| 作者 <br> Author | LSDog |
18-
| 版本 <br> Version | 1.5.12 |
19-
| 支持 <br> Support | **1.7.10 ~ 1.20.6** (Bukkit Spigot Paper ...) |
18+
| 版本 <br> Version | 1.5.13 |
19+
| 支持 <br> Support | **1.7.10 ~ 1.21** (Bukkit Spigot Paper ...) |
2020
| 指令 <br> Cmd | `/sprays` - 主命令 <br>`/spray` - 喷漆<br>`/spray big` - 喷大喷漆 |
2121
| 权限 <br> Perm | 请见 "config.yml" / see "config.yml" |
2222
>
@@ -72,7 +72,7 @@ ___
7272

7373
## 🎮 版本支持 | Version Support
7474
___
75-
> 🔷 **1.7.10 ~ 1.20.4**
75+
> 🔷 **1.7.10 ~ 1.21**
7676
7777
> 📏 支持的 **"领域"** 插件 | Supported **"region"** plugins:
7878
> - [x] Residence .......... [ *?* ~ 5.0.1.3+ ]

src/fun/LSDog/CustomSprays/spray/MapFrameFactory.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public static void init() {}
9494
}
9595

9696
cPacketPlayOutSpawnEntity = NMS.getConstructor(NMS.getPacketClass("PacketPlayOutSpawnEntity"),
97-
(subVer <= 13) ?
98-
MethodType.methodType(void.class, NMS.mcEntityClass, int.class, int.class) :
99-
MethodType.methodType(void.class, NMS.mcEntityClass, int.class));
97+
(subVer <= 13) ? MethodType.methodType(void.class, NMS.mcEntityClass, int.class, int.class)
98+
: (subVer <= 20) ? MethodType.methodType(void.class, NMS.mcEntityClass, int.class)
99+
: MethodType.methodType(void.class, NMS.mcEntityClass, int.class, NMS.mcBlockPositionClass));
100100

101101
if (subVer <= 12) {
102102
cItemStack = NMS.getConstructor(NMS.mcItemStackClass, MethodType.methodType(void.class, NMS.mcItemClass, int.class, int.class));
@@ -202,19 +202,29 @@ protected static Object getItemFrame(Object itemStack, Location location, BlockF
202202

203203

204204
/**
205-
* 获取生成 ItemFrame 的包
205+
* Get spawn packet of ItemFrame
206206
*/
207207
protected static Object getSpawnPacket(Object itemFrame, int intDirection) throws Throwable {
208208
int subVer = NMS.getSubVer();
209209
if (subVer <= 13) {
210210
/* ItemFrame, ItemFrameID:71, Data:Facing(int) */
211211
return cPacketPlayOutSpawnEntity.invoke(itemFrame, 71, intDirection);
212-
} else {
212+
} else if (subVer <= 20) {
213213
/* ItemFrame, Data:Facing(int) */
214214
return cPacketPlayOutSpawnEntity.invoke(itemFrame, intDirection);
215+
} else {
216+
throw new RuntimeException("SpawnPacket in 1.21+ requires a BlockPosition!");
215217
}
216218
}
217219

220+
/**
221+
* version >= 1.21
222+
* Get spawn packet of ItemFrame
223+
*/
224+
protected static Object getSpawnPacket(Object itemFrame, int intDirection, Object blockPosition) throws Throwable {
225+
return cPacketPlayOutSpawnEntity.invoke(itemFrame, intDirection, blockPosition);
226+
}
227+
218228
/**
219229
* 获取 NMS map
220230
*/

src/fun/LSDog/CustomSprays/spray/SprayBase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public abstract class SprayBase implements ISpray {
3030
public Location location;
3131
public BlockFace blockFace;
3232
public double distance;
33-
protected Location playerLocation;
3433
protected int intDirection;
3534
protected int intRotation;
3635

@@ -68,9 +67,8 @@ public boolean init(long removeTick) {
6867
location = block.getLocation();
6968
blockFace = ray.blockFace;
7069
distance = ray.distance;
71-
playerLocation = player.getLocation();
7270
intDirection = MapFrameFactory.blockFaceToIntDirection(ray.blockFace);
73-
intRotation = MapFrameFactory.getItemFrameRotate(location, blockFace);
71+
intRotation = MapFrameFactory.getItemFrameRotate(player.getLocation(), blockFace);
7472

7573
// ↓喷漆占用就取消
7674
if (SprayManager.hasSpray(ray.getRelativeBlock(), ray.blockFace)) return false;

src/fun/LSDog/CustomSprays/spray/SprayBig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public void valid() throws Throwable {
8888
offLocs[i] = NMS.getSubVer() >= 8 ? reLoc : reLoc.add(-blockFace.getModX(), 0, -blockFace.getModZ());
8989
itemFrames[i] = MapFrameFactory.getItemFrame(mcMap, offLocs[i], blockFace, intRotation);
9090
itemFrameIds[i] = NMS.getMcEntityId(itemFrames[i]);
91-
spawnPackets[i] = MapFrameFactory.getSpawnPacket(itemFrames[i], intDirection);
91+
if (NMS.getSubVer() <= 20) spawnPackets[i] = MapFrameFactory.getSpawnPacket(itemFrames[i], intDirection);
92+
else spawnPackets[i] = MapFrameFactory.getSpawnPacket(itemFrames[i], intDirection, NMS.getMcBlockPosition(locs[i]));
9293
if (NMS.getSubVer() <= 7) {
9394
NMS.setSpawnPacketLocation_7(spawnPackets[i], offLocs[i]);
9495
mapPackets_7s[i] = MapFrameFactory.getMapPackets_7((short) mapViewId, pixelPieces[i]);

src/fun/LSDog/CustomSprays/spray/SpraySmall.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public void valid() throws Throwable {
3838
Object mcMap = MapFrameFactory.getMcMap(mapViewId);
3939
Object itemFrame = MapFrameFactory.getItemFrame(mcMap, offLoc, blockFace, intRotation);
4040
itemFrameId = NMS.getMcEntityId(itemFrame);
41-
spawnPacket = MapFrameFactory.getSpawnPacket(itemFrame, intDirection);
41+
if (NMS.getSubVer() <= 20) spawnPacket = MapFrameFactory.getSpawnPacket(itemFrame, intDirection);
42+
else spawnPacket = MapFrameFactory.getSpawnPacket(itemFrame, intDirection, NMS.getMcBlockPosition(location));
4243
if (NMS.getSubVer() <= 7) {
4344
NMS.setSpawnPacketLocation_7(spawnPacket, offLoc);
4445
mapPackets_7 = MapFrameFactory.getMapPackets_7((short) mapViewId, pixels);
@@ -48,7 +49,6 @@ public void valid() throws Throwable {
4849
dataPacket = NMS.getPacketPlayOutEntityMetadata(itemFrame);
4950

5051
valid = true;
51-
5252
}
5353

5454
/**
@@ -77,6 +77,7 @@ public void spawn(Collection<? extends Player> playersShowTo, boolean playSound,
7777

7878
if (spawnParticle && NMS.getSubVer() >= 9) ParticleUtil.playSprayParticleEffect(this, 3, 1, 0.8, 80);
7979
if (playSound) SprayManager.playSpraySound(player);
80+
8081
}
8182

8283

src/fun/LSDog/CustomSprays/util/NMS.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ public static int getSubRVer() {
189189
case 18: name = "ae"; break;
190190
case 19: name = subRVer == 1 ? "ae" : subRVer == 2 ? "ah" : "af"; break;
191191
case 20: name = subRVer == 1 ? "af" : subRVer == 2 ? "ah" : subRVer == 3 ? "aj" : "al"; break;
192-
default: name = "al"; break;
192+
case 21: name = "an";
193+
default: name = "an"; break;
193194
}
194195
Entity_getId = getMethodVirtual(mcEntityClass, name, MethodType.methodType(int.class));
195196

@@ -198,15 +199,15 @@ public static int getSubRVer() {
198199
case 18: name = "ai"; break;
199200
case 19: name = subRVer == 1 ? "ai" : subRVer == 2 ? "al" : "aj"; break;
200201
case 20: name = subRVer == 1 ? "aj" : subRVer == 2 ? "al" : subRVer == 3 ? "an" : "ap"; break;
201-
default: name = "ap"; break;
202+
case 21:
203+
default: name = "ar"; break;
202204
}
203205
Entity_getDataWatcher = getMethodVirtual(mcEntityClass, name, MethodType.methodType(mcDataWatcherClass));
204206

205207
if (subVer <= 17) name = "sendPacket";
206208
else if (subVer < 20 || (subVer == 20 && subRVer <= 1)) name = "a";
207209
else name = "b"; // wtf 你为什么要在1.20.2这个小版本改这个 mojang你丧尽天良啊啊啊啊啊啊
208-
PlayerConnection_sendPacket = getMethodVirtual(
209-
mcPlayerConnectionClass, name, MethodType.methodType(void.class, getPacketClass()));
210+
PlayerConnection_sendPacket = getMethodVirtual(mcPlayerConnectionClass, name, MethodType.methodType(void.class, getPacketClass()));
210211

211212
DataWatcher_getNonDefaultValues = (subVer > 19 || (subVer == 19 && subRVer > 1)) ?
212213
getMethodVirtual(mcDataWatcherClass, "c", MethodType.methodType(List.class)) : null;

src/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: CustomSprays
2-
version: 1.5.12
2+
version: 1.5.13
33
main: fun.LSDog.CustomSprays.CustomSprays
44
authors: [LSDog]
55
softdepend: [PlaceholderAPI,WorldEdit,FastAsyncWorldEdit,Residence,WorldGuard,GriefDefender,Vault]

0 commit comments

Comments
 (0)