Mention what nbt file is broken. Fixes #124.

This commit is contained in:
Olof Larsson 2014-05-23 09:17:32 +02:00
parent ed980f2dbe
commit 25cb50924c
3 changed files with 112 additions and 1 deletions

View File

@ -958,7 +958,8 @@ public class IdUtil implements Listener, Runnable
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); String message = Txt.parse("<b>NBT file couldn't be loaded: <h>%s<b>. Error: %s.", file.toString(), e.getMessage());
MCore.get().log(message);
return null; return null;
} }
} }

View File

@ -24,6 +24,7 @@ import java.util.TreeSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -142,6 +143,46 @@ public class MUtil
return recurseResolveMap(output, map); return recurseResolveMap(output, map);
} }
// -------------------------------------------- //
// GET BLOCKS
// -------------------------------------------- //
public static List<Block> getBlocks(Location location, int halfWidth)
{
return getBlocks(location.getBlock(), halfWidth);
}
public static List<Block> getBlocks(Block block, int halfWidth)
{
int xmin = block.getX() - halfWidth;
int ymin = block.getY() - halfWidth;
int zmin = block.getZ() - halfWidth;
int xmax = block.getX() + halfWidth;
int ymax = block.getY() + halfWidth;
int zmax = block.getZ() + halfWidth;
return getBlocks(block.getWorld(), xmin, ymin, zmin, xmax, ymax, zmax);
}
public static List<Block> getBlocks(World world, int xmin, int ymin, int zmin, int xmax, int ymax, int zmax)
{
List<Block> blocks = new ArrayList<Block>();
for (int x = xmin; x <= xmax; x++)
{
for (int y = ymin; y <= ymax; y++)
{
for (int z = zmin; z <= zmax; z++)
{
blocks.add(world.getBlockAt(x, y, z));
}
}
}
return blocks;
}
// -------------------------------------------- // // -------------------------------------------- //
// LOCATIONS COMPARISON // LOCATIONS COMPARISON
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -0,0 +1,69 @@
package com.massivecraft.mcore.util;
import java.util.HashMap;
import java.util.Map;
public class PeriodUtil
{
// -------------------------------------------- //
// MILLIS STORE
// -------------------------------------------- //
private static Map<Object, Long> objectToMillis = new HashMap<Object, Long>();
public static long getMillis(Object object)
{
Long ret = objectToMillis.get(object);
if (ret == null) ret = 0L;
return ret;
}
public static void setMillis(Object object, Long millis)
{
if (millis == null || millis == 0)
{
objectToMillis.remove(object);
}
else
{
objectToMillis.put(object, millis);
}
}
// -------------------------------------------- //
// RANDOM SIMPLE
// -------------------------------------------- //
public static long getPeriod(long length, long now)
{
return now / length;
}
public static long getPeriod(long length)
{
return getPeriod(length, System.currentTimeMillis());
}
public static long getLastPeriod(Object object, long length)
{
return getPeriod(length, getMillis(object));
}
public static boolean isNewPeriod(Object object, long length, long now)
{
long currentPeriod = getPeriod(length, now);
long lastPeriod = getLastPeriod(object, length);
if (currentPeriod == lastPeriod) return false;
setMillis(object, now);
return true;
}
public static boolean isNewPeriod(Object object, long length)
{
return isNewPeriod(object, length, System.currentTimeMillis());
}
}