diff --git a/api/src/main/java/io/github/pronze/sba/game/tasks/BaseGameTask.java b/api/src/main/java/io/github/pronze/sba/game/tasks/BaseGameTask.java index 04a58623..db856854 100644 --- a/api/src/main/java/io/github/pronze/sba/game/tasks/BaseGameTask.java +++ b/api/src/main/java/io/github/pronze/sba/game/tasks/BaseGameTask.java @@ -4,9 +4,10 @@ import lombok.Data; import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.api.game.GameStatus; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; -import org.screamingsandals.lib.tasker.task.TaskerTask; +import org.screamingsandals.lib.tasker.task.Task; import java.util.UUID; @@ -17,7 +18,7 @@ public abstract class BaseGameTask { protected Game game; private long duration; private TaskerTime timeUnit; - private TaskerTask task; + private Task task; private boolean started; public BaseGameTask() { @@ -32,7 +33,7 @@ public BaseGameTask start(IArena arena) { if (task != null) { task.cancel(); } - task = Tasker.build(this::loopLogic).repeat(duration, timeUnit).start(); + task = Tasker.runRepeatedly(DefaultThreads.GLOBAL_THREAD, this::loopLogic, duration, timeUnit); return this; } diff --git a/api/src/main/java/io/github/pronze/sba/lang/Message.java b/api/src/main/java/io/github/pronze/sba/lang/Message.java index 1a3f3443..605b6c60 100644 --- a/api/src/main/java/io/github/pronze/sba/lang/Message.java +++ b/api/src/main/java/io/github/pronze/sba/lang/Message.java @@ -3,25 +3,21 @@ import io.github.pronze.sba.AddonAPI; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; -import net.kyori.adventure.text.minimessage.MiniMessage; import org.screamingsandals.lib.spectator.Component; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.sender.CommandSenderWrapper; -import org.screamingsandals.lib.sender.CommandSenderWrapper.Type; +import org.screamingsandals.lib.sender.CommandSender; +import org.screamingsandals.lib.sender.CommandSender.Type; import java.util.ArrayList; import java.util.List; import java.util.function.Function; -import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.libs.kyori.adventure.text.ComponentLike; @RequiredArgsConstructor(staticName = "of", access = AccessLevel.PRIVATE) public class Message implements Cloneable { @@ -237,7 +233,7 @@ public List toComponentList() { .collect(Collectors.toList()); } - public void send(CommandSenderWrapper... wrapper) { + public void send(CommandSender... wrapper) { // var message = toComponentList(); // for (var sender : wrapper) { // message.forEach(sender::sendMessage); @@ -252,7 +248,7 @@ public void send(CommandSenderWrapper... wrapper) { } } - public void send(List wrapperList) { + public void send(List wrapperList) { wrapperList.forEach(receiver -> { Player target = null; diff --git a/api/src/main/java/io/github/pronze/sba/wrapper/SBAPlayerWrapper.java b/api/src/main/java/io/github/pronze/sba/wrapper/SBAPlayerWrapper.java index 51f30c78..fdec38ee 100644 --- a/api/src/main/java/io/github/pronze/sba/wrapper/SBAPlayerWrapper.java +++ b/api/src/main/java/io/github/pronze/sba/wrapper/SBAPlayerWrapper.java @@ -8,7 +8,7 @@ import lombok.Getter; import lombok.Setter; import org.screamingsandals.bedwars.Main; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -19,12 +19,12 @@ @Getter @Setter -public class SBAPlayerWrapper extends org.screamingsandals.lib.player.ExtendablePlayerWrapper { +public class SBAPlayerWrapper extends org.screamingsandals.lib.player.ExtendablePlayer { private int shoutCooldown; private final ToggleableSetting settings; public SBAPlayerWrapper(Player player) { - super(org.screamingsandals.lib.player.PlayerMapper.wrapPlayer(player)); + super(Players.wrapPlayer(player)); this.shoutCooldown = 0; this.settings = ToggleableSetting.of(PlayerSetting.class); @@ -50,7 +50,7 @@ public void shout(Component message) { Collection receivers = Bukkit.getOnlinePlayers(); if(Main.isPlayerInGame(as(Player.class))) receivers=Main.getInstance().getGameOfPlayer(as(Player.class)).getConnectedPlayers(); - receivers.forEach(receiver->PlayerMapper.wrapPlayer(receiver).sendMessage(message)); + receivers.forEach(receiver->Players.wrapPlayer(receiver).sendMessage(message)); if (getInstance().hasPermission(Permissions.SHOUT_BYPASS.getKey()) || getDefaultShoutCoolDownTime() == 0) { return; } diff --git a/gradle.properties b/gradle.properties index cdda703a..b7bb3955 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,8 +7,8 @@ KYORI_ADVENTURE_VERSION=4.11.0 KYORI_ADVENTURE_TEXT_MINIMESSAGE_VERSION=4.11.0 KYORI_ADVENTURE_PLATFORM_BUKKIT_VERSION=4.11.0 PAPI_VERSION=2.11.1 -SCREAMINGLIB_VERSION=2.0.2-SNAPSHOT -SIMPLEINVENTORIES_VERSION=2.0.2-SNAPSHOT +SCREAMINGLIB_VERSION=2.0.3-SNAPSHOT +SIMPLEINVENTORIES_VERSION=2.0.3-SNAPSHOT SCREAMING_PLUGIN_BUILDER_VERSION=1.0.76 org.gradle.jvmargs='-Dfile.encoding=UTF-8' BUILDCONFIG_VERSION=3.0.2 diff --git a/plugin/build.gradle b/plugin/build.gradle index 06beb303..5447736a 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -34,6 +34,7 @@ dependencies { implementation "cloud.commandframework:cloud-annotations:" + CLOUD_COMMANDS_VERSION, { exclude group: 'net.kyori' } + implementation 'org.spongepowered:configurate-yaml:4.1.2' compileOnly "net.citizensnpcs:citizens-main:2.0.31-SNAPSHOT" } test { diff --git a/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/Scoreboard.java b/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/Scoreboard.java index 7e9f915f..f1c8d519 100644 --- a/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/Scoreboard.java +++ b/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/Scoreboard.java @@ -9,16 +9,8 @@ import io.github.pronze.lib.pronzelib.scoreboards.api.PlaceholderFunction; import java.util.ArrayList; import org.bukkit.Bukkit; -import io.github.pronze.lib.pronzelib.scoreboards.animations.ScoreboardAnimator; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Collector; import java.util.stream.Collectors; import java.util.Objects; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.Iterator; -import java.util.Collections; import java.util.HashMap; import io.github.pronze.lib.pronzelib.scoreboards.builder.ScoreboardBuilder; @@ -26,7 +18,6 @@ import io.github.pronze.lib.pronzelib.scoreboards.scoreboardr.board.BoardPlayer; import io.github.pronze.lib.pronzelib.scoreboards.scoreboardr.board.ConfigBoard; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import java.util.List; import java.util.Map; @@ -34,15 +25,9 @@ import io.github.pronze.lib.pronzelib.scoreboards.api.UpdateCallback; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.player.PlayerWrapper; -import org.screamingsandals.lib.sidebar.Sidebar; -import org.screamingsandals.lib.sidebar.SidebarImpl; -import org.screamingsandals.lib.utils.visual.TextEntry; -import io.github.pronze.sba.utils.Logger; import me.clip.placeholderapi.PlaceholderAPI; -import org.screamingsandals.lib.spectator.Component; +import org.screamingsandals.lib.player.Players; public class Scoreboard { private ConfigBoard holder; @@ -56,7 +41,7 @@ public class Scoreboard { private List animatedTitle; private boolean updateTaskRunning; private boolean animationTaskRunning; - private PlayerWrapper player; + private org.screamingsandals.lib.player.Player player; private List lines; private PlaceholderFunction papiFunction; private final HashMap persistentPlaceholders; @@ -72,7 +57,7 @@ public Scoreboard(final Player player) { if (ScoreboardManager.getPluginInstance() == null) { throw new NullPointerException("Plugin instance not set! call ScoreboardManager.install() first"); } - this.player = PlayerMapper.wrapPlayer(player); + this.player = Players.wrapPlayer(player); this.holder = new ConfigBoard(player.getName()); BoardPlayer.getBoardPlayer(player).attachConfigBoard(this.holder); this.holder.runTaskTimerAsynchronously(ScoreboardManager.getPluginInstance(), 1, 1); @@ -254,7 +239,7 @@ public void setOccupyMaxWidth(final boolean occupyMaxWidth) { this.occupyMaxWidth = occupyMaxWidth; } - public PlayerWrapper getPlayer() { + public org.screamingsandals.lib.player.Player getPlayer() { return player; } diff --git a/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/data/PlaceholderData.java b/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/data/PlaceholderData.java index e2426982..711f36d9 100644 --- a/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/data/PlaceholderData.java +++ b/plugin/src/main/java/io/github/pronze/lib/pronzelib/scoreboards/data/PlaceholderData.java @@ -5,22 +5,21 @@ package io.github.pronze.lib.pronzelib.scoreboards.data; import io.github.pronze.lib.pronzelib.scoreboards.Scoreboard; -import org.bukkit.entity.Player; -import org.screamingsandals.lib.player.PlayerWrapper; +import org.screamingsandals.lib.player.Player; public class PlaceholderData { - private final PlayerWrapper player; + private final Player player; private final Scoreboard holder; private final String line; - public PlaceholderData(final PlayerWrapper player, final Scoreboard holder, final String line) { + public PlaceholderData(final Player player, final Scoreboard holder, final String line) { this.player = player; this.holder = holder; this.line = line; } - public PlayerWrapper getPlayer() { + public Player getPlayer() { return this.player; } diff --git a/plugin/src/main/java/io/github/pronze/sba/SBA.java b/plugin/src/main/java/io/github/pronze/sba/SBA.java index 55a5cb8d..10f297ec 100644 --- a/plugin/src/main/java/io/github/pronze/sba/SBA.java +++ b/plugin/src/main/java/io/github/pronze/sba/SBA.java @@ -43,13 +43,11 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; -import io.github.pronze.sba.VersionInfo; import org.screamingsandals.bedwars.api.BedwarsAPI; import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.lib.bstats.bukkit.Metrics; @@ -59,20 +57,17 @@ import org.screamingsandals.lib.hologram.HologramManager; import org.screamingsandals.lib.npc.NPCManager; import org.screamingsandals.lib.packet.PacketMapper; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.plugin.PluginContainer; import org.screamingsandals.lib.sidebar.SidebarManager; -import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.utils.PlatformType; import org.screamingsandals.lib.utils.annotations.Init; import org.screamingsandals.lib.utils.annotations.Plugin; import org.screamingsandals.lib.utils.annotations.PluginDependencies; -import org.screamingsandals.lib.utils.reflect.Reflect; import org.screamingsandals.simpleinventories.SimpleInventoriesCore; import io.github.pronze.lib.pronzelib.scoreboards.ScoreboardManager; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -308,7 +303,7 @@ public Optional getGameStorage(Game game) { @Override public SBAPlayerWrapper getPlayerWrapper(Player player) { return PlayerWrapperService.getInstance().get(player) - .orElseGet(() -> PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class)); + .orElseGet(() -> Players.wrapPlayer(player).as(SBAPlayerWrapper.class)); } @Override @@ -323,7 +318,7 @@ public boolean isSnapshot() { @Override public String getVersion() { - return getPluginDescription().getVersion(); + return getPluginDescription().version(); } @Override diff --git a/plugin/src/main/java/io/github/pronze/sba/UpdateChecker.java b/plugin/src/main/java/io/github/pronze/sba/UpdateChecker.java index b7454159..0195ff73 100644 --- a/plugin/src/main/java/io/github/pronze/sba/UpdateChecker.java +++ b/plugin/src/main/java/io/github/pronze/sba/UpdateChecker.java @@ -6,11 +6,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.event.EventManager; -import org.screamingsandals.lib.event.player.SPlayerJoinEvent; import org.screamingsandals.lib.plugin.ServiceManager; -import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.utils.reflect.Reflect; @@ -27,7 +25,8 @@ import java.net.URL; import java.util.Scanner; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { SBAConfig.class }) public class UpdateChecker { diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/AICommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/AICommand.java index 7faefcc1..37b29d77 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/AICommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/AICommand.java @@ -1,55 +1,24 @@ package io.github.pronze.sba.commands; -import cloud.commandframework.annotations.Argument; import cloud.commandframework.annotations.CommandDescription; import cloud.commandframework.annotations.CommandMethod; import cloud.commandframework.annotations.CommandPermission; import io.github.pronze.sba.MessageKeys; -import io.github.pronze.sba.Permissions; import io.github.pronze.sba.SBA; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.service.AIService; -import io.github.pronze.sba.utils.Logger; import io.github.pronze.sba.utils.citizens.Strategy; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; -import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.event.DespawnReason; -import net.citizensnpcs.api.event.SpawnReason; -import net.citizensnpcs.api.npc.MemoryNPCDataStore; -import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.api.npc.NPCRegistry; -import net.citizensnpcs.trait.CurrentLocation; -import net.citizensnpcs.trait.Gravity; -import net.citizensnpcs.trait.SkinTrait; -import org.screamingsandals.lib.spectator.Component; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; -import org.screamingsandals.bedwars.api.events.BedwarsPlayerDeathMessageSendEvent; import org.screamingsandals.bedwars.api.game.GameStatus; -import org.screamingsandals.bedwars.game.TeamColor; -import org.screamingsandals.bedwars.utils.FakeDeath; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.tasker.Tasker; -import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import org.screamingsandals.lib.utils.annotations.methods.OnPreDisable; import io.github.pronze.sba.config.SBAConfig; -import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; @Service public class AICommand implements Listener { diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/CommandManager.java b/plugin/src/main/java/io/github/pronze/sba/commands/CommandManager.java index c11187c7..99cc787a 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/CommandManager.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/CommandManager.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnEnable; import io.github.pronze.sba.utils.Logger; @@ -32,7 +33,8 @@ import java.util.function.Function; -@Service(initAnother = { +@Service +@ServiceDependencies(initAnother = { SBACommand.class, GamesInvNPCCommand.class, ShoutCommand.class, diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/GamesInvNPCCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/GamesInvNPCCommand.java index 99f0c58c..859b3a6c 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/GamesInvNPCCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/GamesInvNPCCommand.java @@ -5,17 +5,14 @@ import cloud.commandframework.annotations.CommandPermission; import io.github.pronze.sba.MessageKeys; import io.github.pronze.sba.SBA; -import io.github.pronze.sba.game.GameMode; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.service.GamesInventoryService; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import org.screamingsandals.lib.world.LocationMapper; @Service public class GamesInvNPCCommand { @@ -52,7 +49,7 @@ private void commandSpawn(final @NotNull Player player, LanguageService .getInstance() .get(MessageKeys.ADDED_NPC) - .send(PlayerMapper.wrapPlayer(player)); + .send(Players.wrapPlayer(player)); } @CommandMethod("sba gamesinv removenpc") @@ -61,8 +58,8 @@ private void commandRemove(final @NotNull Player player) { LanguageService .getInstance() .get(MessageKeys.REMOVABLE_NPC_TOGGLE) - .send(PlayerMapper.wrapPlayer(player)); - GamesInventoryService.getInstance().addEditable(PlayerMapper.wrapPlayer(player), + .send(Players.wrapPlayer(player)); + GamesInventoryService.getInstance().addEditable(Players.wrapPlayer(player), GamesInventoryService.Action.Remove, null); } @@ -72,8 +69,8 @@ private void commandEdit(final @NotNull Player player, final @NotNull @Argument( LanguageService .getInstance() .get(MessageKeys.SKIN_NPC_TOGGLE) - .send(PlayerMapper.wrapPlayer(player)); - GamesInventoryService.getInstance().addEditable(PlayerMapper.wrapPlayer(player), + .send(Players.wrapPlayer(player)); + GamesInventoryService.getInstance().addEditable(Players.wrapPlayer(player), GamesInventoryService.Action.Skin, skin); } } \ No newline at end of file diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/SBACommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/SBACommand.java index 472ac2e9..906eb292 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/SBACommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/SBACommand.java @@ -11,6 +11,7 @@ import io.github.pronze.sba.service.GamesInventoryService; import io.github.pronze.sba.utils.Logger; import io.leangen.geantyref.TypeToken; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; import org.screamingsandals.lib.spectator.Color; import org.screamingsandals.bedwars.api.game.Game; @@ -25,20 +26,18 @@ import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.api.game.GameStore; import org.screamingsandals.lib.npc.NPC; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.Pair; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import org.screamingsandals.lib.world.LocationMapper; import org.spongepowered.configurate.serialize.SerializationException; import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.utils.SBAUtil; import io.github.pronze.sba.utils.ShopUtil; import io.github.pronze.sba.utils.Logger.Level; -import io.github.pronze.sba.visuals.LobbyScoreboardManager; import io.github.pronze.sba.visuals.MainLobbyVisualsManager; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; @@ -49,6 +48,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; @@ -131,15 +131,13 @@ private void commandTestNPC( final @NotNull Player sender) { var player = SBA.getInstance().getPlayerWrapper(sender); - NPC npc = NPC.of(LocationMapper.wrapLocation(sender.getLocation())) + NPC npc = NPC.of(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(sender.getLocation()))) .addViewer(player) .lookAtPlayer(true) .displayName(List.of( Component.text("Test NPC, will despawn after 10 seconds").withColor((Color.rgb(139, 69, 19))))) .show(); - Tasker.build(() -> { - npc.destroy(); - }).delay(10, TaskerTime.SECONDS).start(); + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, npc::destroy, 10, TaskerTime.SECONDS); } @CommandMethod("sba setlobby") @@ -161,7 +159,7 @@ private void commandSetLobby( LanguageService .getInstance() .get(MessageKeys.SUCCESSFULLY_SET_LOBBY) - .send(PlayerMapper.wrapPlayer(player)); + .send(Players.wrapPlayer(player)); MainLobbyVisualsManager.getInstance().reload(); @@ -180,14 +178,14 @@ private void commandReset( .get(MessageKeys.COMMAND_RESETTING) .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(component); + Players.wrapSender(sender).sendMessage(component); SBAConfig.getInstance().upgrade(); final var c2 = LanguageService .getInstance() .get(MessageKeys.RESET_COMMAND_SUCCESS) .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(c2); + Players.wrapSender(sender).sendMessage(c2); } @CommandMethod("sba generate [gamemode] [maps]") @@ -216,7 +214,7 @@ private void commandGenerate( .allMatch(t -> t.getMaxPlayers() == ShopUtil.getIntFromMode(gameMode))) .collect(Collectors.toList()); - PlayerMapper.wrapSender(sender).sendMessage(message); + Players.wrapSender(sender).sendMessage(message); } final var maps = mapsTmp != null ? mapsTmp : List.of(mapsArg); Logger.trace("Generating Games Inventory file for game mode: {}", gameMode); @@ -307,7 +305,7 @@ private void commandGenerate( .get(MessageKeys.GAMESINV_NO_MAPS_WITH_NAME) .replace("%name%", game.getSecond()) .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(message); + Players.wrapSender(sender).sendMessage(message); } }); } @@ -327,7 +325,7 @@ private void commandGenerate( .get(MessageKeys.GAMESINV_GENERATED) .replace("%gamemode%", gameMode) .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(generated); + Players.wrapSender(sender).sendMessage(generated); GamesInventoryService.getInstance().destroy(); GamesInventoryService.getInstance().loadGamesInv(); @@ -348,7 +346,7 @@ private void commandGamesInv( .getInstance() .get(MessageKeys.GAMES_INV_DISABLED) .toComponent(); - PlayerMapper.wrapPlayer(player).sendMessage(disabled); + Players.wrapPlayer(player).sendMessage(disabled); return; } GamesInventory @@ -366,13 +364,13 @@ private void commandJoinRandom( .getInstance() .get(MessageKeys.GAMES_INV_DISABLED) .toComponent(); - PlayerMapper.wrapPlayer(player).sendMessage(disabled); + Players.wrapPlayer(player).sendMessage(disabled); return; } var couldNotFindGameMessage = LanguageService .getInstance() .get(MessageKeys.GAMES_INVENTORY_CANNOT_FIND_GAME); - final var playerWrapper = PlayerMapper.wrapPlayer(player); + final var playerWrapper = Players.wrapPlayer(player); final var games = GamesInventory.getInstance().getGamesWithMode(gameMode); if (games == null || games.isEmpty()) { couldNotFindGameMessage.send(playerWrapper); @@ -425,9 +423,9 @@ private void commandUpgrade( final var cannotExecute = LanguageService .getInstance() .get(MessageKeys.COMMAND_CANNOT_EXECUTE) - .toString(); + .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(cannotExecute); + Players.wrapSender(sender).sendMessage(cannotExecute); return; } @@ -436,9 +434,9 @@ private void commandUpgrade( final var upgraded = LanguageService .getInstance() .get(MessageKeys.COMMAND_SUCCESSFULLY_UPGRADED) - .toString(); + .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(upgraded); + Players.wrapSender(sender).sendMessage(upgraded); } @CommandMethod("sba updateplugin") @@ -451,9 +449,9 @@ private void commandUpdatePlugin( final var cannotExecute = LanguageService .getInstance() .get(MessageKeys.COMMAND_CANNOT_EXECUTE) - .toString(); + .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(cannotExecute); + Players.wrapSender(sender).sendMessage(cannotExecute); return; } @@ -470,9 +468,9 @@ private void commandCancel( final var m1 = LanguageService .getInstance() .get(MessageKeys.CANNOT_DO_COMMAND) - .toString(); + .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(m1); + Players.wrapSender(sender).sendMessage(m1); return; } @@ -482,9 +480,9 @@ private void commandCancel( final var m2 = LanguageService .getInstance() .get(MessageKeys.COMMAND_CANCEL_UPGRADE) - .toString(); + .toComponent(); - PlayerMapper.wrapSender(sender).sendMessage(m2); + Players.wrapSender(sender).sendMessage(m2); } catch (SerializationException ex) { ex.printStackTrace(); } diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/ShoutCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/ShoutCommand.java index 36f1cfb4..1e16658c 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/ShoutCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/ShoutCommand.java @@ -13,7 +13,6 @@ import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.game.TeamColor; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.config.SBAConfig; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyAcceptCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyAcceptCommand.java index b741d8fa..0eb02f6b 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyAcceptCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyAcceptCommand.java @@ -10,7 +10,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyChatCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyChatCommand.java index 7765fd1b..442eb633 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyChatCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyChatCommand.java @@ -7,10 +7,8 @@ import io.github.pronze.sba.wrapper.PlayerSetting; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import io.github.pronze.sba.commands.CommandManager; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.lib.lang.LanguageService; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyCommand.java index 2ed654e0..8717d55c 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyCommand.java @@ -1,12 +1,14 @@ package io.github.pronze.sba.commands.party; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; import io.github.pronze.sba.commands.CommandManager; -@Service(initAnother = { +@Service +@ServiceDependencies(initAnother = { PartyAcceptCommand.class, PartyChatCommand.class, PartyDebugCommand.class, diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDebugCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDebugCommand.java index c568bdb0..74ab3c17 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDebugCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDebugCommand.java @@ -7,11 +7,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import io.github.pronze.sba.commands.CommandManager; import io.github.pronze.sba.config.SBAConfig; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDeclineCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDeclineCommand.java index cb42b537..9cb8d496 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDeclineCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDeclineCommand.java @@ -9,7 +9,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDisbandCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDisbandCommand.java index 4db38b93..0693c571 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDisbandCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyDisbandCommand.java @@ -8,7 +8,6 @@ import io.github.pronze.sba.wrapper.PlayerSetting; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyHelpCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyHelpCommand.java index 6d0650ea..0060ee2f 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyHelpCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyHelpCommand.java @@ -7,7 +7,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.commands.CommandManager; @@ -36,7 +36,7 @@ private void commandHelp( LanguageService .getInstance() .get(MessageKeys.PARTY_MESSAGE_HELP) - .send(PlayerMapper.wrapPlayer(sender)); + .send(Players.wrapPlayer(sender)); } } diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyInviteCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyInviteCommand.java index bcc359f5..952e8152 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyInviteCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyInviteCommand.java @@ -10,12 +10,10 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; import io.github.pronze.sba.events.SBAPlayerPartyInviteEvent; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import io.github.pronze.sba.commands.CommandManager; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.lib.lang.LanguageService; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyJoinCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyJoinCommand.java index f32a88c9..10bf1d71 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyJoinCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyJoinCommand.java @@ -12,7 +12,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyKickCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyKickCommand.java index 09d8d0b9..d0bf329d 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyKickCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyKickCommand.java @@ -10,7 +10,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyLeaveCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyLeaveCommand.java index 654292ec..369538d4 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyLeaveCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyLeaveCommand.java @@ -8,7 +8,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyListCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyListCommand.java index d9c33d90..babb9ffc 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyListCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyListCommand.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.commands.CommandManager; @@ -66,7 +66,7 @@ private void commandList( .replace("%count%", String.valueOf(party.getMembers().size())) .replace("%leader%", (leader)) .replace("%members%", (membersComponent)) - .send(PlayerMapper.wrapPlayer(sender)); + .send(Players.wrapPlayer(sender)); }); } diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyPromoteCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyPromoteCommand.java index 97757959..1d4ad9a6 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyPromoteCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyPromoteCommand.java @@ -10,7 +10,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartySettingsCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartySettingsCommand.java index bbc95228..a96a4da1 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartySettingsCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartySettingsCommand.java @@ -12,7 +12,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyWarpCommand.java b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyWarpCommand.java index 7f44f984..d2379d24 100644 --- a/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyWarpCommand.java +++ b/plugin/src/main/java/io/github/pronze/sba/commands/party/PartyWarpCommand.java @@ -10,11 +10,10 @@ import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.lib.nms.entity.PlayerUtils; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import io.github.pronze.sba.commands.CommandManager; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.lib.lang.LanguageService; @@ -107,7 +106,7 @@ private void commandWarp( LanguageService .getInstance() .get(MessageKeys.PARTY_MESSAGE_LEADER_JOIN_LEAVE) - .send(PlayerMapper.wrapPlayer(member.getInstance())); + .send(Players.wrapPlayer(member.getInstance())); }); } }, () -> LanguageService diff --git a/plugin/src/main/java/io/github/pronze/sba/config/CompassConfig.java b/plugin/src/main/java/io/github/pronze/sba/config/CompassConfig.java index 4e7b05da..6be0ef98 100644 --- a/plugin/src/main/java/io/github/pronze/sba/config/CompassConfig.java +++ b/plugin/src/main/java/io/github/pronze/sba/config/CompassConfig.java @@ -1,27 +1,27 @@ package io.github.pronze.sba.config; -import io.github.pronze.sba.config.ConfigGenerator.ConfigSection; -import io.github.pronze.sba.utils.FirstStartConfigReplacer; -import io.github.pronze.sba.utils.Logger; -import net.md_5.bungee.api.ChatColor; - -import org.bukkit.Material; -import org.bukkit.plugin.java.JavaPlugin; -import org.screamingsandals.bedwars.Main; -import org.screamingsandals.lib.item.Item; -import org.screamingsandals.lib.item.builder.ItemFactory; -import org.screamingsandals.lib.plugin.ServiceManager; -import org.screamingsandals.lib.utils.annotations.Service; -import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import org.spongepowered.configurate.ConfigurateException; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.serialize.SerializationException; -import org.spongepowered.configurate.yaml.NodeStyle; -import org.spongepowered.configurate.yaml.YamlConfigurationLoader; -import io.github.pronze.sba.utils.SBAUtil; -import java.io.File; -import java.util.*; -import java.util.List; +//import io.github.pronze.sba.config.ConfigGenerator.ConfigSection; +//import io.github.pronze.sba.utils.FirstStartConfigReplacer; +//import io.github.pronze.sba.utils.Logger; +//import net.md_5.bungee.api.ChatColor; +// +//import org.bukkit.Material; +//import org.bukkit.plugin.java.JavaPlugin; +//import org.screamingsandals.bedwars.Main; +//import org.screamingsandals.lib.item.Item; +//import org.screamingsandals.lib.item.builder.ItemFactory; +//import org.screamingsandals.lib.plugin.ServiceManager; +//import org.screamingsandals.lib.utils.annotations.Service; +//import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; +//import org.spongepowered.configurate.ConfigurateException; +//import org.spongepowered.configurate.ConfigurationNode; +//import org.spongepowered.configurate.serialize.SerializationException; +//import org.spongepowered.configurate.yaml.NodeStyle; +//import org.spongepowered.configurate.yaml.YamlConfigurationLoader; +//import io.github.pronze.sba.utils.SBAUtil; +//import java.io.File; +//import java.util.*; +//import java.util.List; /* @Service public class CompassConfig implements IConfigurator { diff --git a/plugin/src/main/java/io/github/pronze/sba/config/SBAConfig.java b/plugin/src/main/java/io/github/pronze/sba/config/SBAConfig.java index ee9dfe43..7efda192 100644 --- a/plugin/src/main/java/io/github/pronze/sba/config/SBAConfig.java +++ b/plugin/src/main/java/io/github/pronze/sba/config/SBAConfig.java @@ -15,8 +15,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; -import org.screamingsandals.lib.item.Item; -import org.screamingsandals.lib.item.builder.ItemFactory; +import org.screamingsandals.lib.item.builder.ItemStackFactory; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; @@ -840,13 +839,13 @@ public String getString(String path, String def) { return str; } - public Item readDefinedItem(ConfigurationNode node, String def) { + public org.screamingsandals.lib.item.ItemStack readDefinedItem(ConfigurationNode node, String def) { if (!node.empty()) { var obj = node.raw(); - return ItemFactory.build(obj).orElse(ItemFactory.getAir()); + return Objects.requireNonNullElse(ItemStackFactory.build(obj), ItemStackFactory.getAir()); } - return ItemFactory.build(def).orElse(ItemFactory.getAir()); + return Objects.requireNonNullElse(ItemStackFactory.build(def), ItemStackFactory.getAir()); } } diff --git a/plugin/src/main/java/io/github/pronze/sba/fix/CitizensFix.java b/plugin/src/main/java/io/github/pronze/sba/fix/CitizensFix.java index 4f139f10..7a091dc5 100644 --- a/plugin/src/main/java/io/github/pronze/sba/fix/CitizensFix.java +++ b/plugin/src/main/java/io/github/pronze/sba/fix/CitizensFix.java @@ -1,9 +1,6 @@ package io.github.pronze.sba.fix; import org.bukkit.Bukkit; -import org.screamingsandals.bedwars.Main; -import org.screamingsandals.lib.bukkit.utils.nms.Version; -import org.screamingsandals.lib.utils.reflect.Reflect; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.utils.Logger; diff --git a/plugin/src/main/java/io/github/pronze/sba/fix/ViaVersionFix.java b/plugin/src/main/java/io/github/pronze/sba/fix/ViaVersionFix.java index 15e14f91..4c1d50c2 100644 --- a/plugin/src/main/java/io/github/pronze/sba/fix/ViaVersionFix.java +++ b/plugin/src/main/java/io/github/pronze/sba/fix/ViaVersionFix.java @@ -1,9 +1,6 @@ package io.github.pronze.sba.fix; import org.bukkit.Bukkit; -import org.screamingsandals.bedwars.Main; -import org.screamingsandals.lib.bukkit.utils.nms.Version; -import org.screamingsandals.lib.utils.reflect.Reflect; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.utils.Logger; diff --git a/plugin/src/main/java/io/github/pronze/sba/game/Arena.java b/plugin/src/main/java/io/github/pronze/sba/game/Arena.java index 3e472925..8c6f7b13 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/Arena.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/Arena.java @@ -14,11 +14,10 @@ import io.github.pronze.sba.utils.citizens.HologramTrait; import io.github.pronze.sba.utils.citizens.ReturnToStoreTrait; import io.github.pronze.sba.visuals.GameScoreboardManager; -import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.npc.MemoryNPCDataStore; import net.citizensnpcs.trait.Gravity; import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.SkinTrait; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; import org.apache.commons.lang.StringUtils; @@ -30,8 +29,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.StringUtil; -import org.checkerframework.checker.index.qual.GTENegativeOne; import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.RunningTeam; @@ -43,12 +40,11 @@ import org.screamingsandals.bedwars.game.GameStore; import org.screamingsandals.bedwars.game.ItemSpawner; import org.screamingsandals.lib.npc.NPC; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.player.PlayerWrapper; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.utils.reflect.Reflect; -import org.screamingsandals.lib.world.LocationMapper; import org.screamingsandals.lib.npc.skin.NPCSkin; +import org.screamingsandals.lib.world.Location; import java.util.*; import java.util.stream.Collectors; @@ -105,9 +101,7 @@ public void addHiddenPlayer(@NotNull Player player) { final var invisiblePlayer = new InvisiblePlayerImpl(player, this); invisiblePlayers.put(player.getUniqueId(), invisiblePlayer); - Tasker.build(() -> { - invisiblePlayer.vanish(); - }).afterOneTick().start(); + Tasker.run(DefaultThreads.GLOBAL_THREAD, invisiblePlayer::vanish); } @@ -173,7 +167,7 @@ public void onGameStarted() { LanguageService .getInstance() .get(MessageKeys.GAME_START_MESSAGE) - .send(game.getConnectedPlayers().stream().map(PlayerMapper::wrapPlayer).toArray(PlayerWrapper[]::new)); + .send(game.getConnectedPlayers().stream().map(Players::wrapPlayer).toArray(org.screamingsandals.lib.player.Player[]::new)); // spawn rotating generators if (SBAConfig.getInstance().node("floating-generator", "enabled").getBoolean()) { @@ -240,7 +234,7 @@ public void onGameStarted() { t.printStackTrace(); } - final var npc = NPC.of(LocationMapper.wrapLocation(store.getStoreLocation())) + final var npc = NPC.of(Objects.requireNonNull(Location.fromPlatform(store.getStoreLocation()))) .displayName(name) .lookAtPlayer(true) .skin(skin) @@ -250,7 +244,7 @@ public void onGameStarted() { game.getConnectedPlayers() .stream() - .map(PlayerMapper::wrapPlayer) + .map(Players::wrapPlayer) .forEach(npc::addViewer); npc.show(); }); @@ -353,7 +347,7 @@ public void onTargetBlockDestroyed(BedwarsTargetBlockDestroyedEvent e) { .toComponent(); team.getConnectedPlayers() - .forEach(player -> SBAUtil.sendTitle(PlayerMapper.wrapPlayer(player), title, subtitle, 0, 40, 20)); + .forEach(player -> SBAUtil.sendTitle(Players.wrapPlayer(player), title, subtitle, 0, 40, 20)); final var destroyer = e.getPlayer(); if (destroyer != null) { @@ -389,7 +383,7 @@ public void removeVisualsForPlayer(Player player) { if (((RotatingGenerator) gen).getStack().getType() != Material.AIR) gen.removeViewer(player); }); - stores.values().forEach(npc -> npc.removeViewer(PlayerMapper.wrapPlayer(player))); + stores.values().forEach(npc -> npc.removeViewer(Players.wrapPlayer(player))); } public void addVisualsForPlayer(Player player) { @@ -397,7 +391,7 @@ public void addVisualsForPlayer(Player player) { if (((RotatingGenerator) gen).getStack().getType() != Material.AIR) gen.addViewer(player); }); - stores.values().forEach(npc -> npc.addViewer(PlayerMapper.wrapPlayer(player))); + stores.values().forEach(npc -> npc.addViewer(Players.wrapPlayer(player))); } public void removePlayerFromGame(Player player) { @@ -483,7 +477,7 @@ public void onOver(BedwarsGameEndingEvent e) { winner.getConnectedPlayers() .forEach(player -> WinTeamPlayers.add(player.getDisplayName() + ChatColor.RESET)); winner.getConnectedPlayers() - .forEach(pl -> SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), victoryTitle, + .forEach(pl -> SBAUtil.sendTitle(Players.wrapPlayer(pl), victoryTitle, org.screamingsandals.lib.spectator.Component.empty(), 0, 90, 0)); LanguageService @@ -504,8 +498,8 @@ public void onOver(BedwarsGameEndingEvent e) { .replace("%second_killer_score%", String.valueOf(secondKillerScore)) .replace("%third_killer_score%", String.valueOf(thirdKillerScore)) - .send(game.getConnectedPlayers().stream().map(PlayerMapper::wrapPlayer) - .toArray(PlayerWrapper[]::new)); + .send(game.getConnectedPlayers().stream().map(Players::wrapPlayer) + .toArray(org.screamingsandals.lib.player.Player[]::new)); } } diff --git a/plugin/src/main/java/io/github/pronze/sba/game/InvisiblePlayerImpl.java b/plugin/src/main/java/io/github/pronze/sba/game/InvisiblePlayerImpl.java index 1eb1ea69..c911f1e8 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/InvisiblePlayerImpl.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/InvisiblePlayerImpl.java @@ -17,14 +17,16 @@ import org.bukkit.scoreboard.Team.OptionStatus; import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.game.TeamColor; -import org.screamingsandals.lib.item.Item; -import org.screamingsandals.lib.item.builder.ItemFactory; -import org.screamingsandals.lib.slot.EquipmentSlotHolder; -import org.screamingsandals.lib.slot.EquipmentSlotMapping; +import org.screamingsandals.lib.item.builder.ItemStackFactory; +import org.screamingsandals.lib.packet.ClientboundSetEquipmentPacket; +import org.screamingsandals.lib.player.Players; +import org.screamingsandals.lib.slot.EquipmentSlot; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; -import org.screamingsandals.lib.packet.SClientboundSetEquipmentPacket; -import org.screamingsandals.lib.packet.SClientboundSetPlayerTeamPacket.TagVisibility; -import org.screamingsandals.lib.player.PlayerMapper; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; @Data public class InvisiblePlayerImpl implements InvisiblePlayer { @@ -111,16 +113,16 @@ private void showArmor() { convert(helmet), convert(chestplate), convert(leggings), - convert(boots), convert(currentHand)).sendPacket(PlayerMapper.wrapPlayer(pl))); + convert(boots), convert(currentHand)).sendPacket(Players.wrapPlayer(pl))); } - public Item convert(ItemStack itemStack) { - return ItemFactory.build(itemStack).orElse(ItemFactory.getAir()); + public org.screamingsandals.lib.item.ItemStack convert(ItemStack itemStack) { + return Objects.requireNonNullElse(ItemStackFactory.build(itemStack), ItemStackFactory.getAir()); } private void hideArmor() { var hiddenPlayerTeam = arena.getGame().getTeamOfPlayer(hiddenPlayer); - final var airStack = ItemFactory.getAir(); + final var airStack = ItemStackFactory.getAir(); arena.getGame() .getConnectedPlayers() .stream() @@ -128,15 +130,15 @@ private void hideArmor() { .forEach(pl -> { getEquipPacket(airStack, airStack, airStack, airStack, convert(hiddenPlayer.getInventory().getItemInMainHand())) - .sendPacket(PlayerMapper.wrapPlayer(pl)); + .sendPacket(Players.wrapPlayer(pl)); }); } public void refresh() { // TODO Auto-generated method stub - final var airStack = ItemFactory.getAir(); + final var airStack = ItemStackFactory.getAir(); var hiddenPlayerTeam = arena.getGame().getTeamOfPlayer(hiddenPlayer); - Tasker.build(() -> { + Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> { arena.getGame() .getConnectedPlayers() .stream() @@ -144,28 +146,30 @@ public void refresh() { .forEach(pl -> { getEquipPacket(airStack, airStack, airStack, airStack, convert(hiddenPlayer.getInventory().getItemInMainHand())) - .sendPacket(PlayerMapper.wrapPlayer(pl)); + .sendPacket(Players.wrapPlayer(pl)); }); - }).afterOneTick().start(); + }); } - private SClientboundSetEquipmentPacket getEquipPacket(Item helmet, Item chestPlate, Item leggings, Item boots, - Item hand) { - final var packet = new SClientboundSetEquipmentPacket(); + private ClientboundSetEquipmentPacket getEquipPacket(org.screamingsandals.lib.item.ItemStack helmet, org.screamingsandals.lib.item.ItemStack chestPlate, + org.screamingsandals.lib.item.ItemStack leggings, org.screamingsandals.lib.item.ItemStack boots, + org.screamingsandals.lib.item.ItemStack hand) { + final var packet = ClientboundSetEquipmentPacket.builder(); packet.entityId(hiddenPlayer.getEntityId()); - final var slots = packet.slots(); + final var slots = new HashMap(); if (hand != null) - slots.put(EquipmentSlotMapping.resolve("HAND").orElseThrow(), hand); + slots.put(EquipmentSlot.of("HAND"), hand); if (helmet != null) - slots.put(EquipmentSlotMapping.resolve("HEAD").orElseThrow(), helmet); + slots.put(EquipmentSlot.of("HEAD"), helmet); if (chestPlate != null) - slots.put(EquipmentSlotMapping.resolve("CHEST").orElseThrow(), chestPlate); + slots.put(EquipmentSlot.of("CHEST"), chestPlate); if (leggings != null) - slots.put(EquipmentSlotMapping.resolve("LEGS").orElseThrow(), leggings); + slots.put(EquipmentSlot.of("LEGS"), leggings); if (boots != null) - slots.put(EquipmentSlotMapping.resolve("FEET").orElseThrow(), boots); - return packet; + slots.put(EquipmentSlot.of("FEET"), boots); + packet.slots(slots); + return packet.build(); } @Override diff --git a/plugin/src/main/java/io/github/pronze/sba/game/RotatingGenerator.java b/plugin/src/main/java/io/github/pronze/sba/game/RotatingGenerator.java index eff5397e..68daa382 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/RotatingGenerator.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/RotatingGenerator.java @@ -3,6 +3,8 @@ import io.github.pronze.sba.utils.ShopUtil; import lombok.Getter; import lombok.Setter; +import org.screamingsandals.lib.item.builder.ItemStackFactory; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; import org.bukkit.Location; import org.bukkit.Material; @@ -20,14 +22,12 @@ import io.github.pronze.sba.utils.SBAUtil; import org.screamingsandals.lib.hologram.Hologram; import org.screamingsandals.lib.hologram.HologramManager; -import org.screamingsandals.lib.item.builder.ItemFactory; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.Pair; -import org.screamingsandals.lib.world.LocationMapper; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class RotatingGenerator implements IRotatingGenerator { private Location location; @@ -62,26 +62,26 @@ public void spawn(@NotNull List viewers) { final var holoHeight = SBAConfig.getInstance() .node("floating-generator", "height").getDouble(2.0); - hologram = HologramManager.hologram(LocationMapper.wrapLocation(location.clone().add(0, holoHeight, 0))); - hologram.item(ItemFactory.build(stack).orElseThrow()) + hologram = HologramManager.hologram(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(location.clone().add(0, holoHeight, 0)))); + hologram.item(ItemStackFactory.build(stack)) .itemPosition(Hologram.ItemPosition.BELOW) .rotationMode(Hologram.RotationMode.Y) .rotationTime(Pair.of(1, TaskerTime.TICKS)); hologram.show(); - viewers.forEach(player -> hologram.addViewer(PlayerMapper.wrapPlayer(player))); + viewers.forEach(player -> hologram.addViewer(Players.wrapPlayer(player))); scheduleTasks(); } @Override public void addViewer(@NotNull Player player) { if (hologram != null) - hologram.addViewer(PlayerMapper.wrapPlayer(player)); + hologram.addViewer(Players.wrapPlayer(player)); } @Override public void removeViewer(@NotNull Player player) { - hologram.removeViewer(PlayerMapper.wrapPlayer(player)); + hologram.removeViewer(Players.wrapPlayer(player)); } protected void scheduleTasks() { diff --git a/plugin/src/main/java/io/github/pronze/sba/game/tasks/CustomTrapTask.java b/plugin/src/main/java/io/github/pronze/sba/game/tasks/CustomTrapTask.java index f0b5b979..edec2bea 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/tasks/CustomTrapTask.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/tasks/CustomTrapTask.java @@ -4,8 +4,6 @@ import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.events.SBATeamTrapTriggeredEvent; -import io.github.pronze.sba.game.Arena; -import io.github.pronze.sba.game.IArena; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.utils.SBAUtil; import io.github.pronze.sba.wrapper.SBAPlayerWrapper; @@ -13,12 +11,9 @@ import java.util.HashMap; import java.util.Map; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.utils.Sounds; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; public class CustomTrapTask extends BaseGameTask { private final double radius; @@ -72,7 +67,7 @@ public void run() { .get(MessageKeys.TEAM_CUSTOM_TRAP_TRIGGERED_MESSAGE) .replace("%trap%",trap) .replace("%team%", arena.getGame().getTeamOfPlayer(player).getName()) - .send(PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class)); + .send(Players.wrapPlayer(player).as(SBAPlayerWrapper.class)); var title = LanguageService .getInstance() @@ -94,7 +89,7 @@ public void run() { Sounds.playSound(pl, pl.getLocation(), sound, Sounds.ENTITY_ENDERMAN_TELEPORT, 1, 1); - SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), title, subTitle, 20, 60, 0); + SBAUtil.sendTitle(Players.wrapPlayer(pl), title, subTitle, 20, 60, 0); }); } }); diff --git a/plugin/src/main/java/io/github/pronze/sba/game/tasks/GameTaskManager.java b/plugin/src/main/java/io/github/pronze/sba/game/tasks/GameTaskManager.java index 62e262cb..335ff101 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/tasks/GameTaskManager.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/tasks/GameTaskManager.java @@ -6,12 +6,15 @@ import org.jetbrains.annotations.NotNull; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -@Service(dependsOn = SBAConfig.class) +@Service +@ServiceDependencies(dependsOn = SBAConfig.class) public class GameTaskManager implements IGameTaskManager { public static GameTaskManager getInstance() { diff --git a/plugin/src/main/java/io/github/pronze/sba/game/tasks/GeneratorTask.java b/plugin/src/main/java/io/github/pronze/sba/game/tasks/GeneratorTask.java index 1271a9b0..fd46e10b 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/tasks/GeneratorTask.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/tasks/GeneratorTask.java @@ -10,9 +10,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.screamingsandals.bedwars.api.game.Game; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.player.Players; import java.util.regex.Pattern; @@ -93,8 +91,8 @@ public void run() { .send(game .getConnectedPlayers() .stream() - .map(PlayerMapper::wrapPlayer) - .toArray(org.screamingsandals.lib.player.PlayerWrapper[]::new)); + .map(Players::wrapPlayer) + .toArray(org.screamingsandals.lib.player.Player[]::new)); } } } catch (NameNotFoundException e) { diff --git a/plugin/src/main/java/io/github/pronze/sba/game/tasks/MinerTrapTask.java b/plugin/src/main/java/io/github/pronze/sba/game/tasks/MinerTrapTask.java index 4d027a93..70a846a3 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/tasks/MinerTrapTask.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/tasks/MinerTrapTask.java @@ -4,17 +4,14 @@ import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.events.SBATeamTrapTriggeredEvent; -import io.github.pronze.sba.game.Arena; -import io.github.pronze.sba.game.IArena; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.utils.SBAUtil; import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.utils.Sounds; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; public class MinerTrapTask extends BaseGameTask { private final double radius; @@ -58,7 +55,7 @@ public void run() { .getInstance() .get(MessageKeys.TEAM_MINER_TRAP_TRIGGERED_MESSAGE) .replace("%team%", team.getName()) - .send(PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class)); + .send(Players.wrapPlayer(player).as(SBAPlayerWrapper.class)); var title = LanguageService .getInstance() @@ -78,7 +75,7 @@ public void run() { Sounds.playSound(pl, pl.getLocation(), sound, Sounds.ENTITY_ENDERMAN_TELEPORT, 1, 1); - SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), title, subTitle, 20, 60, 0); + SBAUtil.sendTitle(Players.wrapPlayer(pl), title, subTitle, 20, 60, 0); }); } })); diff --git a/plugin/src/main/java/io/github/pronze/sba/game/tasks/TrapTask.java b/plugin/src/main/java/io/github/pronze/sba/game/tasks/TrapTask.java index e07276ed..c46c538c 100644 --- a/plugin/src/main/java/io/github/pronze/sba/game/tasks/TrapTask.java +++ b/plugin/src/main/java/io/github/pronze/sba/game/tasks/TrapTask.java @@ -4,17 +4,14 @@ import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.events.SBATeamTrapTriggeredEvent; -import io.github.pronze.sba.game.Arena; -import io.github.pronze.sba.game.IArena; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.utils.SBAUtil; import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.utils.Sounds; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; public class TrapTask extends BaseGameTask { private final double radius; @@ -58,7 +55,7 @@ public void run() { .getInstance() .get(MessageKeys.TEAM_BLIND_TRAP_TRIGGERED_MESSAGE) .replace("%team%", team.getName()) - .send(PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class)); + .send(Players.wrapPlayer(player).as(SBAPlayerWrapper.class)); var title = LanguageService .getInstance() @@ -78,7 +75,7 @@ public void run() { Sounds.playSound(pl, pl.getLocation(), sound, Sounds.ENTITY_ENDERMAN_TELEPORT, 1, 1); - SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), title, subTitle, 20, 60, 0); + SBAUtil.sendTitle(Players.wrapPlayer(pl), title, subTitle, 20, 60, 0); }); } })); diff --git a/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java b/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java index 7a47a63e..c346b2ac 100644 --- a/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java +++ b/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java @@ -24,16 +24,10 @@ import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.events.BedwarsApplyPropertyToBoughtItem; import org.screamingsandals.bedwars.api.events.BedwarsApplyPropertyToDisplayedItem; -import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.api.game.ItemSpawnerType; -import org.screamingsandals.bedwars.api.upgrades.Upgrade; -import org.screamingsandals.bedwars.api.upgrades.UpgradeRegistry; -import org.screamingsandals.bedwars.api.upgrades.UpgradeStorage; import org.screamingsandals.bedwars.game.GameStore; import org.screamingsandals.bedwars.utils.Sounds; -import org.screamingsandals.lib.item.Item; -import org.screamingsandals.lib.item.builder.ItemFactory; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.item.builder.ItemStackFactory; import org.screamingsandals.lib.utils.ConfigurateUtils; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.simpleinventories.builder.InventorySetBuilder; @@ -48,12 +42,8 @@ import org.screamingsandals.simpleinventories.inventory.SubInventory; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; @@ -288,9 +278,7 @@ public void handlePrePurchase(OnTradeEvent event) { } } - var materialItem = ItemFactory - .build(type.getStack(priceAmount)) - .orElseThrow(); + var materialItem = Objects.requireNonNull(ItemStackFactory.build(type.getStack(priceAmount))); // purchase failed, player does not have enough resources to purchase if (!event.hasPlayerInInventory(materialItem)) { @@ -325,7 +313,7 @@ public void handlePrePurchase(OnTradeEvent event) { } AtomicReference newItemRef = new AtomicReference(newItem); - AtomicReference newMaterialItemRef = new AtomicReference(materialItem); + AtomicReference newMaterialItemRef = new AtomicReference<>(materialItem); AtomicReference messageOnFail = new AtomicReference<>(MessageKeys.CANNOT_BUY); final var result = handlePurchase(player, newItemRef, newMaterialItemRef, itemInfo, type,messageOnFail); @@ -360,7 +348,7 @@ public void handlePrePurchase(OnTradeEvent event) { LanguageService .getInstance() .get(MessageKeys.SHOP_PURCHASE_SUCCESS) - .replace("%item%", ShopUtil.getNameOrCustomNameOfItem(ItemFactory.build(newItem).orElseThrow())) + .replace("%item%", ShopUtil.getNameOrCustomNameOfItem(Objects.requireNonNull(ItemStackFactory.build(newItem)))) .replace("%material%", type.getItemName()) .send(event.getPlayer()); } @@ -517,7 +505,7 @@ private void onGeneratingItem(ItemRenderEvent event) { player, event.getStack().as(ItemStack.class), propertyData); Bukkit.getServer().getPluginManager().callEvent(applyEvent); - event.setStack(ItemFactory.build(applyEvent.getStack()).orElse(event.getStack())); + event.setStack(Objects.requireNonNullElse(ItemStackFactory.build(applyEvent.getStack()), event.getStack())); } }); @@ -532,7 +520,7 @@ private void onGeneratingItem(ItemRenderEvent event) { public abstract void onPreGenerateItem(ItemRenderEvent event); public abstract Map.Entry handlePurchase(Player player, AtomicReference newItem, - AtomicReference materialItem, PlayerItemInfo itemInfo, ItemSpawnerType type, AtomicReference messageOnFail); + AtomicReference materialItem, PlayerItemInfo itemInfo, ItemSpawnerType type, AtomicReference messageOnFail); @NotNull public abstract InventorySetBuilder getInventorySetBuilder(); diff --git a/plugin/src/main/java/io/github/pronze/sba/inventories/GamesInventory.java b/plugin/src/main/java/io/github/pronze/sba/inventories/GamesInventory.java index f2f3a771..acac4d01 100644 --- a/plugin/src/main/java/io/github/pronze/sba/inventories/GamesInventory.java +++ b/plugin/src/main/java/io/github/pronze/sba/inventories/GamesInventory.java @@ -7,9 +7,10 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.simpleinventories.SimpleInventoriesCore; import org.screamingsandals.simpleinventories.events.PostClickEvent; @@ -27,15 +28,14 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Random; import java.util.stream.Collectors; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { SBAConfig.class, SimpleInventoriesCore.class }) @@ -115,7 +115,7 @@ public void openForPlayer(Player player, int mode) { } final var format = inventoryMap.get(labels.get(mode)); if (format != null) { - PlayerMapper.wrapPlayer(player).openInventory(format); + Players.wrapPlayer(player).openInventory(format); } } @@ -127,7 +127,7 @@ public void openForPlayer(Player player, String mode) { } final var format = inventoryMap.get(mode); if (format != null) { - PlayerMapper.wrapPlayer(player).openInventory(format); + Players.wrapPlayer(player).openInventory(format); } } @@ -190,7 +190,7 @@ public void onClick(PostClickEvent event) { var couldNotFindGameMessage = LanguageService .getInstance() .get(MessageKeys.GAMES_INVENTORY_CANNOT_FIND_GAME); - final var playerWrapper = PlayerMapper.wrapPlayer(player); + final var playerWrapper = Players.wrapPlayer(player); player.closeInventory(); properties.stream() diff --git a/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java b/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java index 980d0f9c..eeb21ee7 100644 --- a/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java +++ b/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java @@ -14,7 +14,6 @@ import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import lombok.SneakyThrows; -import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -29,13 +28,13 @@ import org.screamingsandals.bedwars.api.game.ItemSpawner; import org.screamingsandals.bedwars.api.game.ItemSpawnerType; import org.screamingsandals.bedwars.game.GameStore; -import org.screamingsandals.lib.item.Item; -import org.screamingsandals.lib.item.builder.ItemFactory; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.item.builder.ItemStackFactory; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.ConfigurateUtils; import org.screamingsandals.lib.utils.Controllable; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.simpleinventories.SimpleInventoriesCore; import org.screamingsandals.simpleinventories.builder.InventorySetBuilder; import org.screamingsandals.simpleinventories.events.ItemRenderEvent; @@ -55,7 +54,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { SimpleInventoriesCore.class, SBAConfig.class }) @@ -134,7 +134,7 @@ public void onPreGenerateItem(ItemRenderEvent event) { } public Map.Entry handlePurchase(Player player, AtomicReference newItem, - AtomicReference materialItem, PlayerItemInfo itemInfo, ItemSpawnerType type, AtomicReference messageOnFail) { + AtomicReference materialItem, PlayerItemInfo itemInfo, ItemSpawnerType type, AtomicReference messageOnFail) { boolean shouldSellStack = true; final var game = Main.getInstance().getGameOfPlayer(player); final var gameStorage = ArenaManager @@ -143,7 +143,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .orElseThrow() .getStorage(); final var team = game.getTeamOfPlayer(player); - final var wrappedPlayer = PlayerMapper.wrapPlayer(player); + final var wrappedPlayer = Players.wrapPlayer(player); if (itemInfo.getProperties().size() == 0) { final var typeName = newItem.get().getType().name(); @@ -234,12 +234,12 @@ public Map.Entry handlePurchase(Player player, AtomicReference gameStorage.setPurchasedTrap(team, true, trap_identifier); if (SBAConfig.getInstance().trapTitleEnabled()) - team.getConnectedPlayers().forEach(pl -> SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), + team.getConnectedPlayers().forEach(pl -> SBAUtil.sendTitle(Players.wrapPlayer(pl), blindnessTrapTitle, org.screamingsandals.lib.spectator.Component.empty(), 20, 40, 20)); if (SBAConfig.getInstance().trapMessageEnabled()) team.getConnectedPlayers() - .forEach(pl -> PlayerMapper.wrapPlayer(pl).sendMessage(blindnessTrapTitle)); + .forEach(pl -> Players.wrapPlayer(pl).sendMessage(blindnessTrapTitle)); } break; case "sharpness": @@ -249,7 +249,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UGPRADE_TEAM_SHARPNESS) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -273,7 +273,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference var ePrice = sharpnessPrices.get(teamSharpnessLevel); teamSharpnessLevel = teamSharpnessLevel + 1; - materialItem.set(ItemFactory.build(type.getStack(ePrice)).get());// . (ItemFactory. ( + materialItem.set(ItemStackFactory.build(type.getStack(ePrice)));// . (ItemFactory. ( // type.getStack(ePrice))); if (player.getInventory().containsAtLeast(materialItem.get().as(ItemStack.class), @@ -285,7 +285,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UGPRADE_TEAM_SHARPNESS) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -304,7 +304,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_KNOCKBACK) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -326,7 +326,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference var ePrice = knockbackPrices.get(teamKnockbackLevel); teamKnockbackLevel = teamKnockbackLevel + 1; - materialItem.set(ItemFactory.build(type.getStack(ePrice)).get());// . (ItemFactory. ( + materialItem.set(ItemStackFactory.build(type.getStack(ePrice)));// . (ItemFactory. ( // type.getStack(ePrice))); if (player.getInventory().containsAtLeast(materialItem.get().as(ItemStack.class), @@ -338,7 +338,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_KNOCKBACK) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -358,7 +358,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_EFFICIENCY) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Logger.trace("efficiency level add"); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -380,7 +380,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference } else { var ePrice = efficiencyPrices.get(efficiencyLevel); efficiencyLevel = efficiencyLevel + 1; - materialItem.set(ItemFactory.build(type.getStack(ePrice)).get());// . (ItemFactory. ( + materialItem.set(ItemStackFactory.build(type.getStack(ePrice)));// . (ItemFactory. ( // type.getStack(ePrice))); if (player.getInventory().containsAtLeast(materialItem.get().as(ItemStack.class), @@ -392,7 +392,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_EFFICIENCY) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -417,12 +417,12 @@ public Map.Entry handlePurchase(Player player, AtomicReference gameStorage.setPurchasedBlindTrap(team, true); if (SBAConfig.getInstance().trapTitleEnabled()) - team.getConnectedPlayers().forEach(pl -> SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), + team.getConnectedPlayers().forEach(pl -> SBAUtil.sendTitle(Players.wrapPlayer(pl), blindnessTrapTitle, org.screamingsandals.lib.spectator.Component.empty(), 20, 40, 20)); if (SBAConfig.getInstance().trapMessageEnabled()) team.getConnectedPlayers() - .forEach(pl -> PlayerMapper.wrapPlayer(pl).sendMessage(blindnessTrapTitle)); + .forEach(pl -> Players.wrapPlayer(pl).sendMessage(blindnessTrapTitle)); } break; @@ -439,12 +439,12 @@ public Map.Entry handlePurchase(Player player, AtomicReference gameStorage.setPurchasedMinerTrap(team, true); if (SBAConfig.getInstance().trapTitleEnabled()) - team.getConnectedPlayers().forEach(pl -> SBAUtil.sendTitle(PlayerMapper.wrapPlayer(pl), + team.getConnectedPlayers().forEach(pl -> SBAUtil.sendTitle(Players.wrapPlayer(pl), minerTrapTitle, org.screamingsandals.lib.spectator.Component.empty(), 20, 40, 20)); if (SBAConfig.getInstance().trapMessageEnabled()) team.getConnectedPlayers() - .forEach(pl -> PlayerMapper.wrapPlayer(pl).sendMessage(minerTrapTitle)); + .forEach(pl -> Players.wrapPlayer(pl).sendMessage(minerTrapTitle)); } break; @@ -465,7 +465,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference gameStorage.setPurchasedPool(team, true); shouldSellStack = true; team.getConnectedPlayers().forEach( - pl -> PlayerMapper.wrapPlayer(pl).sendMessage(purchaseHealPoolMessage)); + pl -> Players.wrapPlayer(pl).sendMessage(purchaseHealPoolMessage)); } break; case "forge": @@ -554,7 +554,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_PROTECTION) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -580,7 +580,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference Logger.trace("ePrice:{}", ePrice); teamProtectionLevel = teamProtectionLevel + 1; Logger.trace("teamProtectionLevel:{}", teamProtectionLevel); - materialItem.set(ItemFactory.build(type.getStack(ePrice)).get());// . (ItemFactory. ( + materialItem.set(ItemStackFactory.build(type.getStack(ePrice)));// . (ItemFactory. ( // type.getStack(ePrice))); if (player.getInventory().containsAtLeast(materialItem.get().as(ItemStack.class), @@ -601,7 +601,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .forEach(item -> { ShopUtil.applyTeamEnchants(teamPlayer, item); }); - PlayerMapper.wrapPlayer(teamPlayer).sendMessage(upgradeMessage); + Players.wrapPlayer(teamPlayer).sendMessage(upgradeMessage); }); } else @@ -618,7 +618,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_ENCHANT) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Optional ech = Arrays.stream(Enchantment.values()) .filter(x -> x.getName().equalsIgnoreCase(propertyName)) .findAny(); @@ -645,7 +645,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference var ePrice = otherPrices.get(propertyName).get(teamOtherLevel); teamOtherLevel = teamOtherLevel + 1; - materialItem.set(ItemFactory.build(type.getStack(ePrice)).get());// . (ItemFactory. ( + materialItem.set(ItemStackFactory.build(type.getStack(ePrice)));// . (ItemFactory. ( // type.getStack(ePrice))); if (player.getInventory().containsAtLeast(materialItem.get().as(ItemStack.class), ePrice)) { @@ -655,7 +655,7 @@ public Map.Entry handlePurchase(Player player, AtomicReference .getInstance() .get(MessageKeys.UPGRADE_TEAM_ENCHANT) .replace("%player%", player.getDisplayName() + ChatColor.RESET) - .send(PlayerMapper.wrapPlayer(teamPlayer)); + .send(Players.wrapPlayer(teamPlayer)); Arrays.stream(teamPlayer.getInventory().getContents()) .filter(Objects::nonNull) @@ -730,17 +730,17 @@ public void onBedWarsOpenShop(BedwarsOpenShopEvent event) { LanguageService .getInstance() .get(MessageKeys.MESSAGE_NOT_IN_GAME) - .send(PlayerMapper.wrapPlayer(event.getPlayer())); + .send(Players.wrapPlayer(event.getPlayer())); return; } if (Main.getInstance().getGameOfPlayer(event.getPlayer()).getTeamOfPlayer(event.getPlayer())==null) { LanguageService .getInstance() .get(MessageKeys.MESSAGE_NOT_IN_GAME) - .send(PlayerMapper.wrapPlayer(event.getPlayer())); + .send(Players.wrapPlayer(event.getPlayer())); return; } - openForPlayer(PlayerMapper.wrapPlayer(event.getPlayer()).as(SBAPlayerWrapper.class), + openForPlayer(Players.wrapPlayer(event.getPlayer()).as(SBAPlayerWrapper.class), (GameStore) event.getStore()); } } \ No newline at end of file diff --git a/plugin/src/main/java/io/github/pronze/sba/lib/lang/LanguageService.java b/plugin/src/main/java/io/github/pronze/sba/lib/lang/LanguageService.java index 10b49856..b8fe385c 100644 --- a/plugin/src/main/java/io/github/pronze/sba/lib/lang/LanguageService.java +++ b/plugin/src/main/java/io/github/pronze/sba/lib/lang/LanguageService.java @@ -8,8 +8,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.screamingsandals.lib.plugin.ServiceManager; -import org.screamingsandals.lib.tasker.Tasker; -import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.spongepowered.configurate.ConfigurationNode; diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/BedWarsListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/BedWarsListener.java index 21151606..7c0a05ab 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/BedWarsListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/BedWarsListener.java @@ -6,13 +6,9 @@ import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.party.IParty; import io.github.pronze.sba.party.PartyManager; -import io.github.pronze.sba.service.AIService; import io.github.pronze.sba.utils.Logger; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -21,13 +17,11 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent.Reason; import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; @@ -36,11 +30,10 @@ import org.screamingsandals.bedwars.api.events.*; import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.game.Game; -import org.screamingsandals.bedwars.lib.lang.I; -import org.screamingsandals.bedwars.lib.nms.entity.PlayerUtils; import org.screamingsandals.bedwars.utils.MiscUtils; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; @@ -57,12 +50,10 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collector; import java.util.stream.Collectors; import static org.screamingsandals.bedwars.lib.lang.I18n.i18nonly; @@ -314,7 +305,7 @@ public void run() { message = seconds == 1 ? message .replace("seconds", "second") : message; player.sendMessage(message); - SBAUtil.sendTitle(PlayerMapper.wrapPlayer(player), + SBAUtil.sendTitle(Players.wrapPlayer(player), Component.fromLegacy(ShopUtil.translateColors("&c" + seconds)), org.screamingsandals.lib.spectator.Component.empty(), 0, 20, 0); } @@ -374,12 +365,12 @@ public void onBedWarsPlayerLeave(BedwarsPlayerLeaveEvent e) { if (party.getPartyLeader().getInstance() == e.getPlayer()) { party.getMembers().forEach(member -> { if (member != e.getPlayer()) { - Tasker.build(() -> { + Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> { var memberGame = Main.getInstance().getGameOfPlayer(member.getInstance()); if (memberGame != null) { memberGame.leaveFromGame(member.getInstance()); } - }).afterOneTick().start(); + }); } }); } @@ -395,14 +386,14 @@ public void onBedWarsPlayerRespawnEvent(PlayerRespawnEvent e) { } final var game = Main.getInstance().getGameOfPlayer(victim); // query arena instance for access to Victim/Killer data - Tasker.build(() -> { + Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> { ArenaManager .getInstance() .get(game.getName()) .ifPresent(arena -> { arena.addVisualsForPlayer(victim); }); - }).afterOneTick().start(); + }); } @EventHandler(priority = EventPriority.MONITOR) @@ -438,7 +429,7 @@ public void onBedwarsPlayerPlay(PlayerGameModeChangeEvent e) { arena_.removeHiddenPlayer(player); }); } - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { if (inventoryContent.containsKey(player.getUniqueId())) { player.getInventory().clear(); player.getInventory().setContents(inventoryContent.get(player.getUniqueId())); @@ -450,7 +441,7 @@ public void onBedwarsPlayerPlay(PlayerGameModeChangeEvent e) { final var game = Main.getInstance().getGameOfPlayer(player); ShopUtil.applyTeamUpgrades(player, game); - }).delay(2, TaskerTime.TICKS).start(); + }, 2, TaskerTime.TICKS); } @@ -477,7 +468,7 @@ public void onBedwarsPlayerSpectate(PlayerGameModeChangeEvent e) { } if(!collidableValue.containsKey(player.getUniqueId())) collidableValue.put(player.getUniqueId(), player.isCollidable()); - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { player.getInventory().clear(); @@ -503,7 +494,7 @@ public void onBedwarsPlayerSpectate(PlayerGameModeChangeEvent e) { player.getInventory().setItem(leavePosition, SBAConfig.getInstance().spectator().leave().get()); } player.setGameMode(GameMode.ADVENTURE); - }).delay(1, TaskerTime.TICKS).start(); + }, 1, TaskerTime.TICKS); } @EventHandler @@ -578,7 +569,7 @@ public void onBedwarsPlayerFakeSpectate(PlayerGameModeChangeEvent e) { } if (!SBAConfig.getInstance().spectator().adventure()) return; - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 360000, 0)); player.setAllowFlight(true); player.setFlying(true); @@ -589,7 +580,7 @@ public void onBedwarsPlayerFakeSpectate(PlayerGameModeChangeEvent e) { arena.ifPresent(arena_ -> { arena_.addHiddenPlayer(player); }); - }).delay(1, TaskerTime.TICKS).start(); + }, 1, TaskerTime.TICKS); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/BedwarsCustomMessageModifierListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/BedwarsCustomMessageModifierListener.java index df5be4ff..afd6f163 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/BedwarsCustomMessageModifierListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/BedwarsCustomMessageModifierListener.java @@ -15,11 +15,10 @@ import org.screamingsandals.bedwars.api.events.BedwarsBedDestroyedMessageSendEvent; import org.screamingsandals.bedwars.api.events.BedwarsPlayerDeathMessageSendEvent; import org.screamingsandals.bedwars.game.TeamColor; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import java.util.List; import java.util.Random; @Service @@ -48,7 +47,7 @@ public void onBedwarsPlayerDeath(PlayerDeathEvent event) { .getInstance() .get(MessageKeys.TEAM_ELIMINATED_MESSAGE) .replace("%team%", teamColorStr + playerTeam.getName()) - .send(PlayerMapper.wrapPlayer(gPlayer))); + .send(Players.wrapPlayer(gPlayer))); } } @@ -71,7 +70,7 @@ public void onBedWarsBedDestroyedMessageSendEvent(BedwarsBedDestroyedMessageSend final var randomlyChosen = messages.get(RANDOM.nextInt(messages.size())); event.getVictim().sendMessage(" "); - PlayerMapper.wrapPlayer(event.getVictim()).sendMessage(randomlyChosen); + Players.wrapPlayer(event.getVictim()).sendMessage(randomlyChosen); event.getVictim().sendMessage(" "); } diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/GameChatListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/GameChatListener.java index 9b40384b..969f8b4b 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/GameChatListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/GameChatListener.java @@ -12,7 +12,7 @@ import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.game.TeamColor; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; @@ -30,7 +30,7 @@ public void registerListener() { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerChat(AsyncPlayerChatEvent event) { final var player = event.getPlayer(); - final var playerWrapper = PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class); + final var playerWrapper = Players.wrapPlayer(player).as(SBAPlayerWrapper.class); if (playerWrapper.getSettings().isToggled(PlayerSetting.IN_PARTY) && playerWrapper.getSettings().isToggled(PlayerSetting.PARTY_CHAT_ENABLED)) { diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/GameModeListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/GameModeListener.java index bb5d79b4..fb79aeeb 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/GameModeListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/GameModeListener.java @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -22,11 +23,14 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; +import org.screamingsandals.lib.item.builder.ItemStackFactory; +import org.screamingsandals.lib.packet.ClientboundSetPlayerTeamPacket; +import org.screamingsandals.lib.player.Players; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.utils.Pair; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.utils.reflect.Reflect; -import org.screamingsandals.lib.world.LocationMapper; import org.screamingsandals.lib.spectator.Color; import org.screamingsandals.lib.spectator.Component; @@ -35,15 +39,12 @@ import org.screamingsandals.bedwars.commands.AdminCommand; import org.screamingsandals.lib.hologram.Hologram; import org.screamingsandals.lib.hologram.HologramManager; -import org.screamingsandals.lib.item.builder.ItemFactory; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.bedwars.game.Game; import org.screamingsandals.bedwars.game.GameStore; import org.screamingsandals.bedwars.game.ItemSpawner; import org.screamingsandals.lib.npc.NPC; -import org.screamingsandals.lib.packet.SClientboundSetPlayerTeamPacket.CollisionRule; @Service public class GameModeListener implements Listener { @@ -160,41 +161,41 @@ public void setArena(GameCreator gameCreator) { } public void playerMoved(@NotNull Player player) { - npcs.values().forEach(n -> n.removeViewer(PlayerMapper.wrapPlayer(player))); - holograms.values().forEach(h -> h.removeViewer(PlayerMapper.wrapPlayer(player))); + npcs.values().forEach(n -> n.removeViewer(Players.wrapPlayer(player))); + holograms.values().forEach(h -> h.removeViewer(Players.wrapPlayer(player))); - Tasker.build(() -> { + Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> { for (var npc : npcs.values()) { if (npc.location().getWorld().getName().equals(player.getWorld().getName())) { - npc.addViewer(PlayerMapper.wrapPlayer(player)); + npc.addViewer(Players.wrapPlayer(player)); } } for (var holo : holograms.values()) { if (holo.location().getWorld().getName().equals(player.getWorld().getName())) { - holo.addViewer(PlayerMapper.wrapPlayer(player)); + holo.addViewer(Players.wrapPlayer(player)); } } - }).afterOneTick().start(); + }); } public void playerDisconnect(@NotNull Player player) { - holograms.values().forEach(h -> h.removeViewer(PlayerMapper.wrapPlayer(player))); - npcs.values().forEach(n -> n.removeViewer(PlayerMapper.wrapPlayer(player))); + holograms.values().forEach(h -> h.removeViewer(Players.wrapPlayer(player))); + npcs.values().forEach(n -> n.removeViewer(Players.wrapPlayer(player))); } private NPC addNpcAt(Location l, String name) { if (name == null) name = "shop.yml"; - NPC npc = NPC.of(LocationMapper.wrapLocation(l)) + NPC npc = NPC.of(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(l))) .lookAtPlayer(true) .displayName(List.of(Component.text(name) .withColor(Color.rgb(139, 69, 19)))) - .collisionRule(CollisionRule.NEVER) + .collisionRule(ClientboundSetPlayerTeamPacket.CollisionRule.NEVER) .show(); for (Player p : Bukkit.getOnlinePlayers()) { if (l.getWorld() == p.getWorld()) { - npc.addViewer(PlayerMapper.wrapPlayer(p)); + npc.addViewer(Players.wrapPlayer(p)); } } return npc; @@ -214,16 +215,16 @@ public void run() { for (var spawners : game.getSpawners()) { if (!holograms.containsKey(spawners)) { var hologram = HologramManager - .hologram(LocationMapper.wrapLocation(spawners.getLocation().clone())); + .hologram(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(spawners.getLocation().clone()))); hologram.show(); for (Player p : Bukkit.getOnlinePlayers()) { if (spawners.getLocation().getWorld() == p.getWorld()) { - hologram.addViewer(PlayerMapper.wrapPlayer(p)); + hologram.addViewer(Players.wrapPlayer(p)); } } - hologram.item(ItemFactory.build(spawners.getItemSpawnerType().getStack()).orElseThrow()) + hologram.item(Objects.requireNonNull(ItemStackFactory.build(spawners.getItemSpawnerType().getStack()))) .itemPosition(Hologram.ItemPosition.BELOW) .rotationMode(Hologram.RotationMode.Y) .rotationTime(Pair.of(1, TaskerTime.TICKS)) diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/GeneratorSplitterListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/GeneratorSplitterListener.java index b646cbb9..90964080 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/GeneratorSplitterListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/GeneratorSplitterListener.java @@ -1,9 +1,7 @@ package io.github.pronze.sba.listener; -import com.google.gson.Gson; import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; -import io.github.pronze.sba.utils.Logger; import lombok.SneakyThrows; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -16,14 +14,13 @@ import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.Plugin; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.APIUtils; import org.screamingsandals.bedwars.api.BedwarsAPI; import org.screamingsandals.bedwars.api.events.BedwarsResourceSpawnEvent; import org.screamingsandals.bedwars.utils.Sounds; -import org.screamingsandals.lib.bukkit.utils.nms.Version; +import org.screamingsandals.lib.impl.bukkit.utils.Version; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/PacketListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/PacketListener.java index edecfff5..36f1720e 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/PacketListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/PacketListener.java @@ -3,8 +3,8 @@ import org.bukkit.entity.Player; import org.screamingsandals.bedwars.Main; import org.screamingsandals.lib.event.OnEvent; -import org.screamingsandals.lib.nms.accessors.ClientboundSetEquipmentPacketAccessor; -import org.screamingsandals.lib.nms.accessors.ClientboundUpdateMobEffectPacketAccessor; +import org.screamingsandals.lib.impl.nms.accessors.ClientboundSetEquipmentPacketAccessor; +import org.screamingsandals.lib.impl.nms.accessors.ClientboundUpdateMobEffectPacketAccessor; import org.screamingsandals.lib.packet.event.SPacketEvent; import org.screamingsandals.lib.utils.PacketMethod; import org.screamingsandals.lib.utils.annotations.Service; diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/PartyListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/PartyListener.java index 823f8beb..b94d8ea4 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/PartyListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/PartyListener.java @@ -2,15 +2,12 @@ import io.github.pronze.sba.events.SBAPlayerPartyChatEvent; import io.github.pronze.sba.wrapper.PlayerSetting; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import org.screamingsandals.lib.spectator.Component; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.scheduler.BukkitRunnable; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/PlayerListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/PlayerListener.java index 78452289..63bdc90f 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/PlayerListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/PlayerListener.java @@ -37,14 +37,13 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.scheduler.BukkitRunnable; import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.game.GamePlayer; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.utils.reflect.Reflect; @@ -156,7 +155,7 @@ public void onPlayerDeath(PlayerDeathEvent e) { final GamePlayer gamePlayer = gVictim; final Player player = gamePlayer.player; - final SBAPlayerWrapper wrappedPlayer = PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class); + final SBAPlayerWrapper wrappedPlayer = Players.wrapPlayer(player).as(SBAPlayerWrapper.class); int livingTime = Main.getInstance().getConfig().getInt("respawn-cooldown.time", 5); byte buffer = 2; @@ -253,7 +252,7 @@ public void onClick(InventoryClickEvent event) { LanguageService .getInstance() .get(MessageKeys.CANNOT_PUT_ITEM_IN_CHEST) - .send(PlayerMapper.wrapPlayer(player)); + .send(Players.wrapPlayer(player)); } } } @@ -296,7 +295,7 @@ public void onPlayerLeave(PlayerQuitEvent e) { .fromCache(uuid) .ifPresent(Scoreboard::destroy); - final var wrappedPlayer = PlayerMapper.wrapPlayer(player) + final var wrappedPlayer = Players.wrapPlayer(player) .as(SBAPlayerWrapper.class); SBA.getInstance() .getPartyManager() diff --git a/plugin/src/main/java/io/github/pronze/sba/listener/SpawnerProtectionListener.java b/plugin/src/main/java/io/github/pronze/sba/listener/SpawnerProtectionListener.java index 2d3d4d1e..511714f4 100644 --- a/plugin/src/main/java/io/github/pronze/sba/listener/SpawnerProtectionListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/listener/SpawnerProtectionListener.java @@ -1,51 +1,21 @@ package io.github.pronze.sba.listener; import io.github.pronze.sba.MessageKeys; -import io.github.pronze.sba.Permissions; import io.github.pronze.sba.SBA; -import io.github.pronze.sba.config.SBAConfig; -import io.github.pronze.sba.data.DegradableItem; -import io.github.pronze.sba.game.ArenaManager; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.specials.SpawnerProtection; -import io.github.pronze.sba.utils.SBAUtil; -import io.github.pronze.sba.utils.ShopUtil; -import io.github.pronze.sba.wrapper.SBAPlayerWrapper; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.inventory.InventoryType.SlotType; -import org.bukkit.event.player.*; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import org.bukkit.scheduler.BukkitRunnable; import org.screamingsandals.bedwars.Main; -import org.screamingsandals.bedwars.api.game.GameStatus; -import org.screamingsandals.bedwars.game.GamePlayer; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; -import io.github.pronze.lib.pronzelib.scoreboards.Scoreboard; -import io.github.pronze.lib.pronzelib.scoreboards.ScoreboardManager; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -@Service(dependsOn = SpawnerProtection.class) +@Service +@ServiceDependencies(dependsOn = SpawnerProtection.class) public class SpawnerProtectionListener implements Listener { @OnPostEnable @@ -72,7 +42,7 @@ public void onPlace(BlockPlaceEvent event) .getInstance() .get(MessageKeys.SPAWNER_PROTECTION) .toComponent(); - PlayerMapper.wrapSender(player).sendMessage(component); + Players.wrapSender(player).sendMessage(component); } } } diff --git a/plugin/src/main/java/io/github/pronze/sba/party/Party.java b/plugin/src/main/java/io/github/pronze/sba/party/Party.java index 1ced270f..066252f3 100644 --- a/plugin/src/main/java/io/github/pronze/sba/party/Party.java +++ b/plugin/src/main/java/io/github/pronze/sba/party/Party.java @@ -1,12 +1,12 @@ package io.github.pronze.sba.party; import io.github.pronze.sba.wrapper.PlayerSetting; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.MessageKeys; @@ -57,7 +57,7 @@ public void sendMessage(@NotNull Component message, @NotNull SBAPlayerWrapper se .replace("%name%", sender.as(Player.class).getDisplayName() + ChatColor.RESET) .replace("%message%", (message)) .toComponent(); - members.forEach(player -> PlayerMapper.wrapPlayer(player.getInstance()).sendMessage(formattedMessage)); + members.forEach(player -> Players.wrapPlayer(player.getInstance()).sendMessage(formattedMessage)); } @Override diff --git a/plugin/src/main/java/io/github/pronze/sba/party/PartyManager.java b/plugin/src/main/java/io/github/pronze/sba/party/PartyManager.java index 6e5620ac..1c8d9204 100644 --- a/plugin/src/main/java/io/github/pronze/sba/party/PartyManager.java +++ b/plugin/src/main/java/io/github/pronze/sba/party/PartyManager.java @@ -3,7 +3,6 @@ import io.github.pronze.sba.manager.IPartyManager; import io.github.pronze.sba.wrapper.PlayerSetting; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; import io.github.pronze.sba.SBA; @@ -11,13 +10,15 @@ import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import io.github.pronze.sba.utils.Logger; import io.github.pronze.sba.utils.SBAUtil; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.UUID; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { Logger.class }) public class PartyManager implements IPartyManager { diff --git a/plugin/src/main/java/io/github/pronze/sba/placeholderapi/SBAExpansion.java b/plugin/src/main/java/io/github/pronze/sba/placeholderapi/SBAExpansion.java index 1bad3c08..19cbb097 100644 --- a/plugin/src/main/java/io/github/pronze/sba/placeholderapi/SBAExpansion.java +++ b/plugin/src/main/java/io/github/pronze/sba/placeholderapi/SBAExpansion.java @@ -8,8 +8,6 @@ import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import javax.lang.model.util.ElementScanner14; - import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; diff --git a/plugin/src/main/java/io/github/pronze/sba/service/AIService.java b/plugin/src/main/java/io/github/pronze/sba/service/AIService.java index 8844199a..055a3669 100644 --- a/plugin/src/main/java/io/github/pronze/sba/service/AIService.java +++ b/plugin/src/main/java/io/github/pronze/sba/service/AIService.java @@ -56,9 +56,11 @@ import org.screamingsandals.lib.npc.NPCManager; import org.screamingsandals.lib.npc.event.NPCInteractEvent; import org.screamingsandals.lib.plugin.ServiceManager; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.utils.annotations.methods.OnPreDisable; import org.screamingsandals.lib.utils.reflect.Reflect; @@ -74,7 +76,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { NPCManager.class }) @Getter @@ -171,11 +174,11 @@ public CompletableFuture spawnAI(Location loc, Strategy strategy) { npc.addTrait(new BedwarsBlockPlace()); npc.getOrAddTrait(SkinTrait.class).setSkinName(settings.skin()); - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { Player ai = (Player) (npc.getEntity()); ai.setCanPickupItems(true); CompletableFuture.complete(ai); - }).delay(settings.delay(), TaskerTime.TICKS).start(); + }, settings.delay(), TaskerTime.TICKS); } else { CompletableFuture.complete(null); @@ -222,7 +225,7 @@ public void onNPCRespawn(PlayerGameModeChangeEvent event) { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerLeave(BedwarsPlayerLeaveEvent event) { var game = event.getGame(); - Tasker.build(() -> { + Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> { boolean allAI = true; for (Player p : game.getConnectedPlayers()) { if (!isNPC(p)) { @@ -236,7 +239,7 @@ public void onPlayerLeave(BedwarsPlayerLeaveEvent event) { getNPC(p).destroy(); } } - }).afterOneTick().start(); + }); } @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) diff --git a/plugin/src/main/java/io/github/pronze/sba/service/GamesInventoryService.java b/plugin/src/main/java/io/github/pronze/sba/service/GamesInventoryService.java index b8317207..c4bf041b 100644 --- a/plugin/src/main/java/io/github/pronze/sba/service/GamesInventoryService.java +++ b/plugin/src/main/java/io/github/pronze/sba/service/GamesInventoryService.java @@ -2,16 +2,12 @@ import io.github.pronze.sba.MessageKeys; import io.github.pronze.sba.SBA; -import io.github.pronze.sba.game.GameMode; import io.github.pronze.sba.inventories.GamesInventory; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.utils.Logger; -import io.github.pronze.sba.visuals.MainLobbyVisualsManager; import lombok.SneakyThrows; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -21,20 +17,18 @@ import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.screamingsandals.lib.event.OnEvent; -import org.screamingsandals.lib.event.player.SPlayerJoinEvent; import org.screamingsandals.lib.npc.NPC; import org.screamingsandals.lib.npc.event.NPCInteractEvent; import org.screamingsandals.lib.npc.skin.NPCSkin; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.player.PlayerWrapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.plugin.ServiceManager; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.utils.annotations.methods.OnPreDisable; -import org.screamingsandals.lib.world.LocationHolder; -import org.screamingsandals.lib.world.LocationMapper; import java.io.File; import java.util.ArrayList; @@ -43,8 +37,8 @@ import java.util.Map; import java.util.Objects; -@Service(dependsOn = { - PlayerMapper.class, +@Service +@ServiceDependencies(dependsOn = { PlayerWrapperService.class }) public class GamesInventoryService implements Listener { @@ -127,9 +121,9 @@ public void loadGamesInv() { }); update(); } - Tasker.build(() -> Bukkit.getOnlinePlayers().forEach(player -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> Bukkit.getOnlinePlayers().forEach(player -> { addViewer(player); - })).delay(1L, TaskerTime.SECONDS).start(); + }), 1L, TaskerTime.SECONDS); } @SuppressWarnings("unchecked") @@ -152,7 +146,7 @@ private void checkAndAdd(YamlConfiguration config, String mode, List l } private NPC createNpc(String mode, Location location) { - return NPC.of(LocationMapper.wrapLocation(location)) + return NPC.of(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(location))) .lookAtPlayer(true) .displayName(LanguageService .getInstance() @@ -195,7 +189,7 @@ public void addNPC(@NotNull String mode, @NotNull Location location) { update(); } - public void removeNPC(PlayerWrapper remover, @NotNull NPC npc) { + public void removeNPC(org.screamingsandals.lib.player.Player remover, @NotNull NPC npc) { NPCs.stream().filter(n -> n.npc == npc).findAny().ifPresent(c -> { LanguageService .getInstance() @@ -244,14 +238,14 @@ public void addViewer(@NotNull Player player) { Logger.trace("npc::addViewer", player.getName()); if (npc.location.getWorld().equals(player.getWorld())) if (npc.npc != null) - npc.npc.addViewer(PlayerMapper.wrapPlayer(player)); + npc.npc.addViewer(Players.wrapPlayer(player)); }); } public void removeViewer(@NotNull Player player) { NPCs.forEach(npc -> { if (npc.npc != null) - npc.npc.removeViewer(PlayerMapper.wrapPlayer(player)); + npc.npc.removeViewer(Players.wrapPlayer(player)); }); } @@ -268,21 +262,21 @@ public void destroy() { @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { final var player = e.getPlayer(); - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { if (player.isOnline()) { addViewer(player); } - }).delay(1L, TaskerTime.TICKS).start(); + }, 1L, TaskerTime.TICKS); } @EventHandler public void onPlayerChangeWorld(PlayerChangedWorldEvent e) { final var player = e.getPlayer(); - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { if (player.isOnline()) { addViewer(player); } - }).delay(1L, TaskerTime.TICKS).start(); + }, 1L, TaskerTime.TICKS); } @OnPreDisable @@ -290,20 +284,19 @@ private void onDisable() { entityEditMap.clear(); } - public void addEditable(PlayerWrapper player, Action mode, Object argument) { + public void addEditable(org.screamingsandals.lib.player.Player player, Action mode, Object argument) { if (entityEditMap.containsKey(player.as(Player.class).getEntityId())) { return; } entityEditMap.put(player.as(Player.class).getEntityId(), mode); entityEditMapArgument.put(player.as(Player.class).getEntityId(), argument); - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { entityEditMap.remove(Integer.valueOf(player.as(Player.class).getEntityId())); entityEditMapArgument.remove(Integer.valueOf(player.as(Player.class).getEntityId())); - }) - .delay(5L, TaskerTime.SECONDS).start(); + }, 5L, TaskerTime.SECONDS); } - private void setNpcSkin(PlayerWrapper player, NPC visual) { + private void setNpcSkin(org.screamingsandals.lib.player.Player player, NPC visual) { String argument = (String) entityEditMapArgument.get(player.as(Player.class).getEntityId()); NPCSkin.retrieveSkin(argument).whenComplete((skin, exp) -> { if (skin != null) { diff --git a/plugin/src/main/java/io/github/pronze/sba/service/HealthIndicatorService.java b/plugin/src/main/java/io/github/pronze/sba/service/HealthIndicatorService.java index 36e700fc..5b157a3f 100644 --- a/plugin/src/main/java/io/github/pronze/sba/service/HealthIndicatorService.java +++ b/plugin/src/main/java/io/github/pronze/sba/service/HealthIndicatorService.java @@ -3,10 +3,10 @@ import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.game.IArena; -import io.github.pronze.sba.utils.Logger; import me.clip.placeholderapi.PlaceholderAPI; import io.github.pronze.sba.game.ArenaManager; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Color; import org.screamingsandals.lib.spectator.Component; @@ -19,24 +19,21 @@ import org.screamingsandals.bedwars.api.events.BedwarsGameStartedEvent; import org.screamingsandals.bedwars.api.events.BedwarsPlayerLeaveEvent; import org.screamingsandals.bedwars.api.game.Game; -import org.screamingsandals.lib.healthindicator.HealthIndicator; import org.screamingsandals.lib.healthindicator.HealthIndicator2; import org.screamingsandals.lib.healthindicator.HealthIndicatorImpl2; import org.screamingsandals.lib.healthindicator.HealthIndicatorManager2; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.player.PlayerWrapper; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.utils.annotations.methods.OnPreDisable; import org.screamingsandals.lib.visuals.Visual; -import java.beans.DefaultPersistenceDelegate; import java.util.HashMap; import java.util.Map; -import java.util.function.Supplier; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { HealthIndicatorManager2.class }) public class HealthIndicatorService implements Listener { @@ -73,7 +70,7 @@ public void postEnabled() { SBA.getInstance().registerListener(this); } - private String placeholderProvider(PlayerWrapper p) { + private String placeholderProvider(org.screamingsandals.lib.player.Player p) { if (defaultPlaceholderProvider.equals(placeholderProvider)) { return p.getName(); } @@ -106,12 +103,12 @@ public void onGameStart(BedwarsGameStartedEvent event) { game.getConnectedPlayers() .stream() - .map(PlayerMapper::wrapPlayer) + .map(Players::wrapPlayer) .forEach(healthIndicator::addViewer); game.getConnectedPlayers() .stream() - .map(PlayerMapper::wrapPlayer) + .map(Players::wrapPlayer) .forEach(healthIndicator::addTrackedPlayer); healthIndicatorMap.put(ArenaManager.getInstance().get(game.getName()).orElseThrow(), healthIndicator); @@ -119,7 +116,7 @@ public void onGameStart(BedwarsGameStartedEvent event) { @EventHandler public void onPlayerLeave(BedwarsPlayerLeaveEvent event) { - final var playerWrapper = PlayerMapper.wrapPlayer(event.getPlayer()); + final var playerWrapper = Players.wrapPlayer(event.getPlayer()); final var healthIndicator = healthIndicatorMap .get(ArenaManager.getInstance().get(event.getGame().getName()).orElse(null)); if (healthIndicator != null) { diff --git a/plugin/src/main/java/io/github/pronze/sba/service/NPCStoreService.java b/plugin/src/main/java/io/github/pronze/sba/service/NPCStoreService.java index 218af2d6..d22074ff 100644 --- a/plugin/src/main/java/io/github/pronze/sba/service/NPCStoreService.java +++ b/plugin/src/main/java/io/github/pronze/sba/service/NPCStoreService.java @@ -21,6 +21,7 @@ import org.screamingsandals.lib.npc.event.NPCInteractEvent; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import org.screamingsandals.lib.npc.skin.NPCSkin; @@ -29,7 +30,8 @@ import java.util.Objects; import java.util.stream.Collectors; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { NPCManager.class }) @Getter diff --git a/plugin/src/main/java/io/github/pronze/sba/service/PlayerWrapperService.java b/plugin/src/main/java/io/github/pronze/sba/service/PlayerWrapperService.java index 6d97bcfd..33282128 100644 --- a/plugin/src/main/java/io/github/pronze/sba/service/PlayerWrapperService.java +++ b/plugin/src/main/java/io/github/pronze/sba/service/PlayerWrapperService.java @@ -7,10 +7,11 @@ import io.github.pronze.sba.wrapper.SBAPlayerWrapper; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.player.SenderWrapper; +import org.screamingsandals.lib.player.Players; +import org.screamingsandals.lib.player.Sender; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; @@ -19,8 +20,8 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -@Service(dependsOn = { - PlayerMapper.class, +@Service +@ServiceDependencies(dependsOn = { Logger.class }) public class PlayerWrapperService implements WrapperService { @@ -35,9 +36,9 @@ public static PlayerWrapperService getInstance() { public void registerMapping() { if(SBA.isBroken())return; if(!init) - PlayerMapper.UNSAFE_getPlayerConverter() + Players.UNSAFE_getPlayerConverter() .registerW2P(SBAPlayerWrapper.class, wrapper -> { - if (wrapper.getType() == SenderWrapper.Type.PLAYER) { + if (wrapper.getType() == Sender.Type.PLAYER) { if(!playerData.containsKey(wrapper.getUuid())){ var player = wrapper.as(Player.class);// Bukkit.getServer().getPlayer(wrapper.getUuid()); register(player); diff --git a/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java b/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java index 9d447edb..c2e4c488 100644 --- a/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java +++ b/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java @@ -15,6 +15,7 @@ import org.screamingsandals.bedwars.api.RunningTeam; import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.api.game.GameStatus; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.reflect.Reflect; @@ -62,7 +63,7 @@ public void createTower() { placeAnimated(BlockFace.WEST, BlockFace.SOUTH); placeAnimated(BlockFace.EAST, BlockFace.SOUTH); - Tasker.build(() -> { + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { // second platform final Block secondPlatform = centerPoint.getBlock().getRelative(BlockFace.UP, 5); placeBlock(secondPlatform.getLocation(), material); @@ -112,7 +113,7 @@ public void createTower() { final Location firstLadderBlock = centerPoint.getBlock().getRelative(placementFace).getLocation(); placeLadderRow(5, firstLadderBlock, BlockFace.UP, placementFace.getOppositeFace()); - }).delay(40L, TaskerTime.TICKS).start(); + }, 40L, TaskerTime.TICKS); } public void placeAnimated(BlockFace direction, BlockFace start) { @@ -125,7 +126,7 @@ public void placeRowAnimated(int length, Location loc, BlockFace face, int delay for (int i = 0; i < length; i++) { lastLoc = lastLoc.getBlock().getRelative(face).getLocation(); Location finalLastLoc = lastLoc; - Tasker.build(() -> placeBlock(finalLastLoc, material)).delay((delay += 1), TaskerTime.TICKS).start(); + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> placeBlock(finalLastLoc, material), (delay += 1), TaskerTime.TICKS); } } diff --git a/plugin/src/main/java/io/github/pronze/sba/specials/SpawnerProtection.java b/plugin/src/main/java/io/github/pronze/sba/specials/SpawnerProtection.java index b04a926c..46155c2b 100644 --- a/plugin/src/main/java/io/github/pronze/sba/specials/SpawnerProtection.java +++ b/plugin/src/main/java/io/github/pronze/sba/specials/SpawnerProtection.java @@ -3,12 +3,14 @@ import org.bukkit.Location; import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; import io.github.pronze.sba.SBA; import io.github.pronze.sba.config.SBAConfig; -@Service(dependsOn = SBAConfig.class) +@Service +@ServiceDependencies(dependsOn = SBAConfig.class) public class SpawnerProtection { private static SpawnerProtection instance; diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/DateUtils.java b/plugin/src/main/java/io/github/pronze/sba/utils/DateUtils.java index c47a04be..5e96c826 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/DateUtils.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/DateUtils.java @@ -2,11 +2,13 @@ import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; import io.github.pronze.sba.config.SBAConfig; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import java.text.SimpleDateFormat; import java.util.Date; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { SBAConfig.class }) public class DateUtils { diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/SBAUtil.java b/plugin/src/main/java/io/github/pronze/sba/utils/SBAUtil.java index c171f23c..7e9da437 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/SBAUtil.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/SBAUtil.java @@ -7,9 +7,6 @@ import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.service.AIService; import io.github.pronze.sba.service.DynamicSpawnerLimiterService; -import io.github.pronze.sba.service.GamesInventoryService; -import io.github.pronze.sba.service.NPCStoreService; -import io.github.pronze.sba.service.PlayerWrapperService; import lombok.NonNull; import org.bukkit.*; import org.bukkit.block.BlockFace; @@ -20,8 +17,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; -import org.screamingsandals.lib.nms.accessors.DirectionAccessor; -import org.screamingsandals.lib.player.PlayerWrapper; import org.screamingsandals.lib.spectator.title.TimesProvider; import org.screamingsandals.lib.spectator.title.Title; import org.bukkit.entity.Player; @@ -210,8 +205,8 @@ public static void reloadPlugin(@NonNull JavaPlugin plugin, CommandSender sender sender.sendMessage("Plugin reloaded! Keep in mind that restarting the server is safer!"); } - public static void sendTitle(PlayerWrapper player, org.screamingsandals.lib.spectator.Component title, org.screamingsandals.lib.spectator.Component subtitle, int fadeIn, int stay, - int fadeOut) { + public static void sendTitle(org.screamingsandals.lib.player.Player player, org.screamingsandals.lib.spectator.Component title, org.screamingsandals.lib.spectator.Component subtitle, int fadeIn, int stay, + int fadeOut) { var titleComponent = Title.title( title, subtitle, diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/ShopUtil.java b/plugin/src/main/java/io/github/pronze/sba/utils/ShopUtil.java index 345577c6..13d2a034 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/ShopUtil.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/ShopUtil.java @@ -12,9 +12,9 @@ import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.service.PlayerWrapperService; import io.github.pronze.sba.wrapper.SBAPlayerWrapper; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -29,9 +29,6 @@ import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.api.game.ItemSpawnerType; import org.screamingsandals.bedwars.api.utils.ColorChanger; -import org.screamingsandals.lib.item.Item; -import org.screamingsandals.lib.item.meta.EnchantmentMapping; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.simpleinventories.builder.LocalOptionsBuilder; import org.screamingsandals.simpleinventories.events.ItemRenderEvent; import org.screamingsandals.simpleinventories.inventory.PlayerItemInfo; @@ -112,7 +109,7 @@ public static boolean buyArmor(Player player, Material mat_boots, IGameStorage g .getInstance() .get(MessageKeys.CANNOT_DOWNGRADE_ITEM) .replace("%item%", "armor") - .send(PlayerMapper.wrapPlayer(player)); + .send(Players.wrapPlayer(player)); return false; } } @@ -122,7 +119,7 @@ public static boolean buyArmor(Player player, Material mat_boots, IGameStorage g .getInstance() .get(MessageKeys.ALREADY_PURCHASED) .replace("%thing%", "armor") - .send(PlayerMapper.wrapPlayer(player)); + .send(Players.wrapPlayer(player)); return false; } } @@ -204,7 +201,7 @@ public static ItemStack applyTeamEnchants(Player player, ItemStack newItem) { return newItem; } - public static Item applyTeamEnchants(Player player, Item newItem, StoreType type, List list) { + public static org.screamingsandals.lib.item.ItemStack applyTeamEnchants(Player player, org.screamingsandals.lib.item.ItemStack newItem, StoreType type, List list) { final var game = Main.getInstance().getGameOfPlayer(player); var gameStorage = SBA .getInstance() @@ -272,7 +269,7 @@ private static boolean canApply(String string, ItemStack newItem) { .anyMatch(x -> newItem.getType().toString().contains(x.toUpperCase())); } - private static boolean canApply(String string, Item newItem) { + private static boolean canApply(String string, org.screamingsandals.lib.item.ItemStack newItem) { if (SBAConfig.getInstance().upgrades().enchants().of(string) == null) { Logger.error("SBA doesn't know how to apply enchant {}, add it in the upgrade-item.enchants.ENCHANT_HERE", string); @@ -286,7 +283,7 @@ private static boolean canApply(Enchantment string, ItemStack newItem) { return canApply(getName(string), newItem); } - private static boolean canApply(Enchantment string, Item newItem) { + private static boolean canApply(Enchantment string, org.screamingsandals.lib.item.ItemStack newItem) { return canApply(getName(string), newItem); } @@ -417,7 +414,7 @@ public static File normalizeShopFile(String name) { return map; } - public static Item setLore(Item item, PlayerItemInfo itemInfo, String price, ItemSpawnerType type, Player player) { + public static org.screamingsandals.lib.item.ItemStack setLore(org.screamingsandals.lib.item.ItemStack item, PlayerItemInfo itemInfo, String price, ItemSpawnerType type, Player player) { var enabled = itemInfo.getFirstPropertyByName("generateLore") .map(property -> property.getPropertyData().getBoolean()) .orElseGet(() -> Main.getConfigurator().config.getBoolean("lore.generate-automatically", true)); @@ -499,7 +496,7 @@ public static Item setLore(Item item, PlayerItemInfo itemInfo, String price, Ite return item; } - public static Component getNameOrCustomNameOfItem(Item item) { + public static Component getNameOrCustomNameOfItem(org.screamingsandals.lib.item.ItemStack item) { try { if (item.getDisplayName() != null) { return (item.getDisplayName()); @@ -530,7 +527,7 @@ public static void addEnchantsToPlayerArmor(Player player, int newLevel) { } } - public static Item clampOrApplyEnchants(Item item, int level, Enchantment enchantment, StoreType type, + public static org.screamingsandals.lib.item.ItemStack clampOrApplyEnchants(org.screamingsandals.lib.item.ItemStack item, int level, Enchantment enchantment, StoreType type, int maxLevel) { Logger.trace("--- {} ENCHANT IS lvl {}/{}", enchantment, level, maxLevel); @@ -548,7 +545,7 @@ public static Item clampOrApplyEnchants(Item item, int level, Enchantment enchan item.getEnchantments().clear(); } } else if (level > 0) { - item = item.withEnchantment(EnchantmentMapping.resolve(enchantment).orElseThrow().withLevel(level)); + item = item.withEnchantment(org.screamingsandals.lib.item.meta.Enchantment.of(enchantment).withLevel(level)); } return item; } @@ -561,7 +558,7 @@ public static Item clampOrApplyEnchants(Item item, int level, Enchantment enchan * @param item * @param event */ - public static Item applyTeamUpgradeEnchantsToItem(Item item, ItemRenderEvent event, StoreType type) { + public static org.screamingsandals.lib.item.ItemStack applyTeamUpgradeEnchantsToItem(org.screamingsandals.lib.item.ItemStack item, ItemRenderEvent event, StoreType type) { final var player = event.getPlayer().as(Player.class); final var game = Main.getInstance().getGameOfPlayer(player); if (game == null) diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java index da439bf6..9d2c5488 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java @@ -6,45 +6,25 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageByBlockEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityPickupItemEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.metadata.MetadataValue; import org.screamingsandals.bedwars.api.game.Game; -import org.screamingsandals.lib.bukkit.utils.nms.Version; -import org.screamingsandals.lib.hologram.Hologram; -import org.screamingsandals.lib.hologram.HologramManager; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.world.LocationMapper; import io.github.pronze.sba.SBA; import io.github.pronze.sba.service.AIService; import io.github.pronze.sba.utils.Logger; -import lombok.Data; import lombok.Getter; import lombok.Setter; -import lombok.experimental.Accessors; import net.citizensnpcs.api.trait.Trait; -import org.screamingsandals.lib.spectator.Component; +import org.screamingsandals.lib.impl.bukkit.utils.Version; public class FakeDeathTrait extends Trait { diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/GatherBlocks.java b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/GatherBlocks.java index ed13bf14..a6be3157 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/GatherBlocks.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/GatherBlocks.java @@ -1,8 +1,6 @@ package io.github.pronze.sba.utils.citizens; import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Player; @@ -14,7 +12,6 @@ import io.github.pronze.sba.inventories.SBAStoreInventoryV2; import io.github.pronze.sba.utils.Logger; -import io.github.pronze.sba.utils.citizens.FakeDeathTrait.AiGoal; import lombok.Data; public class GatherBlocks implements FakeDeathTrait.AiGoal { @@ -124,7 +121,7 @@ public void doGoal() { } public void iterateShop(Player aiPlayer, GameStore gs, - BiConsumer consumer) { + BiConsumer consumer) { if (gs.getShopFile() == null || !StringUtils.containsIgnoreCase(gs.getShopFile(), "upgrade")) { var storeInv = SBAStoreInventoryV2.getInstance().iterate(gs); if (storeInv != null) { diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/HologramTrait.java b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/HologramTrait.java index eba11a34..40f4a98c 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/HologramTrait.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/HologramTrait.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.bukkit.Location; import org.bukkit.event.EventHandler; @@ -11,11 +12,9 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.screamingsandals.lib.hologram.Hologram; import org.screamingsandals.lib.hologram.HologramManager; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.world.LocationMapper; -import io.github.pronze.sba.utils.Logger; import net.citizensnpcs.api.trait.Trait; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; public class HologramTrait extends Trait { @@ -39,11 +38,11 @@ public void run() { holo.destroy(); holo = HologramManager - .hologram(LocationMapper.wrapLocation(newLoc)); + .hologram(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(newLoc))); holo.setLines(lines); getNPC().getEntity().getLocation().getWorld().getPlayers() - .forEach(player -> holo.addViewer(PlayerMapper.wrapPlayer(player))); + .forEach(player -> holo.addViewer(Players.wrapPlayer(player))); holo.spawn(); } } @@ -81,11 +80,11 @@ public void onSpawn() { onDespawn(); holo = HologramManager - .hologram(LocationMapper.wrapLocation(loc = getNPC().getEntity().getLocation().add(0.0D, 1.5D, 0.0D))); + .hologram(Objects.requireNonNull(org.screamingsandals.lib.world.Location.fromPlatform(loc = getNPC().getEntity().getLocation().add(0.0D, 1.5D, 0.0D)))); holo.setLines(lines); getNPC().getEntity().getLocation().getWorld().getPlayers() - .forEach(player -> holo.addViewer(PlayerMapper.wrapPlayer(player))); + .forEach(player -> holo.addViewer(Players.wrapPlayer(player))); holo.spawn(); } @@ -101,10 +100,10 @@ public void setLines(List lines) { @EventHandler(ignoreCancelled = true) public void onPlayerChangeWorld(PlayerChangedWorldEvent event) { if (holo != null) { - holo.removeViewer(PlayerMapper.wrapPlayer(event.getPlayer())); + holo.removeViewer(Players.wrapPlayer(event.getPlayer())); var player = event.getPlayer(); if (holo.location().getWorld().getName().equals(player.getWorld().getName())) { - holo.addViewer(PlayerMapper.wrapPlayer(player)); + holo.addViewer(Players.wrapPlayer(player)); } } } @@ -114,7 +113,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (holo != null) { var player = event.getPlayer(); if (holo.location().getWorld().getName().equals(player.getWorld().getName())) { - holo.addViewer(PlayerMapper.wrapPlayer(player)); + holo.addViewer(Players.wrapPlayer(player)); } } } @@ -122,10 +121,10 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler(ignoreCancelled = true) public void onPlayerTeleport(PlayerTeleportEvent event) { if (holo != null) { - holo.removeViewer(PlayerMapper.wrapPlayer(event.getPlayer())); + holo.removeViewer(Players.wrapPlayer(event.getPlayer())); var player = event.getPlayer(); if (holo.location().getWorld().getName().equals(player.getWorld().getName())) { - holo.addViewer(PlayerMapper.wrapPlayer(player)); + holo.addViewer(Players.wrapPlayer(player)); } } } @@ -133,7 +132,7 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { @EventHandler(ignoreCancelled = true) public void onPlayerLeave(PlayerQuitEvent event) { if (holo != null) - holo.removeViewer(PlayerMapper.wrapPlayer(event.getPlayer())); + holo.removeViewer(Players.wrapPlayer(event.getPlayer())); } } diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/ReturnToStoreTrait.java b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/ReturnToStoreTrait.java index d928418a..410933b7 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/ReturnToStoreTrait.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/ReturnToStoreTrait.java @@ -4,17 +4,7 @@ import java.util.List; import org.bukkit.Location; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.screamingsandals.lib.hologram.Hologram; -import org.screamingsandals.lib.hologram.HologramManager; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.world.LocationMapper; -import io.github.pronze.sba.utils.Logger; import net.citizensnpcs.api.trait.Trait; import org.screamingsandals.lib.spectator.Component; diff --git a/plugin/src/main/java/io/github/pronze/sba/visuals/GameScoreboardManager.java b/plugin/src/main/java/io/github/pronze/sba/visuals/GameScoreboardManager.java index bf2780ac..0079b1c1 100644 --- a/plugin/src/main/java/io/github/pronze/sba/visuals/GameScoreboardManager.java +++ b/plugin/src/main/java/io/github/pronze/sba/visuals/GameScoreboardManager.java @@ -5,7 +5,6 @@ import io.github.pronze.sba.game.tasks.GeneratorTask; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.utils.DateUtils; -import io.github.pronze.sba.utils.Logger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -22,7 +21,7 @@ import io.github.pronze.sba.config.SBAConfig; import io.github.pronze.sba.game.Arena; -import org.screamingsandals.lib.player.PlayerMapper; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import io.github.pronze.lib.pronzelib.scoreboards.Scoreboard; import io.github.pronze.lib.pronzelib.scoreboards.ScoreboardManager; @@ -83,7 +82,7 @@ public void createScoreboard(@NotNull Player player) { final var holder = scoreboard.getHolder().of(player); if (holder != null) { - Tasker.build(() -> game.getRunningTeams().forEach(team -> { + Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> game.getRunningTeams().forEach(team -> { if (!holder.hasTeamEntry(team.getName())) { holder.addTeam(team.getName(), TeamColor.fromApiColor(team.getColor()).chatColor); } @@ -97,7 +96,7 @@ public void createScoreboard(@NotNull Player player) { scoreboardTeam.addEntry(teamPlayer.getName()); } }); - })).afterOneTick().start(); + })); } scoreboardMap.put(player.getUniqueId(), scoreboard); } diff --git a/plugin/src/main/java/io/github/pronze/sba/visuals/LobbyScoreboardManager.java b/plugin/src/main/java/io/github/pronze/sba/visuals/LobbyScoreboardManager.java index 04ab3599..36c36f06 100644 --- a/plugin/src/main/java/io/github/pronze/sba/visuals/LobbyScoreboardManager.java +++ b/plugin/src/main/java/io/github/pronze/sba/visuals/LobbyScoreboardManager.java @@ -3,7 +3,6 @@ import io.github.pronze.sba.MessageKeys; import io.github.pronze.sba.lib.lang.LanguageService; import io.github.pronze.sba.utils.DateUtils; -import io.github.pronze.sba.utils.Logger; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Bukkit; @@ -14,14 +13,11 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Team.Option; import org.bukkit.scoreboard.Team.OptionStatus; -import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.events.BedwarsPlayerJoinedEvent; import org.screamingsandals.bedwars.api.events.BedwarsPlayerLeaveEvent; import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.game.TeamColor; -import org.screamingsandals.lib.player.PlayerMapper; -import org.screamingsandals.lib.player.PlayerWrapper; import org.screamingsandals.lib.plugin.ServiceManager; import org.screamingsandals.lib.utils.annotations.Service; import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable; diff --git a/plugin/src/main/java/io/github/pronze/sba/visuals/MainLobbyVisualsManager.java b/plugin/src/main/java/io/github/pronze/sba/visuals/MainLobbyVisualsManager.java index c0fd2c82..4d6fe335 100644 --- a/plugin/src/main/java/io/github/pronze/sba/visuals/MainLobbyVisualsManager.java +++ b/plugin/src/main/java/io/github/pronze/sba/visuals/MainLobbyVisualsManager.java @@ -2,8 +2,8 @@ import io.github.pronze.sba.MessageKeys; import io.github.pronze.sba.lib.lang.LanguageService; -import io.github.pronze.sba.utils.Logger; import me.clip.placeholderapi.PlaceholderAPI; +import org.screamingsandals.lib.player.Players; import org.screamingsandals.lib.spectator.Component; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -11,7 +11,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; @@ -20,8 +19,8 @@ import org.screamingsandals.bedwars.Main; import org.screamingsandals.bedwars.api.events.BedwarsPlayerJoinedEvent; import org.screamingsandals.bedwars.api.events.BedwarsPlayerLeaveEvent; -import org.screamingsandals.lib.player.PlayerMapper; import org.screamingsandals.lib.plugin.ServiceManager; +import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.utils.annotations.Service; @@ -251,7 +250,7 @@ public void remove(Player player) { player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); } if (SBAConfig.getInstance().node("main-lobby", "tablist-modifications").getBoolean()) { - PlayerMapper.wrapPlayer(player).sendPlayerListHeaderFooter(Component.empty(), Component.empty()); + Players.wrapPlayer(player).sendPlayerListHeaderFooter(Component.empty(), Component.empty()); } } @@ -266,10 +265,11 @@ public void onBedWarsPlayerLeaveEvent(BedwarsPlayerLeaveEvent e) { final var player = e.getPlayer(); if (!enabled) return; - Tasker.build(() -> { - if (isInWorld(player.getLocation()) && player.isOnline()) { - create(player); - } - }).delay(1L, TaskerTime.SECONDS); + // the Slib 2.0.2-SNAPSHOT version of the following code did not have the .start() call, therefore was never functional. Is it needed? +// Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { +// if (isInWorld(player.getLocation()) && player.isOnline()) { +// create(player); +// } +// }, 1L, TaskerTime.SECONDS); } } diff --git a/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicator2.java b/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicator2.java index 16a671a6..368c7b53 100644 --- a/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicator2.java +++ b/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicator2.java @@ -16,9 +16,9 @@ package org.screamingsandals.lib.healthindicator; +import org.screamingsandals.lib.player.Player; import org.screamingsandals.lib.spectator.Component; import org.screamingsandals.lib.spectator.ComponentLike; -import org.screamingsandals.lib.player.PlayerWrapper; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.visuals.DatableVisual; @@ -35,9 +35,9 @@ static HealthIndicator2 of() { HealthIndicator2 startUpdateTask(long time, TaskerTime unit); - HealthIndicator2 addTrackedPlayer(PlayerWrapper player); + HealthIndicator2 addTrackedPlayer(Player player); - HealthIndicator2 removeTrackedPlayer(PlayerWrapper player); + HealthIndicator2 removeTrackedPlayer(Player player); default HealthIndicator2 title(Component component) { return symbol(component); diff --git a/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorImpl2.java b/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorImpl2.java index 263582a3..0fa3fda1 100644 --- a/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorImpl2.java +++ b/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorImpl2.java @@ -19,17 +19,17 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import org.screamingsandals.lib.entity.HumanEntity; +import org.screamingsandals.lib.packet.ClientboundSetDisplayObjectivePacket; +import org.screamingsandals.lib.packet.ClientboundSetObjectivePacket; +import org.screamingsandals.lib.packet.ClientboundSetScorePacket; +import org.screamingsandals.lib.player.Player; import org.screamingsandals.lib.spectator.Component; import org.screamingsandals.lib.spectator.ComponentLike; -import org.screamingsandals.lib.entity.EntityHuman; import org.screamingsandals.lib.packet.AbstractPacket; -import org.screamingsandals.lib.packet.SClientboundSetDisplayObjectivePacket; -import org.screamingsandals.lib.packet.SClientboundSetObjectivePacket; -import org.screamingsandals.lib.packet.SClientboundSetScorePacket; -import org.screamingsandals.lib.player.PlayerWrapper; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; -import org.screamingsandals.lib.tasker.task.TaskerTask; +import org.screamingsandals.lib.tasker.task.Task; import org.screamingsandals.lib.utils.data.DataContainer; import org.screamingsandals.lib.visuals.UpdateStrategy; import org.screamingsandals.lib.visuals.impl.AbstractVisual; @@ -42,9 +42,9 @@ public class HealthIndicatorImpl2 extends AbstractVisual imple private final String underNameTagKey; private final String tabListKey; private final ConcurrentSkipListMap values = new ConcurrentSkipListMap<>(); - protected final List trackedPlayers = new LinkedList<>(); + protected final List trackedPlayers = new LinkedList<>(); + - @Accessors(chain = true, fluent = true) @Getter @Setter @@ -52,7 +52,7 @@ public class HealthIndicatorImpl2 extends AbstractVisual imple protected volatile boolean ready; protected volatile boolean healthInTabList; protected volatile Component symbol = Component.empty(); - protected TaskerTask task; + protected Task task; public HealthIndicatorImpl2(UUID uuid) { super(uuid); @@ -62,7 +62,7 @@ public HealthIndicatorImpl2(UUID uuid) { @Override - public HealthIndicator2 addTrackedPlayer(PlayerWrapper player) { + public HealthIndicator2 addTrackedPlayer(Player player) { if (!trackedPlayers.contains(player)) { trackedPlayers.add(player); if (visible && ready && task == null) { @@ -73,7 +73,7 @@ public HealthIndicator2 addTrackedPlayer(PlayerWrapper player) { } @Override - public HealthIndicator2 removeTrackedPlayer(PlayerWrapper player) { + public HealthIndicator2 removeTrackedPlayer(Player player) { if (trackedPlayers.contains(player)) { trackedPlayers.remove(player); if (visible && ready && task == null) { @@ -112,17 +112,18 @@ public boolean hasData() { return !data.isEmpty(); } - private static Function nameProvider; - public static void setNameProvider(Function nFunction) + private static Function nameProvider; + public static void setNameProvider(Function nFunction) { nameProvider = nFunction; } - private String getName(PlayerWrapper p) + private String getName(Player p) { if(nameProvider!=null) return nameProvider.apply(p); return p.getName(); } + @Override public HealthIndicator2 update(UpdateStrategy strategy) { if (ready) { @@ -132,9 +133,9 @@ public HealthIndicator2 update(UpdateStrategy strategy) { List.copyOf(values.keySet()).stream().filter(s -> trackedPlayers.stream().noneMatch(p -> getName(p).equals(s))).forEach(s -> { values.remove(s); - packets.add(getDestroyScorePacket(s).objectiveKey(underNameTagKey)); + packets.add(getDestroyScorePacket(s).objectiveKey(underNameTagKey).build()); if (healthInTabList) { - packets.add(getDestroyScorePacket(s).objectiveKey(tabListKey)); + packets.add(getDestroyScorePacket(s).objectiveKey(tabListKey).build()); } }); @@ -144,13 +145,13 @@ public HealthIndicator2 update(UpdateStrategy strategy) { return; } - var health = (int) Math.round(playerWrapper.as(EntityHuman.class).getHealth()); + var health = (int) Math.round(playerWrapper.as(HumanEntity.class).getHealth()); var key = getName(playerWrapper); if (!values.containsKey(key) || values.get(key) != health) { values.put(key, health); - packets.add(createScorePacket(key, health).objectiveKey(underNameTagKey)); + packets.add(createScorePacket(key, health).objectiveKey(underNameTagKey).build()); if (healthInTabList) { - packets.add(createScorePacket(key, health).objectiveKey(tabListKey)); + packets.add(createScorePacket(key, health).objectiveKey(tabListKey).build()); } } }); @@ -199,10 +200,7 @@ public HealthIndicator2 startUpdateTask(long time, TaskerTime unit) { task.cancel(); } - task = Tasker.build(() -> update()) - .async() - .repeat(time, unit) - .start(); + task = Tasker.runAsyncRepeatedly(() -> update(), time, unit); return this; } @@ -211,92 +209,100 @@ protected void updateSymbol0() { if (visible) { getUpdateObjectivePacket() .objectiveKey(underNameTagKey) + .build() .sendPacket(viewers); if (healthInTabList) { getUpdateObjectivePacket() .objectiveKey(tabListKey) + .build() .sendPacket(viewers); } } } @Override - public void onViewerAdded(PlayerWrapper player, boolean checkDistance) { + public void onViewerAdded(Player player, boolean checkDistance) { if (visible) { getCreateObjectivePacket() .objectiveKey(underNameTagKey) + .build() .sendPacket(player); - new SClientboundSetDisplayObjectivePacket() + ClientboundSetDisplayObjectivePacket.builder() .objectiveKey(underNameTagKey) - .slot(SClientboundSetDisplayObjectivePacket.DisplaySlot.BELOW_NAME) + .slot(ClientboundSetDisplayObjectivePacket.DisplaySlot.BELOW_NAME) + .build() .sendPacket(player); - values.forEach((s, integer) -> createScorePacket(s, integer).objectiveKey(underNameTagKey).sendPacket(player)); + values.forEach((s, integer) -> createScorePacket(s, integer).objectiveKey(underNameTagKey).build().sendPacket(player)); if (healthInTabList) { getCreateObjectivePacket() .objectiveKey(tabListKey) + .build() .sendPacket(player); - new SClientboundSetDisplayObjectivePacket() + ClientboundSetDisplayObjectivePacket.builder() .objectiveKey(tabListKey) - .slot(SClientboundSetDisplayObjectivePacket.DisplaySlot.PLAYER_LIST) + .slot(ClientboundSetDisplayObjectivePacket.DisplaySlot.PLAYER_LIST) + .build() .sendPacket(player); - values.forEach((s, integer) -> createScorePacket(s, integer).objectiveKey(tabListKey).sendPacket(player)); + values.forEach((s, integer) -> createScorePacket(s, integer).objectiveKey(tabListKey).build().sendPacket(player)); } } } @Override - public void onViewerRemoved(PlayerWrapper player, boolean checkDistance) { + public void onViewerRemoved(Player player, boolean checkDistance) { getDestroyObjectivePacket() .objectiveKey(underNameTagKey) + .build() .sendPacket(player); if (healthInTabList) { getDestroyObjectivePacket() .objectiveKey(tabListKey) + .build() .sendPacket(player); } } - private SClientboundSetObjectivePacket getNotFinalObjectivePacket() { - return new SClientboundSetObjectivePacket() + private ClientboundSetObjectivePacket.ClientboundSetObjectivePacketBuilder getNotFinalObjectivePacket() { + return ClientboundSetObjectivePacket.builder() .title(symbol.asComponent()) - .criteriaType(SClientboundSetObjectivePacket.Type.INTEGER); + .criteriaType(ClientboundSetObjectivePacket.Type.INTEGER); } - private SClientboundSetObjectivePacket getCreateObjectivePacket() { + private ClientboundSetObjectivePacket.ClientboundSetObjectivePacketBuilder getCreateObjectivePacket() { var packet = getNotFinalObjectivePacket(); - packet.mode(SClientboundSetObjectivePacket.Mode.CREATE); + packet.mode(ClientboundSetObjectivePacket.Mode.CREATE); return packet; } - private SClientboundSetObjectivePacket getUpdateObjectivePacket() { + private ClientboundSetObjectivePacket.ClientboundSetObjectivePacketBuilder getUpdateObjectivePacket() { var packet = getNotFinalObjectivePacket(); - packet.mode(SClientboundSetObjectivePacket.Mode.UPDATE); + packet.mode(ClientboundSetObjectivePacket.Mode.UPDATE); return packet; } - private SClientboundSetObjectivePacket getDestroyObjectivePacket() { - return new SClientboundSetObjectivePacket() - .mode(SClientboundSetObjectivePacket.Mode.DESTROY); + private ClientboundSetObjectivePacket.ClientboundSetObjectivePacketBuilder getDestroyObjectivePacket() { + return ClientboundSetObjectivePacket.builder() + .mode(ClientboundSetObjectivePacket.Mode.DESTROY); } - private SClientboundSetScorePacket createScorePacket(String key, int score) { - return new SClientboundSetScorePacket() + private ClientboundSetScorePacket.ClientboundSetScorePacketBuilder createScorePacket(String key, int score) { + return ClientboundSetScorePacket.builder() .entityName(key) .score(score) - .action(SClientboundSetScorePacket.ScoreboardAction.CHANGE); + .action(ClientboundSetScorePacket.ScoreboardAction.CHANGE); } - private SClientboundSetScorePacket getDestroyScorePacket(String key) { - return new SClientboundSetScorePacket() + private ClientboundSetScorePacket.ClientboundSetScorePacketBuilder getDestroyScorePacket(String key) { + return ClientboundSetScorePacket.builder() .entityName(key) - .action(SClientboundSetScorePacket.ScoreboardAction.REMOVE); + .action(ClientboundSetScorePacket.ScoreboardAction.REMOVE); } private static String generateObjectiveKey() { diff --git a/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorManager2.java b/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorManager2.java index 688bdaa5..a23a6295 100644 --- a/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorManager2.java +++ b/plugin/src/main/java/org/screamingsandals/lib/healthindicator/HealthIndicatorManager2.java @@ -19,9 +19,10 @@ import org.jetbrains.annotations.ApiStatus; import org.screamingsandals.lib.Core; import org.screamingsandals.lib.event.OnEvent; +import org.screamingsandals.lib.event.player.PlayerLeaveEvent; import org.screamingsandals.lib.packet.PacketMapper; -import org.screamingsandals.lib.event.player.SPlayerLeaveEvent; import org.screamingsandals.lib.utils.annotations.Service; +import org.screamingsandals.lib.utils.annotations.ServiceDependencies; import org.screamingsandals.lib.utils.annotations.methods.OnPreDisable; import org.screamingsandals.lib.visuals.Visual; @@ -30,7 +31,8 @@ import java.util.Optional; import java.util.UUID; -@Service(dependsOn = { +@Service +@ServiceDependencies(dependsOn = { Core.class, PacketMapper.class }) @@ -105,7 +107,7 @@ public void destroy() { } @OnEvent - public void onLeave(SPlayerLeaveEvent event) { + public void onLeave(PlayerLeaveEvent event) { if (activeIndicators.isEmpty()) { return; } diff --git a/plugin/src/main/java/sba/sl/n/accessors/AccessorUtils.java b/plugin/src/main/java/sba/sl/n/accessors/AccessorUtils.java deleted file mode 100644 index 09d44c82..00000000 --- a/plugin/src/main/java/sba/sl/n/accessors/AccessorUtils.java +++ /dev/null @@ -1,432 +0,0 @@ -package sba.sl.n.accessors; - -/* - * Copyright 2022 ScreamingSandals - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - import java.lang.reflect.Constructor; - import java.lang.reflect.Field; - import java.lang.reflect.Method; - import java.util.*; - import java.util.function.Consumer; - import java.util.regex.MatchResult; - import java.util.regex.Matcher; - import java.util.regex.Pattern; - - public class AccessorUtils { - private static final Map, Class> classCache = new HashMap<>(); - private static final Map, String>, Field> fieldCache = new HashMap<>(); - private static final Map, String>, Object> enumCache = new HashMap<>(); - private static final Map, String>, Method> methodCache = new HashMap<>(); - private static final Map, Integer>, Constructor> constructorCache = new HashMap<>(); - - private static int MAJOR_VERSION; - private static int MINOR_VERSION; - private static int PATCH_VERSION; - private static boolean availableMapping_SEARGE = false; - public static boolean isAvailableMapping_SEARGE() { - return availableMapping_SEARGE; - } - private static boolean availableMapping_SPIGOT = false; - public static boolean isAvailableMapping_SPIGOT() { - return availableMapping_SPIGOT; - } - private static String craftBukkitImpl = "v1_99_R9"; - - public static String getCraftBukkitImpl() { - return craftBukkitImpl; - } - - - static { - try { - Class mcForgeClass = Class.forName("net.minecraftforge.common.MinecraftForge"); - availableMapping_SEARGE = true; // auto-generated field - - String str; - try { - // Flattening versions - Class mcpVersionClass = Class.forName("net.minecraftforge.versions.mcp.MCPVersion"); - str = mcpVersionClass.getMethod("getMCVersion").invoke(null).toString(); - } catch (Throwable ignored) { - // Legacy versions - str = mcForgeClass.getField("MC_VERSION").get(null).toString(); - } - - if (str != null) { - int[] res = convertVersion(str); - MAJOR_VERSION = res[0]; - MINOR_VERSION = res[1]; - PATCH_VERSION = res[2]; - } - } catch (Throwable ignored) { - // probably not using MCP mappings - } - try { - Class bukkitClass = Class.forName("org.bukkit.Bukkit"); - Method method = bukkitClass.getMethod("getServer"); - if (MAJOR_VERSION == 0) { // we don't know version yet, this server don't implement forge - Pattern versionPattern = Pattern.compile("\\(MC: (\\d+)\\.(\\d+)\\.?(\\d+?)?"); - Matcher matcher = versionPattern.matcher(bukkitClass.getMethod("getVersion").invoke(null).toString()); - int majorVersion = 1; - int minorVersion = 0; - int patchVersion = 0; - if (matcher.find()) { - MatchResult matchResult = matcher.toMatchResult(); - try { - majorVersion = Integer.parseInt(matchResult.group(1), 10); - } catch (Exception ignored) { - } - try { - minorVersion = Integer.parseInt(matchResult.group(2), 10); - } catch (Exception ignored) { - } - if (matchResult.groupCount() >= 3) { - try { - patchVersion = Integer.parseInt(matchResult.group(3), 10); - } catch (Exception ignored) { - } - } - } - MAJOR_VERSION = majorVersion; - MINOR_VERSION = minorVersion; - PATCH_VERSION = patchVersion; - } - - String packName = method.invoke(null).getClass().getPackage().getName(); - craftBukkitImpl = packName.substring(packName.lastIndexOf('.') + 1); - availableMapping_SPIGOT = true; - } catch (Throwable ignored) { - // probably not CraftBukkit Based - } - - } - - - - public static Class getType(Class accessor, Consumer mapper) { - Class cache = classCache.get(accessor); - if (cache != null) { - return cache; - } - - AccessorMapper accessorMapper = new AccessorMapper(); - mapper.accept(accessorMapper); - - Map> map = accessorMapper.map; - - if (availableMapping_SEARGE) { - // getting the last mapping - String res = reduceMapping(map, "SEARGE"); - - if (res != null) { - // trying to use it - try { - Class clazz = Class.forName(res); - classCache.put(accessor, clazz); - return clazz; - } catch (Throwable ignored) { - } - } - } - if (availableMapping_SPIGOT) { - // getting the last mapping - String res = reduceMapping(map, "SPIGOT"); - - if (res != null) { - // trying to use it - try { - Class clazz = Class.forName(res); - classCache.put(accessor, clazz); - return clazz; - } catch (Throwable ignored) { - } - } - } - - - // cache that we don't have it - classCache.put(accessor, null); - return null; - } - - public static Field getField(Class accessor, String field, Consumer mapper) { - Map.Entry, String> kvholder = new AbstractMap.SimpleEntry<>(accessor, field); - if (fieldCache.containsKey(kvholder)) { - return fieldCache.get(kvholder); - } - - AccessorMapper accessorMapper = new AccessorMapper(); - mapper.accept(accessorMapper); - - Map> map = accessorMapper.map; - - if (availableMapping_SEARGE) { - // getting the last mapping - String res = reduceMapping(map, "SEARGE"); - - if (res != null) { - // trying to use it - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - Class clazz1 = clazz; - do { - try { - Field fieldC = clazz1.getDeclaredField(res); - fieldC.setAccessible(true); - fieldCache.put(kvholder, fieldC); - return fieldC; - } catch (Throwable ignored2) { - } - } while ((clazz1 = clazz1.getSuperclass()) != null && clazz1 != Object.class); - } catch (Throwable ignored) { - } - } - } - if (availableMapping_SPIGOT) { - // getting the last mapping - String res = reduceMapping(map, "SPIGOT"); - - if (res != null) { - // trying to use it - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - Class clazz1 = clazz; - do { - try { - Field fieldC = clazz1.getDeclaredField(res); - fieldC.setAccessible(true); - fieldCache.put(kvholder, fieldC); - return fieldC; - } catch (Throwable ignored2) { - } - } while ((clazz1 = clazz1.getSuperclass()) != null && clazz1 != Object.class); - } catch (Throwable ignored) { - } - } - } - - - // cache that we don't have it - fieldCache.put(kvholder, null); - return null; - } - - public static Object getEnumField(Class accessor, String field, Consumer mapper) { - Map.Entry, String> kvholder = new AbstractMap.SimpleEntry<>(accessor, field); - if (enumCache.containsKey(kvholder)) { - return enumCache.get(kvholder); - } - - AccessorMapper accessorMapper = new AccessorMapper(); - mapper.accept(accessorMapper); - - Map> map = accessorMapper.map; - - if (availableMapping_SEARGE) { - String res = reduceMapping(map, "SEARGE"); - - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - try { - Field fieldC = clazz.getDeclaredField(res); - fieldC.setAccessible(true); - - Object enumeration = fieldC.get(null); - enumCache.put(kvholder, enumeration); - return enumeration; - } catch (Throwable ignored2) { - } - } catch (Throwable ignored) {} - } - if (availableMapping_SPIGOT) { - String res = reduceMapping(map, "SPIGOT"); - - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - try { - Field fieldC = clazz.getDeclaredField(res); - fieldC.setAccessible(true); - - Object enumeration = fieldC.get(null); - enumCache.put(kvholder, enumeration); - return enumeration; - } catch (Throwable ignored2) { - } - } catch (Throwable ignored) {} - } - - - // cache that we don't have it - enumCache.put(kvholder, null); - return null; - } - - public static Method getMethod(Class accessor, String method, Consumer mapper, Class... params) { - Map.Entry, String> kvholder = new AbstractMap.SimpleEntry<>(accessor, method); - if (methodCache.containsKey(kvholder)) { - return methodCache.get(kvholder); - } - - AccessorMapper accessorMapper = new AccessorMapper(); - mapper.accept(accessorMapper); - - Map> map = accessorMapper.map; - - if (availableMapping_SEARGE) { - // getting the last mapping - String res = reduceMapping(map, "SEARGE"); - - if (res != null) { - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - Class clazz2 = clazz; - do { - try { - Method methodC = clazz2.getDeclaredMethod(res, params); - methodC.setAccessible(true); - methodCache.put(kvholder, methodC); - return methodC; - } catch (Throwable ignored2) { - } - } while ((clazz2 = clazz2.getSuperclass()) != null && clazz2 != Object.class); - } catch (Throwable ignored) { - } - } - } - if (availableMapping_SPIGOT) { - // getting the last mapping - String res = reduceMapping(map, "SPIGOT"); - - if (res != null) { - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - Class clazz2 = clazz; - do { - try { - Method methodC = clazz2.getDeclaredMethod(res, params); - methodC.setAccessible(true); - methodCache.put(kvholder, methodC); - return methodC; - } catch (Throwable ignored2) { - } - } while ((clazz2 = clazz2.getSuperclass()) != null && clazz2 != Object.class); - } catch (Throwable ignored) { - } - } - } - - - // cache that we don't have it - methodCache.put(kvholder, null); - return null; - } - - public static Constructor getConstructor(Class accessor, int constructor, Class... params) { - Map.Entry, Integer> kvholder = new AbstractMap.SimpleEntry<>(accessor, constructor); - if (constructorCache.containsKey(kvholder)) { - return constructorCache.get(kvholder); - } - - try { - Class clazz = (Class) accessor.getMethod("getType").invoke(null); - Constructor constructorC = clazz.getDeclaredConstructor(params); - constructorC.setAccessible(true); - constructorCache.put(kvholder, constructorC); - return constructorC; - } catch (Throwable ignored) { - } - - // cache that we don't have it - constructorCache.put(kvholder, null); - return null; - } - - public static boolean isVersion(int[] ver) { - return isVersion(ver[0], ver[1], ver[2]); - } - - public static boolean isVersion(int major, int minor, int patch) { - return MAJOR_VERSION > major || (MAJOR_VERSION >= major && (MINOR_VERSION > minor || (MINOR_VERSION >= minor && PATCH_VERSION >= patch))); - } - - public static int compare(int[] ver, int[] ver2) { - if (ver[0] != ver2[0]) { - return ver[0] - ver2[0]; - } - if (ver[1] != ver2[1]) { - return ver[1] - ver2[1]; - } - return ver[2] - ver2[2]; - } - - public static int[] convertVersion(String version) { - int[] result = new int[3]; - if (version != null) { - String[] split = version.split("\\."); - for (int i = 0; i < split.length; i++) { - if (i == 0) { - result[0] = Integer.parseInt(split[i]); - } else if (i == 1) { - result[1] = Integer.parseInt(split[i]); - } else if (i == 2) { - result[2] = Integer.parseInt(split[i]); - } - } - } - return result; - } - - public static String reduceMapping(Map> map, String mapping) { - Optional opt = Optional.ofNullable(map.get(mapping)) - .flatMap(m -> m.entrySet() - .stream() - .filter(entry -> isVersion(entry.getKey())) - .sorted((o1, o2) -> compare(o1.getKey(), o2.getKey())) - .reduce((first, second) -> second) - .map(Map.Entry::getValue) - ); - if (opt.isPresent()) { - return opt.get(); - } else { - return null; - } - } - - public static class AccessorMapper { - private final Map> map = new HashMap<>(); - - public AccessorMapper map(String mappingType, String minVersion, String symbol) { - if (!map.containsKey(mappingType)) { - map.put(mappingType, new HashMap<>()); - } - if (mappingType.equals("SPIGOT")) { - symbol = symbol.replace("${V}", craftBukkitImpl); - } - - Map map2 = map.get(mappingType); - map2.put(convertVersion(minVersion), symbol); - return this; - } - } - - public static Class getOrCatch(String name) { - try { - return Class.forName(name); - } catch (ClassNotFoundException ex) { - return null; - } - } - } \ No newline at end of file