diff --git a/.gradle/8.8/checksums/checksums.lock b/.gradle/8.8/checksums/checksums.lock index 5a1120c..204d4a8 100644 Binary files a/.gradle/8.8/checksums/checksums.lock and b/.gradle/8.8/checksums/checksums.lock differ diff --git a/.gradle/8.8/executionHistory/executionHistory.bin b/.gradle/8.8/executionHistory/executionHistory.bin index a1af76c..08884ea 100644 Binary files a/.gradle/8.8/executionHistory/executionHistory.bin and b/.gradle/8.8/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.8/executionHistory/executionHistory.lock b/.gradle/8.8/executionHistory/executionHistory.lock index 6e7a580..4aa7b91 100644 Binary files a/.gradle/8.8/executionHistory/executionHistory.lock and b/.gradle/8.8/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.8/fileHashes/fileHashes.bin b/.gradle/8.8/fileHashes/fileHashes.bin index b92adb4..03d2948 100644 Binary files a/.gradle/8.8/fileHashes/fileHashes.bin and b/.gradle/8.8/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.8/fileHashes/fileHashes.lock b/.gradle/8.8/fileHashes/fileHashes.lock index 610ab4f..9781c70 100644 Binary files a/.gradle/8.8/fileHashes/fileHashes.lock and b/.gradle/8.8/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.8/fileHashes/resourceHashesCache.bin b/.gradle/8.8/fileHashes/resourceHashesCache.bin index ce098b5..7ca2721 100644 Binary files a/.gradle/8.8/fileHashes/resourceHashesCache.bin and b/.gradle/8.8/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index b603c89..80d64ac 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/build.gradle b/build.gradle index 866683d..d598ebb 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'me.trouper' -version = '1.0-SNAPSHOT' +version = '1.0.0' jar { from { diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 7975c6b..88cbe1a 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/me/trouper/armorsmp/ArmorSMP.java b/src/main/java/me/trouper/armorsmp/ArmorSMP.java index 4ff1cda..34ed7d7 100644 --- a/src/main/java/me/trouper/armorsmp/ArmorSMP.java +++ b/src/main/java/me/trouper/armorsmp/ArmorSMP.java @@ -3,6 +3,7 @@ package me.trouper.armorsmp; import io.github.itzispyder.pdk.PDK; import io.github.itzispyder.pdk.utils.misc.Timer; import me.trouper.armorsmp.server.Manager; +import org.bukkit.NamespacedKey; import org.bukkit.plugin.java.JavaPlugin; public final class ArmorSMP extends JavaPlugin { @@ -40,6 +41,9 @@ public final class ArmorSMP extends JavaPlugin { public static ArmorSMP getInstance() { return instance; } + public NamespacedKey getNameSpace() { + return new NamespacedKey(getInstance(),"armor_smp"); + } public Manager getManager() { return manager; } diff --git a/src/main/java/me/trouper/armorsmp/data/Unique.java b/src/main/java/me/trouper/armorsmp/data/Unique.java index 0ac2ff0..8449c0a 100644 --- a/src/main/java/me/trouper/armorsmp/data/Unique.java +++ b/src/main/java/me/trouper/armorsmp/data/Unique.java @@ -1,6 +1,7 @@ package me.trouper.armorsmp.data; import io.github.itzispyder.pdk.plugin.builders.ItemBuilder; +import io.github.itzispyder.pdk.utils.DisplayUtils; import io.github.itzispyder.pdk.utils.misc.SoundPlayer; import io.github.itzispyder.pdk.utils.raytracers.CustomDisplayRaytracer; import me.trouper.armorsmp.ArmorSMP; @@ -9,6 +10,8 @@ import me.trouper.armorsmp.utils.Text; import me.trouper.armorsmp.utils.Verbose; import me.trouper.armorsmp.utils.ItemUtils; import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; @@ -28,17 +31,17 @@ public enum Unique { .lore(Text.legacyColor("&bAbilities:")) .lore(Text.legacyColor("&3| &75 Extra Hearts")) .lore(Text.legacyColor("&3| &7Fire Resistence")) - .enchant(Enchantment.BINDING_CURSE,1) - .enchant(Enchantment.PROTECTION,4) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.MENDING,1) - .enchant(Enchantment.RESPIRATION,3) - .enchant(Enchantment.AQUA_AFFINITY,1) + .enchant(Enchantment.BINDING_CURSE, 1) + .enchant(Enchantment.PROTECTION, 4) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.MENDING, 1) + .enchant(Enchantment.RESPIRATION, 3) + .enchant(Enchantment.AQUA_AFFINITY, 1) + .attribute(Attribute.MAX_HEALTH, new AttributeModifier(ArmorSMP.getInstance().getNameSpace(),10, AttributeModifier.Operation.ADD_NUMBER)) .customModelData(2) .build(), "Netherite Helmet", (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE,21,0,true,false,false)); - p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,25,2,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 21, 0, true, false, false)); }, (p) -> { }, 50), DRAGON_EGG(ItemBuilder.create() @@ -48,33 +51,34 @@ public enum Unique { .lore(Text.legacyColor(" &1- &7Shoot Dragon's Breath for 7 Seconds")) .lore(Text.legacyColor("&3| &7Resistence I")) .lore(Text.legacyColor("&3| &7Strength I")) - .enchant(Enchantment.BINDING_CURSE,1) - .enchant(Enchantment.PROTECTION,4) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.MENDING,1) + .enchant(Enchantment.BINDING_CURSE, 1) + .enchant(Enchantment.PROTECTION, 4) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.MENDING, 1) .customModelData(3) .build(), "Dragon Egg", (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH,21,0,true,false,false)); - p.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE,21,0,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH, 21, 0, true, false, false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE, 21, 0, true, false, false)); }, (p) -> { World world = p.getWorld(); - + Location eyeLocation = p.getEyeLocation(); Vector direction = eyeLocation.getDirection(); - - Location hit = CustomDisplayRaytracer.trace(eyeLocation,direction,30,point -> { + + Location hit = CustomDisplayRaytracer.trace(eyeLocation, direction, 30, point -> { Location particleLocation = point.getLoc(); world.spawnParticle(Particle.DRAGON_BREATH, particleLocation, 10, 0.2, 0.2, 0.2, 0.01); return !point.getBlock().isPassable(); }).getLoc(); - + AreaEffectCloud cloud = (AreaEffectCloud) world.spawnEntity(hit, EntityType.AREA_EFFECT_CLOUD); cloud.setRadius(3.0f); - cloud.setDuration(200); + cloud.setDuration(200); cloud.setParticle(Particle.DRAGON_BREATH); - cloud.addCustomEffect(PotionEffectType.INSTANT_DAMAGE.createEffect(1,1),true); + cloud.addCustomEffect(PotionEffectType.INSTANT_DAMAGE.createEffect(1, 1), true); cloud.setOwnerUniqueId(p.getUniqueId()); + p.getWorld().playSound(p.getLocation(),Sound.ENTITY_ENDER_DRAGON_GROWL,SoundCategory.MASTER,10,1); }, 50), LEGGINGS(ItemBuilder.create() .material(Material.NETHERITE_LEGGINGS) @@ -82,59 +86,54 @@ public enum Unique { .lore(Text.legacyColor("&3| &7Back-Up")) .lore(Text.legacyColor(" &1- &7Create a shield around you knocking players away")) .lore(Text.legacyColor("&3| &7Resistence I")) - .enchant(Enchantment.BINDING_CURSE,1) - .enchant(Enchantment.PROTECTION,4) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.MENDING,1) - .enchant(Enchantment.SWIFT_SNEAK,3) + .enchant(Enchantment.BINDING_CURSE, 1) + .enchant(Enchantment.PROTECTION, 4) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.MENDING, 1) + .enchant(Enchantment.SWIFT_SNEAK, 3) .customModelData(4) .build(), "Netherite Leggings", (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE,21,0,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE, 21, 0, true, false, false)); }, (p) -> { - Stream toKnockBack = p.getNearbyEntities(10,10,10).stream().filter(target -> { - if (!(target instanceof Player v)) return false; - boolean tooClose = target.getLocation().distance(p.getLocation()) < 10; - boolean self = target.getUniqueId().equals(p.getUniqueId()); - boolean trusted = ArmorSMP.getInstance().getManager().trust.getTrustees(p).contains(v.getUniqueId().toString()); - return tooClose && !self && !trusted; - }); - toKnockBack.forEach((target -> { - Vector direction = target.getLocation().toVector().subtract(p.getLocation().toVector()); - direction.normalize(); - direction.multiply(2); - direction.setY(direction.getY() + 0.5); - - target.setVelocity(direction); - })); AtomicBoolean cancelShield = new AtomicBoolean(); - Bukkit.getScheduler().runTaskLater(ArmorSMP.getInstance(),(task)->{ + Bukkit.getScheduler().runTaskLater(ArmorSMP.getInstance(), task -> { cancelShield.set(true); - },120); - Bukkit.getScheduler().runTaskTimer(ArmorSMP.getInstance(), (task) -> { - if (cancelShield.get()) task.cancel(); + p.getWorld().playSound(p.getLocation(),Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE,SoundCategory.MASTER,5,1); + }, 120); + p.getWorld().playSound(p.getLocation(),Sound.BLOCK_BEACON_ACTIVATE,SoundCategory.MASTER,5,1.5F); + Bukkit.getScheduler().runTaskTimer(ArmorSMP.getInstance(), task -> { + if (cancelShield.get()) { + task.cancel(); + return; + } + World w = p.getWorld(); Particle.DustOptions dust = new Particle.DustOptions(Color.AQUA, 0.5F); - Display.sphere(p.getEyeLocation(), 5.0, 0.5, 0.5, point -> { - w.spawnParticle(Particle.DUST, point, 1, 0, 0, 0, 0, dust); - }); - List targets = new ArrayList<>(w.getNearbyEntities(p.getLocation(), 10, 10, 10, entity -> - entity instanceof LivingEntity living && !living.isDead() && living != p && living.getLocation().distance(p.getLocation()) < 5 - )); + Display.sphere(p.getEyeLocation(), 5.0, 0.5, 0.5, point -> + w.spawnParticle(Particle.DUST, point, 1, 0, 0, 0, 0, dust) + ); + + w.getNearbyEntities(p.getLocation(), 10, 10, 10).stream() + .filter(entity -> entity instanceof LivingEntity living + && !ArmorSMP.getInstance().getManager().trust.getTrustees(p).contains(living.getUniqueId().toString()) + && !living.getUniqueId().equals(p.getUniqueId()) + && !living.isDead() + && living.getLocation().distance(p.getLocation()) < 5) + .map(entity -> (LivingEntity) entity) + .forEach(living -> { + new SoundPlayer(living.getLocation(), Sound.ITEM_SHIELD_BLOCK, 1, 1).playWithin(16); + Vector direction = living.getLocation().toVector() + .subtract(p.getEyeLocation().toVector()) + .normalize() + .multiply(0.5) + .setY(0.1); + living.setVelocity(direction); + w.spawnParticle(Particle.POOF, living.getLocation().clone().add(0, 1, 0), 10, 0.2, 1, 0.2, 0.1); + }); + }, 0, 2); - targets.forEach(target -> { - if (target instanceof LivingEntity living) { - SoundPlayer blockSound = new SoundPlayer(target.getLocation(), Sound.ITEM_SHIELD_BLOCK, 1, 1); - Vector direction = target.getLocation().toVector().subtract(p.getEyeLocation().toVector()).normalize(); - double strength = 2.0; - double verticalMultiplier = 0.5; - living.setVelocity(direction.multiply(strength).setY(verticalMultiplier)); - blockSound.playWithin(10); - w.spawnParticle(Particle.POOF,target.getLocation().clone().add(0,1,0),10,0.2,1,0.2,0.1); - } - }); - }, 0,2); }, 45), BOOTS(ItemBuilder.create() .material(Material.NETHERITE_BOOTS) @@ -142,74 +141,94 @@ public enum Unique { .lore(Text.legacyColor("&3| &7Dash")) .lore(Text.legacyColor(" &1- &7Launch yourself forwards")) .lore(Text.legacyColor("&3| &7Speed 1")) - .enchant(Enchantment.BINDING_CURSE,1) - .enchant(Enchantment.PROTECTION,4) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.MENDING,1) - .enchant(Enchantment.SOUL_SPEED,3) - .enchant(Enchantment.FEATHER_FALLING,4) - .enchant(Enchantment.DEPTH_STRIDER,3) + .enchant(Enchantment.BINDING_CURSE, 1) + .enchant(Enchantment.PROTECTION, 4) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.MENDING, 1) + .enchant(Enchantment.SOUL_SPEED, 3) + .enchant(Enchantment.FEATHER_FALLING, 4) + .enchant(Enchantment.DEPTH_STRIDER, 3) .customModelData(5) .build(), "Netherite Boots", (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,21,0,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 21, 0, true, false, false)); }, (p) -> { - Vector direction = p.getLocation().getDirection(); - Vector velocity = direction.multiply(4); // TODO: Test Vector + Vector direction = p.getLocation().getDirection(); + Vector velocity = direction.multiply(3).setY(1.5); - p.setVelocity(velocity); + p.setVelocity(velocity); + p.getWorld().playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF,5,1); + DisplayUtils.wave(p.getLocation(),3,(point)->{ + point.getWorld().spawnParticle(Particle.WHITE_SMOKE,point,1,0,0,0,0.02); + },0.2); + Bukkit.getScheduler().runTaskTimer(ArmorSMP.getInstance(),(task)->{ + if (p.isOnGround()) { + Verbose.send("Canceling because on ground"); + task.cancel(); + return; + } + p.getWorld().spawnParticle(Particle.WHITE_ASH,p.getLocation(),1,0,0,0,0.2); + },3,1); }, 50), MACE(ItemBuilder.create() .material(Material.MACE) .lore(Text.legacyColor("&bAbilities:")) .lore(Text.legacyColor("&3| &7Speed 1")) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.WIND_BURST,2) - .enchant(Enchantment.DENSITY,3) - .enchant(Enchantment.MENDING,1) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.WIND_BURST, 2) + .enchant(Enchantment.DENSITY, 3) + .enchant(Enchantment.MENDING, 1) .customModelData(6) .build(), "Mace", (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,21,0,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 21, 0, true, false, false)); }, (p) -> { - + }, 50), SWORD(ItemBuilder.create() .material(Material.NETHERITE_SWORD) .lore(Text.legacyColor("&bAbilities:")) .lore(Text.legacyColor("&3| &7Go Wild")) .lore(Text.legacyColor(" &1- &7Strength 2 for 7 seconds")) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.MENDING,1) - .enchant(Enchantment.SHARPNESS,5) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.MENDING, 1) + .enchant(Enchantment.SHARPNESS, 5) .customModelData(7) .build(), "Netherite Sword", (p) -> { }, (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH,20*7,1,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH, 20 * 7, 1, true, false, false)); + p.getWorld().playSound(p.getLocation(),Sound.ENTITY_ZOMBIE_VILLAGER_CURE,SoundCategory.MASTER,3,2); + DisplayUtils.helix(p.getLocation(),0.7,(point)->{ + point.getWorld().spawnParticle(Particle.FLAME,point,1,0,0,0,0.01); + }, ((double) 2)/144,2); }, 50), AXE(ItemBuilder.create() .material(Material.NETHERITE_AXE) .lore(Text.legacyColor("&bAbilities:")) .lore(Text.legacyColor("&3| &7Rampage")) .lore(Text.legacyColor(" &1- &7Haste 6 for 5 seconds")) - .enchant(Enchantment.UNBREAKING,3) - .enchant(Enchantment.MENDING,1) - .enchant(Enchantment.SHARPNESS,5) - .enchant(Enchantment.EFFICIENCY,5) + .enchant(Enchantment.UNBREAKING, 3) + .enchant(Enchantment.MENDING, 1) + .enchant(Enchantment.SHARPNESS, 5) + .enchant(Enchantment.EFFICIENCY, 5) .customModelData(8) .build(), "Netherite Axe", (p) -> { }, (p) -> { - p.addPotionEffect(new PotionEffect(PotionEffectType.HASTE,20*5,5,true,false,false)); + p.addPotionEffect(new PotionEffect(PotionEffectType.HASTE, 20 * 5, 5, true, false, false)); + p.getWorld().playSound(p.getLocation(),Sound.BLOCK_BEACON_ACTIVATE,SoundCategory.MASTER,3,2); + DisplayUtils.helix(p.getLocation(),0.7,(point)->{ + point.getWorld().spawnParticle(Particle.HAPPY_VILLAGER,point,1,0,0,0,0.01); + }, ((double) 2)/144,2); }, 50); - + private final ItemStack inGame; private final String canonical; private final Consumer passiveAbility; private final Consumer ability; private final int abilityCooldownSeconds; - + Unique(ItemStack inGame, String canonical, Consumer passiveAbility, Consumer ability, int abilityCooldownSeconds) { this.inGame = inGame; this.canonical = canonical; @@ -217,38 +236,36 @@ public enum Unique { this.ability = ability; this.abilityCooldownSeconds = abilityCooldownSeconds; } - + public ItemStack getInGameItem() { return inGame; } - + public static boolean isUnique(ItemStack i) { if (i == null) return false; - Verbose.send("Checking if item is unique %s",i.getType()); + Verbose.send("Checking if item is unique %s", i.getType()); for (Unique value : values()) { - if (ItemUtils.isSimilar(value.getInGameItem(),i)) return true; + if (ItemUtils.isSimilar(value.getInGameItem(), i)) return true; if (i.getType().equals(Material.DRAGON_EGG)) return true; } Verbose.send("Item did not match any unique material..."); return false; } - public static boolean isArmor(Unique unique) { - return ItemUtils.isArmor(unique.getInGameItem()); - } - public static Unique matchUnique(ItemStack i) { - Verbose.send("Matching Unique, Item Type: %s",i.getType()); + if (i == null || i.isEmpty()) return null; + + Verbose.send("Matching Unique, Item Type: %s", i.getType()); Unique match = null; for (Unique value : values()) { - if (ItemUtils.isSimilar(value.getInGameItem(),i)) { + if (ItemUtils.isSimilar(value.getInGameItem(), i)) { match = value; - Verbose.send("Matched with, Unique: %s",match); + Verbose.send("Matched with, Unique: %s", match); } } if (i.getType().equals(Material.DRAGON_EGG)) { match = Unique.DRAGON_EGG; - Verbose.send("Matched with dragon egg: Unique: %s",match); + Verbose.send("Matched with dragon egg: Unique: %s", match); } return match; } @@ -264,7 +281,7 @@ public enum Unique { public Consumer getPassiveAbility() { return passiveAbility; } - + public int getAbilityCooldownSeconds() { return abilityCooldownSeconds; } diff --git a/src/main/java/me/trouper/armorsmp/data/io/Config.java b/src/main/java/me/trouper/armorsmp/data/io/Config.java index b44a146..55631cb 100644 --- a/src/main/java/me/trouper/armorsmp/data/io/Config.java +++ b/src/main/java/me/trouper/armorsmp/data/io/Config.java @@ -33,49 +33,4 @@ public class Config implements JsonSerializable { public String prefix = "&9ArmorSMP> &7"; public String pluginName = "ArmorSMP"; public boolean fancyAlerts = true; - - public Tips tips = new Tips(); - public class Tips { - public boolean tipsEnabled = true; - public boolean broadcastTips = true; - public int tipInterval = 1200; - public List tipList = Arrays.asList( - "Kill players to obtain Armor Upgraders and progress through armor tiers!", - "Right-click an Armor Upgrader to upgrade your armor to the next tier!", - "When you die, you'll drop an Armor Upgrader and be downgraded one tier.", - "Enchants stay when upgrading armor, but are lost when downgrading after death.", - "Armor cannot be crafted, removed, dropped, or moved in your inventory!", - "Found armor in the world cannot be equipped - you must use the upgrade system.", - "Craft Armor Upgraders using diamond blocks, ominous keys, and enchanted golden apples!", - "Netherite armor and tools are special event rewards with powerful abilities!", - "The Dragon Egg grants a special Netherite Chestplate with the Bad Breath ability!", - "Bad Breath summons damaging dragon breath for 7 seconds with a 50-second cooldown.", - "Netherite Helmet grants 5 extra hearts and permanent Fire Resistance!", - "Use Back Up ability (Netherite Leggings) to create a protective shield for 10 seconds.", - "Dash forward 10 blocks with Netherite Boots' ability (30-second cooldown).", - "Netherite Sword's Go Wild gives 7 seconds of Strength 2 for massive damage!", - "Activate Rampage with Netherite Axe for 5 seconds of Haste 6 attacks!", - "Trust players to prevent your abilities from affecting them with /trust commands.", - "The Mace is a powerful weapon that can only be crafted once when enabled!", - "Netherite items cannot be stored in containers - they must be kept in your inventory.", - "Losing Netherite items makes you lose their abilities - be careful when dropping them!", - "Use /armorsmp commands to manage armor tiers and special items (OPs only).", - "Higher armor tiers provide better protection and more powerful abilities!", - "Strategize with teammates - trusted players won't be affected by your abilities!", - "The Dragon Egg holder becomes a high-value target - protect your Netherite Chestplate!", - "Combine abilities for powerful combos - Dash in then use Go Wild for surprise attacks!", - "Manage your cooldowns wisely - abilities are powerful but have long wait times.", - "Upgrade through all tiers: None → Leather → Chainmail → Gold → Iron → Diamond!", - "Players with no armor (naked) don't drop Armor Upgraders when killed.", - "Your armor progress is saved even when you log out or the server restarts!", - "Netherite tools have both combat utility and special abilities - use them wisely!", - "The Mace's Wind Burst can knock enemies away while you maintain Speed 1!", - "Ominous Keys are valuable - save them for crafting Armor Upgraders!", - "Higher tier armor makes you a bigger target - balance protection with strategy!", - "Use terrain to your advantage while abilities are on cooldown!", - "Team up to take down players with Netherite gear and share the upgrades!", - "The End and Nether can be disabled by admins to focus on overworld PvP!" - ); - } - } diff --git a/src/main/java/me/trouper/armorsmp/server/Manager.java b/src/main/java/me/trouper/armorsmp/server/Manager.java index 8059967..f33249c 100644 --- a/src/main/java/me/trouper/armorsmp/server/Manager.java +++ b/src/main/java/me/trouper/armorsmp/server/Manager.java @@ -4,9 +4,9 @@ import me.trouper.armorsmp.ArmorSMP; import me.trouper.armorsmp.data.io.IO; import me.trouper.armorsmp.server.commands.AbilityCommand; import me.trouper.armorsmp.server.commands.AdminCommand; -import me.trouper.armorsmp.server.commands.TipsCommand; import me.trouper.armorsmp.server.commands.TrustCommand; import me.trouper.armorsmp.server.crafting.ArmorUpgrade; +import me.trouper.armorsmp.server.crafting.CustomMace; import me.trouper.armorsmp.server.events.*; import me.trouper.armorsmp.server.systems.*; import org.bukkit.Bukkit; @@ -17,9 +17,9 @@ public class Manager { public TrustBackend trust; public TierBackend tiers; - public Broadcaster broadcaster; public UniquesBackend uniques; public ArmorUpgrade upgrade; + public CustomMace mace; public Manager() { io = new IO(); @@ -32,16 +32,14 @@ public class Manager { trust = new TrustBackend(); tiers = new TierBackend(); //uniques = new UniquesBackend(); - broadcaster = new Broadcaster(); uniques = new UniquesBackend(); upgrade = new ArmorUpgrade(); + mace = new CustomMace(); registerCommands(); registerEvents(); registerCrafting(); - - Bukkit.getScheduler().runTaskTimer(ArmorSMP.getInstance(),broadcaster::broadcastTip,0,io.config.tips.tipInterval); - Bukkit.getScheduler().runTaskTimer(ArmorSMP.getInstance(), uniques::applyPersistence,0,20); + startPolling(); } @@ -56,6 +54,7 @@ public class Manager { new TrustEvents().register(); new DropItemEvent().register(); new ContainerEvents().register(); + new DimensionEvents().register(); } private void registerCommands() { @@ -63,13 +62,20 @@ public class Manager { new AdminCommand().register(); new TrustCommand().register(); new AbilityCommand().register(); - new TipsCommand().register(); } private void registerCrafting() { ArmorSMP.getInstance().getLogger().info("Registering Crafts"); upgrade.removeRecipe(); + mace.removeRecipe(); + upgrade.addRecipe(); + mace.addRecipe(); + } + + private void startPolling() { + Bukkit.getScheduler().runTaskTimer(ArmorSMP.getInstance(), uniques::applyPersistence,0,20); + // ArmorSMP.getInstance().getServer().getScheduler().runTaskTimer(ArmorSMP.getInstance(),uniques::pollUniques,0,1); } } diff --git a/src/main/java/me/trouper/armorsmp/server/commands/AbilityCommand.java b/src/main/java/me/trouper/armorsmp/server/commands/AbilityCommand.java index 5337a87..c756e60 100644 --- a/src/main/java/me/trouper/armorsmp/server/commands/AbilityCommand.java +++ b/src/main/java/me/trouper/armorsmp/server/commands/AbilityCommand.java @@ -25,21 +25,23 @@ public class AbilityCommand implements CustomCommand { public void dispatchCommand(CommandSender sender, Command command, String label, Args args) { final Unique piece = args.get(0).toEnum(Unique.class); Player p = (Player) sender; + final boolean bypass = args.getSize() > 1 && args.get(1).toBool() && p.isOp(); + if (piece == null) { - Text.sendMessage(false, Text.Pallet.ERROR, sender, "Error: {0} is not a valid unique. Please choose from these values: ", args.get(2).toString(), Arrays.toString(Unique.values())); + Text.sendMessage(Text.Pallet.ERROR, sender, "Error: {0} is not a valid unique. Please choose from these values: ", args.get(2).toString(), Arrays.toString(Unique.values())); return; } - if (!p.getUniqueId().toString().equals(ArmorSMP.getInstance().getManager().io.storage.uniques.owners.get(piece))) { - Text.sendMessage(false, Text.Pallet.WARNING, sender, "You do not own the {0}.",piece.getCanonical()); + if (!bypass && !p.getUniqueId().toString().equals(ArmorSMP.getInstance().getManager().io.storage.uniques.owners.get(piece))) { + Text.sendMessage(Text.Pallet.WARNING, sender, "You do not own the {0}.",piece.getCanonical()); return; } - if (abilityCooldown.isOnCooldown(getCooldownString(p.getUniqueId(),piece))) { - Text.sendMessage(false, Text.Pallet.WARNING, sender, "The ability for your {0} is on cooldown for {1} seconds.",piece.getCanonical(),abilityCooldown.getCooldownSec(getCooldownString(p.getUniqueId(),piece))); + if (!bypass && abilityCooldown.isOnCooldown(getCooldownString(p.getUniqueId(),piece))) { + Text.sendMessage(Text.Pallet.WARNING, sender, "The ability for your {0} is on cooldown for {1} seconds.",piece.getCanonical(),abilityCooldown.getCooldownSec(getCooldownString(p.getUniqueId(),piece))); return; } piece.getAbility().accept(p); abilityCooldown.addCooldown(getCooldownString(p.getUniqueId(),piece),piece.getAbilityCooldownSeconds() * 1000L); - Text.sendMessage(false, Text.Pallet.SUCCESS,sender,"Successfully used your {0}'s ability!",piece.getCanonical()); + Text.sendMessage(Text.Pallet.SUCCESS,sender,"Successfully used your {0}'s ability!",piece.getCanonical()); } @Override diff --git a/src/main/java/me/trouper/armorsmp/server/commands/AdminCommand.java b/src/main/java/me/trouper/armorsmp/server/commands/AdminCommand.java index d1a4721..ec84a48 100644 --- a/src/main/java/me/trouper/armorsmp/server/commands/AdminCommand.java +++ b/src/main/java/me/trouper/armorsmp/server/commands/AdminCommand.java @@ -107,7 +107,7 @@ public class AdminCommand implements CustomCommand { config.debugMode = result = !config.debugMode; config.save(); - Text.sendMessage(false, Text.Pallet.SUCCESS,sender,"Toggled debug mode {0}.",result ? "on" : "off"); + Text.sendMessage(Text.Pallet.SUCCESS,sender,"Toggled debug mode {0}.",result ? "on" : "off"); } case "exclude" -> { if (args.getSize() < 3) { @@ -118,7 +118,7 @@ public class AdminCommand implements CustomCommand { config.debuggerExclusions.add(exclusion); config.save(); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Excluded {0} from the debugger.", exclusion); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Excluded {0} from the debugger.", exclusion); } case "include" -> { if (args.getSize() < 3) { @@ -129,13 +129,13 @@ public class AdminCommand implements CustomCommand { config.debuggerExclusions.remove(exclusion); config.save(); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Removed exclusion for {0} on the debugger.", exclusion); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Removed exclusion for {0} on the debugger.", exclusion); } } } private void handleReload(CommandSender sender, Args args) { - Text.sendMessage(false, Text.Pallet.NEUTRAL,sender,"Reloading IO..."); + Text.sendMessage(Text.Pallet.NEUTRAL,sender,"Reloading IO..."); ArmorSMP.getInstance().getManager().io.loadAll(); } @@ -153,12 +153,12 @@ public class AdminCommand implements CustomCommand { return; } if (tier == null) { - Text.sendMessage(false, Text.Pallet.ERROR, sender, "Error: {0} is not a valid armor tier. Please choose from these values: ", args.get(2).toString(), Arrays.toString(ArmorTier.values())); + Text.sendMessage(Text.Pallet.ERROR, sender, "Error: {0} is not a valid armor tier. Please choose from these values: ", args.get(2).toString(), Arrays.toString(ArmorTier.values())); return; } ArmorSMP.getInstance().getManager().tiers.setTier(target, tier); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Changed armor tier to {0} for {1}", tier, target.getName()); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Changed armor tier to {0} for {1}", tier, target.getName()); } private void handleGive(CommandSender sender, Args args) { @@ -187,7 +187,7 @@ public class AdminCommand implements CustomCommand { } target.getInventory().addItem(ArmorSMP.getInstance().getManager().upgrade.getItem()); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Given and Upgrader to {0}", target.getName()); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Given and Upgrader to {0}", target.getName()); } private void handleGiveUnique(CommandSender sender, Args args) { @@ -197,7 +197,7 @@ public class AdminCommand implements CustomCommand { } final Unique piece = args.get(2).toEnum(Unique.class); if (piece == null) { - Text.sendMessage(false, Text.Pallet.ERROR, sender, "Error: {0} is not a valid unique piece. Please choose from these values: ", args.get(2).toString(), Arrays.toString(Unique.values())); + Text.sendMessage(Text.Pallet.ERROR, sender, "Error: {0} is not a valid unique piece. Please choose from these values: ", args.get(2).toString(), Arrays.toString(Unique.values())); return; } @@ -208,10 +208,10 @@ public class AdminCommand implements CustomCommand { return; } - ArmorSMP.getInstance().getManager().uniques.setOwner(piece, target); + ArmorSMP.getInstance().getManager().uniques.setOwner(piece, target,true); ArmorSMP.getInstance().getManager().tiers.queueUpdate(target, true); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Set the owner of unique {0} to {1}.", piece.getCanonical(), target.getName()); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Set the owner of unique {0} to {1}.", piece.getCanonical(), target.getName()); } private void handleToggle(CommandSender sender, Args args) { @@ -227,12 +227,12 @@ public class AdminCommand implements CustomCommand { case "end" -> { config.endEnabled = result = !config.endEnabled; config.save(); - feature = "The End"; + feature = "The End Disabler"; } case "nether" -> { config.netherEnabled = result = !config.netherEnabled; config.save(); - feature = "The Nether"; + feature = "The Nether Disabler"; } case "mace" -> { config.maceCraftingEnabled = result = !config.maceCraftingEnabled; @@ -240,12 +240,12 @@ public class AdminCommand implements CustomCommand { feature = "Mace Crafting"; } default -> { - Text.sendMessage(false, Text.Pallet.ERROR, sender, "Error: {0} is not a valid feature.", feature); + Text.sendMessage(Text.Pallet.ERROR, sender, "Error: {0} is not a valid feature.", feature); return; } } - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Toggled {0} {1}.", feature, result ? "on" : "off"); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Toggled {0} {1}.", feature, result ? "on" : "off"); } @@ -256,7 +256,7 @@ public class AdminCommand implements CustomCommand { } ArmorSMP.getInstance().getManager().io.storage.uniques.owners.remove(Unique.MACE); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Reset Mace"); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Reset Mace"); } private void handleRemove(CommandSender sender, Args args) { @@ -293,6 +293,6 @@ public class AdminCommand implements CustomCommand { ArmorSMP.getInstance().getManager().tiers.queueUpdate(target, true); ArmorSMP.getInstance().getManager().uniques.queueUpdate(target); - Text.sendMessage(false, Text.Pallet.SUCCESS, sender, "Removed {0} from {1}", piece.getCanonical(), target.getName()); + Text.sendMessage(Text.Pallet.SUCCESS, sender, "Removed {0} from {1}", piece.getCanonical(), target.getName()); } } diff --git a/src/main/java/me/trouper/armorsmp/server/commands/TipsCommand.java b/src/main/java/me/trouper/armorsmp/server/commands/TipsCommand.java deleted file mode 100644 index b208740..0000000 --- a/src/main/java/me/trouper/armorsmp/server/commands/TipsCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.trouper.armorsmp.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.completions.CompletionBuilder; -import me.trouper.armorsmp.ArmorSMP; -import me.trouper.armorsmp.utils.Text; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandRegistry(value = "tips",playersOnly = true) -public class TipsCommand implements CustomCommand { - @Override - public void dispatchCommand(CommandSender sender, Command command, String s, Args args) { - Player p = (Player) sender; - boolean result = false; - - if (ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(p.getUniqueId().toString())) { - ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.remove(p.getUniqueId().toString()); - result = true; - } else { - ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.add(p.getUniqueId().toString()); - } - - ArmorSMP.getInstance().getManager().io.storage.save(); - - Text.sendMessage(false, Text.Pallet.SUCCESS,sender,"Successfully {0} tips.", result ? "enabled" : "disabled"); - } - - @Override - public void dispatchCompletions(CommandSender sender, Command command, String s, CompletionBuilder completionBuilder) { - - } -} diff --git a/src/main/java/me/trouper/armorsmp/server/commands/TrustCommand.java b/src/main/java/me/trouper/armorsmp/server/commands/TrustCommand.java index d747462..321e540 100644 --- a/src/main/java/me/trouper/armorsmp/server/commands/TrustCommand.java +++ b/src/main/java/me/trouper/armorsmp/server/commands/TrustCommand.java @@ -43,10 +43,10 @@ public class TrustCommand implements CustomCommand { } if (ArmorSMP.getInstance().getManager().trust.addTrust((Player) sender,trustee.getUniqueId())) { - Text.sendMessage(true, Text.Pallet.SUCCESS,sender,"Successfully trusted {0}.",target); - if (trustee.isOnline())Text.sendMessage(true, Text.Pallet.SUCCESS,(Player) trustee,"Successfully trusted {0}.",sender.getName()); + Text.sendMessage(Text.Pallet.SUCCESS,sender,"Successfully trusted {0}.",target); + if (trustee.isOnline())Text.sendMessage(Text.Pallet.SUCCESS,(Player) trustee,"{0} has trusted you.",sender.getName()); } else { - Text.sendMessage(true, Text.Pallet.NEUTRAL,sender,"You already have {0} trusted.",target); + Text.sendMessage(Text.Pallet.NEUTRAL,sender,"You already have {0} trusted.",target); } } case "remove" -> { @@ -67,10 +67,10 @@ public class TrustCommand implements CustomCommand { } if (ArmorSMP.getInstance().getManager().trust.removeTrust((Player) sender,trustee.getUniqueId())) { - Text.sendMessage(true, Text.Pallet.SUCCESS,sender,"Successfully un-trusted {0}.",target); - if (trustee.isOnline())Text.sendMessage(true, Text.Pallet.SUCCESS,(Player) trustee,"{0} has un-trusted you.",sender.getName()); + Text.sendMessage(Text.Pallet.SUCCESS,sender,"Successfully un-trusted {0}.",target); + if (trustee.isOnline())Text.sendMessage(Text.Pallet.SUCCESS,(Player) trustee,"{0} has un-trusted you.",sender.getName()); } else { - Text.sendMessage(true, Text.Pallet.NEUTRAL,sender,"You do not have {0} trusted.",target); + Text.sendMessage(Text.Pallet.NEUTRAL,sender,"You do not have {0} trusted.",target); } } case "list" -> { @@ -79,7 +79,7 @@ public class TrustCommand implements CustomCommand { for (String trustee : trustees) { names.add(Bukkit.getOfflinePlayer(UUID.fromString(trustee)).getName()); } - Text.sendMessage(false, Text.Pallet.NEUTRAL,sender,"You currently have {0} players trusted: {1}",trustees.size(), Arrays.toString(names.toArray())); + Text.sendMessage(Text.Pallet.NEUTRAL,sender,"You currently have {0} players trusted: {1}",trustees.size(), Arrays.toString(names.toArray())); } } } diff --git a/src/main/java/me/trouper/armorsmp/server/crafting/CustomMace.java b/src/main/java/me/trouper/armorsmp/server/crafting/CustomMace.java new file mode 100644 index 0000000..d4e94ce --- /dev/null +++ b/src/main/java/me/trouper/armorsmp/server/crafting/CustomMace.java @@ -0,0 +1,42 @@ +package me.trouper.armorsmp.server.crafting; + +import me.trouper.armorsmp.ArmorSMP; +import me.trouper.armorsmp.data.Unique; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; + +public class CustomMace { + private ItemStack customMace; + public final NamespacedKey key; + public final ShapedRecipe recipe; + + public CustomMace() { + this.key = new NamespacedKey(ArmorSMP.getInstance(), "mace_recipe"); + this.customMace = Unique.MACE.getInGameItem(); + this.recipe = new ShapedRecipe(key, customMace); + } + + public void addRecipe() { + recipe.shape("C", "B"); + + recipe.setIngredient('C', Material.HEAVY_CORE); + recipe.setIngredient('B', Material.BREEZE_ROD); + + + ArmorSMP.getInstance().getServer().addRecipe(recipe); + } + + public void removeRecipe() { + ArmorSMP.getInstance().getServer().removeRecipe(key); + } + + public ItemStack getItem() { + if (!customMace.getType().equals(Material.NETHER_STAR)) { + customMace = Unique.MACE.getInGameItem(); + return customMace; + } + return customMace; + } +} diff --git a/src/main/java/me/trouper/armorsmp/server/events/CraftEvents.java b/src/main/java/me/trouper/armorsmp/server/events/CraftEvents.java index 0396c8f..f1004b1 100644 --- a/src/main/java/me/trouper/armorsmp/server/events/CraftEvents.java +++ b/src/main/java/me/trouper/armorsmp/server/events/CraftEvents.java @@ -3,17 +3,33 @@ package me.trouper.armorsmp.server.events; import io.github.itzispyder.pdk.events.CustomListener; import me.trouper.armorsmp.ArmorSMP; import me.trouper.armorsmp.data.Unique; +import me.trouper.armorsmp.utils.ItemUtils; import me.trouper.armorsmp.utils.Text; import me.trouper.armorsmp.utils.Verbose; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; +import org.bukkit.event.block.CrafterCraftEvent; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.PrepareSmithingEvent; import org.bukkit.inventory.ItemStack; public class CraftEvents implements CustomListener { + @EventHandler + public void onCrafter(CrafterCraftEvent e) { + ItemStack result = e.getRecipe().getResult(); + + Verbose.send("Handling crafter, result: %s", result.getType().name()); + + if (!ItemUtils.isUnique(result) && !ItemUtils.isArmor(result) && !result.getType().equals(Material.MACE)) return; + + Verbose.send("A crafter attempted to craft a disabled item."); + + e.setCancelled(true); + } + @EventHandler public void onCraft(CraftItemEvent e) { ItemStack result = e.getRecipe().getResult(); @@ -23,6 +39,7 @@ public class CraftEvents implements CustomListener { Verbose.send("Handling craft for %s, result: %s", p.getName(), result.getType().name()); if (result.getType().equals(Material.MACE)) { + if (!ArmorSMP.getInstance().getManager().io.config.maceCraftingEnabled) { e.setCancelled(true); p.closeInventory(); @@ -36,15 +53,12 @@ public class CraftEvents implements CustomListener { return; } - - result.addEnchantments(Unique.MACE.getInGameItem().getEnchantments()); - result.lore(Unique.MACE.getInGameItem().lore()); - result.setItemMeta(Unique.MACE.getInGameItem().getItemMeta()); - + Text.sendMessage(Text.Pallet.INFO,p,"Congratulations! You have crafted up the unique mace. There is only one of each in the whole server!"); + ArmorSMP.getInstance().getManager().uniques.setOwner(Unique.MACE,p,false); return; } - if (isUnique(result)) return; + if (!ItemUtils.isUnique(result) && !ItemUtils.isArmor(result)) return; Verbose.send("%s Attempted to craft a disabled item.", p.getName()); @@ -52,15 +66,4 @@ public class CraftEvents implements CustomListener { p.closeInventory(); Text.sendWarning(p,"You are not allowed to craft {0}.",name); } - - private boolean isUnique(ItemStack item) { - return isUnique(item.getType()); - } - - private boolean isUnique(Material m) { - for (Unique unique : Unique.values()) { - if (unique.getInGameItem().getType().equals(m)) return true; - } - return false; - } } diff --git a/src/main/java/me/trouper/armorsmp/server/events/DeathEvents.java b/src/main/java/me/trouper/armorsmp/server/events/DeathEvents.java index 406cc60..0953620 100644 --- a/src/main/java/me/trouper/armorsmp/server/events/DeathEvents.java +++ b/src/main/java/me/trouper/armorsmp/server/events/DeathEvents.java @@ -26,18 +26,19 @@ public class DeathEvents implements CustomListener { if (ArmorSMP.getInstance().getManager().uniques.isOwner(p,Unique.DRAGON_EGG)) { e.getDrops().add(new ItemStack(Material.DRAGON_EGG)); } + + ArmorSMP.getInstance().getManager().uniques.dropAllUniques(p); if (tier.equals(ArmorTier.NONE)) { Verbose.send("Tier was none"); - Text.sendMessage(true, Text.Pallet.INFO,p,"You have died! Since you were at tier {0}, you didn't drop an Armor Upgrader.",tier); + Text.sendMessage(Text.Pallet.INFO,p,"You have died! Since you were at tier {0}, you didn't drop an Armor Upgrader.",tier); return; } if (ArmorSMP.getInstance().getManager().tiers.downTier(p)) { Verbose.send("They have been down-tiered"); e.getDrops().add(ArmorSMP.getInstance().getManager().upgrade.getItem()); - e.deathMessage(Text.getMessage(false, Text.Pallet.INFO,"{0} has died, and dropped an {1}!", LegacyComponentSerializer.legacyAmpersand().serialize(p.name()),"Armor Upgrader")); + e.deathMessage(Text.getMessage(Text.Pallet.INFO,"{0} has died, and dropped an {1}!", LegacyComponentSerializer.legacyAmpersand().serialize(p.name()),"Armor Upgrader")); } - ArmorSMP.getInstance().getManager().uniques.dropAllUniques(p); } @EventHandler diff --git a/src/main/java/me/trouper/armorsmp/server/events/DimensionEvents.java b/src/main/java/me/trouper/armorsmp/server/events/DimensionEvents.java new file mode 100644 index 0000000..78a93c9 --- /dev/null +++ b/src/main/java/me/trouper/armorsmp/server/events/DimensionEvents.java @@ -0,0 +1,78 @@ +package me.trouper.armorsmp.server.events; + +import io.github.itzispyder.pdk.events.CustomListener; +import io.github.itzispyder.pdk.utils.misc.Cooldown; +import me.trouper.armorsmp.ArmorSMP; +import me.trouper.armorsmp.utils.Text; +import org.bukkit.Bukkit; +import org.bukkit.PortalType; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityPortalEnterEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.world.PortalCreateEvent; + +import java.util.Locale; +import java.util.UUID; + +public class DimensionEvents implements CustomListener { + + Cooldown messageCooldown = new Cooldown<>(); + + @EventHandler + public void onPortalEnter(EntityPortalEnterEvent e) { + if ((ArmorSMP.getInstance().getManager().io.config.endEnabled && e.getPortalType().equals(PortalType.ENDER)) + || (ArmorSMP.getInstance().getManager().io.config.netherEnabled && e.getPortalType().equals(PortalType.NETHER))) { + e.setCancelled(true); + if (e.getEntity() instanceof Player p && !messageCooldown.isOnCooldown(p.getUniqueId())) { + Text.sendWarning(p,"{0} portals are disabled.",e.getPortalType().name()); + messageCooldown.addCooldown(p.getUniqueId(),3000); + } + } + } + + @EventHandler + public void onPlayerTeleport(PlayerTeleportEvent e) { + World targetWorld = e.getTo().getWorld(); + if (targetWorld == null) return; + + World.Environment env = targetWorld.getEnvironment(); + if ((ArmorSMP.getInstance().getManager().io.config.netherEnabled && env == World.Environment.NETHER) + || (ArmorSMP.getInstance().getManager().io.config.endEnabled && env == World.Environment.THE_END)) { + e.setCancelled(true); + Text.sendWarning(e.getPlayer(),"The {0} is disabled. You have been moved to the overworld.", targetWorld.getEnvironment().name()); + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + World world = player.getWorld(); + + if ((ArmorSMP.getInstance().getManager().io.config.netherEnabled && world.getEnvironment() == World.Environment.NETHER) + || (ArmorSMP.getInstance().getManager().io.config.endEnabled && world.getEnvironment() == World.Environment.THE_END)) { + World overworld = Bukkit.getWorlds().stream() + .filter(w -> w.getEnvironment() == World.Environment.NORMAL) + .findFirst() + .orElse(Bukkit.getWorlds().get(0)); + + if (overworld != null) { + player.teleport(overworld.getSpawnLocation()); + Text.sendWarning(player,"The {0} is disabled. You have been moved to the overworld.", world.getEnvironment().name()); + } + } + } + + @EventHandler + public void onPortalCreate(PortalCreateEvent e) { + if ((ArmorSMP.getInstance().getManager().io.config.endEnabled && e.getReason().equals(PortalCreateEvent.CreateReason.END_PLATFORM)) + || (ArmorSMP.getInstance().getManager().io.config.netherEnabled && e.getReason().equals(PortalCreateEvent.CreateReason.FIRE)) + || (ArmorSMP.getInstance().getManager().io.config.netherEnabled && e.getReason().equals(PortalCreateEvent.CreateReason.NETHER_PAIR))) { + e.setCancelled(true); + if (e.getEntity() instanceof Player p) Text.sendWarning(p,"You cannot create that portal."); + } + } + +} diff --git a/src/main/java/me/trouper/armorsmp/server/events/JoinEvent.java b/src/main/java/me/trouper/armorsmp/server/events/JoinEvent.java index 219e7af..67fb0f5 100644 --- a/src/main/java/me/trouper/armorsmp/server/events/JoinEvent.java +++ b/src/main/java/me/trouper/armorsmp/server/events/JoinEvent.java @@ -32,14 +32,24 @@ public class JoinEvent implements CustomListener { Verbose.send("Checking for updates needed on %s",p.getName()); final Map armorCache = ArmorSMP.getInstance().getManager().io.storage.armorUpdateCache; final Set uniquesCache = ArmorSMP.getInstance().getManager().io.storage.uniqueUpdateCache; - if (!ArmorSMP.getInstance().getManager().tiers.verifyArmor(p)) { - Verbose.send("Updating armor"); - ArmorSMP.getInstance().getManager().tiers.queueUpdate(p,armorCache.getOrDefault(p.getUniqueId().toString(),true)); - } + if (!ArmorSMP.getInstance().getManager().uniques.verifyUniques(p)) { Verbose.send("Updating uniques"); ArmorSMP.getInstance().getManager().uniques.queueUpdate(p); } + + if (!ArmorSMP.getInstance().getManager().tiers.verifyArmor(p)) { + Verbose.send("Updating armor"); + ArmorSMP.getInstance().getManager().tiers.queueUpdate(p,armorCache.getOrDefault(p.getUniqueId().toString(),true)); + } + + if (uniquesCache.contains(p.getUniqueId().toString())) { + Verbose.send("Updating uniques from cache"); + ArmorSMP.getInstance().getManager().uniques.queueUpdate(p); + ArmorSMP.getInstance().getManager().io.storage.uniqueUpdateCache.remove(p.getUniqueId().toString()); + ArmorSMP.getInstance().getManager().io.storage.save(); + } + if (armorCache.containsKey(p.getUniqueId().toString())) { Verbose.send("Updating armor from cache"); ArmorSMP.getInstance().getManager().tiers.queueUpdate(p,armorCache.getOrDefault(p.getUniqueId().toString(),true)); @@ -47,11 +57,6 @@ public class JoinEvent implements CustomListener { ArmorSMP.getInstance().getManager().io.storage.save(); } - if (uniquesCache.contains(p.getUniqueId().toString())) { - Verbose.send("Updating uniques"); - ArmorSMP.getInstance().getManager().uniques.queueUpdate(p); - ArmorSMP.getInstance().getManager().io.storage.uniqueUpdateCache.remove(p.getUniqueId().toString()); - ArmorSMP.getInstance().getManager().io.storage.save(); - } + } } diff --git a/src/main/java/me/trouper/armorsmp/server/events/PickUpEvent.java b/src/main/java/me/trouper/armorsmp/server/events/PickUpEvent.java index b12e112..e469f4b 100644 --- a/src/main/java/me/trouper/armorsmp/server/events/PickUpEvent.java +++ b/src/main/java/me/trouper/armorsmp/server/events/PickUpEvent.java @@ -5,6 +5,7 @@ import me.trouper.armorsmp.ArmorSMP; import me.trouper.armorsmp.data.Unique; import me.trouper.armorsmp.utils.Text; import me.trouper.armorsmp.utils.ItemUtils; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityPickupItemEvent; @@ -22,15 +23,14 @@ public class PickUpEvent implements CustomListener { if (!Unique.isUnique(i)) return; Unique match = Unique.matchUnique(i); - e.setCancelled(true); - e.getItem().remove(); - ArmorSMP.getInstance().getManager().uniques.setOwner(match,p); - Text.sendMessage(true, Text.Pallet.INFO,p,"Congratulations! You have picked up the unique {0}. There is only one of each in the whole server!",match.getCanonical()); - ArmorSMP.getInstance().getServer().broadcast(Text.getMessage(false, Text.Pallet.INFO,"GG, {0}! They are the new owner of the unique {1}.",p.getName(),match.getCanonical())); + ArmorSMP.getInstance().getManager().uniques.setOwner(match,p,false); + Text.sendMessage(Text.Pallet.INFO,p,"Congratulations! You have picked up the unique {0}. There is only one of each in the whole server!",match.getCanonical()); + ArmorSMP.getInstance().getLogger().info(LegacyComponentSerializer.legacySection().serialize(Text.getMessage(Text.Pallet.INFO,"{0} is the new owner of the unique {1}.",p.getName(),match.getCanonical()))); if (ItemUtils.isArmor(match.getInGameItem())) { - p.getInventory().remove(i); + e.setCancelled(true); + e.getItem().remove(); ArmorSMP.getInstance().getManager().tiers.queueUpdate(p,true); } } diff --git a/src/main/java/me/trouper/armorsmp/server/events/TrustEvents.java b/src/main/java/me/trouper/armorsmp/server/events/TrustEvents.java index 3d25561..d0eb5b7 100644 --- a/src/main/java/me/trouper/armorsmp/server/events/TrustEvents.java +++ b/src/main/java/me/trouper/armorsmp/server/events/TrustEvents.java @@ -2,6 +2,9 @@ package me.trouper.armorsmp.server.events; import io.github.itzispyder.pdk.events.CustomListener; import me.trouper.armorsmp.ArmorSMP; +import me.trouper.armorsmp.utils.Verbose; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -13,15 +16,23 @@ public class TrustEvents implements CustomListener { @EventHandler public void onDamage(EntityDamageByEntityEvent e) { if (!(e.getEntity() instanceof Player v)) return; - Set trustees = ArmorSMP.getInstance().getManager().trust.getTrustees(v); - String damager = e.getDamager().getUniqueId().toString(); + Verbose.send("Detected damage on %s", v.getName()); - if (trustees.contains(damager)) { - e.setCancelled(true); - return; + if (e.getDamager() instanceof Player a) { + Set trustees = ArmorSMP.getInstance().getManager().trust.getTrustees(a); + String victim = v.getUniqueId().toString(); + + if (trustees.contains(victim)) { + e.setCancelled(true); + return; + } } + if (e.getDamager() instanceof AreaEffectCloud aoe && aoe.getOwnerUniqueId() != null) { - if (trustees.contains(aoe.getOwnerUniqueId().toString())) { + Verbose.send("Detected AOE damage from owner %s", aoe.getOwnerUniqueId()); + OfflinePlayer a = Bukkit.getOfflinePlayer(aoe.getOwnerUniqueId()); + Set trustees = ArmorSMP.getInstance().getManager().trust.getTrustees(a); + if (trustees.contains(v.getUniqueId().toString())) { e.setCancelled(true); return; } diff --git a/src/main/java/me/trouper/armorsmp/server/events/UpgradeRedeemEvent.java b/src/main/java/me/trouper/armorsmp/server/events/UpgradeRedeemEvent.java index d2411d5..01e257c 100644 --- a/src/main/java/me/trouper/armorsmp/server/events/UpgradeRedeemEvent.java +++ b/src/main/java/me/trouper/armorsmp/server/events/UpgradeRedeemEvent.java @@ -30,10 +30,10 @@ public class UpgradeRedeemEvent implements CustomListener { if (ArmorSMP.getInstance().getManager().tiers.upTier(p)) { holding.setAmount(holding.getAmount() - 1); Verbose.send("Successfully updated player"); - Text.sendMessage(true, Text.Pallet.INFO,p,"Successfully redeemed armor upgrade! Tier {0} -> Tier {1}",tier,ArmorSMP.getInstance().getManager().tiers.getTier(p)); + Text.sendMessage(Text.Pallet.INFO,p,"Successfully redeemed armor upgrade! Tier {0} -> Tier {1}",tier,ArmorSMP.getInstance().getManager().tiers.getTier(p)); } else { Verbose.send("Failed to update player (tier manager refused)"); - Text.sendMessage(true, Text.Pallet.ERROR,p,"Unable to upgrade. You are already at the maximum Armor Tier!"); + Text.sendMessage(Text.Pallet.ERROR,p,"Unable to upgrade. You are already at the maximum Armor Tier!"); } } } diff --git a/src/main/java/me/trouper/armorsmp/server/systems/Broadcaster.java b/src/main/java/me/trouper/armorsmp/server/systems/Broadcaster.java deleted file mode 100644 index e408ab6..0000000 --- a/src/main/java/me/trouper/armorsmp/server/systems/Broadcaster.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.trouper.armorsmp.server.systems; - -import io.github.itzispyder.pdk.utils.misc.Randomizer; -import me.trouper.armorsmp.ArmorSMP; -import me.trouper.armorsmp.data.io.IO; -import me.trouper.armorsmp.utils.Text; -import org.bukkit.entity.Player; - -public class Broadcaster { - - private final IO io = ArmorSMP.getInstance().getManager().io; - - public void broadcastTip() { - if (!io.config.tips.broadcastTips) return; - String tip = new Randomizer().getRandomElement(io.config.tips.tipList); - for (Player onlinePlayer : ArmorSMP.getInstance().getServer().getOnlinePlayers()) { - if (ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(onlinePlayer.getUniqueId().toString())) continue; - onlinePlayer.sendMessage(Text.getMessage(false, Text.Pallet.NEUTRAL,tip)); - } - } -} diff --git a/src/main/java/me/trouper/armorsmp/server/systems/TrustBackend.java b/src/main/java/me/trouper/armorsmp/server/systems/TrustBackend.java index 7395772..93792c5 100644 --- a/src/main/java/me/trouper/armorsmp/server/systems/TrustBackend.java +++ b/src/main/java/me/trouper/armorsmp/server/systems/TrustBackend.java @@ -3,11 +3,11 @@ package me.trouper.armorsmp.server.systems; import me.trouper.armorsmp.ArmorSMP; import me.trouper.armorsmp.data.io.IO; import me.trouper.armorsmp.data.io.Storage; +import me.trouper.armorsmp.utils.Verbose; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; +import java.util.*; public class TrustBackend { private final Storage storage = ArmorSMP.getInstance().getManager().io.storage; @@ -28,7 +28,7 @@ public class TrustBackend { return removed; } - public Set getTrustees(Player target) { + public Set getTrustees(OfflinePlayer target) { return storage.userData.playerTrust.getOrDefault(target.getUniqueId().toString(),new HashSet<>()); } diff --git a/src/main/java/me/trouper/armorsmp/server/systems/UniquesBackend.java b/src/main/java/me/trouper/armorsmp/server/systems/UniquesBackend.java index d78f378..f83b261 100644 --- a/src/main/java/me/trouper/armorsmp/server/systems/UniquesBackend.java +++ b/src/main/java/me/trouper/armorsmp/server/systems/UniquesBackend.java @@ -6,13 +6,17 @@ import me.trouper.armorsmp.data.io.Storage; import me.trouper.armorsmp.utils.ItemUtils; import me.trouper.armorsmp.utils.Verbose; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class UniquesBackend { @@ -24,7 +28,6 @@ public class UniquesBackend { storage.uniqueUpdateCache.add(target.getUniqueId().toString()); ArmorSMP.getInstance().getManager().io.storage.save(); } - } private void updateUniques(Player p) { @@ -57,7 +60,7 @@ public class UniquesBackend { private void equipOwnedArmor(Player p) { storage.uniques.owners.forEach((unique, ownerId) -> { - if (ownerId.equals(p.getUniqueId().toString()) && Unique.isArmor(unique)) { + if (unique != null && unique.getInGameItem() != null && !unique.getInGameItem().isEmpty() && ownerId.equals(p.getUniqueId().toString()) && ItemUtils.isArmor(unique.getInGameItem())) { if (ItemUtils.isHelmet(unique.getInGameItem())) p.getInventory().setHelmet(unique.getInGameItem()); else if (ItemUtils.isChestplate(unique.getInGameItem())) p.getInventory().setChestplate(unique.getInGameItem()); else if (ItemUtils.isLeggings(unique.getInGameItem())) p.getInventory().setLeggings(unique.getInGameItem()); @@ -68,8 +71,8 @@ public class UniquesBackend { private void addMissing(Player p) { storage.uniques.owners.forEach((unique, ownerId) -> { - if (ownerId.equals(p.getUniqueId().toString())) { - if (!Unique.isArmor(unique) && !hasItem(p, unique)) { + if (unique != null && unique.getInGameItem() != null && ownerId.equals(p.getUniqueId().toString())) { + if (!ItemUtils.isArmor(unique.getInGameItem()) && !hasItem(p, unique)) { p.getInventory().addItem(unique.getInGameItem()); } } @@ -96,38 +99,55 @@ public class UniquesBackend { public void applyEffects(Player p) { storage.uniques.owners.forEach((unique, owner) -> { - if (p != null && owner.equals(p.getUniqueId().toString()) && p.isOnline()) { + if (unique != null && unique.getPassiveAbility() != null && p != null && owner.equals(p.getUniqueId().toString()) && p.isOnline()) { unique.getPassiveAbility().accept(p); } }); } - public void dropUnique(Player p, Unique dropped) { + public synchronized void dropUnique(Player p, Unique dropped) { storage.uniques.owners.remove(dropped); storage.save(); + clearUnique(p,dropped); + } + + public void clearUnique(Player p, Unique unique) { + Verbose.send("Clearing %s of the unique %s",p.getName(),unique.getCanonical()); + p.getInventory().remove(unique.getInGameItem()); + ItemStack head = p.getEquipment().getItem(EquipmentSlot.HEAD); + ItemStack chest = p.getEquipment().getItem(EquipmentSlot.CHEST); + ItemStack legs = p.getEquipment().getItem(EquipmentSlot.LEGS); + ItemStack feet = p.getEquipment().getItem(EquipmentSlot.FEET); + if (ItemUtils.isSimilar(head,unique.getInGameItem())) p.getEquipment().setHelmet(new ItemStack(Material.AIR)); + if (ItemUtils.isSimilar(chest,unique.getInGameItem())) p.getEquipment().setChestplate(new ItemStack(Material.AIR)); + if (ItemUtils.isSimilar(legs,unique.getInGameItem())) p.getEquipment().setLeggings(new ItemStack(Material.AIR)); + if (ItemUtils.isSimilar(feet,unique.getInGameItem())) p.getEquipment().setBoots(new ItemStack(Material.AIR)); } public void dropAllUniques(Player p) { - storage.uniques.owners.forEach((unique,owner)->{ + Map clone = new HashMap<>(storage.uniques.owners); + clone.forEach((unique,owner)->{ if (owner.equals(p.getUniqueId().toString())) { - storage.uniques.owners.remove(unique); + dropUnique(p,unique); } }); - storage.save(); } - public void setOwner(Unique u, OfflinePlayer p) { + public void setOwner(Unique u, OfflinePlayer p, boolean update) { storage.uniques.owners.put(u, p.getUniqueId().toString()); storage.save(); - if (p.isOnline()) updateUniques(p.getPlayer()); + if (p.isOnline() && update) updateUniques(p.getPlayer()); } public boolean verifyUniques(Player p) { List checks = new ArrayList<>(); - ArmorSMP.getInstance().getManager().io.storage.uniques.owners.forEach(((unique, id) -> { + Map owners = ArmorSMP.getInstance().getManager().io.storage.uniques.owners; + + // Check if player has all uniques they own + owners.forEach((unique, id) -> { if (id.equals(p.getUniqueId().toString())) { Verbose.send(1, "They own the unique, checking if they have it: ", p.getInventory().contains(unique.getInGameItem())); - if (hasItem(p,unique)) { + if (hasItem(p, unique)) { Verbose.send(1, "They have it"); checks.add(true); } else { @@ -135,9 +155,38 @@ public class UniquesBackend { checks.add(false); } } - })); + }); + + // Check if player has any uniques they don't own + for (ItemStack item : p.getInventory().getContents()) { + if (item != null && ItemUtils.isUnique(item)) { + Unique unique = Unique.matchUnique(item); + if (unique != null && !owners.getOrDefault(unique, "").equals(p.getUniqueId().toString())) { + Verbose.send(1, "Player has unique they don't own: ", unique.getCanonical()); + checks.add(false); + } + } + } + + // Check armor slots too + for (ItemStack armor : p.getInventory().getArmorContents()) { + if (armor != null && ItemUtils.isUnique(armor)) { + Unique unique = Unique.matchUnique(armor); + if (unique != null && !owners.getOrDefault(unique, "").equals(p.getUniqueId().toString())) { + Verbose.send(1, "Player has unique armor they don't own: ", unique.getCanonical()); + checks.add(false); + } + } + } + return !checks.contains(false); } + public void pollUniques() { + for (Player player : ArmorSMP.getInstance().getServer().getOnlinePlayers()) { + updateUniques(player); + } + } + } \ No newline at end of file diff --git a/src/main/java/me/trouper/armorsmp/utils/ItemUtils.java b/src/main/java/me/trouper/armorsmp/utils/ItemUtils.java index 65bc8f7..7af21ec 100644 --- a/src/main/java/me/trouper/armorsmp/utils/ItemUtils.java +++ b/src/main/java/me/trouper/armorsmp/utils/ItemUtils.java @@ -30,39 +30,53 @@ public class ItemUtils { } private static boolean isDragonEggEquivalent(ItemStack i) { + if (i == null || i.isEmpty()) return false; + Material m = i.getType(); return m.equals(Unique.DRAGON_EGG.getInGameItem().getType()); } public static boolean isArmor(ItemStack i) { + if (i == null || i.isEmpty()) return false; + return isHelmet(i) || isChestplate(i) || isLeggings(i) || isBoots(i); } public static boolean isHelmet(ItemStack i) { + if (i == null || i.isEmpty()) return false; + Material m = i.getType(); String n = m.name(); return n.contains("HELMET"); } public static boolean isChestplate(ItemStack i) { + if (i == null || i.isEmpty()) return false; + Material m = i.getType(); String n = m.name(); return n.contains("CHESTPLATE"); } public static boolean isLeggings(ItemStack i) { + if (i == null || i.isEmpty()) return false; + Material m = i.getType(); String n = m.name(); return n.contains("LEGGINGS"); } public static boolean isBoots(ItemStack i) { + if (i == null || i.isEmpty()) return false; + Material m = i.getType(); String n = m.name(); return n.contains("BOOTS"); } public static boolean isUnique(ItemStack i) { + if (i == null || i.isEmpty()) return false; + Material m = i.getType(); List uniqueMets = new ArrayList<>(); for (Unique value : Unique.values()) { @@ -73,6 +87,8 @@ public class ItemUtils { } public static boolean isUniqueArmor(ItemStack i) { + if (i == null || i.isEmpty()) return false; + return isUnique(i) && isArmor(i); } diff --git a/src/main/java/me/trouper/armorsmp/utils/Text.java b/src/main/java/me/trouper/armorsmp/utils/Text.java index 23774ab..f4ef6a4 100644 --- a/src/main/java/me/trouper/armorsmp/utils/Text.java +++ b/src/main/java/me/trouper/armorsmp/utils/Text.java @@ -1,12 +1,14 @@ package me.trouper.armorsmp.utils; -import io.github.itzispyder.pdk.utils.misc.Randomizer; +import io.github.itzispyder.pdk.utils.misc.SoundPlayer; import me.trouper.armorsmp.ArmorSMP; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -28,41 +30,35 @@ public class Text { } public static void sendWarning(CommandSender sender, String warning, Object... args) { - sendMessage(false, Pallet.WARNING, sender, warning, args); + sendMessage(Pallet.WARNING, sender, warning, args); } public static void sendError(CommandSender sender, String error, Object... args) { - sendMessage(false, Pallet.ERROR, sender, error, args); + sendMessage(Pallet.ERROR, sender, error, args); } - public static void sendMessage(boolean allowTip, CommandSender sender, String text, Object... args) { - sendMessage(false, Pallet.NEUTRAL, sender, text, args); + public static void sendMessage(CommandSender sender, String text, Object... args) { + sendMessage(Pallet.NEUTRAL, sender, text, args); } - public static void sendMessage(boolean allowTip, Pallet pallet, CommandSender sender, String text, Object... args) { + public static void sendMessage(Pallet pallet, CommandSender sender, String text, Object... args) { text = formatArgs(pallet, text, args); - sendMessage(allowTip,sender, text); + sendMessage(sender, text); + if (sender instanceof Player p) p.playSound(p.getLocation(),pallet.sound.sound, SoundCategory.VOICE,10f,pallet.sound.pitch); } - public static void sendMessage(boolean allowTip, CommandSender sender, String text) { - if (sender instanceof Player player) { - allowTip = allowTip - && ArmorSMP.getInstance().getManager().io.config.tips.tipsEnabled - && !ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(player.getUniqueId().toString()); - } else { - allowTip = false; - } - Component message = getMessage(allowTip,text); + public static void sendMessage(CommandSender sender, String text) { + Component message = getMessage(text); sender.sendMessage(message); } - public static Component getMessage(boolean addFancyTip, Pallet pallet, String text, Object... args) { - return getMessage(addFancyTip,formatArgs(pallet,text,args)); + public static Component getMessage(Pallet pallet, String text, Object... args) { + return getMessage(formatArgs(pallet, text, args)); } - - public static Component getMessage(boolean addFancyTip, String text) { + + public static Component getMessage(String text) { if (ArmorSMP.getInstance().getManager().io.config.fancyAlerts) { - return formatFancyMessage(text, addFancyTip); + return formatFancyMessage(text); } else { return color(ArmorSMP.getInstance().getManager().io.config.prefix + text); } @@ -101,14 +97,9 @@ public class Text { return LegacyComponentSerializer.legacyAmpersand().serialize(message); } - public static Component formatFancyMessage(String text, boolean addTip) { + public static Component formatFancyMessage(String text) { Component message = Component.empty().appendNewline(); - if (addTip) { - String tip = new Randomizer().getRandomElement(ArmorSMP.getInstance().getManager().io.config.tips.tipList); - text = text + " &r&7&o" + tip; - } - List wrappedLines = wrapText(text, 50, (int) Math.round((ArmorSMP.getInstance().getManager().io.config.pluginName.length() + 3) * 1.3)); message = message @@ -116,7 +107,6 @@ public class Text { .append(Component.text(ArmorSMP.getInstance().getManager().io.config.pluginName + " ", NamedTextColor.WHITE, TextDecoration.BOLD)) .append(color(wrappedLines.getFirst())); - String active = getActiveFormatting(wrappedLines.getFirst()); wrappedLines.removeFirst(); @@ -211,44 +201,47 @@ public class Text { NamedTextColor.RED, NamedTextColor.YELLOW, NamedTextColor.GOLD, - NamedTextColor.DARK_RED - ), + NamedTextColor.DARK_RED, + new SoundData(Sound.BLOCK_NOTE_BLOCK_BASS,1)), WARNING( NamedTextColor.YELLOW, NamedTextColor.GOLD, NamedTextColor.RED, - NamedTextColor.DARK_RED - ), + NamedTextColor.DARK_RED, + new SoundData(Sound.BLOCK_NOTE_BLOCK_BIT,0.5F)), INFO( NamedTextColor.GRAY, NamedTextColor.WHITE, NamedTextColor.AQUA, - NamedTextColor.DARK_AQUA - ), + NamedTextColor.DARK_AQUA, + new SoundData(Sound.BLOCK_NOTE_BLOCK_BELL,1)), SUCCESS( NamedTextColor.GREEN, NamedTextColor.DARK_GREEN, NamedTextColor.YELLOW, - NamedTextColor.GOLD - ), + NamedTextColor.GOLD, + new SoundData(Sound.BLOCK_NOTE_BLOCK_CHIME,1)), NEUTRAL( NamedTextColor.GRAY, NamedTextColor.WHITE, NamedTextColor.DARK_AQUA, - NamedTextColor.BLUE - ); + NamedTextColor.BLUE, + new SoundData(Sound.BLOCK_NOTE_BLOCK_BELL,1)); private final TextColor mainText; private final TextColor argDefault; private final TextColor arg2; private final TextColor arg3; + private final SoundData sound; - Pallet(TextColor mainText, TextColor argDefault, TextColor arg2, TextColor arg3) { + Pallet(TextColor mainText, TextColor argDefault, TextColor arg2, TextColor arg3, SoundData sound) { this.mainText = mainText; this.argDefault = argDefault; this.arg2 = arg2; this.arg3 = arg3; + this.sound = sound; } } -} - + + public record SoundData(Sound sound, float pitch){}; +} \ No newline at end of file