tweak blockpos abstraction

This commit is contained in:
nossr50 2019-02-13 10:22:58 -08:00
parent 9383b1c65c
commit 3a7b6fef7d
10 changed files with 67 additions and 52 deletions

View File

@ -1,9 +1,9 @@
package com.gmail.nossr50.core.data.blockmeta.chunkmeta; package com.gmail.nossr50.core.data.blockmeta.chunkmeta;
import org.bukkit.World; import com.gmail.nossr50.core.mcmmo.block.Block;
import org.bukkit.block.Block; import com.gmail.nossr50.core.mcmmo.block.BlockState;
import org.bukkit.block.BlockState; import com.gmail.nossr50.core.mcmmo.entity.Entity;
import org.bukkit.entity.Entity; import com.gmail.nossr50.core.mcmmo.world.World;
import java.io.IOException; import java.io.IOException;

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.core.data.blockmeta.chunkmeta; package com.gmail.nossr50.core.data.blockmeta.chunkmeta;
import org.bukkit.World; import com.gmail.nossr50.core.mcmmo.world.World;
public class ChunkStoreFactory { public class ChunkStoreFactory {
protected static ChunkStore getChunkStore(World world, int x, int z) { protected static ChunkStore getChunkStore(World world, int x, int z) {

View File

@ -1,11 +1,11 @@
package com.gmail.nossr50.core.data.blockmeta.chunkmeta; package com.gmail.nossr50.core.data.blockmeta.chunkmeta;
import com.gmail.nossr50.core.data.blockmeta.blockmeta.conversion.BlockStoreConversionZDirectory; import com.gmail.nossr50.core.McmmoCore;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.core.data.blockmeta.conversion.BlockStoreConversionZDirectory;
import org.bukkit.World; import com.gmail.nossr50.core.mcmmo.block.Block;
import org.bukkit.block.Block; import com.gmail.nossr50.core.mcmmo.block.BlockState;
import org.bukkit.block.BlockState; import com.gmail.nossr50.core.mcmmo.entity.Entity;
import org.bukkit.entity.Entity; import com.gmail.nossr50.core.mcmmo.world.World;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -90,7 +90,7 @@ public class HashChunkManager implements ChunkManager {
directory.mkdirs(); directory.mkdirs();
UUID key = world.getUID(); UUID key = world.getUUID();
HashMap<Long, McMMOSimpleRegionFile> worldRegions = regionFiles.get(key); HashMap<Long, McMMOSimpleRegionFile> worldRegions = regionFiles.get(key);
@ -131,7 +131,7 @@ public class HashChunkManager implements ChunkManager {
return; return;
} }
UUID key = world.getUID(); UUID key = world.getUUID();
if (!oldData.containsKey(key)) { if (!oldData.containsKey(key)) {
oldData.put(key, (new File(world.getWorldFolder(), "mcmmo_data")).exists()); oldData.put(key, (new File(world.getWorldFolder(), "mcmmo_data")).exists());
@ -260,7 +260,7 @@ public class HashChunkManager implements ChunkManager {
public synchronized void saveAll() { public synchronized void saveAll() {
closeAll(); closeAll();
for (World world : mcMMO.p.getServer().getWorlds()) { for (World world : McmmoCore.getServer().getWorlds()) {
saveWorld(world); saveWorld(world);
} }
} }
@ -269,7 +269,7 @@ public class HashChunkManager implements ChunkManager {
public synchronized void unloadAll() { public synchronized void unloadAll() {
closeAll(); closeAll();
for (World world : mcMMO.p.getServer().getWorlds()) { for (World world : McmmoCore.getServer().getWorlds()) {
unloadWorld(world); unloadWorld(world);
} }
} }
@ -315,7 +315,7 @@ public class HashChunkManager implements ChunkManager {
return false; return false;
} }
return isTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld()); return isTrue(blockState.getBlock().getX(), blockState.getBlock().getY(), blockState.getBlock().getZ(), blockState.getBlock().getWorld());
} }
@Override @Override
@ -361,7 +361,7 @@ public class HashChunkManager implements ChunkManager {
return; return;
} }
setTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld()); setTrue(blockState.getBlock().getX(), blockState.getBlock().getY(), blockState.getBlock().getZ(), blockState.getBlock().getWorld());
} }
@Override @Override
@ -406,7 +406,7 @@ public class HashChunkManager implements ChunkManager {
return; return;
} }
setFalse(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld()); setFalse(blockState.getBlock().getX(), blockState.getBlock().getY(), blockState.getBlock().getZ(), blockState.getBlock().getWorld());
} }
@Override @Override

