add NullPointerException check and use new spigot api

Former-commit-id: bd80156980ddf2c7a1facd4a275dbc8ec984ec54
This commit is contained in:
Ghost_chu committed 2018-10-01 14:35:40 +08:00
1 parent 3b71363cf8
commit fb05c25038
4 files changed
+83 -27

No files matched your search

@@ -284,25 +284,31 @@ public class QS implements CommandExecutor {
private void create(CommandSender sender, String[] args) {
if (sender instanceof Player) {
Player p = (Player) sender;
ItemStack item = p.getItemInHand();
if (item.getType()!=Material.AIR) {
ItemStack item = p.getInventory().getItemInMainHand();
if (item.getType() != Material.AIR) {
if (sender.hasPermission("quickshop.create.sell")) {
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
if (Util.canBeShop(b)) {
PlayerInteractEvent e = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, b, BlockFace.UP);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
return;
if (p != null && b != null && p.isOnline()) {
PlayerInteractEvent e = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, b,
BlockFace.UP);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
return;
}
BlockBreakEvent be = new BlockBreakEvent(b, p);
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
return;
}
}
BlockBreakEvent be = new BlockBreakEvent(b,p);
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
return;
}
if (!plugin.getShopManager().canBuildShop(p, b, Util.getYawFace(p.getLocation().getYaw()))) {
if (!plugin.getShopManager().canBuildShop(p, b,
Util.getYawFace(p.getLocation().getYaw()))) {
// As of the new checking system, most plugins will tell the
// player why they can't create a shop there.
// So telling them a message would cause spam etc.
@@ -313,16 +319,19 @@ public class QS implements CommandExecutor {
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
return;
}
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getType().name())) {
if (Util.isBlacklisted(item.getType())
&& !p.hasPermission("quickshop.bypass." + item.getType().name())) {
p.sendMessage(MsgUtil.getMessage("blacklisted-item"));
return;
}
if (args.length<2) {
if (args.length < 2) {
// Send creation menu.
Info info = new Info(b.getLocation(), ShopAction.CREATE, p.getItemInHand(), b.getRelative(Util.getYawFace(p.getLocation().getYaw())));
Info info = new Info(b.getLocation(), ShopAction.CREATE, p.getItemInHand(),
b.getRelative(Util.getYawFace(p.getLocation().getYaw())));
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
p.sendMessage(MsgUtil.getMessage("how-much-to-trade-for", Util.getName(info.getItem())));
p.sendMessage(
MsgUtil.getMessage("how-much-to-trade-for", Util.getName(info.getItem())));
} else {
plugin.getShopManager().handleChat(p, args[1]);
}
@@ -155,8 +155,52 @@ public class QuickShop extends JavaPlugin {
getLogger().info("Couldn't find a Vault permission provider. Some feature may be limited.");
}
int CurrentConfigVersion = 1;
if (getConfig().getInt("config-version") != CurrentConfigVersion) {
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning(
"WARNING! You not have lastet version config.yml, Please follow SpigotMC updatelog to update your config.yml!");
getLogger().warning("WARNING! Server will continue boot in 5 seconds...");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Metrics
if (getConfig().getBoolean("metrics")) {
if (!getConfig().getBoolean("disabled-metrics")) {
PluginDescriptionFile pdf = Bukkit.getServer().getPluginManager().getPlugin("QuickShop").getDescription();
String qsVer = pdf.getVersion();
Metrics metrics = new Metrics(this);
@@ -389,7 +433,7 @@ public class QuickShop extends JavaPlugin {
getLogger().severe("#Shop data >>");
getLogger().severe("Location: " + worldName + ";(X:" + x + ", Y:" + y + ", Z:" + z + ")");
getLogger().severe(
"Item: " + item.getType().name() + "MetaData: " + item.getItemMeta().spigot().toString());
"Item: " + item.getType().name() + " MetaData: " + item.getItemMeta().spigot().toString());
getLogger().severe("Owner: " + owner + "(" + ownerUUID.toString() + ")");
try {
getLogger().severe(
@@ -408,9 +452,9 @@ public class QuickShop extends JavaPlugin {
getLogger().severe("#Database info >>");
getLogger().severe("Connected:" + !getDB().getConnection().isClosed());
getLogger().severe("Read Only:" + !getDB().getConnection().isReadOnly());
getLogger().severe("Read Only:" + getDB().getConnection().isReadOnly());
getLogger().severe("Client Info:" + getDB().getConnection().getClientInfo().toString());
getLogger().severe("Read Only:" + !getDB().getConnection().isReadOnly());
getLogger().severe("Read Only:" + getDB().getConnection().isReadOnly());
getLogger().severe("#Debuging >>");
getLogger().severe("Runnnig on step: " + step);
@@ -420,13 +464,13 @@ public class QuickShop extends JavaPlugin {
if (!isBackuped) {
File sqlfile = new File(Bukkit.getPluginManager().getPlugin("QuickShop").getDataFolder()
.getAbsolutePath().toString() + "\\shop.db");
.getAbsolutePath().toString() + "/shop.db");
if (!sqlfile.exists()) {
getLogger().severe("Failed to backup! (File not found)");
}
String uuid = UUID.randomUUID().toString().replaceAll("_", "");
File bksqlfile = new File(Bukkit.getPluginManager().getPlugin("QuickShop").getDataFolder()
.getAbsolutePath().toString() + "\\shop_backup_" + uuid + ".db");
.getAbsolutePath().toString() + "/shop_backup_" + uuid + ".db");
try {
bksqlfile.createNewFile();
} catch (IOException e1) {
@@ -448,8 +492,8 @@ public class QuickShop extends JavaPlugin {
inputChannel.close();
outputChannel.close();
} catch (IOException e1) {
inputChannel=null;
outputChannel=null;
inputChannel = null;
outputChannel = null;
}
}