1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 19:55:48 +00:00

Merge branch 'master' of https://github.com/Slimefun/Slimefun4 into master

This commit is contained in:
Moritz Kempe 2020-10-19 07:36:07 +02:00
commit e9d2d28c43
17 changed files with 193 additions and 48 deletions

View File

@ -31,6 +31,8 @@
* Removed 1.13 support * Removed 1.13 support
#### Fixes #### Fixes
* Fixed #2448
* Fixed #2470
## Release Candidate 17 (17 Oct 2020) ## Release Candidate 17 (17 Oct 2020)

View File

@ -349,7 +349,7 @@
<dependency> <dependency>
<groupId>com.konghq</groupId> <groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId> <artifactId>unirest-java</artifactId>
<version>3.11.01</version> <version>3.11.02</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

View File

@ -394,7 +394,7 @@ public final class SlimefunItems {
public static final SlimefunItemStack PLASTIC_SHEET = new SlimefunItemStack("PLASTIC_SHEET", Material.PAPER, "&fPlastic Sheet"); public static final SlimefunItemStack PLASTIC_SHEET = new SlimefunItemStack("PLASTIC_SHEET", Material.PAPER, "&fPlastic Sheet");
public static final SlimefunItemStack MAGNET = new SlimefunItemStack("MAGNET", HeadTexture.MAGNET, "&cMagnet"); public static final SlimefunItemStack MAGNET = new SlimefunItemStack("MAGNET", HeadTexture.MAGNET, "&cMagnet");
public static final SlimefunItemStack NECROTIC_SKULL = new SlimefunItemStack("NECROTIC_SKULL", Material.WITHER_SKELETON_SKULL, "&cNecrotic Skull"); public static final SlimefunItemStack NECROTIC_SKULL = new SlimefunItemStack("NECROTIC_SKULL", HeadTexture.NECROTIC_SKULL, "&cNecrotic Skull");
public static final SlimefunItemStack ESSENCE_OF_AFTERLIFE = new SlimefunItemStack("ESSENCE_OF_AFTERLIFE", Material.GUNPOWDER, "&4Essence of Afterlife"); public static final SlimefunItemStack ESSENCE_OF_AFTERLIFE = new SlimefunItemStack("ESSENCE_OF_AFTERLIFE", Material.GUNPOWDER, "&4Essence of Afterlife");
public static final SlimefunItemStack STRANGE_NETHER_GOO = new SlimefunItemStack("STRANGE_NETHER_GOO", Material.PURPLE_DYE, "&5Strange Nether Goo", "", "&fA strange bio matter that", "&fcan be acquired from", "&fbartering with Piglins"); public static final SlimefunItemStack STRANGE_NETHER_GOO = new SlimefunItemStack("STRANGE_NETHER_GOO", Material.PURPLE_DYE, "&5Strange Nether Goo", "", "&fA strange bio matter that", "&fcan be acquired from", "&fbartering with Piglins");
public static final SlimefunItemStack ELECTRO_MAGNET = new SlimefunItemStack("ELECTRO_MAGNET", HeadTexture.MAGNET, "&cElectromagnet"); public static final SlimefunItemStack ELECTRO_MAGNET = new SlimefunItemStack("ELECTRO_MAGNET", HeadTexture.MAGNET, "&cElectromagnet");

View File

@ -487,6 +487,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new AncientAltarListener(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem(), (AncientPedestal) SlimefunItems.ANCIENT_PEDESTAL.getItem()); new AncientAltarListener(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem(), (AncientPedestal) SlimefunItems.ANCIENT_PEDESTAL.getItem());
grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem()); grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem());
bowListener.register(this); bowListener.register(this);
backpackListener.register(this);
// Toggleable Listeners for performance reasons // Toggleable Listeners for performance reasons
if (config.getBoolean("items.talismans")) { if (config.getBoolean("items.talismans")) {
@ -497,10 +498,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new SoulboundListener(this); new SoulboundListener(this);
} }
if (config.getBoolean("items.backpacks")) {
backpackListener.register(this);
}
// Handle Slimefun Guide being given on Join // Handle Slimefun Guide being given on Join
new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join")); new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join"));

View File

