Skip to content

Commit

Permalink
Upgraded to MC 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey-Terzi committed Oct 3, 2018
1 parent 284b844 commit 9fa505a
Show file tree
Hide file tree
Showing 50 changed files with 3,086 additions and 868 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.12-R0.1-SNAPSHOT</version>
<version>1.13.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public interface IBlockInfo {
int getX();
int getY();
int getZ();
int getTypeId();
int getCombinedId();
}
36 changes: 29 additions & 7 deletions API/src/main/java/com/lishid/orebfuscator/nms/INmsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@

package com.lishid.orebfuscator.nms;

import com.lishid.orebfuscator.types.ConfigDefaults;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;

import com.lishid.orebfuscator.types.BlockCoord;
import com.lishid.orebfuscator.types.BlockState;

import java.util.Set;

public interface INmsManager {
void setMaxLoadedCacheFiles(int value);
ConfigDefaults getConfigDefaults();

void setMaxLoadedCacheFiles(int value);

INBT createNBT();

Expand All @@ -25,12 +31,28 @@ public interface INmsManager {
int getBlockLightLevel(World world, int x, int y, int z);

IBlockInfo getBlockInfo(World world, int x, int y, int z);

BlockState getBlockState(World world, int x, int y, int z);

int getBlockId(World world, int x, int y, int z);

int loadChunkAndGetBlockId(World world, int x, int y, int z);

String getTextFromChatComponent(String json);
}

boolean isHoe(Material item);

boolean isSign(int combinedBlockId);

boolean isAir(int combinedBlockId);

boolean isTileEntity(int combinedBlockId);

int getCaveAirBlockId();

int getBitsPerBlock();

boolean canApplyPhysics(Material blockMaterial);

Set<Integer> getMaterialIds(Material material);

int getTypeId(int combinedBlockId);

boolean sendBlockChange(Player player, Location blockLocation);
}
11 changes: 0 additions & 11 deletions API/src/main/java/com/lishid/orebfuscator/types/BlockState.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @author Aleksey Terzi
*
*/

package com.lishid.orebfuscator.types;

public class ConfigDefaults {
public int[] defaultProximityHiderBlockIds;
public int[] defaultDarknessBlockIds;
public int defaultMode1BlockId;
public int defaultProximityHiderSpecialBlockId;

public int[] endWorldRandomBlockIds;
public int[] endWorldObfuscateBlockIds;
public int endWorldMode1BlockId;
public int[] endWorldRequiredObfuscateBlockIds;

public int[] netherWorldRandomBlockIds;
public int[] netherWorldObfuscateBlockIds;
public int netherWorldMode1BlockId;
public int[] netherWorldRequiredObfuscateBlockIds;

public int[] normalWorldRandomBlockIds;
public int[] normalWorldObfuscateBlockIds;
public int normalWorldMode1BlockId;
public int[] normalWorldRequiredObfuscateBlockIds;
}
22 changes: 19 additions & 3 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.3.4-SNAPSHOT</version>
<version>4.4.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.12-R0.1-SNAPSHOT</version>
<version>1.13.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down Expand Up @@ -89,7 +89,23 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>orebfuscator-v1_13_R1</artifactId>
<version>v1_13_R1</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>orebfuscator-v1_13_R2</artifactId>
<version>v1_13_R2</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<directory>../target</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,11 @@

package com.lishid.orebfuscator;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import com.lishid.orebfuscator.types.BlockState;

