Skip to content

Commit

Permalink
Add support for bukkit/spigot 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey-Terzi committed Nov 17, 2016
1 parent b132147 commit ce1b92a
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 4 deletions.
2 changes: 1 addition & 1 deletion API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
12 changes: 10 additions & 2 deletions Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.1.14-SNAPSHOT</version>
<version>4.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Orebfuscator4</name>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down Expand Up @@ -73,6 +73,14 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>orebfuscator-v1_11_R1</artifactId>
<version>v1_11_R1</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ private static INmsManager createNmsManager() {

String serverVersion = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];

if(serverVersion.equals("v1_10_R1")) {
if(serverVersion.equals("v1_11_R1")) {
return new com.lishid.orebfuscator.nms.v1_11_R1.NmsManager();
}
else if(serverVersion.equals("v1_10_R1")) {
return new com.lishid.orebfuscator.nms.v1_10_R1.NmsManager();
}
else if(serverVersion.equals("v1_9_R2")) {
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<module>v1_9_R1</module>
<module>v1_9_R2</module>
<module>v1_10_R1</module>
<module>v1_11_R1</module>
<module>API</module>
</modules>

Expand Down
46 changes: 46 additions & 0 deletions v1_11_R1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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.lishid</groupId>
<artifactId>orebfuscator-v1_11_R1</artifactId>
<version>v1_11_R1</version>
<packaging>jar</packaging>
<name>Orebfuscator4 v1_11_R1</name>

<parent>
<groupId>com.lishid.parent</groupId>
<artifactId>orebfuscator-parent</artifactId>
<version>parent</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>orebfuscator-api</artifactId>
<version>API</version>
<type>jar</type>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @author Aleksey Terzi
*
*/

package com.lishid.orebfuscator.nms.v1_11_R1;

import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.IBlockData;

import com.lishid.orebfuscator.nms.IBlockInfo;

public class BlockInfo implements IBlockInfo {
private int x;
private int y;
private int z;
private IBlockData blockData;

public BlockInfo(int x, int y, int z, IBlockData blockData) {
this.x = x;
this.y = y;
this.z = z;
this.blockData = blockData;
}

public int getX() {
return this.x;
}

public int getY() {
return this.y;
}

public int getZ() {
return this.z;
}

public int getTypeId() {
return Block.getId(this.blockData.getBlock());
}

public IBlockData getBlockData() {
return this.blockData;
}

@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof BlockInfo)) {
return false;
}
BlockInfo object = (BlockInfo) other;

return this.x == object.x && this.y == object.y && this.z == object.z;
}

@Override
public int hashCode() {
return this.x ^ this.y ^ this.z;
}

@Override
public String toString() {
return this.x + " " + this.y + " " + this.z;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @author lishid
* @author Aleksey Terzi
*
*/

package com.lishid.orebfuscator.nms.v1_11_R1;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;

import net.minecraft.server.v1_11_R1.RegionFile;

import com.lishid.orebfuscator.nms.IChunkCache;

public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();

private int maxLoadedCacheFiles;

public ChunkCache(int maxLoadedCacheFiles) {
this.maxLoadedCacheFiles = maxLoadedCacheFiles;
}

public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}

public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}

public void closeCacheFiles() {
closeCacheFilesInternal();
}

private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}

if (!path.exists()) {
path.mkdirs();
}

if (cachedRegionFiles.size() >= this.maxLoadedCacheFiles) {
closeCacheFiles();
}

regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);

return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
}
}
return null;
}

private synchronized void closeCacheFilesInternal() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author Aleksey Terzi
*
*/

package com.lishid.orebfuscator.nms.v1_11_R1;

import java.util.HashSet;

import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_11_R1.PacketPlayOutUnloadChunk;
import net.minecraft.server.v1_11_R1.PlayerChunk;
import net.minecraft.server.v1_11_R1.PlayerChunkMap;

import org.bukkit.entity.Player;

import com.lishid.orebfuscator.nms.IChunkManager;

public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;

public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
}

public boolean resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return true;

PlayerChunk playerChunk = this.chunkMap.getChunk(chunkX, chunkZ);

if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;

for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
player.playerConnection.sendPacket(new PacketPlayOutMapChunk(playerChunk.chunk, 0xffff));

affectedPlayers.add(player.getBukkitEntity());
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @author lishid
* @author Aleksey Terzi
*
*/

package com.lishid.orebfuscator.nms.v1_11_R1;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.IOException;

import net.minecraft.server.v1_11_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_11_R1.NBTTagCompound;

import com.lishid.orebfuscator.nms.INBT;

public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();

public void reset() {
nbt = new NBTTagCompound();
}

public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}

public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}

public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}

public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}

public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}

public int getInt(String tag) {
return nbt.getInt(tag);
}

public long getLong(String tag) {
return nbt.getLong(tag);
}

public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}

public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}

public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}

public void Read(DataInput stream) throws IOException {
nbt = NBTCompressedStreamTools.a((DataInputStream) stream);
}

public void Write(DataOutput stream) throws IOException {
NBTCompressedStreamTools.a(nbt, stream);
}
}
Loading

0 comments on commit ce1b92a

Please sign in to comment.