Skip to content

Commit

Permalink
If the prev ip is the same as the current IP skip pin login
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Jul 19, 2024
1 parent 87ed5a7 commit 043b398
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.nookure.staff.api.config.bukkit.BukkitConfig;
import com.nookure.staff.api.config.bukkit.BukkitMessages;
import com.nookure.staff.api.manager.PlayerWrapperManager;
import com.nookure.staff.api.model.PinModel;
import com.nookure.staff.api.state.PinState;
import com.nookure.staff.api.util.NumberUtils;
import com.nookure.staff.api.util.TextUtils;
import com.nookure.staff.paper.PaperPlayerWrapper;
import com.nookure.staff.paper.inventory.InventoryList;
import io.ebean.Database;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -31,6 +33,8 @@ public class PinTask implements Runnable {
private ConfigurationContainer<BukkitMessages> messages;
@Inject
private JavaPlugin plugin;
@Inject
private AtomicReference<Database> database;

@Override
public void run() {
Expand All @@ -50,6 +54,18 @@ private void check(PlayerWrapper wrapper, @NotNull PinState pinState) {
if (pinState.isLogin()) return;
if (pinState.isPinInventoryOpen()) return;

PinModel model = database.get().find(PinModel.class)
.where()
.eq("player", wrapper.getPlayerModel())
.findOne();

if (model != null) {
if (model.ip().equals(wrapper.getPlayerModel().getLastIp())) {
pinState.setLogin(true);
return;
}
}

if (pinState.isPinSet()) {
engine.get().openAsync(player, InventoryList.ENTER_PIN, "player", player, "pinSize", pinState.getPin().length());
pinState.setPinInventoryOpen(true);
Expand Down

0 comments on commit 043b398

Please sign in to comment.