Skip to content

Commit

Permalink
Added more API methods for handling data of players
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Aug 5, 2022
1 parent 1d1a952 commit c255a2e
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 35 deletions.
Expand Up @@ -53,6 +53,13 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
*/
void updateLastTimeStatus();

/**
* Set the last time player joined or left the server.
*
* @param lastTimeStatus The time to set.
*/
void setLastTimeStatus(long lastTimeStatus);

/**
* Get the last time player joined or left the server.
*/
Expand All @@ -64,6 +71,12 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
*/
void updateName();

/**
* Set the cached name with the given name.
* When the player will join the server, it will be synced again with his correct name.
*/
void setName(String name);

/**
* Get the player object.
*/
Expand Down Expand Up @@ -299,7 +312,7 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
void setUserLocale(Locale locale);

/**
* Check whether or not the world border is enabled for the player.
* Check whether the world border is enabled for the player.
*/
boolean hasWorldBorderEnabled();

Expand All @@ -308,6 +321,13 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
*/
void toggleWorldBorder();

/**
* Set whether the world border is enabled for the player.
*
* @param enabled true to enable borders.
*/
void setWorldBorderEnabled(boolean enabled);

/**
* Update world border for this player.
*
Expand All @@ -316,17 +336,24 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
void updateWorldBorder(@Nullable Island island);

/**
* Check whether or not the blocks stacker mode is enabled for the player.
* Check whether the blocks-stacker mode is enabled for the player.
*/
boolean hasBlocksStackerEnabled();

/**
* Toggle the blocks stacker for the player.
* Toggle the blocks-stacker for the player.
*/
void toggleBlocksStacker();

/**
* Check whether or not the schematic mode is enabled for the player.
* Set whether the blocks-stacker mode is enabled for the player.
*
* @param enabled true to enable blocks-stacker mode.
*/
void setBlocksStacker(boolean enabled);

/**
* Check whether the schematic mode is enabled for the player.
*/
boolean hasSchematicModeEnabled();

Expand All @@ -336,7 +363,14 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
void toggleSchematicMode();

/**
* Check whether or not the team chat is enabled for the player.
* Set whether the schematic mode is enabled for the player.
*
* @param enabled true to enable schematic mode.
*/
void setSchematicMode(boolean enabled);

/**
* Check whether the team chat is enabled for the player.
*/
boolean hasTeamChatEnabled();

Expand All @@ -346,7 +380,14 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
void toggleTeamChat();

/**
* Check whether or not the bypass mode is enabled for the player.
* Set whether the schematic mode is enabled for the player.
*
* @param enabled true to enable schematic mode.
*/
void setTeamChat(boolean enabled);

/**
* Check whether the bypass mode is enabled for the player.
*/
boolean hasBypassModeEnabled();

Expand All @@ -355,6 +396,13 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
*/
void toggleBypassMode();

/**
* Set whether the bypass mode is enabled for the player.
*
* @param enabled true to enable bypass mode.
*/
void setBypassMode(boolean enabled);

/**
* Check whether or not the player has their panel toggled.
*/
Expand All @@ -366,7 +414,7 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
void setToggledPanel(boolean toggledPanel);

/**
* Set whether or not the player has flying enabled.
* Set whether the player has flying enabled.
*/
boolean hasIslandFlyEnabled();

Expand All @@ -376,7 +424,14 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
void toggleIslandFly();

/**
* Check whether or not the player has admin spy mode enabled.
* Set whether the player has flying enabled.
*
* @param enabled true to enable flying.
*/
void setIslandFly(boolean enabled);

/**
* Check whether the player has admin spy mode enabled.
*/
boolean hasAdminSpyEnabled();

Expand All @@ -385,6 +440,13 @@ public interface SuperiorPlayer extends IMissionsHolder, IPersistentDataHolder,
*/
void toggleAdminSpy();

/**
* Set whether the player has admin spy mode enabled.
*
* @param enabled true to enable admin spy mode.
*/
void setAdminSpy(boolean enabled);

/**
* Get the border color of the player.
*/
Expand Down
Expand Up @@ -195,10 +195,13 @@ public void setTextureValue(@Nonnull String textureValue) {

@Override
public void updateLastTimeStatus() {
lastTimeStatus = System.currentTimeMillis() / 1000;
setLastTimeStatus(System.currentTimeMillis() / 1000);
}

@Override
public void setLastTimeStatus(long lastTimeStatus) {
PluginDebugger.debug("Action: Update Last Time, Player: " + getName() + ", Last Time: " + lastTimeStatus);

this.lastTimeStatus = lastTimeStatus;
PlayersDatabaseBridge.saveLastTimeStatus(this);
}

Expand All @@ -210,16 +213,21 @@ public long getLastTimeStatus() {
@Override
public void updateName() {
Player player = asPlayer();
if (player != null) {
String newName = player.getName();
if (!this.name.equals(newName)) {
try {
plugin.getPlayers().getPlayersContainer().removePlayer(this);
this.name = newName;
PlayersDatabaseBridge.savePlayerName(this);
} finally {
plugin.getPlayers().getPlayersContainer().addPlayer(this);
}
if (player != null)
this.setName(player.getName());
}

@Override
public void setName(String name) {
Preconditions.checkNotNull(name, "name parameter cannot be null.");

if (!this.name.equals(name)) {
try {
plugin.getPlayers().getPlayersContainer().removePlayer(this);
this.name = name;
PlayersDatabaseBridge.savePlayerName(this);
} finally {
plugin.getPlayers().getPlayersContainer().addPlayer(this);
}
}
}
Expand Down Expand Up @@ -490,8 +498,13 @@ public boolean hasWorldBorderEnabled() {

@Override
public void toggleWorldBorder() {
worldBorderEnabled = !worldBorderEnabled;
PluginDebugger.debug("Action: Toggle Border, Player: " + getName() + ", Border: " + worldBorderEnabled);
setWorldBorderEnabled(!worldBorderEnabled);
}

@Override
public void setWorldBorderEnabled(boolean enabled) {
PluginDebugger.debug("Action: Toggle Border, Player: " + getName() + ", Border: " + enabled);
this.worldBorderEnabled = enabled;
PlayersDatabaseBridge.saveToggledBorder(this);
}

Expand All @@ -507,8 +520,13 @@ public boolean hasBlocksStackerEnabled() {

@Override
public void toggleBlocksStacker() {
blocksStackerEnabled = !blocksStackerEnabled;
PluginDebugger.debug("Action: Toggle Stacker, Player: " + getName() + ", Stacker: " + blocksStackerEnabled);
setBlocksStacker(!blocksStackerEnabled);
}

@Override
public void setBlocksStacker(boolean enabled) {
PluginDebugger.debug("Action: Toggle Stacker, Player: " + getName() + ", Stacker: " + enabled);
blocksStackerEnabled = enabled;
}

@Override
Expand All @@ -518,8 +536,13 @@ public boolean hasSchematicModeEnabled() {

@Override
public void toggleSchematicMode() {
schematicModeEnabled = !schematicModeEnabled;
PluginDebugger.debug("Action: Toggle Schematic, Player: " + getName() + ", Schematic: " + schematicModeEnabled);
setSchematicMode(!schematicModeEnabled);
}

@Override
public void setSchematicMode(boolean enabled) {
PluginDebugger.debug("Action: Toggle Schematic, Player: " + getName() + ", Schematic: " + enabled);
schematicModeEnabled = enabled;
}

@Override
Expand All @@ -529,8 +552,13 @@ public boolean hasTeamChatEnabled() {

@Override
public void toggleTeamChat() {
teamChatEnabled = !teamChatEnabled;
PluginDebugger.debug("Action: Toggle Chat, Player: " + getName() + ", Chat: " + teamChatEnabled);
setTeamChat(!teamChatEnabled);
}

@Override
public void setTeamChat(boolean enabled) {
PluginDebugger.debug("Action: Toggle Chat, Player: " + getName() + ", Chat: " + enabled);
teamChatEnabled = enabled;
}

@Override
Expand All @@ -545,8 +573,13 @@ public boolean hasBypassModeEnabled() {

@Override
public void toggleBypassMode() {
bypassModeEnabled = !bypassModeEnabled;
PluginDebugger.debug("Action: Toggle Bypass, Player: " + getName() + ", Bypass: " + bypassModeEnabled);
setBypassMode(!bypassModeEnabled);
}

@Override
public void setBypassMode(boolean enabled) {
PluginDebugger.debug("Action: Toggle Bypass, Player: " + getName() + ", Bypass: " + enabled);
bypassModeEnabled = enabled;
}

@Override
Expand Down Expand Up @@ -578,8 +611,13 @@ public boolean hasIslandFlyEnabled() {

@Override
public void toggleIslandFly() {
islandFly = !islandFly;
PluginDebugger.debug("Action: Toggle Fly, Player: " + getName() + ", Fly: " + islandFly);
setIslandFly(!islandFly);
}

@Override
public void setIslandFly(boolean enabled) {
PluginDebugger.debug("Action: Toggle Fly, Player: " + getName() + ", Fly: " + enabled);
islandFly = enabled;
PlayersDatabaseBridge.saveIslandFly(this);
}

Expand All @@ -590,8 +628,13 @@ public boolean hasAdminSpyEnabled() {

@Override
public void toggleAdminSpy() {
adminSpyEnabled = !adminSpyEnabled;
PluginDebugger.debug("Action: Toggle Spy, Player: " + getName() + ", Spy: " + adminSpyEnabled);
setAdminSpy(!adminSpyEnabled);
}

@Override
public void setAdminSpy(boolean enabled) {
PluginDebugger.debug("Action: Toggle Spy, Player: " + getName() + ", Spy: " + enabled);
adminSpyEnabled = enabled;
}

@Override
Expand Down

0 comments on commit c255a2e

Please sign in to comment.