Skip to content

Adds support for armor trims and custom patterns for date and time keywords. #6155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ public interface ISettings extends IConf {

boolean isUpdateCheckEnabled();

String getDateFormat();

String getTimeFormat();

boolean showZeroBaltop();

String getNickRegex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.bukkit.block.Banner;
import org.bukkit.block.banner.PatternType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.Registry;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
Expand All @@ -32,6 +34,10 @@
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

Expand Down Expand Up @@ -343,6 +349,15 @@ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe,
} else {
throw new TranslatableException("leatherSyntax");
}
} else if (MaterialUtil.isArmor(stack.getType()) && split.length > 1 && split[0].equalsIgnoreCase("trim")) {
final ArmorMeta armorMeta = (ArmorMeta) stack.getItemMeta();
final String[] trimData = split[1].split("\\|");
final TrimPattern pattern = Registry.TRIM_PATTERN.getOrThrow(NamespacedKey.minecraft(trimData[0].toLowerCase()));
final TrimMaterial material = Registry.TRIM_MATERIAL.getOrThrow(NamespacedKey.minecraft(trimData[1].toLowerCase()));

armorMeta.setTrim(new ArmorTrim(material, pattern));

stack.setItemMeta(armorMeta);
} else {
parseEnchantmentStrings(sender, allowUnsafe, split, ess);
}
Expand Down
10 changes: 10 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,16 @@ public boolean isUpdateCheckEnabled() {
return config.getBoolean("update-check", true);
}

@Override
public String getDateFormat() {
return config.getString("date-format", "locale");
}

@Override
public String getTimeFormat() {
return config.getString("time-format", "locale");
}

@Override
public boolean showZeroBaltop() {
return config.getBoolean("show-zero-baltop", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;

Expand Down Expand Up @@ -337,10 +339,21 @@ public String serialize(final ItemStack is, final boolean useResolvers) {
}
}
}
} else if (MaterialUtil.isLeatherArmor(material)) {
final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) is.getItemMeta();
final int rgb = leatherArmorMeta.getColor().asRGB();
sb.append("color:").append(rgb).append(" ");
} else if (MaterialUtil.isArmor(material)) {
final ArmorTrim armorTrim = ((ArmorMeta) is.getItemMeta()).getTrim();

if (armorTrim != null) {
final String trimPattern = armorTrim.getPattern().getKey().getKey();
final String trimMaterial = armorTrim.getMaterial().getKey().getKey();

sb.append("trim:").append(trimPattern).append("|").append(trimMaterial).append(" ");
}

if (MaterialUtil.isLeatherArmor(material)) {
final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) is.getItemMeta();
final int rgb = leatherArmorMeta.getColor().asRGB();
sb.append("color:").append(rgb).append(" ");
}
}

return sb.toString().trim().replaceAll("§", "&");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.earth2me.essentials.ExecuteTimer;
import com.earth2me.essentials.PlayerList;
import com.earth2me.essentials.User;
import com.earth2me.essentials.ISettings;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.DescParseTickFormat;
Expand All @@ -20,13 +21,15 @@
import java.lang.management.ManagementFactory;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -96,6 +99,8 @@ public class KeywordReplacer implements IText {
private final transient IText input;
private final transient List<String> replaced;
private final transient IEssentials ess;

private final transient ISettings settings;
private final transient boolean includePrivate;
private final transient boolean replaceSpacesWithUnderscores;
private final EnumMap<KeywordType, Object> keywordCache = new EnumMap<>(KeywordType.class);
Expand All @@ -104,6 +109,7 @@ public KeywordReplacer(final IText input, final CommandSource sender, final IEss
this.input = input;
this.replaced = new ArrayList<>(this.input.getLines().size());
this.ess = ess;
this.settings = ess.getSettings();
this.includePrivate = true;
this.replaceSpacesWithUnderscores = false;
replaceKeywords(sender);
Expand All @@ -113,6 +119,7 @@ public KeywordReplacer(final IText input, final CommandSource sender, final IEss
this.input = input;
this.replaced = new ArrayList<>(this.input.getLines().size());
this.ess = ess;
this.settings = ess.getSettings();
this.includePrivate = showPrivate;
this.replaceSpacesWithUnderscores = false;
replaceKeywords(sender);
Expand All @@ -123,6 +130,7 @@ public KeywordReplacer(final IText input, final CommandSource sender, final IEss
this.input = input;
this.replaced = new ArrayList<>(this.input.getLines().size());
this.ess = ess;
this.settings = ess.getSettings();
this.includePrivate = showPrivate;
this.replaceSpacesWithUnderscores = replaceSpacesWithUnderscores;
replaceKeywords(sender);
Expand Down Expand Up @@ -320,10 +328,20 @@ private String replaceLine(String line, final String fullMatch, final String[] m
keywordCache.put(validKeyword, outputList);
break;
case TIME:
replacer = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
final String timeFormat = settings.getTimeFormat();

if (!Objects.equals(timeFormat, "locale"))
replacer = new SimpleDateFormat(timeFormat).format(new Date());
else
replacer = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
break;
case DATE:
replacer = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
final String dateFormat = settings.getDateFormat();

if (!Objects.equals(dateFormat, "locale"))
replacer = new SimpleDateFormat(dateFormat).format(new Date());
else
replacer = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
break;
case WORLDTIME12:
if (user != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public static boolean isBoots(final Material material) {
return BOOTS.contains(material);
}

public static boolean isArmor(final Material material) {
return isHelmet(material) || isChestplate(material) || isLeggings(material) || isBoots(material);
}

public static boolean isBed(final Material material) {
return BEDS.contains(material);
}
Expand Down
18 changes: 18 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,24 @@ max-itemlore-lines: 10
# This uses the public GitHub API and no identifying information is sent or stored.
update-check: true

############################################################
# +------------------------------------------------------+ #
# | Keywords | #
# +------------------------------------------------------+ #
############################################################

# Format for the {DATE} keyword.
# Set `locale` to display dates according to the regional standards of the host location.
# For custom patterns, follow the Java SimpleDateFormat syntax conventions. https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
# Custom pattern example: dd/MM/yyyy
date-format: locale

# Format for the {TIME} keyword.
# Set `locale` to display time according to the regional standards of the host location.
# For custom patterns, follow the Java SimpleDateFormat syntax conventions. https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
# Custom pattern example: HH:mm:ss
time-format: locale

############################################################
# +------------------------------------------------------+ #
# | Homes | #
Expand Down