Skip to content

Commit

Permalink
Feature: implemented the /leave command (#47).
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Nov 21, 2014
1 parent 718b752 commit a9ca072
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/me/azenet/UHPlugin/UHPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void onEnable() {
getCommand("g").setExecutor(commandManager);
getCommand("togglechat").setExecutor(commandManager);
getCommand("join").setExecutor(commandManager);
getCommand("leave").setExecutor(commandManager);

getCommand("uh").setTabCompleter(tabCompleter);
getCommand("togglechat").setTabCompleter(tabCompleter);
Expand Down
47 changes: 45 additions & 2 deletions src/main/java/me/azenet/UHPlugin/UHPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import me.azenet.UHPlugin.i18n.I18n;

import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
Expand Down Expand Up @@ -167,12 +166,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

/** /join command **/
/** /join & /leave commands **/

if(command.getName().equalsIgnoreCase("join")) {
doJoin(sender, command, label, args);
return true;
}
if(command.getName().equalsIgnoreCase("leave")) {
doLeave(sender, command, label, args);
return true;
}


if(args.length == 0) {
Expand Down Expand Up @@ -223,6 +226,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}



/**
* Prints the help.
*
Expand Down Expand Up @@ -2037,6 +2041,45 @@ else if(args.length >= 2) {
}
}

/**
* This command is used to allow a player to quit his team.
*
* @param sender
* @param command
* @param label
* @param args
*/
private void doLeave(CommandSender sender, Command command, String label, String[] args) {

Player target = null;

if(args.length >= 1 && sender.hasPermission("uh.player.leave.others")) {
if((target = p.getServer().getPlayer(args[0])) == null) {
sender.sendMessage(i.t("team.removeplayer.disconnected", args[0]));
return;
}
}
else if(args.length == 0 && sender.hasPermission("uh.player.leave.self")) {
if(sender instanceof Player) {
target = (Player) sender;
}
else {
sender.sendMessage(i.t("team.onlyAsAPlayer"));
return;
}
}
else {
sender.sendMessage(i.t("cmd.errorUnauthorized"));
return;
}

p.getTeamManager().removePlayerFromTeam(target);

if(!target.equals(sender)) {
sender.sendMessage(i.t("team.removeplayer.success", args[0]));
}
}




Expand Down
27 changes: 26 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ commands:
join:
description: Use this to join an UltraHardcore team.
usage: /join [player] <team>

leave:
description: Use this to quit your current UltraHardcore team.
usage: /leave [player]

permissions:

Expand Down Expand Up @@ -118,7 +122,14 @@ permissions:
default: op


# Permissions for the /join command
# Permissions for the /join & /leave commands

uh.player:
description: Allows the full use of both /join and /leave.
children:
uh.player.join: true
uh.player.leave: true


uh.player.join.*:
description: Allows the full use of /join.
Expand All @@ -132,3 +143,17 @@ permissions:
uh.player.join.others:
description: Allows a player to use /join <player> <team>.
default: op


uh.player.leave.*:
description: Allows the full use of /leave.
children:
uh.player.leave.self: true
uh.player.leave.others: true

uh.player.leave.self:
description: Allows a player to use /leave (quits his own team).
default: true
uh.player.leave.others:
description: Allows a player to use /leave <player>.
default: op

0 comments on commit a9ca072

Please sign in to comment.