View File

@ -1,9 +1,9 @@
package com.gmail.nossr50.core.data.blockmeta.chunkmeta; package com.gmail.nossr50.core.data.blockmeta.chunkmeta;
import org.bukkit.World; import com.gmail.nossr50.core.mcmmo.block.Block;
import org.bukkit.block.Block; import com.gmail.nossr50.core.mcmmo.block.BlockState;
import org.bukkit.block.BlockState; import com.gmail.nossr50.core.mcmmo.entity.Entity;
import org.bukkit.entity.Entity; import com.gmail.nossr50.core.mcmmo.world.World;
import java.io.IOException; import java.io.IOException;

View File

@ -24,7 +24,7 @@ public class PrimitiveChunkStore implements ChunkStore {
public PrimitiveChunkStore(World world, int cx, int cz) { public PrimitiveChunkStore(World world, int cx, int cz) {
this.cx = cx; this.cx = cx;
this.cz = cz; this.cz = cz;
this.worldUid = world.getUID(); this.worldUid = world.getUUID();
this.store = new boolean[16][16][world.getMaxHeight()]; this.store = new boolean[16][16][world.getMaxHeight()];
} }

View File

@ -6,31 +6,10 @@ package com.gmail.nossr50.core.mcmmo.block;
* @see Property * @see Property
* @see BlockState * @see BlockState
*/ */
public class Block { public interface Block extends BlockPos {
private final String unlocalizedName; //The name before it is localized (english)
private BlockState blockState;
public Block(String unlocalizedName, BlockState blockState) {
this.unlocalizedName = unlocalizedName;
this.blockState = blockState;
}
/** /**
* Gets the name of this block in English * Get the state for this block
* * @return the block state
* @return name of this block in English
*/ */
public String getUnlocalizedName() { BlockState getBlockState();
return unlocalizedName;
}
/**
* Gets the state of this block
*
* @return the state of this block
*/
public BlockState getBlockState() {
return blockState;
}
} }

View File

@ -0,0 +1,21 @@
package com.gmail.nossr50.core.mcmmo.block;
import com.gmail.nossr50.core.mcmmo.world.World;
/**
* Block positions are handled a bit differently than other locations
*/
public interface BlockPos {
int getX();
int getY();
int getZ();
/**
* Gets the world for this block
* @return this block's world
*/
World getWorld();
}

View File

@ -19,21 +19,21 @@ public interface Location {
* *
* @return x-axis position * @return x-axis position
*/ */
//double getX(); default double getX() { return getVector().getX(); }
/** /**
* Returns the position of this location on the y-axis * Returns the position of this location on the y-axis
* *
* @return y-axis position * @return y-axis position
*/ */
//double getY(); default double getY() { return getVector().getY(); }
/** /**
* Returns the position of this location on the z-axis * Returns the position of this location on the z-axis
* *
* @return z-axis position * @return z-axis position
*/ */
//double getZ(); default double getZ() { return getVector().getZ(); }
/** /**
* The world for this Location * The world for this Location

View File

@ -2,6 +2,8 @@ package com.gmail.nossr50.core.mcmmo.world;
import com.gmail.nossr50.core.mcmmo.Unique; import com.gmail.nossr50.core.mcmmo.Unique;
import java.io.File;
/** /**
* Represents a world in MC * Represents a world in MC
*/ */
@ -12,4 +14,17 @@ public interface World extends Unique {
* @return the name of this world * @return the name of this world
*/ */
String getName(); String getName();
/**
* Gets the folder on disk for this world
*
* @return the folder on disk for this world
*/
File getWorldFolder();
/**
* Gets the max height for this world
* @return the max height
*/
int getMaxHeight();
} }

View File

@ -32,7 +32,7 @@ public interface Platform {
* *
* @return true if the platform is loaded * @return true if the platform is loaded
*/ */
Boolean isPlatformLoaded(); boolean isPlatformLoaded();
/** /**
* Gets the PlatformSoftwareType for this platform * Gets the PlatformSoftwareType for this platform