Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Spigot: Ajout wrapper + début StorageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Farmeurimmo committed Aug 28, 2022
1 parent 749293b commit 321064e
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 75 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository>
<id>verymc</id>
<url>https://nexus.premsiserv.com/repository/maven-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand Down Expand Up @@ -110,6 +114,11 @@
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>fr.verymc.api</groupId>
<artifactId>Wrapper</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/fr/verymc/spigot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@
import main.java.fr.verymc.spigot.core.spawners.SpawnerCmd;
import main.java.fr.verymc.spigot.core.spawners.SpawnersListener;
import main.java.fr.verymc.spigot.core.spawners.SpawnersManager;
import main.java.fr.verymc.spigot.core.storage.ConfigManager;
import main.java.fr.verymc.spigot.core.storage.SkyblockUser;
import main.java.fr.verymc.spigot.core.storage.SkyblockUserManager;
import main.java.fr.verymc.spigot.core.storage.StorageJSONManager;
import main.java.fr.verymc.spigot.core.storage.StorageManager;
import main.java.fr.verymc.spigot.dungeon.DungeonManager;
import main.java.fr.verymc.spigot.dungeon.cmd.DungeonAdminCmd;
import main.java.fr.verymc.spigot.dungeon.events.DungeonEntityListener;
Expand Down Expand Up @@ -102,7 +101,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class Main extends JavaPlugin {
Expand Down Expand Up @@ -285,8 +283,10 @@ public void onEnable() {

new ServersManager();

new ConfigManager();
new StorageJSONManager();
/*new ConfigManager();
new StorageJSONManager();*/

new StorageManager();

System.out.println("Starting core part 1 FINISHED");
System.out.println("------------------------------------------------");
Expand Down Expand Up @@ -364,6 +364,7 @@ public void run() {

@Override
public void onDisable() {
StorageManager.instance.forceUpdateAllQueuedUsers();
if (serverType == ServerType.SKYBLOCK_ISLAND) {
ServersManager.instance.removeServerPlayersFromAPI();
IslandManager.instance.saveAllIslands();
Expand All @@ -372,14 +373,15 @@ public void onDisable() {
DungeonManager.instance.makeAllDungeonsEnd();
DungeonMobManager.instance.removeAllMobs();
}
for (SkyblockUser user : SkyblockUserManager.instance.users) {
for (SkyblockUser user : SkyblockUserManager.instance.getUsers()) {
if (Bukkit.getPlayer(user.getUserUUID()) == null) continue;
if (user.isInInvestMode()) {
InvestManager.instance.giveReward(user);
}
}
CompletableFuture.runAsync(() -> {
/*CompletableFuture.runAsync(() -> {
StorageJSONManager.instance.sendDataToAPIAuto(true);
}).join();
}).join();*/
for (Hologram hologram : HologramsAPI.getHolograms(this)) {
hologram.delete();
}
Expand Down
57 changes: 25 additions & 32 deletions src/main/java/fr/verymc/spigot/core/events/JoinLeave.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import main.java.fr.verymc.spigot.core.storage.SkyblockUser;
import main.java.fr.verymc.spigot.core.storage.SkyblockUserManager;
import main.java.fr.verymc.spigot.core.storage.StorageJSONManager;
import main.java.fr.verymc.spigot.core.storage.StorageManager;
import main.java.fr.verymc.spigot.dungeon.Dungeon;
import main.java.fr.verymc.spigot.dungeon.DungeonManager;
import main.java.fr.verymc.spigot.hub.invest.InvestManager;
Expand All @@ -25,7 +26,6 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand All @@ -35,22 +35,13 @@

public class JoinLeave implements Listener {

@EventHandler
public void postLogin(PlayerLoginEvent e) {
if (!e.getPlayer().hasPermission("maintenance")) {
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "§cLe serveur est en maintenance.");
}
}

@EventHandler
public void OnJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();

InventorySyncManager.instance.playerJoin(player);
SkyblockUser skyblockUser = SkyblockUserManager.instance.getUser(player);

SkyblockUserManager.instance.checkForAccount(player);

SkyblockUser skyblockUser = SkyblockUserManager.instance.getUser(player.getUniqueId());
InventorySyncManager.instance.playerJoin(player);

player.setGameMode(GameMode.SURVIVAL);

Expand Down Expand Up @@ -79,12 +70,23 @@ public void OnJoin(PlayerJoinEvent event) {

ScoreBoard.acces.setScoreBoard(player);

if (skyblockUser.hasHasteActive()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 999999999, 1));
}
if (skyblockUser.hasSpeedActive()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999999, 1));
}
if (skyblockUser.hasJumpActive()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 999999999, 2));
}

User user = LuckPermsProvider.get().getUserManager().getUser(player.getName());
String Grade = "§7N/A";
assert user != null;
if (user.getCachedData().getMetaData().getPrefix() != null) {
Grade = user.getCachedData().getMetaData().getPrefix();
}
String JoinMessage = null;
String JoinMessage;
if (playerIsland == null) {
JoinMessage = "§7[§a+§7] " + Grade.replace("&", "§") + " " + player.getName();
} else {
Expand All @@ -95,29 +97,24 @@ public void OnJoin(PlayerJoinEvent event) {
JoinMessage = "§7[§a+§7] [#" + classement + "] " + Grade.replace("&", "§") + " " + player.getName();
}
event.setJoinMessage(JoinMessage);

if (skyblockUser.hasHasteActive()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 999999999, 1));
}
if (skyblockUser.hasSpeedActive()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999999, 1));
}
if (skyblockUser.hasJumpActive()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 999999999, 2));
}
}

@EventHandler
public void OnLeave(PlayerQuitEvent event) {
Player player = event.getPlayer();

SkyblockUser skyblockUser = SkyblockUserManager.instance.getUser(player);
StorageManager.instance.updateUser(skyblockUser);

if (skyblockUser.isInInvestMode()) InvestManager.instance.giveReward(skyblockUser);
InventorySyncManager.instance.playerQuit(player);

if (Main.instance.serverType == ServerType.SKYBLOCK_DUNGEON) {
Dungeon dungeon = DungeonManager.instance.getDungeonByPlayer(player);
if (dungeon != null) {
dungeon.addDeadPlayer(player);
}
}
InventorySyncManager.instance.playerQuit(player);
SkyblockUser skyblockUser = SkyblockUserManager.instance.getUser(player.getUniqueId());
Island playerIsland = null;
if (Main.instance.serverType == ServerType.SKYBLOCK_ISLAND) {
playerIsland = IslandManager.instance.getPlayerIsland(player);
Expand All @@ -142,12 +139,13 @@ public void OnLeave(PlayerQuitEvent event) {
}
}
}
User user = LuckPermsProvider.get().getUserManager().getUser(player.getName());
User user = LuckPermsProvider.get().getUserManager().getUser(player.getUniqueId());
String Grade = "§7N/A";
assert user != null;
if (user.getCachedData().getMetaData().getPrefix() != null) {
Grade = user.getCachedData().getMetaData().getPrefix();
}
String LeaveMessage = null;
String LeaveMessage;
if (playerIsland == null) {
LeaveMessage = "§7[§c-§7] " + Grade.replace("&", "§").replace("&", "§") + " " + player.getName();
} else {
Expand All @@ -158,11 +156,6 @@ public void OnLeave(PlayerQuitEvent event) {
LeaveMessage = "§7[§c-§7] [" + classement + "] " + Grade.replace("&", "§").replace("&", "§") + " " + player.getName();
}
event.setQuitMessage(LeaveMessage);
if (skyblockUser != null) {
if (skyblockUser.isInInvestMode()) {
InvestManager.instance.giveReward(skyblockUser);
}
}
}

@EventHandler
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/fr/verymc/spigot/core/storage/SkyblockUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,17 @@ public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public UUID getUserUUID() {
return userUUID;
}

public void setUserUUID(UUID userUUID) {
this.userUUID = userUUID;
}

public double getMoney() {
return money;
}

public void setMoney(double money) {
this.money = money;
StorageManager.instance.startUpdateUser(this, StoragePriorities.NORMAL);
}

public boolean hasHaste() {
Expand Down Expand Up @@ -104,7 +97,6 @@ public int getFlyLeft() {
}

public void setFlyLeft(int flyLeft) {

this.flyLeft = flyLeft;
if (flyLeft == 0) {
this.isActive = false;
Expand All @@ -113,30 +105,37 @@ public void setFlyLeft(int flyLeft) {
this.isActive = true;
}
}
StorageManager.instance.startUpdateUser(this, StoragePriorities.NORMAL);
}

public void setHaste(boolean hasHaste) {
this.hasHaste = hasHaste;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public void setHasteActive(boolean hasHasteActvie) {
this.hasHasteActive = hasHasteActvie;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public void setSpeed(boolean hasSpeed) {
this.hasSpeed = hasSpeed;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public void setSpeedActive(boolean hasSpeedActive) {
this.hasSpeedActive = hasSpeedActive;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public void setJump(boolean hasJump) {
this.hasJump = hasJump;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public void setJumpActive(boolean hasJumpActive) {
this.hasJumpActive = hasJumpActive;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public boolean isActive() {
Expand All @@ -145,6 +144,7 @@ public boolean isActive() {

public void setActive(boolean isActive) {
this.isActive = isActive;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public boolean isInInvestMode() {
Expand All @@ -169,6 +169,7 @@ public PlayerWarp getPlayerWarp() {

public void setPlayerWarp(PlayerWarp playerWarp) {
this.playerWarp = playerWarp;
StorageManager.instance.startUpdateUser(this, StoragePriorities.NORMAL);
}

public Double getExp() {
Expand All @@ -177,6 +178,7 @@ public Double getExp() {

public void incrementLevel() {
this.level++;
StorageManager.instance.startUpdateUser(this, StoragePriorities.NORMAL);
}

public Double getLevel() {
Expand All @@ -185,16 +187,19 @@ public Double getLevel() {

public void setLevel(Double level) {
this.level = level;
StorageManager.instance.startUpdateUser(this, StoragePriorities.NORMAL);
}

public void addExp(Double exp) {
this.exp += exp;
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}

public void removeExp(Double exp) {
this.exp -= exp;
if (this.exp < 0) {
this.exp = 0.0;
}
StorageManager.instance.startUpdateUser(this, StoragePriorities.LOWEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class SkyblockUserManager {

public static SkyblockUserManager instance;
public ArrayList<SkyblockUser> users = new ArrayList<>();
public HashMap<UUID, SkyblockUser> users = new HashMap<>();

public SkyblockUserManager() {
instance = this;
Expand All @@ -18,18 +20,22 @@ public SkyblockUserManager() {
}
}

public Collection<SkyblockUser> getUsers() {
return users.values();
}

public void addUser(SkyblockUser user) {
users.add(user);
users.put(user.getUserUUID(), user);
}

public void removeUser(SkyblockUser user) {
users.remove(user);
users.remove(user.getUserUUID());
}

public SkyblockUser getUser(UUID uuid) {
for (SkyblockUser user : users) {
if (user.getUserUUID().equals(uuid)) {
return user;
for (Map.Entry<UUID, SkyblockUser> entry : users.entrySet()) {
if (entry.getKey().equals(uuid)) {
return entry.getValue();
}
}
return null;
Expand All @@ -41,12 +47,15 @@ public SkyblockUser getUser(Player player) {
}

public void checkForAccount(Player player) {
SkyblockUser skyblockUser = SkyblockUserManager.instance.getUser(player.getUniqueId());
SkyblockUser skyblockUser = (users.get(player.getUniqueId()) != null) ? users.get(player.getUniqueId()) : StorageManager.instance.getUser(player.getUniqueId());
if (skyblockUser == null) {
skyblockUser = new SkyblockUser(player.getName(), player.getUniqueId(), 200.0, false, false, false,
false, false, false, 0, false, false, 0, null, 0.0, 0.0);
SkyblockUserManager.instance.addUser(skyblockUser);
StorageManager.instance.createUser(skyblockUser);
return;
}
users.replace(skyblockUser.getUserUUID(), skyblockUser);
}

}
Loading

0 comments on commit 321064e

Please sign in to comment.