Merge branch 'master' into feature/AntiPlayerLootDespawn
This commit is contained in:
commit
067a6f41dc
5 files changed
+91
-17
No files matched your search
@@ -32,7 +32,7 @@ public class IteratorUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void times(int times, Runnable callback) {
|
public static void times(int times, Runnable callback) {
|
||||||
IntStream.range(0, times).forEach(value -> callback.run());
|
IntStream.range(0, times).forEach(_ -> callback.run());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void iterateListInGlobal(int sectionStart, List<T> list, BiConsumer<Integer, T> callback) {
|
public static <T> void iterateListInGlobal(int sectionStart, List<T> list, BiConsumer<Integer, T> callback) {
|
||||||
|
|||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.newYearFirework;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class NewYearFirework extends Appliance {
|
||||||
|
private static final String namespace = NewYearFirework.class.getSimpleName().toLowerCase(Locale.ROOT);
|
||||||
|
public static NamespacedKey fireworkKey = new NamespacedKey(namespace, "newyear_firework".toLowerCase());
|
||||||
|
|
||||||
|
public void spawnFirework(Player player) {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
Firework firework = player.getWorld().spawn(player.getLocation(), Firework.class);
|
||||||
|
firework.getPersistentDataContainer().set(fireworkKey, PersistentDataType.BOOLEAN, true);
|
||||||
|
FireworkMeta fireworkMeta = firework.getFireworkMeta();
|
||||||
|
fireworkMeta.addEffect(FireworkEffect.builder()
|
||||||
|
.with(FireworkEffect.Type.BALL)
|
||||||
|
.withColor(Color.AQUA, Color.RED, Color.LIME, Color.ORANGE, Color.YELLOW)
|
||||||
|
.withFade(Color.FUCHSIA, Color.WHITE)
|
||||||
|
.trail(true)
|
||||||
|
.flicker(true)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
fireworkMeta.setPower((int) (i % 3 + 0.25));
|
||||||
|
firework.setFireworkMeta(fireworkMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldSpawnFirework() {
|
||||||
|
return LocalDate.now().getDayOfYear() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(new NewYearFireworkListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.newYearFirework;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
class NewYearFireworkListener extends ApplianceListener<NewYearFirework> {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
if(!this.getAppliance().shouldSpawnFirework()) return;
|
||||||
|
this.getAppliance().spawnFirework(event.getPlayer());
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
|
public void onDamage(EntityDamageByEntityEvent event) {
|
||||||
|
if(!(event.getDamager() instanceof Firework firework)) return;
|
||||||
|
if(!firework.getPersistentDataContainer().has(NewYearFirework.fireworkKey)) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -4,7 +4,7 @@ import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class QuarzRecipeListener extends ApplianceListener<QuarzRecipe> {
|
class QuarzRecipeListener extends ApplianceListener<QuarzRecipe> {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
this.getAppliance().unlock(event.getPlayer());
|
this.getAppliance().unlock(event.getPlayer());
|
||||||
|
|||||||
+20
-15
@@ -26,10 +26,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static java.util.Map.entry;
|
|
||||||
import static org.bukkit.Sound.MUSIC_DISC_LAVA_CHICKEN;
|
import static org.bukkit.Sound.MUSIC_DISC_LAVA_CHICKEN;
|
||||||
|
|
||||||
public class ProjectStart extends Appliance {
|
public class ProjectStart extends Appliance {
|
||||||
@@ -57,16 +55,23 @@ public class ProjectStart extends Appliance {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
private final Map<GameRule<Boolean>, Boolean> gameRulesAfterStart = Map.ofEntries(
|
private record GameRuleSetting<T>(GameRule<T> rule, T before, T after) {
|
||||||
entry(GameRules.ADVANCE_TIME, true),
|
void apply(boolean afterStart) {
|
||||||
entry(GameRules.SPAWN_PHANTOMS, true),
|
IteratorUtil.worlds(world -> world.setGameRule(this.rule, afterStart ? this.after : this.before));
|
||||||
entry(GameRules.RAIDS, true),
|
}
|
||||||
entry(GameRules.ENTITY_DROPS, true),
|
}
|
||||||
entry(GameRules.SPAWN_PATROLS, true),
|
|
||||||
entry(GameRules.SPAWN_WANDERING_TRADERS, true),
|
private final List<GameRuleSetting<?>> gameRules = List.of(
|
||||||
entry(GameRules.ADVANCE_WEATHER, true),
|
new GameRuleSetting<>(GameRules.ADVANCE_TIME, false, true),
|
||||||
entry(GameRules.FALL_DAMAGE, true),
|
new GameRuleSetting<>(GameRules.SPAWN_PHANTOMS, false, true),
|
||||||
entry(GameRules.FIRE_DAMAGE, true)
|
new GameRuleSetting<>(GameRules.RAIDS, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.ENTITY_DROPS, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.SPAWN_PATROLS, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.SPAWN_WANDERING_TRADERS, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.ADVANCE_WEATHER, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.FALL_DAMAGE, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.FIRE_DAMAGE, false, true),
|
||||||
|
new GameRuleSetting<>(GameRules.FIRE_SPREAD_RADIUS_AROUND_PLAYER, 0, -1)
|
||||||
);
|
);
|
||||||
|
|
||||||
public ProjectStart() {
|
public ProjectStart() {
|
||||||
@@ -75,7 +80,7 @@ public class ProjectStart extends Appliance {
|
|||||||
this.countdown.addCustomAnnouncement(
|
this.countdown.addCustomAnnouncement(
|
||||||
new Countdown.CustomAnnouncements(
|
new Countdown.CustomAnnouncements(
|
||||||
counter -> counter == this.startMusicAt,
|
counter -> counter == this.startMusicAt,
|
||||||
counter -> this.glassLocation
|
_ -> this.glassLocation
|
||||||
.getWorld()
|
.getWorld()
|
||||||
.playSound(this.glassLocation, MUSIC_DISC_LAVA_CHICKEN, SoundCategory.RECORDS, 500f, 1f)
|
.playSound(this.glassLocation, MUSIC_DISC_LAVA_CHICKEN, SoundCategory.RECORDS, 500f, 1f)
|
||||||
)
|
)
|
||||||
@@ -120,7 +125,7 @@ public class ProjectStart extends Appliance {
|
|||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
|
|
||||||
IteratorUtil.worlds(World::getWorldBorder, worldBorder -> worldBorder.setSize(worldBorder.getMaxSize()));
|
IteratorUtil.worlds(World::getWorldBorder, worldBorder -> worldBorder.setSize(worldBorder.getMaxSize()));
|
||||||
IteratorUtil.worlds(world -> IteratorUtil.setGameRules(this.gameRulesAfterStart, false));
|
this.gameRules.forEach(setting -> setting.apply(true));
|
||||||
Bukkit.getWorlds().getFirst().setFullTime(0);
|
Bukkit.getWorlds().getFirst().setFullTime(0);
|
||||||
|
|
||||||
this.netherFireLocations.forEach(location -> Objects.requireNonNull(this.startWorld).getBlockAt(location).setType(Material.FIRE));
|
this.netherFireLocations.forEach(location -> Objects.requireNonNull(this.startWorld).getBlockAt(location).setType(Material.FIRE));
|
||||||
@@ -167,7 +172,7 @@ public class ProjectStart extends Appliance {
|
|||||||
worldBorder.setDamageAmount(0);
|
worldBorder.setDamageAmount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
IteratorUtil.worlds(world -> world, world -> IteratorUtil.setGameRules(this.gameRulesAfterStart, true));
|
this.gameRules.forEach(setting -> setting.apply(false));
|
||||||
this.resetAdvancements();
|
this.resetAdvancements();
|
||||||
|
|
||||||
this.blockCycle.reset();
|
this.blockCycle.reset();
|
||||||
|
|||||||
Reference in new issue
Block a user