That should be the whole thing

This commit is contained in:
wolf
2024-09-08 20:07:44 -05:00
parent 4018d78716
commit 9480179765
29 changed files with 1490 additions and 138 deletions

View File

@@ -7,6 +7,9 @@ version = '1.0-SNAPSHOT'
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url = "https://repo.papermc.io/repository/maven-public/"
}
maven { maven {
name = "spigotmc-repo" name = "spigotmc-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
@@ -15,10 +18,11 @@ repositories {
name = "sonatype" name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/" url = "https://oss.sonatype.org/content/groups/public/"
} }
} }
dependencies { dependencies {
compileOnly("org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
implementation files("libs/PDK-1.4.0.jar") implementation files("libs/PDK-1.4.0.jar")
} }

View File

@@ -1,12 +1,19 @@
package me.trouper.ultrabliss; package me.trouper.ultrabliss;
import io.github.itzispyder.pdk.PDK; import io.github.itzispyder.pdk.PDK;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.misc.config.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.config.JsonSerializable;
import me.trouper.ultrabliss.data.Config; import me.trouper.ultrabliss.data.Config;
import me.trouper.ultrabliss.data.GemStorage; import me.trouper.ultrabliss.data.GemStorage;
import me.trouper.ultrabliss.server.VirtualGems;
import me.trouper.ultrabliss.server.commands.AdminCommand;
import me.trouper.ultrabliss.server.crafting.TradeItem;
import me.trouper.ultrabliss.server.crafting.UpgradeItem;
import me.trouper.ultrabliss.server.events.*;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.logging.Logger;
public final class UltraBliss extends JavaPlugin { public final class UltraBliss extends JavaPlugin {
@@ -15,14 +22,22 @@ public final class UltraBliss extends JavaPlugin {
public static File configFile = new File("plugins/UltraBliss/config.json"); public static File configFile = new File("plugins/UltraBliss/config.json");
public static Config config = JsonSerializable.load(configFile,Config.class,new Config()); public static Config config = JsonSerializable.load(configFile,Config.class,new Config());
private static UltraBliss instance; private static UltraBliss instance;
public static Logger log;
@Override @Override
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
PDK.init(this); PDK.init(this);
instance = this; instance = this;
log = instance.getLogger();
log.info("Preload Finished");
initStorage(); initStorage();
initCrafting();
initCommands();
initEvents();
initGems();
} }
@@ -32,10 +47,42 @@ public final class UltraBliss extends JavaPlugin {
// Plugin shutdown logic // Plugin shutdown logic
} }
public static UltraBliss getInstance() {
return instance;
}
private void initStorage() { private void initStorage() {
log.info("Initializing Storage, Any stack-traces in yellow are expected.");
gemStorage = JsonSerializable.load(gemStorageFile,GemStorage.class,new GemStorage()); gemStorage = JsonSerializable.load(gemStorageFile,GemStorage.class,new GemStorage());
gemStorage.save(); gemStorage.save();
config = JsonSerializable.load(configFile,Config.class,new Config()); config = JsonSerializable.load(configFile,Config.class,new Config());
config.save(); config.save();
} }
private void initCrafting() {
log.info("Initializing crafting");
UpgradeItem.addUpgradeRecipe();
TradeItem.addTradeRecipe();
}
private void initCommands() {
log.info("Initializing Commands");
new AdminCommand().register();
}
private void initEvents() {
log.info("Initializing Events");
new GemProtectionListeners().register();
new UpgradeListener().register();
new UseListener().register();
new DeathListener().register();
new JoinListener().register();
new TradeListener().register();
new ProjectileHitListener().register();
}
private void initGems() {
log.info("Initializing Gems");
SchedulerUtils.repeat(20, VirtualGems::applyPassiveEffects);
}
} }

View File

@@ -1,40 +0,0 @@
package me.trouper.ultrabliss.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.ultrabliss.UltraBliss;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.awt.*;
public class AdminCommand implements CustomCommand {
@Override
public void dispatchCommand(CommandSender commandSender, Command command, String s, Args args) {
}
@Override
public void dispatchCompletions(CommandSender commandSender, Command command, String s, CompletionBuilder b) {
}
private void handleGiveGemCommand(Player p, Args args) {
if (args.getSize() < 3) return;
String gemType = args.get(2).toString();
switch (gemType) {
case "fire" -> p.getInventory().setItemInOffHand(Gems.FIRE_GEM.item());
case "life" -> p.getInventory().setItemInOffHand(Gems.LIFE_GEM.item());
case "puff" -> p.getInventory().setItemInOffHand(Gems.PUFF_GEM.item());
case "speed" -> p.getInventory().setItemInOffHand(Gems.SPEED_GEM.item());
case "wealth" -> p.getInventory().setItemInOffHand(Gems.WEALTH_GEM.item());
case "strength" -> p.getInventory().setItemInOffHand(Gems.STRENGTH_GEM.item());
case "astra" -> p.getInventory().setItemInOffHand(Gems.ASTRA_GEM.item());
}
p.sendMessage(color(UltraBliss.config.prefix + "Given you a &a%s&7 gem!".formatted(gemType)));
}
}

View File

