Use sign with plot schematic
Tweak world unloading
This commit is contained in:
Jesse Boyd 2017-09-24 00:13:05 +10:00
parent 2360782234
commit 92f94ecedc
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
7 changed files with 98 additions and 12 deletions

View File

@ -200,7 +200,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
public void run() {
unload();
}
}, 20);
}, 5);
}
}
@ -211,19 +211,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
for (World world : Bukkit.getWorlds()) {
String name = world.getName();
char char0 = name.charAt(0);
if (!Character.isDigit(char0) && char0 != '-') continue;
if (!world.getPlayers().isEmpty()) continue;
PlotId id = PlotId.fromString(name);
if (id != null) {
Plot plot = area.getOwnedPlot(id);
if (plot != null) {
List<PlotPlayer> players = plot.getPlayersInPlot();
if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) {
for (Chunk chunk : world.getLoadedChunks()) {
if (!chunk.unload(true, false)) return;
if (System.currentTimeMillis() - start > 20) {
return;
}
if (PlotPlayer.wrap(plot.owner) == null) {
if (world.getKeepSpawnInMemory()) {
world.setKeepSpawnInMemory(false);
return;
}
Chunk[] chunks = world.getLoadedChunks();
if (chunks.length == 0) {
if (!Bukkit.unloadWorld(world, true)) {
PS.debug("Failed to unload " + world.getName());
}
return;
}
Bukkit.unloadWorld(world, true);
}
}
}

View File

@ -119,7 +119,15 @@ public class BukkitUtil extends WorldUtil {
World world = getWorld(worldName);
Block block = world.getBlockAt(x, y, z);
// block.setType(Material.AIR);
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
Material type = block.getType();
if (type != Material.SIGN && type != Material.SIGN_POST) {
int data = 2;
if (world.getBlockAt(x, y, z + 1).getType().isSolid()) data = 2;
else if (world.getBlockAt(x + 1, y, z).getType().isSolid()) data = 4;
else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) data = 3;
else if (world.getBlockAt(x - 1, y, z).getType().isSolid()) data = 5;
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) data, false);
}
BlockState blockstate = block.getState();
if (blockstate instanceof Sign) {
final Sign sign = (Sign) blockstate;

View File

@ -214,11 +214,15 @@ public class HybridGen extends IndependentPlotGenerator {
if (queue == null) {
queue = GlobalBlockQueue.IMP.getNewQueue(hpw.worldname, false);
}
SchematicHandler.manager.restoreTile(queue, entry.getValue(), p1x + x, entry.getKey(), p1z + z);
CompoundTag tag = entry.getValue();
SchematicHandler.manager.restoreTile(queue, tag, p1x + x, entry.getKey(), p1z + z);
}
}
}
}
if (queue != null) {
queue.flush();
}
}
return false;
}

View File

@ -208,4 +208,13 @@ public class HybridPlotManager extends ClassicPlotManager {
}
createSchemAbs(plotWorld, queue, l1, l2, false);
}
/**
* Remove sign for a plot.
*/
@Override
public Location getSignLoc(PlotArea plotArea, Plot plot) {
HybridPlotWorld dpw = (HybridPlotWorld) plotArea;
return dpw.getSignLocation(plot);
}
}

View File

@ -2,18 +2,21 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@ -26,6 +29,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public short PATH_WIDTH_UPPER;
public HashMap<Integer, char[]> G_SCH;
public HashMap<Integer, HashMap<Integer, CompoundTag>> G_SCH_STATE;
private Location SIGN_LOCATION;
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldName, id, generator, min, max);
@ -45,6 +49,19 @@ public class HybridPlotWorld extends ClassicPlotWorld {
return data;
}
public Location getSignLocation(Plot plot) {
plot = plot.getBasePlot(false);
Location bot = plot.getBottomAbs();
if (SIGN_LOCATION == null) {
bot.setY(ROAD_HEIGHT + 1);
return bot.add(-1, ROAD_HEIGHT, -2);
} else {
bot.setY(0);
Location loc = bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ());
return loc;
}
}
// FIXME depends on block ids
// Possibly make abstract?
public static byte rotate(short id, byte data) {
@ -228,6 +245,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
HashMap<BlockLoc, CompoundTag> items = schematic3.getTiles();
if (!items.isEmpty()) {
this.G_SCH_STATE = new HashMap<>();
outer:
for (Map.Entry<BlockLoc, CompoundTag> entry : items.entrySet()) {
BlockLoc loc = entry.getKey();
short x = (short) (loc.x + shift + oddshift + centerShiftX);
@ -240,6 +258,16 @@ public class HybridPlotWorld extends ClassicPlotWorld {
this.G_SCH_STATE.put(pair, existing);
}
existing.put((int) y, entry.getValue());
CompoundTag tag = entry.getValue();
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
for (int i = 1; i <= 4; i++) {
String ln = tag.getString("Line" + i);
if (ln == null || ln.length() > 11) continue outer;
}
SIGN_LOCATION = new Location(worldname, loc.x + centerShiftX, this.PLOT_HEIGHT + loc.y, loc.z + centerShiftZ);
ALLOW_SIGNS = true;
continue outer;
}
}
}

View File

@ -96,6 +96,30 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
}
public PlotId getNearestPlotId(PlotArea plotArea, int x, int y, int z) {
SquarePlotWorld dpw = (SquarePlotWorld) plotArea;
if (dpw.ROAD_OFFSET_X != 0) {
x -= dpw.ROAD_OFFSET_X;
}
if (dpw.ROAD_OFFSET_Z != 0) {
z -= dpw.ROAD_OFFSET_Z;
}
int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
int idx;
if (x < 0) {
idx = x / size;
} else {
idx = (x / size) + 1;
}
int idz;
if (z < 0) {
idz = z / size;
} else {
idz = (z / size) + 1;
}
return new PlotId(idx, idz);
}
@Override
public PlotId getPlotId(PlotArea plotArea, int x, int y, int z) {
try {

View File

@ -182,6 +182,12 @@ public class MathMan {
return new float[]{(float) (pitch_sin * Math.cos(yaw)), (float) (pitch_sin * Math.sin(yaw)), (float) Math.cos(pitch)};
}
public static int floorMod(int x, int y) {
int i = x % y;
if (i < 0) i += y;
return i;
}
public static int roundInt(double value) {
return (int) (value < 0 ? (value == (int) value) ? value : value - 1 : value);
}