removed horde announcement message and unnecessary copy of player location, added setting feedback when bloodmoon active
This commit is contained in:
@@ -12,6 +12,7 @@ import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -152,6 +153,34 @@ public class Bloodmoon extends Appliance {
|
||||
);
|
||||
}
|
||||
|
||||
public void spawnRandomHorde() {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) return;
|
||||
if(!this.hordesEnabled) return;
|
||||
List<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(this::getBloodmoonSetting)
|
||||
.filter(player -> player.getGameMode().equals(GameMode.SURVIVAL))
|
||||
.toList();
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
Player player = onlinePlayerList.get(random.nextInt(onlinePlayerList.size()));
|
||||
EntityType hordeEntityType = this.hordeMobList.get(random.nextInt(this.hordeMobList.size()));
|
||||
int hordeSize = random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
|
||||
this.spawnHorde(player, hordeSize, hordeEntityType);
|
||||
}
|
||||
|
||||
private void spawnHorde(Player player, int size, EntityType type) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
double spawnRadiant = ThreadLocalRandom.current().nextDouble(0, 2*Math.PI);
|
||||
Location mobSpawnLocation = player.getLocation().add(
|
||||
Math.sin(spawnRadiant)*this.hordeSpawnDistance,
|
||||
0,
|
||||
Math.cos(spawnRadiant)*this.hordeSpawnDistance
|
||||
);
|
||||
mobSpawnLocation.setY(player.getWorld().getHighestBlockYAt(mobSpawnLocation) + 1);
|
||||
player.getWorld().spawnEntity(mobSpawnLocation, type);
|
||||
player.getWorld().strikeLightningEffect(mobSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getRandomBonusDrops() {
|
||||
int itemCount = ThreadLocalRandom.current().nextInt(this.minBonusDrops, this.maxBonusDrops + 1);
|
||||
List<ItemStack> result = new ArrayList<>();
|
||||
@@ -161,20 +190,6 @@ public class Bloodmoon extends Appliance {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void spawnRandomHorde() {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) return;
|
||||
if(!this.hordesEnabled) return;
|
||||
List<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(this::getBloodmoonSetting)
|
||||
.toList();
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
Player player = onlinePlayerList.get(random.nextInt(onlinePlayerList.size()));
|
||||
EntityType hordeEntityType = this.hordeMobList.get(random.nextInt(this.hordeMobList.size()));
|
||||
int hordeSize = random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
|
||||
this.spawnHorde(player, hordeSize, hordeEntityType);
|
||||
Bukkit.getOnlinePlayers().forEach(p -> p.sendMessage(Component.text("Eine Horde ist bei %s gespawnt.".formatted(player.getName()), NamedTextColor.RED)));
|
||||
}
|
||||
|
||||
private ItemStack getRandomBonusDrop() {
|
||||
int totalWeight = this.bonusDropWeightMap.values().stream().mapToInt(value -> value).sum();
|
||||
int randomInt = ThreadLocalRandom.current().nextInt(0, totalWeight + 1);
|
||||
@@ -186,20 +201,6 @@ public class Bloodmoon extends Appliance {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void spawnHorde(Player player, int size, EntityType type) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
double spawnRadiant = ThreadLocalRandom.current().nextDouble(0, 2*Math.PI);
|
||||
Location mobSpawnLocation = player.getLocation().clone().add(
|
||||
Math.sin(spawnRadiant)*this.hordeSpawnDistance,
|
||||
0,
|
||||
Math.cos(spawnRadiant)*this.hordeSpawnDistance
|
||||
);
|
||||
mobSpawnLocation.setY(player.getWorld().getHighestBlockYAt(mobSpawnLocation) + 1);
|
||||
player.getWorld().spawnEntity(mobSpawnLocation, type);
|
||||
player.getWorld().strikeLightningEffect(mobSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
|
||||
@@ -5,6 +5,9 @@ import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Setting
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.BoolSetting;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.util.world.InteractSounds;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
@@ -36,12 +39,16 @@ public class BloodmoonSetting extends BoolSetting implements CategorizedSetting
|
||||
|
||||
@Override
|
||||
protected Boolean defaultValue() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void change(Player player, ClickType clickType) {
|
||||
if(Main.instance().getAppliance(Bloodmoon.class).bloodmoonIsActive()) return;
|
||||
if(Main.instance().getAppliance(Bloodmoon.class).bloodmoonIsActive()) {
|
||||
InteractSounds.of(player).delete();
|
||||
player.sendMessage(Component.text("Während dem Blutmond kann diese Einstellung nicht geändert werden!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
super.change(player, clickType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
if(args.length == 0) {
|
||||
sender.sendMessage("Bloodmoon is currently " + (this.getAppliance().bloodmoonIsActive() ? "active." : "inactive."));
|
||||
sender.sendMessage("Bloodmoon is currently %s.".formatted(this.getAppliance().bloodmoonIsActive() ? "active" : "inactive"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
|
||||
sender.sendMessage("Stopped bloodmoon.");
|
||||
break;
|
||||
}
|
||||
default: throw new Error("No such option: '" + args[0] + "' !");
|
||||
default: throw new Error("No such option: '%s' !".formatted(args[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user