Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-107 Multification setup #197

Merged
merged 9 commits into from
Oct 27, 2024
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
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ object Versions {
const val JETBRAINS_ANNOTATIONS = "24.1.0"

const val ETERNALCODE_COMMONS = "1.1.3"
// TODO: Multification.
const val MULTIFICATION = "1.1.4"

const val ADVENTURE_PLATFORM_BUKKIT = "4.3.4"
const val ADVENTURE_TEXT_MINIMESSAGE = "4.17.0"
const val ADVENTURE_API = "4.17.0"

const val LITE_COMMANDS = "3.5.0"
const val LITE_COMMANDS = "3.7.0"
const val OKAERI_CONFIGS_YAML_BUKKIT = "5.0.3"
const val OKAERI_CONFIGS_SERDES_COMMONS = "5.0.3"
const val OKAERI_CONFIGS_SERDES_BUKKIT = "5.0.3"
Expand Down
14 changes: 12 additions & 2 deletions eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ dependencies {

// kyori
implementation("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM_BUKKIT}")
implementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_TEXT_MINIMESSAGE}")
implementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_API}")
implementation("net.kyori:adventure-api") {
version {
strictly(Versions.ADVENTURE_API)
}
}

// litecommands
implementation("dev.rollczi:litecommands-bukkit:${Versions.LITE_COMMANDS}")
Expand Down Expand Up @@ -45,6 +50,10 @@ dependencies {

// PlaceholderAPI
compileOnly("me.clip:placeholderapi:${Versions.PLACEHOLDER_API}")

// Multification
implementation("com.eternalcode:multification-bukkit:${Versions.MULTIFICATION}")
implementation("com.eternalcode:multification-okaeri:${Versions.MULTIFICATION}")
}

bukkit {
Expand Down Expand Up @@ -92,7 +101,8 @@ tasks.shadowJar {
"org.apache.commons",
"javassist",
"com.github.benmanes.caffeine",
"com.eternalcode.commons"
"com.eternalcode.commons",
"com.eternalcode.multification"
).forEach { pack ->
relocate(pack, "$prefix.$pack")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.eternalcode.combat.event.EventCaller;
import com.eternalcode.combat.fight.FightManagerImpl;
import com.eternalcode.combat.fight.FightTask;
import com.eternalcode.combat.fight.bossbar.FightBossBarService;
import com.eternalcode.combat.fight.effect.FightEffectServiceImpl;
import com.eternalcode.combat.fight.logout.LogoutController;
import com.eternalcode.combat.fight.logout.LogoutService;
Expand All @@ -41,6 +40,7 @@
import com.eternalcode.combat.updater.UpdaterService;
import com.eternalcode.commons.adventure.AdventureLegacyColorPostProcessor;
import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor;
import com.eternalcode.multification.notice.Notice;
import com.google.common.base.Stopwatch;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
Expand Down Expand Up @@ -108,13 +108,12 @@ public void onEnable() {
.preProcessor(new AdventureLegacyColorPreProcessor())
.build();

FightBossBarService fightBossBarService = new FightBossBarService(this.pluginConfig, this.audienceProvider, miniMessage);

BridgeService bridgeService = new BridgeService(this.pluginConfig, server.getPluginManager(), this.getLogger(), this);
bridgeService.init(this.fightManager, server);
this.regionProvider = bridgeService.getRegionProvider();

NotificationAnnouncer notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, miniMessage);

NotificationAnnouncer notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, this.pluginConfig, miniMessage);

this.liteCommands = LiteBukkitFactory.builder(FALLBACK_PREFIX, this, server)
.message(LiteBukkitMessages.PLAYER_NOT_FOUND, this.pluginConfig.messages.playerNotFound)
Expand All @@ -129,9 +128,14 @@ public void onEnable() {
new EternalCombatReloadCommand(configService, notificationAnnouncer)
)

.result(Notice.class, (invocation, result, chain) -> notificationAnnouncer.create()
.viewer(invocation.sender())
.notice(result)
.send())

.build();

FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, fightBossBarService, notificationAnnouncer);
FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, notificationAnnouncer);
this.getServer().getScheduler().runTaskTimer(this, fightTask, 20L, 20L);

new Metrics(this, BSTATS_METRICS_ID);
Expand All @@ -153,7 +157,7 @@ public void onEnable() {
new RegionController(notificationAnnouncer, this.regionProvider, this.fightManager, this.pluginConfig),
new FightEffectController(this.pluginConfig.effect, this.fightEffectService, this.fightManager, this.getServer()),
new FightTagOutController(this.fightTagOutService),
new FightMessageController(this.fightManager, notificationAnnouncer, fightBossBarService, this.pluginConfig, this.getServer())
new FightMessageController(this.fightManager, notificationAnnouncer, this.pluginConfig, this.getServer())
).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this));

