diff --git a/src/main/java/fr/openmc/core/OMCPlugin.java b/src/main/java/fr/openmc/core/OMCPlugin.java index 8ffb27f43..9349c0050 100644 --- a/src/main/java/fr/openmc/core/OMCPlugin.java +++ b/src/main/java/fr/openmc/core/OMCPlugin.java @@ -37,6 +37,7 @@ import fr.openmc.core.features.events.contents.dailyevents.DailyEventsManager; import fr.openmc.core.features.events.contents.halloween.managers.HalloweenManager; import fr.openmc.core.features.events.contents.weeklyevents.WeeklyEventsManager; +import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.ContestParticlesUtils; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers.ContestManager; import fr.openmc.core.features.friend.FriendManager; import fr.openmc.core.features.homes.HomesManager; @@ -61,7 +62,6 @@ import fr.openmc.core.hooks.github.GitHubHook; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; import fr.openmc.core.listeners.ItemsAddersListener; -import fr.openmc.core.utils.bukkit.ParticleUtils; import fr.openmc.core.utils.text.MotdUtils; import io.papermc.paper.datapack.Datapack; import lombok.Getter; @@ -235,7 +235,7 @@ public void loadAfterItemsAdder() { }); if (WorldGuardHook.isEnable()) { - ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130); + ContestParticlesUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130); } } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java index cdccfd85d..2c5232cbf 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java @@ -27,7 +27,6 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -80,9 +79,7 @@ public static void createNPCS(UUID cityUUID, Location locationMayor, Location lo if (city.getMayor().getMayorUUID() != null && city.getElectionType() == ElectionType.ELECTION) { String mayorName = CacheOfflinePlayer.getOfflinePlayer(city.getMayor().getMayorUUID()).getName(); dataMayor.setSkin(mayorName); - String mayorDisplayName = "" + LegacyComponentSerializer.legacySection() - .serialize(TranslationManager.translation("feature.city.mayor.npc.display.mayor", Component.text(mayorName))) + ""; - dataMayor.setDisplayName(mayorDisplayName); + dataMayor.setDisplayName(""); dataMayor.addEquipment(NpcEquipmentSlot.HEAD, OMCRegistry.CUSTOM_ITEMS.SUIT_HELMET.getBest()); dataMayor.addEquipment(NpcEquipmentSlot.CHEST, OMCRegistry.CUSTOM_ITEMS.SUIT_CHESTPLATE.getBest()); @@ -90,9 +87,7 @@ public static void createNPCS(UUID cityUUID, Location locationMayor, Location lo dataMayor.addEquipment(NpcEquipmentSlot.FEET, OMCRegistry.CUSTOM_ITEMS.SUIT_BOOTS.getBest()); } else { dataMayor.setSkin("https://s.namemc.com/i/1971f3c39cb8e3ef.png"); - String unknownDisplayName = "" + LegacyComponentSerializer.legacySection() - .serialize(TranslationManager.translation("feature.city.mayor.npc.display.unknown")) + ""; - dataMayor.setDisplayName(unknownDisplayName); + dataMayor.setDisplayName(""); } Npc npcMayor = FancyNpcsPlugin.get().getNpcAdapter().apply(dataMayor); @@ -100,9 +95,8 @@ public static void createNPCS(UUID cityUUID, Location locationMayor, Location lo NpcData dataOwner = new NpcData("owner-" + cityUUID, creatorUUID, locationOwner); String ownerName = CacheOfflinePlayer.getOfflinePlayer(city.getPlayerWithPermission(CityPermission.OWNER)).getName(); dataOwner.setSkin(ownerName); - String ownerDisplayName = LegacyComponentSerializer.legacySection() - .serialize(TranslationManager.translation("feature.city.mayor.npc.display.owner", Component.text(ownerName))); - dataOwner.setDisplayName("" + ownerDisplayName + ""); + + dataOwner.setDisplayName(""); Npc npcOwner = FancyNpcsPlugin.get().getNpcAdapter().apply(dataOwner); diff --git a/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java b/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java index b91b89ef3..fa46b2ab7 100644 --- a/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java +++ b/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java @@ -7,8 +7,6 @@ import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.dream.DreamDimensionManager; import fr.openmc.core.hooks.FancyNpcsHook; -import fr.openmc.core.utils.text.messages.TranslationManager; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.EntityType; @@ -40,8 +38,7 @@ public static void createNPC(Location locationNpc) { UUID npcUUID = UUID.randomUUID(); NpcData data = new NpcData("glacite-" + npcUUID, null, locationNpc); - data.setDisplayName(LegacyComponentSerializer.legacySection() - .serialize(TranslationManager.translation("feature.dream.trader.npc.name"))); + data.setDisplayName(""); data.setType(EntityType.ILLUSIONER); data.setTurnToPlayerDistance(10); data.setTurnToPlayer(true); diff --git a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/ContestParticlesUtils.java b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/ContestParticlesUtils.java new file mode 100644 index 000000000..c35397a40 --- /dev/null +++ b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/ContestParticlesUtils.java @@ -0,0 +1,123 @@ +package fr.openmc.core.features.events.contents.weeklyevents.contents.contest; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import fr.openmc.core.OMCPlugin; +import fr.openmc.core.features.events.contents.weeklyevents.WeeklyEventsManager; +import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers.ContestManager; +import fr.openmc.core.utils.RandomUtils; +import fr.openmc.core.utils.bukkit.ParticleUtils; +import fr.openmc.core.utils.text.ColorUtils; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.*; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +public class ContestParticlesUtils { + + + public static Color color1; + public static Color color2; + + public static void spawnParticlesInRegion(String regionId, World world, Particle particle, int amountPer2Tick, int minHeight, int maxHeight) { + RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); + if (regionManager == null) return; + + ProtectedRegion region = regionManager.getRegion(regionId); + if (region == null) return; + + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + + Location minLocation = new Location(world, min.x(), minHeight, min.z()); + Location maxLocation = new Location(world, max.x(), maxHeight, max.z()); + + new BukkitRunnable() { + @Override + public void run() { + if (WeeklyEventsManager.getCurrentEvent() != null) return; + + for (int i = 0; i < amountPer2Tick; i++) { + double x = RandomUtils.randomBetween(minLocation.getX(), maxLocation.getX()); + double y = RandomUtils.randomBetween(minLocation.getY(), maxLocation.getY()); + double z = RandomUtils.randomBetween(minLocation.getZ(), maxLocation.getZ()); + + Location particleLocation = new Location(world, x, y, z); + + for (Player player : Bukkit.getOnlinePlayers()) { + if (!player.getWorld().equals(world)) continue; + + if (!region.contains(BukkitAdapter.asBlockVector(player.getLocation()))) continue; + + ParticleUtils.sendParticlePacket(player, particle, particleLocation); + } + } + } + }.runTaskTimerAsynchronously(OMCPlugin.getInstance(), 0L, 2L); + } + + public static void spawnContestParticlesInRegion(String regionId, World world, int amountPer2Tick, int minHeight, int maxHeight) { + RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); + if (regionManager == null) return; + + ProtectedRegion region = regionManager.getRegion(regionId); + if (region == null) return; + + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + + Location minLocation = new Location(world, min.x(), minHeight, min.z()); + Location maxLocation = new Location(world, max.x(), maxHeight, max.z()); + + new BukkitRunnable() { + @Override + public void run() { + if (!(WeeklyEventsManager.getCurrentEvent() instanceof Contest)) return; + if (WeeklyEventsManager.getCurrentPhase() == ContestPhase.END_PHASE.getPhase()) return; + + if (color1 == null || color2 == null) { + String camp1Color = ContestManager.data.getColor1(); + String camp2Color = ContestManager.data.getColor2(); + + if (camp1Color == null || camp1Color.isEmpty()) { + camp1Color = "WHITE"; + } + + if (camp2Color == null || camp2Color.isEmpty()) { + camp2Color = "BLACK"; + } + + NamedTextColor colorCamp1 = ColorUtils.getNamedTextColor(camp1Color); + NamedTextColor colorCamp2 = ColorUtils.getNamedTextColor(camp2Color); + + int[] rgb1 = ColorUtils.getRGBFromNamedTextColor(colorCamp1); + int[] rgb2 = ColorUtils.getRGBFromNamedTextColor(colorCamp2); + + color1 = Color.fromRGB(rgb1[0], rgb1[1], rgb1[2]); + color2 = Color.fromRGB(rgb2[0], rgb2[1], rgb2[2]); + } + + for (int i = 0; i < amountPer2Tick; i++) { + double x = RandomUtils.randomBetween(minLocation.getX(), maxLocation.getX()); + double y = RandomUtils.randomBetween(minLocation.getY(), maxLocation.getY()); + double z = RandomUtils.randomBetween(minLocation.getZ(), maxLocation.getZ()); + + Location base = new Location(world, x, y, z); + ParticleUtils.spawnRisingDustParticle(regionId, world, base, color1, 1.0f, 15, 1); + } + + for (int i = 0; i < amountPer2Tick; i++) { + double x = RandomUtils.randomBetween(minLocation.getX(), maxLocation.getX()); + double y = RandomUtils.randomBetween(minLocation.getY(), maxLocation.getY()); + double z = RandomUtils.randomBetween(minLocation.getZ(), maxLocation.getZ()); + + Location base = new Location(world, x, y, z); + ParticleUtils.spawnRisingDustParticle(regionId, world, base, color2, 1.0f, 15, 1); + } + } + }.runTaskTimerAsynchronously(OMCPlugin.getInstance(), 0L, 2L); + } +} diff --git a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java index aa0cf0d28..3775ff3ab 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java @@ -15,6 +15,7 @@ import fr.openmc.core.bootstrap.integration.DatabaseManager; import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.ContestParticlesUtils; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.commands.ContestCommand; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.events.ContestEndEvent; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.listeners.ContestIntractEvents; @@ -28,7 +29,6 @@ import fr.openmc.core.features.mailboxes.MailboxManager; import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; -import fr.openmc.core.utils.bukkit.ParticleUtils; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.ColorUtils; import fr.openmc.core.utils.text.messages.TranslationManager; @@ -105,7 +105,7 @@ public void init() { // ** PARTICLE REGION ** if (WorldGuardHook.isEnable()) { - ParticleUtils.spawnContestParticlesInRegion("spawn", Bukkit.getWorld("world"), 10, 70, 135); + ContestParticlesUtils.spawnContestParticlesInRegion("spawn", Bukkit.getWorld("world"), 10, 70, 135); } } @@ -210,8 +210,8 @@ public static void clearDB() { * - Diffuse un message et joue un son aux joueurs connectés */ public static void initPhase1() { - ParticleUtils.color1 = null; - ParticleUtils.color2 = null; + ContestParticlesUtils.color1 = null; + ContestParticlesUtils.color2 = null; Bukkit.broadcast(TranslationManager.translation("feature.events.contest.broadcast.phase1")); @@ -253,8 +253,8 @@ public static void initPhase2() { * - Réinitialise les données en DB pour le prochain contest */ public static void initPhase3() { - ParticleUtils.color1 = null; - ParticleUtils.color2 = null; + ContestParticlesUtils.color1 = null; + ContestParticlesUtils.color2 = null; for (Player player : Bukkit.getOnlinePlayers()) { InventoryView openInv = player.getOpenInventory(); diff --git a/src/main/java/fr/openmc/core/utils/bukkit/ParticleUtils.java b/src/main/java/fr/openmc/core/utils/bukkit/ParticleUtils.java index 1f693ae36..b48913293 100644 --- a/src/main/java/fr/openmc/core/utils/bukkit/ParticleUtils.java +++ b/src/main/java/fr/openmc/core/utils/bukkit/ParticleUtils.java @@ -1,18 +1,10 @@ package fr.openmc.core.utils.bukkit; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.features.events.contents.weeklyevents.WeeklyEventsManager; -import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.Contest; -import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.ContestPhase; -import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers.ContestManager; -import fr.openmc.core.utils.RandomUtils; -import fr.openmc.core.utils.text.ColorUtils; -import net.kyori.adventure.text.format.NamedTextColor; import net.minecraft.core.particles.DustParticleOptions; import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; import net.minecraft.server.level.ServerPlayer; @@ -33,11 +25,6 @@ public class ParticleUtils { - private static final double MAX_PARTICLE_DISTANCE_SQR = 100 * 100; - - public static Color color1; - public static Color color2; - /** * based on {@link org.bukkit.craftbukkit.CraftParticle} */ @@ -61,6 +48,19 @@ public class ParticleUtils { PARTICLE_FALLBACKS.put("flash", () -> Color.WHITE); PARTICLE_FALLBACKS.put("effect", () -> new Particle.Spell(Color.WHITE, 1.0f)); PARTICLE_FALLBACKS.put("instant_effect", () -> new Particle.Spell(Color.WHITE, 1.0f)); + PARTICLE_FALLBACKS.put("vibration", () -> new Vibration( + new Vibration.Destination.BlockDestination(new Location(null, 0, 0, 0)), + 20 + )); + PARTICLE_FALLBACKS.put("trail", () -> new Particle.Trail( + new Location(null, 0, 0, 0), + Color.RED, + 20 + )); + PARTICLE_FALLBACKS.put("geyser", () -> new Particle.Geyser(1)); + PARTICLE_FALLBACKS.put("geyser_plume", () -> new Particle.Geyser(1)); + PARTICLE_FALLBACKS.put("geyser_base", () -> new Particle.GeyserBase(1, 1.0f)); + PARTICLE_FALLBACKS.put("geyser_poof", () -> new Particle.GeyserBase(1, 1.0f)); } public static void sendRandomCubeParticles(Player player, Particle particle, double radius, int amount) { @@ -76,44 +76,6 @@ public static void sendRandomCubeParticles(Player player, Particle particle, dou } } - public static void spawnParticlesInRegion(String regionId, World world, Particle particle, int amountPer2Tick, int minHeight, int maxHeight) { - RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); - if (regionManager == null) return; - - ProtectedRegion region = regionManager.getRegion(regionId); - if (region == null) return; - - BlockVector3 min = region.getMinimumPoint(); - BlockVector3 max = region.getMaximumPoint(); - - Location minLocation = new Location(world, min.x(), minHeight, min.z()); - Location maxLocation = new Location(world, max.x(), maxHeight, max.z()); - - new BukkitRunnable() { - @Override - public void run() { - if (!(WeeklyEventsManager.getCurrentEvent() instanceof Contest)) return; - if (WeeklyEventsManager.getCurrentPhase() == ContestPhase.END_PHASE.getPhase()) return; - - for (int i = 0; i < amountPer2Tick; i++) { - double x = RandomUtils.randomBetween(minLocation.getX(), maxLocation.getX()); - double y = RandomUtils.randomBetween(minLocation.getY(), maxLocation.getY()); - double z = RandomUtils.randomBetween(minLocation.getZ(), maxLocation.getZ()); - - Location particleLocation = new Location(world, x, y, z); - - for (Player player : Bukkit.getOnlinePlayers()) { - if (!player.getWorld().equals(world)) continue; - - if (!region.contains(BukkitAdapter.asBlockVector(player.getLocation()))) continue; - - sendParticlePacket(player, particle, particleLocation); - } - } - } - }.runTaskTimerAsynchronously(OMCPlugin.getInstance(), 0L, 2L); - } - public static void sendParticlePacket(Particle particle, Location loc, int radius) { sendParticlePacket(particle, loc, loc.getNearbyEntitiesByType(Player.class, radius)); } @@ -165,68 +127,6 @@ public static void sendParticlePacket(Player player, Particle particle, Loca nmsPlayer.connection.send(packet); } - public static void spawnContestParticlesInRegion(String regionId, World world, int amountPer2Tick, int minHeight, int maxHeight) { - RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); - if (regionManager == null) return; - - ProtectedRegion region = regionManager.getRegion(regionId); - if (region == null) return; - - BlockVector3 min = region.getMinimumPoint(); - BlockVector3 max = region.getMaximumPoint(); - - Location minLocation = new Location(world, min.x(), minHeight, min.z()); - Location maxLocation = new Location(world, max.x(), maxHeight, max.z()); - - new BukkitRunnable() { - @Override - public void run() { - if (!(WeeklyEventsManager.getCurrentEvent() instanceof Contest)) return; - if (WeeklyEventsManager.getCurrentPhase() == ContestPhase.END_PHASE.getPhase()) return; - - if (color1 == null || color2 == null) { - String camp1Color = ContestManager.data.getColor1(); - String camp2Color = ContestManager.data.getColor2(); - - if (camp1Color == null || camp1Color.isEmpty()) { - camp1Color = "WHITE"; - } - - if (camp2Color == null || camp2Color.isEmpty()) { - camp2Color = "BLACK"; - } - - NamedTextColor colorCamp1 = ColorUtils.getNamedTextColor(camp1Color); - NamedTextColor colorCamp2 = ColorUtils.getNamedTextColor(camp2Color); - - int[] rgb1 = ColorUtils.getRGBFromNamedTextColor(colorCamp1); - int[] rgb2 = ColorUtils.getRGBFromNamedTextColor(colorCamp2); - - color1 = Color.fromRGB(rgb1[0], rgb1[1], rgb1[2]); - color2 = Color.fromRGB(rgb2[0], rgb2[1], rgb2[2]); - } - - for (int i = 0; i < amountPer2Tick; i++) { - double x = RandomUtils.randomBetween(minLocation.getX(), maxLocation.getX()); - double y = RandomUtils.randomBetween(minLocation.getY(), maxLocation.getY()); - double z = RandomUtils.randomBetween(minLocation.getZ(), maxLocation.getZ()); - - Location base = new Location(world, x, y, z); - spawnRisingDustParticle(regionId, world, base, color1, 1.0f, 15, 1); - } - - for (int i = 0; i < amountPer2Tick; i++) { - double x = RandomUtils.randomBetween(minLocation.getX(), maxLocation.getX()); - double y = RandomUtils.randomBetween(minLocation.getY(), maxLocation.getY()); - double z = RandomUtils.randomBetween(minLocation.getZ(), maxLocation.getZ()); - - Location base = new Location(world, x, y, z); - spawnRisingDustParticle(regionId, world, base, color2, 1.0f, 15, 1); - } - } - }.runTaskTimerAsynchronously(OMCPlugin.getInstance(), 0L, 2L); - } - public static void spawnRisingDustParticle(String regionId, World world, Location origin, Color color, float size, int steps, int count) { RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); if (regionManager == null) return; @@ -257,7 +157,7 @@ public void run() { if (!region.contains(BukkitAdapter.asBlockVector(player.getLocation()))) continue; - if (player.getLocation().distanceSquared(origin) > MAX_PARTICLE_DISTANCE_SQR) continue; + if (player.getLocation().distanceSquared(origin) > 100) continue; ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(