Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Update to 1.16.3
Browse files Browse the repository at this point in the history
  • Loading branch information
LlewVallis committed Sep 24, 2020
1 parent 2b34df5 commit 5a47ddc
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 111 deletions.
9 changes: 3 additions & 6 deletions agent/src/main/java/org/astropeci/omwagent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import javassist.*;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
import java.util.Date;

public class Agent {

Expand All @@ -34,7 +31,7 @@ public class Agent {

private static ClassPool classPool;

public static void premain(String args, Instrumentation instrumentation) throws FileNotFoundException {
public static void premain(String args, Instrumentation instrumentation) {
classPool = new ClassPool();
classPool.appendSystemPath();

Expand All @@ -45,7 +42,7 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
try {
classPool.makeClass(new ByteArrayInputStream(classfileBuffer));

if (className.matches("net/minecraft/server/v[_a-zA-Z0-9]+/ExplosionDamageCalculatorBlock")) {
if (className.matches("net/minecraft/server/v[_a-zA-Z0-9]+/ExplosionDamageCalculator")) {
return redefineExplosionDamageCalculator(className);
}

Expand Down Expand Up @@ -73,7 +70,7 @@ private static byte[] redefineExplosionDamageCalculator(String internalClassName
continue;
}

String nmsPackage = className.substring(0, className.indexOf("ExplosionDamageCalculatorBlock") - 1);
String nmsPackage = className.substring(0, className.indexOf("ExplosionDamageCalculator") - 1);
String payload = EXPLOSION_DAMAGE_CALCULATOR_INJECTION.replaceAll("\\$NMS", nmsPackage);

behavior.insertBefore(payload);
Expand Down
2 changes: 1 addition & 1 deletion artifacts/paper/url
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://papermc.io/ci/job/Paper-1.16/136/artifact/paperclip-136.jar
https://papermc.io/ci/job/Paper-1.16/204/artifact/paperclip-204.jar
1 change: 1 addition & 0 deletions artifacts/structureblocklib/url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/Shynixn/StructureBlockLib/releases/download/2.0.0/StructureBlockLib-Bukkit-Plugin.jar
7 changes: 7 additions & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
</repositories>

<dependencies>
<dependency>
<groupId>com.github.shynixn.structureblocklib</groupId>
<artifactId>structureblocklib-bukkit-api</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onEnable() {
arenaPool = new ArenaPool(template);
arenaPool.create("mw1");

structureManager = new StructureManager(worldManager);
structureManager = new StructureManager(this, worldManager);

EquipmentProvider equipmentProvider = new EquipmentProvider();

Expand Down
115 changes: 13 additions & 102 deletions plugin/src/main/java/org/astropeci/omw/structures/Structure.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.astropeci.omw.structures;

import com.github.shynixn.structureblocklib.api.bukkit.StructureBlockLibApi;
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
import lombok.Getter;
import org.astropeci.omw.teams.GameTeam;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -63,118 +65,27 @@ public boolean load(Location location, GameTeam team, Rotation rotation) {
private void loadUnsafe(Location target, String structureName, Rotation rotation) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException, InstantiationException {
Bukkit.getLogger().fine("Attempting to spawn structure " + structureName + " at " + target);

if (isClientSide(target.getWorld())) {
return;
}

delegateLoad(target, structureName, rotation);
}

/*
* Here comes NMS reflection blood magic...
*/

private void delegateLoad(Location target, String structureName, Rotation rotation) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
Class<?> c_definedStructureInfo = fetchClass("$NMS.DefinedStructureInfo");
Class<?> c_blockPosition = fetchClass("$NMS.BlockPosition");
Class<?> c_generatorAccess = fetchClass("$NMS.GeneratorAccess");
Class<?> c_definedStructure = fetchClass("$NMS.DefinedStructure");

Object targetBlockPosition = getTargetBlockPosition(target);
Object definedStructure = getDefinedStructure(structureName);
Object definedStructureInfo = getDefinedStructureInfo(rotation);
Object targetWorld = getNmsWorld(target.getWorld());

Method m_definedStructure_a = c_definedStructure.getDeclaredMethod("a", c_generatorAccess, c_blockPosition, c_definedStructureInfo, Random.class);
m_definedStructure_a.invoke(definedStructure, targetWorld, targetBlockPosition, definedStructureInfo, new Random());
}

private boolean isClientSide(World world) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
Class<?> c_world = fetchClass("$NMS.World");

Object nmsWorld = getNmsWorld(world);
return c_world.getDeclaredField("isClientSide").getBoolean(nmsWorld);
}

private Object getNmsWorld(World world) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> c_craftWorld = fetchClass("$OBC.CraftWorld");
return c_craftWorld.getDeclaredMethod("getHandle").invoke(world);
}

private Object getDefinedStructure(String structureName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class<?> c_minecraftKey = fetchClass("$NMS.MinecraftKey");
Class<?> c_worldServer = fetchClass("$NMS.WorldServer");
Class<?> c_definedStructureManager = fetchClass("$NMS.DefinedStructureManager");

Object nmsSourceWorlds = getNmsWorld(Bukkit.getWorld("world"));
Object structureManager = c_worldServer.getDeclaredMethod("r_").invoke(nmsSourceWorlds);

Object minecraftKey = c_minecraftKey.getDeclaredConstructor(String.class, String.class).newInstance(TRANSFORMED_AUTHOR, structureName);

Method m_definedStructureManager_a = c_definedStructureManager.getDeclaredMethod("a", c_minecraftKey);
return m_definedStructureManager_a.invoke(structureManager, minecraftKey);
}

private Object getTargetBlockPosition(Location target) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class<?> c_blockPosition = fetchClass("$NMS.BlockPosition");
Class<?> c_baseBlockPosition = fetchClass("$NMS.BaseBlockPosition");

Constructor<?> i_blockPosition = c_blockPosition.getConstructor(int.class, int.class, int.class);
Object originBlockPosition = i_blockPosition.newInstance(0, 0, 0);
Object targetOffsetBlockPosition = i_blockPosition.newInstance(target.getBlockX(), target.getBlockY(), target.getBlockZ());

Method m_blockPosition_a = c_blockPosition.getDeclaredMethod("a", c_baseBlockPosition);
return m_blockPosition_a.invoke(originBlockPosition, targetOffsetBlockPosition);
}

private Object getDefinedStructureInfo(Rotation rotation) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
Class<?> c_definedStructureInfo = fetchClass("$NMS.DefinedStructureInfo");
Class<?> c_enumBlockMirror = fetchClass("$NMS.EnumBlockMirror");
Class<?> c_enumBlockRotation = fetchClass("$NMS.EnumBlockRotation");
Class<?> c_chunkCoordIntPair = fetchClass("$NMS.ChunkCoordIntPair");

Object blockMirror = getBlockMirror();
Object blockRotation = getBlockRotation(rotation);

Object definedStructureInfo = c_definedStructureInfo.getDeclaredConstructor().newInstance();
c_definedStructureInfo.getDeclaredMethod("a", c_enumBlockMirror).invoke(definedStructureInfo, blockMirror);
c_definedStructureInfo.getDeclaredMethod("a", c_enumBlockRotation).invoke(definedStructureInfo, blockRotation);
c_definedStructureInfo.getDeclaredMethod("a", boolean.class).invoke(definedStructureInfo, true);
c_definedStructureInfo.getDeclaredMethod("a", c_chunkCoordIntPair).invoke(definedStructureInfo, new Object[] { null });
c_definedStructureInfo.getDeclaredMethod("c", boolean.class).invoke(definedStructureInfo, false);

return definedStructureInfo;
}

private Object getBlockMirror() throws ClassNotFoundException {
Class<?> c_enumBlockMirror = fetchClass("$NMS.EnumBlockMirror");

@SuppressWarnings("unchecked")
Object blockMirror = Enum.valueOf((Class) c_enumBlockMirror, "NONE");
return blockMirror;
}

private Object getBlockRotation(Rotation rotation) throws ClassNotFoundException {
Class<?> c_enumBlockRotation = fetchClass("$NMS.EnumBlockRotation");

String rotationValueName = null;
StructureRotation apiRotation = null;
switch (rotation) {
case ROTATE_0:
rotationValueName = "NONE";
apiRotation = StructureRotation.NONE;
break;
case ROTATE_90:
rotationValueName = "CLOCKWISE_90";
apiRotation = StructureRotation.ROTATION_90;
break;
case ROTATE_180:
rotationValueName = "CLOCKWISE_180";
apiRotation = StructureRotation.ROTATION_180;
break;
case ROTATE_270:
rotationValueName = "COUNTERCLOCKWISE_90";
apiRotation = StructureRotation.ROTATION_270;
break;
}

@SuppressWarnings("unchecked")
Object blockRotation = Enum.valueOf((Class) c_enumBlockRotation, rotationValueName);
return blockRotation;
StructureBlockLibApi.INSTANCE
.loadStructure(structureManager.getPlugin())
.at(target)
.rotation(apiRotation)
.loadFromPath(structureManager.getStructureDirectory(TRANSFORMED_AUTHOR).resolve(structureName + ".nbt"))
.onException(e -> Bukkit.getLogger().log(Level.WARNING, "Failed to load structure", e));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.astropeci.omw.structures;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import net.querz.nbt.io.NBTDeserializer;
Expand All @@ -11,6 +13,7 @@
import org.astropeci.omw.teams.GameTeam;
import org.astropeci.omw.worlds.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -23,6 +26,8 @@
@RequiredArgsConstructor
public class StructureManager implements AutoCloseable {

@Getter(AccessLevel.PACKAGE)
private final Plugin plugin;
private final WorldManager worldManager;

private final NBTSerializer nbtSerializer = new NBTSerializer();
Expand Down Expand Up @@ -125,7 +130,7 @@ public Set<String> getAllStructureNames() {
}
}

private Path getStructureDirectory(String author) {
/* package-private */ Path getStructureDirectory(String author) {
Path worldDirectory = worldManager.getDefaultWorld().getWorldFolder().toPath();
return worldDirectory.resolve(Path.of("generated", author, "structures"));
}
Expand Down
1 change: 1 addition & 0 deletions server/plugins/structureblocklib.jar

0 comments on commit 5a47ddc

Please sign in to comment.