Working on project
This commit is contained in:
@@ -17,7 +17,9 @@ public final class Mineclass extends JavaPlugin implements Listener {
|
|||||||
new MineClassListeners(this);
|
new MineClassListeners(this);
|
||||||
PluginCommand pluginCommand = this.getCommand("class");
|
PluginCommand pluginCommand = this.getCommand("class");
|
||||||
if (pluginCommand != null) {
|
if (pluginCommand != null) {
|
||||||
pluginCommand.setTabCompleter((sender, command, alias, args) -> Arrays.asList("dwarf", "elf", "fire_dwarf", "naga", "clear", "whoami"));
|
pluginCommand.setTabCompleter(
|
||||||
|
(sender, command, alias, args) ->
|
||||||
|
Arrays.asList("dwarf", "elf", "fire_dwarf", "naga", "clear", "whoami"));
|
||||||
pluginCommand.setExecutor(new CommandClass());
|
pluginCommand.setExecutor(new CommandClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,15 @@ package net.babamod.mineclass.classes;
|
|||||||
|
|
||||||
import net.babamod.mineclass.utils.AppliedStatus;
|
import net.babamod.mineclass.utils.AppliedStatus;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ClassWrapper {
|
public class ClassWrapper {
|
||||||
|
|
||||||
public static void reapplyRightClassEffects(Player player, boolean sendReminder) {
|
public static void reapplyRightClassEffects(Player player, boolean sendReminder) {
|
||||||
@@ -61,4 +67,68 @@ public class ClassWrapper {
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import net.babamod.mineclass.utils.Pair;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
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.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@@ -13,7 +15,9 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class DwarfClass {
|
public class DwarfClass {
|
||||||
|
|
||||||
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
|
private static final Set<Material> forbiddenItems =
|
||||||
|
new HashSet<Material>() {
|
||||||
|
{
|
||||||
add(Material.DIAMOND_AXE);
|
add(Material.DIAMOND_AXE);
|
||||||
add(Material.GOLDEN_AXE);
|
add(Material.GOLDEN_AXE);
|
||||||
add(Material.IRON_AXE);
|
add(Material.IRON_AXE);
|
||||||
@@ -24,50 +28,67 @@ public class DwarfClass {
|
|||||||
add(Material.NETHERITE_HOE);
|
add(Material.NETHERITE_HOE);
|
||||||
add(Material.BOW);
|
add(Material.BOW);
|
||||||
add(Material.TRIDENT);
|
add(Material.TRIDENT);
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
|
private static final Map<PotionEffectType, Integer> potionEffects =
|
||||||
|
Stream.of(
|
||||||
|
new Object[][] {
|
||||||
{PotionEffectType.HEALTH_BOOST, 2},
|
{PotionEffectType.HEALTH_BOOST, 2},
|
||||||
{PotionEffectType.DAMAGE_RESISTANCE, 1},
|
{PotionEffectType.DAMAGE_RESISTANCE, 1},
|
||||||
{PotionEffectType.HERO_OF_THE_VILLAGE, 1},
|
{PotionEffectType.HERO_OF_THE_VILLAGE, 1},
|
||||||
{PotionEffectType.FAST_DIGGING, 1},
|
{PotionEffectType.FAST_DIGGING, 1},
|
||||||
{PotionEffectType.NIGHT_VISION, 1},
|
{PotionEffectType.NIGHT_VISION, 1},
|
||||||
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
})
|
||||||
|
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
||||||
|
|
||||||
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments = Stream.of(
|
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
|
||||||
new AbstractMap.SimpleEntry<>(Material.NETHERITE_PICKAXE, Arrays.asList(
|
Stream.of(
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Material.NETHERITE_PICKAXE,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 8),
|
new Pair<>(Enchantment.DIG_SPEED, 8),
|
||||||
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
|
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.DIAMOND_PICKAXE, Arrays.asList(
|
Material.DIAMOND_PICKAXE,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 8),
|
new Pair<>(Enchantment.DIG_SPEED, 8),
|
||||||
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
|
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.IRON_PICKAXE, Arrays.asList(
|
Material.IRON_PICKAXE,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 8),
|
new Pair<>(Enchantment.DIG_SPEED, 8),
|
||||||
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
|
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.GOLDEN_PICKAXE, Arrays.asList(
|
Material.GOLDEN_PICKAXE,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 8),
|
new Pair<>(Enchantment.DIG_SPEED, 8),
|
||||||
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
|
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.STONE_PICKAXE, Arrays.asList(
|
Material.STONE_PICKAXE,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 8),
|
new Pair<>(Enchantment.DIG_SPEED, 8),
|
||||||
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
|
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.WOODEN_PICKAXE, Arrays.asList(
|
Material.WOODEN_PICKAXE,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 8),
|
new Pair<>(Enchantment.DIG_SPEED, 8),
|
||||||
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2)
|
new Pair<>(Enchantment.LOOT_BONUS_BLOCKS, 2))))
|
||||||
))
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
public static boolean is(Player player) {
|
public static boolean is(Player player) {
|
||||||
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
|
return player.getActivePotionEffects().stream()
|
||||||
|
.map(PotionEffect::getType)
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.containsAll(potionEffects.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reapplyEffects(Player player) {
|
public static void reapplyEffects(Player player) {
|
||||||
potionEffects.forEach((key, value) -> {
|
potionEffects.forEach(
|
||||||
|
(key, value) -> {
|
||||||
|
if (player.hasPotionEffect(key)) {
|
||||||
player.removePotionEffect(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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -75,4 +96,39 @@ public class DwarfClass {
|
|||||||
public static boolean isItemForbidden(Material type) {
|
public static boolean isItemForbidden(Material type) {
|
||||||
return forbiddenItems.contains(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package net.babamod.mineclass.classes;
|
|||||||
import net.babamod.mineclass.utils.Pair;
|
import net.babamod.mineclass.utils.Pair;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
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.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@@ -13,7 +16,9 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class ElfClass {
|
public class ElfClass {
|
||||||
|
|
||||||
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
|
private static final Set<Material> forbiddenItems =
|
||||||
|
new HashSet<Material>() {
|
||||||
|
{
|
||||||
add(Material.DIAMOND_SWORD);
|
add(Material.DIAMOND_SWORD);
|
||||||
add(Material.GOLDEN_SWORD);
|
add(Material.GOLDEN_SWORD);
|
||||||
add(Material.IRON_SWORD);
|
add(Material.IRON_SWORD);
|
||||||
@@ -28,29 +33,41 @@ public class ElfClass {
|
|||||||
add(Material.NETHERITE_SHOVEL);
|
add(Material.NETHERITE_SHOVEL);
|
||||||
add(Material.CROSSBOW);
|
add(Material.CROSSBOW);
|
||||||
add(Material.TRIDENT);
|
add(Material.TRIDENT);
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
|
private static final Map<PotionEffectType, Integer> potionEffects =
|
||||||
|
Stream.of(
|
||||||
|
new Object[][] {
|
||||||
{PotionEffectType.SPEED, 2},
|
{PotionEffectType.SPEED, 2},
|
||||||
{PotionEffectType.JUMP, 3},
|
{PotionEffectType.JUMP, 3},
|
||||||
{PotionEffectType.LUCK, 1},
|
{PotionEffectType.LUCK, 1},
|
||||||
{PotionEffectType.NIGHT_VISION, 1},
|
{PotionEffectType.NIGHT_VISION, 1},
|
||||||
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
})
|
||||||
|
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
||||||
|
|
||||||
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments = Stream.of(
|
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
|
||||||
new AbstractMap.SimpleEntry<>(Material.BOW, Arrays.asList(
|
Stream.of(
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Material.BOW,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.ARROW_INFINITE, 1),
|
new Pair<>(Enchantment.ARROW_INFINITE, 1),
|
||||||
new Pair<>(Enchantment.ARROW_DAMAGE, 8)
|
new Pair<>(Enchantment.ARROW_DAMAGE, 8))))
|
||||||
))
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
public static boolean is(Player player) {
|
public static boolean is(Player player) {
|
||||||
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
|
return player.getActivePotionEffects().stream()
|
||||||
|
.map(PotionEffect::getType)
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.containsAll(potionEffects.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reapplyEffects(Player player) {
|
public static void reapplyEffects(Player player) {
|
||||||
potionEffects.forEach((key, value) -> {
|
potionEffects.forEach(
|
||||||
|
(key, value) -> {
|
||||||
|
if (player.hasPotionEffect(key)) {
|
||||||
player.removePotionEffect(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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -58,4 +75,49 @@ public class ElfClass {
|
|||||||
public static boolean isItemForbidden(Material type) {
|
public static boolean isItemForbidden(Material type) {
|
||||||
return forbiddenItems.contains(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package net.babamod.mineclass.classes;
|
|||||||
import net.babamod.mineclass.utils.Pair;
|
import net.babamod.mineclass.utils.Pair;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
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.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@@ -13,7 +16,9 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class FireDwarfClass {
|
public class FireDwarfClass {
|
||||||
|
|
||||||
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
|
private static final Set<Material> forbiddenItems =
|
||||||
|
new HashSet<Material>() {
|
||||||
|
{
|
||||||
add(Material.DIAMOND_SWORD);
|
add(Material.DIAMOND_SWORD);
|
||||||
add(Material.GOLDEN_SWORD);
|
add(Material.GOLDEN_SWORD);
|
||||||
add(Material.IRON_SWORD);
|
add(Material.IRON_SWORD);
|
||||||
@@ -29,65 +34,78 @@ public class FireDwarfClass {
|
|||||||
add(Material.BOW);
|
add(Material.BOW);
|
||||||
add(Material.ARROW);
|
add(Material.ARROW);
|
||||||
add(Material.TRIDENT);
|
add(Material.TRIDENT);
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
|
private static final Map<PotionEffectType, Integer> potionEffects =
|
||||||
|
Stream.of(
|
||||||
|
new Object[][] {
|
||||||
{PotionEffectType.FIRE_RESISTANCE, 1},
|
{PotionEffectType.FIRE_RESISTANCE, 1},
|
||||||
{PotionEffectType.FAST_DIGGING, 1},
|
{PotionEffectType.FAST_DIGGING, 1},
|
||||||
{PotionEffectType.JUMP, 2},
|
{PotionEffectType.JUMP, 2},
|
||||||
{PotionEffectType.NIGHT_VISION, 1},
|
{PotionEffectType.NIGHT_VISION, 1},
|
||||||
{PotionEffectType.HEALTH_BOOST, 2},
|
{PotionEffectType.HEALTH_BOOST, 2},
|
||||||
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
})
|
||||||
|
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
||||||
|
|
||||||
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantment = Stream.of(
|
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
|
||||||
new AbstractMap.SimpleEntry<>(Material.NETHERITE_AXE, Collections.singletonList(
|
Stream.of(
|
||||||
new Pair<>(Enchantment.FIRE_ASPECT, 2)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.NETHERITE_AXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.DIAMOND_AXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
|
||||||
new Pair<>(Enchantment.FIRE_ASPECT, 2)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.DIAMOND_AXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.IRON_AXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
|
||||||
new Pair<>(Enchantment.FIRE_ASPECT, 2)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.IRON_AXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.GOLDEN_AXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
|
||||||
new Pair<>(Enchantment.FIRE_ASPECT, 2)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.GOLDEN_AXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.STONE_AXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
|
||||||
new Pair<>(Enchantment.FIRE_ASPECT, 2)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.STONE_AXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.WOODEN_AXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
|
||||||
new Pair<>(Enchantment.FIRE_ASPECT, 2)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.WOODEN_AXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.NETHERITE_PICKAXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.FIRE_ASPECT, 2))),
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 5)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.NETHERITE_PICKAXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.DIAMOND_PICKAXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 5)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.DIAMOND_PICKAXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.IRON_PICKAXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 5)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.IRON_PICKAXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.GOLDEN_PICKAXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 5)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.GOLDEN_PICKAXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.STONE_PICKAXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 5)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.STONE_PICKAXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.WOODEN_PICKAXE, Collections.singletonList(
|
Collections.singletonList(new Pair<>(Enchantment.DIG_SPEED, 5))),
|
||||||
new Pair<>(Enchantment.DIG_SPEED, 5)
|
new AbstractMap.SimpleEntry<>(
|
||||||
)),
|
Material.WOODEN_PICKAXE,
|
||||||
new AbstractMap.SimpleEntry<>(Material.FLINT_AND_STEEL, new ArrayList<Pair<Enchantment, Integer>>())
|
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
|
// See to make infinity working on crossbow
|
||||||
// Inventory auto smelt
|
// Inventory auto smelt
|
||||||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
)
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
public static boolean is(Player player) {
|
public static boolean is(Player player) {
|
||||||
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
|
return player.getActivePotionEffects().stream()
|
||||||
|
.map(PotionEffect::getType)
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.containsAll(potionEffects.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reapplyEffects(Player player) {
|
public static void reapplyEffects(Player player) {
|
||||||
potionEffects.forEach((key, value) -> {
|
potionEffects.forEach(
|
||||||
|
(key, value) -> {
|
||||||
|
if (player.hasPotionEffect(key)) {
|
||||||
player.removePotionEffect(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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -95,4 +113,40 @@ public class FireDwarfClass {
|
|||||||
public static boolean isItemForbidden(Material type) {
|
public static boolean isItemForbidden(Material type) {
|
||||||
return forbiddenItems.contains(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import net.babamod.mineclass.utils.Pair;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
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.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@@ -13,7 +15,9 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class NagaClass {
|
public class NagaClass {
|
||||||
|
|
||||||
private static final Set<Material> forbiddenItems = new HashSet<Material>() {{
|
private static final Set<Material> forbiddenItems =
|
||||||
|
new HashSet<Material>() {
|
||||||
|
{
|
||||||
add(Material.DIAMOND_SWORD);
|
add(Material.DIAMOND_SWORD);
|
||||||
add(Material.GOLDEN_SWORD);
|
add(Material.GOLDEN_SWORD);
|
||||||
add(Material.IRON_SWORD);
|
add(Material.IRON_SWORD);
|
||||||
@@ -25,53 +29,64 @@ public class NagaClass {
|
|||||||
add(Material.CROSSBOW);
|
add(Material.CROSSBOW);
|
||||||
add(Material.BOW);
|
add(Material.BOW);
|
||||||
add(Material.FLINT_AND_STEEL);
|
add(Material.FLINT_AND_STEEL);
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final Map<PotionEffectType, Integer> potionEffects = Stream.of(new Object[][]{
|
private static final Map<PotionEffectType, Integer> potionEffects =
|
||||||
|
Stream.of(
|
||||||
|
new Object[][] {
|
||||||
{PotionEffectType.DOLPHINS_GRACE, 1},
|
{PotionEffectType.DOLPHINS_GRACE, 1},
|
||||||
{PotionEffectType.CONDUIT_POWER, 1},
|
{PotionEffectType.CONDUIT_POWER, 1},
|
||||||
{PotionEffectType.WATER_BREATHING, 1},
|
{PotionEffectType.WATER_BREATHING, 1},
|
||||||
{PotionEffectType.SLOW, 2},
|
{PotionEffectType.SLOW, 2},
|
||||||
{PotionEffectType.WEAKNESS, 1},
|
{PotionEffectType.WEAKNESS, 1},
|
||||||
}).collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
})
|
||||||
|
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
||||||
|
|
||||||
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantment = Stream.of(
|
private static final Map<Material, List<Pair<Enchantment, Integer>>> classEnchantments =
|
||||||
new AbstractMap.SimpleEntry<>(Material.TRIDENT, Arrays.asList(
|
Stream.of(
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Material.TRIDENT,
|
||||||
|
Arrays.asList(
|
||||||
new Pair<>(Enchantment.LOYALTY, 3),
|
new Pair<>(Enchantment.LOYALTY, 3),
|
||||||
new Pair<>(Enchantment.IMPALING, 5),
|
new Pair<>(Enchantment.IMPALING, 5),
|
||||||
new Pair<>(Enchantment.CHANNELING, 1)
|
new Pair<>(Enchantment.CHANNELING, 1))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.NETHERITE_HOE, Collections.singletonList(
|
Material.NETHERITE_HOE,
|
||||||
new Pair<>(Enchantment.DAMAGE_ALL, 5)
|
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.DIAMOND_HOE, Collections.singletonList(
|
Material.DIAMOND_HOE,
|
||||||
new Pair<>(Enchantment.DAMAGE_ALL, 5)
|
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.IRON_HOE, Collections.singletonList(
|
Material.IRON_HOE,
|
||||||
new Pair<>(Enchantment.DAMAGE_ALL, 5)
|
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.WOODEN_HOE, Collections.singletonList(
|
Material.WOODEN_HOE,
|
||||||
new Pair<>(Enchantment.DAMAGE_ALL, 5)
|
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.GOLDEN_HOE, Collections.singletonList(
|
Material.GOLDEN_HOE,
|
||||||
new Pair<>(Enchantment.DAMAGE_ALL, 5)
|
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.STONE_HOE, Collections.singletonList(
|
Material.STONE_HOE,
|
||||||
new Pair<>(Enchantment.DAMAGE_ALL, 5)
|
Collections.singletonList(new Pair<>(Enchantment.DAMAGE_ALL, 5))),
|
||||||
)),
|
new AbstractMap.SimpleEntry<>(
|
||||||
new AbstractMap.SimpleEntry<>(Material.FISHING_ROD, Arrays.asList(
|
Material.FISHING_ROD,
|
||||||
new Pair<>(Enchantment.LUCK, 3),
|
Arrays.asList(new Pair<>(Enchantment.LUCK, 3), new Pair<>(Enchantment.LURE, 3))))
|
||||||
new Pair<>(Enchantment.LURE, 3)
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
))
|
|
||||||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
public static boolean is(Player player) {
|
public static boolean is(Player player) {
|
||||||
return player.getActivePotionEffects().stream().map(PotionEffect::getType).collect(Collectors.toList()).containsAll(potionEffects.keySet());
|
return player.getActivePotionEffects().stream()
|
||||||
|
.map(PotionEffect::getType)
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.containsAll(potionEffects.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reapplyEffects(Player player) {
|
public static void reapplyEffects(Player player) {
|
||||||
potionEffects.forEach((key, value) -> {
|
potionEffects.forEach(
|
||||||
|
(key, value) -> {
|
||||||
|
if (player.hasPotionEffect(key)) {
|
||||||
player.removePotionEffect(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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -79,4 +94,40 @@ public class NagaClass {
|
|||||||
public static boolean isItemForbidden(Material type) {
|
public static boolean isItemForbidden(Material type) {
|
||||||
return forbiddenItems.contains(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class CommandClass implements CommandExecutor {
|
|||||||
AppliedStatus.getInstance().setDwarf(player.getName(), true);
|
AppliedStatus.getInstance().setDwarf(player.getName(), true);
|
||||||
ClassWrapper.clearAllClassEffects(player);
|
ClassWrapper.clearAllClassEffects(player);
|
||||||
DwarfClass.reapplyEffects(player);
|
DwarfClass.reapplyEffects(player);
|
||||||
|
DwarfClass.giveClassItem(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equals("elf")) {
|
if (args[0].equals("elf")) {
|
||||||
@@ -32,6 +33,7 @@ public class CommandClass implements CommandExecutor {
|
|||||||
AppliedStatus.getInstance().setElf(player.getName(), true);
|
AppliedStatus.getInstance().setElf(player.getName(), true);
|
||||||
ClassWrapper.clearAllClassEffects(player);
|
ClassWrapper.clearAllClassEffects(player);
|
||||||
ElfClass.reapplyEffects(player);
|
ElfClass.reapplyEffects(player);
|
||||||
|
ElfClass.giveClassItem(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equals("fire_dwarf")) {
|
if (args[0].equals("fire_dwarf")) {
|
||||||
@@ -41,6 +43,7 @@ public class CommandClass implements CommandExecutor {
|
|||||||
AppliedStatus.getInstance().setFireDwarf(player.getName(), true);
|
AppliedStatus.getInstance().setFireDwarf(player.getName(), true);
|
||||||
ClassWrapper.clearAllClassEffects(player);
|
ClassWrapper.clearAllClassEffects(player);
|
||||||
FireDwarfClass.reapplyEffects(player);
|
FireDwarfClass.reapplyEffects(player);
|
||||||
|
FireDwarfClass.giveClassItem(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equals("naga")) {
|
if (args[0].equals("naga")) {
|
||||||
@@ -50,6 +53,7 @@ public class CommandClass implements CommandExecutor {
|
|||||||
AppliedStatus.getInstance().setNaga(player.getName(), true);
|
AppliedStatus.getInstance().setNaga(player.getName(), true);
|
||||||
ClassWrapper.clearAllClassEffects(player);
|
ClassWrapper.clearAllClassEffects(player);
|
||||||
NagaClass.reapplyEffects(player);
|
NagaClass.reapplyEffects(player);
|
||||||
|
NagaClass.giveClassItem(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equals("clear")) {
|
if (args[0].equals("clear")) {
|
||||||
@@ -58,6 +62,7 @@ public class CommandClass implements CommandExecutor {
|
|||||||
AppliedStatus.getInstance().setFireDwarf(player.getName(), false);
|
AppliedStatus.getInstance().setFireDwarf(player.getName(), false);
|
||||||
AppliedStatus.getInstance().setNaga(player.getName(), false);
|
AppliedStatus.getInstance().setNaga(player.getName(), false);
|
||||||
ClassWrapper.clearAllClassEffects(player);
|
ClassWrapper.clearAllClassEffects(player);
|
||||||
|
ClassWrapper.removePlayerClassItem(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equals("whoami")) {
|
if (args[0].equals("whoami")) {
|
||||||
|
|||||||
@@ -5,18 +5,15 @@ import java.util.HashMap;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AppliedStatus implements Serializable {
|
public class AppliedStatus implements Serializable {
|
||||||
/**
|
/** Instance unique pré-initialisée */
|
||||||
* Instance unique pré-initialisée
|
|
||||||
*/
|
|
||||||
private static AppliedStatus INSTANCE;
|
private static AppliedStatus INSTANCE;
|
||||||
|
|
||||||
private final HashMap<String, Boolean> dwarf;
|
private final HashMap<String, Boolean> dwarf;
|
||||||
private final HashMap<String, Boolean> elf;
|
private final HashMap<String, Boolean> elf;
|
||||||
private final HashMap<String, Boolean> fireDwarf;
|
private final HashMap<String, Boolean> fireDwarf;
|
||||||
private final HashMap<String, Boolean> naga;
|
private final HashMap<String, Boolean> naga;
|
||||||
|
|
||||||
/**
|
/** Constructeur privé */
|
||||||
* Constructeur privé
|
|
||||||
*/
|
|
||||||
private AppliedStatus() {
|
private AppliedStatus() {
|
||||||
dwarf = new HashMap<>();
|
dwarf = new HashMap<>();
|
||||||
elf = new HashMap<>();
|
elf = new HashMap<>();
|
||||||
@@ -24,9 +21,7 @@ public class AppliedStatus implements Serializable {
|
|||||||
naga = new HashMap<>();
|
naga = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Point d'accès pour l'instance unique du singleton */
|
||||||
* Point d'accès pour l'instance unique du singleton
|
|
||||||
*/
|
|
||||||
public static synchronized AppliedStatus getInstance() {
|
public static synchronized AppliedStatus getInstance() {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
INSTANCE = new AppliedStatus();
|
INSTANCE = new AppliedStatus();
|
||||||
@@ -68,10 +63,10 @@ public class AppliedStatus implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAClass(String playerName) {
|
public boolean hasAClass(String playerName) {
|
||||||
return dwarf.getOrDefault(playerName, false) ||
|
return dwarf.getOrDefault(playerName, false)
|
||||||
elf.getOrDefault(playerName, false) ||
|
|| elf.getOrDefault(playerName, false)
|
||||||
fireDwarf.getOrDefault(playerName, false) ||
|
|| fireDwarf.getOrDefault(playerName, false)
|
||||||
naga.getOrDefault(playerName, false);
|
|| naga.getOrDefault(playerName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,10 +74,10 @@ public class AppliedStatus implements Serializable {
|
|||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
AppliedStatus that = (AppliedStatus) o;
|
AppliedStatus that = (AppliedStatus) o;
|
||||||
return Objects.equals(dwarf, that.dwarf) &&
|
return Objects.equals(dwarf, that.dwarf)
|
||||||
Objects.equals(elf, that.elf) &&
|
&& Objects.equals(elf, that.elf)
|
||||||
Objects.equals(fireDwarf, that.fireDwarf) &&
|
&& Objects.equals(fireDwarf, that.fireDwarf)
|
||||||
Objects.equals(naga, that.naga);
|
&& Objects.equals(naga, that.naga);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,11 +87,15 @@ public class AppliedStatus implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AppliedStatus{" +
|
return "AppliedStatus{"
|
||||||
"dwarf=" + dwarf +
|
+ "dwarf="
|
||||||
", elf=" + elf +
|
+ dwarf
|
||||||
", fireDwarf=" + fireDwarf +
|
+ ", elf="
|
||||||
", naga=" + naga +
|
+ elf
|
||||||
'}';
|
+ ", fireDwarf="
|
||||||
|
+ fireDwarf
|
||||||
|
+ ", naga="
|
||||||
|
+ naga
|
||||||
|
+ '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,4 @@ public class ApplyClassStatusTask extends BukkitRunnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
ClassWrapper.reapplyRightClassEffects(player, false);
|
ClassWrapper.reapplyRightClassEffects(player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,25 @@ package net.babamod.mineclass.utils;
|
|||||||
import net.babamod.mineclass.Mineclass;
|
import net.babamod.mineclass.Mineclass;
|
||||||
import net.babamod.mineclass.classes.ClassWrapper;
|
import net.babamod.mineclass.classes.ClassWrapper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.inventory.*;
|
||||||
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MineClassListeners implements Listener {
|
public class MineClassListeners implements Listener {
|
||||||
|
|
||||||
@@ -38,9 +51,69 @@ public class MineClassListeners implements Listener {
|
|||||||
public void on(EntityPickupItemEvent event) {
|
public void on(EntityPickupItemEvent event) {
|
||||||
if (event.getEntity() instanceof Player) {
|
if (event.getEntity() instanceof Player) {
|
||||||
Player player = (Player) event.getEntity();
|
Player player = (Player) event.getEntity();
|
||||||
|
player.sendMessage("You picked up " + event.getItem().getItemStack().getType());
|
||||||
if (ClassWrapper.isItemForbidden(player, event.getItem().getItemStack().getType())) {
|
if (ClassWrapper.isItemForbidden(player, event.getItem().getItemStack().getType())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
player.sendMessage(
|
||||||
|
String.valueOf(
|
||||||
|
ClassWrapper.isItemEnchantable(player, event.getItem().getItemStack().getType())));
|
||||||
|
if (ClassWrapper.isItemEnchantable(player, event.getItem().getItemStack().getType())) {
|
||||||
|
player.sendMessage("Enchantable item !");
|
||||||
|
ClassWrapper.enchantItem(player, event.getItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void on(PlayerDeathEvent event) {
|
||||||
|
List<ItemStack> itemStackList =
|
||||||
|
event.getDrops().stream().filter(ClassWrapper::isSoulBound).collect(Collectors.toList());
|
||||||
|
event.getDrops().removeAll(itemStackList);
|
||||||
|
ClassWrapper.removePlayerClassItem(event.getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void on(PlayerRespawnEvent event) {
|
||||||
|
ClassWrapper.givePlayerClassItem(event.getPlayer());
|
||||||
|
new ApplyClassStatusTask(this.plugin, event.getPlayer()).runTaskLater(this.plugin, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void on(PlayerDropItemEvent event) {
|
||||||
|
if (ClassWrapper.isSoulBound(event.getItemDrop().getItemStack())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void on(InventoryClickEvent event) {
|
||||||
|
System.out.println("InventoryClickEvent triggered !");
|
||||||
|
System.out.println("-----------------------------------");
|
||||||
|
System.out.println(event.getAction());
|
||||||
|
System.out.println(event.getClick());
|
||||||
|
System.out.println(event.getClickedInventory());
|
||||||
|
System.out.println(event.getCurrentItem());
|
||||||
|
System.out.println(event.getCursor());
|
||||||
|
System.out.println(event.getSlotType());
|
||||||
|
System.out.println(Arrays.toString(event.getHandlers().getRegisteredListeners()));
|
||||||
|
System.out.println(event.getHotbarButton());
|
||||||
|
System.out.println(event.getRawSlot());
|
||||||
|
System.out.println(event.getSlot());
|
||||||
|
System.out.println("-----------------------------------");
|
||||||
|
|
||||||
|
if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||||
|
if (event.getCurrentItem() != null && ClassWrapper.isSoulBound(event.getCurrentItem())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getCursor() != null && ClassWrapper.isSoulBound(event.getCursor())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
IMPOSSIBLE DE GIVER LES ITEMS DE CLASSES.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user