Working on flag system

This commit is contained in:
boy0001 2015-01-07 03:08:29 +11:00
parent 6b988f616a
commit 277018df63
15 changed files with 118 additions and 58 deletions

View file

@ -24,9 +24,12 @@ package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.listeners.PlotListener;
import com.intellectualcrafters.plot.object.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.*;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
@ -1051,6 +1054,71 @@ import java.util.UUID;
final PlotManager manager = PlotMain.getPlotManager(world);
return manager.getPlotBottomLocAbs(plotworld, id);
}
public static boolean checkModified(Plot plot, int requiredChanges) {
World world = Bukkit.getWorld(plot.world);
Location bottom = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
Location top = PlotHelper.getPlotTopLoc(world, plot.id);
int botx = bottom.getBlockX();
int boty = bottom.getBlockY();
int botz = bottom.getBlockZ();
int topx = top.getBlockX();
int topy = top.getBlockY();
int topz = top.getBlockZ();
HybridPlotWorld hpw = (HybridPlotWorld) PlotMain.getWorldSettings(world);
PlotBlock[] air = new PlotBlock[] {new PlotBlock((short) 0, (byte) 0)};
int changes = checkModified(requiredChanges, world, botx, topx, hpw.PLOT_HEIGHT, hpw.PLOT_HEIGHT, botz, topz, hpw.TOP_BLOCK);
if (changes == -1) {
return true;
}
requiredChanges -= changes;
changes = checkModified(requiredChanges, world, botx, topx, hpw.PLOT_HEIGHT + 1, hpw.PLOT_HEIGHT + 1, botz, topz, air);
if (changes == -1) {
return true;
}
requiredChanges -= changes;
changes = checkModified(requiredChanges, world, botx, topx, hpw.PLOT_HEIGHT + 2, world.getMaxHeight(), botz, topz, air);
if (changes == -1) {
return true;
}
requiredChanges -= changes;
changes = checkModified(requiredChanges, world, botx, topx, 1, hpw.PLOT_HEIGHT, botz, topz, hpw.MAIN_BLOCK);
if (changes == -1) {
return true;
}
return false;
}
public static int checkModified(int threshhold, World world, int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock[] blocks) {
int count = 0;
for (int y = y1; y <= y2; y++) {
for (int x = x1; x <= x2; x++) {
for (int z = z1; z <= z2; z++) {
Block block = world.getBlockAt(x, y, z);
int id = block.getTypeId();
boolean same = false;
for (PlotBlock p : blocks) {
if (id == p.id) {
same = true;
break;
}
}
if (!same) {
count++;
if (count > threshhold) {
return -1;
}
}
}
}
}
return count;
}
/**
* Fetches the plot from the main class