Files
src
build.gradle
settings.gradle
Code
5 164
src/main/java/com/monsoonwelcome/MonsoonWelcomePlugin.java
package com.monsoonwelcome;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public final class MonsoonWelcomePlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
saveDefaultConfig();
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
sendTitle(player);
playJoinSound(player);
sendWelcomeMessage(player);
spawnWelcomeParticles(player);
}
private void sendTitle(Player player) {
String title = color(getConfig().getString("title.text", "&5&lWELCOME TO MONSOON SMP"));
String subtitle = color(getConfig().getString("title.subtitle", "&d&lSEASON 4 &8• &fSURVIVAL SMP"));
int fadeIn = Math.max(0, getConfig().getInt("title.fade-in-ticks", 10));
int stay = Math.max(0, getConfig().getInt("title.stay-ticks", 60));
int fadeOut = Math.max(0, getConfig().getInt("title.fade-out-ticks", 20));
player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
}
private void playJoinSound(Player player) {
if (!getConfig().getBoolean("sound.enabled", true)) {
return;
}
String soundName = getConfig().getString("sound.name", "ENTITY_PLAYER_LEVELUP");
float volume = (float) getConfig().getDouble("sound.volume", 1.0);
float pitch = (float) getConfig().getDouble("sound.pitch", 1.0);
XSound.matchXSound(soundName).ifPresent(sound ->
player.playSound(player.getLocation(), sound.get(), volume, pitch));
}
private void sendWelcomeMessage(Player player) {
for (String line : getConfig().getStringList("chat.lines")) {
player.sendMessage(color(line.replace("%player%", player.getName())));
}
}
private void spawnWelcomeParticles(Player player) {
if (!getConfig().getBoolean("particles.enabled", true)) {
return;
}
int duration = Math.max(0, getConfig().getInt("particles.duration-ticks", 40));
int interval = Math.max(1, getConfig().getInt("particles.interval-ticks", 5));
int count = Math.max(0, getConfig().getInt("particles.count", 8));
double horizontalOffset = Math.max(0.0, getConfig().getDouble("particles.horizontal-offset", 0.8));
double verticalOffset = Math.max(0.0, getConfig().getDouble("particles.vertical-offset", 1.0));
double extra = Math.max(0.0, getConfig().getDouble("particles.extra", 0.02));
if (duration == 0 || count == 0) {
return;
}
new BukkitRunnable() {
private int elapsedTicks;
@Override
public void run() {
if (!player.isOnline() || elapsedTicks >= duration) {
cancel();
return;
}
Location location = player.getLocation().add(0, 1, 0);
for (String particleName : getConfig().getStringList("particles.types")) {
XParticle.of(particleName).ifPresent(particle ->
player.getWorld().spawnParticle(
particle.get(), location, count,
horizontalOffset, verticalOffset, horizontalOffset, extra));
}
elapsedTicks += interval;
}
}.runTaskTimer(this, 0L, interval);
}
private String color(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
}