generated from Alathra/Template-Gradle-Plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Alathra/feat/db-testing-commands
Feat/db testing commands
- Loading branch information
Showing
7 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/io/github/alathra/alathraskills/db/testing/TestGetExerienceCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.github.alathra.alathraskills.db.testing; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import com.github.milkdrinkers.colorparser.ColorParser; | ||
|
||
import dev.jorel.commandapi.CommandAPICommand; | ||
import dev.jorel.commandapi.arguments.IntegerArgument; | ||
import dev.jorel.commandapi.executors.CommandArguments; | ||
import io.github.alathra.alathraskills.db.DatabaseQueries; | ||
|
||
public class TestGetExerienceCommand { | ||
|
||
public TestGetExerienceCommand() { | ||
new CommandAPICommand("testGetExperience") | ||
.withArguments(new IntegerArgument("skillCategoryID")) | ||
.withFullDescription("Get Experience For a Given Skill Category.") | ||
.withShortDescription("Get Experience") | ||
.withPermission("example.command") | ||
.executesPlayer(this::runCommand) | ||
.register(); | ||
} | ||
|
||
private void runCommand(Player player, CommandArguments args) { | ||
if (args.get("skillCategoryID") == null) { | ||
player.sendMessage( | ||
ColorParser.of("Provide a value after the command to indicate skill category.") | ||
.parseLegacy() // Parse legacy color codes | ||
.build() | ||
); | ||
return; | ||
} | ||
// TODO Make Async | ||
float dbReturnValue = DatabaseQueries.getSkillCategoryExperienceFloat(player, (Integer) args.get("skillCategoryID")); | ||
String returnString = | ||
"Player with ID " + | ||
player.getUniqueId() + | ||
" has an experience value of " + | ||
Float.toString(dbReturnValue) + | ||
" in skill category " + | ||
args.get(0) + | ||
"."; | ||
player.sendMessage( | ||
ColorParser.of(returnString) | ||
.parseLegacy() // Parse legacy color codes | ||
.build() | ||
); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/io/github/alathra/alathraskills/db/testing/TestSetExerienceCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.github.alathra.alathraskills.db.testing; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import com.github.milkdrinkers.colorparser.ColorParser; | ||
|
||
import dev.jorel.commandapi.CommandAPICommand; | ||
import dev.jorel.commandapi.arguments.FloatArgument; | ||
import dev.jorel.commandapi.arguments.IntegerArgument; | ||
import dev.jorel.commandapi.executors.CommandArguments; | ||
import io.github.alathra.alathraskills.db.DatabaseQueries; | ||
|
||
public class TestSetExerienceCommand { | ||
|
||
public TestSetExerienceCommand() { | ||
new CommandAPICommand("testSetExperience") | ||
.withArguments(new IntegerArgument("skillCategoryID"), new FloatArgument("Experience")) | ||
.withFullDescription("Set Experience For a Given Skill Category.") | ||
.withShortDescription("Set Experience") | ||
.withPermission("example.command") | ||
.executesPlayer(this::runCommand) | ||
.register(); | ||
} | ||
|
||
private void runCommand(Player player, CommandArguments args) { | ||
if (args.get("skillCategoryID") == null) { | ||
player.sendMessage( | ||
ColorParser.of("Provide a value after the command to indicate skill category.") | ||
.parseLegacy() // Parse legacy color codes | ||
.build() | ||
); | ||
} | ||
if (args.get("Experience") == null) { | ||
player.sendMessage( | ||
ColorParser.of("Provide a value after the skill category to indicate experience amount.") | ||
.parseLegacy() // Parse legacy color codes | ||
.build() | ||
); | ||
return; | ||
} | ||
// TODO Make Async | ||
DatabaseQueries.saveSkillCategoryExperience(player, (Integer) args.get("skillCategoryID"), (float) args.get("Experience")); | ||
String returnString = | ||
"Player with ID " + | ||
player.getUniqueId() + | ||
" has had an experience value of " + | ||
args.get("Experience") + | ||
" set in skill category " + | ||
args.get("skillCategoryID") + | ||
"."; | ||
player.sendMessage( | ||
ColorParser.of(returnString) | ||
.parseLegacy() // Parse legacy color codes | ||
.build() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# Database Settings | ||
db: | ||
type: "hsqldb" # Available types: "hsqldb", "h2", "mysql", "mariadb" | ||
prefix: "example_" # The table prefix | ||
type: "mariadb" # Available types: "mysql", "mariadb" | ||
prefix: "alathra_skills_" # The table prefix | ||
host: "127.0.0.1" | ||
port: 3306 | ||
database: "database_name" | ||
user: "name" | ||
pass: "123" | ||
database: "alathra" | ||
user: "root" | ||
pass: "" | ||
repair: false |