mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Update several commands with cross-version enum lookups
This commit is contained in:
parent
5a14a64b6c
commit
0114b5e4f6
5 changed files with 28 additions and 13 deletions
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
|||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
|
@ -15,6 +16,9 @@ import static com.earth2me.essentials.I18n.tl;
|
|||
|
||||
|
||||
public class Commandbook extends EssentialsCommand {
|
||||
|
||||
private static final Material WRITABLE_BOOK = EnumUtil.getMaterial("WRITABLE_BOOK", "BOOK_AND_QUILL");
|
||||
|
||||
public Commandbook() {
|
||||
super("book");
|
||||
}
|
||||
|
@ -44,7 +48,7 @@ public class Commandbook extends EssentialsCommand {
|
|||
}
|
||||
} else {
|
||||
if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) {
|
||||
ItemStack newItem = new ItemStack(Material.WRITABLE_BOOK, item.getAmount());
|
||||
ItemStack newItem = new ItemStack(WRITABLE_BOOK, item.getAmount());
|
||||
newItem.setItemMeta(bmeta);
|
||||
InventoryWorkaround.setItemInMainHand(user.getBase(), newItem);
|
||||
user.sendMessage(tl("editBookContents"));
|
||||
|
@ -52,7 +56,7 @@ public class Commandbook extends EssentialsCommand {
|
|||
throw new Exception(tl("denyBookEdit"));
|
||||
}
|
||||
}
|
||||
} else if (item.getType() == Material.WRITABLE_BOOK) {
|
||||
} else if (item.getType() == WRITABLE_BOOK) {
|
||||
BookMeta bmeta = (BookMeta) item.getItemMeta();
|
||||
if (!user.isAuthorized("essentials.book.author")) {
|
||||
bmeta.setAuthor(player);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
|||
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.DyeColor;
|
||||
|
@ -44,7 +45,7 @@ public class Commandfirework extends EssentialsCommand {
|
|||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ItemStack stack = user.getBase().getInventory().getItemInMainHand();
|
||||
if (stack.getType() == Material.FIREWORK_ROCKET || stack.getType() == Material.FIREWORK_STAR) {
|
||||
if (MaterialUtil.isFirework(stack.getType())) {
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("clear")) {
|
||||
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
|||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import org.bukkit.Material;
|
||||
|
@ -20,6 +21,11 @@ import net.ess3.nms.refl.ReflUtil;
|
|||
|
||||
|
||||
public class Commandrecipe extends EssentialsCommand {
|
||||
|
||||
private static final Material FIREWORK_ROCKET = EnumUtil.getMaterial("FIREWORK_ROCKET", "FIREWORK");
|
||||
private static final Material FIREWORK_STAR = EnumUtil.getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE");
|
||||
private static final Material GUNPOWDER = EnumUtil.getMaterial("GUNPOWDER", "SULPHUR");
|
||||
|
||||
public Commandrecipe() {
|
||||
super("recipe");
|
||||
}
|
||||
|
@ -67,11 +73,11 @@ public class Commandrecipe extends EssentialsCommand {
|
|||
} else if (selectedRecipe instanceof ShapedRecipe) {
|
||||
shapedRecipe(sender, (ShapedRecipe) selectedRecipe, sender.isPlayer());
|
||||
} else if (selectedRecipe instanceof ShapelessRecipe) {
|
||||
if (recipesOfType.size() == 1 && (itemType.getType() == Material.FIREWORK_ROCKET || itemType.getType() == Material.FIREWORK_STAR)) {
|
||||
if (recipesOfType.size() == 1 && (itemType.getType() == FIREWORK_ROCKET)) {
|
||||
ShapelessRecipe shapelessRecipe = new ShapelessRecipe(itemType);
|
||||
shapelessRecipe.addIngredient(Material.LEGACY_SULPHUR);
|
||||
shapelessRecipe.addIngredient(GUNPOWDER);
|
||||
shapelessRecipe.addIngredient(Material.PAPER);
|
||||
shapelessRecipe.addIngredient(Material.FIREWORK_ROCKET);
|
||||
shapelessRecipe.addIngredient(FIREWORK_STAR);
|
||||
shapelessRecipe(sender, shapelessRecipe, sender.isPlayer());
|
||||
} else {
|
||||
shapelessRecipe(sender, (ShapelessRecipe) selectedRecipe, sender.isPlayer());
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.earth2me.essentials.commands;
|
|||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
|
@ -14,6 +16,9 @@ import java.util.List;
|
|||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandskull extends EssentialsCommand {
|
||||
|
||||
private static final Material SKULL_ITEM = EnumUtil.getMaterial("PLAYER_HEAD", "SKULL_ITEM");
|
||||
|
||||
public Commandskull() {
|
||||
super("skull");
|
||||
}
|
||||
|
@ -35,10 +40,10 @@ public class Commandskull extends EssentialsCommand {
|
|||
SkullMeta metaSkull = null;
|
||||
boolean spawn = false;
|
||||
|
||||
if (itemSkull != null && itemSkull.getType() == Material.LEGACY_SKULL_ITEM && itemSkull.getDurability() == 3) {
|
||||
if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull.getType(), itemSkull.getDurability())) {
|
||||
metaSkull = (SkullMeta) itemSkull.getItemMeta();
|
||||
} else if (user.isAuthorized("essentials.skull.spawn")) {
|
||||
itemSkull = new ItemStack(Material.LEGACY_SKULL_ITEM, 1, (byte) 3);
|
||||
itemSkull = new ItemStack(SKULL_ITEM, 1, (byte) 3);
|
||||
metaSkull = (SkullMeta) itemSkull.getItemMeta();
|
||||
spawn = true;
|
||||
} else {
|
||||
|
|
|
@ -17,13 +17,12 @@ import static com.earth2me.essentials.I18n.tl;
|
|||
|
||||
|
||||
public class Commandwhois extends EssentialsCommand {
|
||||
private final Statistic playOneTick;
|
||||
// For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played = what used to be PLAY_ONE_TICK
|
||||
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579
|
||||
private static final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||
|
||||
public Commandwhois() {
|
||||
super("whois");
|
||||
// For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played
|
||||
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579
|
||||
playOneTick = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,7 +41,7 @@ public class Commandwhois extends EssentialsCommand {
|
|||
sender.sendMessage(tl("whoisHunger", user.getBase().getFoodLevel(), user.getBase().getSaturation()));
|
||||
sender.sendMessage(tl("whoisExp", SetExpFix.getTotalExperience(user.getBase()), user.getBase().getLevel()));
|
||||
sender.sendMessage(tl("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()));
|
||||
long playtimeMs = System.currentTimeMillis() - (user.getBase().getStatistic(playOneTick) * 50);
|
||||
long playtimeMs = System.currentTimeMillis() - (user.getBase().getStatistic(PLAY_ONE_TICK) * 50);
|
||||
sender.sendMessage(tl("whoisPlaytime", DateUtil.formatDateDiff(playtimeMs)));
|
||||
if (!ess.getSettings().isEcoDisabled()) {
|
||||
sender.sendMessage(tl("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess)));
|
||||
|
|
Loading…
Reference in a new issue