Working on project

This commit is contained in:
Barazok
2020-10-09 23:20:31 +02:00
parent 688b61ba36
commit 896106222d
12 changed files with 860 additions and 489 deletions

View File

@@ -2,63 +2,133 @@ package net.babamod.mineclass.classes;
import net.babamod.mineclass.utils.AppliedStatus;
import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
public class ClassWrapper {
public static void reapplyRightClassEffects(Player player, boolean sendReminder) {
if (AppliedStatus.getInstance().isDwarf(player.getName()) || DwarfClass.is(player)) {
AppliedStatus.getInstance().setDwarf(player.getName(), true);
DwarfClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are a dwarf.");
}
}
if (AppliedStatus.getInstance().isElf(player.getName()) || ElfClass.is(player)) {
AppliedStatus.getInstance().setElf(player.getName(), true);
ElfClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are an elf.");
}
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName()) || FireDwarfClass.is(player)) {
AppliedStatus.getInstance().setFireDwarf(player.getName(), true);
FireDwarfClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are a fire dwarf.");
}
}
if (AppliedStatus.getInstance().isNaga(player.getName()) || NagaClass.is(player)) {
AppliedStatus.getInstance().setNaga(player.getName(), true);
NagaClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are a naga.");
}
}
public static void reapplyRightClassEffects(Player player, boolean sendReminder) {
if (AppliedStatus.getInstance().isDwarf(player.getName()) || DwarfClass.is(player)) {
AppliedStatus.getInstance().setDwarf(player.getName(), true);
DwarfClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are a dwarf.");
}
}
if (AppliedStatus.getInstance().isElf(player.getName()) || ElfClass.is(player)) {
AppliedStatus.getInstance().setElf(player.getName(), true);
ElfClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are an elf.");
}
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName()) || FireDwarfClass.is(player)) {
AppliedStatus.getInstance().setFireDwarf(player.getName(), true);
FireDwarfClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are a fire dwarf.");
}
}
if (AppliedStatus.getInstance().isNaga(player.getName()) || NagaClass.is(player)) {
AppliedStatus.getInstance().setNaga(player.getName(), true);
NagaClass.reapplyEffects(player);
if (sendReminder) {
player.sendMessage("Reminder : You are a naga.");
}
}
}
public static void clearAllClassEffects(Player player) {
for (PotionEffect activePotionEffect : player.getActivePotionEffects()) {
if (activePotionEffect.getDuration() > 32766) {
player.removePotionEffect(activePotionEffect.getType());
}
}
public static void clearAllClassEffects(Player player) {
for (PotionEffect activePotionEffect : player.getActivePotionEffects()) {
if (activePotionEffect.getDuration() > 32766) {
player.removePotionEffect(activePotionEffect.getType());
}
}
}
public static boolean isItemForbidden(Player player, Material type) {
if (AppliedStatus.getInstance().isDwarf(player.getName())) {
return DwarfClass.isItemForbidden(type);
}
if (AppliedStatus.getInstance().isElf(player.getName())) {
return ElfClass.isItemForbidden(type);
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName())) {
return FireDwarfClass.isItemForbidden(type);
}
if (AppliedStatus.getInstance().isNaga(player.getName())) {
return NagaClass.isItemForbidden(type);
}
return false;
public static boolean isItemForbidden(Player player, Material type) {
if (AppliedStatus.getInstance().isDwarf(player.getName())) {
return DwarfClass.isItemForbidden(type);
}
if (AppliedStatus.getInstance().isElf(player.getName())) {
return ElfClass.isItemForbidden(type);
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName())) {
return FireDwarfClass.isItemForbidden(type);
}
if (AppliedStatus.getInstance().isNaga(player.getName())) {
return NagaClass.isItemForbidden(type);
}
return false;
}
public static boolean isItemEnchantable(Player player, Material type) {
if (AppliedStatus.getInstance().isDwarf(player.getName())) {
return DwarfClass.isItemEnchantable(type);
}
if (AppliedStatus.getInstance().isElf(player.getName())) {
return ElfClass.isItemEnchantable(type);
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName())) {
return FireDwarfClass.isItemEnchantable(type);
}
if (AppliedStatus.getInstance().isNaga(player.getName())) {
return NagaClass.isItemEnchantable(type);
}
return false;
}
public static void enchantItem(Player player, Item item) {
if (AppliedStatus.getInstance().isDwarf(player.getName())) {
DwarfClass.enchantItem(item.getItemStack());
}
if (AppliedStatus.getInstance().isElf(player.getName())) {
ElfClass.enchantItem(item.getItemStack());
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName())) {
FireDwarfClass.enchantItem(item.getItemStack());
}
if (AppliedStatus.getInstance().isNaga(player.getName())) {
NagaClass.enchantItem(item.getItemStack());
}
}
public static void givePlayerClassItem(Player player) {
if (AppliedStatus.getInstance().isDwarf(player.getName())) {
DwarfClass.giveClassItem(player);
}
if (AppliedStatus.getInstance().isElf(player.getName())) {
ElfClass.giveClassItem(player);
}
if (AppliedStatus.getInstance().isFireDwarf(player.getName())) {
FireDwarfClass.giveClassItem(player);
}
if (AppliedStatus.getInstance().isNaga(player.getName())) {
NagaClass.giveClassItem(player);
}
}
public static boolean isSoulBound(ItemStack itemStack) {
if (itemStack.getItemMeta() != null && itemStack.getItemMeta().getLore() != null) {
return itemStack.getItemMeta().getLore().contains("Soulbound");
}
return false;
}
public static void removePlayerClassItem(Player player) {
for (ItemStack content :
Arrays.stream(player.getInventory().getContents())
.filter(Objects::nonNull)
.collect(Collectors.toList())) {
if (isSoulBound(content)) {
player.getInventory().remove(content);
}
}
}
}

