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

Commit

Permalink
mysql check player is online
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightTale committed May 7, 2023
1 parent a817418 commit 5219007
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package xyz.hynse.phantomisolation2;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.hynse.phantomisolation2.command.PhantomIsolationCommand;
import xyz.hynse.phantomisolation2.command.ReloadCommand;
Expand All @@ -20,7 +23,11 @@ public void onEnable() {
PhantomIsolationListener listener = new PhantomIsolationListener();
listener.start();
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
PhantomIsolationListener listener = new PhantomIsolationListener();
listener.start();
}
public void register() {
getCommand("phantomisolation").setExecutor(new PhantomIsolationCommand());
getCommand("phantomisolationreload").setExecutor(new ReloadCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

public class PhantomIsolationListener implements Listener {
public void start() {
PhantomIsolationSchedulerUtil.runAsyncScheduler(PhantomIsolation2.instance, this::tick, 1, 20);
PhantomIsolationSchedulerUtil.runAsyncScheduler(PhantomIsolation2.instance, this::tick, 1, 1000);
}

public void tick() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (PhantomIsolation2.databaseUtil.getPlayerIsolationStatus(player)) {
int timeSinceRest = player.getStatistic(Statistic.TIME_SINCE_REST);
if (timeSinceRest >= 1200) {
player.setStatistic(Statistic.TIME_SINCE_REST, 0);
if (timeSinceRest >= 100) {
player.setStatistic(Statistic.TIME_SINCE_REST, 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public void loadData() {
while (resultSet.next()) {
String uuid = resultSet.getString("uuid");
boolean status = resultSet.getBoolean("status");
PhantomIsolation2.databaseUtil.setPlayerIsolationStatus(PhantomIsolation2.instance.getServer().getPlayer(UUID.fromString(uuid)), status);
Player player = PhantomIsolation2.instance.getServer().getPlayer(UUID.fromString(uuid));
if (player != null && player.isOnline()) {
PhantomIsolation2.databaseUtil.setPlayerIsolationStatus(player, status);
}
}
}
} catch (SQLException e) {
Expand Down

0 comments on commit 5219007

Please sign in to comment.