develop-bloodmoon #10

Merged
MineTec merged 17 commits from develop-bloodmoon into master 2025-11-23 14:03:07 +00:00
3 changed files with 40 additions and 32 deletions
Showing only changes of commit 045f31d4ca - Show all commits

View File

@@ -12,6 +12,7 @@ import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; 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;
Pupsi marked this conversation as resolved
Review

hier die Variable aus dem map.get zu überschreiben sieht komisch aus
Mach doch eine neue Variable, du setzt unten ja sowiso manuell .put

hier die Variable aus dem map.get zu überschreiben sieht komisch aus Mach doch eine neue Variable, du setzt unten ja sowiso manuell .put
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() { public List<ItemStack> getRandomBonusDrops() {
int itemCount = ThreadLocalRandom.current().nextInt(this.minBonusDrops, this.maxBonusDrops + 1); int itemCount = ThreadLocalRandom.current().nextInt(this.minBonusDrops, this.maxBonusDrops + 1);
List<ItemStack> result = new ArrayList<>(); List<ItemStack> result = new ArrayList<>();
@@ -161,20 +190,6 @@ public class Bloodmoon extends Appliance {
return result; 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() { private ItemStack getRandomBonusDrop() {
int totalWeight = this.bonusDropWeightMap.values().stream().mapToInt(value -> value).sum(); int totalWeight = this.bonusDropWeightMap.values().stream().mapToInt(value -> value).sum();
int randomInt = ThreadLocalRandom.current().nextInt(0, totalWeight + 1); int randomInt = ThreadLocalRandom.current().nextInt(0, totalWeight + 1);
@@ -186,20 +201,6 @@ public class Bloodmoon extends Appliance {
return null; 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 @Override
protected @NotNull List<Listener> listeners() { protected @NotNull List<Listener> listeners() {
return List.of( return List.of(

View File

@@ -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.Settings;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.BoolSetting; import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.BoolSetting;
import eu.mhsl.craftattack.spawn.core.Main; 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.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@@ -36,12 +39,16 @@ public class BloodmoonSetting extends BoolSetting implements CategorizedSetting
@Override @Override
protected Boolean defaultValue() { protected Boolean defaultValue() {
return false; return true;
} }
@Override @Override
protected void change(Player player, ClickType clickType) { 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); super.change(player, clickType);
} }
} }

View File

@@ -17,7 +17,7 @@ public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
if(args.length == 0) { 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; return;
} }
@@ -32,7 +32,7 @@ public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
sender.sendMessage("Stopped bloodmoon."); sender.sendMessage("Stopped bloodmoon.");
break; break;
} }
default: throw new Error("No such option: '" + args[0] + "' !"); default: throw new Error("No such option: '%s' !".formatted(args[0]));
} }
} }