built against CB 1000

Signed-off-by: locutus <bladedpenguin@gmail.com>
This commit is contained in:
locutus
2011-07-22 23:00:34 -04:00
commit c1a601ff32
120 changed files with 13969 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package org.mcteam.ancientgates.util;
import java.io.*;
/**
* Harddisc related methods such as read and write.
*/
public class DiscUtil {
/**
* Convenience function for writing a string to a file.
*/
public static void write(File file, String content) throws IOException {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF8"));
out.write(content);
out.close();
}
/**
* Convenience function for reading a file as a string.
*/
public static String read(File file) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String ret = new String(new byte[0], "UTF-8");
String line;
while ((line = in.readLine()) != null) {
ret += line;
}
return ret;
}
}

View File

@ -0,0 +1,79 @@
package org.mcteam.ancientgates.util;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.mcteam.ancientgates.Conf;
public class FloodUtil {
private static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
private static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
static {
exp1.add(BlockFace.UP);
exp1.add(BlockFace.DOWN);
exp1.add(BlockFace.EAST);
exp1.add(BlockFace.WEST);
exp2.add(BlockFace.UP);
exp2.add(BlockFace.DOWN);
exp2.add(BlockFace.NORTH);
exp2.add(BlockFace.SOUTH);
}
// For the same frame and location this set of blocks is deterministic
public static Set<Block> getGateFrameBlocks(Block block) {
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, Conf.getGateMaxArea());
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, Conf.getGateMaxArea());
if (blocks1 == null && blocks2 == null) {
return null;
}
if (blocks1 == null) {
return blocks2;
}
if (blocks2 == null) {
return blocks1;
}
if (blocks1.size() > blocks2.size()) {
return blocks2;
}
return blocks1;
}
public static Set<Block> getAirFloodBlocks(Block startBlock, Set<Block> foundBlocks, Set<BlockFace> expandFaces, int limit) {
if (foundBlocks == null) {
return null;
}
if (foundBlocks.size() > limit) {
return null;
}
if (foundBlocks.contains(startBlock)) {
return foundBlocks;
}
if (startBlock.getType() == Material.AIR || startBlock.getType() == Material.PORTAL) {
// ... We found a block :D ...
foundBlocks.add(startBlock);
// ... And flood away !
for (BlockFace face : expandFaces) {
Block potentialBlock = startBlock.getFace(face);
foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit);
}
}
return foundBlocks;
}
}

View File

@ -0,0 +1,15 @@
package org.mcteam.ancientgates.util;
import org.bukkit.Location;
public class GeometryUtil {
// How long between two locations?
public static double distanceBetweenLocations(Location location1, Location location2) {
double X = location1.getX() - location2.getX();
double Y = location1.getY() - location2.getY();
double Z = location1.getZ() - location2.getZ();
return Math.sqrt(X*X+Y*Y+Z*Z);
}
}

View File

@ -0,0 +1,48 @@
package org.mcteam.ancientgates.util;
import java.util.*;
import org.bukkit.Material;
import org.mcteam.ancientgates.Conf;
public class TextUtil {
public static String titleize(String str) {
String line = Conf.colorChrome+repeat("_", 60);
String center = ".[ " + Conf.colorSystem + str + Conf.colorChrome + " ].";
int pivot = line.length() / 2;
int eatLeft = center.length() / 2;
int eatRight = center.length() - eatLeft;
return line.substring(0, pivot - eatLeft) + center + line.substring(pivot + eatRight);
}
public static String repeat(String s, int times) {
if (times <= 0) return "";
else return s + repeat(s, times-1);
}
public static ArrayList<String> split(String str) {
return new ArrayList<String>(Arrays.asList(str.trim().split("\\s+")));
}
public static String implode(List<String> list, String glue) {
String ret = "";
for (int i=0; i<list.size(); i++) {
if (i!=0) {
ret += glue;
}
ret += list.get(i);
}
return ret;
}
public static String implode(List<String> list) {
return implode(list, " ");
}
public static String getMaterialName(Material material) {
String ret = material.toString();
ret = ret.replace('_', ' ');
ret = ret.toLowerCase();
return ret.substring(0, 1).toUpperCase()+ret.substring(1);
}
}