refactor code

This commit is contained in:
Enderaoe 2021-11-11 01:31:12 +08:00
parent 044e0c9f62
commit 28836c11e4
3 changed files with 50 additions and 55 deletions

View File

@ -17,10 +17,7 @@ import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.compat.layers.persistentdata.AbstractPersistentDataLayer;
import com.gmail.nossr50.util.compat.layers.persistentdata.MobMetaFlagType;
import com.gmail.nossr50.util.player.NotificationManager;
@ -931,7 +928,7 @@ public class EntityListener implements Listener {
return;
}
Float foodSaturation = ItemUtils.getFoodSaturation(foodInHand);
Float foodSaturation = MaterialMapStore.getFoodSaturation(foodInHand);
if (foodSaturation != null) {
newSaturationLevel = currentSaturationLevel + foodSaturation;

View File

@ -31,51 +31,6 @@ public final class ItemUtils {
*/
private ItemUtils() {}
private static final HashMap<Material, Float> foodSaturation = new HashMap<>();
static {
foodSaturation.put(Material.APPLE, 1.2F);
foodSaturation.put(Material.BAKED_POTATO, 3.0F);
foodSaturation.put(Material.BEETROOT, 0.6F);
foodSaturation.put(Material.BEETROOT_SOUP, 3.6F);
foodSaturation.put(Material.BREAD, 3.0F);
foodSaturation.put(Material.CAKE, 0.2F);
foodSaturation.put(Material.CARROT, 1.8F);
foodSaturation.put(Material.CHORUS_FRUIT, 1.2F);
foodSaturation.put(Material.COOKED_BEEF, 6.4F);
foodSaturation.put(Material.COOKED_CHICKEN, 3.6F);
foodSaturation.put(Material.COOKED_COD, 3.0F);
foodSaturation.put(Material.COOKED_MUTTON, 4.8F);
foodSaturation.put(Material.COOKED_PORKCHOP, 6.4F);
foodSaturation.put(Material.COOKED_RABBIT, 3.0F);
foodSaturation.put(Material.COOKED_SALMON, 4.8F);
foodSaturation.put(Material.COOKIE, 0.2F);
foodSaturation.put(Material.DRIED_KELP, 0.3F);
foodSaturation.put(Material.ENCHANTED_GOLDEN_APPLE, 4.8F);
foodSaturation.put(Material.HONEY_BOTTLE, 0.6F);
foodSaturation.put(Material.GOLDEN_APPLE, 4.8F);
foodSaturation.put(Material.GOLDEN_CARROT, 7.2F);
foodSaturation.put(Material.MELON_SLICE, 0.6F);
foodSaturation.put(Material.MUSHROOM_STEW, 3.6F);
foodSaturation.put(Material.POISONOUS_POTATO, 0.6F);
foodSaturation.put(Material.POTATO, 0.3F);
foodSaturation.put(Material.PUFFERFISH, 0.1F);
foodSaturation.put(Material.PUMPKIN_PIE, 2.4F);
foodSaturation.put(Material.RABBIT_STEW, 6.0F);
foodSaturation.put(Material.BEEF, 0.9F);
foodSaturation.put(Material.CHICKEN, 0.6F);
foodSaturation.put(Material.COD, 0.2F);
foodSaturation.put(Material.MUTTON, 0.6F);
foodSaturation.put(Material.PORKCHOP, 0.9F);
foodSaturation.put(Material.RABBIT, 0.9F);
foodSaturation.put(Material.SALMON, 0.2F);
foodSaturation.put(Material.ROTTEN_FLESH, 0.4F);
foodSaturation.put(Material.SPIDER_EYE, 1.6F);
foodSaturation.put(Material.SUSPICIOUS_STEW, 3.6F);
foodSaturation.put(Material.SWEET_BERRIES, 0.2F);
foodSaturation.put(Material.TROPICAL_FISH, 0.1F);
}
/**
* Checks if the item is a bow.
*
@ -696,8 +651,4 @@ public final class ItemUtils {
int randomIndex = Misc.getRandom().nextInt(enchantmentWrappers.size());
return enchantmentWrappers.get(randomIndex);
}
public static @Nullable Float getFoodSaturation(@NotNull Material food) {
return foodSaturation.get(food);
}
}

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.util;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.HashSet;
@ -59,7 +60,7 @@ public class MaterialMapStore {
private final @NotNull HashSet<String> intendedToolShovel;
private final @NotNull HashMap<String, Integer> tierValue;
private static final @NotNull HashMap<Material, Float> foodSaturation = new HashMap<>();
public MaterialMapStore()
{
@ -130,6 +131,7 @@ public class MaterialMapStore {
fillIntendedTools();
fillTierMap();
fillFoodSaturation();
}
public boolean isMultiBlockPlant(@NotNull Material material)
@ -198,6 +200,49 @@ public class MaterialMapStore {
}
}
private void fillFoodSaturation() {
foodSaturation.put(Material.APPLE, 1.2F);
foodSaturation.put(Material.BAKED_POTATO, 3.0F);
foodSaturation.put(Material.BEETROOT, 0.6F);
foodSaturation.put(Material.BEETROOT_SOUP, 3.6F);
foodSaturation.put(Material.BREAD, 3.0F);
foodSaturation.put(Material.CAKE, 0.2F);
foodSaturation.put(Material.CARROT, 1.8F);
foodSaturation.put(Material.CHORUS_FRUIT, 1.2F);
foodSaturation.put(Material.COOKED_BEEF, 6.4F);
foodSaturation.put(Material.COOKED_CHICKEN, 3.6F);
foodSaturation.put(Material.COOKED_COD, 3.0F);
foodSaturation.put(Material.COOKED_MUTTON, 4.8F);
foodSaturation.put(Material.COOKED_PORKCHOP, 6.4F);
foodSaturation.put(Material.COOKED_RABBIT, 3.0F);
foodSaturation.put(Material.COOKED_SALMON, 4.8F);
foodSaturation.put(Material.COOKIE, 0.2F);
foodSaturation.put(Material.DRIED_KELP, 0.3F);
foodSaturation.put(Material.ENCHANTED_GOLDEN_APPLE, 4.8F);
foodSaturation.put(Material.HONEY_BOTTLE, 0.6F);
foodSaturation.put(Material.GOLDEN_APPLE, 4.8F);
foodSaturation.put(Material.GOLDEN_CARROT, 7.2F);
foodSaturation.put(Material.MELON_SLICE, 0.6F);
foodSaturation.put(Material.MUSHROOM_STEW, 3.6F);
foodSaturation.put(Material.POISONOUS_POTATO, 0.6F);
foodSaturation.put(Material.POTATO, 0.3F);
foodSaturation.put(Material.PUFFERFISH, 0.1F);
foodSaturation.put(Material.PUMPKIN_PIE, 2.4F);
foodSaturation.put(Material.RABBIT_STEW, 6.0F);
foodSaturation.put(Material.BEEF, 0.9F);
foodSaturation.put(Material.CHICKEN, 0.6F);
foodSaturation.put(Material.COD, 0.2F);
foodSaturation.put(Material.MUTTON, 0.6F);
foodSaturation.put(Material.PORKCHOP, 0.9F);
foodSaturation.put(Material.RABBIT, 0.9F);
foodSaturation.put(Material.SALMON, 0.2F);
foodSaturation.put(Material.ROTTEN_FLESH, 0.4F);
foodSaturation.put(Material.SPIDER_EYE, 1.6F);
foodSaturation.put(Material.SUSPICIOUS_STEW, 3.6F);
foodSaturation.put(Material.SWEET_BERRIES, 0.2F);
foodSaturation.put(Material.TROPICAL_FISH, 0.1F);
}
private void fillOres() {
ores.add("coal_ore");
ores.add("diamond_ore");
@ -1318,6 +1363,8 @@ public class MaterialMapStore {
return tierValue.getOrDefault(id, 1); //1 for unknown items
}
public @Nullable static float getFoodSaturation(@NotNull Material food) { return foodSaturation.get(food); }
private void addToHashSet(@NotNull String string, @NotNull HashSet<String> stringHashSet)
{
stringHashSet.add(string.toLowerCase(Locale.ENGLISH));