Files
src
build.gradle
settings.gradle
Code
7 331
src/main/java/com/kodari/riftworld/RiftWorldPlugin.java
package com.kodari.riftworld;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public final class RiftWorldPlugin extends JavaPlugin {
private World riftWorld;
@Override
public void onEnable() {
saveDefaultConfig();
String worldName = getConfig().getString("rift-world", "rift-world");
riftWorld = Bukkit.createWorld(new org.bukkit.WorldCreator(worldName)
.environment(World.Environment.NORMAL)
.generator(new RiftWorldGenerator()));
if (riftWorld == null) {
getLogger().severe("Could not create the rift world: " + worldName);
getServer().getPluginManager().disablePlugin(this);
return;
}
RiftListener listener = new RiftListener(this);
getServer().getPluginManager().registerEvents(listener, this);
listener.createExitRift();
startRiftWeather();
startMonsterSpawns();
}
public World getRiftWorld() {
return riftWorld;
}
private void startRiftWeather() {
riftWorld.setStorm(true);
riftWorld.setThundering(true);
riftWorld.setWeatherDuration(12000);
riftWorld.setThunderDuration(12000);
Bukkit.getScheduler().runTaskTimer(this, () -> {
riftWorld.setStorm(true);
riftWorld.setThundering(true);
riftWorld.setWeatherDuration(12000);
riftWorld.setThunderDuration(12000);
List<Player> players = riftWorld.getPlayers();
if (players.isEmpty()) {
return;
}
Player target = players.get(ThreadLocalRandom.current().nextInt(players.size()));
Location strike = target.getLocation().clone().add(
ThreadLocalRandom.current().nextInt(-12, 13), 0,
ThreadLocalRandom.current().nextInt(-12, 13));
strike.setY(riftWorld.getHighestBlockYAt(strike) + 1);
riftWorld.strikeLightningEffect(strike);
drawRedLightning(strike);
}, 20L * 30, 20L * 30);
}
private void drawRedLightning(Location strike) {
XParticle.of("DAMAGE_INDICATOR").ifPresent(particle -> {
for (int y = 2; y <= 18; y += 2) {
Location point = strike.clone().add(
ThreadLocalRandom.current().nextDouble(-0.25, 0.25), y,
ThreadLocalRandom.current().nextDouble(-0.25, 0.25));
riftWorld.spawnParticle(particle.get(), point, 3, 0.12, 0.12, 0.12);
}
});
}
private void startMonsterSpawns() {
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (Player player : riftWorld.getPlayers()) {
if (ThreadLocalRandom.current().nextInt(4) != 0) {
continue;
}
int x = player.getLocation().getBlockX() + ThreadLocalRandom.current().nextInt(-14, 15);
int z = player.getLocation().getBlockZ() + ThreadLocalRandom.current().nextInt(-14, 15);
Location spawn = riftWorld.getHighestBlockAt(x, z).getLocation().add(0, 1, 0);
LivingEntity stalker = (LivingEntity) riftWorld.spawnEntity(spawn, EntityType.ZOMBIE);
stalker.setCustomName("§cRift Stalker");
stalker.setCustomNameVisible(true);
stalker.setRemoveWhenFarAway(true);
}
}, 20L * 10, 20L * 20);
}
}