Archived
0

add repository layout, updateAdjacentComparators api

This commit is contained in:
Dico200
2018-01-30 20:13:39 +00:00
commit d121520e0f
6 changed files with 212 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.iml
.idea/
out/
target/

49
Nms-v1_12_R1/pom.xml Normal file
View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.redstoner.nms</groupId>
<artifactId>Nms-v1_12_R1</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--Spigot API and NMS-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>D:/Resources/Java/minecraft/spigot-1.12.2.jar</systemPath>
</dependency>
<dependency>
<groupId>com.redstoner.nms</groupId>
<artifactId>NmsApi</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,29 @@
package com.redstoner.nms.v1_12_R1;
import com.redstoner.nms.INmsDriver;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
final class NmsDriver implements INmsDriver
{
@Override
public void updateAdjacentComparators(Block block)
{
updateAdjacentComparators(block.getWorld(), block.getX(), block.getY(), block.getZ());
}
@Override
public void updateAdjacentComparators(World world, int blockX, int blockY, int blockZ)
{
WorldServer handle = ((CraftWorld) world).getHandle();
BlockPosition bp = new BlockPosition(blockX, blockY, blockZ);
IBlockData type = handle.c(bp);
handle.updateAdjacentComparators(bp, type.getBlock());
}
}

49
pom.xml Normal file
View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.redstoner.nms</groupId>
<artifactId>NmsApi</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--Bukkit API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,26 @@
package com.redstoner.nms;
import org.bukkit.World;
import org.bukkit.block.Block;
public interface INmsDriver
{
/**
* Update comparators adjacent to the given block
*
* @param block the block
*/
void updateAdjacentComparators(Block block);
/**
* Update comparators adjacent to the given coordinates
*
* @param world the world
* @param blockX x coord
* @param blockY y coord
* @param blockZ z coord
*/
void updateAdjacentComparators(World world, int blockX, int blockY, int blockZ);
}

View File

@@ -0,0 +1,55 @@
package com.redstoner.nms;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
public class NmsFactory
{
private static final String NMS_DRIVER_CLASS = "com.redstoner.nms.%s.NmsDriver";
private static final INmsDriver driver;
private static final String nmsPackage;
private static void logError(String description, Throwable error) {
Bukkit.getLogger().severe("[Nms API] " + description);
error.printStackTrace();
}
static {
/*
Static initialization should never throw an error
This would cause the error to propagate to the code that first uses the driver,
causing arbitrary parts of the server code to fail and other's to get null.
If an exception occurs during initialization, this is instead printed to the console.
*/
// get the nms package from the server
String[] split = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
nmsPackage = split[split.length - 1];
// instantiate the driver
INmsDriver localDriver;
try {
String driverClassName = String.format(NMS_DRIVER_CLASS, nmsPackage);
Class<?> driverClass = Class.forName(driverClassName);
// get no-arg constructor explicitly, because direct newInstance() requires the driver to be public
Constructor<?> constructor = driverClass.getConstructor();
constructor.setAccessible(true);
localDriver = (INmsDriver) constructor.newInstance();
} catch (Exception ex) {
// could use a mock implementation here to avoid NPE
localDriver = null;
logError("reflectively instantiating the Nms Driver for version " + nmsPackage, ex);
}
driver = localDriver;
}
public static INmsDriver getDriver() {
return driver;
}
public static String getNmsPackage() {
return nmsPackage;
}
}