To integrate the Supernova explosion mechanics from the deadlydisasters plugin into your existing RocketPlugin, we'll adapt and enhance your current implementation. This involves modifying the Rocket class to utilize Supernova-like explosions, defining multiple Supernova types, and updating configuration files accordingly.
Overview
- Extend
RocketType: Add Supernova-specific parameters to define different Supernova types.
- Update
config.yml: Define multiple Supernova rocket types with varying parameters.
- Modify
Rocket Class: Implement Supernova-like explosion mechanics within the Rocket lifecycle.
- Provide Complete Code: Ensure all related classes are updated to support the new functionality.
1. Extending RocketType
First, we'll enhance the RocketType class to include Supernova-specific parameters. This allows each rocket type to have unique explosion behaviors resembling Supernovas.
Updated RocketType.java
package com.yourname.rocketplugin;
import org.bukkit.Particle;
import org.bukkit.Sound;
/**
* Класс, представляющий тип ракеты.
*/
public class RocketType {
private final String name;
private final double power;
private final int range;
private final Particle launchParticle;
private final Sound launchSound;
private final Sound explosionSound;
private final Particle explosionParticle;
private final int successChance;
private final boolean optimized;
// Supernova-specific parameters
private final double explosionSize;
private final double particleMultiplier;
private final double fallSpeedMultiplier;
private final boolean flash;
private final Particle supernovaParticle;
private final Material[] explosionMaterials;
/**
* Конструктор типа ракеты.
*
* @param name Имя ракеты.
* @param power Сила взрыва.
* @param range Дальность полета.
* @param launchParticle Частица при запуске.
* @param launchSound Звук при запуске.
* @param explosionSound Звук взрыва.
* @param explosionParticle Частица при взрыве.
* @param successChance Шанс успешного запуска.
* @param optimized Флаг оптимизированного взрыва.
* @param explosionSize Размер взрыва суперновы.
* @param particleMultiplier Множитель для частиц суперновы.
* @param fallSpeedMultiplier Множитель скорости падения кристалла.
* @param flash Включение/отключение вспышки.
* @param supernovaParticle Тип частицы для суперновы.
* @param explosionMaterials Материалы для разрушения при супернове.
*/
public RocketType(String name, double power, int range, Particle launchParticle,
Sound launchSound, Sound explosionSound, Particle explosionParticle,
int successChance, boolean optimized,
double explosionSize, double particleMultiplier, double fallSpeedMultiplier,
boolean flash, Particle supernovaParticle, Material[] explosionMaterials) {
this.name = name;
this.power = power;
this.range = range;
this.launchParticle = launchParticle;
this.launchSound = launchSound;
this.explosionSound = explosionSound;
this.explosionParticle = explosionParticle;
this.successChance = successChance;
this.optimized = optimized;
this.explosionSize = explosionSize;
this.particleMultiplier = particleMultiplier;
this.fallSpeedMultiplier = fallSpeedMultiplier;
this.flash = flash;
this.supernovaParticle = supernovaParticle;
this.explosionMaterials = explosionMaterials;
}
// Getters for all fields
public String getName() {
return name;
}
public double getPower() {
return power;
}
public int getRange() {
return range;
}
public Particle getLaunchParticle() {
return launchParticle;
}
public Sound getLaunchSound() {
return launchSound;
}
public Sound getExplosionSound() {
return explosionSound;
}
public Particle getExplosionParticle() {
return explosionParticle;
}
public int getSuccessChance() {
return successChance;
}
public boolean isOptimized() {
return optimized;
}
public double getExplosionSize() {
return explosionSize;
}
public double getParticleMultiplier() {
return particleMultiplier;
}
public double getFallSpeedMultiplier() {
return fallSpeedMultiplier;
}
public boolean isFlash() {
return flash;
}
public Particle getSupernovaParticle() {
return supernovaParticle;
}
public Material[] getExplosionMaterials() {
return explosionMaterials;
}
}
Key Changes:
- Supernova Parameters: Added parameters like
explosionSize, particleMultiplier, fallSpeedMultiplier, flash, supernovaParticle, and explosionMaterials to manage Supernova-specific behaviors.
- Constructor: Updated to initialize these new fields.
2. Updating config.yml
We'll define multiple Supernova rocket types in the configuration file. Each type can be customized with different parameters to create diverse explosion effects.
Updated config.yml
# RocketPlugin Configuration
# Настройки суперновы
supernova:
# Размер взрыва суперновы по умолчанию
explosion_size: 200.0
# Множитель для количества частиц при расширении взрыва
particle_multiplier: 2.5
# Множитель скорости падения кристалла
fall_speed_multiplier: 1.5
# Включение/отключение вспышки
flash: true
# Тип частицы при взрыве суперновы
explosion_particle: EXPLOSION_NORMAL
# Материалы, используемые при разрушении блоков взрывом
explosion_materials:
OBSIDIAN: true
BLACK_CONCRETE: true
FIRE: true
END_STONE: true
# Настройки ракет
rockets:
SMALL_SUPERNOVA:
power: 50.0
range: 150
launchParticle: FLAME
launchSound: ENTITY_FIREWORK_ROCKET_LAUNCH
explosionSound: ENTITY_GENERIC_EXPLODE
explosionParticle: SMOKE_NORMAL
successChance: 90
optimized: false
# Supernova-specific parameters
explosionSize: 100.0
particleMultiplier: 1.5
fallSpeedMultiplier: 1.2
flash: true
supernovaParticle: CLOUD
explosionMaterials:
OBSIDIAN: true
BLACK_CONCRETE: true
FIRE: true
MEDIUM_SUPERNOVA:
power: 100.0
range: 300
launchParticle: EXPLOSION_NORMAL
launchSound: ENTITY_FIREWORK_ROCKET_LAUNCH
explosionSound: ENTITY_GENERIC_EXPLODE
explosionParticle: SMOKE_LARGE
successChance: 75
optimized: false
# Supernova-specific parameters
explosionSize: 200.0
particleMultiplier: 2.0
fallSpeedMultiplier: 1.5
flash: true
supernovaParticle: EXPLOSION_NORMAL
explosionMaterials:
OBSIDIAN: true
BLACK_CONCRETE: true
FIRE: true
END_STONE: true
LARGE_SUPERNOVA:
power: 200.0
range: 500
launchParticle: EXPLOSION_HUGE
launchSound: ENTITY_GENERIC_EXPLODE
explosionSound: ENTITY_GENERIC_EXPLODE
explosionParticle: EXPLOSION_HUGE
successChance: 60
optimized: false
# Supernova-specific parameters
explosionSize: 300.0
particleMultiplier: 3.0
fallSpeedMultiplier: 2.0
flash: true
supernovaParticle: EXPLOSION_HUGE
explosionMaterials:
OBSIDIAN: true
BLACK_CONCRETE: true
FIRE: true
END_STONE: true
DIAMOND_BLOCK: true
# Добавьте дополнительные типы супернов по необходимости
# SUPER_NUCLEAR:
# ...
# Рецепты крафта ракет
craftingRecipes:
SMALL_SUPERNOVA:
ingredients:
DIAMOND: 2
FIREWORK_ROCKET: 1
MEDIUM_SUPERNOVA:
ingredients:
DIAMOND: 3
FIREWORK_ROCKET: 2
LARGE_SUPERNOVA:
ingredients:
DIAMOND: 5
FIREWORK_ROCKET: 4
# Добавьте рецепты для дополнительных типов ракет
Key Changes:
- Rocket Types: Defined
SMALL_SUPERNOVA, MEDIUM_SUPERNOVA, and LARGE_SUPERNOVA with unique Supernova parameters.
- Supernova Parameters: Each rocket type includes
explosionSize, particleMultiplier, fallSpeedMultiplier, flash, supernovaParticle, and explosionMaterials.
- Crafting Recipes: Updated to match the new rocket types.
3. Modifying the Rocket Class
Next, we'll update the Rocket class to utilize the newly defined Supernova parameters during the explosion phase.
Updated Rocket.java
package com.yourname.rocketplugin;
import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.EnderCrystal;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
import java.util.Random;
/**
* Класс, представляющий ракету.
*/
public class Rocket {
protected final Player launcher;
protected final RocketType type;
protected final Location target;
protected final RocketPlugin plugin;
protected Location currentLocation;
protected double speed = 1.5; // Скорость полета ракеты
/**
* Конструктор ракеты.
*
* @param launcher Игрок, запустивший ракету.
* @param type Тип ракеты.
* @param target Целевая локация.
* @param plugin Главный плагин.
*/
public Rocket(Player launcher, RocketType type, Location target, RocketPlugin plugin) {
this.launcher = launcher;
this.type = type;
this.target = target;
this.plugin = plugin;
this.currentLocation = launcher.getEyeLocation().clone();
}
/**
* Запускает ракету.
*/
public void launch() {
final World world = this.launcher.getWorld();
if (world == null) {
this.launcher.sendMessage("§cОшибка: Мир не найден.");
return;
}
// Вспышка при запуске
world.spawnParticle(this.type.getLaunchParticle(), this.currentLocation, 20, 0.5, 0.5, 0.5, 0.05);
world.playSound(this.currentLocation, this.type.getLaunchSound(), 1.0F, 1.0F);
// Запуск ракеты
new BukkitRunnable() {
@Override
public void run() {
Vector direction = target.clone().subtract(currentLocation).toVector();
double distance = direction.length();
if (distance < type.getRange()) {
explode();
this.cancel();
} else {
direction = direction.normalize().multiply(speed);
currentLocation.add(direction);
world.spawnParticle(type.getLaunchParticle(), currentLocation, 5, 0.1, 0.1, 0.1, 0.02);
}
}
}.runTaskTimer(this.plugin, 0L, 1L);
}
/**
* Вызывает взрыв ракеты, интегрируя эффекты суперновы для мощных ракет.
*/
protected void explode() {
final World world = this.target.getWorld();
if (world == null) {
this.launcher.sendMessage("§cОшибка: Целевая локация не найдена.");
return;
}
// Определяем, является ли ракета суперновой
boolean isSupernova = this.type.getPower() >= plugin.getConfig().getDouble("supernova.explosion_size", 100.0);
if (isSupernova) {
performSupernova(world, target);
} else {
performNormalExplosion(world, target);
}
}
/**
* Выполняет обычный взрыв ракеты.
*
* @param world Мир, в котором происходит взрыв.
* @param explosionLocation Локация взрыва.
*/
private void performNormalExplosion(World world, Location explosionLocation) {
// Визуальные эффекты взрыва
world.spawnParticle(this.type.getExplosionParticle(), explosionLocation, 200, this.type.getPower(), this.type.getPower(), this.type.getPower(), 0.1);
world.playSound(explosionLocation, this.type.getExplosionSound(), 2.0F, 1.0F);
// Создание анимации расширяющегося взрыва
new BukkitRunnable() {
private double currentRadius = 0.0;
private final double maxRadius = type.getPower();
private final double step = 2.0;
@Override
public void run() {
if (currentRadius > maxRadius) {
this.cancel();
return;
}
// Спавн частиц по кругу взрыва
for (double angle = 0; angle < 360; angle += 10) {
double rad = Math.toRadians(angle);
double x = explosionLocation.getX() + currentRadius * Math.cos(rad);
double z = explosionLocation.getZ() + currentRadius * Math.sin(rad);
Location particleLoc = new Location(world, x, explosionLocation.getY(), z);
world.spawnParticle(Particle.EXPLOSION_NORMAL, particleLoc, 1);
}
currentRadius += step * type.getParticleMultiplier();
}
}.runTaskTimer(this.plugin, 0L, 2L); // Выполняется каждые 2 тика
}
/**
* Выполняет взрыв ракеты с эффектами суперновы.
*
* @param world Мир, в котором происходит взрыв.
* @param explosionLocation Локация взрыва.
*/
private void performSupernova(World world, Location explosionLocation) {
// Извлекаем Supernova-параметры из типа ракеты
double explosionSize = this.type.getExplosionSize();
double particleMultiplier = this.type.getParticleMultiplier();
double fallSpeedMultiplier = this.type.getFallSpeedMultiplier();
boolean flash = this.type.isFlash();
Particle explosionParticle = this.type.getSupernovaParticle();
Material[] explosionMaterials = this.type.getExplosionMaterials();
// Визуальные эффекты суперновы
world.spawnParticle(explosionParticle, explosionLocation, 500, explosionSize, explosionSize, explosionSize, 0.1);
world.playSound(explosionLocation, this.type.getExplosionSound(), 3.0F, 1.0F);
// Создание EnderCrystal для анимации падения (имитация суперновы)
EnderCrystal crystal = (EnderCrystal) world.spawn(explosionLocation, EnderCrystal.class);
try {
crystal.setShowingBottom(false);
} catch (NoSuchMethodError e) {
// Метод не поддерживается, пропускаем
plugin.getLogger().warning("Метод setShowBottom не поддерживается в текущей версии сервера.");
}
crystal.setBeamTarget(explosionLocation.clone().add(0, 50, 0)); // Направляем луч вверх
Vector fallVector = new Vector(0.0, -2.0 * fallSpeedMultiplier, 0.0); // Скорость падения
final double fallSpeedDecrease = 0.05; // Замедление падения
// Используем массив для хранения кристалла, чтобы изменять его внутри Runnable
final EnderCrystal[] crystalHolder = new EnderCrystal[]{crystal};
new BukkitRunnable() {
Location crystalLoc = explosionLocation.clone();
Random random = new Random();
@Override
public void run() {
// Обновление позиции кристалла
crystalLoc.add(fallVector);
if (fallVector.getY() < -0.5) {
fallVector.setY(fallVector.getY() + fallSpeedDecrease);
}
// Переспавн кристалла
crystalHolder[0].remove();
if (crystalLoc.getWorld() == null) {
this.cancel();
return;
}
crystalHolder[0] = (EnderCrystal) world.spawn(crystalLoc, EnderCrystal.class);
try {
crystalHolder[0].setShowingBottom(false);
} catch (NoSuchMethodError e) {
// Метод не поддерживается, пропускаем
plugin.getLogger().warning("Метод setShowBottom не поддерживается в текущей версии сервера.");
}
crystalHolder[0].setBeamTarget(explosionLocation.clone().add(0, 50, 0));
// Спавн частиц для анимации
world.spawnParticle(Particle.CLOUD, crystalLoc, 20, 0.5, 0.5, 0.5, 0.01);
world.spawnParticle(Particle.FLAME, crystalLoc, 20, 0.5, 0.5, 0.5, 0.01);
// Разрушение блока под кристаллом
Block blockBelow = crystalLoc.clone().subtract(0, 1, 0).getBlock();
if (blockBelow.getType() != Material.AIR && !Utils.isBlockImmune(blockBelow.getType()) && !Utils.isZoneProtected(blockBelow.getLocation())) {
blockBelow.setType(Material.AIR);
}
// Проверка близости к исходной локации для взрыва
if (crystalLoc.distance(explosionLocation) < 3.0) {
crystalHolder[0].remove();
this.cancel();
performSupernovaEffects(world, explosionLocation, explosionSize, particleMultiplier, explosionMaterials, flash);
}
}
}.runTaskTimer(this.plugin, 0L, 1L);
}
/**
* Создает эффекты суперновы после завершения анимации падения кристалла.
*
* @param world Мир, в котором происходит взрыв.
* @param explosionLocation Локация взрыва.
* @param explosionSize Размер суперновы.
* @param particleMultiplier Множитель для частиц.
* @param explosionMaterials Материалы для разрушения.
* @param flash Включение вспышки.
*/
private void performSupernovaEffects(World world, Location explosionLocation,
double explosionSize, double particleMultiplier,
Material[] explosionMaterials, boolean flash) {
Random random = new Random();
// Расширяющийся взрыв суперновы
new BukkitRunnable() {
private double currentRadius = 0.0;
private final double maxRadius = explosionSize;
private final double step = 5.0;
@Override
public void run() {
if (currentRadius > maxRadius) {
this.cancel();
return;
}
// Спавн частиц по кругу суперновы
for (double angle = 0; angle < 360; angle += 10) {
double rad = Math.toRadians(angle);
double x = explosionLocation.getX() + currentRadius * Math.cos(rad);
double z = explosionLocation.getZ() + currentRadius * Math.sin(rad);
Location particleLoc = new Location(world, x, explosionLocation.getY(), z);
world.spawnParticle(Rocket.this.type.getSupernovaParticle(), particleLoc, 1);
}
// Разрушение блоков в радиусе
for (Block block : Utils.getBlocksInRadius(explosionLocation, currentRadius)) {
if (block.getType() != Material.AIR && !Utils.isBlockImmune(block.getType()) && !Utils.isZoneProtected(block.getLocation())) {
block.setType(explosionMaterials[random.nextInt(explosionMaterials.length)]);
}
}
// Влияние на сущности в радиусе
for (Entity entity : world.getNearbyEntities(explosionLocation, currentRadius, currentRadius, currentRadius)) {
if (entity instanceof Player) {
Player player = (Player) entity;
player.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 1.0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 1, false, false));
}
if (entity instanceof LivingEntity) {
Utils.pureDamageEntity((LivingEntity) entity, 20.0, "RocketPlugin-supernova", true, EntityDamageEvent.DamageCause.EXPLOSION);
}
}
currentRadius += step * particleMultiplier;
}
}.runTaskTimer(this.plugin, 0L, 2L); // Выполняется каждые 2 тика
}
}
Key Changes:
-
Supernova Detection:
- The
explode() method now checks if the rocket is a Supernova based on its power relative to the explosion_size from the config.
-
Supernova Explosion (performSupernova):
- Visual Effects: Particles and sounds are spawned to mimic a Supernova.
- EnderCrystal Animation: An
EnderCrystal is spawned and animated to fall, creating particle effects and destroying blocks beneath it.
- Final Explosion: Once the crystal is close enough to the explosion location, it triggers the Supernova effects.
-
Supernova Effects (performSupernovaEffects):
- Particle Spawning: Expanding particles to visualize the explosion.
- Block Transformation: Blocks within the explosion radius are either set to
AIR or transformed into predefined materials.
- Entity Interaction: Players receive blindness, and all nearby
LivingEntity instances take pure damage.
-
Randomness and Safety:
- Incorporated randomness for block transformations.
- Added checks to prevent modifications in protected zones or immune blocks.
4. Utility Class Adjustments
Ensure your Utils class includes necessary methods for handling block operations and entity damage.
Updated Utils.java
package com.yourname.rocketplugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import java.util.HashSet;
import java.util.Set;
/**
* Вспомогательный класс с утилитными методами.
*/
public class Utils {
/**
* Проверяет, является ли блок устойчивым к взрыву.
*
* @param material Тип материала.
* @return true, если блок устойчив.
*/
public static boolean isBlockImmune(Material material) {
// Добавьте здесь логику для блоков, устойчивых к взрывам
Set<Material> immuneMaterials = new HashSet<>();
immuneMaterials.add(Material.BEDROCK);
immuneMaterials.add(Material.ENDER_CHEST);
immuneMaterials.add(Material.ANVIL);
immuneMaterials.add(Material.GOLD_BLOCK);
immuneMaterials.add(Material.DIAMOND_BLOCK);
immuneMaterials.add(Material.EMERALD_BLOCK);
// Добавьте другие материалы по необходимости
return immuneMaterials.contains(material);
}
/**
* Проверяет, защищена ли зона для данного местоположения.
*
* @param location Локация.
* @return true, если зона защищена.
*/
public static boolean isZoneProtected(Location location) {
// Реализуйте проверку защищенных зон
// Без сторонних зависимостей всегда возвращаем false
return false;
}
/**
* Получает все блоки в заданном радиусе.
*
* @param center Локация центра.
* @param radius Радиус.
* @return Set блоков.
*/
public static Set<Block> getBlocksInRadius(Location center, double radius) {
Set<Block> blocks = new HashSet<>();
int r = (int) Math.ceil(radius);
for (int x = center.getBlockX() - r; x <= center.getBlockX() + r; x++) {
for (int y = center.getBlockY() - r; y <= center.getBlockY() + r; y++) {
for (int z = center.getBlockZ() - r; z <= center.getBlockZ() + r; z++) {
Block block = center.getWorld().getBlockAt(x, y, z);
double distance = center.distance(block.getLocation().add(0.5, 0.5, 0.5));
if (distance <= radius) {
blocks.add(block);
}
}
}
}
return blocks;
}
/**
* Наносят чистый урон сущности без отскока.
*
* @param entity Сущность, получающая урон.
* @param damage Урон.
* @param damageType Тип урона (строка для логирования или других целей).
* @param ignoreArmor Игнорировать броню.
* @param damageCause Тип причины урона.
*/
public static void pureDamageEntity(LivingEntity entity, double damage, String damageType, boolean ignoreArmor, EntityDamageEvent.DamageCause damageCause) {
// Создаем кастомное событие для урона, если необходимо
EntityDamageEvent event = new EntityDamageEvent(entity, damageCause, damage);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
entity.damage(damage, null); // null означает, что урон приходит не от какого-либо источника
}
}
}
Key Points:
- isBlockImmune: Defines blocks that are immune to explosion effects.
- isZoneProtected: Placeholder for zone protection logic. Currently returns
false.
- getBlocksInRadius: Efficiently retrieves blocks within a specified radius.
- pureDamageEntity: Applies damage to entities without knockback and respects event cancellation.
5. Additional Class Adjustments
Ensure other classes like RocketCommand, RocketManager, and StatsManager are compatible with the new Supernova types. Typically, these classes might not require significant changes, but ensure that they handle the new rocket types appropriately.
Example: Updating RocketManager.java (Partial)
Ensure that RocketManager correctly loads the new rocket types with Supernova parameters.
package com.yourname.rocketplugin;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* Класс управления ракетами и ПВО.
*/
public class RocketManager {
private final RocketPlugin plugin;
private StatsManager statsManager;
private final Random random;
private final Map<String, RocketType> rocketTypes;
/**
* Конструктор RocketManager.
*
* @param plugin Главный плагин.
*/
public RocketManager(RocketPlugin plugin) {
this.plugin = plugin;
this.random = new Random();
this.rocketTypes = new HashMap<>();
loadRocketTypes();
}
/**
* Устанавливает ссылку на StatsManager.
*
* @param statsManager Экземпляр StatsManager.
*/
public void setStatsManager(StatsManager statsManager) {
this.statsManager = statsManager;
}
/**
* Загружает типы ракет из config.yml.
*/
public void loadRocketTypes() {
FileConfiguration config = plugin.getConfig();
ConfigurationSection rocketsSection = config.getConfigurationSection("rockets");
if (rocketsSection == null) {
plugin.getLogger().severe("§cРаздел 'rockets' не найден в config.yml! Плагин отключен.");
plugin.getServer().getPluginManager().disablePlugin(plugin);
return;
}
for (String key : rocketsSection.getKeys(false)) {
ConfigurationSection rocketSection = rocketsSection.getConfigurationSection(key);
if (rocketSection == null) continue;
double power = rocketSection.getDouble("power");
int range = rocketSection.getInt("range");
String launchParticleStr = rocketSection.getString("launchParticle", "FLAME");
String launchSoundStr = rocketSection.getString("launchSound", "ENTITY_FIREWORK_ROCKET_LAUNCH");
String explosionSoundStr = rocketSection.getString("explosionSound", "ENTITY_GENERIC_EXPLODE");
String explosionParticleStr = rocketSection.getString("explosionParticle", "SMOKE_NORMAL");
int successChance = rocketSection.getInt("successChance", 50);
boolean optimized = rocketSection.getBoolean("optimized", false);
// Supernova-specific parameters
double explosionSize = rocketSection.getDouble("explosionSize", config.getDouble("supernova.explosion_size", 200.0));
double particleMultiplier = rocketSection.getDouble("particleMultiplier", config.getDouble("supernova.particle_multiplier", 2.5));
double fallSpeedMultiplier = rocketSection.getDouble("fallSpeedMultiplier", config.getDouble("supernova.fall_speed_multiplier", 1.5));
boolean flash = rocketSection.getBoolean("flash", config.getBoolean("supernova.flash", true));
String supernovaParticleStr = rocketSection.getString("supernovaParticle", "EXPLOSION_NORMAL");
ConfigurationSection materialsSection = rocketSection.getConfigurationSection("explosionMaterials");
Material[] explosionMaterials = new Material[]{Material.OBSIDIAN, Material.BLACK_CONCRETE, Material.FIRE}; // Default
if (materialsSection != null) {
explosionMaterials = materialsSection.getKeys(false).stream()
.map(matName -> {
try {
return Material.valueOf(matName.toUpperCase());
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("§cНеизвестный материал '" + matName + "' в настройках суперновы для ракеты '" + key + "'.");
return null;
}
})
.filter(mat -> mat != null)
.toArray(Material[]::new);
}
Particle launchParticle;
Sound launchSound;
Sound explosionSound;
Particle explosionParticle;
Particle supernovaParticle;
try {
launchParticle = Particle.valueOf(launchParticleStr);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("§cНеизвестный тип частицы запуска '" + launchParticleStr + "' для ракеты '" + key + "'. Используется FLAME.");
launchParticle = Particle.FLAME;
}
try {
launchSound = Sound.valueOf(launchSoundStr);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("§cНеизвестный звук запуска '" + launchSoundStr + "' для ракеты '" + key + "'. Используется ENTITY_FIREWORK_ROCKET_LAUNCH.");
launchSound = Sound.ENTITY_FIREWORK_ROCKET_LAUNCH;
}
try {
explosionSound = Sound.valueOf(explosionSoundStr);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("§cНеизвестный звук взрыва '" + explosionSoundStr + "' для ракеты '" + key + "'. Используется ENTITY_GENERIC_EXPLODE.");
explosionSound = Sound.ENTITY_GENERIC_EXPLODE;
}
try {
explosionParticle = Particle.valueOf(explosionParticleStr);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("§cНеизвестный тип частицы взрыва '" + explosionParticleStr + "' для ракеты '" + key + "'. Используется SMOKE_NORMAL.");
explosionParticle = Particle.SMOKE_NORMAL;
}
try {
supernovaParticle = Particle.valueOf(supernovaParticleStr);
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("§cНеизвестный тип частицы суперновы '" + supernovaParticleStr + "' для ракеты '" + key + "'. Используется EXPLOSION_NORMAL.");
supernovaParticle = Particle.EXPLOSION_NORMAL;
}
RocketType rocketType = new RocketType(
key,
power,
range,
launchParticle,
launchSound,
explosionSound,
explosionParticle,
successChance,
optimized,
explosionSize,
particleMultiplier,
fallSpeedMultiplier,
flash,
supernovaParticle,
explosionMaterials
);
rocketTypes.put(key.toUpperCase(), rocketType);
}
plugin.getLogger().info("§aЗагружено " + rocketTypes.size() + " типов ракет.");
}
/**
* Получает тип ракеты по имени.
*
* @param name Имя ракеты.
* @return RocketType или null, если не найден.
*/
public RocketType getRocketType(String name) {
return rocketTypes.get(name.toUpperCase());
}
/**
* Возвращает все загруженные типы ракет.
*
* @return Карта типов ракет.
*/
public Map<String, RocketType> getAllRocketTypes() {
return rocketTypes;
}
/**
* Запускает ракету.
*
* @param player Игрок, запустивший ракету.
* @param type Тип ракеты.
* @param target Целевая локация.
* @param delay Задержка запуска в секундах.
*/
public void launchRocket(final Player player, final RocketType type, final Location target, final int delay) {
if (!target.getWorld().getName().equalsIgnoreCase("P_Drilla")) { // Измените на нужное название мира
player.sendMessage("§cРакеты могут взрываться только в мире P_Drilla.");
return;
}
if (!this.statsManager.hasRockets(player, type)) {
player.sendMessage("§cУ вас нет ракет типа " + type.getName() + "!");
return;
}
this.statsManager.useRocket(player, type);
if (delay > 0) {
player.sendMessage("§eЗапуск ракеты через " + delay + " секунда(ы).");
new BukkitRunnable() {
private int secondsLeft = delay;
@Override
public void run() {
if (secondsLeft <= 0) {
this.cancel();
boolean success = checkLaunchSuccess(type);
if (success) {
Rocket rocket = new Rocket(player, type, target, plugin);
rocket.launch();
player.sendMessage("§aРакета успешно запущена!");
} else {
player.sendMessage("§cРакета не смогла достичь цели и не взорвалась.");
}
} else {
player.sendMessage("§eЗапуск ракеты через " + secondsLeft + " секунда(ы).");
secondsLeft--;
}
}
}.runTaskTimer(plugin, 0L, 20L); // Запуск каждую секунду
} else {
boolean success = checkLaunchSuccess(type);
if (success) {
Rocket rocket = new Rocket(player, type, target, plugin);
rocket.launch();
player.sendMessage("§aРакета успешно запущена!");
} else {
player.sendMessage("§cРакета не смогла достичь цели и не взорвалась.");
}
}
}
/**
* Проверяет вероятность успешного запуска ракеты.
*
* @param type Тип ракеты.
* @return true, если ракета успешно запущена.
*/
private boolean checkLaunchSuccess(RocketType type) {
int chance = type.getSuccessChance();
int roll = random.nextInt(100) + 1;
return roll <= chance;
}
}
Key Changes:
-
Supernova Parameters:
- Extracted Supernova-specific parameters from
RocketType.
- Configured explosion size, particle multiplier, fall speed multiplier, flash effect, supernova particles, and explosion materials.
-
Supernova Explosion (performSupernova):
- Visuals & Sound: Spawn particles and play sounds to simulate a Supernova.
- EnderCrystal Animation: Mimic the falling crystal animation.
- Final Effects: Trigger the expanding explosion with blocks transformed based on defined materials and apply effects to entities.
-
Safety Checks:
- Ensure that operations like block modification and entity damage respect protections and immunities.
6. Ensuring Command Compatibility
Ensure that your command handling allows users to launch the new Supernova rocket types. With the updated RocketCommand class, users can specify which Supernova rocket to launch.
Example: RocketCommand.java (Partial)
// Within handleLaunch method
String typeName = args[1].toUpperCase();
RocketType type = rocketManager.getRocketType(typeName);
if (type == null) {
player.sendMessage(ChatColor.RED + "§cНеверный тип ракеты. Используйте /rocket для просмотра доступных типов.");
return;
}
// Continue as before...
Key Points:
- Users can launch any defined Supernova rocket type by specifying its name.
- Ensure that tab completion (
RocketTabCompleter) includes the new Supernova types.
7. Final Steps
- Reload Plugin: After making these changes, reload or restart your server to apply the updates.
- Testing: Test each Supernova rocket type to ensure that explosions behave as expected.
- Adjust Configurations: Modify the configuration parameters as needed to fine-tune the explosion effects.
Complete Updated Code
Below are all the updated classes and configuration files necessary to integrate Supernova-like explosions into your RocketPlugin.
RocketType.java
(As provided above.)
Rocket.java
(As provided above.)
Utils.java
(As provided above.)
config.yml
(As provided above.)
RocketManager.java
(As provided above.)
RocketCommand.java
Ensure that RocketCommand handles the new rocket types seamlessly.
RocketPlugin.java
Ensure that RocketManager and StatsManager are properly initialized.
package com.yourname.rocketplugin;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Главный класс плагина RocketPlugin.
*/
public class RocketPlugin extends JavaPlugin {
private static RocketPlugin instance;
private RocketManager rocketManager;
private StatsManager statsManager;
public RocketPlugin() { }
/**
* Возвращает экземпляр плагина.
*
* @return Экземпляр RocketPlugin.
*/
public static RocketPlugin getInstance() {
return instance;
}
public RocketManager getRocketManager() {
return rocketManager;
}
public StatsManager getStatsManager() {
return statsManager;
}
@Override
public void onEnable() {
instance = this;
this.saveDefaultConfig();
// Инициализация RocketManager
this.rocketManager = new RocketManager(this);
// Инициализация StatsManager с RocketManager
this.statsManager = new StatsManager(this, this.rocketManager);
// Установка StatsManager в RocketManager
this.rocketManager.setStatsManager(this.statsManager);
// Загрузка статистики
this.statsManager.load();
// Регистрация команд
PluginCommand rocketCommand = this.getCommand("rocket");
if (rocketCommand != null) {
rocketCommand.setExecutor(new RocketCommand(this.rocketManager, this.statsManager, this));
rocketCommand.setTabCompleter(new RocketTabCompleter(this));
} else {
this.getLogger().severe("§cНе удалось зарегистрировать команду 'rocket'. Проверьте plugin.yml.");
this.setEnabled(false);
return;
}
// Регистрация событий
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(new RocketListener(this.rocketManager, this), this);
this.getLogger().info("§aRocketPlugin был включен!");
}
@Override
public void onDisable() {
if (this.statsManager != null) {
this.statsManager.save();
}
this.getLogger().info("§cRocketPlugin был отключен!");
}
}
plugin.yml
Ensure that plugin.yml aligns with the new command and permissions.
name: RocketPlugin
version: 1.0
main: com.yourname.rocketplugin.RocketPlugin
api-version: 1.16
commands:
rocket:
description: Управление ракетами.
usage: /rocket <launch|give|stats|reload|craft>
aliases: [rk]
permissions:
rocketplugin.use:
description: Разрешение на использование команд RocketPlugin.
default: true
rocketplugin.give:
description: Разрешение на выдачу ракет другим игрокам.
default: op
rocketplugin.reload:
description: Разрешение на перезагрузку конфигурации плагина.
default: op
RocketListener.java
Ensure that event listeners remain functional.
package com.yourname.rocketplugin;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
/**
* Класс слушателя событий взрыва и ПВО.
*/
public class RocketListener implements Listener {
private final RocketManager rocketManager;
private final RocketPlugin plugin;
/**
* Конструктор RocketListener.
*
* @param rocketManager Менеджер ракет и ПВО.
* @param plugin Главный плагин.
*/
public RocketListener(RocketManager rocketManager, RocketPlugin plugin) {
this.rocketManager = rocketManager;
this.plugin = plugin;
}
/**
* Событие взрыва сущности.
*
* @param event Событие.
*/
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
World world = event.getEntity().getWorld();
if (!world.getName().equalsIgnoreCase("P_Drilla")) { // Измените на нужное название мира
event.setCancelled(true);
return;
}
// Если взрыв вызван ракетою, разрешаем, иначе отменяем
// Предполагается, что только ракеты запускают взрывы, иначе блокировать
// В текущей реализации Rocket класс сам управляет взрывами, поэтому дублировать проверку не требуется
// Можно оставить как есть или добавить дополнительные проверки
}
}
Conclusion
By following the above steps, you've successfully integrated Supernova-like explosion mechanics into your RocketPlugin. This integration allows for diverse and visually impressive explosions, enhancing gameplay experiences on your Minecraft server. Ensure thorough testing of each rocket type to fine-tune parameters and maintain server performance.
Feel free to expand upon this foundation by adding more rocket types, refining explosion effects, and integrating advanced features as needed.