Skip to content

Commit

Permalink
4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Genife authored and Genife committed Apr 24, 2023
1 parent 16cd38f commit 468ae7a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>AdventBombs</groupId>
<artifactId>AdventBombs</artifactId>
<version>4.1</version>
<version>4.2</version>
<packaging>jar</packaging>

<name>AdventBombs</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void launchNuclearRocket() {
World senderWorld = rocketSender.getWorld();
Location targetLocation = senderWorld.getHighestBlockAt(cordsX, cordsZ).getLocation();

RocketRunnable task = new RocketRunnable(new NuclearRocket(rocketSender, rocketType, targetLocation, explosionPower, 24000));
RocketRunnable task = new RocketRunnable(new NuclearRocket(rocketSender, rocketType, targetLocation, explosionPower));
task.runTaskTimer(instance, 0L, 0L);
}

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/genife/adventbombs/Managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
public class ConfigManager {
public static int DISTANCE_TO_MOVE_ROCKET_WITH_Y;
public static int FLYING_ROCKET_HEIGHT;
public static double FLYING_ROCKET_SPEED;
public static double MOVE_UP_SPEED;
public static double MOVE_WITH_Y_SPEED;
public static int MAX_FLY_DURATION;
public static String NUCLEAR_START_PASS;
public static String SCULK_START_PASS;
public static Integer ROCKET_USAGE_COOLDOWN;
Expand Down Expand Up @@ -79,6 +83,10 @@ public void loadConfig() {

config.addDefault("rockets.distance_to_move_with_y", 340);
config.addDefault("rockets.flying_height", 250);
config.addDefault("rockets.flying_speed", 5.8);
config.addDefault("rockets.move_up_speed", 0.8);
config.addDefault("rockets.move_with_y_speed", 0.8);
config.addDefault("rockets.max_fly_duration", 1200);
config.addDefault("rockets.nuclear.password", "nuclear_start_pass");
config.addDefault("rockets.sculk.password", "sculk_start_pass");
config.addDefault("rockets.cooldown", 5);
Expand Down Expand Up @@ -118,7 +126,7 @@ public void loadConfig() {
config.addDefault("messages.alarm.start_broadcast", "§cВНИМАНИЕ! ОБЪЯВЛЕНА ВОЗДУШНАЯ ТРЕВОГА! ВСЕМ ПРОЙТИ В УКРЫТИЕ!");
config.addDefault("messages.alarm.stop_broadcast", "§aВнимание! Отбой воздушной тревоги! Все ракеты достигли целей!");
config.addDefault("messages.alarm.nuclear.detonated", "§fМежконтинентальная ядерная ракета произвела детонацию!");
config.addDefault("messages.alarm.sculk.detonated", "§fСкалковая ракета достигла цели!");
config.addDefault("messages.alarm.sculk.detonated", "§fСкалковая ракета произвела детонацию!");

config.addDefault("messages.effects.acid_rain.start", "§fСообщается о начале §aкислотного дождя §fв мире {world}. Все в укрытия!");
config.addDefault("messages.effects.acid_rain.stop", "§aКислотный дождь §fзакончился в мире {world}. Можно выходить из укрытий, будьте осторожны!");
Expand All @@ -139,13 +147,17 @@ public void loadConfig() {
config.addDefault("sounds.alarm.sound", "minecraft:my_sounds.alarm_sound");

config.options().copyDefaults(true);
config.options().setHeader(List.of("На данный момент, конфиг в стадии тестирования. Репорти ошибки, если найдёшь", "Все параметры, которые так или иначе связаны со временем указывай в СЕКУНДАХ!", "Названия звуков бери из ресурс пака или игры"));
config.options().setHeader(List.of("На данный момент, конфиг в стадии тестирования. Репорти ошибки, если найдёшь", "Все параметры, которые так или иначе связаны со временем указывай в СЕКУНДАХ!", "Названия звуков бери из ресурс пака или игры", "MOVE WITH Y - это когда ракета снижается. Но бывает так, что цель находится выше самой ракеты, потому говорить, что она снижается - не корректно"));
instance.saveConfig();
}

private void loadValues() {
DISTANCE_TO_MOVE_ROCKET_WITH_Y = config.getInt("rockets.distance_to_move_with_y");
FLYING_ROCKET_HEIGHT = config.getInt("rockets.flying_height");
FLYING_ROCKET_SPEED = config.getDouble("rockets.flying_speed");
MOVE_UP_SPEED = config.getDouble("rockets.move_up_speed");
MOVE_WITH_Y_SPEED = config.getDouble("rockets.move_with_y_speed");
MAX_FLY_DURATION = config.getInt("rockets.max_fly_duration");
NUCLEAR_START_PASS = config.getString("rockets.nuclear.password");
SCULK_START_PASS = config.getString("rockets.sculk.password");
ROCKET_USAGE_COOLDOWN = config.getInt("rockets.cooldown");
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/genife/adventbombs/Rockets/NuclearRocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class NuclearRocket extends Rocket implements Selfguided, Soared, Exploda
private final int explosionPower;
private final AdventBombs instance = AdventBombs.getInstance();

public NuclearRocket(Player rocketSender, String rocketType, Location targetLocation, int explosionPower, int maxBeam) {
super(rocketSender, targetLocation, maxBeam);
public NuclearRocket(Player rocketSender, String rocketType, Location targetLocation, int explosionPower) {
super(rocketSender, targetLocation);
this.explosionPower = explosionPower;
this.rocketType = rocketType;
}
Expand All @@ -42,13 +42,13 @@ public void move() {
double distanceToTargetLoc = getRocketLocation().distance(getTargetLocation());

// проверка на совпадение одно из условий для детонации
if ((reachMaxBeam() || inBlock() || (distanceToTargetLoc <= 1 && isDown())) && getBeam() > MIN_BEAM) {
if ((reachMaxDuration() || inBlock() || (distanceToTargetLoc <= 1 && isDown())) && getDuration() > MIN_BEAM) {
explode();
return;
}

// движение ракеты, логика в зависимости от высоты
if (getBeam() == 0) {
if (getDuration() == 0) {
getRocketLocation().setPitch(-90);
new CreateSound(ROCKET_START_FLYING_SOUND, 200, getRocketLocation());

Expand All @@ -74,7 +74,7 @@ public void move() {
if (getState() != RocketState.FLYING) {
setState(RocketState.FLYING);
}
getRocketLocation().add(findPath(false).multiply(5.8));
getRocketLocation().add(findPath(false).multiply(FLYING_ROCKET_SPEED));
}
} else if (distanceToTargetLoc < DISTANCE_TO_MOVE_ROCKET_WITH_Y) {
new CreateSound(ROCKET_FLYING_SOUND, 316, getRocketLocation());
Expand All @@ -83,7 +83,7 @@ public void move() {

getRocketWorld().spawnParticle(Particle.FIREWORKS_SPARK, getRocketLocation(), 0);
getRocketWorld().spawnParticle(Particle.LAVA, getRocketLocation(), 0);
addBeam();
addDuration();
}

@Override
Expand Down Expand Up @@ -166,7 +166,7 @@ private void catastrophe(Location explosionCenter) {
@Override
public void moveUp() {
Vector dir = getRocketLocation().getDirection();
dir.multiply(0.8);
dir.multiply(MOVE_UP_SPEED);
// поднимаем ракету
getRocketLocation().add(dir);
}
Expand All @@ -179,7 +179,7 @@ public void moveWithY() {
// обновляем целевую локацию с актуальным Y
getTargetLocation().setY(getRocketWorld().getHighestBlockYAt(getTargetLocation()));
// двигаем ракету к цели
getRocketLocation().add(findPath(true));
getRocketLocation().add(findPath(true).multiply(MOVE_WITH_Y_SPEED));
}

public Vector findPath(boolean includeY) {
Expand Down
30 changes: 13 additions & 17 deletions src/main/java/com/genife/adventbombs/Rockets/Rocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import org.bukkit.World;
import org.bukkit.entity.Player;

import static com.genife.adventbombs.Managers.ConfigManager.MAX_FLY_DURATION;

public abstract class Rocket {
private Location rocketLocation;
private Location targetLocation;
private World rocketWorld;
private int beam;
private int maxBeam;
private int duration;
private RocketState state;

public Rocket(Player sender, Location targetLocation, int maxBeam) {
public Rocket(Player sender, Location targetLocation) {
setRocketLocation(sender.getLocation());
setTargetLocation(targetLocation);
setRocketWorld(sender.getWorld());
setBeam(0);
setMaxBeam(maxBeam);
setDuration(0);
}

public boolean isDown() {
Expand Down Expand Up @@ -67,23 +67,19 @@ public void setState(RocketState state) {
this.state = state;
}

public boolean reachMaxBeam() {
return beam >= maxBeam;
}

public void setMaxBeam(int maxBeam) {
this.maxBeam = maxBeam;
public boolean reachMaxDuration() {
return duration >= MAX_FLY_DURATION * 20L;
}

public int getBeam() {
return beam;
public int getDuration() {
return duration;
}

public void setBeam(int beam) {
this.beam = beam;
public void setDuration(int duration) {
this.duration = duration;
}

public void addBeam() {
this.setBeam(getBeam() + 1);
public void addDuration() {
this.setDuration(getDuration() + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RocketRunnable extends BukkitRunnable {

public RocketRunnable(Rocket rocket) {
setRocket(rocket);
activeRockets.add(this); // добавляем созданный инстанс в список активных ракет
activeRockets.add(this); // добавляем созданную ракету в список активных ракет
}

public static int getActiveRocketCount() {
Expand Down

0 comments on commit 468ae7a

Please sign in to comment.