Always use item in Main hand for Cauldron

Fixes #130
This commit is contained in:
Sn0wStorm 2016-06-17 22:09:04 +02:00
parent 98394b14b4
commit b3a5013a7f
3 changed files with 34 additions and 6 deletions

View File

@ -642,6 +642,15 @@ public class P extends JavaPlugin {
// Utility
@SuppressWarnings("deprecation")
public void setHand(Player player, ItemStack item) {
if (P.use1_9) {
player.getInventory().setItemInMainHand(item);
} else {
player.setItemInHand(item);
}
}
public int parseInt(String string) {
return NumberUtils.toInt(string, 0);
}

View File

@ -353,6 +353,7 @@ public class CommandListener implements CommandExecutor {
}
@SuppressWarnings("deprecation")
public void cmdCopy(CommandSender sender, int count) {
if (sender instanceof Player) {
@ -389,6 +390,7 @@ public class CommandListener implements CommandExecutor {
}
@SuppressWarnings("deprecation")
public void cmdDelete(CommandSender sender) {
if (sender instanceof Player) {
@ -413,6 +415,7 @@ public class CommandListener implements CommandExecutor {
}
@SuppressWarnings("deprecation")
public void cmdPersist(CommandSender sender) {
if (sender instanceof Player) {
@ -441,6 +444,7 @@ public class CommandListener implements CommandExecutor {
}
@SuppressWarnings("deprecation")
public void cmdStatic(CommandSender sender) {
if (sender instanceof Player) {
@ -471,6 +475,7 @@ public class CommandListener implements CommandExecutor {
}
@SuppressWarnings("deprecation")
public void cmdUnlabel(CommandSender sender) {
if (sender instanceof Player) {

View File

@ -38,10 +38,24 @@ public class PlayerListener implements Listener {
// Interacting with a Cauldron
if (type == Material.CAULDRON) {
Material materialInHand = event.getMaterial();
ItemStack item = event.getItem();
Material materialInHand;
ItemStack item;
if (P.use1_9) {
item = player.getInventory().getItemInMainHand();
if (item != null) {
materialInHand = item.getType();
} else {
materialInHand = null;
}
} else {
materialInHand = event.getMaterial();
item = event.getItem();
}
if (materialInHand == Material.WATCH) {
if (item == null || materialInHand == null) {
return;
} else if (materialInHand == Material.WATCH) {
BCauldron.printTime(player, clickedBlock);
return;
@ -54,7 +68,7 @@ public class PlayerListener implements Listener {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
} else {
player.setItemInHand(new ItemStack(Material.AIR));
P.p.setHand(player, new ItemStack(Material.AIR));
}
}
}
@ -101,9 +115,9 @@ public class PlayerListener implements Listener {
}
} else {
if (isBucket) {
player.setItemInHand(new ItemStack(Material.BUCKET));
P.p.setHand(player, new ItemStack(Material.BUCKET));
} else {
player.setItemInHand(new ItemStack(Material.AIR));
P.p.setHand(player, new ItemStack(Material.AIR));
}
}
}