@ -9,6 +9,7 @@ import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -64,14 +65,14 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
public class ChestSlimefunGuide implements SlimefunGuideImplementation { public class ChestSlimefunGuide implements SlimefunGuideImplementation {
private static final int CATEGORY_SIZE = 36; private static final int CATEGORY_SIZE = 36;
private static final Sound sound = Sound.ITEM_BOOK_PAGE_TURN;
private final ItemStack item;
private final int[] recipeSlots = { 3, 4, 5, 12, 13, 14, 21, 22, 23 }; private final int[] recipeSlots = { 3, 4, 5, 12, 13, 14, 21, 22, 23 };
private final Sound sound = Sound.ITEM_BOOK_PAGE_TURN; private final ItemStack item;
private final boolean showVanillaRecipes; private final boolean showVanillaRecipes;
public ChestSlimefunGuide(boolean vanillaRecipes) { public ChestSlimefunGuide(boolean showVanillaRecipes) {
showVanillaRecipes = vanillaRecipes; this.showVanillaRecipes = showVanillaRecipes;
item = new SlimefunGuideItem(this, "&aSlimefun Guide &7(Chest GUI)"); item = new SlimefunGuideItem(this, "&aSlimefun Guide &7(Chest GUI)");
} }
@ -125,7 +126,6 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
} }
ChestMenu menu = create(p); ChestMenu menu = create(p);
List<Category> categories = getVisibleCategories(p, profile); List<Category> categories = getVisibleCategories(p, profile);
int index = 9; int index = 9;
@ -334,26 +334,14 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
int index = 9; int index = 9;
// Find items and add them // Find items and add them
for (SlimefunItem slimefunItem : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) { for (SlimefunItem slimefunItem : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) {
String itemName = ChatColor.stripColor(slimefunItem.getItemName()).toLowerCase(Locale.ROOT);
if (index == 44) { if (index == 44) {
break; break;
} }
if (!itemName.isEmpty() && (itemName.equals(searchTerm) || itemName.contains(searchTerm))) { if (isSearchFilterApplicable(slimefunItem, searchTerm)) {
ItemStack itemstack = new CustomItem(slimefunItem.getItem(), meta -> { ItemStack itemstack = new CustomItem(slimefunItem.getItem(), meta -> {
List<String> lore = null;
Category category = slimefunItem.getCategory(); Category category = slimefunItem.getCategory();
meta.setLore(Arrays.asList("", ChatColor.DARK_GRAY + "\u21E8 " + ChatColor.WHITE + category.getDisplayName(p)));
if (category != null) {
ItemStack categoryItem = category.getItem(p);
if (categoryItem != null && categoryItem.hasItemMeta() && categoryItem.getItemMeta().hasDisplayName()) {
lore = Arrays.asList("", ChatColor.DARK_GRAY + "\u21E8 " + ChatColor.WHITE + categoryItem.getItemMeta().getDisplayName());
}
}
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS);
}); });
@ -379,6 +367,12 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
menu.open(p); menu.open(p);
} }
@ParametersAreNonnullByDefault
private boolean isSearchFilterApplicable(SlimefunItem slimefunItem, String searchTerm) {
String itemName = ChatColor.stripColor(slimefunItem.getItemName()).toLowerCase(Locale.ROOT);
return !itemName.isEmpty() && (itemName.equals(searchTerm) || itemName.contains(searchTerm));
}
@Override @Override
public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) { public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) {
Player p = profile.getPlayer(); Player p = profile.getPlayer();

View File

@ -108,7 +108,8 @@ public enum HeadTexture {
CARGO_ARROW_RIGHT("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), CARGO_ARROW_RIGHT("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"),
ADD_NEW_LANGUAGE("3edd20be93520949e6ce789dc4f43efaeb28c717ee6bfcbbe02780142f716"), ADD_NEW_LANGUAGE("3edd20be93520949e6ce789dc4f43efaeb28c717ee6bfcbbe02780142f716"),
IRON_GOLEM("89091d79ea0f59ef7ef94d7bba6e5f17f2f7d4572c44f90f76c4819a714"), IRON_GOLEM("89091d79ea0f59ef7ef94d7bba6e5f17f2f7d4572c44f90f76c4819a714"),
PIGLIN_HEAD("2882af1294a74023e6919a31d1a027310f2e142afb4667d230d155e7f21dbb41"); PIGLIN_HEAD("2882af1294a74023e6919a31d1a027310f2e142afb4667d230d155e7f21dbb41"),
NECROTIC_SKULL("7953b6c68448e7e6b6bf8fb273d7203acd8e1be19e81481ead51f45de59a8");
public static final HeadTexture[] valuesCache = values(); public static final HeadTexture[] valuesCache = values();

View File

@ -12,16 +12,51 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
/**
* This class contains various utilities related to numbers and number formatting.
*
* @author TheBusyBiscuit
* @author Walshy
*
*/
public final class NumberUtils { public final class NumberUtils {
/**
* This is our {@link DecimalFormat} for decimal values.
*/
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
/**
* We do not want any instance of this to be created.
*/
private NumberUtils() {} private NumberUtils() {}
public static String formatBigNumber(int i) { /**
return NumberFormat.getNumberInstance(Locale.US).format(i); * This method formats a given {@link Integer} to be displayed nicely with
* decimal digit grouping.
* {@code 1000000} for example will return {@code "1,000,000"} as a {@link String}.
* It uses the american (US) {@link Locale} for this transformation.
*
* @param number
* Your {@link Integer}
*
* @return The formatted String
*/
@Nonnull
public static String formatBigNumber(int number) {
return NumberFormat.getNumberInstance(Locale.US).format(number);
} }
/**
* This method transforms a String representation of a {@link LocalDateTime}
* from GitHub's API back into a {@link LocalDateTime} object
*
* @param date
* The formatted String version of a date from GitHub
*
* @return The {@link LocalDateTime} for the given input
*/
@Nonnull
public static LocalDateTime parseGitHubDate(@Nonnull String date) { public static LocalDateTime parseGitHubDate(@Nonnull String date) {
Validate.notNull(date, "Provided date was null"); Validate.notNull(date, "Provided date was null");
return LocalDateTime.parse(date.substring(0, date.length() - 1)); return LocalDateTime.parse(date.substring(0, date.length() - 1));
@ -37,6 +72,7 @@ public final class NumberUtils {
* *
* @return A representative {@link ChatColor} * @return A representative {@link ChatColor}
*/ */
@Nonnull
public static ChatColor getColorFromPercentage(float percentage) { public static ChatColor getColorFromPercentage(float percentage) {
if (percentage < 16.0F) { if (percentage < 16.0F) {
return ChatColor.DARK_RED; return ChatColor.DARK_RED;
@ -53,13 +89,28 @@ public final class NumberUtils {
} }
} }
/**
* This returns the elapsed time since the given {@link LocalDateTime}.
* The output will be nicely formatted based on the elapsed hours or days since the
* given {@link LocalDateTime}.
*
* If a {@link LocalDateTime} from yesterday was passed it will return {@code "1d"}.
* One hour later it will read {@code "1d 1h"}. For values smaller than an hour {@code "< 1h"}
* will be returned instead.
*
* @param date
* The {@link LocalDateTime}.
*
* @return The elapsed time as a {@link String}
*/
@Nonnull
public static String getElapsedTime(@Nonnull LocalDateTime date) { public static String getElapsedTime(@Nonnull LocalDateTime date) {
Validate.notNull(date, "Provided date was null"); Validate.notNull(date, "Provided date was null");
long hours = Duration.between(date, LocalDateTime.now()).toHours(); long hours = Duration.between(date, LocalDateTime.now()).toHours();
if (hours == 0) { if (hours == 0) {
return "< 1h"; return "< 1h";
} else if ((hours / 24) == 0) { } else if (hours / 24 == 0) {
return (hours % 24) + "h"; return (hours % 24) + "h";
} else if (hours % 24 == 0) { } else if (hours % 24 == 0) {
return (hours / 24) + "d"; return (hours / 24) + "d";
@ -68,10 +119,12 @@ public final class NumberUtils {
} }
} }
@Nonnull
public static String getTimeLeft(int seconds) { public static String getTimeLeft(int seconds) {
String timeleft = ""; String timeleft = "";
int minutes = (int) (seconds / 60L); int minutes = (int) (seconds / 60L);
if (minutes > 0) { if (minutes > 0) {
timeleft += minutes + "m "; timeleft += minutes + "m ";
} }
@ -80,7 +133,7 @@ public final class NumberUtils {
return timeleft + seconds + "s"; return timeleft + seconds + "s";
} }
public static int getInt(String str, int defaultValue) { public static int getInt(@Nonnull String str, int defaultValue) {
if (PatternUtils.NUMERIC.matcher(str).matches()) { if (PatternUtils.NUMERIC.matcher(str).matches()) {
return Integer.parseInt(str); return Integer.parseInt(str);
} }
@ -88,6 +141,7 @@ public final class NumberUtils {
return defaultValue; return defaultValue;
} }
@Nonnull
public static String getAsMillis(long nanoseconds) { public static String getAsMillis(long nanoseconds) {
if (nanoseconds == 0) { if (nanoseconds == 0) {
return "0ms"; return "0ms";

View File

@ -121,6 +121,16 @@ public enum SlimefunTag implements Tag<Material> {
*/ */
CONCRETE_POWDERS, CONCRETE_POWDERS,
/**
* All the types of pressure plates.
*/
PRESSURE_PLATES,
/**
* All tall flowers because minecraft doesn't have a tag for this
*/
TALL_FLOWERS,
/** /**
* Materials which are sensitive to break. * Materials which are sensitive to break.
* Things like Saplings or Pressure plates which break as well when you break * Things like Saplings or Pressure plates which break as well when you break

View File

@ -134,6 +134,7 @@ public class Category implements Keyed {
* *
* @param p * @param p
* The Player to create this {@link ItemStack} for * The Player to create this {@link ItemStack} for
*
* @return A localized display item for this {@link Category} * @return A localized display item for this {@link Category}
*/ */
@Nonnull @Nonnull
@ -166,6 +167,26 @@ public class Category implements Keyed {
return ChatColor.stripColor(item.getItemMeta().getDisplayName()); return ChatColor.stripColor(item.getItemMeta().getDisplayName());
} }
/**
* This returns the localized display name of this {@link Category} for the given {@link Player}.
* The method will fall back to {@link #getUnlocalizedName()} if no translation was found.
*
* @param p
* The {@link Player} who to translate the name for
*
* @return The localized name of this {@link Category}
*/
@Nonnull
public String getDisplayName(@Nonnull Player p) {
String localized = SlimefunPlugin.getLocalization().getCategoryName(p, getKey());
if (localized != null) {
return localized;
} else {
return getUnlocalizedName();
}
}
/** /**
* Returns all instances of {@link SlimefunItem} bound to this {@link Category}. * Returns all instances of {@link SlimefunItem} bound to this {@link Category}.
* *

View File

@ -40,7 +40,6 @@ networks:
items: items:
talismans: true talismans: true
backpacks: true
soulbound: true soulbound: true
metrics: metrics:

View File

@ -20,6 +20,10 @@ commands:
player-never-joined: "&4找不到叫这个名字的玩家!" player-never-joined: "&4找不到叫这个名字的玩家!"
backpack-does-not-exist: "&4你指定的背包不存在!" backpack-does-not-exist: "&4你指定的背包不存在!"
restored-backpack-given: "&a你的背包已被恢复并且已经放入了你的物品栏!" restored-backpack-given: "&a你的背包已被恢复并且已经放入了你的物品栏!"
charge:
description: 为你手持的物品充电
charge-success: 充电完成!
not-rechargeable: 这个物品不能充电!
guide: guide:
search: search:
message: "&b你想要搜索什么?" message: "&b你想要搜索什么?"
@ -127,6 +131,7 @@ messages:
knight: "&a&o你的护身符给予了你 5 秒的生命恢复" knight: "&a&o你的护身符给予了你 5 秒的生命恢复"
whirlwind: "&a&o你的护身符反弹了所有的弹射物" whirlwind: "&a&o你的护身符反弹了所有的弹射物"
wizard: "&a&o你的护身符使一个附魔的等级提高了, 同时其他附魔等级将会下降" wizard: "&a&o你的护身符使一个附魔的等级提高了, 同时其他附魔等级将会下降"
caveman: "&a&o你的护身符给予了你急迫效果"
soulbound-rune: soulbound-rune:
fail: "&c一次只能灵魂绑定一个物品." fail: "&c一次只能灵魂绑定一个物品."
success: "&a物品绑定成功! 在你死亡后此物品将不会掉落." success: "&a物品绑定成功! 在你死亡后此物品将不会掉落."
@ -223,6 +228,7 @@ machines:
finished: "&e你的工业矿机采矿已完成! 总共开采了 %ores% 个矿石!" finished: "&e你的工业矿机采矿已完成! 总共开采了 %ores% 个矿石!"
anvil: anvil:
not-working: "&4你不能在铁砧里使用 Slimefun 的物品" not-working: "&4你不能在铁砧里使用 Slimefun 的物品"
mcmmo-salvaging: "&4你不能分解 Slimefun 物品!"
backpack: backpack:
already-open: "&c抱歉, 这个背包已在别处打开了!" already-open: "&c抱歉, 这个背包已在别处打开了!"
no-stack: "&c你不能同时手持两个背包" no-stack: "&c你不能同时手持两个背包"
@ -331,5 +337,9 @@ brewing_stand:
not-working: "&4你不能在酿造台中使用 Slimefun 物品!" not-working: "&4你不能在酿造台中使用 Slimefun 物品!"
villagers: villagers:
no-trading: "&4你不能用 Slimefun 的物品和村民交易!" no-trading: "&4你不能用 Slimefun 的物品和村民交易!"
cartography_table:
not-working: "&4你不能在制图台中使用 Slimefun 物品!"
cauldron:
no-discoloring: "&4你不能用炼药锅清洗 Slimefun 物品上的颜色"
miner: miner:
no-ores: "&e抱歉, 周围找不到矿石了!" no-ores: "&e抱歉, 周围找不到矿石了!"

View File

@ -243,3 +243,6 @@ slimefun:
climbing_pick: 古块丽影 climbing_pick: 古块丽影
shulker_shell: 人造潜影贝 shulker_shell: 人造潜影贝
villager_rune: 防奸商神器 villager_rune: 防奸商神器
caveman_talisman: 穴居人护身符
even_higher_tier_capacitors: 三级电容器
energy_connectors: 有线连接

View File

@ -1,16 +1,50 @@
{ {
"values" : [ "values" : [
"#slimefun:sensitive_materials", "#slimefun:sensitive_materials",
"#slimefun:tall_flowers",
"#slimefun:mushrooms", "#slimefun:mushrooms",
"#minecraft:beds", "#minecraft:beds",
"#minecraft:buttons",
"#minecraft:signs",
"#minecraft:doors", "#minecraft:doors",
"minecraft:sugar_cane",
"minecraft:bamboo", "minecraft:bamboo",
"minecraft:cactus", "#minecraft:rails",
"#minecraft:small_flowers",
"#minecraft:coral_blocks",
"#minecraft:coral_plants",
"#minecraft:banners",
"minecraft:sugar_cane",
"minecraft:ladder",
"minecraft:snow",
"minecraft:lever",
"minecraft:repeater",
"minecraft:tripwire_hook",
"minecraft:lily_pad", "minecraft:lily_pad",
"minecraft:dead_bush", "minecraft:dead_bush",
"minecraft:fern",
"minecraft:grass",
"minecraft:seagrass",
"minecraft:tall_seagrass",
"minecraft:cactus",
"minecraft:kelp",
{ {
"id" : "#minecraft:tall_flowers", "id" : "minecraft:nether_sprouts",
"required" : false
},
{
"id" : "minecraft:crimson_roots",
"required": false
},
{
"id" : "minecraft:twisting_vines",
"required" : false
},
{
"id" : "minecraft:warped_roots",
"required" : false
},
{
"id" : "minecraft:weeping_vines",
"required" : false "required" : false
} }
] ]

View File

@ -0,0 +1,12 @@
{
"values" : [
"#minecraft:wooden_pressure_plates",
"minecraft:stone_pressure_plate",
"minecraft:light_weighted_pressure_plate",
"minecraft:heavy_weighted_pressure_plate",
{
"id" : "minecraft:polished_blackstone_pressure_plate",
"required" : false
}
]
}

View File

@ -1,11 +1,8 @@
{ {
"values" : [ "values" : [
"#minecraft:saplings", "#minecraft:saplings",
"#minecraft:wooden_pressure_plates",
"#slimefun:torches", "#slimefun:torches",
"minecraft:stone_pressure_plate", "#slimefun:pressure_plates",
"minecraft:light_weighted_pressure_plate",
"minecraft:heavy_weighted_pressure_plate",
"minecraft:cake" "minecraft:cake"
] ]
} }

View File

@ -0,0 +1,10 @@
{
"values" : [
"minecraft:lilac",
"minecraft:rose_bush",
"minecraft:peony",
"minecraft:tall_grass",
"minecraft:large_fern",
"minecraft:sunflower"
]
}

View File

@ -63,6 +63,7 @@ class TestSlimefunTags {
// Inclusion through a Slimefun Tag // Inclusion through a Slimefun Tag
Assertions.assertTrue(SlimefunTag.SENSITIVE_MATERIALS.isTagged(Material.TORCH)); Assertions.assertTrue(SlimefunTag.SENSITIVE_MATERIALS.isTagged(Material.TORCH));
Assertions.assertTrue(SlimefunTag.SENSITIVE_MATERIALS.isTagged(Material.OAK_PRESSURE_PLATE));
} }
@Test @Test