@SuppressWarnings("deprecation")
public class DeprecatedMethods {
public static Material getMaterial(int materialId) {
return Material.getMaterial(materialId);
}

public static int getMaterialId(Material material) {
return material.getId();
public static boolean isTransparent(Material material) {
return material.isTransparent();
}

public static boolean applyPhysics(Block block) {
// See net.minecraft.server.v1_4_5.BlockSand.canFall(World world, int i, int j, int k)

int blockID = block.getRelative(0, -1, 0).getTypeId();

int air = Material.AIR.getId();
int fire = Material.FIRE.getId();
int water = Material.WATER.getId();
int water2 = Material.STATIONARY_WATER.getId();
int lava = Material.LAVA.getId();
int lava2 = Material.STATIONARY_LAVA.getId();

return (blockID == air || blockID == fire || blockID == water || blockID == water2 || blockID == lava || blockID == lava2);
}

public static int getTypeId(Block block) {
return block.getTypeId();
}

public static void sendBlockChange(Player player, Location blockLocation, BlockState blockState) {
player.sendBlockChange(blockLocation, blockState.id, (byte)blockState.meta);
}
}
12 changes: 12 additions & 0 deletions Plugin/src/main/java/com/lishid/orebfuscator/NmsInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @author Aleksey Terzi
*
*/

package com.lishid.orebfuscator;

import com.lishid.orebfuscator.nms.INmsManager;

public class NmsInstance {
public static INmsManager current;
}
23 changes: 16 additions & 7 deletions Plugin/src/main/java/com/lishid/orebfuscator/Orebfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.*;
import java.util.logging.Logger;

import com.lishid.orebfuscator.chunkmap.ChunkMapBuffer;
import com.lishid.orebfuscator.utils.MaterialHelper;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -50,8 +52,6 @@ public class Orebfuscator extends JavaPlugin {
public static OrebfuscatorConfig config;
public static ConfigManager configManager;

public static INmsManager nms;

private boolean isProtocolLibFound;
public boolean getIsProtocolLibFound() {
return this.isProtocolLibFound;
Expand All @@ -64,7 +64,11 @@ public void onEnable() {
PluginManager pm = getServer().getPluginManager();

instance = this;
nms = createNmsManager();

NmsInstance.current = createNmsManager();

MaterialHelper.init();
ChunkMapBuffer.init(NmsInstance.current.getBitsPerBlock());

// Load configurations
loadOrebfuscatorConfig();
Expand All @@ -86,7 +90,7 @@ public void onEnable() {
(new ProtocolLibHook()).register(this);

// Run CacheCleaner
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new CacheCleaner(), 0, config.getCacheCleanRate());
getServer().getScheduler().runTaskTimerAsynchronously(this, new CacheCleaner(), 0, config.getCacheCleanRate());
}

public void loadOrebfuscatorConfig() {
Expand All @@ -99,7 +103,7 @@ public void loadOrebfuscatorConfig() {

ObfuscatedDataCache.resetCacheFolder();

nms.setMaxLoadedCacheFiles(config.getMaxLoadedCacheFiles());
NmsInstance.current.setMaxLoadedCacheFiles(config.getMaxLoadedCacheFiles());

//Make sure cache is cleared if config was changed since last start
try {
Expand All @@ -115,7 +119,6 @@ private void makeConfigExample() {
if(outputFile.exists()) return;

InputStream configStream = Orebfuscator.class.getResourceAsStream("/resources/config.example_enabledworlds.yml");
StringBuilder content = new StringBuilder();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(configStream));
PrintWriter writer = new PrintWriter(outputFile)
Expand All @@ -140,7 +143,13 @@ private static INmsManager createNmsManager() {

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

if(serverVersion.equals("v1_12_R1")) {
if(serverVersion.equals("v1_13_R2")) {
return new com.lishid.orebfuscator.nms.v1_13_R2.NmsManager();
}
else if(serverVersion.equals("v1_13_R1")) {
return new com.lishid.orebfuscator.nms.v1_13_R1.NmsManager();
}
else if(serverVersion.equals("v1_12_R1")) {
return new com.lishid.orebfuscator.nms.v1_12_R1.NmsManager();
}
else if(serverVersion.equals("v1_11_R1")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.io.DataOutputStream;
import java.io.File;

import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.NmsInstance;
import com.lishid.orebfuscator.nms.INBT;

public class ObfuscatedCachedChunk {
Expand All @@ -29,12 +29,13 @@ public class ObfuscatedCachedChunk {
int z;
public byte[] data;
public int[] proximityList;
public int[] removedEntityList;
public long hash = 0L;
private boolean loaded = false;

private static final ThreadLocal<INBT> nbtAccessor = new ThreadLocal<INBT>() {
protected INBT initialValue() {
return Orebfuscator.nms.createNBT();
return NmsInstance.current.createNBT();
}
};

Expand All @@ -46,12 +47,13 @@ public ObfuscatedCachedChunk(File file, int x, int z) {
}

public void invalidate() {
write(0L, new byte[0], new int[0]);
write(0L, new byte[0], new int[0], new int[0]);
}

public void free() {
data = null;
proximityList = null;
removedEntityList = null;
}

public long getHash() {
Expand Down Expand Up @@ -84,6 +86,7 @@ public void read() {
// Get Data
data = nbt.getByteArray("Data");
proximityList = nbt.getIntArray("ProximityList");
removedEntityList = nbt.getIntArray("RemovedEntityList");
loaded = true;
}
} catch (Exception e) {
Expand All @@ -93,7 +96,7 @@ public void read() {
}
}

public void write(long hash, byte[] data, int[] proximityList) {
public void write(long hash, byte[] data, int[] proximityList, int[] removedEntityList) {
try {
INBT nbt = nbtAccessor.get();
nbt.reset();
Expand All @@ -108,6 +111,7 @@ public void write(long hash, byte[] data, int[] proximityList) {
// Set data
nbt.setByteArray("Data", data);
nbt.setIntArray("ProximityList", proximityList);
nbt.setIntArray("RemovedEntityList", removedEntityList);

DataOutputStream stream = ObfuscatedDataCache.getOutputStream(path, x, z);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Date;
import java.util.Objects;

import com.lishid.orebfuscator.NmsInstance;
import org.bukkit.Bukkit;

import com.lishid.orebfuscator.Orebfuscator;
Expand All @@ -36,7 +37,7 @@ public class ObfuscatedDataCache {

private static IChunkCache getInternalCache() {
if (internalCache == null) {
internalCache = Orebfuscator.nms.createChunkCache();
internalCache = NmsInstance.current.createChunkCache();
}
return internalCache;
}
Expand Down
Loading

0 comments on commit 9fa505a

Please sign in to comment.