Adjustments to fastbreak + debug output.

This commit is contained in:
asofold 2012-09-16 23:40:19 +02:00
parent a478cc529a
commit 3348400268
3 changed files with 44 additions and 9 deletions

View File

@ -220,6 +220,7 @@ public class BlockBreakListener implements Listener {
return;
// Skip if already set to the same block without breaking.
// TODO: should probably always set or depending on configuration.
if (data.fastBreakBreakTime < data.fastBreakfirstDamage && data.clickedX == block.getX() && data.clickedZ == block.getZ() && data.clickedY == block.getY())
return;

View File

@ -37,14 +37,14 @@ public class FastBreak extends Check {
* the player
* @param block
* the block
* @param isInstaBreak
* @param data
* @param cc
* @param elaspedTime
* @return true, if successful
*/
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data) {
public boolean check(final Player player, final Block block, final boolean isInstaBreak, final BlockBreakConfig cc, final BlockBreakData data) {
final long now = System.currentTimeMillis();
boolean cancel = false;
// First, check the game mode of the player and choose the right limit.
@ -56,9 +56,12 @@ public class FastBreak extends Check {
breakingTime = Math.round((double) cc.fastBreakModSurvival / 100D * (double) BlockProperties.getBreakingDuration(block.getTypeId(), player));
// fastBreakfirstDamage is the first interact on block (!).
final long elapsedTime = (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage;
// Check if the time used time is lower than expected.
if (elapsedTime + cc.fastBreakDelay < breakingTime){
if (isInstaBreak){
// Ignore those for now.
}
else if (elapsedTime + cc.fastBreakDelay < breakingTime){
// lag or cheat or Minecraft.
final long missingTime = breakingTime - elapsedTime;
@ -79,11 +82,19 @@ public class FastBreak extends Check {
data.fastBreakVL *= 0.9D;
}
if (cc.fastBreakDebug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG) && data.stats != null){
data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+"u", true), elapsedTime);
data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+ "r", true), breakingTime);
player.sendMessage(data.stats.getStatsStr(true));
}
if (cc.fastBreakDebug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){
// General stats:
if (data.stats != null){
data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+"u", true), elapsedTime);
data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+ "r", true), breakingTime);
player.sendMessage(data.stats.getStatsStr(true));
}
// Send info about current break:
final int blockId = block.getTypeId();
final boolean isValidTool = BlockProperties.isValidTool(blockId, player.getItemInHand());
String msg = (isInstaBreak ? "[Insta]" : "[Normal]") + "[" + blockId + "] "+ elapsedTime + "u / " + breakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")";
player.sendMessage(msg);
}
// (The break time is set in the listener).

View File

@ -453,6 +453,11 @@ public class BlockProperties {
return new long[]{v, v, v, v, v, v};
}
public static ToolProps getToolProps(final ItemStack stack){
if (stack == null) return noTool;
else return getToolProps(stack.getTypeId());
}
public static ToolProps getToolProps(final Material mat){
if (mat == null) return noTool;
else return getToolProps(mat.getId());
@ -464,6 +469,16 @@ public class BlockProperties {
else return props;
}
public static BlockProps getBlockProps(final ItemStack stack){
if (stack == null) return defaultBlockProps;
else return getBlockProps(stack.getTypeId());
}
public static BlockProps getBlockProps(final Material mat){
if (mat == null) return defaultBlockProps;
else return getBlockProps(mat.getId());
}
public static BlockProps getBlockProps(final int blockId){
if (blockId <0 || blockId >= blocks.length || blocks[blockId] == null) return defaultBlockProps;
else return blocks[blockId];
@ -665,4 +680,12 @@ public class BlockProperties {
if (blockId < 0 || blockId >= blocks.length) throw new IllegalArgumentException("The blockId is outside of supported range: " + blockId);
blocks[blockId] = blockProps;
}
public static boolean isValidTool(final int blockId, final ItemStack itemInHand) {
final BlockProps blockProps = getBlockProps(blockId);
final ToolProps toolProps = getToolProps(itemInHand);
final int efficiency = itemInHand == null ? 0 : itemInHand.getEnchantmentLevel(Enchantment.DIG_SPEED);
return isValidTool(blockId, blockProps, toolProps, efficiency);
}
}