Files
src
build.gradle
Code
3 371
src/main/java/me/flowersmp/FlowerSMP.java
package me.flowersmp;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Random;
import java.util.UUID;
public class FlowerSMP extends JavaPlugin implements Listener, CommandExecutor {
HashMap<UUID, String> flowers = new HashMap<>();
HashMap<UUID, Integer> levels = new HashMap<>();
HashMap<UUID, Integer> kills = new HashMap<>();
HashMap<UUID, Long> sneak = new HashMap<>();
HashMap<UUID, Boolean> doubleSneak = new HashMap<>();
HashMap<UUID, Integer> bossMode = new HashMap<>();
Random r = new Random();
String[] types = {"ender", "aqua", "crimson", "wind", "pack"};
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
getCommand("flowersmp").setExecutor(this);
passiveLoop();
shrineSpawner();
registerBossRecipe();
getLogger().info("FlowerSMP has been enabled!");
}
@Override
public void onDisable() {
getLogger().info("FlowerSMP has been disabled!");
}
void passiveLoop() {
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (Player p : Bukkit.getOnlinePlayers()) {
if (!flowers.containsKey(p.getUniqueId())) continue;
String type = flowers.get(p.getUniqueId());
switch (type) {
case "ender":
XPotion.matchXPotion("RESISTANCE").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("INCREASE_DAMAGE").map(xp -> xp.buildPotionEffect(40, 1))
.ifPresent(effect -> p.addPotionEffect(effect));
XParticle.of("PORTAL").ifPresent(particle ->
p.getWorld().spawnParticle(particle.get(), p.getLocation(), 5));
break;
case "aqua":
XPotion.matchXPotion("DOLPHINS_GRACE").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("CONDUIT_POWER").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XParticle.of("WATER_SPLASH").ifPresent(particle ->
p.getWorld().spawnParticle(particle.get(), p.getLocation(), 5));
break;
case "crimson":
XPotion.matchXPotion("INCREASE_DAMAGE").map(xp -> xp.buildPotionEffect(40, 1))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("FIRE_RESISTANCE").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XParticle.of("FLAME").ifPresent(particle ->
p.getWorld().spawnParticle(particle.get(), p.getLocation(), 5));
break;
case "wind":
XPotion.matchXPotion("SPEED").map(xp -> xp.buildPotionEffect(40, 1))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("RESISTANCE").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XParticle.of("CLOUD").ifPresent(particle ->
p.getWorld().spawnParticle(particle.get(), p.getLocation(), 5));
break;
case "pack":
XPotion.matchXPotion("SPEED").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("INCREASE_DAMAGE").map(xp -> xp.buildPotionEffect(40, 0))
.ifPresent(effect -> p.addPotionEffect(effect));
XParticle.of("VILLAGER_HAPPY").ifPresent(particle ->
p.getWorld().spawnParticle(particle.get(), p.getLocation(), 5));
break;
case "boss":
XPotion.matchXPotion("SPEED").map(xp -> xp.buildPotionEffect(40, 1))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("INCREASE_DAMAGE").map(xp -> xp.buildPotionEffect(40, 1))
.ifPresent(effect -> p.addPotionEffect(effect));
XPotion.matchXPotion("RESISTANCE").map(xp -> xp.buildPotionEffect(40, 1))
.ifPresent(effect -> p.addPotionEffect(effect));
XParticle.of("END_ROD").ifPresent(particle ->
p.getWorld().spawnParticle(particle.get(), p.getLocation(), 8));
break;
}
}
}, 0, 20);
}
@EventHandler
public void sneak(PlayerToggleSneakEvent e) {
Player p = e.getPlayer();
long now = System.currentTimeMillis();
if (sneak.containsKey(p.getUniqueId()) && now - sneak.get(p.getUniqueId()) < 400) {
doubleSneak.put(p.getUniqueId(), true);
useAbility(p);
}
sneak.put(p.getUniqueId(), now);
}
@EventHandler
public void jump(PlayerMoveEvent e) {
Player p = e.getPlayer();
if (!doubleSneak.getOrDefault(p.getUniqueId(), false)) return;
if (p.isOnGround()) return;
int mode = bossMode.getOrDefault(p.getUniqueId(), 0);
mode++;
if (mode > 5) mode = 1;
bossMode.put(p.getUniqueId(), mode);
doubleSneak.put(p.getUniqueId(), false);
p.sendTitle(ChatColor.GOLD + "Boss Flower Mode", "Mode " + mode, 10, 40, 10);
}
void useAbility(Player p) {
if (!flowers.containsKey(p.getUniqueId())) return;
String type = flowers.get(p.getUniqueId());
if (type.equals("ender")) {
p.launchProjectile(DragonFireball.class);
XSound.matchXSound("ENTITY_ENDER_DRAGON_SHOOT").ifPresent(sound -> sound.play(p));
}
if (type.equals("aqua")) {
for (Entity e : p.getNearbyEntities(10, 10, 10)) {
if (e instanceof LivingEntity && e != p) {
e.setVelocity(new Vector(0, 1, 3));
}
}
}
if (type.equals("wind")) {
Vector dash = p.getLocation().getDirection().multiply(2);
dash.setY(1);
p.setVelocity(dash);
}
if (type.equals("boss")) {
int mode = bossMode.getOrDefault(p.getUniqueId(), 1);
switch (mode) {
case 1:
p.launchProjectile(DragonFireball.class);
XSound.matchXSound("ENTITY_ENDER_DRAGON_SHOOT").ifPresent(sound -> sound.play(p));
break;
case 2:
for (Entity e : p.getNearbyEntities(10, 10, 10)) {
if (e instanceof LivingEntity && e != p) {
e.setVelocity(new Vector(0, 1, 3));
}