Skip to content

Commit 21d964c

Browse files
committed
Start working on global requirements.
1 parent 0ce74be commit 21d964c

12 files changed

Lines changed: 390 additions & 77 deletions

File tree

Settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ sql:
5050
username: root
5151
password: ''
5252
database: minecraft
53-
table: autorank
53+
server name: '%name%-default'
5454
# All these options are for configuring your MySQL database with Autorank.
5555
# Hostname has to include a port, but doesn't have to be port 3306.
5656

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors: [Staartvin, Armarr]
66
softdepend: [Vault, GroupManager, Privileges, bPermissions, PermissionsEx, PermissionsBukkit, DroxPerms, PowerfulPerms, Statz]
77
depend: [PluginLibrary]
88
description: Reward players based on their stats.
9-
api-version: 1.14
9+
api-version: 1.15
1010
commands:
1111
autorank:
1212
description: Master command of AutoRank

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@
9595
<dependency>
9696
<groupId>org.spigotmc</groupId>
9797
<artifactId>spigot-api</artifactId>
98-
<version>1.14.4-R0.1-SNAPSHOT</version>
98+
<version>1.15-R0.1-SNAPSHOT</version>
9999
<type>jar</type>
100100
</dependency>
101101

102102
<dependency>
103103
<groupId>org.bukkit</groupId>
104104
<artifactId>bukkit</artifactId>
105-
<version>1.14.4-R0.1-SNAPSHOT</version>
105+
<version>1.15-R0.1-SNAPSHOT</version>
106106
</dependency>
107107

108108
<dependency>

