From 3bbabcad21038416d848fb2162ebd8222c4f4e58 Mon Sep 17 00:00:00 2001 From: Wanbin Cao <93872019+Lagggpixel@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:00:46 +0100 Subject: [PATCH] #patch API revamp and bug fixes (#75) * Bump version from 2.0.7 to 2.0.7-SNAPSHOT0 * feat: API rework compatibility * fix: clean up code * Bump version from 2.0.7-SNAPSHOT0 to 2.0.7-SNAPSHOT1 --------- Co-authored-by: version-bump[github-action] <41898282+version-bump[github-action]@users.noreply.github.com> --- build.gradle.kts | 8 +- .../plugily/projects/murdermystery/Main.java | 16 +-- .../game/MurderGameCorpseSpawnEvent.java | 2 +- .../projects/murdermystery/arena/Arena.java | 36 +++--- .../murdermystery/arena/ArenaEvents.java | 59 ++++----- .../murdermystery/arena/ArenaManager.java | 22 ++-- .../murdermystery/arena/ArenaRegistry.java | 7 +- .../murdermystery/arena/ArenaUtils.java | 16 +-- .../arena/managers/ScoreboardManager.java | 10 +- .../murdermystery/arena/role/Role.java | 8 +- .../arena/special/SpecialBlockEvents.java | 13 +- .../arena/special/pray/PrayerRegistry.java | 9 +- .../arena/states/InGameState.java | 6 +- .../arena/states/StartingState.java | 9 +- .../boot/AdditionalValueInitializer.java | 4 +- .../boot/PlaceholderInitializer.java | 48 +++---- .../arguments/admin/RolePassArgument.java | 6 +- .../arena/SpecialBlockRemoverArgument.java | 122 +++++++++--------- .../arguments/game/RoleSelectorArgument.java | 7 +- .../murdermystery/events/PluginEvents.java | 10 +- .../murdermystery/utils/ItemPosition.java | 5 +- 21 files changed, 205 insertions(+), 218 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c7d2dbb7..9862a7ea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,15 +17,15 @@ repositories { } dependencies { - implementation("plugily.projects:MiniGamesBox-Classic:1.3.8") { isTransitive = false } - compileOnly("org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT") - compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT") + implementation("plugily.projects:MiniGamesBox-Classic:1.3.9") { isTransitive = false } + compileOnly("org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:24.0.1") compileOnly(files("lib/CorpseReborn.jar")) } group = "plugily.projects" -version = "2.0.7" +version = "2.0.7-SNAPSHOT1" description = "MurderMystery" java { diff --git a/src/main/java/plugily/projects/murdermystery/Main.java b/src/main/java/plugily/projects/murdermystery/Main.java index da9345cf..ebf313d2 100644 --- a/src/main/java/plugily/projects/murdermystery/Main.java +++ b/src/main/java/plugily/projects/murdermystery/Main.java @@ -18,18 +18,12 @@ package plugily.projects.murdermystery; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.java.JavaPluginLoader; import org.jetbrains.annotations.TestOnly; import plugily.projects.minigamesbox.classic.PluginMain; import plugily.projects.minigamesbox.classic.handlers.setup.SetupInventory; import plugily.projects.minigamesbox.classic.handlers.setup.categories.PluginSetupCategoryManager; import plugily.projects.minigamesbox.classic.utils.services.metrics.Metrics; -import plugily.projects.murdermystery.arena.Arena; -import plugily.projects.murdermystery.arena.ArenaEvents; -import plugily.projects.murdermystery.arena.ArenaManager; -import plugily.projects.murdermystery.arena.ArenaRegistry; -import plugily.projects.murdermystery.arena.ArenaUtils; +import plugily.projects.murdermystery.arena.*; import plugily.projects.murdermystery.arena.special.SpecialBlockEvents; import plugily.projects.murdermystery.arena.special.mysterypotion.MysteryPotionRegistry; import plugily.projects.murdermystery.arena.special.pray.PrayerRegistry; @@ -45,8 +39,6 @@ import plugily.projects.murdermystery.handlers.trails.BowTrailsHandler; import plugily.projects.murdermystery.handlers.trails.TrailsManager; -import java.io.File; - /** * Created by Tigerpanzer_02 on 13.03.2022 */ @@ -65,12 +57,6 @@ public Main() { super(); } - @TestOnly - protected Main( - JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { - super(loader, description, dataFolder, file); - } - @Override public void onEnable() { long start = System.currentTimeMillis(); diff --git a/src/main/java/plugily/projects/murdermystery/api/events/game/MurderGameCorpseSpawnEvent.java b/src/main/java/plugily/projects/murdermystery/api/events/game/MurderGameCorpseSpawnEvent.java index 9763807d..80006d08 100644 --- a/src/main/java/plugily/projects/murdermystery/api/events/game/MurderGameCorpseSpawnEvent.java +++ b/src/main/java/plugily/projects/murdermystery/api/events/game/MurderGameCorpseSpawnEvent.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import plugily.projects.minigamesbox.classic.api.event.PlugilyEvent; +import plugily.projects.minigamesbox.api.events.PlugilyEvent; import plugily.projects.murdermystery.arena.Arena; /** diff --git a/src/main/java/plugily/projects/murdermystery/arena/Arena.java b/src/main/java/plugily/projects/murdermystery/arena/Arena.java index 3d3f7e85..ebba6e04 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/Arena.java +++ b/src/main/java/plugily/projects/murdermystery/arena/Arena.java @@ -25,24 +25,24 @@ import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import plugily.projects.minigamesbox.classic.arena.ArenaState; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArena; import plugily.projects.minigamesbox.classic.arena.managers.PluginMapRestorerManager; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.hologram.ArmorStandHologram; import plugily.projects.minigamesbox.classic.utils.version.VersionUtils; +import plugily.projects.murdermystery.HookManager; import plugily.projects.murdermystery.Main; import plugily.projects.murdermystery.arena.corpse.Corpse; import plugily.projects.murdermystery.arena.corpse.Stand; import plugily.projects.murdermystery.arena.managers.MapRestorerManager; import plugily.projects.murdermystery.arena.managers.ScoreboardManager; import plugily.projects.murdermystery.arena.role.Role; +import plugily.projects.murdermystery.arena.special.SpecialBlock; import plugily.projects.murdermystery.arena.states.InGameState; import plugily.projects.murdermystery.arena.states.RestartingState; import plugily.projects.murdermystery.arena.states.StartingState; -import plugily.projects.murdermystery.HookManager; -import plugily.projects.murdermystery.arena.special.SpecialBlock; import plugily.projects.murdermystery.arena.states.WaitingState; import java.util.*; @@ -73,7 +73,7 @@ public class Arena extends PluginArena { private boolean hideChances; private boolean goldVisuals = false; private final Map gameCharacters = new EnumMap<>(CharacterType.class); - private MapRestorerManager mapRestorerManager; + private final MapRestorerManager mapRestorerManager; private ArmorStandHologram bowHologram; public Arena(String id) { @@ -82,10 +82,10 @@ public Arena(String id) { setScoreboardManager(new ScoreboardManager(this)); mapRestorerManager = new MapRestorerManager(this); setMapRestorerManager(mapRestorerManager); - addGameStateHandler(ArenaState.IN_GAME, new InGameState()); - addGameStateHandler(ArenaState.RESTARTING, new RestartingState()); - addGameStateHandler(ArenaState.STARTING, new StartingState()); - addGameStateHandler(ArenaState.WAITING_FOR_PLAYERS, new WaitingState()); + addGameStateHandler(IArenaState.IN_GAME, new InGameState()); + addGameStateHandler(IArenaState.RESTARTING, new RestartingState()); + addGameStateHandler(IArenaState.STARTING, new StartingState()); + addGameStateHandler(IArenaState.WAITING_FOR_PLAYERS, new WaitingState()); } public static void init(Main plugin) { @@ -178,7 +178,7 @@ public void startGoldVisuals() { return; } visualTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> { - if(!goldVisuals || !plugin.isEnabled() || goldSpawnPoints.isEmpty() || getArenaState() != ArenaState.WAITING_FOR_PLAYERS) { + if(!goldVisuals || !plugin.isEnabled() || goldSpawnPoints.isEmpty() || getArenaState() != IArenaState.WAITING_FOR_PLAYERS) { //we need to cancel it that way as the arena class is an task visualTask.cancel(); return; @@ -234,7 +234,7 @@ public int getTotalRoleChances(Role role) { int totalRoleChances = 0; for(Player p : getPlayers()) { - User user = getPlugin().getUserManager().getUser(p); + IUser user = getPlugin().getUserManager().getUser(p); totalRoleChances += getContributorValue(role, user); } //avoid division / 0 @@ -387,22 +387,22 @@ public void setPlayerSpawnPoints(@NotNull List playerSpawnPoints) { this.playerSpawnPoints = playerSpawnPoints; } - public void adjustContributorValue(Role role, User user, int number) { + public void adjustContributorValue(Role role, IUser user, int number) { user.adjustStatistic("CONTRIBUTION_" + role.name(), number); } - private Map murdererContributions = new HashMap<>(); - private Map detectiveContributions = new HashMap<>(); + private final Map murdererContributions = new HashMap<>(); + private final Map detectiveContributions = new HashMap<>(); - public Map getMurdererContributions() { + public Map getMurdererContributions() { return murdererContributions; } - public Map getDetectiveContributions() { + public Map getDetectiveContributions() { return detectiveContributions; } - public int getContributorValue(Role role, User user) { + public int getContributorValue(Role role, IUser user) { if(role == Role.MURDERER && murdererContributions.containsKey(user)) { return murdererContributions.get(user); } else if(detectiveContributions.containsKey(user)) { @@ -421,7 +421,7 @@ public int getContributorValue(Role role, User user) { return calculatedContributor; } - public void resetContributorValue(Role role, User user) { + public void resetContributorValue(Role role, IUser user) { user.setStatistic("CONTRIBUTION_" + role.name(), 1); } diff --git a/src/main/java/plugily/projects/murdermystery/arena/ArenaEvents.java b/src/main/java/plugily/projects/murdermystery/arena/ArenaEvents.java index 1c8aef4e..c8b0b9dc 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/ArenaEvents.java +++ b/src/main/java/plugily/projects/murdermystery/arena/ArenaEvents.java @@ -21,7 +21,6 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -40,14 +39,13 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.spigotmc.event.entity.EntityDismountEvent; -import plugily.projects.minigamesbox.classic.arena.ArenaState; -import plugily.projects.minigamesbox.classic.arena.PluginArena; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.arena.IPluginArena; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArenaEvents; import plugily.projects.minigamesbox.classic.handlers.items.SpecialItem; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; import plugily.projects.minigamesbox.classic.handlers.language.TitleBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.misc.complement.ComplementAccessor; import plugily.projects.minigamesbox.classic.utils.version.ServerVersion; import plugily.projects.minigamesbox.classic.utils.version.VersionUtils; @@ -75,13 +73,13 @@ public ArenaEvents(Main plugin) { } @Override - public void handleIngameVoidDeath(Player victim, PluginArena arena) { + public void handleIngameVoidDeath(Player victim, IPluginArena arena) { Arena pluginArena = plugin.getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return; } victim.damage(1000.0); - if(arena.getArenaState() == ArenaState.IN_GAME) { + if(arena.getArenaState() == IArenaState.IN_GAME) { VersionUtils.teleport(victim, pluginArena.getPlayerSpawnPoints().get(0)); } } @@ -92,7 +90,7 @@ public void onBowShot(EntityShootBowEvent event) { return; } Player player = (Player) event.getEntity(); - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); if(!Role.isRole(Role.ANY_DETECTIVE, user)) { return; } @@ -127,7 +125,7 @@ public void onItemPickup(PlugilyEntityPickupItemEvent e) { if(arena == null) { return; } - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); e.setCancelled(true); if(arena.getBowHologram() != null && e.getItem().equals(arena.getBowHologram().getEntityItem())) { @@ -138,7 +136,7 @@ public void onItemPickup(PlugilyEntityPickupItemEvent e) { e.getItem().remove(); for(Player loopPlayer : arena.getPlayersLeft()) { - User loopUser = plugin.getUserManager().getUser(loopPlayer); + IUser loopUser = plugin.getUserManager().getUser(loopPlayer); if(Role.isRole(Role.INNOCENT, loopUser)) { ItemPosition.setItem(loopUser, ItemPosition.BOW_LOCATOR, new ItemStack(Material.AIR, 1)); } @@ -157,7 +155,7 @@ public void onItemPickup(PlugilyEntityPickupItemEvent e) { return; } - if(user.isSpectator() || arena.getArenaState() != ArenaState.IN_GAME) { + if(user.isSpectator() || arena.getArenaState() != IArenaState.IN_GAME) { return; } @@ -215,9 +213,9 @@ public void onMurdererDamage(EntityDamageByEntityEvent e) { return; } Player attacker = (Player) e.getDamager(); - User userAttacker = plugin.getUserManager().getUser(attacker); + IUser userAttacker = plugin.getUserManager().getUser(attacker); Player victim = (Player) e.getEntity(); - User userVictim = plugin.getUserManager().getUser(victim); + IUser userVictim = plugin.getUserManager().getUser(victim); if(!ArenaUtils.areInSameArena(attacker, victim)) { return; } @@ -256,10 +254,10 @@ public void onMurdererDamage(EntityDamageByEntityEvent e) { plugin.getRewardsHandler().performReward(attacker, plugin.getRewardsHandler().getRewardType("KILL_DETECTIVE")); } - XSound.ENTITY_PLAYER_DEATH.play(victim.getLocation(), 50, 1); + XSound.ENTITY_PLAYER_DEATH.play(victim.getLocation()); victim.damage(100.0); - User user = plugin.getUserManager().getUser(attacker); + IUser user = plugin.getUserManager().getUser(attacker); user.adjustStatistic("KILLS", 1); user.adjustStatistic("LOCAL_KILLS", 1); @@ -286,7 +284,7 @@ public void onArrowDamage(EntityDamageByEntityEvent e) { return; } Player attacker = (Player) ((Arrow) e.getDamager()).getShooter(); - User userAttacker = plugin.getUserManager().getUser(attacker); + IUser userAttacker = plugin.getUserManager().getUser(attacker); if(plugin.getArenaRegistry().isInArena(attacker)) { e.setCancelled(true); e.getDamager().remove(); @@ -295,7 +293,7 @@ public void onArrowDamage(EntityDamageByEntityEvent e) { return; } Player victim = (Player) e.getEntity(); - User userVictim = plugin.getUserManager().getUser(victim); + IUser userVictim = plugin.getUserManager().getUser(victim); if(!ArenaUtils.areInSameArena(attacker, victim)) { return; } @@ -310,11 +308,14 @@ public void onArrowDamage(EntityDamageByEntityEvent e) { return; } Arena arena = plugin.getArenaRegistry().getArena(attacker); + if (arena == null) { + return; + } //we need to set it before the victim die, because of hero character if(Role.isRole(Role.MURDERER, userVictim)) { arena.setCharacter(Arena.CharacterType.HERO, attacker); } - XSound.ENTITY_PLAYER_DEATH.play(victim.getLocation(), 50, 1); + XSound.ENTITY_PLAYER_DEATH.play(victim.getLocation()); victim.damage(100.0); @@ -362,15 +363,15 @@ public void onPlayerDie(PlayerDeathEvent e) { if(arena == null) { return; } - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); ComplementAccessor.getComplement().setDeathMessage(e, ""); e.getDrops().clear(); e.setDroppedExp(0); plugin.getCorpseHandler().spawnCorpse(player, arena); player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 3 * 20, 0)); - if(arena.getArenaState() == ArenaState.STARTING) { + if(arena.getArenaState() == IArenaState.STARTING) { return; - } else if(arena.getArenaState() == ArenaState.ENDING || arena.getArenaState() == ArenaState.RESTARTING) { + } else if(arena.getArenaState() == IArenaState.ENDING || arena.getArenaState() == IArenaState.RESTARTING) { player.getInventory().clear(); player.setFlying(false); player.setAllowFlight(false); @@ -400,7 +401,7 @@ public void onPlayerDie(PlayerDeathEvent e) { new MessageBuilder(MessageBuilder.ActionType.DEATH).player(player).arena(arena).sendArena(); } - if(arena.getArenaState() != ArenaState.ENDING && arena.getArenaState() != ArenaState.RESTARTING) { + if(arena.getArenaState() != IArenaState.ENDING && arena.getArenaState() != IArenaState.RESTARTING) { arena.addDeathPlayer(player); } //we must call it ticks later due to instant respawn bug @@ -417,16 +418,16 @@ public void onRespawn(PlayerRespawnEvent event) { if(arena == null) { return; } - if(arena.getArenaState() == ArenaState.STARTING || arena.getArenaState() == ArenaState.WAITING_FOR_PLAYERS) { + if(arena.getArenaState() == IArenaState.STARTING || arena.getArenaState() == IArenaState.WAITING_FOR_PLAYERS) { event.setRespawnLocation(arena.getLobbyLocation()); return; } - if(arena.getArenaState() == ArenaState.RESTARTING) { + if(arena.getArenaState() == IArenaState.RESTARTING) { event.setRespawnLocation(arena.getEndLocation()); return; } if(arena.getPlayers().contains(player)) { - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); org.bukkit.Location firstSpawn = arena.getPlayerSpawnPoints().get(0); if(player.getLocation().getWorld().equals(firstSpawn.getWorld())) { @@ -454,12 +455,12 @@ public void locatorDistanceUpdate(PlayerMoveEvent event) { if(arena == null) { return; } - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); //skip spectators if(user.isSpectator()) { return; } - if(arena.getArenaState() == ArenaState.IN_GAME) { + if(arena.getArenaState() == IArenaState.IN_GAME) { if(Role.isRole(Role.INNOCENT, user, arena)) { if(player.getInventory().getItem(ItemPosition.BOW_LOCATOR.getOtherRolesItemPosition()) != null) { ItemStack bowLocator = new ItemStack(Material.COMPASS, 1); @@ -475,7 +476,7 @@ public void locatorDistanceUpdate(PlayerMoveEvent event) { ItemMeta innocentMeta = innocentLocator.getItemMeta(); for(Player p : arena.getPlayersLeft()) { Arena playerArena = plugin.getArenaRegistry().getArena(p); - User playerUser = plugin.getUserManager().getUser(p); + IUser playerUser = plugin.getUserManager().getUser(p); if(Role.isRole(Role.INNOCENT, playerUser, playerArena) || Role.isRole(Role.ANY_DETECTIVE, playerUser, playerArena)) { ComplementAccessor.getComplement().setDisplayName(innocentMeta, new MessageBuilder("IN_GAME_MESSAGES_ARENA_LOCATOR_INNOCENT").asKey().player(player).arena(arena).build() + " §7| §a" + (int) Math.round(player.getLocation().distance(p.getLocation()))); @@ -489,7 +490,7 @@ public void locatorDistanceUpdate(PlayerMoveEvent event) { @EventHandler public void onDrop(PlayerDropItemEvent event) { - if(plugin.getArenaRegistry().getArena(event.getPlayer()) != null && plugin.getArenaRegistry().getArena(event.getPlayer()).getArenaState() == ArenaState.IN_GAME) { + if(plugin.getArenaRegistry().getArena(event.getPlayer()) != null && plugin.getArenaRegistry().getArena(event.getPlayer()).getArenaState() == IArenaState.IN_GAME) { event.setCancelled(true); } } diff --git a/src/main/java/plugily/projects/murdermystery/arena/ArenaManager.java b/src/main/java/plugily/projects/murdermystery/arena/ArenaManager.java index a27d8d02..478fc43e 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/ArenaManager.java +++ b/src/main/java/plugily/projects/murdermystery/arena/ArenaManager.java @@ -20,11 +20,11 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import plugily.projects.minigamesbox.classic.arena.ArenaState; -import plugily.projects.minigamesbox.classic.arena.PluginArena; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.arena.IPluginArena; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArenaManager; import plugily.projects.minigamesbox.classic.handlers.language.TitleBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.murdermystery.Main; import plugily.projects.murdermystery.arena.managers.MapRestorerManager; import plugily.projects.murdermystery.arena.role.Role; @@ -49,7 +49,7 @@ public ArenaManager(Main plugin) { } @Override - public void joinAttempt(@NotNull Player player, @NotNull PluginArena arena) { + public void joinAttempt(@NotNull Player player, @NotNull IPluginArena arena) { Arena pluginArena = (Arena) plugin.getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return; @@ -59,7 +59,7 @@ public void joinAttempt(@NotNull Player player, @NotNull PluginArena arena) { } @Override - public void leaveAttempt(@NotNull Player player, @NotNull PluginArena arena) { + public void leaveAttempt(@NotNull Player player, @NotNull IPluginArena arena) { Arena pluginArena = (Arena) plugin.getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return; @@ -68,7 +68,7 @@ public void leaveAttempt(@NotNull Player player, @NotNull PluginArena arena) { if(pluginArena.isDeathPlayer(player)) { pluginArena.removeDeathPlayer(player); } - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); int localScore = user.getStatistic("LOCAL_SCORE"); if(localScore > user.getStatistic("HIGHEST_SCORE")) { @@ -80,7 +80,7 @@ public void leaveAttempt(@NotNull Player player, @NotNull PluginArena arena) { pluginArena.removeFromMurdererList(player); } - if(arena.getArenaState() == ArenaState.IN_GAME && !user.isSpectator()) { + if(arena.getArenaState() == IArenaState.IN_GAME && !user.isSpectator()) { List playersLeft = arena.getPlayersLeft(); // -1 cause we didn't remove player yet @@ -89,7 +89,7 @@ public void leaveAttempt(@NotNull Player player, @NotNull PluginArena arena) { if(pluginArena.getMurdererList().isEmpty()) { List players = new ArrayList<>(); for(Player gamePlayer : playersLeft) { - User userGamePlayer = plugin.getUserManager().getUser(gamePlayer); + IUser userGamePlayer = plugin.getUserManager().getUser(gamePlayer); if(gamePlayer == player || Role.isRole(Role.ANY_DETECTIVE, userGamePlayer, arena) || Role.isRole(Role.MURDERER, userGamePlayer, arena)) { continue; } @@ -127,7 +127,7 @@ public void leaveAttempt(@NotNull Player player, @NotNull PluginArena arena) { } @Override - public void stopGame(boolean quickStop, @NotNull PluginArena arena) { + public void stopGame(boolean quickStop, @NotNull IPluginArena arena) { Arena pluginArena = (Arena) plugin.getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return; @@ -141,8 +141,8 @@ public void stopGame(boolean quickStop, @NotNull PluginArena arena) { boolean murderWon = arena.getPlayersLeft().size() == pluginArena.aliveMurderer(); for(Player player : arena.getPlayers()) { if(!quickStop) { - User user = plugin.getUserManager().getUser(player); - if(!quickStop && Role.isAnyRole(user, arena)) { + IUser user = plugin.getUserManager().getUser(player); + if(Role.isAnyRole(user, arena)) { boolean hasDeathRole = Role.isRole(Role.DEATH, user, arena); int multiplicator = 1; if(!hasDeathRole) { diff --git a/src/main/java/plugily/projects/murdermystery/arena/ArenaRegistry.java b/src/main/java/plugily/projects/murdermystery/arena/ArenaRegistry.java index 47e0e097..caa9a4b3 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/ArenaRegistry.java +++ b/src/main/java/plugily/projects/murdermystery/arena/ArenaRegistry.java @@ -23,6 +23,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import plugily.projects.minigamesbox.api.arena.IPluginArena; import plugily.projects.minigamesbox.classic.arena.PluginArena; import plugily.projects.minigamesbox.classic.arena.PluginArenaRegistry; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; @@ -100,7 +101,7 @@ public boolean additionalValidatorChecks(ConfigurationSection section, PluginAre @Override public @Nullable Arena getArena(Player player) { - PluginArena pluginArena = super.getArena(player); + IPluginArena pluginArena = super.getArena(player); if(pluginArena instanceof Arena) { return (Arena) pluginArena; } @@ -109,7 +110,7 @@ public boolean additionalValidatorChecks(ConfigurationSection section, PluginAre @Override public @Nullable Arena getArena(String id) { - PluginArena pluginArena = super.getArena(id); + IPluginArena pluginArena = super.getArena(id); if(pluginArena instanceof Arena) { return (Arena) pluginArena; } @@ -118,7 +119,7 @@ public boolean additionalValidatorChecks(ConfigurationSection section, PluginAre public @NotNull List getPluginArenas() { List arenas = new ArrayList<>(); - for(PluginArena pluginArena : super.getArenas()) { + for(IPluginArena pluginArena : super.getArenas()) { if(pluginArena instanceof Arena) { arenas.add((Arena) pluginArena); } diff --git a/src/main/java/plugily/projects/murdermystery/arena/ArenaUtils.java b/src/main/java/plugily/projects/murdermystery/arena/ArenaUtils.java index 29708eac..1caa5a5f 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/ArenaUtils.java +++ b/src/main/java/plugily/projects/murdermystery/arena/ArenaUtils.java @@ -24,12 +24,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import plugily.projects.minigamesbox.classic.arena.ArenaState; -import plugily.projects.minigamesbox.classic.arena.PluginArena; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.arena.IPluginArena; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArenaUtils; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; import plugily.projects.minigamesbox.classic.handlers.language.TitleBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.hologram.ArmorStandHologram; import plugily.projects.minigamesbox.classic.utils.misc.complement.ComplementAccessor; import plugily.projects.minigamesbox.classic.utils.version.VersionUtils; @@ -50,7 +50,7 @@ private ArenaUtils() { public static void onMurdererDeath(Arena arena) { for(Player player : arena.getPlayers()) { VersionUtils.sendSubTitle(player, getPlugin().getLanguageManager().getLanguageMessage("In-Game.Messages.Game-End.Placeholders.Murderer.Stopped"), 5, 40, 5); - User loopUser = getPlugin().getUserManager().getUser(player); + IUser loopUser = getPlugin().getUserManager().getUser(player); if(Role.isRole(Role.INNOCENT, loopUser, arena)) { addScore(loopUser, ScoreAction.SURVIVE_GAME, 0); } else if(Role.isRole(Role.ANY_DETECTIVE, loopUser, arena)) { @@ -126,7 +126,7 @@ private static void addBowLocator(Arena arena, Location loc) { bowMeta, new MessageBuilder("IN_GAME_MESSAGES_ARENA_LOCATOR_BOW").asKey().build()); bowLocator.setItemMeta(bowMeta); for(Player p : arena.getPlayersLeft()) { - User user = getPlugin().getUserManager().getUser(p); + IUser user = getPlugin().getUserManager().getUser(p); if(Role.isRole(Role.INNOCENT, user, arena)) { ItemPosition.setItem(user, ItemPosition.BOW_LOCATOR, bowLocator); p.setCompassTarget(loc); @@ -139,16 +139,16 @@ public static void updateNameTagsVisibility(final Player p) { return; } for(Player players : getPlugin().getServer().getOnlinePlayers()) { - PluginArena arena = getPlugin().getArenaRegistry().getArena(players); + IPluginArena arena = getPlugin().getArenaRegistry().getArena(players); if(arena == null) { continue; } VersionUtils.updateNameTagsVisibility( - p, players, "MMHide", arena.getArenaState() != ArenaState.IN_GAME); + p, players, "MMHide", arena.getArenaState() != IArenaState.IN_GAME); } } - public static void addScore(User user, ScoreAction action, int amount) { + public static void addScore(IUser user, ScoreAction action, int amount) { XSound.matchXSound(XSound.ENTITY_EXPERIENCE_ORB_PICKUP.parseSound()) .play(user.getPlayer().getLocation(), 1F, 2F); diff --git a/src/main/java/plugily/projects/murdermystery/arena/managers/ScoreboardManager.java b/src/main/java/plugily/projects/murdermystery/arena/managers/ScoreboardManager.java index 52208f4b..9d6f0737 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/managers/ScoreboardManager.java +++ b/src/main/java/plugily/projects/murdermystery/arena/managers/ScoreboardManager.java @@ -18,11 +18,11 @@ package plugily.projects.murdermystery.arena.managers; -import plugily.projects.minigamesbox.classic.arena.ArenaState; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArena; import plugily.projects.minigamesbox.classic.arena.managers.PluginScoreboardManager; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.scoreboard.common.EntryBuilder; import plugily.projects.minigamesbox.classic.utils.scoreboard.type.Entry; import plugily.projects.murdermystery.arena.role.Role; @@ -43,16 +43,16 @@ public ScoreboardManager(PluginArena arena) { } @Override - public List formatScoreboard(User user) { + public List formatScoreboard(IUser user) { EntryBuilder builder = new EntryBuilder(); List lines; - if(user.getArena().getArenaState() == ArenaState.FULL_GAME) { + if(user.getArena().getArenaState() == IArenaState.FULL_GAME) { lines = user.getArena() .getPlugin() .getLanguageManager() .getLanguageList("Scoreboard.Content.Starting"); - } else if(user.getArena().getArenaState() == ArenaState.IN_GAME) { + } else if(user.getArena().getArenaState() == IArenaState.IN_GAME) { lines = user.getArena() .getPlugin() diff --git a/src/main/java/plugily/projects/murdermystery/arena/role/Role.java b/src/main/java/plugily/projects/murdermystery/arena/role/Role.java index 6cc7284b..a7fcd5bc 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/role/Role.java +++ b/src/main/java/plugily/projects/murdermystery/arena/role/Role.java @@ -19,6 +19,8 @@ package plugily.projects.murdermystery.arena.role; import org.bukkit.entity.Player; +import plugily.projects.minigamesbox.api.arena.IPluginArena; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArena; import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.murdermystery.arena.Arena; @@ -67,7 +69,7 @@ public enum Role { * @param user player to check * @return true if is playing it, false otherwise */ - public static boolean isRole(Role role, User user) { + public static boolean isRole(Role role, IUser user) { return isRole(role, user, user.getArena()); } @@ -79,7 +81,7 @@ public static boolean isRole(Role role, User user) { * @param arena the arena where to check * @return true if is playing it, false otherwise */ - public static boolean isRole(Role role, User user, PluginArena arena) { + public static boolean isRole(Role role, IUser user, IPluginArena arena) { if(arena == null) return false; Arena pluginArena = (Arena) arena.getPlugin().getArenaRegistry().getArena(arena.getId()); @@ -126,7 +128,7 @@ public static boolean isAnyRole(User user) { * @param arena the player's arena * @return true if is playing one role, false otherwise */ - public static boolean isAnyRole(User user, PluginArena arena) { + public static boolean isAnyRole(IUser user, IPluginArena arena) { return arena != null && java.util.Arrays.stream(roles).anyMatch(role -> isRole(role, user, arena)); } } diff --git a/src/main/java/plugily/projects/murdermystery/arena/special/SpecialBlockEvents.java b/src/main/java/plugily/projects/murdermystery/arena/special/SpecialBlockEvents.java index b2e14194..5361ae9f 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/special/SpecialBlockEvents.java +++ b/src/main/java/plugily/projects/murdermystery/arena/special/SpecialBlockEvents.java @@ -26,7 +26,8 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.inventory.ItemStack; -import plugily.projects.minigamesbox.classic.arena.ArenaState; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.helper.ItemBuilder; @@ -71,7 +72,7 @@ public void onSpecialBlockClick(PlayerInteractEvent event) { return; } - if(arena.getArenaState() != ArenaState.IN_GAME || plugin.getUserManager().getUser(event.getPlayer()).isSpectator()) { + if(arena.getArenaState() != IArenaState.IN_GAME || plugin.getUserManager().getUser(event.getPlayer()).isSpectator()) { return; } @@ -108,7 +109,7 @@ private void onCauldronClick(PlayerInteractEvent event) { return; } - User user = plugin.getUserManager().getUser(event.getPlayer()); + IUser user = plugin.getUserManager().getUser(event.getPlayer()); int localGold = user.getStatistic("LOCAL_GOLD"); if(localGold < 1) { @@ -134,7 +135,7 @@ private void onPrayerClick(PlayerInteractEvent event) { event.setCancelled(true); - User user = plugin.getUserManager().getUser(event.getPlayer()); + IUser user = plugin.getUserManager().getUser(event.getPlayer()); int localGold = user.getStatistic("LOCAL_GOLD"); if(localGold < 1) { @@ -149,7 +150,7 @@ private void onPrayerClick(PlayerInteractEvent event) { } private void onPrayLeverClick(PlayerInteractEvent event) { - User user = plugin.getUserManager().getUser(event.getPlayer()); + IUser user = plugin.getUserManager().getUser(event.getPlayer()); if(user.getStatistic("LOCAL_PRAISES") < 1) { new MessageBuilder("IN_GAME_MESSAGES_ARENA_PLAYING_SPECIAL_BLOCKS_PRAY_PAY").asKey().player(event.getPlayer()).sendPlayer(); return; @@ -170,7 +171,7 @@ public void onMysteryPotionDrink(PlayerItemConsumeEvent event) { } String itemDisplayName = ComplementAccessor.getComplement().getDisplayName(item.getItemMeta()); - User user = plugin.getUserManager().getUser(event.getPlayer()); + IUser user = plugin.getUserManager().getUser(event.getPlayer()); for(MysteryPotion potion : MysteryPotionRegistry.getMysteryPotions()) { if(itemDisplayName.equals(potion.getName())) { event.setCancelled(true); diff --git a/src/main/java/plugily/projects/murdermystery/arena/special/pray/PrayerRegistry.java b/src/main/java/plugily/projects/murdermystery/arena/special/pray/PrayerRegistry.java index d2665193..37673e68 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/special/pray/PrayerRegistry.java +++ b/src/main/java/plugily/projects/murdermystery/arena/special/pray/PrayerRegistry.java @@ -24,10 +24,9 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; - -import plugily.projects.minigamesbox.classic.arena.ArenaState; +import plugily.projects.minigamesbox.api.arena.IArenaState; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.misc.MiscUtils; import plugily.projects.murdermystery.Main; import plugily.projects.murdermystery.arena.Arena; @@ -75,7 +74,7 @@ public static List getPrayers() { return prayers; } - public static void applyRandomPrayer(User user) { + public static void applyRandomPrayer(IUser user) { Prayer prayer = getRandomPray(); user.setStatistic("LOCAL_CURRENT_PRAY", prayer.getPrayerType().ordinal()); @@ -125,7 +124,7 @@ public static void applyRandomPrayer(User user) { @Override public void run() { - if(arena == null || arena.getArenaState() != ArenaState.IN_GAME || !arena.getPlayersLeft().contains(player)) { + if(arena == null || arena.getArenaState() != IArenaState.IN_GAME || !arena.getPlayersLeft().contains(player)) { cancel(); return; } diff --git a/src/main/java/plugily/projects/murdermystery/arena/states/InGameState.java b/src/main/java/plugily/projects/murdermystery/arena/states/InGameState.java index f85d3b8c..0848b1da 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/states/InGameState.java +++ b/src/main/java/plugily/projects/murdermystery/arena/states/InGameState.java @@ -22,11 +22,11 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArena; import plugily.projects.minigamesbox.classic.arena.states.PluginInGameState; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; import plugily.projects.minigamesbox.classic.handlers.language.TitleBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.version.xseries.XSound; import plugily.projects.murdermystery.arena.Arena; import plugily.projects.murdermystery.arena.ArenaUtils; @@ -89,7 +89,7 @@ private void distributeMurdererSword(Arena pluginArena) { if(pluginArena.getMurdererList().isEmpty()) getPlugin().getArenaManager().stopGame(false, pluginArena); for(Player p : pluginArena.getMurdererList()) { - User murderer = getPlugin().getUserManager().getUser(p); + IUser murderer = getPlugin().getUserManager().getUser(p); if(murderer.isSpectator() || !p.isOnline()) continue; @@ -115,7 +115,7 @@ private void givePlayerSurviveReward(Arena pluginArena) { if(pluginArena.getTimer() % 30 == 0) { new TitleBuilder("IN_GAME_MESSAGES_ARENA_PLAYING_TIME_LEFT").arena(pluginArena).sendArena(); for(Player p : pluginArena.getPlayersLeft()) { - User user = getPlugin().getUserManager().getUser(p); + IUser user = getPlugin().getUserManager().getUser(p); if(Role.isRole(Role.INNOCENT, user, pluginArena)) { ArenaUtils.addScore(user, ArenaUtils.ScoreAction.SURVIVE_TIME, 0); } diff --git a/src/main/java/plugily/projects/murdermystery/arena/states/StartingState.java b/src/main/java/plugily/projects/murdermystery/arena/states/StartingState.java index 8832ea27..080e8626 100644 --- a/src/main/java/plugily/projects/murdermystery/arena/states/StartingState.java +++ b/src/main/java/plugily/projects/murdermystery/arena/states/StartingState.java @@ -22,6 +22,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.arena.PluginArena; import plugily.projects.minigamesbox.classic.arena.states.PluginStartingState; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; @@ -65,7 +66,7 @@ public void handleCall(PluginArena arena) { int size = pluginArena.getPlayerSpawnPoints().size(); for(Player player : arena.getPlayers()) { VersionUtils.teleport(player, pluginArena.getPlayerSpawnPoints().get(getPlugin().getRandom().nextInt(size))); - User user = arena.getPlugin().getUserManager().getUser(player); + IUser user = arena.getPlugin().getUserManager().getUser(player); user.resetNonePersistentStatistics(); PrayerRegistry.getRush().remove(player); PrayerRegistry.getBan().remove(player); @@ -94,17 +95,17 @@ public void handleCall(PluginArena arena) { private void addRole(Arena arena, Role role, Set playersToSet) { String roleName = role.toString(); - List chancesRanking = getPlugin().getUserManager().getUsers(arena).stream().filter(user -> playersToSet.contains(user.getPlayer())).sorted(Comparator.comparingInt(user -> arena.getContributorValue(role, user))).collect(Collectors.toList()); + List chancesRanking = getPlugin().getUserManager().getUsers(arena).stream().filter(user -> playersToSet.contains(user.getPlayer())).sorted(Comparator.comparingInt(user -> arena.getContributorValue(role, user))).collect(Collectors.toList()); Collections.reverse(chancesRanking); List chancesPlayer = new ArrayList<>(); - for(User user : chancesRanking) { + for(IUser user : chancesRanking) { chancesPlayer.add(user.getPlayer()); } getPlugin().getDebugger().debug("Arena {0} | Role add {1} | List {2}", arena.getId(), roleName, chancesPlayer); int amount = role == Role.MURDERER ? maxmurderer : maxdetectives; for(int i = 0; i < amount; i++) { - User user = chancesRanking.get(i); + IUser user = chancesRanking.get(i); Player userPlayer = user.getPlayer(); arena.setCharacter(role, userPlayer); arena.resetContributorValue(role, user); diff --git a/src/main/java/plugily/projects/murdermystery/boot/AdditionalValueInitializer.java b/src/main/java/plugily/projects/murdermystery/boot/AdditionalValueInitializer.java index ea19b8eb..0e5ff351 100644 --- a/src/main/java/plugily/projects/murdermystery/boot/AdditionalValueInitializer.java +++ b/src/main/java/plugily/projects/murdermystery/boot/AdditionalValueInitializer.java @@ -1,5 +1,6 @@ package plugily.projects.murdermystery.boot; +import plugily.projects.minigamesbox.api.preferences.IConfigPreferences; import plugily.projects.minigamesbox.classic.api.StatisticType; import plugily.projects.minigamesbox.classic.api.StatsStorage; import plugily.projects.minigamesbox.classic.arena.options.ArenaOption; @@ -10,7 +11,6 @@ import plugily.projects.minigamesbox.classic.handlers.reward.RewardType; import plugily.projects.minigamesbox.classic.handlers.reward.RewardsFactory; import plugily.projects.minigamesbox.classic.preferences.ConfigOption; -import plugily.projects.minigamesbox.classic.preferences.ConfigPreferences; import plugily.projects.murdermystery.Main; /** @@ -82,7 +82,7 @@ private void registerArenaOptions() { getArenaOptionManager().registerArenaOption("MURDERER_DIVIDER", new ArenaOption("null", 1)); } - private ConfigPreferences getConfigPreferences() { + private IConfigPreferences getConfigPreferences() { return plugin.getConfigPreferences(); } diff --git a/src/main/java/plugily/projects/murdermystery/boot/PlaceholderInitializer.java b/src/main/java/plugily/projects/murdermystery/boot/PlaceholderInitializer.java index 61a751ea..bac8f80f 100644 --- a/src/main/java/plugily/projects/murdermystery/boot/PlaceholderInitializer.java +++ b/src/main/java/plugily/projects/murdermystery/boot/PlaceholderInitializer.java @@ -4,13 +4,13 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -import plugily.projects.minigamesbox.classic.arena.PluginArena; -import plugily.projects.minigamesbox.number.NumberUtils; +import plugily.projects.minigamesbox.api.arena.IPluginArena; +import plugily.projects.minigamesbox.api.user.IUser; +import plugily.projects.minigamesbox.api.user.IUserManager; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; import plugily.projects.minigamesbox.classic.handlers.placeholder.Placeholder; import plugily.projects.minigamesbox.classic.handlers.placeholder.PlaceholderManager; -import plugily.projects.minigamesbox.classic.user.User; -import plugily.projects.minigamesbox.classic.user.UserManager; +import plugily.projects.minigamesbox.number.NumberUtils; import plugily.projects.murdermystery.Main; import plugily.projects.murdermystery.arena.Arena; import plugily.projects.murdermystery.arena.ArenaRegistry; @@ -33,7 +33,7 @@ public PlaceholderInitializer(Main plugin) { private void registerPlaceholders() { getPlaceholderManager().registerPlaceholder(new Placeholder("detective_list", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -56,7 +56,7 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("murderer_list", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -64,7 +64,7 @@ public String getValue(Player player, PluginArena arena) { StringBuilder murders = new StringBuilder(); for(Player p : pluginArena.getMurdererList()) { - User user = getUserManager().getUser(p); + IUser user = getUserManager().getUser(p); int localKills = user.getStatistic("LOCAL_KILLS"); murders.append(p.getName()); if(pluginArena.getMurdererList().size() > 1) { @@ -82,14 +82,14 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("murderer_kills", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; } int murdererKills = 0; for(Player p : pluginArena.getMurdererList()) { - User user = getUserManager().getUser(p); + IUser user = getUserManager().getUser(p); int localKills = user.getStatistic("LOCAL_KILLS"); murdererKills += localKills; } @@ -99,7 +99,7 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("hero", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -111,33 +111,33 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("murderer_chance", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; } - User user = getUserManager().getUser(player); + IUser user = getUserManager().getUser(player); return NumberUtils.round(((double) pluginArena.getContributorValue(Role.MURDERER, user) / (double) pluginArena.getTotalRoleChances(Role.MURDERER)) * 100.0, 0) + "%"; } }); getPlaceholderManager().registerPlaceholder(new Placeholder("detective_chance", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; } - User user = getUserManager().getUser(player); + IUser user = getUserManager().getUser(player); return NumberUtils.round(((double) pluginArena.getContributorValue(Role.DETECTIVE, user) / (double) pluginArena.getTotalRoleChances(Role.DETECTIVE)) * 100.0, 0) + "%"; } }); getPlaceholderManager().registerPlaceholder(new Placeholder("detective_status", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -157,7 +157,7 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("innocent_size", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -174,12 +174,12 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("player_role", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; } - User user = getUserManager().getUser(player); + IUser user = getUserManager().getUser(player); String role; if(pluginArena.isDeathPlayer(player)) { role = new MessageBuilder("SCOREBOARD_ROLES_DEAD").asKey().build(); @@ -196,12 +196,12 @@ public String getValue(Player player, PluginArena arena) { getPlaceholderManager().registerPlaceholder(new Placeholder("summary_player", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { return getSummary(player, arena); } @Nullable - private String getSummary(Player player, PluginArena arena) { + private String getSummary(Player player, IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -222,17 +222,17 @@ private String getSummary(Player player, PluginArena arena) { }); getPlaceholderManager().registerPlaceholder(new Placeholder("summary", Placeholder.PlaceholderType.ARENA, Placeholder.PlaceholderExecutor.ALL) { @Override - public String getValue(Player player, PluginArena arena) { + public String getValue(Player player, IPluginArena arena) { return getSummary(arena); } @Override - public String getValue(PluginArena arena) { + public String getValue(IPluginArena arena) { return getSummary(arena); } @Nullable - private String getSummary(PluginArena arena) { + private String getSummary(IPluginArena arena) { Arena pluginArena = getArenaRegistry().getArena(arena.getId()); if(pluginArena == null) { return null; @@ -257,7 +257,7 @@ private ArenaRegistry getArenaRegistry() { return plugin.getArenaRegistry(); } - private UserManager getUserManager() { + private IUserManager getUserManager() { return plugin.getUserManager(); } diff --git a/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/RolePassArgument.java b/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/RolePassArgument.java index 7757d51d..bcbb4f44 100644 --- a/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/RolePassArgument.java +++ b/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/RolePassArgument.java @@ -22,12 +22,12 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.commands.arguments.data.CommandArgument; import plugily.projects.minigamesbox.classic.commands.arguments.data.LabelData; import plugily.projects.minigamesbox.classic.commands.arguments.data.LabeledCommandArgument; -import plugily.projects.minigamesbox.number.NumberUtils; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; -import plugily.projects.minigamesbox.classic.user.User; +import plugily.projects.minigamesbox.number.NumberUtils; import plugily.projects.murdermystery.arena.role.Role; import plugily.projects.murdermystery.commands.arguments.ArgumentsRegistry; @@ -77,7 +77,7 @@ public void execute(CommandSender sender, String[] args) { new MessageBuilder("COMMANDS_PLAYER_NOT_FOUND").asKey().send(sender); return; } - User user = registry.getPlugin().getUserManager().getUser(player); + IUser user = registry.getPlugin().getUserManager().getUser(player); switch(addOrRemove.toLowerCase()) { case "add": if(role == Role.MURDERER) { diff --git a/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/arena/SpecialBlockRemoverArgument.java b/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/arena/SpecialBlockRemoverArgument.java index dc143384..a3739256 100644 --- a/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/arena/SpecialBlockRemoverArgument.java +++ b/src/main/java/plugily/projects/murdermystery/commands/arguments/admin/arena/SpecialBlockRemoverArgument.java @@ -23,8 +23,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; - -import plugily.projects.minigamesbox.classic.arena.PluginArena; +import plugily.projects.minigamesbox.api.arena.IPluginArena; import plugily.projects.minigamesbox.classic.commands.arguments.data.CommandArgument; import plugily.projects.minigamesbox.classic.commands.arguments.data.LabelData; import plugily.projects.minigamesbox.classic.commands.arguments.data.LabeledCommandArgument; @@ -46,73 +45,70 @@ public class SpecialBlockRemoverArgument { public SpecialBlockRemoverArgument(ArgumentsRegistry registry) { registry.mapArgument( - "murdermysteryadmin", - new LabeledCommandArgument( - "removeblock", - "murdermystery.admin.removeblock", - CommandArgument.ExecutorType.PLAYER, - new LabelData( - "/mma removeblock", - "/mma removeblock", - "&7Removes the special block you are looking at \n&6Permission: &7murdermystery.admin.removeblock")) { - @Override - public void execute(CommandSender sender, String[] args) { - // no need for check as argument is only for players - Player player = (Player) sender; - Block targetBlock = player.getTargetBlock(null, 7); - if(targetBlock.getType() == Material.CAULDRON - || targetBlock.getType() == XMaterial.ENCHANTING_TABLE.parseMaterial()) { - for(PluginArena arena : registry.getPlugin().getArenaRegistry().getArenas()) { + "murdermysteryadmin", + new LabeledCommandArgument( + "removeblock", + "murdermystery.admin.removeblock", + CommandArgument.ExecutorType.PLAYER, + new LabelData( + "/mma removeblock", + "/mma removeblock", + "&7Removes the special block you are looking at \n&6Permission: &7murdermystery.admin.removeblock")) { + @Override + public void execute(CommandSender sender, String[] args) { + // no need for check as argument is only for players + Player player = (Player) sender; + Block targetBlock = player.getTargetBlock(null, 7); + if (targetBlock.getType() == Material.CAULDRON + || targetBlock.getType() == XMaterial.ENCHANTING_TABLE.parseMaterial()) { + for (IPluginArena arena : registry.getPlugin().getArenaRegistry().getArenas()) { - Arena pluginArena = (Arena) registry.getPlugin().getArenaRegistry().getArena(arena.getId()); - if(arena == null) { - return; - } + Arena pluginArena = (Arena) registry.getPlugin().getArenaRegistry().getArena(arena.getId()); - // do not check arenas that could not be the case - if(pluginArena.getSpecialBlocks().isEmpty()) { - continue; - } - if(pluginArena.getPlayerSpawnPoints().get(0).getWorld() != player.getWorld()) { - continue; - } - // get all special blocks - for(SpecialBlock specialBlock : new ArrayList<>(pluginArena.getSpecialBlocks())) { - // check if targetBlock is specialblock - if(specialBlock.getLocation().getBlock().equals(targetBlock)) { - // get special blocks from config - FileConfiguration config = - ConfigUtils.getConfig(registry.getPlugin(), "arenas"); - // remove special block from arena - pluginArena.getSpecialBlocks().remove(specialBlock); - // remove hologram - if(specialBlock.getArmorStandHologram() != null) { - specialBlock.getArmorStandHologram().delete(); - } - // remove special block from arena file - String path = - targetBlock.getType() == Material.CAULDRON - ? ".mystery-cauldrons" - : ".confessionals"; - String serializedLoc = - LocationSerializer.locationToString(specialBlock.getLocation()); - List specialBlocksType = - config.getStringList("instances." + arena.getId() + path); - specialBlocksType.remove(serializedLoc); - config.set("instances." + arena.getId() + path, specialBlocksType); - // save arena config after removing special block - ConfigUtils.saveConfig(registry.getPlugin(), config, "arenas"); - new MessageBuilder("&cRemoved special block at loc " - + serializedLoc - + " from arena " - + arena.getId()).player(player).sendPlayer(); - return; + // do not check arenas that could not be the case + if (pluginArena.getSpecialBlocks().isEmpty()) { + continue; + } + if (pluginArena.getPlayerSpawnPoints().get(0).getWorld() != player.getWorld()) { + continue; + } + // get all special blocks + for (SpecialBlock specialBlock : new ArrayList<>(pluginArena.getSpecialBlocks())) { + // check if targetBlock is specialblock + if (specialBlock.getLocation().getBlock().equals(targetBlock)) { + // get special blocks from config + FileConfiguration config = + ConfigUtils.getConfig(registry.getPlugin(), "arenas"); + // remove special block from arena + pluginArena.getSpecialBlocks().remove(specialBlock); + // remove hologram + if (specialBlock.getArmorStandHologram() != null) { + specialBlock.getArmorStandHologram().delete(); } + // remove special block from arena file + String path = + targetBlock.getType() == Material.CAULDRON + ? ".mystery-cauldrons" + : ".confessionals"; + String serializedLoc = + LocationSerializer.locationToString(specialBlock.getLocation()); + List specialBlocksType = + config.getStringList("instances." + arena.getId() + path); + specialBlocksType.remove(serializedLoc); + config.set("instances." + arena.getId() + path, specialBlocksType); + // save arena config after removing special block + ConfigUtils.saveConfig(registry.getPlugin(), config, "arenas"); + new MessageBuilder("&cRemoved special block at loc " + + serializedLoc + + " from arena " + + arena.getId()).player(player).sendPlayer(); + return; } } } - new MessageBuilder("&cPlease target an special block to continue!").player(player).sendPlayer(); } - }); + new MessageBuilder("&cPlease target an special block to continue!").player(player).sendPlayer(); + } + }); } } diff --git a/src/main/java/plugily/projects/murdermystery/commands/arguments/game/RoleSelectorArgument.java b/src/main/java/plugily/projects/murdermystery/commands/arguments/game/RoleSelectorArgument.java index 80bffc3d..dc739703 100644 --- a/src/main/java/plugily/projects/murdermystery/commands/arguments/game/RoleSelectorArgument.java +++ b/src/main/java/plugily/projects/murdermystery/commands/arguments/game/RoleSelectorArgument.java @@ -21,12 +21,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Listener; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.PluginMain; import plugily.projects.minigamesbox.classic.commands.arguments.data.CommandArgument; import plugily.projects.minigamesbox.classic.commands.arguments.data.LabelData; import plugily.projects.minigamesbox.classic.commands.arguments.data.LabeledCommandArgument; import plugily.projects.minigamesbox.classic.handlers.language.MessageBuilder; -import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.minigamesbox.classic.utils.helper.ItemBuilder; import plugily.projects.minigamesbox.classic.utils.version.xseries.XMaterial; import plugily.projects.minigamesbox.inventory.common.item.SimpleClickableItem; @@ -36,7 +36,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class RoleSelectorArgument implements Listener { @@ -62,7 +61,7 @@ public static void openRolePassMenu(Player player, PluginMain plugin) { .name(new MessageBuilder("IN_GAME_MESSAGES_ARENA_PASS_ROLE_MURDERER_NAME").asKey().build()) .lore(descriptionMurderer) .build(), event -> { - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); if(user.getStatistic("PASS_MURDERER") <= 0) { new MessageBuilder("IN_GAME_MESSAGES_ARENA_PASS_FAIL").asKey().player(player).value(Role.MURDERER.name()).sendPlayer(); return; @@ -77,7 +76,7 @@ public static void openRolePassMenu(Player player, PluginMain plugin) { .name(new MessageBuilder("IN_GAME_MESSAGES_ARENA_PASS_ROLE_DETECTIVE_NAME").asKey().build()) .lore(descriptionDetective) .build(), event -> { - User user = plugin.getUserManager().getUser(player); + IUser user = plugin.getUserManager().getUser(player); if(user.getStatistic("PASS_DETECTIVE") <= 0) { new MessageBuilder("IN_GAME_MESSAGES_ARENA_PASS_FAIL").asKey().player(player).value(Role.DETECTIVE.name()).sendPlayer(); return; diff --git a/src/main/java/plugily/projects/murdermystery/events/PluginEvents.java b/src/main/java/plugily/projects/murdermystery/events/PluginEvents.java index dc7042fc..9f4f5828 100644 --- a/src/main/java/plugily/projects/murdermystery/events/PluginEvents.java +++ b/src/main/java/plugily/projects/murdermystery/events/PluginEvents.java @@ -33,7 +33,7 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; -import plugily.projects.minigamesbox.classic.user.User; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.utils.version.ServerVersion; import plugily.projects.minigamesbox.classic.utils.version.VersionUtils; import plugily.projects.minigamesbox.classic.utils.version.xseries.XMaterial; @@ -67,7 +67,7 @@ public void onSwordThrow(PlayerInteractEvent event) { return; } - User attackerUser = plugin.getUserManager().getUser(attacker); + IUser attackerUser = plugin.getUserManager().getUser(attacker); if(!Role.isRole(Role.MURDERER, attackerUser, arena)) { return; } @@ -99,7 +99,7 @@ public void onSwordThrow(PlayerInteractEvent event) { plugin.getBukkitHelper().applyActionBarCooldown(attacker, swordFlyCooldown); } - private void createFlyingSword(Player attacker, User attackerUser) { + private void createFlyingSword(Player attacker, IUser attackerUser) { Location loc = attacker.getLocation(); Vector vec = loc.getDirection(); vec.normalize().multiply(plugin.getConfig().getDouble("Sword.Speed", 0.65)); @@ -156,12 +156,12 @@ public void run() { }.runTaskTimer(plugin, 0, 1); } - private void killBySword(Arena arena, User attackerUser, Player victim) { + private void killBySword(Arena arena, IUser attackerUser, Player victim) { Arena victimArena = plugin.getArenaRegistry().getArena(victim); if(arena == null) { return; } - User user = plugin.getUserManager().getUser(victim); + IUser user = plugin.getUserManager().getUser(victim); // check if victim is murderer if(Role.isRole(Role.MURDERER, user, victimArena)) { diff --git a/src/main/java/plugily/projects/murdermystery/utils/ItemPosition.java b/src/main/java/plugily/projects/murdermystery/utils/ItemPosition.java index 07f976ff..2b18e18e 100644 --- a/src/main/java/plugily/projects/murdermystery/utils/ItemPosition.java +++ b/src/main/java/plugily/projects/murdermystery/utils/ItemPosition.java @@ -20,6 +20,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import plugily.projects.minigamesbox.api.user.IUser; import plugily.projects.minigamesbox.classic.user.User; import plugily.projects.murdermystery.arena.role.Role; @@ -49,7 +50,7 @@ public enum ItemPosition { * @param itemPosition position of item to set/add * @param itemStack itemstack to be added at itemPostion or set at itemPosition */ - public static void addItem(User user, ItemPosition itemPosition, ItemStack itemStack) { + public static void addItem(IUser user, ItemPosition itemPosition, ItemStack itemStack) { int itemPos = Role.isRole(Role.MURDERER, user) ? itemPosition.getMurdererItemPosition() : itemPosition.getOtherRolesItemPosition(); @@ -76,7 +77,7 @@ public static void addItem(User user, ItemPosition itemPosition, ItemStack itemS * @param itemPosition position of item to set * @param itemStack itemstack to set at itemPosition */ - public static void setItem(User user, ItemPosition itemPosition, ItemStack itemStack) { + public static void setItem(IUser user, ItemPosition itemPosition, ItemStack itemStack) { if(itemPosition.getMurdererItemPosition() >= 0 && Role.isRole(Role.MURDERER, user)) { user.getPlayer().getInventory().setItem(itemPosition.getMurdererItemPosition(), itemStack); } else if (itemPosition.getOtherRolesItemPosition() >= 0) {