forked from LogBlock/LogBlock
Fixed npe, renamed some util methods
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package de.diddiz.LogBlock;
|
package de.diddiz.LogBlock;
|
||||||
|
|
||||||
import static de.diddiz.util.BukkitUtils.compressInventory;
|
import static de.diddiz.util.BukkitUtils.compressInventory;
|
||||||
import static de.diddiz.util.BukkitUtils.getEntityName;
|
import static de.diddiz.util.BukkitUtils.entityName;
|
||||||
import static de.diddiz.util.BukkitUtils.rawData;
|
import static de.diddiz.util.BukkitUtils.rawData;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -176,7 +176,7 @@ public class Consumer extends TimerTask
|
|||||||
weapon = ((Player)killer).getItemInHand().getTypeId();
|
weapon = ((Player)killer).getItemInHand().getTypeId();
|
||||||
lastAttackedEntity.put(killer.getEntityId(), victim.getEntityId());
|
lastAttackedEntity.put(killer.getEntityId(), victim.getEntityId());
|
||||||
lastAttackTime.put(killer.getEntityId(), System.currentTimeMillis());
|
lastAttackTime.put(killer.getEntityId(), System.currentTimeMillis());
|
||||||
queueKill(victim.getWorld(), getEntityName(killer), getEntityName(victim), weapon);
|
queueKill(victim.getWorld(), entityName(killer), entityName(victim), weapon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package de.diddiz.LogBlock;
|
package de.diddiz.LogBlock;
|
||||||
|
|
||||||
import static de.diddiz.util.BukkitUtils.getMaterialName;
|
import static de.diddiz.util.BukkitUtils.materialName;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -34,26 +34,26 @@ public class HistoryFormatter
|
|||||||
final int itemType = rs.getInt("itemtype");
|
final int itemType = rs.getInt("itemtype");
|
||||||
final int itemAmount = rs.getInt("itemamount");
|
final int itemAmount = rs.getInt("itemamount");
|
||||||
if (itemType == 0 || itemAmount == 0)
|
if (itemType == 0 || itemAmount == 0)
|
||||||
msg.append("looked inside " + getMaterialName(type));
|
msg.append("looked inside " + materialName(type));
|
||||||
else if (itemAmount < 0)
|
else if (itemAmount < 0)
|
||||||
msg.append("took " + itemAmount * -1 + "x " + getMaterialName(itemType));
|
msg.append("took " + itemAmount * -1 + "x " + materialName(itemType));
|
||||||
else
|
else
|
||||||
msg.append("put in " + itemAmount + "x " + getMaterialName(itemType));
|
msg.append("put in " + itemAmount + "x " + materialName(itemType));
|
||||||
} else if (type == 69)
|
} else if (type == 69)
|
||||||
msg.append("swiched " + getMaterialName(type));
|
msg.append("swiched " + materialName(type));
|
||||||
else if (type == 77)
|
else if (type == 77)
|
||||||
msg.append("pressed " + getMaterialName(type));
|
msg.append("pressed " + materialName(type));
|
||||||
} else if (type == 0)
|
} else if (type == 0)
|
||||||
msg.append("destroyed " + getMaterialName(replaced));
|
msg.append("destroyed " + materialName(replaced));
|
||||||
else if (replaced == 0)
|
else if (replaced == 0)
|
||||||
msg.append("created " + getMaterialName(type));
|
msg.append("created " + materialName(type));
|
||||||
else
|
else
|
||||||
msg.append("replaced " + getMaterialName(replaced) + " with " + getMaterialName(type));
|
msg.append("replaced " + materialName(replaced) + " with " + materialName(type));
|
||||||
if (coords)
|
if (coords)
|
||||||
msg.append(" at " + rs.getInt("x") + ":" + rs.getInt("y") + ":" + rs.getInt("z"));
|
msg.append(" at " + rs.getInt("x") + ":" + rs.getInt("y") + ":" + rs.getInt("z"));
|
||||||
return msg.toString();
|
return msg.toString();
|
||||||
} else if (sum == SummarizationMode.TYPES)
|
} else if (sum == SummarizationMode.TYPES)
|
||||||
return fillWithSpaces(rs.getInt("created")) + fillWithSpaces(rs.getInt("destroyed")) + getMaterialName(rs.getInt("type"));
|
return fillWithSpaces(rs.getInt("created")) + fillWithSpaces(rs.getInt("destroyed")) + materialName(rs.getInt("type"));
|
||||||
else
|
else
|
||||||
return fillWithSpaces(rs.getInt("created")) + fillWithSpaces(rs.getInt("destroyed")) + rs.getString("playername");
|
return fillWithSpaces(rs.getInt("created")) + fillWithSpaces(rs.getInt("destroyed")) + rs.getString("playername");
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,8 @@ package de.diddiz.LogBlock;
|
|||||||
|
|
||||||
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
|
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
|
||||||
import static de.diddiz.util.BukkitUtils.getBlockEquivalents;
|
import static de.diddiz.util.BukkitUtils.getBlockEquivalents;
|
||||||
import static de.diddiz.util.BukkitUtils.getMaterialName;
|
import static de.diddiz.util.BukkitUtils.materialName;
|
||||||
import static de.diddiz.util.BukkitUtils.getSenderName;
|
import static de.diddiz.util.BukkitUtils.senderName;
|
||||||
import static de.diddiz.util.Utils.isInt;
|
import static de.diddiz.util.Utils.isInt;
|
||||||
import static de.diddiz.util.Utils.parseTimeSpec;
|
import static de.diddiz.util.Utils.parseTimeSpec;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -90,7 +90,7 @@ public class QueryParams implements Cloneable
|
|||||||
final StringBuilder title = new StringBuilder();
|
final StringBuilder title = new StringBuilder();
|
||||||
if (!types.isEmpty()) {
|
if (!types.isEmpty()) {
|
||||||
for (int i = 0; i < types.size(); i++)
|
for (int i = 0; i < types.size(); i++)
|
||||||
title.append(getMaterialName(types.get(i)) + ", ");
|
title.append(materialName(types.get(i)) + ", ");
|
||||||
title.deleteCharAt(title.length() - 2);
|
title.deleteCharAt(title.length() - 2);
|
||||||
} else
|
} else
|
||||||
title.append("Block ");
|
title.append("Block ");
|
||||||
@@ -204,7 +204,7 @@ public class QueryParams implements Cloneable
|
|||||||
if (args == null || args.size() == 0)
|
if (args == null || args.size() == 0)
|
||||||
throw new IllegalArgumentException("No parameters specified.");
|
throw new IllegalArgumentException("No parameters specified.");
|
||||||
final Player player = sender instanceof Player ? (Player)sender : null;
|
final Player player = sender instanceof Player ? (Player)sender : null;
|
||||||
final Session session = prepareToolQuery ? null : logblock.getSession(getSenderName(sender));
|
final Session session = prepareToolQuery ? null : logblock.getSession(senderName(sender));
|
||||||
if (player != null && world == null)
|
if (player != null && world == null)
|
||||||
world = player.getWorld();
|
world = player.getWorld();
|
||||||
for (int i = 0; i < args.size(); i++) {
|
for (int i = 0; i < args.size(); i++) {
|
||||||
|
@@ -110,7 +110,7 @@ public class BukkitUtils
|
|||||||
return blockEquivalents;
|
return blockEquivalents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEntityName(Entity entity) {
|
public static String entityName(Entity entity) {
|
||||||
if (entity instanceof Player)
|
if (entity instanceof Player)
|
||||||
return ((Player)entity).getName();
|
return ((Player)entity).getName();
|
||||||
if (entity instanceof TNTPrimed)
|
if (entity instanceof TNTPrimed)
|
||||||
@@ -118,14 +118,12 @@ public class BukkitUtils
|
|||||||
return entity.getClass().getSimpleName().substring(5);
|
return entity.getClass().getSimpleName().substring(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMaterialName(int type) {
|
public static String materialName(int type) {
|
||||||
final Material mat = Material.getMaterial(type);
|
final Material mat = Material.getMaterial(type);
|
||||||
if (mat != null)
|
return mat != null ? mat.toString().replace('_', ' ').toLowerCase() : String.valueOf(type);
|
||||||
return mat.toString().replace('_', ' ').toLowerCase();
|
|
||||||
return String.valueOf(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSenderName(CommandSender sender) {
|
public static String senderName(CommandSender sender) {
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
return ((Player)sender).getName();
|
return ((Player)sender).getName();
|
||||||
if (sender instanceof ConsoleCommandSender)
|
if (sender instanceof ConsoleCommandSender)
|
||||||
@@ -136,21 +134,21 @@ public class BukkitUtils
|
|||||||
public static void giveTool(Player player, int type) {
|
public static void giveTool(Player player, int type) {
|
||||||
final Inventory inv = player.getInventory();
|
final Inventory inv = player.getInventory();
|
||||||
if (inv.contains(type))
|
if (inv.contains(type))
|
||||||
player.sendMessage(ChatColor.RED + "You have alredy a " + getMaterialName(type));
|
player.sendMessage(ChatColor.RED + "You have alredy a " + materialName(type));
|
||||||
else {
|
else {
|
||||||
final int free = inv.firstEmpty();
|
final int free = inv.firstEmpty();
|
||||||
if (free >= 0) {
|
if (free >= 0) {
|
||||||
if (player.getItemInHand() != null && player.getItemInHand().getTypeId() != 0)
|
if (player.getItemInHand() != null && player.getItemInHand().getTypeId() != 0)
|
||||||
inv.setItem(free, player.getItemInHand());
|
inv.setItem(free, player.getItemInHand());
|
||||||
player.setItemInHand(new ItemStack(type, 1));
|
player.setItemInHand(new ItemStack(type, 1));
|
||||||
player.sendMessage(ChatColor.GREEN + "Here's your " + getMaterialName(type));
|
player.sendMessage(ChatColor.GREEN + "Here's your " + materialName(type));
|
||||||
} else
|
} else
|
||||||
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
|
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte rawData(ItemStack item) {
|
public static byte rawData(ItemStack item) {
|
||||||
return item.getData() != null ? item.getData().getData() : 0;
|
return item.getType() != null ? (item.getData() != null ? item.getData().getData() : 0) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int saveSpawnHeight(Location loc) {
|
public static int saveSpawnHeight(Location loc) {
|
||||||
|
Reference in New Issue
Block a user