View File

@@ -4,6 +4,8 @@ import net.babamod.mineclass.utils.Pair;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -13,66 +15,120 @@ import java.util.stream.Stream;
public class DwarfClass {
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
add(Material.DIAMOND_AXE);
add(Material.GOLDEN_AXE);
add(Material.IRON_AXE);
add(Material.NETHERITE_AXE);
add(Material.DIAMOND_HOE);
add(Material.GOLDEN_HOE);
add(Material.IRON_HOE);
add(Material.NETHERITE_HOE);
add(Material.BOW);
add(Material.TRIDENT);
}};
private static final Set<Material> forbiddenItems =
new HashSet<Material>() {
{
add(Material.DIAMOND_AXE);
add(Material.GOLDEN_AXE);
add(Material.IRON_AXE);
add(Material.NETHERITE_AXE);
add(Material.DIAMOND_HOE);
add(Material.GOLDEN_HOE);
add(Material.IRON_HOE);
add(Material.NETHERITE_HOE);
add(Material.BOW);
add(Material.TRIDENT);
}
};
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
{PotionEffectType.HEALTH_BOOST, 2},
{PotionEffectType.DAMAGE_RESISTANCE, 1},
{PotionEffectType.HERO_OF_THE_VILLAGE, 1},
{PotionEffectType.FAST_DIGGING, 1},
{PotionEffectType.NIGHT_VISION, 1},
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<PotionEffectType, Integer> potionEffects =
Stream.of(
new Object[][] {
{PotionEffectType.HEALTH_BOOST, 2},
{PotionEffectType.DAMAGE_RESISTANCE, 1},
{PotionEffectType.HERO_OF_THE_VILLAGE, 1},
{PotionEffectType.FAST_DIGGING, 1},
{PotionEffectType.NIGHT_VISION, 1},
})
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments = Stream.of(
new AbstractMap.SimpleEntry<>(Material.NETHERITE_PICKAXE, Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
)),
new AbstractMap.SimpleEntry<>(Material.DIAMOND_PICKAXE, Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
)),
new AbstractMap.SimpleEntry<>(Material.IRON_PICKAXE, Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
)),
new AbstractMap.SimpleEntry<>(Material.GOLDEN_PICKAXE, Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
)),
new AbstractMap.SimpleEntry<>(Material.STONE_PICKAXE, Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
)),
new AbstractMap.SimpleEntry<>(Material.WOODEN_PICKAXE, Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
))
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
Stream.of(
new AbstractMap.SimpleEntry<>(
Material.NETHERITE_PICKAXE,
Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
new AbstractMap.SimpleEntry<>(
Material.DIAMOND_PICKAXE,
Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
new AbstractMap.SimpleEntry<>(
Material.IRON_PICKAXE,
Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
new AbstractMap.SimpleEntry<>(
Material.GOLDEN_PICKAXE,
Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
new AbstractMap.SimpleEntry<>(
Material.STONE_PICKAXE,
Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
new AbstractMap.SimpleEntry<>(
Material.WOODEN_PICKAXE,
Arrays.asList(
new Pair<>(Enchantment.DIG_SPEED, 8),
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static boolean is(Player player) {
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
}
public static boolean is(Player player) {
return player.getActivePotionEffects().stream()
.map(PotionEffect::getType)
.collect(Collectors.toList())
.containsAll(potionEffects.keySet());
}
public static void reapplyEffects(Player player) {
potionEffects.forEach((key, value) -> {
public static void reapplyEffects(Player player) {
potionEffects.forEach(
(key, value) -> {
if (player.hasPotionEffect(key)) {
player.removePotionEffect(key);
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
}
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
});
}
}
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
}
public static boolean isItemEnchantable(Material type) {
return classEnchantments.containsKey(type);
}
public static void enchantItem(ItemStack itemStack) {
if (itemStack.getItemMeta() != null) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setUnbreakable(true);
itemMeta.setLore(Collections.singletonList("Soulbound"));
itemStack.setItemMeta(itemMeta);
}
classEnchantments
.getOrDefault(itemStack.getType(), new ArrayList<>())
.forEach(
enchantmentIntegerPair ->
itemStack.addUnsafeEnchantment(
enchantmentIntegerPair.getFirst(), enchantmentIntegerPair.getSecond()));
}
public static void giveClassItem(Player player) {
List<Boolean> itemStackList =
Arrays.stream(player.getInventory().getContents())
.filter(Objects::nonNull)
.map(ClassWrapper::isSoulBound)
.collect(Collectors.toList());
if (itemStackList.contains(true)) {
return;
}
for (Material material : classEnchantments.keySet()) {
ItemStack itemStack = new ItemStack(material);
enchantItem(itemStack);
player.getInventory().addItem(itemStack);
}
}
}

View File

@@ -3,7 +3,10 @@ package net.babamod.mineclass.classes;
import net.babamod.mineclass.utils.Pair;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -13,49 +16,108 @@ import java.util.stream.Stream;
public class ElfClass {
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
add(Material.DIAMOND_SWORD);
add(Material.GOLDEN_SWORD);
add(Material.IRON_SWORD);
add(Material.NETHERITE_SWORD);
add(Material.DIAMOND_PICKAXE);
add(Material.GOLDEN_PICKAXE);
add(Material.IRON_PICKAXE);
add(Material.NETHERITE_PICKAXE);
add(Material.DIAMOND_SHOVEL);
add(Material.GOLDEN_SHOVEL);
add(Material.IRON_SHOVEL);
add(Material.NETHERITE_SHOVEL);
add(Material.CROSSBOW);
add(Material.TRIDENT);
}};
private static final Set<Material> forbiddenItems =
new HashSet<Material>() {
{
add(Material.DIAMOND_SWORD);
add(Material.GOLDEN_SWORD);
add(Material.IRON_SWORD);
add(Material.NETHERITE_SWORD);
add(Material.DIAMOND_PICKAXE);
add(Material.GOLDEN_PICKAXE);
add(Material.IRON_PICKAXE);
add(Material.NETHERITE_PICKAXE);
add(Material.DIAMOND_SHOVEL);
add(Material.GOLDEN_SHOVEL);
add(Material.IRON_SHOVEL);
add(Material.NETHERITE_SHOVEL);
add(Material.CROSSBOW);
add(Material.TRIDENT);
}
};
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
{PotionEffectType.SPEED, 2},
{PotionEffectType.JUMP, 3},
{PotionEffectType.LUCK, 1},
{PotionEffectType.NIGHT_VISION, 1},
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<PotionEffectType, Integer> potionEffects =
Stream.of(
new Object[][] {
{PotionEffectType.SPEED, 2},
{PotionEffectType.JUMP, 3},
{PotionEffectType.LUCK, 1},
{PotionEffectType.NIGHT_VISION, 1},
})
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments = Stream.of(
new AbstractMap.SimpleEntry<>(Material.BOW, Arrays.asList(
new Pair<>(Enchantment.ARROW_INFINITE, 1),
new Pair<>(Enchantment.ARROW_DAMAGE, 8)
))
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
Stream.of(
new AbstractMap.SimpleEntry<>(
Material.BOW,
Arrays.asList(
new Pair<>(Enchantment.ARROW_INFINITE, 1),
new Pair<>(Enchantment.ARROW_DAMAGE, 8))))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static boolean is(Player player) {
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
}
public static boolean is(Player player) {
return player.getActivePotionEffects().stream()
.map(PotionEffect::getType)
.collect(Collectors.toList())
.containsAll(potionEffects.keySet());
}
public static void reapplyEffects(Player player) {
potionEffects.forEach((key, value) -> {
public static void reapplyEffects(Player player) {
potionEffects.forEach(
(key, value) -> {
if (player.hasPotionEffect(key)) {
player.removePotionEffect(key);
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
}
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
});
}
}
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
}
public static boolean isItemEnchantable(Material type) {
return classEnchantments.containsKey(type);
}
public static void makeSoulbound(ItemStack itemStack) {
if (itemStack.getItemMeta() != null) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setUnbreakable(true);
itemMeta.setLore(Collections.singletonList("Soulbound"));
itemStack.setItemMeta(itemMeta);
}
}
public static void enchantItem(ItemStack itemStack) {
makeSoulbound(itemStack);
classEnchantments
.getOrDefault(itemStack.getType(), new ArrayList<>())
.forEach(
enchantmentIntegerPair ->
itemStack
.addUnsafeEnchantment(
enchantmentIntegerPair.getFirst(), enchantmentIntegerPair.getSecond()));
}
public static void giveClassItem(Player player) {
List<Boolean> itemStackList =
Arrays.stream(player.getInventory().getContents())
.filter(Objects::nonNull)
.map(ClassWrapper::isSoulBound)
.collect(Collectors.toList());
if (itemStackList.contains(true)) {
return;
}
for (Material material : classEnchantments.keySet()) {
if (material.equals(Material.BOW)) {
ItemStack itemStack = new ItemStack(Material.ARROW);
makeSoulbound(itemStack);
player.getInventory().addItem(itemStack);
}
ItemStack itemStack = new ItemStack(material);
enchantItem(itemStack);
player.getInventory().addItem(itemStack);
}
}
}

View File

@@ -3,7 +3,10 @@ package net.babamod.mineclass.classes;
import net.babamod.mineclass.utils.Pair;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -13,86 +16,137 @@ import java.util.stream.Stream;
public class FireDwarfClass {
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
add(Material.DIAMOND_SWORD);
add(Material.GOLDEN_SWORD);
add(Material.IRON_SWORD);
add(Material.NETHERITE_SWORD);
add(Material.DIAMOND_HOE);
add(Material.GOLDEN_HOE);
add(Material.IRON_HOE);
add(Material.NETHERITE_HOE);
add(Material.DIAMOND_SHOVEL);
add(Material.GOLDEN_SHOVEL);
add(Material.IRON_SHOVEL);
add(Material.NETHERITE_SHOVEL);
add(Material.BOW);
add(Material.ARROW);
add(Material.TRIDENT);
}};
private static final Set<Material> forbiddenItems =
new HashSet<Material>() {
{
add(Material.DIAMOND_SWORD);
add(Material.GOLDEN_SWORD);
add(Material.IRON_SWORD);
add(Material.NETHERITE_SWORD);
add(Material.DIAMOND_HOE);
add(Material.GOLDEN_HOE);
add(Material.IRON_HOE);
add(Material.NETHERITE_HOE);
add(Material.DIAMOND_SHOVEL);
add(Material.GOLDEN_SHOVEL);
add(Material.IRON_SHOVEL);
add(Material.NETHERITE_SHOVEL);
add(Material.BOW);
add(Material.ARROW);
add(Material.TRIDENT);
}
};
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
{PotionEffectType.FIRE_RESISTANCE, 1},
{PotionEffectType.FAST_DIGGING, 1},
{PotionEffectType.JUMP, 2},
{PotionEffectType.NIGHT_VISION, 1},
{PotionEffectType.HEALTH_BOOST, 2},
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<PotionEffectType, Integer> potionEffects =
Stream.of(
new Object[][] {
{PotionEffectType.FIRE_RESISTANCE, 1},
{PotionEffectType.FAST_DIGGING, 1},
{PotionEffectType.JUMP, 2},
{PotionEffectType.NIGHT_VISION, 1},
{PotionEffectType.HEALTH_BOOST, 2},
})
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantment = Stream.of(
new AbstractMap.SimpleEntry<>(Material.NETHERITE_AXE, Collections.singletonList(
new Pair<>(Enchantment.FIRE_ASPECT, 2)
)),
new AbstractMap.SimpleEntry<>(Material.DIAMOND_AXE, Collections.singletonList(
new Pair<>(Enchantment.FIRE_ASPECT, 2)
)),
new AbstractMap.SimpleEntry<>(Material.IRON_AXE, Collections.singletonList(
new Pair<>(Enchantment.FIRE_ASPECT, 2)
)),
new AbstractMap.SimpleEntry<>(Material.GOLDEN_AXE, Collections.singletonList(
new Pair<>(Enchantment.FIRE_ASPECT, 2)
)),
new AbstractMap.SimpleEntry<>(Material.STONE_AXE, Collections.singletonList(
new Pair<>(Enchantment.FIRE_ASPECT, 2)
)),
new AbstractMap.SimpleEntry<>(Material.WOODEN_AXE, Collections.singletonList(
new Pair<>(Enchantment.FIRE_ASPECT, 2)
)),
new AbstractMap.SimpleEntry<>(Material.NETHERITE_PICKAXE, Collections.singletonList(
new Pair<>(Enchantment.DIG_SPEED, 5)
)),
new AbstractMap.SimpleEntry<>(Material.DIAMOND_PICKAXE, Collections.singletonList(
new Pair<>(Enchantment.DIG_SPEED, 5)
)),
new AbstractMap.SimpleEntry<>(Material.IRON_PICKAXE, Collections.singletonList(
new Pair<>(Enchantment.DIG_SPEED, 5)
)),
new AbstractMap.SimpleEntry<>(Material.GOLDEN_PICKAXE, Collections.singletonList(
new Pair<>(Enchantment.DIG_SPEED, 5)
)),
new AbstractMap.SimpleEntry<>(Material.STONE_PICKAXE, Collections.singletonList(
new Pair<>(Enchantment.DIG_SPEED, 5)
)),
new AbstractMap.SimpleEntry<>(Material.WOODEN_PICKAXE, Collections.singletonList(
new Pair<>(Enchantment.DIG_SPEED, 5)
)),
new AbstractMap.SimpleEntry<>(Material.FLINT_AND_STEEL, new ArrayList<Pair<Enchantment, Integer>>())
// See to make infinity working on crossbow
// Inventory auto smelt
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
Stream.of(
new AbstractMap.SimpleEntry<>(
Material.NETHERITE_AXE,
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
new AbstractMap.SimpleEntry<>(
Material.DIAMOND_AXE,
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
new AbstractMap.SimpleEntry<>(
Material.IRON_AXE,
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
new AbstractMap.SimpleEntry<>(
Material.GOLDEN_AXE,
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
new AbstractMap.SimpleEntry<>(
Material.STONE_AXE,
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
new AbstractMap.SimpleEntry<>(
Material.WOODEN_AXE,
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
new AbstractMap.SimpleEntry<>(
Material.NETHERITE_PICKAXE,
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
new AbstractMap.SimpleEntry<>(
Material.DIAMOND_PICKAXE,
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
new AbstractMap.SimpleEntry<>(
Material.IRON_PICKAXE,
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
new AbstractMap.SimpleEntry<>(
Material.GOLDEN_PICKAXE,
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
new AbstractMap.SimpleEntry<>(
Material.STONE_PICKAXE,
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
new AbstractMap.SimpleEntry<>(
Material.WOODEN_PICKAXE,
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
new AbstractMap.SimpleEntry<>(
Material.FLINT_AND_STEEL, new ArrayList<Pair<Enchantment, Integer>>())
// See to make infinity working on crossbow
// Inventory auto smelt
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static boolean is(Player player) {
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
}
public static boolean is(Player player) {
return player.getActivePotionEffects().stream()
.map(PotionEffect::getType)
.collect(Collectors.toList())
.containsAll(potionEffects.keySet());
}
public static void reapplyEffects(Player player) {
potionEffects.forEach((key, value) -> {
public static void reapplyEffects(Player player) {
potionEffects.forEach(
(key, value) -> {
if (player.hasPotionEffect(key)) {
player.removePotionEffect(key);
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
}
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
});
}
}
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
}
public static boolean isItemEnchantable(Material type) {
return classEnchantments.containsKey(type);
}
public static void enchantItem(ItemStack itemStack) {
if (itemStack.getItemMeta() != null) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setUnbreakable(true);
itemMeta.setLore(Collections.singletonList("Soulbound"));
itemStack.setItemMeta(itemMeta);
}
classEnchantments
.getOrDefault(itemStack.getType(), new ArrayList<>())
.forEach(
enchantmentIntegerPair ->
itemStack
.addUnsafeEnchantment(
enchantmentIntegerPair.getFirst(), enchantmentIntegerPair.getSecond()));
}
public static void giveClassItem(Player player) {
List<Boolean> itemStackList =
Arrays.stream(player.getInventory().getContents())
.filter(Objects::nonNull)
.map(ClassWrapper::isSoulBound)
.collect(Collectors.toList());
if (itemStackList.contains(true)) {
return;
}
for (Material material : classEnchantments.keySet()) {
ItemStack itemStack = new ItemStack(material);
enchantItem(itemStack);
player.getInventory().addItem(itemStack);
}
}
}

View File

@@ -4,6 +4,8 @@ import net.babamod.mineclass.utils.Pair;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -13,70 +15,119 @@ import java.util.stream.Stream;
public class NagaClass {
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
add(Material.DIAMOND_SWORD);
add(Material.GOLDEN_SWORD);
add(Material.IRON_SWORD);
add(Material.NETHERITE_SWORD);
add(Material.DIAMOND_AXE);
add(Material.GOLDEN_AXE);
add(Material.IRON_AXE);
add(Material.NETHERITE_AXE);
add(Material.CROSSBOW);
add(Material.BOW);
add(Material.FLINT_AND_STEEL);
}};
private static final Set<Material> forbiddenItems =
new HashSet<Material>() {
{
add(Material.DIAMOND_SWORD);
add(Material.GOLDEN_SWORD);
add(Material.IRON_SWORD);
add(Material.NETHERITE_SWORD);
add(Material.DIAMOND_AXE);
add(Material.GOLDEN_AXE);
add(Material.IRON_AXE);
add(Material.NETHERITE_AXE);
add(Material.CROSSBOW);
add(Material.BOW);
add(Material.FLINT_AND_STEEL);
}
};
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
{PotionEffectType.DOLPHINS_GRACE, 1},
{PotionEffectType.CONDUIT_POWER, 1},
{PotionEffectType.WATER_BREATHING, 1},
{PotionEffectType.SLOW, 2},
{PotionEffectType.WEAKNESS, 1},
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<PotionEffectType, Integer> potionEffects =
Stream.of(
new Object[][] {
{PotionEffectType.DOLPHINS_GRACE, 1},
{PotionEffectType.CONDUIT_POWER, 1},
{PotionEffectType.WATER_BREATHING, 1},
{PotionEffectType.SLOW, 2},
{PotionEffectType.WEAKNESS, 1},
})
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantment = Stream.of(
new AbstractMap.SimpleEntry<>(Material.TRIDENT, Arrays.asList(
new Pair<>(Enchantment.LOYALTY, 3),
new Pair<>(Enchantment.IMPALING, 5),
new Pair<>(Enchantment.CHANNELING, 1)
)),
new AbstractMap.SimpleEntry<>(Material.NETHERITE_HOE, Collections.singletonList(
new Pair<>(Enchantment.DAMAGE_ALL, 5)
)),
new AbstractMap.SimpleEntry<>(Material.DIAMOND_HOE, Collections.singletonList(
new Pair<>(Enchantment.DAMAGE_ALL, 5)
)),
new AbstractMap.SimpleEntry<>(Material.IRON_HOE, Collections.singletonList(
new Pair<>(Enchantment.DAMAGE_ALL, 5)
)),
new AbstractMap.SimpleEntry<>(Material.WOODEN_HOE, Collections.singletonList(
new Pair<>(Enchantment.DAMAGE_ALL, 5)
)),
new AbstractMap.SimpleEntry<>(Material.GOLDEN_HOE, Collections.singletonList(
new Pair<>(Enchantment.DAMAGE_ALL, 5)
)),
new AbstractMap.SimpleEntry<>(Material.STONE_HOE, Collections.singletonList(
new Pair<>(Enchantment.DAMAGE_ALL, 5)
)),
new AbstractMap.SimpleEntry<>(Material.FISHING_ROD, Arrays.asList(
new Pair<>(Enchantment.LUCK, 3),
new Pair<>(Enchantment.LURE, 3)
))
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
Stream.of(
new AbstractMap.SimpleEntry<>(
Material.TRIDENT,
Arrays.asList(
new Pair<>(Enchantment.LOYALTY, 3),
new Pair<>(Enchantment.IMPALING, 5),
new Pair<>(Enchantment.CHANNELING, 1))),
new AbstractMap.SimpleEntry<>(
Material.NETHERITE_HOE,
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
new AbstractMap.SimpleEntry<>(
Material.DIAMOND_HOE,
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
new AbstractMap.SimpleEntry<>(
Material.IRON_HOE,
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
new AbstractMap.SimpleEntry<>(
Material.WOODEN_HOE,
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
new AbstractMap.SimpleEntry<>(
Material.GOLDEN_HOE,
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
new AbstractMap.SimpleEntry<>(
Material.STONE_HOE,
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
new AbstractMap.SimpleEntry<>(
Material.FISHING_ROD,
Arrays.asList(new Pair<>(Enchantment.LUCK, 3), new Pair<>(Enchantment.LURE, 3))))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static boolean is(Player player) {
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
}
public static boolean is(Player player) {
return player.getActivePotionEffects().stream()
.map(PotionEffect::getType)
.collect(Collectors.toList())
.containsAll(potionEffects.keySet());
}
public static void reapplyEffects(Player player) {
potionEffects.forEach((key, value) -> {
public static void reapplyEffects(Player player) {
potionEffects.forEach(
(key, value) -> {
if (player.hasPotionEffect(key)) {
player.removePotionEffect(key);
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
}
player.addPotionEffect(new PotionEffect(key, Integer.MAX_VALUE, value - 1, false, false));
});
}
}
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
public static boolean isItemForbidden(Material type) {
return forbiddenItems.contains(type);
}
public static boolean isItemEnchantable(Material type) {
return classEnchantments.containsKey(type);
}
public static void enchantItem(ItemStack itemStack) {
if (itemStack.getItemMeta() != null) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setUnbreakable(true);
itemMeta.setLore(Collections.singletonList("Soulbound"));
itemStack.setItemMeta(itemMeta);
}
classEnchantments
.getOrDefault(itemStack.getType(), new ArrayList<>())
.forEach(
enchantmentIntegerPair ->
itemStack
.addUnsafeEnchantment(
enchantmentIntegerPair.getFirst(), enchantmentIntegerPair.getSecond()));
}
public static void giveClassItem(Player player) {
List<Boolean> itemStackList =
Arrays.stream(player.getInventory().getContents())
.filter(Objects::nonNull)
.map(ClassWrapper::isSoulBound)
.collect(Collectors.toList());
if (itemStackList.contains(true)) {
return;
}
for (Material material : classEnchantments.keySet()) {
ItemStack itemStack = new ItemStack(material);
enchantItem(itemStack);
player.getInventory().addItem(itemStack);
}
}
}