mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-06-29 02:30:01 +00:00
Use 1.8-friendly User#getItemInHand method in commands
This commit is contained in:
parent
aa6ad271a0
commit
e94202c55a
8 changed files with 9 additions and 8 deletions
|
@ -879,7 +879,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||||
* Returns the {@link ItemStack} in the main hand or off-hand. If the main hand is empty then the offhand item is returned - also nullable.
|
* Returns the {@link ItemStack} in the main hand or off-hand. If the main hand is empty then the offhand item is returned - also nullable.
|
||||||
*/
|
*/
|
||||||
public ItemStack getItemInHand() {
|
public ItemStack getItemInHand() {
|
||||||
if (ReflUtil.getNmsVersionObject().isLowerThan(ReflUtil.V1_9_R1)) {
|
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||||
return getBase().getInventory().getItemInHand();
|
return getBase().getInventory().getItemInHand();
|
||||||
} else {
|
} else {
|
||||||
PlayerInventory inventory = getBase().getInventory();
|
PlayerInventory inventory = getBase().getInventory();
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class Commandfirework extends EssentialsCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||||
final ItemStack stack = user.getBase().getInventory().getItemInMainHand();
|
final ItemStack stack = user.getItemInHand();
|
||||||
if (MaterialUtil.isFirework(stack.getType())) {
|
if (MaterialUtil.isFirework(stack.getType())) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("clear")) {
|
if (args[0].equalsIgnoreCase("clear")) {
|
||||||
|
|
|
@ -33,8 +33,8 @@ public class Commandhat extends EssentialsCommand {
|
||||||
user.sendMessage(tl("hatRemoved"));
|
user.sendMessage(tl("hatRemoved"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (user.getBase().getInventory().getItemInMainHand().getType() != Material.AIR) {
|
final ItemStack hand = user.getItemInHand();
|
||||||
final ItemStack hand = user.getBase().getInventory().getItemInMainHand();
|
if (hand != null && hand.getType() != Material.AIR) {
|
||||||
if (hand.getType().getMaxDurability() == 0) {
|
if (hand.getType().getMaxDurability() == 0) {
|
||||||
final PlayerInventory inv = user.getBase().getInventory();
|
final PlayerInventory inv = user.getBase().getInventory();
|
||||||
final ItemStack head = inv.getHelmet();
|
final ItemStack head = inv.getHelmet();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class Commanditemdb extends EssentialsCommand {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
if (sender.isPlayer() && sender.getPlayer() != null) {
|
if (sender.isPlayer() && sender.getPlayer() != null) {
|
||||||
itemHeld = true;
|
itemHeld = true;
|
||||||
itemStack = sender.getPlayer().getInventory().getItemInMainHand();
|
itemStack = ess.getUser(sender.getPlayer()).getItemInHand();
|
||||||
}
|
}
|
||||||
if (itemStack == null) {
|
if (itemStack == null) {
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class Commandmore extends EssentialsCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||||
final ItemStack stack = user.getBase().getInventory().getItemInMainHand();
|
final ItemStack stack = user.getItemInHand();
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
throw new Exception(tl("cantSpawnItem", "Air"));
|
throw new Exception(tl("cantSpawnItem", "Air"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class Commandrepair extends EssentialsCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repairHand(User user) throws Exception {
|
public void repairHand(User user) throws Exception {
|
||||||
final ItemStack item = user.getBase().getInventory().getItemInMainHand();
|
final ItemStack item = user.getItemInHand();
|
||||||
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
|
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
|
||||||
throw new Exception(tl("repairInvalidType"));
|
throw new Exception(tl("repairInvalidType"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class Commandskull extends EssentialsCommand {
|
||||||
owner = user.getName();
|
owner = user.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack itemSkull = user.getBase().getInventory().getItemInMainHand();
|
ItemStack itemSkull = user.getItemInHand();
|
||||||
SkullMeta metaSkull = null;
|
SkullMeta metaSkull = null;
|
||||||
boolean spawn = false;
|
boolean spawn = false;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.regex.Pattern;
|
||||||
public class VersionUtil {
|
public class VersionUtil {
|
||||||
|
|
||||||
public static final BukkitVersion v1_8_8_R01 = BukkitVersion.fromString("1.8.8-R0.1-SNAPSHOT");
|
public static final BukkitVersion v1_8_8_R01 = BukkitVersion.fromString("1.8.8-R0.1-SNAPSHOT");
|
||||||
|
public static final BukkitVersion v1_9_R01 = BukkitVersion.fromString("1.9-R0.1-SNAPSHOT");
|
||||||
public static final BukkitVersion v1_9_4_R01 = BukkitVersion.fromString("1.9.4-R0.1-SNAPSHOT");
|
public static final BukkitVersion v1_9_4_R01 = BukkitVersion.fromString("1.9.4-R0.1-SNAPSHOT");
|
||||||
public static final BukkitVersion v1_10_2_R01 = BukkitVersion.fromString("1.10.2-R0.1-SNAPSHOT");
|
public static final BukkitVersion v1_10_2_R01 = BukkitVersion.fromString("1.10.2-R0.1-SNAPSHOT");
|
||||||
public static final BukkitVersion v1_11_2_R01 = BukkitVersion.fromString("1.11.2-R0.1-SNAPSHOT");
|
public static final BukkitVersion v1_11_2_R01 = BukkitVersion.fromString("1.11.2-R0.1-SNAPSHOT");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue