From e30be67490f86b5cbef385405a1576099b191e08 Mon Sep 17 00:00:00 2001 From: Bierque Jason Date: Tue, 16 Jan 2024 15:05:09 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20d'essaie=20du=20systeme=20en=20cac?= =?UTF-8?q?he=20Ajout=20du=20SkyblockCreateEvent=20Cr=C3=A9ation=20de=20l'?= =?UTF-8?q?annotation=20pour=20pr=C3=A9ciser=20quand=20c'est=20experimenta?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/sonarlint/issuestore/index.pb | 20 ++++++- .idea/sonarlint/securityhotspotstore/index.pb | 20 ++++++- .../skyfolia/api/annotation/Experimental.java | 8 +++ .../skyfolia/api/annotation/Information.java | 9 +++ .../api/event/SkyblockCreateEvent.java | 31 ++++++++++ .../skyfolia/api/skyblock/model/Position.java | 5 ++ .../model/permissions/PermissionsIsland.java | 2 +- .../main/java/fr/euphyllia/skyfolia/Main.java | 27 ++++++++- .../fr/euphyllia/skyfolia/api/InterneAPI.java | 12 +++- .../skyfolia/cache/CacheManager.java | 60 +++++++++++++++++++ .../cache/PermissionRoleInIslandCache.java | 20 +++++++ .../skyfolia/cache/PlayersInIslandCache.java | 46 ++++++++++++++ .../skyfolia/cache/PositionIslandCache.java | 21 +++++++ .../listeners/bukkitevents/BlockEvent.java | 22 +++++++ .../listeners/bukkitevents/JoinEvent.java | 1 + .../skyblockevents/SkyblockEvent.java | 7 +++ .../managers/skyblock/IslandHook.java | 7 +-- .../managers/skyblock/SkyblockCache.java | 46 -------------- .../managers/skyblock/SkyblockManager.java | 13 ++-- 19 files changed, 310 insertions(+), 67 deletions(-) create mode 100644 api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java create mode 100644 api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java create mode 100644 api/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java create mode 100644 plugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java create mode 100644 plugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java create mode 100644 plugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java create mode 100644 plugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java create mode 100644 plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java delete mode 100644 plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockCache.java diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index 9bd2485..9e8c30a 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -181,4 +181,22 @@ Vplugin/src/main/java/fr/euphyllia/skyfolia/listeners/skyblockevents/SkyblockEve  _api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionInventory.java,4\3\4300b9534a7b8872a26b2859cc5e3ad5c0d4276d  -Wapi/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/gamerule/GameRuleIsland.java,a\e\ae2b1f9ebeca20443d167189e2d10125ae5f18c6 \ No newline at end of file +Wapi/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/gamerule/GameRuleIsland.java,a\e\ae2b1f9ebeca20443d167189e2d10125ae5f18c6 + +Qplugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java,2\d\2ddcd2bd9834ef3f4f49ab7d467c740d2e7f885e +y +Iplugin/src/main/java/fr/euphyllia/skyfolia/cache/MemberInIslandCache.java,d\f\dfda69f771ac5d8a5d7352349aa9e2308b453905 +z +Jplugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java,1\e\1ed76a6614dbe9624d475ba78a03371641b39c6c +r +Bplugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java,0\7\074f53b3fe33fb7ffceb1df450e1b0415f8dda57 + +Qplugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java,5\5\55512ac5e74391f1f913bf12ab8986c9e19a47fa +y +Iplugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java,c\4\c4a948603fed26c58a21ce0877a9d902e8ab8787 +x +Hapi/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java,8\f\8f9ab68e848f1575665aa8868c8d8dbf0210a9e6 +w +Gapi/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java,3\3\3376da0038fc83235314efc96c0e2abe7d4a39d3 +z +Japi/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java,9\6\969d813a90066279e4d975b4c63b3e8d59c63bbb \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index 9bd2485..9e8c30a 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -181,4 +181,22 @@ Vplugin/src/main/java/fr/euphyllia/skyfolia/listeners/skyblockevents/SkyblockEve  _api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionInventory.java,4\3\4300b9534a7b8872a26b2859cc5e3ad5c0d4276d  -Wapi/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/gamerule/GameRuleIsland.java,a\e\ae2b1f9ebeca20443d167189e2d10125ae5f18c6 \ No newline at end of file +Wapi/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/gamerule/GameRuleIsland.java,a\e\ae2b1f9ebeca20443d167189e2d10125ae5f18c6 + +Qplugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java,2\d\2ddcd2bd9834ef3f4f49ab7d467c740d2e7f885e +y +Iplugin/src/main/java/fr/euphyllia/skyfolia/cache/MemberInIslandCache.java,d\f\dfda69f771ac5d8a5d7352349aa9e2308b453905 +z +Jplugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java,1\e\1ed76a6614dbe9624d475ba78a03371641b39c6c +r +Bplugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java,0\7\074f53b3fe33fb7ffceb1df450e1b0415f8dda57 + +Qplugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java,5\5\55512ac5e74391f1f913bf12ab8986c9e19a47fa +y +Iplugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java,c\4\c4a948603fed26c58a21ce0877a9d902e8ab8787 +x +Hapi/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java,8\f\8f9ab68e848f1575665aa8868c8d8dbf0210a9e6 +w +Gapi/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java,3\3\3376da0038fc83235314efc96c0e2abe7d4a39d3 +z +Japi/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java,9\6\969d813a90066279e4d975b4c63b3e8d59c63bbb \ No newline at end of file diff --git a/api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java b/api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java new file mode 100644 index 0000000..500fcd4 --- /dev/null +++ b/api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java @@ -0,0 +1,8 @@ +package fr.euphyllia.skyfolia.api.annotation; + + +import java.lang.annotation.*; + +@Inherited +public @interface Experimental { +} diff --git a/api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java b/api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java new file mode 100644 index 0000000..1aa0792 --- /dev/null +++ b/api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java @@ -0,0 +1,9 @@ +package fr.euphyllia.skyfolia.api.annotation; + +import java.lang.annotation.Inherited; + +@Inherited +public @interface Information { + + String value(); +} diff --git a/api/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java b/api/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java new file mode 100644 index 0000000..f3adf36 --- /dev/null +++ b/api/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java @@ -0,0 +1,31 @@ +package fr.euphyllia.skyfolia.api.event; + +import fr.euphyllia.skyfolia.api.skyblock.Island; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class SkyblockCreateEvent extends Event { + + private static final HandlerList handlerList = new HandlerList(); + private final Island island; + + public SkyblockCreateEvent(Island islandCreate) { + super(true); + this.island = islandCreate; + } + + + public static HandlerList getHandlerList() { + return handlerList; + } + + @Override + public @NotNull HandlerList getHandlers() { + return getHandlerList(); + } + + public Island getIsland() { + return this.island; + } +} diff --git a/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/Position.java b/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/Position.java index aabf133..c8a0c65 100644 --- a/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/Position.java +++ b/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/Position.java @@ -1,4 +1,9 @@ package fr.euphyllia.skyfolia.api.skyblock.model; public record Position(int regionX, int regionZ) { + + @Override + public String toString() { + return "x=%s;z=%s".formatted(regionX, regionZ); + } } diff --git a/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsIsland.java b/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsIsland.java index c92407a..9ede599 100644 --- a/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsIsland.java +++ b/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsIsland.java @@ -15,7 +15,7 @@ public enum PermissionsIsland implements Permissions { KILL_ANIMAL(64), DROP_ITEMS(128), TAKE_ITEMS(256), - USE_PORTAL(5012), + USE_PORTAL(512), INTERACT_ENTITIES(1_024), ; diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/Main.java b/plugin/src/main/java/fr/euphyllia/skyfolia/Main.java index a1d226e..45f0112 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/Main.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/Main.java @@ -4,16 +4,22 @@ import fr.euphyllia.skyfolia.api.InterneAPI; import fr.euphyllia.skyfolia.api.exceptions.DatabaseException; import fr.euphyllia.skyfolia.commands.SkyFoliaCommand; +import fr.euphyllia.skyfolia.listeners.bukkitevents.BlockEvent; import fr.euphyllia.skyfolia.listeners.bukkitevents.JoinEvent; +import fr.euphyllia.skyfolia.listeners.skyblockevents.SkyblockEvent; import fr.euphyllia.skyfolia.managers.Managers; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bukkit.Bukkit; import org.bukkit.command.PluginCommand; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; public class Main extends JavaPlugin { @@ -45,9 +51,9 @@ public void onEnable() { this.interneAPI.setManagers(new Managers(interneAPI)); this.interneAPI.getManagers().init(); - this.interneAPI.loadCachePlugin(); this.setupCommands(); this.loadListener(); + this.runCache(); } @Override @@ -74,6 +80,23 @@ private void setupCommands() { } private void loadListener() { - getServer().getPluginManager().registerEvents(new JoinEvent(this.interneAPI), this); + PluginManager pluginManager = getServer().getPluginManager(); + // Bukkit Events + pluginManager.registerEvents(new JoinEvent(this.interneAPI), this); + pluginManager.registerEvents(new BlockEvent(this.interneAPI), this); + + // Skyblock Event + pluginManager.registerEvents(new SkyblockEvent(this.interneAPI), this); + } + + private void runCache() { + ScheduledExecutorService executors = Executors.newScheduledThreadPool(2); + executors.scheduleAtFixedRate(() -> { + logger.log(Level.FATAL, "Update en cours"); + Bukkit.getOnlinePlayers().forEach(player -> { + this.interneAPI.updateCache(player); + }); + }, 0, 10, TimeUnit.SECONDS); + } } \ No newline at end of file diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/api/InterneAPI.java b/plugin/src/main/java/fr/euphyllia/skyfolia/api/InterneAPI.java index 4fc15c2..907cf2b 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/api/InterneAPI.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/api/InterneAPI.java @@ -2,6 +2,7 @@ import fr.euphyllia.skyfolia.Main; import fr.euphyllia.skyfolia.api.exceptions.DatabaseException; +import fr.euphyllia.skyfolia.cache.CacheManager; import fr.euphyllia.skyfolia.configuration.ConfigToml; import fr.euphyllia.skyfolia.configuration.LanguageToml; import fr.euphyllia.skyfolia.database.DatabaseLoader; @@ -15,6 +16,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,11 +35,13 @@ public class InterneAPI { private MariaDBTransactionQuery transaction; private DatabaseLoader databaseLoader; private Managers managers; + private CacheManager cacheManager; public InterneAPI(Main plugin) { this.plugin = plugin; this.logger = LogManager.getLogger("fr.euphyllia.skyfolia.api.InterneAPI"); this.skyblockManager = new SkyblockManager(this.plugin); + this.cacheManager = new CacheManager(this.skyblockManager); } @@ -131,7 +135,11 @@ public SkyblockManager getSkyblockManager() { return MiniMessage.miniMessage(); } - public void loadCachePlugin() { - this.skyblockManager.loadCache(); + public void updateCache(Player player) { + this.cacheManager.updateCache(skyblockManager, player); + } + + public CacheManager getCacheManager() { + return this.cacheManager; } } diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java new file mode 100644 index 0000000..caaaa0a --- /dev/null +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java @@ -0,0 +1,60 @@ +package fr.euphyllia.skyfolia.cache; + +import fr.euphyllia.skyfolia.api.annotation.Experimental; +import fr.euphyllia.skyfolia.api.annotation.Information; +import fr.euphyllia.skyfolia.api.skyblock.Island; +import fr.euphyllia.skyfolia.api.skyblock.model.PermissionRoleIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsType; +import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bukkit.entity.Player; + +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; + +@Experimental +@Information("Je n'ai pas tester encore cette fonctionnalité") +public class CacheManager { + + private final Logger logger = LogManager.getLogger(CacheManager.class); + private final SkyblockManager skyblockManager; + + public CacheManager(SkyblockManager skyblockManager) { + this.skyblockManager = skyblockManager; + } + + public void updateCache(SkyblockManager skyblockManager, Player bPlayer) { + Island pIsland = skyblockManager.getIslandByOwner(bPlayer.getUniqueId()).join(); + if (pIsland == null) { + // ========= remove player + PlayersInIslandCache.getIslandIdByPlayerId().remove(bPlayer.getUniqueId()); + return; + } + this.updateCacheIsland(pIsland, bPlayer.getUniqueId()); + } + + public void updateCacheIsland(Island island, UUID playerId) { + Executors.newSingleThreadScheduledExecutor().execute(() -> { + // ============= player cache + PlayersInIslandCache.getIslandIdByPlayerId().put(playerId, island.getId()); + PlayersInIslandCache.getListPlayersInIsland().put(island.getId(), island.getMembers()); + // ============= position island cache + PositionIslandCache.getPositionIslandId().put(island.getPosition().toString(), island.getId()); + // ============= permission role cache + ConcurrentHashMap permissionByRole = new ConcurrentHashMap<>(); + for (PermissionsType permissionsType : PermissionsType.values()) { + for (RoleType roleType : RoleType.values()) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), permissionsType, roleType).join(); + permissionByRole.put(roleType, permissionRoleIsland.permission()); + } + } + PermissionRoleInIslandCache.getListPermissionsInIsland().put(island.getId(), permissionByRole); + + logger.log(Level.INFO, island.getId() + " est mis à jour."); + }); + } +} diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java new file mode 100644 index 0000000..fd915e4 --- /dev/null +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java @@ -0,0 +1,20 @@ +package fr.euphyllia.skyfolia.cache; + +import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +public class PermissionRoleInIslandCache { + private static final Logger logger = LogManager.getLogger(PermissionRoleInIslandCache.class); + private static final ConcurrentHashMap> listPermissionsInIsland = new ConcurrentHashMap<>(); + + + public static ConcurrentHashMap> getListPermissionsInIsland() { + return listPermissionsInIsland; + } +} diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java new file mode 100644 index 0000000..c598aac --- /dev/null +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java @@ -0,0 +1,46 @@ +package fr.euphyllia.skyfolia.cache; + +import fr.euphyllia.skyfolia.api.skyblock.Island; +import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArrayList; + +public class PlayersInIslandCache { + + private static final Logger logger = LogManager.getLogger(PlayersInIslandCache.class); + private static final ConcurrentHashMap> listPlayersInIsland = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap islandIdByPlayerId = new ConcurrentHashMap<>(); + + public static Players getPlayers(UUID islandId, UUID playerId) { + List playersInIsland = listPlayersInIsland.getOrDefault(islandId, new CopyOnWriteArrayList<>()); + if (playersInIsland.isEmpty()) { + return new Players(playerId, null, islandId, RoleType.VISITOR); + } + for (Players players : playersInIsland) { + if (players.getMojangId() == playerId) { + return players; + } + } + return new Players(playerId, null, islandId, RoleType.VISITOR); + } + + public static ConcurrentMap> getListPlayersInIsland() { + return listPlayersInIsland; + } + + public static ConcurrentMap getIslandIdByPlayerId() { + return islandIdByPlayerId; + } +} diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java new file mode 100644 index 0000000..007f900 --- /dev/null +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java @@ -0,0 +1,21 @@ +package fr.euphyllia.skyfolia.cache; + +import fr.euphyllia.skyfolia.api.skyblock.model.Position; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +public class PositionIslandCache { + + private static final ConcurrentHashMap positionIslandId = new ConcurrentHashMap<>(); + + public @Nullable UUID getIslandId(Position position) { + return positionIslandId.getOrDefault(position.toString(), null); + } + + public static ConcurrentMap getPositionIslandId() { + return positionIslandId; + } +} diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java b/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java new file mode 100644 index 0000000..80db644 --- /dev/null +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java @@ -0,0 +1,22 @@ +package fr.euphyllia.skyfolia.listeners.bukkitevents; + +import fr.euphyllia.skyfolia.api.InterneAPI; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +public class BlockEvent implements Listener { + + private final InterneAPI api; + private final Logger logger = LogManager.getLogger(BlockEvent.class); + + public BlockEvent(InterneAPI interneAPI) { + this.api = interneAPI; + } + + public void onBlockBreakOnIsland(final BlockBreakEvent event) { + + } + +} diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/JoinEvent.java b/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/JoinEvent.java index 4ffee5b..1a5b09b 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/JoinEvent.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/JoinEvent.java @@ -44,6 +44,7 @@ public void onLoadIslandInJoinEvent(PlayerJoinEvent playerJoinEvent) { if (island == null) { PlayerUtils.teleportPlayerSpawn(this.api.getPlugin(), player); } else { + this.api.updateCache(player); World world = player.getLocation().getWorld(); if (Boolean.TRUE.equals(WorldUtils.isWorldSkyblock(world.getName()))) { Location centerIsland = RegionUtils.getCenterRegion(world, island.getPosition().regionX(), island.getPosition().regionZ()); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/skyblockevents/SkyblockEvent.java b/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/skyblockevents/SkyblockEvent.java index f9d0e2b..507c4d9 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/skyblockevents/SkyblockEvent.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/listeners/skyblockevents/SkyblockEvent.java @@ -1,8 +1,10 @@ package fr.euphyllia.skyfolia.listeners.skyblockevents; import fr.euphyllia.skyfolia.api.InterneAPI; +import fr.euphyllia.skyfolia.api.event.SkyblockCreateEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; public class SkyblockEvent implements Listener { @@ -14,4 +16,9 @@ public SkyblockEvent(InterneAPI interneAPI) { this.api = interneAPI; } + @EventHandler + public void onSkyblockCreate(final SkyblockCreateEvent event) { + System.out.println("create"); + } + } diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/IslandHook.java b/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/IslandHook.java index 4becb62..3462e7a 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/IslandHook.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/IslandHook.java @@ -58,12 +58,7 @@ public UUID getId() { @Override public double getSize() { - if (this.size == -1) { - // check db - throw new UnsupportedOperationException("pas encore implémenter"); - } else { - return this.size; - } + return this.size; } @Override diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockCache.java b/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockCache.java deleted file mode 100644 index fa2a2a0..0000000 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockCache.java +++ /dev/null @@ -1,46 +0,0 @@ -package fr.euphyllia.skyfolia.managers.skyblock; - -import fr.euphyllia.skyfolia.api.skyblock.Island; -import fr.euphyllia.skyfolia.api.skyblock.Players; -import fr.euphyllia.skyfolia.api.skyblock.model.Position; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -public class SkyblockCache { - - private final Logger logger = LogManager.getLogger(SkyblockCache.class); - private final ConcurrentHashMap islandId_Island; - private final ConcurrentHashMap position_islandId; - private final ConcurrentHashMap playerId_IslandId; - private final SkyblockManager skyblockManager; - - - public SkyblockCache(SkyblockManager sm) { - this.skyblockManager = sm; - this.islandId_Island = new ConcurrentHashMap<>(); - this.position_islandId = new ConcurrentHashMap<>(); - this.playerId_IslandId = new ConcurrentHashMap<>(); - } - - public void updateCache() { - for (Player bPlayer : Bukkit.getOnlinePlayers()) { - Island pIsland = this.skyblockManager.getIslandByOwner(bPlayer.getUniqueId()).join(); - if (pIsland == null) { - continue; - } - this.islandId_Island.put(pIsland.getId(), pIsland); - this.position_islandId.put(pIsland.getPosition(), pIsland.getId()); - for (Players players : pIsland.getMembers()) { - this.playerId_IslandId.put(players.getMojangId(), pIsland.getId()); - } - logger.log(Level.INFO, pIsland.getId() + " est mis en cache"); - } - } - -} diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockManager.java b/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockManager.java index 28a1bb9..85cca76 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockManager.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/managers/skyblock/SkyblockManager.java @@ -1,6 +1,7 @@ package fr.euphyllia.skyfolia.managers.skyblock; import fr.euphyllia.skyfolia.Main; +import fr.euphyllia.skyfolia.api.event.SkyblockCreateEvent; import fr.euphyllia.skyfolia.api.skyblock.Island; import fr.euphyllia.skyfolia.api.skyblock.Players; import fr.euphyllia.skyfolia.api.skyblock.model.IslandType; @@ -11,6 +12,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.jetbrains.annotations.Nullable; @@ -20,17 +22,10 @@ public class SkyblockManager { private final Main plugin; - private final SkyblockCache skyblockCache; private final Logger logger = LogManager.getLogger(SkyblockManager.class); public SkyblockManager(Main main) { this.plugin = main; - this.skyblockCache = new SkyblockCache(this); - } - - public void loadCache() { - ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); - executor.scheduleAtFixedRate(this.skyblockCache::updateCache, 1, 60, TimeUnit.SECONDS); } public CompletableFuture<@Nullable Island> createIsland(UUID playerId, IslandType islandType) { @@ -49,7 +44,9 @@ public void loadCache() { boolean create = this.plugin.getInterneAPI().getIslandQuery().getIslandDataQuery().insertIslands(futurIsland).join(); if (create) { Island island = this.getIslandByOwner(playerId).join(); - completableFuture.complete(island); + SkyblockCreateEvent skyblockCreateEvent = new SkyblockCreateEvent(island); + Bukkit.getPluginManager().callEvent(skyblockCreateEvent); + completableFuture.complete(skyblockCreateEvent.getIsland()); } } catch (Exception e) {