first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package de.winniepat.SMPPlugin.bloodmoon;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class BloodmoonCommand implements CommandExecutor {
|
||||
|
||||
private final BloodmoonManager manager;
|
||||
|
||||
public BloodmoonCommand(BloodmoonManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!sender.hasPermission("bloodmoon.toggle")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to do that.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (manager.isActive()) {
|
||||
manager.endBloodmoon();
|
||||
sender.sendMessage(ChatColor.GRAY + "☀ Bloodmoon ended.");
|
||||
} else {
|
||||
manager.startBloodmoon();
|
||||
sender.sendMessage(ChatColor.RED + "☠ Bloodmoon started.");
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package de.winniepat.SMPPlugin.bloodmoon;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BloodmoonListener implements Listener {
|
||||
|
||||
private final BloodmoonManager manager;
|
||||
private final JavaPlugin plugin;
|
||||
private final Random random = new Random();
|
||||
|
||||
public BloodmoonListener(BloodmoonManager manager, JavaPlugin plugin) {
|
||||
this.manager = manager;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBedEnter(PlayerBedEnterEvent event) {
|
||||
if (manager.isActive()) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You cannot sleep during a Bloodmoon!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMobSpawn(CreatureSpawnEvent event) {
|
||||
if (!manager.isActive()) return;
|
||||
|
||||
LivingEntity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof Zombie z && z.isBaby()) return;
|
||||
|
||||
if (random.nextInt(100) < 20) {
|
||||
spawnBoss(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof Creeper creeper) {
|
||||
creeper.setExplosionRadius(6);
|
||||
if (random.nextInt(100) < 30) {
|
||||
creeper.setPowered(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||
entity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(
|
||||
entity.getAttribute(Attribute.MAX_HEALTH).getBaseValue() * 1.5
|
||||
);
|
||||
entity.setHealth(entity.getAttribute(Attribute.MAX_HEALTH).getBaseValue());
|
||||
}
|
||||
|
||||
if (entity.getAttribute(Attribute.ATTACK_DAMAGE) != null) {
|
||||
entity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(
|
||||
entity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue() + 2
|
||||
);
|
||||
}
|
||||
|
||||
if (entity.getAttribute(Attribute.MOVEMENT_SPEED) != null) {
|
||||
entity.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(
|
||||
entity.getAttribute(Attribute.MOVEMENT_SPEED).getBaseValue() * 1.2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnBoss(LivingEntity entity) {
|
||||
if (!(entity instanceof Zombie || entity instanceof Skeleton || entity instanceof Husk || entity instanceof Drowned))
|
||||
return;
|
||||
|
||||
entity.getPersistentDataContainer().set(
|
||||
new NamespacedKey(plugin, "bloodmoon_boss"),
|
||||
PersistentDataType.BYTE,
|
||||
(byte) 1
|
||||
);
|
||||
|
||||
entity.setCustomName(ChatColor.DARK_RED + "Blood Knight");
|
||||
entity.setCustomNameVisible(true);
|
||||
|
||||
if (entity instanceof Zombie || entity instanceof Husk || entity instanceof Drowned) {
|
||||
entity.getEquipment().setHelmet(createItem(Material.DIAMOND_HELMET, "Blood Helmet"));
|
||||
entity.getEquipment().setChestplate(createItem(Material.DIAMOND_CHESTPLATE, "Blood Chestplate"));
|
||||
entity.getEquipment().setLeggings(createItem(Material.DIAMOND_LEGGINGS, "Blood Leggings"));
|
||||
entity.getEquipment().setBoots(createItem(Material.DIAMOND_BOOTS, "Blood Boots"));
|
||||
entity.getEquipment().setItemInMainHand(createItem(Material.DIAMOND_SWORD, "Blood Blade"));
|
||||
} else if (entity instanceof Skeleton) {
|
||||
entity.getEquipment().setHelmet(createItem(Material.DIAMOND_HELMET, "Blood Helmet"));
|
||||
entity.getEquipment().setChestplate(createItem(Material.NETHERITE_CHESTPLATE, "Blood Chestplate"));
|
||||
entity.getEquipment().setItemInMainHand(createItem(Material.BOW, "Blood Bow"));
|
||||
}
|
||||
|
||||
entity.getEquipment().setHelmetDropChance(0.001f);
|
||||
entity.getEquipment().setChestplateDropChance(0.001f);
|
||||
entity.getEquipment().setLeggingsDropChance(0.001f);
|
||||
entity.getEquipment().setBootsDropChance(0.001f);
|
||||
entity.getEquipment().setItemInMainHandDropChance(0.001f);
|
||||
|
||||
if (entity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||
entity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(80);
|
||||
entity.setHealth(80);
|
||||
}
|
||||
if (entity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||
entity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(12);
|
||||
}
|
||||
if (entity.getAttribute(Attribute.MOVEMENT_SPEED) != null) {
|
||||
entity.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(0.35);
|
||||
}
|
||||
|
||||
startParticleEffect(entity);
|
||||
}
|
||||
|
||||
private ItemStack createItem(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(ChatColor.RED + name);
|
||||
meta.addEnchant(Enchantment.PROTECTION, 2, true);
|
||||
meta.addEnchant(Enchantment.UNBREAKING, 3, true);
|
||||
meta.addEnchant(Enchantment.SHARPNESS, 2, true);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private void startParticleEffect(LivingEntity entity) {
|
||||
new BukkitRunnable() {
|
||||
int ticks = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (entity == null || entity.isDead() || !entity.isValid()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
entity.getWorld().spawnParticle(
|
||||
Particle.DUST,
|
||||
entity.getLocation().add(0, 1, 0),
|
||||
8,
|
||||
0.3, 0.5, 0.3,
|
||||
0,
|
||||
new Particle.DustOptions(Color.RED, 1.5f)
|
||||
);
|
||||
|
||||
if ((ticks += 5) > 20 * 300) cancel();
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 5L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package de.winniepat.SMPPlugin.bloodmoon;
|
||||
|
||||
import de.winniepat.SMPPlugin.blackmarket.BlackMarketManager;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BloodmoonManager {
|
||||
private final JavaPlugin plugin;
|
||||
private boolean active = false;
|
||||
private BossBar bloodmoonBar;
|
||||
private int durationTicks = 20 * 60 * 8;
|
||||
private int ticksElapsed = 0;
|
||||
private BukkitRunnable task;
|
||||
|
||||
public BloodmoonManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void startBloodmoon() {
|
||||
if (active) return;
|
||||
active = true;
|
||||
Bukkit.broadcastMessage(ChatColor.DARK_RED + "☠ The Bloodmoon has risen... Be wary!");
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.sendTitle(ChatColor.RED + "Bloodmoon", ChatColor.DARK_RED + "Mobs are stronger tonight!", 10, 100, 20);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 60 * 8, 1, false, false, false));
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0f, 1.0f);
|
||||
|
||||
player.spawnParticle(Particle.DUST, player.getLocation().add(0, 10, 0), 100,5, 5, 5, 0, new Particle.DustOptions(Color.RED, 2));
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (active) {
|
||||
player.spawnParticle(Particle.DUST, player.getLocation().add(
|
||||
Math.random() * 10 - 5, Math.random() * 5, Math.random() * 10 - 5),
|
||||
5, 0, 0, 0, 0, new Particle.DustOptions(Color.RED, 1));
|
||||
}
|
||||
}
|
||||
}, 0L, 1L);
|
||||
|
||||
bloodmoonBar = Bukkit.createBossBar("§4🌕 Bloodmoon Night", BarColor.RED, BarStyle.SEGMENTED_10);
|
||||
bloodmoonBar.setProgress(1.0);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
bloodmoonBar.addPlayer(player);
|
||||
}
|
||||
|
||||
task = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ticksElapsed += 20;
|
||||
double progress = Math.max(0, 1.0 - (double) ticksElapsed / durationTicks);
|
||||
bloodmoonBar.setProgress(progress);
|
||||
|
||||
if (ticksElapsed >= durationTicks) {
|
||||
endBloodmoon();
|
||||
}
|
||||
}
|
||||
};
|
||||
task.runTaskTimer(plugin, 20L, 20L);
|
||||
|
||||
}
|
||||
|
||||
public void endBloodmoon() {
|
||||
if (!active) return;
|
||||
active = false;
|
||||
|
||||
Bukkit.broadcastMessage(ChatColor.GRAY + "☀ The Bloodmoon has ended. It's safe again.");
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.sendTitle(ChatColor.YELLOW + "☀", ChatColor.GREEN + "Bloodmoon ended!", 10, 100, 20);
|
||||
}
|
||||
NamespacedKey key = new NamespacedKey(plugin, "bloodmoon_boss");
|
||||
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (LivingEntity entity : world.getLivingEntities()) {
|
||||
if (entity.getPersistentDataContainer().has(key, PersistentDataType.BYTE)) {
|
||||
entity.getWorld().playSound(entity.getLocation(), Sound.ENTITY_WITHER_DEATH, 1f, 0.5f);
|
||||
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (new Random().nextInt(100) < 5) {
|
||||
//new BlackMarketManager(plugin).spawnMarket();
|
||||
}
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
if (bloodmoonBar != null) {
|
||||
bloodmoonBar.removeAll();
|
||||
bloodmoonBar = null;
|
||||
}
|
||||
|
||||
ticksElapsed = 0;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package de.winniepat.SMPPlugin.bloodmoon;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BloodmoonTask {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final BloodmoonManager manager;
|
||||
|
||||
private boolean checkedThisNight = false;
|
||||
|
||||
public BloodmoonTask(JavaPlugin plugin, BloodmoonManager manager) {
|
||||
this.plugin = plugin;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
long time = world.getTime();
|
||||
if (time >= 13000 && time <= 13100) {
|
||||
if (!checkedThisNight) {
|
||||
checkedThisNight = true;
|
||||
|
||||
if (new Random().nextInt(100) < 5) {
|
||||
manager.startBloodmoon();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (time >= 0 && time < 1000) {
|
||||
if (manager.isActive()) {
|
||||
manager.endBloodmoon();
|
||||
}
|
||||
checkedThisNight = false;
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 100L);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user