Skip to content

Commit

Permalink
Commentary updated
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanOff committed Jan 5, 2021
1 parent 9419860 commit 73bc6a4
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 40 deletions.
17 changes: 12 additions & 5 deletions com/gaetan/staffpin/StaffPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
import java.util.Map;

public final class StaffPlugin extends GCore {
/**
* Map to stock the PayerData
*/
private final Map<Player, PlayerData> players = Maps.newConcurrentMap();

/**
* Same as the classic onEnable.
* Method to launch the plugin
* Note: This is the same as the classic onEnable
*/
@Override
protected void onPluginStart() {
this.registerCommands(new PinCommand(this));
}

/**
* This is trigger when the server finished loading.
* This is trigger when the server finished loading
*/
@Override
protected void onPluginLoad() {
Expand All @@ -32,7 +36,7 @@ protected void onPluginLoad() {
}

/**
* Register listener.
* Method to register listener
*/
@Override
protected void registerListener() {
Expand All @@ -41,16 +45,19 @@ protected void registerListener() {
}

/**
* Get a PlayerData of a Player.
* Getter to get the PlayerData of a specific player.
*
* @param player player
* @return The PlayerData of the choosen player
*/
public PlayerData getPlayer(final Player player) {
return this.players.get(player);
}

/**
* Getter for the PlayerData.
* Getter to get the Map of all PlayerData.
*
* @return The PlayerData of the choosen player
*/
public Map<Player, PlayerData> getPlayers() {
return this.players;
Expand Down
17 changes: 10 additions & 7 deletions com/gaetan/staffpin/command/PinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@
import org.bukkit.entity.Player;

public final class PinCommand {
/**
* Reference to the main class
*/
private final StaffPlugin staffPlugin;

/**
* Constructor for the PinCommand class.
*
* @param staffPlugin reference to the main class
* @param staffPlugin Reference to the main class
*/
public PinCommand(final StaffPlugin staffPlugin) {
this.staffPlugin = staffPlugin;
}

/**
* Show the global usage message.
* Command to show the usage message.
*
* @param context command argument
* @param context The command argument
*/
@Command(name = "pin", permission = "pin.use", target = CommandTarget.PLAYER)
public void handleCommand(final Context<ConsoleCommandSender> context) {
this.usage((Player) context.getSender());
}

/**
* Set your pin.
* Command to set your pin.
*
* @param context command argument
* @param context The command argument
*/
@Command(name = "pin.set", permission = "pin.use", target = CommandTarget.PLAYER)
public void handleCommand_Set(final Context<ConsoleCommandSender> context, final String pin) {
Expand All @@ -47,9 +50,9 @@ public void handleCommand_Set(final Context<ConsoleCommandSender> context, final
}

/**
* Send the help message.
* Method to send the help message.
*
* @param player player to send the help message
* @param player The player to send the message
*/
private void usage(final Player player) {
Message.tell(player, new String[]{
Expand Down
56 changes: 35 additions & 21 deletions com/gaetan/staffpin/data/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public final class PlayerData {
/**
* Constructor for the PlayerData class.
*
* @param player the object of this player
* @param staffPlugin refeference to the main class
* @param player The data of this player
* @param staffPlugin Reference to the main class
*/
public PlayerData(final Player player, final StaffPlugin staffPlugin) {
this.staffPlugin = staffPlugin;
Expand All @@ -34,21 +34,21 @@ public PlayerData(final Player player, final StaffPlugin staffPlugin) {
}

/**
* Save the pin in a config.
* Method to save the pin in a config
*/
private void save() {
this.staffPlugin.getServer().getScheduler().runTaskAsynchronously(this.staffPlugin, new SavePlayerConfig(this.staffPlugin, this));
}

/**
* Load the pin from the config.
* Method to load the pin from the config and cache-it
*/
public void load() {
this.staffPlugin.getServer().getScheduler().runTaskAsynchronously(this.staffPlugin, new LoadPlayerConfig(this.staffPlugin, this));
}

/**
* When player join the server.
* Method when player join the server
*/
public void join() {
this.load();
Expand All @@ -70,7 +70,7 @@ public void join() {
}

/**
* When player enter the correct code in the chat.
* Method when player enter the correct code in the chat
*/
public void correct() {
Message.tell(this.player, Lang.ENTER_SUCESS.getText());
Expand All @@ -86,7 +86,7 @@ public void correct() {
}

/**
* Launch the pin cooldown.
* Method to launch the pin cooldown
*/
private void pinCooldown() {
TaskUtil.runLater(() -> {
Expand All @@ -97,7 +97,7 @@ private void pinCooldown() {
}

/**
* When player left the server.
* Method when player left the server
*/
public void leave() {
if (this.inventory != null) {
Expand All @@ -109,16 +109,16 @@ public void leave() {
}

/**
* Clear player inventory.
* Method to clear player inventory
*/
public void clearInventory() {
PlayerUtil.clearInventory(this.player);
}

/**
* Set the pin and save it.
* Setter to set the pin and save it.
*
* @param pin the pin of the player
* @param pin The new pin
*/
public void setPin(final String pin) {
this.pin = pin;
Expand All @@ -127,66 +127,80 @@ public void setPin(final String pin) {

/**
* Get the reference for the Player of this data.
*
* @return The reference for the Player
*/
public Player getPlayer() {
return this.player;
}

/**
* Get the pin.
* Getter to get the pin.
*
* @return The player pin
*/
public String getPin() {
return this.pin;
}

/**
* Set the player login.
* Setter to set if player is login or not.
*
* @param login state of his login
* @param login The state of his login
*/
public void setLogin(final boolean login) {
this.login = login;
}

/**
* Get if the player is login.
* Getter to get if the player is login.
*
* @return If the player is login
*/
public boolean isLogin() {
return this.login;
}

/**
* Set the player last inventory.
* Setter to set the last player inventory.
*
* @param inventory last inventory
* @param inventory The last player inventory
*/
public void setInventory(final ItemStack[] inventory) {
this.inventory = inventory;
}

/**
* Get the player last inventory.
* Getter to get the last player inventory.
*
* @return The last player inventory
*/
public ItemStack[] getInventory() {
return this.inventory;
}

/**
* Get the player last armor.
* Getter to get the last player armor.
*
* @return The last player armor
*/
public ItemStack[] getArmor() {
return this.armor;
}

/**
* Get the player last location.
* Getter to get the last player location.
*
* @return The last player location
*/
public Location getLocation() {
return this.location;
}

/**
* Get the player last gamemode.
* Getter to get the last player gamemode.
*
* @return The last player gamemode
*/
public GameMode getGameMode() {
return this.gameMode;
Expand Down
5 changes: 5 additions & 0 deletions com/gaetan/staffpin/enums/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public enum Lang {

private final String text;

/**
* Getter to get the text.
*
* @return The choosen text
*/
public String getText() {
return this.text;
}
Expand Down
5 changes: 4 additions & 1 deletion com/gaetan/staffpin/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import org.bukkit.event.player.PlayerQuitEvent;

public final class PlayerListener implements Listener {
/**
* Reference to the main class
*/
private final StaffPlugin staffPlugin;

/**
* Constructor for the PlayerListener class.
*
* @param staffPlugin reference to te main class
* @param staffPlugin Reference to te main class
*/
public PlayerListener(final StaffPlugin staffPlugin) {
this.staffPlugin = staffPlugin;
Expand Down
13 changes: 10 additions & 3 deletions com/gaetan/staffpin/runnable/LoadPlayerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
import java.io.File;

public final class LoadPlayerConfig implements Runnable {
/**
* Reference to the main class
*/
private final StaffPlugin staffPlugin;

/**
* Reference to the PlayerData
*/
private final PlayerData playerData;

/**
* Constructor for the LoadPlayerConfig runnable.
*
* @param staffPlugin refeference to the main class
* @param playerData the reference of the data
* @param staffPlugin Reference to the main class
* @param playerData Reference to the PlayerData
*/
public LoadPlayerConfig(final StaffPlugin staffPlugin, final PlayerData playerData) {
this.staffPlugin = staffPlugin;
Expand All @@ -29,7 +36,7 @@ public void run() {
if (new File(this.staffPlugin.getDataFolder() + "/players", this.playerData.getPlayer().getUniqueId().toString() + ".yml").exists()) {
final ConfigUtil config = new ConfigUtil(this.staffPlugin, "/players", this.playerData.getPlayer().getUniqueId().toString());
this.playerData.setPin(config.getConfig().get("pin.string").toString());

TaskUtil.run(() -> Message.tell(this.playerData.getPlayer(), Lang.ENTER_PING.getText()));
} else {
this.playerData.setLogin(true);
Expand Down
5 changes: 4 additions & 1 deletion com/gaetan/staffpin/runnable/MoveRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import org.bukkit.scheduler.BukkitRunnable;

public final class MoveRunnable extends BukkitRunnable {
/**
* Reference to the main class
*/
private final StaffPlugin staffPlugin;

/**
* Constructor for the MoveRunnable runnable.
*
* @param staffPlugin refeference to the main class
* @param staffPlugin Reference to the main class
*/
public MoveRunnable(final StaffPlugin staffPlugin) {
this.staffPlugin = staffPlugin;
Expand Down
11 changes: 9 additions & 2 deletions com/gaetan/staffpin/runnable/SavePlayerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
import com.gaetan.staffpin.data.PlayerData;

public final class SavePlayerConfig implements Runnable {
/**
* Reference to the main class
*/
private final StaffPlugin staffPlugin;

/**
* Reference to the PlayerData
*/
private final PlayerData playerData;

/**
* Constructor for the SavePlayerConfig runnable.
*
* @param staffPlugin refeference to the main class
* @param playerData the reference of the data
* @param staffPlugin Reference to the main class
* @param playerData Reference to the PlayerData
*/
public SavePlayerConfig(final StaffPlugin staffPlugin, final PlayerData playerData) {
this.staffPlugin = staffPlugin;
Expand Down

0 comments on commit 73bc6a4

Please sign in to comment.