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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ spigot.yml
.project
.settings/
bin/

# Rift Engine lib
!RiftEngine-*.jar
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ repositories {
maven {
url "https://repo.dmulloy2.net/repository/public/"
}
// * GeyserMC
maven {url "https://repo.opencollab.dev/main/"}
maven {
url "https://jitpack.io" // Toujours à la fin
}
Expand All @@ -65,6 +67,11 @@ dependencies {
compileOnly "de.oliver:FancyNpcs:${fancyNpcsVersion}"
compileOnly "net.dmulloy2:ProtocolLib:${protocolLibVersion}"

// Bedrock Dependencies
compileOnly files("libs/RiftEngine-${riftEngineVersion}.jar")
compileOnly "org.geysermc.geyser:api:${geyserApiVersion}"
compileOnly "org.geysermc.floodgate:api:${floodgateApiVersion}"

implementation "org.jetbrains:annotations:${jetbrainsAnnotationsVersion}"
implementation "io.github.revxrsal:lamp.common:${revxrsalLampVersion}"
implementation "io.github.revxrsal:lamp.bukkit:${revxrsalLampVersion}"
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ revxrsalLampVersion = 4.0.0-rc.17
ormVersion = 6.1
lombokVersion = 1.18.46

# Bedrock Dependencies
geyserApiVersion = 2.10.0-SNAPSHOT
floodgateApiVersion = 2.2.5-SNAPSHOT
riftEngineVersion = 0.1-SNAPSHOT

# Test Dependencies
slf4jVersion = 2.1.0-alpha1
junitVersion = 6.1.1
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file added libs/RiftEngine-0.1-SNAPSHOT.jar
Binary file not shown.
12 changes: 5 additions & 7 deletions src/main/java/fr/openmc/api/chronometer/Chronometer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -62,7 +61,7 @@ public static HandlerList getHandlerList() {
* @param group Chronometer group
* @param time duration in second
* @param messageType display type
* @param message to display the time
* @param key translation key
* @param finishMessageType display type
* @param finishMessage message display when the chronometer ends normally
*/
Expand All @@ -71,7 +70,7 @@ public static void startChronometer(
String group,
int time,
ChronometerType messageType,
Component message,
String key,
ChronometerType finishMessageType,
Component finishMessage
) {
Expand All @@ -92,11 +91,10 @@ public void run() {

int remainingTime = chronometer.get(entityUUID).get(group);

if (message != null && entity instanceof Player player) {
String timerMessage = PlainTextComponentSerializer.plainText().serialize(message)
.replace("%sec%", String.valueOf(remainingTime));
if (key != null && entity instanceof Player player) {
Component timerMessage = TranslationManager.translation(key, Component.text(remainingTime + "s"));

sendMessage(player, messageType, Component.text(timerMessage));
sendMessage(player, messageType, timerMessage);
}

if (timerEnd(entityUUID, group)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ public class ItemInteraction implements Listener {
/*
* Méthode qui permet de donner un objet à une personne et de quand elle clique avec l'Item, la méthode renverra la positon ou il a cliqué
*/
public static void runLocationInteraction(Player player, ItemStack item, String chronometerGroup, int chronometerTime, Component startMessage, Component endMessage, Function<Location, Boolean> result, Runnable onFail) {
public static void runLocationInteraction(Player player,
ItemStack item,
String chronometerGroup,
int chronometerTime,
String startMessage,
Component endMessage,
Function<Location, Boolean> result,
Runnable onFail) {
if (!ItemUtils.hasAvailableSlot(player)) {
MessagesManager.sendMessage(player,
TranslationManager.translation("api.iteminteraction.not_egnough_space"), Prefix.OPENMC, MessageType.ERROR, false);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/fr/openmc/core/OMCBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
import io.papermc.paper.registry.event.RegistryEvents;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -41,7 +39,7 @@ public void bootstrap(@NotNull BootstrapContext context) {

// ** LOAD TRANSLATION **
// this creates resource pack who is needed for item adder
TranslationManager.init(
TranslationManager.bootstrap(
context,
Locale.FRANCE,
Locale.US,
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ public void onEnable() {
public void loadAfterItemsAdder() {
ItemsAddersListener.setLoaded(true);

// todo: a rewrite lors registre hook et features
// try {
// new BedrockHook().startInit();
// } catch (NoClassDefFoundError e) {
// OMCLogger.error("Hook BedrockHook désactivé (package non trouvé) " + e.getMessage());
// }

/* LOAD ITEMS ADDER CONTENTS */
ItemsAdderHook.loadContents();

Expand Down
63 changes: 40 additions & 23 deletions src/main/java/fr/openmc/core/bootstrap/hooks/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.sql.SQLException;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand All @@ -18,64 +19,80 @@
public abstract class Hooks {
private static final Map<Class<? extends Hooks>, Boolean> ENABLED = new ConcurrentHashMap<>();

public boolean arePluginEnabled() {
if (!(this instanceof HttpsHook)) return true;
boolean enabled = true;

Set<String> pluginsName = getPluginsName();
for (String pluginName : pluginsName) {
PluginManager pluginManager = OMCPlugin.getInstance().getServer().getPluginManager();
boolean pluginEnable = pluginManager.getPlugin(pluginName) != null
&& pluginManager.isPluginEnabled(pluginName);

if (!pluginEnable) return false;
}

return enabled;
}
/**
* Verifie la presence du plugin cible, puis initialise le hook si actif.
*/
public void startInit() {
String pluginName = getPluginName();

if (this instanceof HttpsHook httpsHook) {
String hookName = httpsHook.getName();
try {
httpsHook.init();
OMCLogger.successFormatted("Hook " + pluginName + " activé.");
OMCLogger.successFormatted("Hook " + hookName + " activé.");
} catch (Exception e) {
OMCLogger.errorFormatted("Hook " + pluginName + " non activé.");
OMCLogger.errorFormatted("Hook " + hookName + " non activé.");
OMCLogger.error(e.getMessage(), e);
}
return;
}

PluginManager pluginManager = OMCPlugin.getInstance().getServer().getPluginManager();
boolean enabled = pluginManager.getPlugin(pluginName) != null
&& pluginManager.isPluginEnabled(pluginName);
ENABLED.put(getClass(), enabled);
if (enabled) {
init();
OMCLogger.successFormatted("Hook " + pluginName + " activé.");
return;
String hookName = this.getClass().getSimpleName();
try {
boolean enabled = arePluginEnabled();
if (enabled) {
ENABLED.put(getClass(), enabled);
this.init();
OMCLogger.successFormatted("Hook " + hookName + " activé.");
}
} catch (Throwable e) {
ENABLED.remove(getClass());
OMCLogger.errorFormatted("Hook " + hookName + " non activé.");
OMCLogger.error(e.getMessage(), e);
}
OMCLogger.errorFormatted("Hook " + pluginName + " non activé.");
}

/**
* Verifie la presence du plugin cible, puis save le hook si actif.
*/
public void startSave() {
String pluginName = getPluginName();

if (this instanceof HttpsHook httpsHook) {
String hookName = httpsHook.getName();
try {
httpsHook.save();
OMCLogger.successFormatted("Hook " + pluginName + " desactivé avec succes.");
OMCLogger.successFormatted("Hook " + hookName + " desactivé avec succes.");
} catch (Exception e) {
OMCLogger.errorFormatted("Hook " + pluginName + " a rencontré une erreur lors du save.");
OMCLogger.errorFormatted("Hook " + hookName + " a rencontré une erreur lors du save.");
OMCLogger.error(e.getMessage(), e);
}
return;
}

PluginManager pluginManager = OMCPlugin.getInstance().getServer().getPluginManager();
boolean enabled = pluginManager.getPlugin(pluginName) != null
&& pluginManager.isPluginEnabled(pluginName)
&& ENABLED.get(getClass()) != null
boolean enabled = arePluginEnabled() && ENABLED.get(getClass()) != null
&& ENABLED.get(getClass());

String hookName = this.getClass().getSimpleName();
if (enabled) {
ENABLED.remove(getClass());
save();
OMCLogger.successFormatted("Hook " + pluginName + " désactivé avec succès.");
OMCLogger.successFormatted("Hook " + hookName + " désactivé avec succès.");
return;
}
OMCLogger.errorFormatted("Hook " + pluginName + " désactivé avec échec.");
OMCLogger.errorFormatted("Hook " + hookName + " désactivé avec échec.");
}

/**
Expand Down Expand Up @@ -106,7 +123,7 @@ public static boolean isEnabled(Class<? extends Hooks> hookClass) {
*
* @return Nom du plugin cible
*/
protected abstract String getPluginName();
protected abstract Set<String> getPluginsName();

/**
* Initialise les méthodes du hook lorsqu'il est actif.
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/fr/openmc/core/bootstrap/hooks/HttpsHook.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.openmc.core.bootstrap.hooks;

import java.util.Collections;
import java.util.Set;

public abstract class HttpsHook extends Hooks {
abstract public String getName();

Expand All @@ -8,7 +11,7 @@ public static boolean isEnable() {
}

@Override
protected String getPluginName() {
return getName();
protected Set<String> getPluginsName() {
return Collections.singleton(getName());
}
}
6 changes: 3 additions & 3 deletions src/main/java/fr/openmc/core/commands/utils/Restart.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class Restart {
@Description("Redémarre le serveur après 1min")
@CommandPermission("omc.admin.commands.restart")
public void restart(CommandSender sender) {
if (sender instanceof Player) {
MessagesManager.sendMessage(sender, TranslationManager.translation("messages.global.cannot_do_this"), Prefix.OPENMC, MessageType.ERROR, false);
if (sender instanceof Player player) {
MessagesManager.sendMessage(player, TranslationManager.translation("messages.global.cannot_do_this"), Prefix.OPENMC, MessageType.ERROR, false);
return;
}

Expand All @@ -50,7 +50,7 @@ public void restart(CommandSender sender) {
if (player == null || !player.isOnline()) continue;


MessagesManager.sendMessage(sender, TranslationManager.translation("command.utils.restart.cannot_open_city_chest"), Prefix.OPENMC, MessageType.INFO, false);
MessagesManager.sendMessage(player, TranslationManager.translation("command.utils.restart.cannot_open_city_chest"), Prefix.OPENMC, MessageType.INFO, false);
player.closeInventory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public void getBits(
@Subcommand("set")
@Description("Permet de définir les bits d'un joueur")
@CommandPermission("omc.admin.commands.bits.set")
public void setBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete.class) OfflinePlayer target, @Range(min = 1E-10) double amount) {
public void setBits(CommandSender sender, @SuggestWith(OnlinePlayerAutoComplete.class) OfflinePlayer target, @Range(min = 1E-10) double amount) {
BitsManager.setBits(target.getUniqueId(), amount);
MessagesManager.sendMessage(player,
MessagesManager.sendMessage(sender,
TranslationManager.translation(
"feature.economy.bits.set.success",
Component.text(target.getName()).color(NamedTextColor.YELLOW),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void beginCreateCity(Player player, String cityName) {
getMascotStick(),
"mascot:stick",
300,
TranslationManager.translation("feature.city.mascot.mascot_wand.claim_mascot_wand"),
"feature.city.mascot.mascot_wand.claim_mascot_wand",
TranslationManager.translation("feature.city.mascot.mascot_wand.create_cancelled"),
location -> {
if (!isValidLocation(player, location)) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fr.openmc.core.features.city.commands.autocomplete.CityNameAutoComplete;
import fr.openmc.core.features.city.menu.list.CityListDetailsMenu;
import fr.openmc.core.features.economy.EconomyManager;
import fr.openmc.core.utils.bedrock.CharRemplacementUtils;
import fr.openmc.core.utils.text.messages.MessageType;
import fr.openmc.core.utils.text.messages.MessagesManager;
import fr.openmc.core.utils.text.messages.Prefix;
Expand Down Expand Up @@ -79,7 +80,7 @@ void list(Player player) {

Component line = Component.text("- ")
.append(Component.text(cityUUID.toString()).color(NamedTextColor.GRAY))
.append(Component.text(" "))
.append(Component.text(" " + CharRemplacementUtils.getPointChar(player) + " "))
.append(Component.text(name).color(NamedTextColor.WHITE))
.append(TranslationManager.translation("feature.city.admin.commands.list.copy_label")
.color(NamedTextColor.GREEN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public static Component getAliveMascotName(String cityName, double health, doubl
"feature.city.mascots.name.alive",
Component.text(cityName).decorate(TextDecoration.BOLD),
Component.text(formattedHealth).color(NamedTextColor.RED),
Component.text("/" + formattedMaxHealth + "").color(NamedTextColor.RED)
Component.text("/" + formattedMaxHealth + "").color(NamedTextColor.RED)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) {
mascotsMoveItem,
"mascots:moveInteraction",
120,
TranslationManager.translation("feature.city.mascots.menu.main.move.interaction.remaining"),
"feature.city.mascots.menu.main.move.interaction.remaining",
TranslationManager.translation("feature.city.mascots.menu.main.move.interaction.cancelled"),
mascotMove -> {
if (mascotMove == null) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void setWarp(Player player) {
getWarpWand(),
"mayor:wait-set-warp",
300,
TranslationManager.translation("feature.city.mayor.warp.interaction.remaining", Component.text("300s").color(NamedTextColor.GRAY)),
"feature.city.mayor.warp.interaction.remaining",
TranslationManager.translation("feature.city.mayor.warp.interaction.timeout"),
locationClick -> {
if (locationClick == null) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) {
itemToGive,
"mayor:mayor-npc-move",
300,
TranslationManager.translation("feature.city.mayor.npc.move.interaction.remaining", Component.text("300s").color(NamedTextColor.GRAY)),
"feature.city.mayor.npc.move.interaction.remaining",
TranslationManager.translation("feature.city.mayor.npc.move.interaction.timeout"),
locationClick -> {
if (locationClick == null) return true;
Expand Down Expand Up @@ -331,7 +331,7 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) {
itemToGive,
"mayor:owner-npc-move",
300,
TranslationManager.translation("feature.city.mayor.npc.move.interaction.remaining", Component.text("300s").color(NamedTextColor.GRAY)),
"feature.city.mayor.npc.move.interaction.remaining",
TranslationManager.translation("feature.city.mayor.npc.move.interaction.timeout"),
locationClick -> {
if (locationClick == null) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void onClose(InventoryCloseEvent event) {
itemToGive,
"mayor:owner-npc-move",
300,
TranslationManager.translation("feature.city.mayor.npc.move.interaction.remaining", Component.text("300s").color(NamedTextColor.GRAY)),
"feature.city.mayor.npc.move.interaction.remaining",
TranslationManager.translation("feature.city.mayor.npc.move.interaction.timeout"),
locationClick -> {
if (locationClick == null) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void onClose(InventoryCloseEvent event) {
itemToGive,
"mayor:owner-npc-move",
300,
TranslationManager.translation("feature.city.mayor.npc.move.interaction.remaining", Component.text("300s").color(NamedTextColor.GRAY)),
"feature.city.mayor.npc.move.interaction.remaining",
TranslationManager.translation("feature.city.mayor.npc.move.interaction.timeout"),
locationClick -> {
if (locationClick == null) return true;
Expand Down
Loading
Loading