1
0
Fork 0

began set up of chunk loader

This commit is contained in:
lightling 2019-09-19 17:25:13 -04:00
parent 7c08152114
commit 4f7fdf62a6
3 changed files with 38 additions and 2 deletions

View file

@ -2,6 +2,10 @@ package lightling.gibsoniacraft;
// Server related
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Chunk;
import org.bukkit.World;
import java.util.ArrayList;
// GibsoniaCraft related
import lightling.gibsoniacraft.crafting.Excavator;
@ -18,6 +22,7 @@ public final class GibsoniaCraft extends JavaPlugin {
private LumberAxe lumberAxeClass;
private PlayerInteractListener pListener;
private BlockListener bListener;
private ArrayList<Chunk> loadedChunks;
@Override
public void onEnable() {
@ -26,6 +31,16 @@ public final class GibsoniaCraft extends JavaPlugin {
lumberAxeClass = new LumberAxe(this);
pListener = new PlayerInteractListener(this);
bListener = new BlockListener(this);
// Load all force-loaded chunks upon server restart
this.loadedChunks = new ArrayList<Chunk>();
for (final World world : this.getServer().getWorlds())
{
for (final Chunk chunk : world.getForceLoadedChunks())
{
this.loadedChunks.add(chunk);
}
}
}
@Override
@ -38,4 +53,17 @@ public final class GibsoniaCraft extends JavaPlugin {
return pListener;
}
/**
* Adds a chunk to the list of force-loaded chunks
* @param chunk The chunk to set as force-loaded
*/
public void ForceChunkActive(final Chunk chunk)
{
if (!this.loadedChunks.contains(chunk))
{
chunk.setForceLoaded(true);
}
this.loadedChunks.add(chunk);
}
}

View file

@ -5,6 +5,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.Chunk;
import org.bukkit.Location;
// Collections
@ -16,6 +17,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import lightling.gibsoniacraft.GibsoniaCraft;
import lightling.gibsoniacraft.lib.BlockRef;
import lightling.gibsoniacraft.util.ToolUtil;
@ -302,4 +305,11 @@ public class BlockListener implements Listener
dMeta.setDamage(currDur + addToDamage);
item.setItemMeta(meta);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void LoaderPlace(BlockPlaceEvent bpEvent)
{
Chunk chunk = bpEvent.getBlock().getLocation().getChunk();
this.gcPlugin.ForceChunkActive(chunk);
}
}

View file

@ -267,7 +267,5 @@ public class ToolUtil
return blocks;
}
// TO-DO: Implement enchantments
// TO-DO: Implement scythes (3x3 harvest) and tillers (3x3 hoe)
}