Skip to content

Commit

Permalink
Prepare MCAccessBukkitModern (1.13).
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Aug 20, 2018
1 parent 40b0107 commit 54c022f
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
2 changes: 1 addition & 1 deletion NCPCompatBukkit/pom.xml
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
@@ -0,0 +1,29 @@
package fr.neatmonster.nocheatplus.compat.bukkit;

import org.bukkit.World;

/**
* BlockCache for MCAccessBukkitModern.
*
* @author asofold
*
*/
public class BlockCacheBukkitModern extends BlockCacheBukkit {

public BlockCacheBukkitModern(World world) {
super(world);
}

@Override
public int fetchData(int x, int y, int z) {
// TODO: Might fake here too.
return super.fetchData(x, y, z);
}

@Override
public double[] fetchBounds(int x, int y, int z) {
// TODO: Fetch what's possible to fetch/guess (...).
return super.fetchBounds(x, y, z);
}

}
Expand Up @@ -17,11 +17,13 @@

import org.bukkit.Material;

import fr.neatmonster.nocheatplus.compat.BridgeMaterial;
import fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup;
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
import fr.neatmonster.nocheatplus.logging.StaticLog;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;

public class MCAccessBukkit extends MCAccessBukkitBase implements BlockPropertiesSetup{
public class MCAccessBukkit extends MCAccessBukkitBase implements BlockPropertiesSetup {

public MCAccessBukkit() {
super();
Expand All @@ -37,21 +39,24 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
}
else if (guessItchyBlock(mat)) {
// Uncertain bounding-box, allow passing through.
StaticLog.logDebug("Itchy: " + mat);
long flags = BlockProperties.F_IGN_PASSABLE;
if ((BlockProperties.isSolid(mat) || BlockProperties.isGround(mat)) && !BlockProperties.isLiquid(mat)) {
if ((BlockProperties.isSolid(mat)
|| BlockProperties.isGround(mat))) {
// Block can be ground, so allow standing on any height.
flags |= BlockProperties.F_GROUND_HEIGHT;
flags |= BlockProperties.F_GROUND | BlockProperties.F_GROUND_HEIGHT;
}
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
}
}
// Blocks that are reported to be full and solid, but which are not.
final long flags = BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT;
for (final Material mat : new Material[]{
Material.ENDER_PORTAL_FRAME,
BridgeMaterial.END_PORTAL_FRAME,
}) {
// TODO: Add BlockFlags.FULL_BOUNDS?
final long flags = BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT;
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
if (!processedBlocks.contains(mat)) {
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
}
}
}

Expand Down
Expand Up @@ -14,6 +14,9 @@
*/
package fr.neatmonster.nocheatplus.compat.bukkit;

import java.util.LinkedHashSet;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -43,13 +46,19 @@ public class MCAccessBukkitBase implements MCAccess {
// private AlmostBoolean entityPlayerAvailable = AlmostBoolean.MAYBE;
protected final boolean bukkitHasGetHeightAndGetWidth;

/**
* Fill in already initialized blocks, to return false for guessItchyBlock.
*/
protected final Set<Material> processedBlocks = new LinkedHashSet<Material>();

private boolean guessItchyBlockPre1_13(final Material mat) {
return !mat.isOccluding() || !mat.isSolid() || mat.isTransparent();
}

protected boolean guessItchyBlock(final Material mat) {
// General considerations first.
if (BlockProperties.isAir(mat) || BlockProperties.isLiquid(mat)) {
if (processedBlocks.contains(mat)
|| BlockProperties.isAir(mat) || BlockProperties.isLiquid(mat)) {
return false;
}
// Fully solid/ground blocks.
Expand All @@ -58,7 +67,7 @@ protected boolean guessItchyBlock(final Material mat) {
* Skip fully passable blocks (partially passable blocks may be itchy,
* though slabs will be easy to handle).
*/
if (BlockFlags.hasAnyFlag(flags,BlockProperties.F_IGN_PASSABLE)) {
if (BlockFlags.hasAnyFlag(flags, BlockProperties.F_IGN_PASSABLE)) {
// TODO: Blocks with min_height may actually be ok, if xz100 and some height are set.
if (BlockFlags.hasNoFlags(flags,
BlockProperties.F_GROUND_HEIGHT
Expand All @@ -75,7 +84,7 @@ protected boolean guessItchyBlock(final Material mat) {
long testFlags = (BlockProperties.F_SOLID | BlockProperties.F_XZ100
| BlockProperties.F_HEIGHT100);
if (BlockFlags.hasAllFlags(flags, testFlags)) {
// Fully solid block!
// Fully solid block.
return false;
}

Expand Down
@@ -0,0 +1,31 @@
package fr.neatmonster.nocheatplus.compat.bukkit;

import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;

public class MCAccessBukkitModern extends MCAccessBukkit {

public MCAccessBukkitModern() {
super();
}
@Override
public String getMCVersion() {
return "1.13|?";
}

@Override
public BlockCache getBlockCache() {
return new BlockCacheBukkitModern(null);
}

@Override
public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvider) {

// TODO: Initialize some blocks and add to this.processedBlocks.

super.setupBlockProperties(worldConfigProvider);
}



}
Expand Up @@ -22,6 +22,7 @@

import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.compat.bukkit.MCAccessBukkit;
import fr.neatmonster.nocheatplus.compat.bukkit.MCAccessBukkitModern;
import fr.neatmonster.nocheatplus.compat.cbreflect.MCAccessCBReflect;
import fr.neatmonster.nocheatplus.logging.StaticLog;

Expand Down Expand Up @@ -66,6 +67,14 @@ public MCAccess getMCAccess(final MCAccessConfig config) {
}
}

// Bukkit API only: 1.13 (and possibly later).
try {
return new MCAccessBukkitModern();
}
catch(Throwable t) {
throwables.add(t);
}

// Try to set up api-only access (since 1.4.6).
try {
mcAccess = new MCAccessBukkit();
Expand Down

0 comments on commit 54c022f

Please sign in to comment.