EternalCombatProvider.initialize(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.eternalcode.combat.config.ConfigService;
import com.eternalcode.combat.notification.NotificationAnnouncer;
import com.eternalcode.multification.bukkit.notice.BukkitNotice;
import com.eternalcode.multification.notice.Notice;
import com.google.common.base.Stopwatch;
import dev.rollczi.litecommands.annotations.async.Async;
import dev.rollczi.litecommands.annotations.command.Command;
Expand All @@ -10,13 +12,14 @@
import dev.rollczi.litecommands.annotations.permission.Permission;
import java.time.Duration;
import org.bukkit.command.CommandSender;
import panda.utilities.text.Formatter;

@Command(name = "combatlog", aliases = "combat")
@Permission("eternalcombat.reload")
public class EternalCombatReloadCommand {

private static final String RELOAD_MESSAGE = "<b><gradient:#8a1212:#fc6b03>EternalCombat:</gradient></b> Reloaded EternalCombat in <color:#fce303>{TIME}ms!</color>";
private static final Notice RELOAD_MESSAGE = BukkitNotice.builder()
Copy link
Member

@P1otrulla P1otrulla Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w tym przypadku może być proste Notice -> BukkitNotice różni się tym że posiada dodatkowo metody stricte pod dzwieki bukkitowe

.chat("<b><gradient:#8a1212:#fc6b03>EternalCombat:</gradient></b> Reloaded EternalCombat in <color:#fce303>{TIME}ms!</color>")
.build();

private final ConfigService configService;
private final NotificationAnnouncer announcer;
Expand All @@ -33,7 +36,11 @@ void execute(@Context CommandSender sender) {
this.configService.reload();

Duration elapsed = stopwatch.elapsed();
Formatter format = new Formatter().register("{TIME}", elapsed.toMillis());
this.announcer.sendMessage(sender, format.format(RELOAD_MESSAGE));
this.announcer.create()
.viewer(sender)
.notice(RELOAD_MESSAGE)
.placeholder("{TIME}", String.valueOf(elapsed.toMillis()))
.send();

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.eternalcode.combat.config;

import com.eternalcode.combat.notification.serializer.NotificationSerializer;
import com.eternalcode.multification.bukkit.notice.resolver.sound.SoundBukkitResolver;
import com.eternalcode.multification.notice.resolver.NoticeResolverDefaults;
import com.eternalcode.multification.notice.resolver.NoticeResolverRegistry;
import com.eternalcode.multification.okaeri.MultificationSerdesPack;
import eu.okaeri.configs.ConfigManager;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.serdes.commons.SerdesCommons;
Expand All @@ -18,10 +22,13 @@ public class ConfigService {
public <T extends OkaeriConfig> T create(Class<T> config, File file) {
T configFile = ConfigManager.create(config);

configFile.withConfigurer(new YamlBukkitConfigurer(), new SerdesCommons(), new SerdesBukkit());
configFile.withSerdesPack(registry -> {
registry.register(new NotificationSerializer());
});
YamlBukkitConfigurer yamlBukkitConfigurer = new YamlBukkitConfigurer();
NoticeResolverRegistry noticeRegistry = NoticeResolverDefaults.createRegistry()
.registerResolver(new SoundBukkitResolver());

configFile.withConfigurer(yamlBukkitConfigurer, new SerdesCommons(), new SerdesBukkit());
configFile.withConfigurer(yamlBukkitConfigurer, new MultificationSerdesPack(noticeRegistry));
configFile.withSerdesPack(registry -> registry.register(new NotificationSerializer()));

configFile.withBindFile(file);
configFile.withRemoveOrphans(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.eternalcode.combat.fight.drop.DropSettings;
import com.eternalcode.combat.fight.effect.FightEffectSettings;
import com.eternalcode.combat.fight.pearl.FightPearlSettings;
import com.eternalcode.combat.notification.Notification;
import com.eternalcode.combat.notification.implementation.ActionBarNotification;
import com.eternalcode.multification.bukkit.notice.BukkitNotice;
import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageEvent;

Expand All @@ -21,13 +23,13 @@ public class PluginConfig extends OkaeriConfig {
@Comment("# Do you want to change the plugin settings?")
public Settings settings = new Settings();

@Comment({" ", "# Ender pearl settings"})
@Comment({ " ", "# Ender pearl settings" })
public FightPearlSettings pearl = new FightPearlSettings();

@Comment({" ", "# Custom effects settings"})
@Comment({ " ", "# Custom effects settings" })
public FightEffectSettings effect = new FightEffectSettings();

@Comment({" ", "# Set a custom way for a player's items to drop on death (if in combat)"})
@Comment({ " ", "# Set a custom way for a player's items to drop on death (if in combat)" })
public DropSettings dropSettings = new DropSettings();

public static class Settings extends OkaeriConfig {
Expand All @@ -53,7 +55,7 @@ public static class Settings extends OkaeriConfig {
})
public double blockedRegionKnockMultiplier = 1;

@Comment({"# Should the player be prevented from entering regions with WorldGuard flag PVP set to DENY "})
@Comment({ "# Should the player be prevented from entering regions with WorldGuard flag PVP set to DENY " })
public boolean shouldPreventPvpRegions = true;

@Comment("# Set the radius of the blocked region if you aren't using WorldGuard basen on default spawn region!")
Expand All @@ -62,7 +64,7 @@ public static class Settings extends OkaeriConfig {
@Comment("# Release attacker after victim dies?")
public boolean shouldReleaseAttacker = true;

@Comment({"# If you want to exclude admins from combat, ",
@Comment({ "# If you want to exclude admins from combat, ",
"# Setting this to true - admins cannot be tagged and will not tag other players on hit",
"# Setting this to false - admins can be tagged and can tag other players on hit"
})
Expand Down Expand Up @@ -150,7 +152,7 @@ public enum BlockPlacingMode {

}

@Comment({" ", "# Do you want to change the plugin messages?"})
@Comment({ " ", "# Do you want to change the plugin messages?" })
public Messages messages = new Messages();

public static class Messages extends OkaeriConfig {
Expand All @@ -168,85 +170,88 @@ public static class Messages extends OkaeriConfig {
"# BossBar colors: https://javadoc.io/static/net.kyori/adventure-api/4.14.0/net/kyori/adventure/bossbar/BossBar.Color.html",
"# BossBar overlays: https://javadoc.io/static/net.kyori/adventure-api/4.14.0/net/kyori/adventure/bossbar/BossBar.Overlay.html"
})
public Notification combatNotification = new ActionBarNotification("&dCombat ends in: &f{TIME}");
public Notice combatNotification = BukkitNotice.builder()
.actionBar("&dCombat ends in: &f{TIME}")
.sound(Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 2.0F, 1.0F)
.build();

@Comment("# Message sent when the player does not have permission to perform a command")
public String noPermission = "&cYou don't have permission to perform this command!";
public Notice noPermission = Notice.chat("&cYou don't have permission \"{PERMISSION}\" to perform this command!");

@Comment("# Message sent when the specified player could not be found")
public String playerNotFound = "&cThe specified player could not be found!";
public Notice playerNotFound = Notice.chat("&cThe specified player could not be found!");

@Comment("# Message sent when the player enters combat")
public String playerTagged = "&cYou are in combat, do not leave the server!";
public Notice playerTagged = Notice.chat("&cYou are in combat, do not leave the server!");

@Comment("# Message sent when the player leaves combat")
public String playerUntagged = "&aYou are no longer in combat! You can safely leave the server.";
public Notice playerUntagged = Notice.chat("&aYou are no longer in combat! You can safely leave the server.");

@Comment("# This is broadcast when the player is in combat and logs out")
public String playerLoggedOutDuringCombat = "&c{PLAYER} logged off during the fight!";
public Notice playerLoggedOutDuringCombat = Notice.chat("&c{PLAYER} logged off during the fight!");

@Comment({
"# Message sent when the player is in combat and tries to use a disabled command",
"# you can configure the list of disabled commands in the blockedCommands section of the config.yml file"
})
public String commandDisabledDuringCombat = "&cUsing this command during combat is prohibited!";
public Notice commandDisabledDuringCombat = Notice.chat("&cUsing this command during combat is prohibited!");

@Comment("# Message sent when player tries to use a command with invalid arguments")
public String invalidCommandUsage = "&7Correct usage: &e{USAGE}";
public Notice invalidCommandUsage = Notice.chat("&7Correct usage: &e{USAGE}");

@Comment("# Message sent when player tries to open inventory, but the inventory open is blocked")
public String inventoryBlockedDuringCombat = "&cYou cannot open this inventory during combat!";
public Notice inventoryBlockedDuringCombat = Notice.chat("&cYou cannot open this inventory during combat!");

@Comment({"# Message sent when player tries to place a block, but the block place is blocked",
"# Placeholder {Y} is replaced with the Y coordinate set in the config",
"# Placeholder {MODE} is replaced with the mode set in the config"})
public String blockPlacingBlockedDuringCombat = "&cYou cannot place {MODE} {Y} coordinate during combat!";
@Comment({ "# Message sent when player tries to place a block, but the block place is blocked",
"# Placeholder {Y} is replaced with the Y coordinate set in the config",
"# Placeholder {MODE} is replaced with the mode set in the config" })
public Notice blockPlacingBlockedDuringCombat = Notice.chat("&cYou cannot place {MODE} {Y} coordinate during combat!");

@Comment("# Message sent when player tries to enter a region")
public String cantEnterOnRegion = "&cYou can't enter this region during combat!";
public Notice cantEnterOnRegion = Notice.chat("&cYou can't enter this region during combat!");

public static class AdminMessages extends OkaeriConfig {
@Comment("# Message sent when console tries to use a command that is only for players")
public String onlyForPlayers = "&cThis command is only available to players!";
public Notice onlyForPlayers = Notice.chat("&cThis command is only available to players!");

@Comment("# Message sent to admin when they tag a player")
public String adminTagPlayer = "&7You have tagged &e{PLAYER}";
public Notice adminTagPlayer = Notice.chat("&7You have tagged &e{PLAYER}");

@Comment("# Message sent when a player is tagged by an admin")
public String adminTagMultiplePlayers = "&7You have tagged &e{FIRST_PLAYER}&7 and &e{SECOND_PLAYER}&7.";
public Notice adminTagMultiplePlayers = Notice.chat("&7You have tagged &e{FIRST_PLAYER}&7 and &e{SECOND_PLAYER}&7.");

@Comment("# Message sent to admin when they remove a player from combat")
public String adminUntagPlayer = "&7You have removed &e{PLAYER}&7 from the fight.";
public Notice adminUntagPlayer = Notice.chat("&7You have removed &e{PLAYER}&7 from the fight.");

@Comment("# Message sent when the player is not in combat")
public String adminPlayerNotInCombat = "&cThis player is not in combat!";
public Notice adminPlayerNotInCombat = Notice.chat("&cThis player is not in combat!");

@Comment("# Message sent when the player is in combat")
public String playerInCombat = "&c{PLAYER} is currently in combat!";
public Notice playerInCombat = Notice.chat("&c{PLAYER} is currently in combat!");

@Comment("# Message sent when a player is not in combat")
public String playerNotInCombat = "&a{PLAYER} is not currently in combat.";
public Notice playerNotInCombat = Notice.chat("&a{PLAYER} is not currently in combat.");

@Comment("# Message sent when an admin tries to tag themselves")
public String adminCannotTagSelf = "&cYou cannot tag yourself!";
public Notice adminCannotTagSelf = Notice.chat("&cYou cannot tag yourself!");

@Comment("# Message sent when an admin disables the ability to get tagged for some time")
public String adminTagOutSelf = "&7Successfully disabled tag for Yourself! You will be taggable after &e{TIME} ";
public Notice adminTagOutSelf = Notice.chat("&7Successfully disabled tag for Yourself! You will be taggable after &e{TIME} ");

@Comment("# Message sent when an admin disables the ability to get tagged for some time for other player")
public String adminTagOut = "&7Successfully disabled tag for &e{PLAYER}! They will be taggable after &e{TIME} ";
public Notice adminTagOut = Notice.chat("&7Successfully disabled tag for &e{PLAYER}! They will be taggable after &e{TIME} ");

@Comment("# Message sent to the player whom the ability to get tagged for some time has been disabled")
public String playerTagOut = "&7You will be taggable in &e{TIME} !";
public Notice playerTagOut = Notice.chat("&7You will be taggable in &e{TIME} !");

@Comment("# Message sent when an admin reenables the ability to get tagged for the player")
public String adminTagOutOff = "&7Successfully enabled tag for &e{PLAYER}!";
public Notice adminTagOutOff = Notice.chat("&7Successfully enabled tag for &e{PLAYER}!");

@Comment("# Message sent to the player whom the ability to get tagged has been reenabled")
public String playerTagOutOff = "&7You are now taggable!";
public Notice playerTagOutOff = Notice.chat("&7You are now taggable!");

@Comment("# Message sent when player cannot be tagged because they have enabled tag-out")
public String adminTagOutCanceled = "&cCannot tag this player due to tag-out!";
public Notice adminTagOutCanceled = Notice.chat("&cCannot tag this player due to tag-out!");
}
}
}
Loading
Loading