Skip to content

Commit

Permalink
Merge branch 'feature/staff-pin' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 authored Jul 23, 2024
2 parents 788e6b8 + 043b398 commit 152edae
Show file tree
Hide file tree
Showing 31 changed files with 1,241 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public final class Permissions {

public static final String STAFF_NOTES_EDIT = "nookure.staff.notes.edit";

/**
* Permission to use set pin command
*/
public static final String SET_PIN_PERMISSION = "nookure.staff.setpin";

private Permissions() {
throw new UnsupportedOperationException("This class cannot be instantiated");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.nookure.staff.api.command.CommandSender;
import com.nookure.staff.api.model.PlayerModel;
import org.jetbrains.annotations.Contract;
import com.nookure.staff.api.state.PlayerState;
import com.nookure.staff.api.state.WrapperState;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
Expand Down Expand Up @@ -33,11 +35,42 @@ public interface PlayerWrapper extends Serializable, CommandSender {
*/
void teleport(@NotNull PlayerWrapper to);

/**
* Kick the player from the server.
*
* @param reason the reason for the kick
*/
void kick(@NotNull String reason);

/**
* Kick the player from the server.
*
* @param reason the reason for the kick
*/
void kick(@NotNull Component reason);

/**
* Get the player's model.
*
* @throws IllegalStateException if the player's model feature is disabled
* @return the player's model
* @throws IllegalStateException if the player's model feature is disabled
*/
PlayerModel getPlayerModel();

/**
* Get the player's state.
*
* @return the player's state
*/
@NotNull
WrapperState getState();

/**
* Check if the player has a state.
*
* @param clazz the class of the state
*/
default boolean hasState(Class<? extends PlayerState> clazz) {
return getState().hasState(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class BukkitMessages {
public FreezeMessagePartial freeze = new FreezeMessagePartial();
public StaffChatPartial staffChat = new StaffChatPartial();
public PlaceholderPartial placeholder = new PlaceholderPartial();
public PinMessagePartial pin = new PinMessagePartial();

@Setting
@Comment(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public class ModulesPartials {
""")
private boolean vanish = true;

@Setting
@Comment("""
Enable or disable the invsee module.
This include /invsee command
""")
private boolean invsee = true;

@Setting
@Comment("""
Enable or disable the StaffChat module.
Expand Down Expand Up @@ -69,6 +62,14 @@ public class ModulesPartials {
""")
private boolean playerList = true;

@Setting
@Comment("""
Enable or disable the pin code module.
This will allow you to set a pin code to the staff's accounts
and use it to login.
""")
private final boolean pinCode = false;

public boolean isStaffMode() {
return staffMode;
}
Expand All @@ -81,10 +82,6 @@ public boolean isVanish() {
return vanish;
}

public boolean isInvsee() {
return invsee;
}

public boolean isStaffChat() {
return staffChat;
}
Expand All @@ -100,4 +97,8 @@ public boolean isUserNotes() {
public boolean isPlayerList() {
return playerList;
}

public boolean isPinCode() {
return pinCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public class StaffModePartial {
""")
private VanishType vanishType = VanishType.INTERNAL_VANISH;

@Setting
@Comment("""
Time to create a PIN code, before the player is kick
""")
private final String pinTime = "60s";

public boolean silentChestOpen() {
return silentChestOpen;
}
Expand Down Expand Up @@ -111,4 +117,8 @@ public boolean actionBar() {
public VanishType vanishType() {
return vanishType;
}

public String pinTime() {
return pinTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.nookure.staff.api.config.bukkit.partials.messages;

import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Setting;

@ConfigSerializable
public class PinMessagePartial {
@Setting
public final String thePinIsIncorrect = "<red>The PIN is incorrect.";
@Setting
public final String correctPin = "<green>The PIN is correct.";
@Setting
public final String pinSet = "<green>Your PIN has been set to {pin}.";
@Setting
public final String youMustHaveToSetAPin = """
{center}<bold>◆ <red>Nookure <white>Network</white> ◆</bold>
{center}<gray>You <red>must</red> have to set a <red>PIN</red> before you can play on this server.
{center}<gray>Use <red><u><click:run_command:'/setpin'>/setpin</click></u></red> to set a PIN.
{center}<gray>You have {time} to set a PIN.
""";
@Setting
public final String pinTimeExpired = "<red>Your time to set a PIN has expired.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Use {@link #connect(DatabaseConfig, ClassLoader)} to connect to the database.
*/
public abstract class AbstractPluginConnection {
public static final String DATABASE_NAME = "nkstaff";
/**
* Connects to the database.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.time.Instant;

import static com.nookure.staff.api.database.AbstractPluginConnection.DATABASE_NAME;

@MappedSuperclass
public class BaseDomain extends Model {
@Id
Expand All @@ -21,7 +23,7 @@ public class BaseDomain extends Model {
Instant whenModified;

public BaseDomain() {
super("nkstaff");
super(DATABASE_NAME);
}

public Long getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.nookure.staff.api.model;

import io.ebean.Model;
import jakarta.persistence.*;

import java.time.Instant;

@Entity
@Table(name = "nookure_staff_pin")
public class PinModel extends Model {
@Id
Long id;
@OneToOne
PlayerModel player;
@Column(nullable = false, length = 64)
String pin;
@Column(nullable = false)
Instant lastLogin;
@Column(nullable = false, length = 15)
String ip;

public PinModel() {
super("nkstaff");
}

public String ip() {
return ip;
}

public PinModel setIp(String ip) {
this.ip = ip;
return this;
}

public String pin() {
return pin;
}

public PinModel setPin(String pin) {
this.pin = pin;
return this;
}

public PlayerModel player() {
return player;
}

public PinModel setPlayer(PlayerModel player) {
this.player = player;
return this;
}

public Long id() {
return id;
}

public Instant lastLogin() {
return lastLogin;
}

public PinModel setLastLogin(Instant lastLogin) {
this.lastLogin = lastLogin;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.nookure.staff.api.service;

import com.nookure.staff.api.model.PlayerModel;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

/**
* This service is responsible for handling the pin user server.
*/
public interface PinUserService {
/**
* Check if the pin is valid for the player.
*
* @param uuid the player to check
* @param pin the pin to check
* @return true if the pin is valid, false otherwise
*/
boolean isValid(@NotNull UUID uuid, @NotNull String pin);

/**
* Check if the pin is valid for the player.
*
* @param player the player to check
* @param pin the pin to check
* @return true if the pin is valid, false otherwise
*/
boolean isValid(@NotNull PlayerModel player, @NotNull String pin);

/**
* Set the pin for the player.
*
* @param player the player to set the pin
* @param pin the pin to set
*/
void setPin(@NotNull PlayerModel player, @NotNull String pin);

/**
* Check if the player has a pin set.
*
* @param player the player to check
* @return true if the player has a pin set, false otherwise
*/
boolean isPinSet(@NotNull PlayerModel player);

void updateIp(@NotNull PlayerModel player);
}
Loading

0 comments on commit 152edae

Please sign in to comment.