Skip to content

Commit

Permalink
Change order to match vanilla (#33)
Browse files Browse the repository at this point in the history
* Change order to match vanilla

* minor

* test
  • Loading branch information
Netherwhal authored Mar 10, 2024
1 parent 9a7b20f commit e27217b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'net.simplyvanilla'
version = '0.3.0'
version = '0.3.1'

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,36 @@ public boolean onCommand(
return false;
}

String subCommand = args[0];
switch (subCommand.toLowerCase(Locale.ROOT)) {
case "create": {
String subCommand = args[0].toLowerCase(Locale.ROOT);
switch (subCommand) {
case "remove", "add":
if (args.length < 2) {
return false;
}
String name = args[1];
return handleCreate(sender, name);
}
case "modify": {
if (args.length < 3) {
return false;
if (subCommand.equals("remove")) {
handleDelete(sender, args[1]);
} else {
handleCreate(sender, args[1]);
}
String name = args[1];
String modifyType = args[2];
String value = args.length > 3 ? args[3] : "";
return handleModify(sender, name, modifyType, value);
}
case "join": {
return true;

case "modify":
if (args.length < 3) {
return false;
}
String member = args[1];
String name = args[2];
return handleJoin(sender, member, name);
}
case "leave": {
handleModify(sender, args[1], args[2], args.length > 3 ? args[3] : "");
return true;

case "leave", "join":
if (args.length < 3) {
return false;
}
String leaver = args[1];
String name = args[2];
return handleLeave(sender, leaver, name);
}
case "delete":
if (args.length < 2) {
return false;
if (subCommand.equals("join")) {
handleJoin(sender, args[2], args[1]);
} else {
handleLeave(sender, args[2], args[1]);
}
String name = args[1];
return handleDelete(sender, name);
return true;
}

return false;
Expand All @@ -89,105 +79,100 @@ private UUID getPlayerId(String input) {
}

// /team delete <name>
private boolean handleDelete(CommandSender sender, String name) {
private void handleDelete(CommandSender sender, String name) {
int teamId = this.plugin.getTeamDatabase().getTeamId(name);
if (teamId < 0) {
this.plugin.sendConfigMessage(sender, "messages.error.teamNotFound");
return false;
return;
}

if (!this.plugin.getTeamDatabase().deleteTeam(teamId)) {
return false;
return;
}

this.plugin.sendConfigMessage(sender, "messages.teamDeletedMessage");
return true;
}

// /team leave <leaver> <owner>
private boolean handleLeave(CommandSender sender, String leaver, String name) {
private void handleLeave(CommandSender sender, String leaver, String name) {
UUID leaverId = getPlayerId(leaver);
if (leaverId == null) {
this.plugin.sendConfigMessage(sender, "messages.error.playerCannotFoundErrorMessage");
return false;
return;
}

TeamMySQL.PlayerTeam playerTeam = this.plugin.getTeamCache().getTeam(leaverId);
if (playerTeam == null) {
this.plugin.sendConfigMessage(sender, "messages.error.teamNotInTeam");
return false;
return;
}

if (!playerTeam.getName().equals(name)) {
this.plugin.sendConfigMessage(sender, "messages.error.teamNotInTeam");
return false;
return;
}

if (!this.plugin.getTeamDatabase().leaveTeam(leaverId, playerTeam.getTeamId())) {
return false;
return;
}

this.plugin.sendConfigMessage(sender, "messages.teamLeftMessage");
return true;
}

// /team join <member> <name>
private boolean handleJoin(CommandSender sender, String member, String name) {
private void handleJoin(CommandSender sender, String member, String name) {
UUID memberId = getPlayerId(member);
if (memberId == null) {
this.plugin.sendConfigMessage(sender, "messages.error.playerCannotFoundErrorMessage");
return false;
return;
}

if (this.plugin.getTeamCache().getTeam(memberId) != null) {
this.plugin.sendConfigMessage(sender, "messages.error.teamAlreadyInTeam");
return false;
return;
}

int teamId = this.plugin.getTeamDatabase().getTeamId(name);
if (teamId < 0) {
this.plugin.sendConfigMessage(sender, "messages.error.teamNotFound");
return false;
return;
}

if (!this.plugin.getTeamDatabase().joinTeam(memberId, teamId)) {
return false;
return;
}

this.plugin.sendConfigMessage(sender, "messages.teamJoinedMessage");
return true;
}

// /team modify <name> <modifyType> [value]
// modifyType: name, color
private boolean handleModify(CommandSender sender, String name, String modifyType, String value) {
private void handleModify(CommandSender sender, String name, String modifyType, String value) {
int teamId = this.plugin.getTeamDatabase().getTeamId(name);
if (teamId < 0) {
this.plugin.sendConfigMessage(sender, "messages.error.teamNotFound");
return false;
return;
}

if (!this.plugin.getTeamDatabase().modifyTeam(teamId, modifyType, value)) {
return false;
return;
}

this.plugin.sendConfigMessage(sender, "messages.teamModifiedMessage");
return true;
}

// /team create <name>
private boolean handleCreate(CommandSender sender, String teamName) {
private void handleCreate(CommandSender sender, String teamName) {
int teamId = this.plugin.getTeamDatabase().getTeamId(teamName);
if (teamId >= 0) {
this.plugin.sendConfigMessage(sender, "messages.error.teamAlreadyExists");
return false;
return;
}

if (!this.plugin.getTeamDatabase().createTeam(teamName)) {
return false;
return;
}

this.plugin.sendConfigMessage(sender, "messages.teamCreatedMessage", Map.of("team", teamName));
return true;
}
}
8 changes: 4 additions & 4 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ commands:
team:
description: Commands for managing teams
usage: |
/team create <team> - Create a team
/team delete <team> - Delete a team
/team add <team> - Create a team
/team remove <team> - Delete a team
/team modify <team> <name|color> <value> - Modify a team
/team join <player> <team> - Join a team
/team leave <player> <team> - Leave a team
/team join <team> <player> - Join a team
/team leave <team> <player> - Leave a team
permission: simplynicks.team

permissions:
Expand Down

0 comments on commit e27217b

Please sign in to comment.