src/me/armar/plugins/autorank/Autorank.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import me.armar.plugins.autorank.pathbuilder.PathManager;
1919
import me.armar.plugins.autorank.pathbuilder.builders.RequirementBuilder;
2020
import me.armar.plugins.autorank.pathbuilder.builders.ResultBuilder;
21-
import me.armar.plugins.autorank.pathbuilder.config.PlayerDataConfig;
21+
import me.armar.plugins.autorank.pathbuilder.playerdata.global.GlobalPlayerDataStorage;
22+
import me.armar.plugins.autorank.pathbuilder.playerdata.local.LocalPlayerDataStorage;
2223
import me.armar.plugins.autorank.pathbuilder.requirement.*;
2324
import me.armar.plugins.autorank.pathbuilder.result.*;
2425
import me.armar.plugins.autorank.permissions.PermissionsPluginManager;
@@ -96,7 +97,10 @@ public class Autorank extends JavaPlugin {
9697
private InternalPropertiesConfig internalPropertiesConfig;
9798
private PathsConfig pathsConfig;
9899
private DefaultBehaviorConfig defaultBehaviorConfig;
99-
private PlayerDataConfig playerDataConfig;
100+
101+
// Data storage
102+
private LocalPlayerDataStorage localPlayerDataStorage;
103+
private GlobalPlayerDataStorage globalPlayerDataStorage;
100104

101105
public static Autorank getInstance() {
102106
return autorank;
@@ -149,14 +153,17 @@ public void onEnable() {
149153
setSettingsConfig(new SettingsConfig(this));
150154
setInternalPropertiesConfig(new InternalPropertiesConfig(this));
151155
setDefaultBehaviorConfig(new DefaultBehaviorConfig((this)));
152-
setPlayerData(new PlayerDataConfig(this));
156+
157+
// Load data storages
158+
setLocalPlayerDataStorage(new LocalPlayerDataStorage(this));
159+
// setGlobalPlayerDataStorage(new GlobalPlayerDataStorage(this));
153160

154161
// Create new configs
155162
this.getDefaultBehaviorConfig().loadConfig();
156163
this.getPathsConfig().loadConfig();
157164
this.getSettingsConfig().loadConfig();
158165
this.getInternalPropertiesConfig().loadConfig();
159-
this.getPlayerData().loadConfig();
166+
this.getLocalPlayerDataStorage().loadConfig();
160167

161168
// ------------- Initialize managers -------------
162169

@@ -791,11 +798,19 @@ public void setTaskManager(TaskManager taskManager) {
791798
this.taskManager = taskManager;
792799
}
793800

794-
public PlayerDataConfig getPlayerData() {
795-
return playerDataConfig;
801+
public LocalPlayerDataStorage getLocalPlayerDataStorage() {
802+
return localPlayerDataStorage;
803+
}
804+
805+
public void setLocalPlayerDataStorage(LocalPlayerDataStorage localPlayerDataStorage) {
806+
this.localPlayerDataStorage = localPlayerDataStorage;
807+
}
808+
809+
public GlobalPlayerDataStorage getGlobalPlayerDataStorage() {
810+
return globalPlayerDataStorage;
796811
}
797812

798-
public void setPlayerData(PlayerDataConfig playerDataConfig) {
799-
this.playerDataConfig = playerDataConfig;
813+
public void setGlobalPlayerDataStorage(GlobalPlayerDataStorage globalPlayerDataStorage) {
814+
this.globalPlayerDataStorage = globalPlayerDataStorage;
800815
}
801816
}

src/me/armar/plugins/autorank/config/SettingsConfig.java

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@
1212
public class SettingsConfig extends AbstractConfig {
1313

1414
/**
15-
* The different type of credentials that is used to connect to a MySQL
16-
* database.
15+
* Get the value of a specific MySQL credential.
16+
*
17+
* @param option Type of credential
18+
* @return the value for the given MySQL credential.
1719
*/
18-
public enum MySQLCredentials {
19-
DATABASE, HOSTNAME, PASSWORD, TABLE, USERNAME
20+
public String getMySQLCredentials(final MySQLCredentials option) {
21+
switch (option) {
22+
case HOSTNAME:
23+
return this.getConfig().getString("sql.hostname");
24+
case USERNAME:
25+
return this.getConfig().getString("sql.username");
26+
case PASSWORD:
27+
return this.getConfig().getString("sql.password");
28+
case DATABASE:
29+
return this.getConfig().getString("sql.database");
30+
case SERVER_NAME:
31+
return this.getConfig().getString("sql.server name", "")
32+
.replace("%ip%", getPlugin().getServer().getIp())
33+
.replace("%port%", getPlugin().getServer().getPort() + "")
34+
.replace("%name%", getPlugin().getServer().getName());
35+
default:
36+
throw new IllegalArgumentException(option + " is not a valid MySQL credential option");
37+
}
2038
}
2139

2240
public SettingsConfig(final Autorank instance) {
@@ -85,26 +103,13 @@ public int getLeaderboardLength() {
85103
}
86104

87105
/**
88-
* Get the value of a specific MySQL credential.
106+
* Check whether Autorank should broadcast a message to all online players
107+
* when a {@link me.armar.plugins.autorank.storage.TimeType} file is reset.
89108
*
90-
* @param option Type of credential
91-
* @return the value for the given MySQL credential.
109+
* @return true if Autorank should notice all players. False otherwise.
92110
*/
93-
public String getMySQLCredentials(final MySQLCredentials option) {
94-
switch (option) {
95-
case HOSTNAME:
96-
return this.getConfig().getString("sql.hostname");
97-
case USERNAME:
98-
return this.getConfig().getString("sql.username");
99-
case PASSWORD:
100-
return this.getConfig().getString("sql.password");
101-
case DATABASE:
102-
return this.getConfig().getString("sql.database");
103-
case TABLE:
104-
return this.getConfig().getString("sql.table");
105-
default:
106-
throw new IllegalArgumentException(option + " is not a valid MySQL credential option");
107-
}
111+
public boolean shouldBroadcastDataReset() {
112+
return this.getConfig().getBoolean("broadcast resetting of data files", true);
108113
}
109114

110115
/**
@@ -128,13 +133,11 @@ public boolean onlyUsePrimaryGroupVault() {
128133
}
129134

130135
/**
131-
* Check whether Autorank should broadcast a message to all online players
132-
* when a {@link TimeType} file is reset.
133-
*
134-
* @return true if Autorank should notice all players. False otherwise.
136+
* The different type of credentials that is used to connect to a MySQL
137+
* database.
135138
*/
136-
public boolean shouldBroadcastDataReset() {
137-
return this.getConfig().getBoolean("broadcast resetting of data files", true);
139+
public enum MySQLCredentials {
140+
DATABASE, HOSTNAME, PASSWORD, SERVER_NAME, USERNAME
138141
}
139142

140143
/**

src/me/armar/plugins/autorank/listeners/PlayerJoinListener.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
9393

9494
private void performPendingResults(Player player) {
9595
// First perform all results when the player has joined a path
96-
List<String> joinedPaths = plugin.getPlayerData().getChosenPathsMissingResults(player.getUniqueId());
96+
List<String> joinedPaths =
97+
plugin.getLocalPlayerDataStorage().getChosenPathsMissingResults(player.getUniqueId());
9798

9899
for (String pathName : joinedPaths) {
99100
Path path = plugin.getPathManager().findPathByInternalName(pathName, false);
@@ -102,27 +103,27 @@ private void performPendingResults(Player player) {
102103
path.performResultsUponChoosing(player);
103104
}
104105

105-
plugin.getPlayerData().removeChosenPathMissingResults(player.getUniqueId(), pathName);
106+
plugin.getLocalPlayerDataStorage().removeChosenPathMissingResults(player.getUniqueId(), pathName);
106107
}
107108

108109
// Then perform results when a player has completed a requirement.
109110
for (Path path : plugin.getPathManager().getAllPaths()) {
110111
List<Integer> completedRequirements =
111-
plugin.getPlayerData().getCompletedRequirementsMissingResults(player.getUniqueId(),
112+
plugin.getLocalPlayerDataStorage().getCompletedRequirementsMissingResults(player.getUniqueId(),
112113
path.getInternalName());
113114

114115
for (int requirementId : completedRequirements) {
115116
path.completeRequirement(player.getUniqueId(), requirementId);
116117

117-
plugin.getPlayerData().removeCompletedRequirementMissingResults(player.getUniqueId(),
118+
plugin.getLocalPlayerDataStorage().removeCompletedRequirementMissingResults(player.getUniqueId(),
118119
path.getInternalName(), requirementId);
119120
}
120121
}
121122

122123

123124
// Lastly perform results when a player has completed a path.
124125
List<String> completedPaths =
125-
plugin.getPlayerData().getCompletedPathsMissingResults(player.getUniqueId());
126+
plugin.getLocalPlayerDataStorage().getCompletedPathsMissingResults(player.getUniqueId());
126127

127128
for (String pathName : completedPaths) {
128129
Path path = plugin.getPathManager().findPathByInternalName(pathName, false);
@@ -133,7 +134,7 @@ private void performPendingResults(Player player) {
133134

134135
System.out.println("Performing result of path " + pathName);
135136

136-
plugin.getPlayerData().removeCompletedPathMissingResults(player.getUniqueId(), pathName);
137+
plugin.getLocalPlayerDataStorage().removeCompletedPathMissingResults(player.getUniqueId(), pathName);
137138
}
138139

139140

src/me/armar/plugins/autorank/pathbuilder/PathManager.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import me.armar.plugins.autorank.Autorank;
44
import me.armar.plugins.autorank.language.Lang;
55
import me.armar.plugins.autorank.pathbuilder.builders.PathBuilder;
6-
import me.armar.plugins.autorank.pathbuilder.config.PlayerDataConfig;
76
import me.armar.plugins.autorank.pathbuilder.holders.CompositeRequirement;
7+
import me.armar.plugins.autorank.pathbuilder.playerdata.local.LocalPlayerDataStorage;
88
import me.armar.plugins.autorank.pathbuilder.result.AbstractResult;
99
import org.bukkit.Bukkit;
1010
import org.bukkit.OfflinePlayer;
@@ -103,7 +103,7 @@ public void setBuilder(final PathBuilder builder) {
103103
* @return paths that a player has chosen and is currently on.
104104
*/
105105
public List<Path> getActivePaths(UUID uuid) {
106-
Collection<String> activePathNames = plugin.getPlayerData().getActivePaths(uuid);
106+
Collection<String> activePathNames = plugin.getLocalPlayerDataStorage().getActivePaths(uuid);
107107

108108
List<Path> activePaths = new ArrayList<>();
109109

@@ -126,7 +126,7 @@ public List<Path> getActivePaths(UUID uuid) {
126126
* @param uuid UUID of the player.
127127
*/
128128
public void resetProgressOnActivePaths(UUID uuid) {
129-
plugin.getPlayerData().setActivePaths(uuid, new ArrayList<>());
129+
plugin.getLocalPlayerDataStorage().setActivePaths(uuid, new ArrayList<>());
130130
}
131131

132132
/**
@@ -137,8 +137,8 @@ public void resetProgressOnActivePaths(UUID uuid) {
137137
* @param path Path to reset progress of.
138138
*/
139139
public void resetProgressOfPath(Path path, UUID uuid) {
140-
plugin.getPlayerData().setCompletedPrerequisites(uuid, path.getInternalName(), new ArrayList<>());
141-
plugin.getPlayerData().setCompletedRequirements(uuid, path.getInternalName(), new ArrayList<>());
140+
plugin.getLocalPlayerDataStorage().setCompletedPrerequisites(uuid, path.getInternalName(), new ArrayList<>());
141+
plugin.getLocalPlayerDataStorage().setCompletedRequirements(uuid, path.getInternalName(), new ArrayList<>());
142142
}
143143

144144
/**
@@ -147,8 +147,8 @@ public void resetProgressOfPath(Path path, UUID uuid) {
147147
* @param uuid UUID of the player
148148
*/
149149
public void resetActivePaths(UUID uuid) {
150-
for (String activePathName : plugin.getPlayerData().getActivePaths(uuid)) {
151-
plugin.getPlayerData().removeActivePath(uuid, activePathName);
150+
for (String activePathName : plugin.getLocalPlayerDataStorage().getActivePaths(uuid)) {
151+
plugin.getLocalPlayerDataStorage().removeActivePath(uuid, activePathName);
152152
}
153153
}
154154

@@ -161,7 +161,7 @@ public void resetActivePaths(UUID uuid) {
161161
* @return a list of paths a player has completed.
162162
*/
163163
public List<Path> getCompletedPaths(UUID uuid) {
164-
Collection<String> completedPathsNames = plugin.getPlayerData().getCompletedPaths(uuid);
164+
Collection<String> completedPathsNames = plugin.getLocalPlayerDataStorage().getCompletedPaths(uuid);
165165

166166
List<Path> completedPaths = new ArrayList<>();
167167

@@ -184,8 +184,8 @@ public List<Path> getCompletedPaths(UUID uuid) {
184184
* @param uuid UUID of the player
185185
*/
186186
public void resetCompletedPaths(UUID uuid) {
187-
for (String completedPath : plugin.getPlayerData().getCompletedPaths(uuid)) {
188-
plugin.getPlayerData().removeCompletedPath(uuid, completedPath);
187+
for (String completedPath : plugin.getLocalPlayerDataStorage().getCompletedPaths(uuid)) {
188+
plugin.getLocalPlayerDataStorage().removeCompletedPath(uuid, completedPath);
189189
}
190190
}
191191

@@ -198,7 +198,7 @@ public void resetCompletedPaths(UUID uuid) {
198198
* @param reqId Id of the requirement.
199199
*/
200200
public void addCompletedRequirement(UUID uuid, Path path, int reqId) {
201-
plugin.getPlayerData().addCompletedRequirement(uuid, path.getInternalName(), reqId);
201+
plugin.getLocalPlayerDataStorage().addCompletedRequirement(uuid, path.getInternalName(), reqId);
202202
}
203203

204204
/**
@@ -210,7 +210,7 @@ public void addCompletedRequirement(UUID uuid, Path path, int reqId) {
210210
* @return true if the player has completed the requirement, false otherwise.
211211
*/
212212
public boolean hasCompletedRequirement(UUID uuid, Path path, int reqId) {
213-
return plugin.getPlayerData().hasCompletedRequirement(uuid, path.getInternalName(), reqId);
213+
return plugin.getLocalPlayerDataStorage().hasCompletedRequirement(uuid, path.getInternalName(), reqId);
214214
}
215215

216216
/**
@@ -341,15 +341,15 @@ public void assignPath(Path path, UUID uuid, boolean byForce) throws IllegalArgu
341341
String internalName = path.getInternalName();
342342

343343
// Add path as an active path.
344-
plugin.getPlayerData().addActivePath(uuid, internalName);
344+
plugin.getLocalPlayerDataStorage().addActivePath(uuid, internalName);
345345

346346
// Only reset progress if there was no progress stored.
347347
if (!path.shouldStoreProgressOnDeactivation()) {
348348
// Reset progress of requirements
349-
plugin.getPlayerData().setCompletedRequirements(uuid, internalName, new ArrayList<>());
349+
plugin.getLocalPlayerDataStorage().setCompletedRequirements(uuid, internalName, new ArrayList<>());
350350

351351
// Reset progress of prerequisites for a path.
352-
plugin.getPlayerData().setCompletedPrerequisites(uuid, internalName, new ArrayList<>());
352+
plugin.getLocalPlayerDataStorage().setCompletedPrerequisites(uuid, internalName, new ArrayList<>());
353353
}
354354

355355
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
@@ -383,7 +383,7 @@ public void deassignPath(Path path, UUID uuid) {
383383
}
384384

385385
// Remove active path of a player.
386-
plugin.getPlayerData().removeActivePath(uuid, path.getInternalName());
386+
plugin.getLocalPlayerDataStorage().removeActivePath(uuid, path.getInternalName());
387387
}
388388

389389
/**
@@ -435,10 +435,10 @@ public List<Path> autoAssignPaths(UUID uuid) {
435435
public boolean completePath(Path path, UUID uuid) {
436436

437437
// Add progress of completed requirements
438-
plugin.getPlayerData().addCompletedPath(uuid, path.getInternalName());
438+
plugin.getLocalPlayerDataStorage().addCompletedPath(uuid, path.getInternalName());
439439

440440
// Remove path from active paths.
441-
plugin.getPlayerData().removeActivePath(uuid, path.getInternalName());
441+
plugin.getLocalPlayerDataStorage().removeActivePath(uuid, path.getInternalName());
442442

443443
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
444444

@@ -464,9 +464,9 @@ public boolean completePath(Path path, UUID uuid) {
464464
/**
465465
* Get the storage of player data regarding paths and requirements.
466466
*
467-
* @return {@link PlayerDataConfig} object.
467+
* @return {@link LocalPlayerDataStorage} object.
468468
*/
469-
protected PlayerDataConfig getPlayerDataStorage() {
470-
return plugin.getPlayerData();
469+
protected LocalPlayerDataStorage getPlayerDataStorage() {
470+
return plugin.getLocalPlayerDataStorage();
471471
}
472472
}

0 commit comments

Comments
 (0)