Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,29 +79,24 @@ 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 = "<gold>" + LegacyComponentSerializer.legacySection()
.serialize(TranslationManager.translation("feature.city.mayor.npc.display.mayor", Component.text(mayorName))) + "</gold>";
dataMayor.setDisplayName(mayorDisplayName);
dataMayor.setDisplayName("<gold><lang:feature.city.mayor.npc.display.mayor:" + mayorName + "></gold>");

dataMayor.addEquipment(NpcEquipmentSlot.HEAD, OMCRegistry.CUSTOM_ITEMS.SUIT_HELMET.getBest());
dataMayor.addEquipment(NpcEquipmentSlot.CHEST, OMCRegistry.CUSTOM_ITEMS.SUIT_CHESTPLATE.getBest());
dataMayor.addEquipment(NpcEquipmentSlot.LEGS, OMCRegistry.CUSTOM_ITEMS.SUIT_LEGGINGS.getBest());
dataMayor.addEquipment(NpcEquipmentSlot.FEET, OMCRegistry.CUSTOM_ITEMS.SUIT_BOOTS.getBest());
} else {
dataMayor.setSkin("https://s.namemc.com/i/1971f3c39cb8e3ef.png");
String unknownDisplayName = "<dark_gray>" + LegacyComponentSerializer.legacySection()
.serialize(TranslationManager.translation("feature.city.mayor.npc.display.unknown")) + "</dark_gray>";
dataMayor.setDisplayName(unknownDisplayName);
dataMayor.setDisplayName("<dark_gray><lang:feature.city.mayor.npc.display.unknown></dark_gray>");
}

Npc npcMayor = FancyNpcsPlugin.get().getNpcAdapter().apply(dataMayor);

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("<yellow>" + ownerDisplayName + "</yellow>");

dataOwner.setDisplayName("<yellow><lang:feature.city.mayor.npc.display.owner:" + ownerName + "></yellow>");

Npc npcOwner = FancyNpcsPlugin.get().getNpcAdapter().apply(dataOwner);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("<lang:feature.dream.trader.npc.name>");
data.setType(EntityType.ILLUSIONER);
data.setTurnToPlayerDistance(10);
data.setTurnToPlayer(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -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();
Expand Down
Loading
Loading