@@ -6,7 +6,6 @@ import me.trouper.ultrabliss.UltraBliss;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
public class GemStorage implements JsonSerializable<GemStorage> { public class GemStorage implements JsonSerializable<GemStorage> {
@Override @Override

View File

@@ -1,77 +0,0 @@
package me.trouper.ultrabliss.server;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
import java.util.function.Consumer;
public class GemData {
public GemData(int dataID, ItemStack item, List<PotionEffect> passive, Consumer<Player> onRightClick, int cooldown, GemData upgrade, GemData downgrade) {
}
public static Builder create(int dataID) {
return new Builder(dataID);
}
public static class Builder {
private int dataID;
private ItemStack item;
private List<PotionEffect> passive;
private Consumer<Player> onRightClick;
private int cooldown;
private GemData upgrade;
private GemData downgrade;
public Builder(int dataID) {
this.dataID = dataID;
item = ItemBuilder.create()
.material(Material.EMERALD)
.name("L Bozo forgot to define the item")
.build();
passive = List.of(new PotionEffect(PotionEffectType.WATER_BREATHING,0,1));
}
public Builder setItem(ItemStack item) {
ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(this.dataID);
item.setItemMeta(meta);
this.item = item;
return this;
}
public Builder setPassive(List<PotionEffect> passive) {
this.passive = passive;
return this;
}
public Builder setOnRightClick(Consumer<Player> onRightClick) {
this.onRightClick = onRightClick;
return this;
}
public Builder setCooldown(int ticks) {
this.cooldown = ticks;
return this;
}
public Builder setUpgrade(GemData upgrade) {
this.upgrade = upgrade;
return this;
}
public Builder setDowngrade(GemData downgrade) {
this.downgrade = downgrade;
return this;
}
public GemData build() {
return new GemData(dataID,item,passive,onRightClick,cooldown,upgrade,downgrade);
}
}
}

View File

@@ -0,0 +1,138 @@
package me.trouper.ultrabliss.server;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.ServerUtils;
import io.github.itzispyder.pdk.utils.misc.Randomizer;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.UltraBliss;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.server.generic.Registry;
import me.trouper.ultrabliss.utils.MapUtils;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Sound;
import org.bukkit.entity.Firework;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.Nullable;
public class VirtualGems {
public static void setGem(Player p, Gem<?> gem) {
p.getInventory().setItemInOffHand(gem.getItem());
UltraBliss.gemStorage.playerGems.put(p.getUniqueId().toString(),gem.getDataID());
UltraBliss.gemStorage.save();
}
public static Gem<?> getGem(Player p) {
try {
int id = UltraBliss.gemStorage.playerGems.get(p.getUniqueId().toString());
for (Gem<?> gem : Registry.set) {
if (gem.getDataID() == id) return gem;
}
return null;
} catch (Exception e) {
return null;
}
}
public static Gem<?> setRandomGem(Player p) {
Randomizer rand = new Randomizer();
Gem<?> pick = rand.getRandomElement(Registry.set);
setGem(p,pick);
return pick;
}
public static boolean downgradeGem(Player p) {
Gem<?> has = getGem(p);
if (has == null) return false;
Gem<?> set = MapUtils.swapValues(Registry.upgrades).get(has);
if (set == null) return false;
setGem(p,set);
return true;
}
public static boolean upgradeGem(Player p) {
Gem<?> has = getGem(p);
if (has == null) return false;
Gem<?> set = Registry.upgrades.get(has);
if (set == null) return false;
setGem(p,set);
SoundPlayer upgrade = new SoundPlayer(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10,0.6F);
upgrade.playWithin(3);
Firework f = p.getWorld().spawn(p.getLocation(), Firework.class);
FireworkMeta fm = f.getFireworkMeta();
fm.addEffect(
FireworkEffect.builder()
.withColor(Color.BLUE)
.withColor(Color.AQUA)
.withColor(Color.TEAL)
.with(FireworkEffect.Type.BURST)
.withTrail()
.withFlicker()
.build());
fm.setPower(1);
f.setFireworkMeta(fm);
SchedulerUtils.later(1,f::detonate);
return true;
}
public static boolean verifyGem(Player p) {
Gem<?> has = getGem(p);
if (has == null) has = setRandomGem(p);
if (p.getInventory().getItemInOffHand().equals(has.getItem())) return true;
p.getInventory().setItemInOffHand(has.getItem());
return false;
}
public static void applyPassiveEffects() {
ServerUtils.forEachPlayer(VirtualGems::effectPlayer);
}
public static void effectPlayer(Player p) {
Gem<?> has = getGem(p);
if (has == null) has = setRandomGem(p);
if (has.getPassive().isEmpty()) return;
for (PotionEffect potionEffect : has.getPassive()) {
potionEffect.apply(p);
}
}
public static boolean isGem(ItemStack i) {
if (i == null) return false;
for (Gem<?> gem : Registry.set) {
if (i.isSimilar(gem.getItem())) {
return true;
}
}
return false;
}
public static boolean cleanInventory(Inventory inv) {
int cleared = 0;
for (ItemStack i : inv.getContents()) {
if (isGem(i)) {
i.setAmount(0);
cleared++;
}
}
for (HumanEntity viewer : inv.getViewers()) {
verifyGem((Player) viewer);
cleared++;
}
return cleared > 0;
}
}

View File

@@ -0,0 +1,62 @@
package me.trouper.ultrabliss.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.ultrabliss.UltraBliss;
import me.trouper.ultrabliss.server.VirtualGems;
import me.trouper.ultrabliss.server.generic.Registry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandRegistry(value = "bliss",permission = @Permission("ultrabliss.admin"),printStackTrace = true)
public class AdminCommand implements CustomCommand {
@Override
public void dispatchCommand(CommandSender commandSender, Command command, String s, Args args) {
Player p = (Player) commandSender;
switch (args.get(0).toString()) {
case "gems" -> handleGemsCommand(p,args);
}
}
@Override
public void dispatchCompletions(CommandSender commandSender, Command command, String s, CompletionBuilder b) {
b.then(b.arg("gems").then(
b.arg("give")
.then(b.arg("fire","life","puff","speed","wealth","strength","astra"))));
}
private void handleGemsCommand(Player p, Args args) {
if (args.getSize() < 2) return;
String subCommand = args.get(1).toString();
switch (subCommand) {
case "give" -> handleGiveGemCommand(p, args);
case "upgrade" -> VirtualGems.upgradeGem(p);
case "downgrade" -> VirtualGems.downgradeGem(p);
}
}
private void handleGiveGemCommand(Player p, Args args) {
if (args.getSize() < 3) return;
String gemType = args.get(2).toString();
switch (gemType) {
case "astra" -> VirtualGems.setGem(p,Registry.ASTRA_UPGRADE_GEM);
case "fire" -> VirtualGems.setGem(p,Registry.FIRE_UPGRADE_GEM);
case "life" -> VirtualGems.setGem(p,Registry.LIFE_UPGRADE_GEM);
case "puff" -> VirtualGems.setGem(p,Registry.PUFF_UPGRADE_GEM);
case "speed" -> VirtualGems.setGem(p,Registry.SPEED_UPGRADE_GEM);
case "strength" -> VirtualGems.setGem(p,Registry.STRENGTH_UPGRADE_GEM);
case "wealth" -> VirtualGems.setGem(p,Registry.WEALTH_UPGRADE_GEM);
}
p.sendMessage(color(UltraBliss.config.prefix + "Given you a &a%s&7 gem!".formatted(gemType)));
}
}

View File

@@ -0,0 +1,44 @@
package me.trouper.ultrabliss.server.crafting;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import me.trouper.ultrabliss.UltraBliss;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
public class TradeItem {
public static final NamespacedKey key = new NamespacedKey(UltraBliss.getInstance(), "gem_trade_recipe");
public static final ItemStack TRADE_ITEM = ItemBuilder.create()
.material(Material.NAME_TAG)
.name(Global.instance.color("&eGem Trader"))
.lore(Global.instance.color("&7Right click to randomize your gem!"))
.enchant(Enchantment.LURE,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public static void addTradeRecipe() {
UltraBliss.getInstance().getServer().removeRecipe(key);
ShapedRecipe recipe = new ShapedRecipe(key, TRADE_ITEM);
recipe.shape("ABC", "DEF", "GHI");
recipe.setIngredient('A', Material.NETHERITE_INGOT);
recipe.setIngredient('B', Material.DIAMOND_BLOCK);
recipe.setIngredient('C', Material.NETHERITE_INGOT);
recipe.setIngredient('D', Material.DIAMOND_BLOCK);
recipe.setIngredient('E', Material.NETHER_STAR);
recipe.setIngredient('F', Material.DIAMOND_BLOCK);
recipe.setIngredient('G', Material.NETHERITE_INGOT);
recipe.setIngredient('H', Material.DIAMOND_BLOCK);
recipe.setIngredient('I', Material.NETHERITE_INGOT);
UltraBliss.getInstance().getServer().addRecipe(recipe);
}
}

View File

@@ -0,0 +1,44 @@
package me.trouper.ultrabliss.server.crafting;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import me.trouper.ultrabliss.UltraBliss;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
public class UpgradeItem {
public static final NamespacedKey key = new NamespacedKey(UltraBliss.getInstance(), "gem_upgrade_recipe");
public static final ItemStack UPGRADE_ITEM = ItemBuilder.create()
.material(Material.HEART_OF_THE_SEA)
.name(Global.instance.color("&bGem Upgrade"))
.lore(Global.instance.color("&7Right click to upgrade your gem!"))
.enchant(Enchantment.LURE,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public static void addUpgradeRecipe() {
UltraBliss.getInstance().getServer().removeRecipe(key);
ShapedRecipe recipe = new ShapedRecipe(key, UPGRADE_ITEM);
recipe.shape("ABC", "DEF", "GHI");
recipe.setIngredient('A', Material.NETHERITE_INGOT);
recipe.setIngredient('B', Material.DIAMOND_BLOCK);
recipe.setIngredient('C', Material.NETHERITE_INGOT);
recipe.setIngredient('D', Material.DIAMOND_BLOCK);
recipe.setIngredient('E', Material.TRIDENT);
recipe.setIngredient('F', Material.DIAMOND_BLOCK);
recipe.setIngredient('G', Material.NETHERITE_INGOT);
recipe.setIngredient('H', Material.DIAMOND_BLOCK);
recipe.setIngredient('I', Material.NETHERITE_INGOT);
UltraBliss.getInstance().getServer().addRecipe(recipe);
}
}

View File

@@ -0,0 +1,28 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import me.trouper.ultrabliss.server.VirtualGems;
import me.trouper.ultrabliss.server.generic.Gem;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
public class DeathListener implements CustomListener {
@EventHandler
private void onPlayerDeath(PlayerDeathEvent e) {
Gem<?> gem = VirtualGems.getGem(e.getPlayer());
if (gem == null) return;
e.getItemsToKeep().add(gem.getItem());
e.getDrops().removeIf(drop -> drop.isSimilar(gem.getItem()));
}
@EventHandler
private void onRespawn(PlayerRespawnEvent e) {
SchedulerUtils.later(40,()->{
VirtualGems.downgradeGem(e.getPlayer());
});
}
}

View File

@@ -0,0 +1,204 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.papermc.paper.event.block.BlockPreDispenseEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerItemFrameChangeEvent;
import io.papermc.paper.event.player.PlayerPickItemEvent;
import me.trouper.ultrabliss.server.VirtualGems;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.block.Crafter;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.CrafterCraftEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
public class GemProtectionListeners implements CustomListener {
@EventHandler
private void onItemFrame(PlayerItemFrameChangeEvent e) {
if (!VirtualGems.isGem(e.getItemStack())) return;
if (e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) return;
e.setCancelled(true);
e.setItemStack(ItemBuilder.create()
.material(Material.TROPICAL_FISH)
.name(color("&6You are a clown!"))
.build());
VirtualGems.verifyGem((Player) e.getPlayer());
}
@EventHandler
private void onDispense(BlockPreDispenseEvent e) {
Container container = (Container) e.getBlock().getState();
e.setCancelled(VirtualGems.cleanInventory(container.getInventory()));
}
@EventHandler
private void onCraft(CrafterCraftEvent e) {
Container container = (Container) e.getBlock().getState();
e.setCancelled(VirtualGems.cleanInventory(container.getInventory()));
}
@EventHandler
private void invEvent(InventoryClickEvent e) {
VirtualGems.verifyGem((Player) e.getWhoClicked());
VirtualGems.cleanInventory(e.getInventory());
if (!VirtualGems.isGem(e.getCurrentItem())) return;
e.setCancelled(true);
e.getCurrentItem().setAmount(0);
}
@EventHandler
private void onPickup(EntityPickupItemEvent e) {
if (!VirtualGems.isGem(e.getItem().getItemStack())) return;
e.setCancelled(true);
e.getItem().setItemStack(new ItemStack(Material.AIR));
}
@EventHandler
private void onEat(PlayerItemConsumeEvent e) {
VirtualGems.verifyGem((Player) e.getPlayer());
if (!VirtualGems.isGem(e.getItem())) return;
e.setCancelled(true);
}
@EventHandler
private void onPlayerDrop(PlayerDropItemEvent e) {
VirtualGems.verifyGem((Player) e.getPlayer());
if (!VirtualGems.isGem(e.getItemDrop().getItemStack())) return;
e.setCancelled(true);
e.getItemDrop().setItemStack(new ItemStack(Material.AIR));
}
@EventHandler
private void onEntityDrop(EntityDropItemEvent e) {
if (!VirtualGems.isGem(e.getItemDrop().getItemStack())) return;
e.setCancelled(true);
e.getItemDrop().setItemStack(new ItemStack(Material.AIR));
}
@EventHandler
private void onBlockDrop(EntityDropItemEvent e) {
if (!VirtualGems.isGem(e.getItemDrop().getItemStack())) return;
e.setCancelled(true);
e.getItemDrop().setItemStack(new ItemStack(Material.AIR));
}
/* @EventHandler
public void onSwapItems(PlayerSwapHandItemsEvent e) {
if (e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) return;
e.setCancelled(true);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
if (e.getClickedInventory() != null && e.getClickedInventory().getType() != InventoryType.PLAYER) {
return;
}
Player p = (Player) e.getWhoClicked();
if (p.getGameMode() != GameMode.CREATIVE) {
p.sendMessage(color("&c&l--= START OF AN EVENT =--") );
p.sendMessage("SLOT: " + e.getSlot());
if (e.getClickedInventory().getItem(e.getSlot()) != null && e.getClickedInventory().getItem(e.getSlot()).isSimilar(p.getInventory().getItemInOffHand())) {
p.sendMessage("SLOT 2: " + e.getSlot());
e.setCancelled(true);
return;
}
p.sendMessage("OFF: " + p.getInventory().getItemInOffHand());
p.sendMessage(color("&6&l--= BEFORE TOOL CHECK 1 =--"));
if (p.getInventory().getItemInOffHand().getType() != Material.AIR) {
p.sendMessage("ITEM: " + e.getCurrentItem());
ItemStack offhandItem = p.getInventory().getItemInOffHand();
p.sendMessage("OFFHAND VAR: " + offhandItem);
ItemStack currentItem = e.getCurrentItem();
p.sendMessage("ITEM VAR: " + currentItem);
SchedulerUtils.later(1, () -> {
p.sendMessage("OFF 2: " + p.getInventory().getItemInOffHand());
p.sendMessage(color("&6&l--= BEFORE TOOL CHECK 2 =--"));
if (!p.getInventory().getItemInOffHand().equals(offhandItem)) {
p.sendMessage("SLOT 2: " + e.getSlot());
p.sendMessage("ITEM VAR 2: " + currentItem);
e.setCurrentItem(currentItem);
p.getInventory().setItemInOffHand(offhandItem);
p.sendMessage("SLOT 3: " + e.getSlot());
p.sendMessage("OFFHAND VAR 2: " + p.getInventory().getItemInOffHand());
p.sendMessage("OFF 3: " + p.getInventory().getItemInOffHand());
p.sendMessage(color("&c&l--= END OF EVENT =--"));
}
});
}
}
}*/
}
/*@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
ItemStack offhand = p.getInventory().getItemInOffHand();
ItemStack clicked = ItemBuilder.create().material(Material.AIR).build();
if (e.getClickedInventory() != null) {
clicked = e.getClickedInventory().getItem(e.getSlot());
}
if (p.getGameMode().equals(GameMode.CREATIVE)) return;
if (GemUtils.isGem(e.getCursor()) || GemUtils.isGem(e.getCurrentItem()) || GemUtils.isGem(e.getWhoClicked().getItemOnCursor())) {
e.setCancelled(true);
return;
}
p.getOpenInventory().getTopInventory().removeItem(gems.toArray(new ItemStack[0]));
p.getOpenInventory().getBottomInventory().removeItem(gems.toArray(new ItemStack[0]));
e.getInventory().removeItem(gems.toArray(new ItemStack[0]));
if (e.getClickedInventory() != null) {
e.getClickedInventory().removeItem(gems.toArray(new ItemStack[0]));
}
if (!GemUtils.isGem(clicked)) {
//e.getClickedInventory().setItem(e.getSlot(),clicked);
}
ItemStack finalClicked = clicked;
SchedulerUtils.later(1,()->{
p.getOpenInventory().getTopInventory().removeItem(gems.toArray(new ItemStack[0]));
p.getOpenInventory().getBottomInventory().removeItem(gems.toArray(new ItemStack[0]));
e.getInventory().removeItem(gems.toArray(new ItemStack[0]));
if (e.getClickedInventory() != null) {
e.getClickedInventory().removeItem(gems.toArray(new ItemStack[0]));
}
p.getInventory().removeItem(gems.toArray(new ItemStack[0]));
p.getInventory().setItemInOffHand(offhand);
if (!GemUtils.isGem(finalClicked)) {
//e.getClickedInventory().setItem(e.getSlot(),clicked);
}
});
}
@EventHandler
public void onSwap(PlayerSwapHandItemsEvent e) {
if (e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) return;
e.setCancelled(true);
}*/

View File

@@ -0,0 +1,17 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import me.trouper.ultrabliss.server.VirtualGems;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener implements CustomListener {
@EventHandler
private void onJoin(PlayerJoinEvent e) {
if (e.getPlayer().getScoreboardTags().contains("joined")) return;
e.getPlayer().getScoreboardTags().add("joined");
VirtualGems.setRandomGem(e.getPlayer());
}
}

View File

@@ -0,0 +1,47 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileHitEvent;
public class ProjectileHitListener implements CustomListener {
@EventHandler
private void onAstraTridentLand(ProjectileHitEvent e) {
if (e.getEntity() instanceof Trident t && t.getScoreboardTags().contains("astra-trident")) {
t.remove();
}
}
@EventHandler
private void onAstraTridentHit(ProjectileHitEvent e) {
if (e.getHitEntity() != null && e.getEntity() instanceof Trident t && t.getScoreboardTags().contains("astra-trident")) {
if (!(e.getHitEntity() instanceof LivingEntity victim)) return;
victim.damage(10,(Entity) e.getEntity().getShooter());
//victim.setHealth(victim.getHealth() - 4);
}
}
@EventHandler
private void onFireballLand(ProjectileHitEvent e) {
if (e.getHitBlock() != null && e.getEntity() instanceof Fireball f && f.getScoreboardTags().contains("fire-fireball")) {
// e.setCancelled(true);
//e.getHitBlock().getWorld().createExplosion(e.getHitBlock().getLocation(),4,false,false);
}
}
@EventHandler
private void onFireballHit(ProjectileHitEvent e) {
if (e.getHitEntity() != null && e.getEntity() instanceof Fireball f && f.getScoreboardTags().contains("fire-fireball")) {
if (!(e.getHitEntity() instanceof LivingEntity victim)) return;
// e.setCancelled(true);
//victim.getWorld().createExplosion(victim.getLocation(),4,false,false);
victim.setHealth(victim.getHealth() - 10);
victim.damage(1,(Entity) e.getEntity().getShooter());
}
}
}

View File

@@ -0,0 +1,68 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.misc.Cooldown;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.server.VirtualGems;
import me.trouper.ultrabliss.server.crafting.TradeItem;
import me.trouper.ultrabliss.utils.PlayerUtils;
import me.trouper.ultrabliss.utils.Text;
import net.kyori.adventure.text.Component;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Sound;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.meta.FireworkMeta;
public class TradeListener implements CustomListener {
Cooldown<Player> tradeCooldown = new Cooldown<>();
@EventHandler(priority = EventPriority.HIGHEST)
private void onTrade(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (!e.getAction().isRightClick()) return;
if (e.getItem() == null) return;
if (!p.getInventory().getItemInMainHand().isSimilar(TradeItem.TRADE_ITEM)) return;
if (tradeCooldown.isOnCooldown(p)) {
e.getPlayer().sendMessage(Component.text(Text.prefix("&cYour on cooldown! &7You can use it again in &e%s&7 seconds!".formatted(
(tradeCooldown.getCooldown(p)) / 1000L)
)));
return;
}
tradeCooldown.setCooldown(p, 5000);
PlayerUtils.subtractItems(p,TradeItem.TRADE_ITEM,1);
VirtualGems.setRandomGem(p);
p.sendMessage(Component.text(Text.prefix("You have traded your gem!")));
SoundPlayer swap = new SoundPlayer(p.getLocation(), Sound.BLOCK_BEACON_POWER_SELECT, 10,2F);
swap.playWithin(3);
Firework f = p.getWorld().spawn(p.getLocation(), Firework.class);
// Configure the Firework's meta
FireworkMeta fm = f.getFireworkMeta();
fm.addEffect(
FireworkEffect.builder()
.withColor(Color.RED)
.withColor(Color.WHITE)
.withColor(Color.ORANGE)
.with(FireworkEffect.Type.BURST)
.withTrail()
.withFlicker()
.build());
fm.setPower(1);
f.setFireworkMeta(fm);
SchedulerUtils.later(1,f::detonate);
}
}

View File

@@ -0,0 +1,42 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.utils.misc.Cooldown;
import me.trouper.ultrabliss.server.VirtualGems;
import me.trouper.ultrabliss.server.crafting.UpgradeItem;
import me.trouper.ultrabliss.utils.PlayerUtils;
import me.trouper.ultrabliss.utils.Text;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
public class UpgradeListener implements CustomListener {
Cooldown<Player> upgradeCooldown = new Cooldown<>();
@EventHandler(priority = EventPriority.HIGHEST)
private void onUpgrade(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (!e.getAction().isRightClick()) return;
if (e.getItem() == null) return;
if (!p.getInventory().getItemInMainHand().isSimilar(UpgradeItem.UPGRADE_ITEM)) return;
if (upgradeCooldown.isOnCooldown(p)) {
e.getPlayer().sendMessage(Component.text(color("&cYour on cooldown! &7You can use it again in &e%s&7 seconds!".formatted(
(upgradeCooldown.getCooldown(p))/1000L)
)));
return;
}
upgradeCooldown.setCooldown(p, 5000);
if (VirtualGems.upgradeGem(p)) {
PlayerUtils.subtractItems(p,UpgradeItem.UPGRADE_ITEM,1);
p.sendMessage(Component.text(Text.prefix("Your gem has been upgraded!")));
} else {
p.sendMessage(Component.text(Text.prefix("Your gem is already upgraded!")));
}
}
}

View File

@@ -0,0 +1,47 @@
package me.trouper.ultrabliss.server.events;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.utils.misc.Cooldown;
import me.trouper.ultrabliss.server.VirtualGems;
import me.trouper.ultrabliss.server.crafting.UpgradeItem;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.Text;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class UseListener implements CustomListener {
Cooldown<Map<UUID,Integer>> gemCooldown = new Cooldown<>();
@EventHandler(priority = EventPriority.HIGH)
private void onGemUse(PlayerSwapHandItemsEvent e) {
Player p = e.getPlayer();
UUID u = e.getPlayer().getUniqueId();
Gem<?> gem = VirtualGems.getGem(e.getPlayer());
if (p.getInventory().getItemInMainHand().isSimilar(UpgradeItem.UPGRADE_ITEM)) return;
if (gem == null) return;
if (!p.getInventory().getItemInMainHand().equals(gem.getItem()) && !p.getInventory().getItemInOffHand().equals(gem.getItem())) return;
e.setCancelled(true);
Map<UUID,Integer> gemCool = new HashMap<>();
gemCool.put(u,gem.getDataID());
if (gemCooldown.isOnCooldown(gemCool)) {
p.sendMessage(Component.text(color(Text.prefix("&cYour gem is on cooldown! &7You can use it again in &e%s&7 seconds!").formatted(
(gemCooldown.getCooldown(gemCool))/1000L)
)));
return;
}
gemCooldown.setCooldown(gemCool, gem.getCooldown() * 1000L);
try {
gem.getOnUse().accept(e.getPlayer());
p.sendMessage(Text.prefix("You successfully used your gem ability"));
} catch (Exception ignored) {}
}
}

View File

@@ -0,0 +1,71 @@
package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.DisplayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class AstraUpgrade extends Gem<AstraUpgrade> {
private static final ItemStack ASTRA_GEM_UPGRADE = ItemBuilder.create()
.material(Material.NAUTILUS_SHELL)
.name(Global.instance.color("&d&lAstra Gem &5\uD83E\uDC45"))
.lore(Global.instance.color("&8➥ &7Resistance 2"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&e★ &fShoot 3 Tridents"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&7Press &n(Swap-Hands)&r&7 to use &e★&7 ability"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public AstraUpgrade() {
super(1201,ASTRA_GEM_UPGRADE,
List.of(new PotionEffect(PotionEffectType.RESISTANCE,60,1)),
AstraUpgrade::useAbility,
15,
null,
null
);
}
private static void useAbility(Player p) {
for (int height = 0; height < 20; height++) {
int finalHeight = height;
SchedulerUtils.later(height/2, () -> {
DisplayUtils.ring(p.getLocation().clone().add(0, (double) finalHeight / 10, 0), 2, Color.AQUA, 1);
});
}
shootAstraTrident(p,0);
shootAstraTrident(p,5);
shootAstraTrident(p,10);
}
private static void shootAstraTrident(Player p, int tickdelay) {
SchedulerUtils.later(tickdelay,()->{
SoundPlayer shoot = new SoundPlayer(p.getLocation(), Sound.ITEM_TRIDENT_THROW,20,0.6F);
shoot.playWithin(30);
p.getWorld().spawn(p.getEyeLocation(), Trident.class,(trident -> {
trident.setShooter(p);
trident.setVelocity(p.getLocation().getDirection().multiply(2));
trident.getScoreboardTags().add("astra-trident");
}));
});
}
}

View File

@@ -1,10 +1,13 @@
package me.trouper.ultrabliss.server.gems; package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder; import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import me.trouper.ultrabliss.server.GemData; import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.Text; import me.trouper.ultrabliss.utils.Text;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@@ -12,16 +15,7 @@ import org.bukkit.potion.PotionEffectType;
import java.util.List; import java.util.List;
public class FireGem { public class FireUpgrade extends Gem<FireUpgrade> {
private static final ItemStack FIRE_GEM = ItemBuilder.create()
.material(Material.MAGMA_CREAM)
.name(Text.color("&c&lFire Gem"))
.lore(Text.color("&8➥ &7Fire Resistance"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
private static final ItemStack FIRE_GEM_UPGRADE = ItemBuilder.create() private static final ItemStack FIRE_GEM_UPGRADE = ItemBuilder.create()
.material(Material.MAGMA_CREAM) .material(Material.MAGMA_CREAM)
.name(Text.color("&c&lFire Gem &6\uD83E\uDC45")) .name(Text.color("&c&lFire Gem &6\uD83E\uDC45"))
@@ -34,12 +28,22 @@ public class FireGem {
.flag(ItemFlag.HIDE_ENCHANTS) .flag(ItemFlag.HIDE_ENCHANTS)
.build(); .build();
public static GemData gem = new GemData.Builder(1000) public FireUpgrade() {
.setPassive(List.of( super(1001, FIRE_GEM_UPGRADE,
new PotionEffect(PotionEffectType.FIRE_RESISTANCE,20*5,1) List.of(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 60, 0)),
)) FireUpgrade::useAbility,
.setItem(FIRE_GEM) 15,
.build(); null,
null
);
}
public static GemData private static void useAbility(Player player) {
Location eye = player.getEyeLocation();
Fireball shoot = eye.getWorld().spawn(eye, Fireball.class, fireball -> {});
shoot.setVelocity(eye.getDirection().multiply(0.5));
shoot.setIsIncendiary(false);
shoot.setYield(4);
shoot.getScoreboardTags().add("fire-fireball");
}
} }

View File

@@ -0,0 +1,67 @@
package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.DisplayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class LifeUpgrade extends Gem<LifeUpgrade> {
private static final ItemStack LIFE_GEM_UPGRADE = ItemBuilder.create()
.material(Material.RED_DYE)
.name(Global.instance.color("&c&lLife Gem &6\uD83E\uDC45"))
.lore(Global.instance.color("&8➥ &7Regeneration 2"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&e★ &fGain 10 Extra Hearts (20s)"))
.lore(Global.instance.color("&e★ &fEnemies Loose 4 Hearts (20s)"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&7Press &n(Swap-Hands)&r&7 to use &e★&7 ability"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public LifeUpgrade() {
super(1301,LIFE_GEM_UPGRADE,
List.of(new PotionEffect(PotionEffectType.REGENERATION,60,1)),
LifeUpgrade::onUse,
15,
null,
null
);
}
private static void onUse(Player p) {
p.registerAttribute(Attribute.GENERIC_MAX_HEALTH);
p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(40);
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION,200,3));
List<LivingEntity> list = p.getLocation().getNearbyLivingEntities(5,5,5).stream().toList();
for (int i = 0; i < 10; i++) {
DisplayUtils.ring(p.getLocation().add(0,i/10D,0),0.5, Color.ORANGE,1);
}
for (LivingEntity entity : list) {
if (entity.equals(p) || !(entity instanceof Player)) continue;
entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(12);
SchedulerUtils.later(400,()->{
entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
});
for (int i = 0; i < 20; i++) {
DisplayUtils.ring(entity.getLocation().add(0,i/10D,0),0.5,Color.RED,1);
}
}
SchedulerUtils.later(400,()->{
p.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
});
}
}

View File

@@ -0,0 +1,58 @@
package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.DisplayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class PuffUpgrade extends Gem<PuffUpgrade> {
private static final ItemStack PUFF_GEM_UPGRADE = ItemBuilder.create()
.material(Material.PUFFERFISH)
.name(Global.instance.color("&b&lPuff Gem &9\uD83E\uDC45"))
.lore(Global.instance.color("&8➥ &7Jump Boost 2"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&e★ &fLaunch Enemies"))
.lore(Global.instance.color("&e★ &fGives Enemies Mining Fatigue (20s)"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&7Press &n(Swap-Hands)&r&7 to use &e★&7 ability"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public PuffUpgrade() {
super(1400,PUFF_GEM_UPGRADE,
List.of(new PotionEffect(PotionEffectType.JUMP_BOOST,60,1)),
PuffUpgrade::onUse,
15,
null,
null
);
}
private static void onUse(Player p) {
SoundPlayer sp = new SoundPlayer(p.getLocation(), Sound.ENTITY_PUFFER_FISH_BLOW_OUT,10,0.7F);
sp.playWithin(30);
for (int rad = 0; rad < 30; rad++) {
DisplayUtils.ring(p.getLocation().add(0,0.2,0),rad/10D, Color.WHITE,1);
}
List<LivingEntity> list = p.getLocation().getNearbyLivingEntities(5,5,5).stream().toList();
for (LivingEntity entity : list) {
if (entity.equals(p)) continue;
entity.setVelocity(entity.getVelocity().setY(2));
entity.addPotionEffect(new PotionEffect(PotionEffectType.MINING_FATIGUE,400,2));
}
}
}

View File

@@ -0,0 +1,62 @@
package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.DisplayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class SpeedUpgrade extends Gem<SpeedUpgrade> {
private static final ItemStack SPEED_GEM_UPGRADE = ItemBuilder.create()
.material(Material.SUGAR)
.name(Global.instance.color("&f&lSpeed Gem &7\uD83E\uDC45"))
.lore(Global.instance.color("&8➥ &7Speed 2"))
.lore(Global.instance.color("&8➥ &7Haste 2"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&e★ &fGives Enemies Slowness (5s)"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&7Press &n(Swap-Hands)&r&7 to use &e★&7 ability"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public SpeedUpgrade() {
super(1501,SPEED_GEM_UPGRADE,
List.of(new PotionEffect(PotionEffectType.HASTE,60,1),
new PotionEffect(PotionEffectType.SPEED,60,1)),
SpeedUpgrade::onUse,
15,
null,
null
);
}
private static void onUse(Player p) {
SoundPlayer sp = new SoundPlayer(p.getLocation(), Sound.ENTITY_CAT_AMBIENT,10,1.3F);
sp.playWithin(30);
for (int height = 0; height < 20; height++) {
int finalHeight = height;
SchedulerUtils.later(height/5, () -> {
DisplayUtils.ring(p.getLocation().clone().add(0, (double) finalHeight / 10, 0), 2, Color.YELLOW, 1);
});
}
List<LivingEntity> list = p.getLocation().getNearbyLivingEntities(5,5,5).stream().toList();
for (LivingEntity entity : list) {
if (entity.equals(p)) continue;
entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS,100,3));
}
}
}

View File

@@ -0,0 +1,60 @@
package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.DisplayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class StrengthUpgrade extends Gem<StrengthUpgrade> {
private static final ItemStack STRENGTH_GEM_UPGRADE = ItemBuilder.create()
.material(Material.COOKED_BEEF)
.name(Global.instance.color("&4&lStrength Gem &c\uD83E\uDC45"))
.lore(Global.instance.color("&8➥ &7Strength 2"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&e★ &fGives Enemies Wither (10s)"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&7Press &n(Swap-Hands)&r&7 to use &e★&7 ability"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public StrengthUpgrade() {
super(1601,STRENGTH_GEM_UPGRADE,
List.of(new PotionEffect(PotionEffectType.STRENGTH,60,1)),
StrengthUpgrade::onUse,
15,
null,
null
);
}
private static void onUse(Player p) {
SoundPlayer sp = new SoundPlayer(p.getLocation(), Sound.ENTITY_ZOMBIE_VILLAGER_CURE,10,0.7F);
sp.playWithin(30);
for (int height = 0; height < 20; height++) {
int finalHeight = height;
SchedulerUtils.later(height, () -> {
DisplayUtils.ring(p.getLocation().clone().add(0, (double) finalHeight / 10, 0), 2, Color.RED, 1);
});
}
List<LivingEntity> list = p.getLocation().getNearbyLivingEntities(5,5,5).stream().toList();
for (LivingEntity entity : list) {
if (entity.equals(p)) continue;
entity.addPotionEffect(new PotionEffect(PotionEffectType.WITHER,200,1));
}
}
}

View File

@@ -0,0 +1,57 @@
package me.trouper.ultrabliss.server.gems;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultrabliss.server.generic.Gem;
import me.trouper.ultrabliss.utils.DisplayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class WealthUpgrade extends Gem<WealthUpgrade> {
private static final ItemStack WEALTH_GEM_UPGRADE = ItemBuilder.create()
.material(Material.EMERALD)
.name(Global.instance.color("&e&lWealth Gem &6\uD83E\uDC45"))
.lore(Global.instance.color("&8➥ &7Hero of the Village 4"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&e★ &fSpawn Villager"))
.lore(Global.instance.color(""))
.lore(Global.instance.color("&7Press &n(Swap-Hands)&r&7 to use &e★&7 ability"))
.enchant(Enchantment.MENDING,1)
.flag(ItemFlag.HIDE_ENCHANTS)
.build();
public WealthUpgrade() {
super(1701,WEALTH_GEM_UPGRADE,
List.of(new PotionEffect(PotionEffectType.HERO_OF_THE_VILLAGE,60,3)),
WealthUpgrade::onUse,
15,
null,
null
);
}
private static void onUse(Player p) {
SoundPlayer sp = new SoundPlayer(p.getLocation(), Sound.ENTITY_VILLAGER_YES,10,1.4F);
sp.playWithin(30);
for (int height = 0; height < 20; height++) {
int finalHeight = height;
SchedulerUtils.later(height/4, () -> {
DisplayUtils.ring(p.getLocation().clone().add(0, (double) finalHeight / 10, 0), 1, Color.LIME, 1);
});
}
p.getLocation().getWorld().spawn(p.getLocation(), Villager.class);
}
}

View File

@@ -0,0 +1,57 @@
package me.trouper.ultrabliss.server.generic;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.List;
import java.util.function.Consumer;
public abstract class Gem<T extends Gem<?>> {
private final int dataID;
private final ItemStack item;
private final List<PotionEffect> passive;
private final Consumer<Player> onUse;
private final int cooldown;
private final Gem<?> upgrade;
private final Gem<?> downgrade;
public Gem(int dataID, ItemStack item, List<PotionEffect> passive, Consumer<Player> onUse, int cooldown, Gem<?> upgrade, Gem<?> downgrade) {
this.dataID = dataID;
this.item = item;
this.passive = passive;
this.onUse = onUse;
this.cooldown = cooldown;
this.upgrade = upgrade;
this.downgrade = downgrade;
}
public int getDataID() {
return dataID;
}
public ItemStack getItem() {
return item;
}
public List<PotionEffect> getPassive() {
return passive;
}
public Consumer<Player> getOnUse() {
return onUse;
}
public int getCooldown() {
return cooldown;
}
public Gem<?> getUpgrade() {
return upgrade;
}
public Gem<?> getDowngrade() {
return downgrade;
}
}

View File

@@ -0,0 +1,30 @@
package me.trouper.ultrabliss.server.generic;
import me.trouper.ultrabliss.server.gems.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Registry {
public static final Gem<?> ASTRA_UPGRADE_GEM = new AstraUpgrade();
public static final Gem<?> FIRE_UPGRADE_GEM = new FireUpgrade();
public static final Gem<?> LIFE_UPGRADE_GEM = new LifeUpgrade();
public static final Gem<?> PUFF_UPGRADE_GEM = new PuffUpgrade();
public static final Gem<?> SPEED_UPGRADE_GEM = new SpeedUpgrade();
public static final Gem<?> STRENGTH_UPGRADE_GEM = new StrengthUpgrade();
public static final Gem<?> WEALTH_UPGRADE_GEM = new WealthUpgrade();
public static Map<Gem<?>,Gem<?>> upgrades = new HashMap<>();
public static List<Gem<?>> set = List.of(
ASTRA_UPGRADE_GEM,
FIRE_UPGRADE_GEM,
LIFE_UPGRADE_GEM,
PUFF_UPGRADE_GEM,
SPEED_UPGRADE_GEM,
STRENGTH_UPGRADE_GEM,
WEALTH_UPGRADE_GEM
);
}

View File

@@ -0,0 +1,144 @@
package me.trouper.ultrabliss.utils;
import io.github.itzispyder.pdk.Global;
import io.github.itzispyder.pdk.utils.misc.Randomizer;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
public class DisplayUtils implements Global {
public static final Function<Particle, Consumer<Location>> PARTICLE_FACTORY = particle -> l -> l.getWorld().spawnParticle(particle, l, 1, 0, 0, 0, 0);
public static final BiFunction<Color, Float, Consumer<Location>> DUST_PARTICLE_FACTORY = (color, thickness) -> {
Particle.DustOptions dust = new Particle.DustOptions(color, thickness);
return l -> l.getWorld().spawnParticle(Particle.DUST, l, 1, 0, 0, 0, 0, dust);
};
public static final Function<Boolean, Consumer<Location>> FLAME_PARTICLE_FACTORY = soul -> {
Particle flame = soul ? Particle.SOUL_FIRE_FLAME : Particle.FLAME;
return l -> l.getWorld().spawnParticle(flame, l, 1, 0, 0, 0, 0);
};
public static void ring(Location loc, double radius, Color color, float thickness) {
ring(loc, radius, DUST_PARTICLE_FACTORY.apply(color, thickness));
}
public static void wave(Location loc, double radius, Color color, float thickness, double gap) {
wave(loc, radius, DUST_PARTICLE_FACTORY.apply(color, thickness), gap);
}
public static void ring(Location loc, double radius, Consumer<Location> action) {
for (int theta = 0; theta < 360; theta += 10) {
double x = Math.cos(Math.toRadians(theta)) * radius;
double z = Math.sin(Math.toRadians(theta)) * radius;
Location newLoc = loc.clone().add(x, 0, z);
action.accept(newLoc);
}
}
public static void wave(Location loc, double radius, Consumer<Location> action, double gap) {
AtomicReference<Double> i = new AtomicReference<>(gap);
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance.getPlugin(), () -> {
if (i.get() >= radius) {
return;
}
ring(loc, i.get(), action);
i.set(i.get() + gap);
}, 0, 1);
}
public static void disc(Location loc, double radius, Consumer<Location> action, double gap) {
for (double i = gap; i < radius; i += gap) {
ring(loc, i, action);
}
}
public static void helix(Location loc, double radius, Consumer<Location> action, double gap, int height) {
int theta = 0;
for (double y = 0; y <= height; y += gap) {
double x = Math.cos(Math.toRadians(theta)) * radius;
double z = Math.sin(Math.toRadians(theta)) * radius;
Location newLoc = loc.clone().add(x, y, z);
action.accept(newLoc);
theta += 10;
}
}
public static void vortex(Location loc, double radius, Consumer<Location> action, double gapH, double gapV, int height) {
double r = radius;
int theta = 0;
for (double y = 0; y <= height; y += gapV) {
double x = Math.cos(Math.toRadians(theta)) * r;
double z = Math.sin(Math.toRadians(theta)) * r;
Location newLoc = loc.clone().add(x, y, z);
action.accept(newLoc);
r += gapH;
theta += 10;
}
}
public static void beam(Location loc, Consumer<Location> action, double gap, int height) {
for (double y = 0; y <= height; y += gap) {
Location newLoc = loc.clone().add(0, y, 0);
action.accept(newLoc);
}
}
public static void arc(Location loc, double radius, int angleFrom, int angleTo, Consumer<Location> action) {
for (int theta = angleFrom; theta < angleTo; theta += 10) {
double x = Math.cos(Math.toRadians(theta)) * radius;
double z = Math.sin(Math.toRadians(theta)) * radius;
Location newLoc = loc.clone().add(x, 0, z);
action.accept(newLoc);
}
}
public static void fan(Location loc, double radius, int angleFrom, int angleTo, Consumer<Location> action, double gap) {
for (double i = gap; i < radius; i += gap) {
arc(loc, i, angleFrom, angleTo, action);
}
}
public static void fanWave(Location loc, double radius, int sections, Consumer<Location> action, double gap) {
double arcLength = 360.0 / sections;
AtomicReference<Double> i = new AtomicReference<>(0.0);
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance.getPlugin(), () -> {
if (i.get() >= 360) {
return;
}
double start = i.get();
fan(loc, radius, (int)start, (int)(start + arcLength), action, gap);
i.set(i.get() + arcLength);
}, 0, 5);
}
public static void fanWaveRandom(Location loc, double radius, int sections, Consumer<Location> action, double gap) {
double arcLength = 360.0 / sections;
List<Double> ints = new ArrayList<>();
for (double start = 0; start < 360; start += arcLength) {
ints.add(start);
}
AtomicInteger i = new AtomicInteger(0);
Randomizer random = new Randomizer();
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance.getPlugin(), () -> {
if (i.get() >= sections) {
return;
}
double start = random.getRandomElement(ints);
ints.remove(start);
fan(loc, radius, (int)start, (int)(start + arcLength), action, gap);
i.getAndIncrement();
}, 0, 5);
}
}

View File

@@ -0,0 +1,16 @@
package me.trouper.ultrabliss.utils;
import java.util.HashMap;
import java.util.Map;
public class MapUtils {
public static <K, V> Map<V, K> swapValues(Map<K, V> originalMap) {
Map<V, K> swappedMap = new HashMap<>();
for (Map.Entry<K, V> entry : originalMap.entrySet()) {
swappedMap.put(entry.getValue(), entry.getKey());
}
return swappedMap;
}
}

View File

@@ -0,0 +1,43 @@
package me.trouper.ultrabliss.utils;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class PlayerUtils {
/**
* Removes a specified amount of a specific ItemStack from a player's inventory.
*
* @param player The player from whose inventory items will be removed.
* @param item The ItemStack to be removed.
* @param amount The amount of items to remove.
* @return {@code true} if the specified amount of items was successfully removed,
* {@code false} if the player does not have enough items.
*/
public static boolean subtractItems(Player player, ItemStack item, int amount) {
Inventory inventory = player.getInventory();
int totalAmountToRemove = amount;
for (ItemStack stack : inventory.getContents()) {
if (stack != null && stack.isSimilar(item)) {
int stackAmount = stack.getAmount();
if (stackAmount <= totalAmountToRemove) {
totalAmountToRemove -= stackAmount;
inventory.removeItem(stack);
} else {
stack.setAmount(stackAmount - totalAmountToRemove);
totalAmountToRemove = 0;
break;
}
if (totalAmountToRemove == 0) {
return true; // Successfully removed the items
}
}
}
return false; // Player didn't have enough items
}
}

View File

@@ -1,4 +1,13 @@
name: UltraBliss name: UltraBliss
version: '0.0.1' version: '0.0.1'
main: me.trouper.ultraBliss.UltraBliss main: me.trouper.ultrabliss.UltraBliss
api-version: '1.21' api-version: '1.21'
permissions:
ultrabliss.admin:
default: op
description: Access to the admin command
commands:
bliss:
permission: ultrabliss.admin
usage: Its complicated.
description: Control the gems