-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout du SkyblockCreateEvent Création de l'annotation pour préciser quand c'est experimental
- Loading branch information
Showing
19 changed files
with
310 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Experimental.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fr.euphyllia.skyfolia.api.annotation; | ||
|
||
|
||
import java.lang.annotation.*; | ||
|
||
@Inherited | ||
public @interface Experimental { | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/fr/euphyllia/skyfolia/api/annotation/Information.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fr.euphyllia.skyfolia.api.annotation; | ||
|
||
import java.lang.annotation.Inherited; | ||
|
||
@Inherited | ||
public @interface Information { | ||
|
||
String value(); | ||
} |
31 changes: 31 additions & 0 deletions
31
api/src/main/java/fr/euphyllia/skyfolia/api/event/SkyblockCreateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/Position.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
plugin/src/main/java/fr/euphyllia/skyfolia/cache/CacheManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RoleType, Integer> 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."); | ||
}); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
plugin/src/main/java/fr/euphyllia/skyfolia/cache/PermissionRoleInIslandCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UUID, ConcurrentHashMap<RoleType, Integer>> listPermissionsInIsland = new ConcurrentHashMap<>(); | ||
|
||
|
||
public static ConcurrentHashMap<UUID, ConcurrentHashMap<RoleType, Integer>> getListPermissionsInIsland() { | ||
return listPermissionsInIsland; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
plugin/src/main/java/fr/euphyllia/skyfolia/cache/PlayersInIslandCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UUID, CopyOnWriteArrayList<Players>> listPlayersInIsland = new ConcurrentHashMap<>(); | ||
private static final ConcurrentHashMap<UUID, UUID> islandIdByPlayerId = new ConcurrentHashMap<>(); | ||
|
||
public static Players getPlayers(UUID islandId, UUID playerId) { | ||
List<Players> 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<UUID, CopyOnWriteArrayList<Players>> getListPlayersInIsland() { | ||
return listPlayersInIsland; | ||
} | ||
|
||
public static ConcurrentMap<UUID, UUID> getIslandIdByPlayerId() { | ||
return islandIdByPlayerId; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
plugin/src/main/java/fr/euphyllia/skyfolia/cache/PositionIslandCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, UUID> positionIslandId = new ConcurrentHashMap<>(); | ||
|
||
public @Nullable UUID getIslandId(Position position) { | ||
return positionIslandId.getOrDefault(position.toString(), null); | ||
} | ||
|
||
public static ConcurrentMap<String, UUID> getPositionIslandId() { | ||
return positionIslandId; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
plugin/src/main/java/fr/euphyllia/skyfolia/listeners/bukkitevents/BlockEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.