Implement the Naga class and update some behaviors and effects of other classes
This commit is contained in:
@@ -50,7 +50,7 @@ public class BeastMasterClass extends MineClassImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<PotionEffectType, Integer> getPotionEffects() {
|
public Map<PotionEffectType, Integer> getPotionEffects(Player player) {
|
||||||
return potionEffects;
|
return potionEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class DwarfClass extends MineClassImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<PotionEffectType, Integer> getPotionEffects() {
|
public Map<PotionEffectType, Integer> getPotionEffects(Player player) {
|
||||||
return potionEffects;
|
return potionEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class ElfClass extends MineClassImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<PotionEffectType, Integer> getPotionEffects() {
|
public Map<PotionEffectType, Integer> getPotionEffects(Player player) {
|
||||||
return potionEffects;
|
return potionEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class EnderElfClass extends MineClassImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<PotionEffectType, Integer> getPotionEffects() {
|
public Map<PotionEffectType, Integer> getPotionEffects(Player player) {
|
||||||
return potionEffects;
|
return potionEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +87,12 @@ public class EnderElfClass extends MineClassImpl {
|
|||||||
public void reapplyEffects(Player player) {
|
public void reapplyEffects(Player player) {
|
||||||
super.reapplyEffects(player);
|
super.reapplyEffects(player);
|
||||||
if (player.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
|
if (player.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
|
||||||
PotionEffect saturation =
|
player.addPotionEffect(
|
||||||
new PotionEffect(PotionEffectType.SATURATION, Integer.MAX_VALUE, 9, false, false);
|
new PotionEffect(PotionEffectType.SATURATION, Integer.MAX_VALUE, 0, false, false));
|
||||||
player.addPotionEffect(saturation);
|
player.addPotionEffect(
|
||||||
|
new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0, false, false));
|
||||||
|
player.addPotionEffect(
|
||||||
|
new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 0, false, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package net.rawmod.mineclass.classes;
|
|||||||
|
|
||||||
import net.rawmod.mineclass.utils.Pair;
|
import net.rawmod.mineclass.utils.Pair;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -88,13 +90,26 @@ public class FireDwarfClass extends MineClassImpl {
|
|||||||
Material.FLINT_AND_STEEL, new ArrayList<Pair<Enchantment, Integer>>()))
|
Material.FLINT_AND_STEEL, new ArrayList<Pair<Enchantment, Integer>>()))
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reapplyEffects(Player player) {
|
||||||
|
super.reapplyEffects(player);
|
||||||
|
if (player.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
|
||||||
|
player.addPotionEffect(
|
||||||
|
new PotionEffect(PotionEffectType.SATURATION, Integer.MAX_VALUE, 0, false, false));
|
||||||
|
player.addPotionEffect(
|
||||||
|
new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0, false, false));
|
||||||
|
player.addPotionEffect(
|
||||||
|
new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 0, false, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Material> getForbiddenItems() {
|
public Set<Material> getForbiddenItems() {
|
||||||
return forbiddenItems;
|
return forbiddenItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<PotionEffectType, Integer> getPotionEffects() {
|
public Map<PotionEffectType, Integer> getPotionEffects(Player player) {
|
||||||
return potionEffects;
|
return potionEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public interface MineClass {
|
|||||||
|
|
||||||
Set<Material> getForbiddenItems();
|
Set<Material> getForbiddenItems();
|
||||||
|
|
||||||
Map<PotionEffectType, Integer> getPotionEffects();
|
Map<PotionEffectType, Integer> getPotionEffects(Player player);
|
||||||
|
|
||||||
Map<Material, List<Pair<Enchantment, Integer>>> getClassEnchantments();
|
Map<Material, List<Pair<Enchantment, Integer>>> getClassEnchantments();
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class MineClassFactory {
|
|||||||
availableClasses.put("fire_dwarf", new FireDwarfClass());
|
availableClasses.put("fire_dwarf", new FireDwarfClass());
|
||||||
availableClasses.put("ender_elf", new EnderElfClass());
|
availableClasses.put("ender_elf", new EnderElfClass());
|
||||||
availableClasses.put("beast_master", new BeastMasterClass());
|
availableClasses.put("beast_master", new BeastMasterClass());
|
||||||
|
availableClasses.put("naga", new NagaClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Point d'accès pour l'instance unique du singleton */
|
/** Point d'accès pour l'instance unique du singleton */
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public abstract class MineClassImpl implements MineClass {
|
|||||||
@Override
|
@Override
|
||||||
public void reapplyEffects(Player player) {
|
public void reapplyEffects(Player player) {
|
||||||
MineClassFactory.clearAllClassEffects(player);
|
MineClassFactory.clearAllClassEffects(player);
|
||||||
getPotionEffects()
|
getPotionEffects(player)
|
||||||
.forEach(
|
.forEach(
|
||||||
(key, value) -> {
|
(key, value) -> {
|
||||||
if (player.hasPotionEffect(key)) {
|
if (player.hasPotionEffect(key)) {
|
||||||
|
|||||||
106
src/main/java/net/rawmod/mineclass/classes/NagaClass.java
Normal file
106
src/main/java/net/rawmod/mineclass/classes/NagaClass.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package net.rawmod.mineclass.classes;
|
||||||
|
|
||||||
|
import net.rawmod.mineclass.utils.Pair;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class NagaClass extends MineClassImpl {
|
||||||
|
|
||||||
|
private static final Set<Material> forbiddenItems =
|
||||||
|
new HashSet<>() {
|
||||||
|
{
|
||||||
|
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_AXE);
|
||||||
|
add(Material.GOLDEN_AXE);
|
||||||
|
add(Material.IRON_AXE);
|
||||||
|
add(Material.NETHERITE_AXE);
|
||||||
|
add(Material.CROSSBOW);
|
||||||
|
add(Material.BOW);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Map<PotionEffectType, Integer> potionEffectsInWater =
|
||||||
|
Stream.of(
|
||||||
|
new Object[][] {
|
||||||
|
{PotionEffectType.WATER_BREATHING, 1},
|
||||||
|
{PotionEffectType.HEALTH_BOOST, 2},
|
||||||
|
{PotionEffectType.CONDUIT_POWER, 1},
|
||||||
|
{PotionEffectType.DOLPHINS_GRACE, 3},
|
||||||
|
{PotionEffectType.SATURATION, 1},
|
||||||
|
{PotionEffectType.NIGHT_VISION, 1},
|
||||||
|
{PotionEffectType.DAMAGE_RESISTANCE, 2},
|
||||||
|
{PotionEffectType.INCREASE_DAMAGE, 2},
|
||||||
|
{PotionEffectType.FAST_DIGGING, 10},
|
||||||
|
})
|
||||||
|
.collect(Collectors.toMap(data -> (PotionEffectType) data[0], data -> (Integer) data[1]));
|
||||||
|
|
||||||
|
private static final Map<PotionEffectType, Integer> potionEffectsOnEarth =
|
||||||
|
Stream.of(
|
||||||
|
new Object[][] {
|
||||||
|
{PotionEffectType.SLOW, 4},
|
||||||
|
{PotionEffectType.SLOW_DIGGING, 1},
|
||||||
|
{PotionEffectType.HUNGER, 10},
|
||||||
|
{PotionEffectType.WEAKNESS, 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.TRIDENT,
|
||||||
|
Arrays.asList(
|
||||||
|
new Pair<>(Enchantment.LOYALTY, 3),
|
||||||
|
new Pair<>(Enchantment.CHANNELING, 1),
|
||||||
|
new Pair<>(Enchantment.IMPALING, 5))))
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Material> getForbiddenItems() {
|
||||||
|
return forbiddenItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<PotionEffectType, Integer> getPotionEffects(Player player) {
|
||||||
|
return player.isInWater() ? potionEffectsInWater : potionEffectsOnEarth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Material, List<Pair<Enchantment, Integer>>> getClassEnchantments() {
|
||||||
|
return classEnchantments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCode() {
|
||||||
|
return "naga";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Naga";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void giveItems(Player player) {
|
||||||
|
if (!player.getInventory().contains(Material.TRIDENT)) {
|
||||||
|
ItemStack itemStack = new ItemStack(Material.TRIDENT, 1);
|
||||||
|
enchantItem(itemStack, player);
|
||||||
|
player.getInventory().addItem(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import org.bukkit.metadata.MetadataValue;
|
|||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -34,6 +35,8 @@ import java.util.stream.Collectors;
|
|||||||
public class MineClassListeners implements Listener {
|
public class MineClassListeners implements Listener {
|
||||||
|
|
||||||
private final Mineclass plugin;
|
private final Mineclass plugin;
|
||||||
|
private final HashMap<Player, PlayerTimerEffects> playerTimerEffectsHashMap =
|
||||||
|
new HashMap<>();
|
||||||
|
|
||||||
public MineClassListeners(Mineclass plugin) {
|
public MineClassListeners(Mineclass plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -46,11 +49,26 @@ public class MineClassListeners implements Listener {
|
|||||||
Optional<MineClass> mineClass = MineClassFactory.getInstance().getRightClass(player);
|
Optional<MineClass> mineClass = MineClassFactory.getInstance().getRightClass(player);
|
||||||
if (mineClass.isPresent()) {
|
if (mineClass.isPresent()) {
|
||||||
mineClass.get().reapplyEffects(player);
|
mineClass.get().reapplyEffects(player);
|
||||||
player.sendMessage(String.format("Reminder : You are a %s.", mineClass.get().getCode()));
|
player.sendMessage(String.format("Reminder, your class is : %s.", mineClass.get().getName()));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
"Hello ! The amazing MineClass mod is available on this server ! You can pick a class with the /class command.");
|
"Hello ! The amazing MineClass mod is available on this server ! You can pick a class with the /class command.");
|
||||||
}
|
}
|
||||||
|
if (!playerTimerEffectsHashMap.containsKey(player)) {
|
||||||
|
PlayerTimerEffects playerTimerEffects =
|
||||||
|
new PlayerTimerEffects(player);
|
||||||
|
playerTimerEffectsHashMap.put(player, playerTimerEffects);
|
||||||
|
playerTimerEffects.runTaskTimer(this.plugin, 20, 20);
|
||||||
|
} else {
|
||||||
|
playerTimerEffectsHashMap.get(player).runTaskTimer(this.plugin, 20, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void on(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (playerTimerEffectsHashMap.containsKey(player)) {
|
||||||
|
playerTimerEffectsHashMap.get(player).cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -230,7 +248,7 @@ public class MineClassListeners implements Listener {
|
|||||||
if (player.getAttackCooldown() == 1) {
|
if (player.getAttackCooldown() == 1) {
|
||||||
// Vampirisme
|
// Vampirisme
|
||||||
if (player.getHealth() < 20) {
|
if (player.getHealth() < 20) {
|
||||||
player.setHealth(Math.min(player.getHealth() + 1, 20));
|
PlayerUtils.heal(player, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PlayerHitCounter.getInstance().getHitCounter(player) == 15) {
|
if (PlayerHitCounter.getInstance().getHitCounter(player) == 15) {
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package net.rawmod.mineclass.utils;
|
||||||
|
|
||||||
|
import net.rawmod.mineclass.classes.MineClass;
|
||||||
|
import net.rawmod.mineclass.classes.MineClassFactory;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class PlayerTimerEffects extends BukkitRunnable {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private boolean inWater;
|
||||||
|
|
||||||
|
public PlayerTimerEffects(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
this.inWater = player.isInWater();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Optional<MineClass> mineClass = MineClassFactory.getInstance().getRightClass(player);
|
||||||
|
if (mineClass.isPresent() && mineClass.get().getCode().equals("naga")) {
|
||||||
|
if (!player.isInWater()) {
|
||||||
|
player.damage(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (player.isInWater() != inWater) {
|
||||||
|
inWater = player.isInWater();
|
||||||
|
mineClass.get().reapplyEffects(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mineClass.isPresent() && mineClass.get().getCode().equals("fire_dwarf")) {
|
||||||
|
if (player.getFireTicks() > 0) {
|
||||||
|
PlayerUtils.heal(player, 2);
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 40, 3));
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 40, 1));
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 40, 1));
|
||||||
|
}
|
||||||
|
if (player.isInWater()) {
|
||||||
|
player.damage(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/java/net/rawmod/mineclass/utils/PlayerUtils.java
Normal file
14
src/main/java/net/rawmod/mineclass/utils/PlayerUtils.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package net.rawmod.mineclass.utils;
|
||||||
|
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PlayerUtils {
|
||||||
|
public static void heal(Player player, double amount) {
|
||||||
|
AttributeInstance maxHealh = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
if (maxHealh != null) {
|
||||||
|
player.setHealth(Math.min(player.getHealth() + amount, maxHealh.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user