Skip to content

Commit

Permalink
Major refactoring of the island-command
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Dec 29, 2014
1 parent 725ddff commit a0c1d3f
Show file tree
Hide file tree
Showing 50 changed files with 1,342 additions and 899 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,38 @@ public boolean completeChallenge(final Player player, final String challengeName
Challenge challenge = getChallenge(challengeName);
ChallengeCompletion completion = pi.getChallenge(challengeName);
if (!challenge.getRank().isAvailable(pi)) {
player.sendMessage(ChatColor.RED + "You have not unlocked this challenge yet!");
player.sendMessage("\u00a74You have not unlocked this challenge yet!");
return false;
}
if (!pi.challengeExists(challengeName)) {
player.sendMessage(ChatColor.RED + "Unknown challenge name (check spelling)!");
player.sendMessage("\u00a74Unknown challenge name (check spelling)!");
return false;
}
if (completion.getTimesCompleted() > 0 && (!challenge.isRepeatable() || challenge.getType() == Challenge.Type.ISLAND)) {
player.sendMessage(ChatColor.RED + "The " + challengeName + " challenge is not repeatable!");
player.sendMessage("\u00a74The " + challengeName + " challenge is not repeatable!");
return false;
}
if (challenge.getType() == Challenge.Type.PLAYER) {
if (!tryComplete(player, challengeName, "onPlayer")) {
player.sendMessage(ChatColor.RED + challenge.getDescription());
player.sendMessage(ChatColor.RED + "You don't have enough of the required item(s)!");
player.sendMessage("\u00a74" + challenge.getDescription());
player.sendMessage("\u00a74You don't have enough of the required item(s)!");
return false;
}
return true;
} else if (challenge.getType() == Challenge.Type.ISLAND) {
if (!skyBlock.playerIsOnIsland(player)) {
player.sendMessage(ChatColor.RED + "You must be on your island to do that!");
player.sendMessage("\u00a74You must be on your island to do that!");
return false;
}
if (!tryComplete(player, challengeName, "onIsland")) {
player.sendMessage(ChatColor.RED + challenge.getDescription());
player.sendMessage(ChatColor.RED + "You must be standing within " + challenge.getRadius() + " blocks of all required items.");
player.sendMessage("\u00a74" + challenge.getDescription());
player.sendMessage("\u00a74You must be standing within " + challenge.getRadius() + " blocks of all required items.");
return false;
}
return true;
} else if (challenge.getType() == Challenge.Type.ISLAND_LEVEL) {
if (!tryCompleteIslandLevel(player, challenge)) {
player.sendMessage(ChatColor.RED + "Your island must be level " + challenge.getRequiredLevel() + " to complete this challenge!");
player.sendMessage("\u00a74Your island must be level " + challenge.getRequiredLevel() + " to complete this challenge!");
}
return true;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public boolean tryComplete(final Player player, final String challenge, final St
} else if (type.equalsIgnoreCase("onIsland")) {
return tryCompleteOnIsland(player, challenge);
} else {
player.sendMessage(ChatColor.RED + "Unknown type of challenge: " + type);
player.sendMessage("\u00a74Unknown type of challenge: " + type);
}
return true;
}
Expand Down Expand Up @@ -188,17 +188,17 @@ private boolean islandContains(Player player, List<ItemStack> itemStacks, int ra
int diffSpecific = item.getAmount() - blockCount[(item.getTypeId() << 8) + (item.getDurability() & 0xff)];
int diffGeneral = item.getAmount() - baseBlocks[item.getTypeId()];
if (item.getDurability() != 0 && diffSpecific > 0) {
sb.append(" " + ChatColor.RED + diffSpecific
+ " " + ChatColor.AQUA + VaultHandler.getItemName(item));
sb.append(" \u00a74" + diffSpecific
+ " \u00a7b" + VaultHandler.getItemName(item));
hasAll = false;
} if (diffGeneral > 0) {
sb.append(" " + ChatColor.RED + diffGeneral
+ " " + ChatColor.AQUA + VaultHandler.getItemName(item));
sb.append(" \u00a74" + diffGeneral
+ " \u00a7b" + VaultHandler.getItemName(item));
hasAll = false;
}
}
if (!hasAll) {
player.sendMessage(ChatColor.YELLOW + "Still the following blocks short:" + sb.toString());
player.sendMessage("\u00a7eStill the following blocks short:" + sb.toString());
}
return hasAll;
}
Expand All @@ -225,8 +225,8 @@ private boolean tryCompleteOnPlayer(Player player, String challengeName) {
for (ItemStack required : requiredItems) {
required.setItemMeta(null);
if (!player.getInventory().containsAtLeast(required, required.getAmount())) {
sb.append(" " + ChatColor.RED + (required.getAmount() - getCountOf(player.getInventory(), required))
+ " " + ChatColor.AQUA + VaultHandler.getItemName(required));
sb.append(" \u00a74" + (required.getAmount() - getCountOf(player.getInventory(), required))
+ " \u00a7b" + VaultHandler.getItemName(required));
hasAll = false;
}
}
Expand All @@ -237,7 +237,7 @@ private boolean tryCompleteOnPlayer(Player player, String challengeName) {
giveReward(player, challenge);
return true;
} else {
player.sendMessage(ChatColor.YELLOW + "You are the following items short:" + sb.toString());
player.sendMessage("\u00a7eYou are the following items short:" + sb.toString());
}
}
return true;
Expand Down Expand Up @@ -296,9 +296,9 @@ private boolean giveReward(Player player, Challenge challenge) {
if (defaults.broadcastCompletion && isFirstCompletion) {
Bukkit.getServer().broadcastMessage(config.getString("broadcastText") + player.getName() + " has completed the " + challengeName + " challenge!");
}
player.sendMessage(ChatColor.YELLOW + "Item reward(s): " + ChatColor.WHITE + reward.getRewardText());
player.sendMessage(ChatColor.YELLOW + "Exp reward: " + ChatColor.WHITE + reward.getXpReward());
player.sendMessage(ChatColor.YELLOW + "Currency reward: " + ChatColor.WHITE + this.DECIMAL_FORMAT.format(reward.getCurrencyReward() * rewBonus) + " " + VaultHandler.getEcon().currencyNamePlural() + "\u00a7a (+" + this.DECIMAL_FORMAT.format((rewBonus - 1.0) * 100.0) + "%)");
player.sendMessage("\u00a7eItem reward(s): " + ChatColor.WHITE + reward.getRewardText());
player.sendMessage("\u00a7eExp reward: " + ChatColor.WHITE + reward.getXpReward());
player.sendMessage("\u00a7eCurrency reward: " + ChatColor.WHITE + this.DECIMAL_FORMAT.format(reward.getCurrencyReward() * rewBonus) + " " + VaultHandler.getEcon().currencyNamePlural() + "\u00a7a (+" + this.DECIMAL_FORMAT.format((rewBonus - 1.0) * 100.0) + "%)");
if (reward.getPermissionReward() != null) {
for (String perm : reward.getPermissionReward().split(" ")) {
if (!VaultHandler.checkPerm(player, perm, player.getWorld())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
}
final Player player = (Player)sender;
if (!VaultHandler.checkPerk(player.getName(), "usb.island.challenges", player.getWorld())) {
player.sendMessage(ChatColor.RED + "You don't have access to this command!");
player.sendMessage("\u00a74You don't have access to this command!");
return true;
}
if (!player.getWorld().getName().equalsIgnoreCase(Settings.general_worldName)) {
player.sendMessage(ChatColor.RED + "You can only submit challenges in the skyblock world!");
player.sendMessage("\u00a74You can only submit challenges in the skyblock world!");
return true;
}
PlayerInfo playerInfo = uSkyBlock.getInstance().getPlayerInfo(player);
if (!playerInfo.getHasIsland()) {
player.sendMessage(ChatColor.RED + "You can only submit challenges when you have an island!");
player.sendMessage("\u00a74You can only submit challenges when you have an island!");
return true;
}
ChallengeLogic challengeLogic = uSkyBlock.getInstance().getChallengeLogic();
Expand All @@ -40,26 +40,26 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
String arg = split[0].toLowerCase();
Challenge challenge = challengeLogic.getChallenge(arg);
if (arg.equals("help") || arg.equals("complete") || arg.equals("c")) {
player.sendMessage(ChatColor.YELLOW + "Use /c <name> to view information about a challenge.");
player.sendMessage(ChatColor.YELLOW + "Use /c complete <name> to attempt to complete that challenge.");
player.sendMessage(ChatColor.YELLOW + "Challenges will have different colors depending on if they are:");
player.sendMessage("\u00a7eUse /c <name> to view information about a challenge.");
player.sendMessage("\u00a7eUse /c complete <name> to attempt to complete that challenge.");
player.sendMessage("\u00a7eChallenges will have different colors depending on if they are:");
player.sendMessage(challengeLogic.defaults.challengeColor + "Incomplete " + challengeLogic.defaults.finishedColor + "Completed (not repeatable) " + challengeLogic.defaults.repeatableColor + "Completed(repeatable) ");
} else if (challenge != null && challenge.getRank().isAvailable(playerInfo)) {
player.sendMessage(ChatColor.YELLOW + "Challenge Name: " + ChatColor.WHITE + arg.toLowerCase());
player.sendMessage(ChatColor.YELLOW + challenge.getDescription());
player.sendMessage("\u00a7eChallenge Name: " + ChatColor.WHITE + arg.toLowerCase());
player.sendMessage("\u00a7e" + challenge.getDescription());
if (challenge.getType() == Challenge.Type.PLAYER) {
if (challenge.isTakeItems()) {
player.sendMessage(ChatColor.RED + "You will lose all required items when you complete this challenge!");
player.sendMessage("\u00a74You will lose all required items when you complete this challenge!");
}
} else if (challenge.getType() == Challenge.Type.ISLAND) {
player.sendMessage(ChatColor.RED + "All required items must be placed on your island, within " + challenge.getRadius() + " blocks of you.");
player.sendMessage("\u00a74All required items must be placed on your island, within " + challenge.getRadius() + " blocks of you.");
}
if (challengeLogic.getRanks().size() > 1) {
player.sendMessage(ChatColor.YELLOW + "Rank: " + ChatColor.WHITE + challenge.getRank());
player.sendMessage("\u00a7eRank: " + ChatColor.WHITE + challenge.getRank());
}
ChallengeCompletion completion = playerInfo.getChallenge(arg);
if (completion.getTimesCompleted() > 0 && !challenge.isRepeatable()) {
player.sendMessage(ChatColor.RED + "This Challenge is not repeatable!");
player.sendMessage("\u00a74This Challenge is not repeatable!");
return true;
}
ItemStack item = challenge.getDisplayItem(completion, challengeLogic.defaults.enableEconomyPlugin);
Expand All @@ -68,9 +68,9 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
player.sendMessage(lore);
}
}
player.sendMessage(ChatColor.YELLOW + "To complete this challenge, use " + ChatColor.WHITE + "/c c " + arg.toLowerCase());
player.sendMessage("\u00a7eTo complete this challenge, use " + "\u00a7f/c c " + arg.toLowerCase());
} else {
player.sendMessage(ChatColor.RED + "Invalid challenge name! Use /c help for more information");
player.sendMessage("\u00a74Invalid challenge name! Use /c help for more information");
}
} else if (split.length == 2 && (split[0].equalsIgnoreCase("complete") || split[0].equalsIgnoreCase("c"))) {
challengeLogic.completeChallenge(player, split[1]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package us.talabrek.ultimateskyblock.admin;
package us.talabrek.ultimateskyblock.command;

import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import us.talabrek.ultimateskyblock.command.AbstractCommandExecutor;
import us.talabrek.ultimateskyblock.command.admin.*;
import us.talabrek.ultimateskyblock.command.common.AbstractCommandExecutor;
import us.talabrek.ultimateskyblock.command.completion.AllPlayerTabCompleter;
import us.talabrek.ultimateskyblock.command.completion.BiomeTabCompleter;
import us.talabrek.ultimateskyblock.command.completion.ChallengeTabCompleter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package us.talabrek.ultimateskyblock.command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.talabrek.ultimateskyblock.SkyBlockMenu;
import us.talabrek.ultimateskyblock.command.common.AbstractCommandExecutor;
import us.talabrek.ultimateskyblock.command.completion.AllPlayerTabCompleter;
import us.talabrek.ultimateskyblock.command.completion.BiomeTabCompleter;
import us.talabrek.ultimateskyblock.command.completion.OnlinePlayerTabCompleter;
import us.talabrek.ultimateskyblock.command.island.*;
import us.talabrek.ultimateskyblock.uSkyBlock;

/**
* The main /island command
*/
public class IslandCommand extends AbstractCommandExecutor {
private final SkyBlockMenu menu;

public IslandCommand(uSkyBlock plugin, SkyBlockMenu menu) {
super("island|is", null, "general island command");
this.menu = menu;
InviteHandler inviteHandler = new InviteHandler(plugin);
AllPlayerTabCompleter playerTabCompleter = new AllPlayerTabCompleter();
addTab("island", playerTabCompleter);
addTab("player", playerTabCompleter);
addTab("oplayer", new OnlinePlayerTabCompleter());
addTab("biome", new BiomeTabCompleter());
add(new RestartCommand(plugin));
add(new LogCommand(plugin, menu));
add(new CreateCommand(plugin));
add(new SetHomeCommand(plugin));
add(new HomeCommand(plugin));
add(new SetWarpCommand(plugin));
add(new WarpCommand(plugin));
add(new ToggleWarp(plugin));
add(new BanCommand(plugin));
add(new LockUnlockCommand(plugin));
add(new TopCommand(plugin));
add(new BiomeCommand(plugin, menu));
add(new LevelCommand(plugin));
add(new InviteCommand(plugin, inviteHandler));
add(new AcceptRejectCommand(inviteHandler));
add(new LeaveCommand(plugin));
add(new KickCommand(plugin));
add(new PartyCommand(plugin, menu, inviteHandler));
}

@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 0 && sender instanceof Player) {
Player player = (Player) sender;
player.openInventory(menu.displayIslandGUI(player));
return true;
}
return super.onCommand(sender, command, alias, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package us.talabrek.ultimateskyblock.admin;
package us.talabrek.ultimateskyblock.command.admin;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import us.talabrek.ultimateskyblock.island.IslandInfo;
import us.talabrek.ultimateskyblock.player.PlayerInfo;
Expand All @@ -25,8 +24,8 @@ protected final void doExecute(CommandSender sender, PlayerInfo playerInfo) {
}

@Override
public boolean execute(CommandSender sender, Map<String, Object> data, String... args) {
if (super.execute(sender, data, args)) {
public boolean execute(CommandSender sender, String alias, Map<String, Object> data, String... args) {
if (super.execute(sender, alias, data, args)) {
PlayerInfo playerInfo = (PlayerInfo) data.get("playerInfo");
if (playerInfo != null) {
IslandInfo islandInfo = uSkyBlock.getInstance().getIslandInfo(playerInfo);
Expand All @@ -36,7 +35,7 @@ public boolean execute(CommandSender sender, Map<String, Object> data, String...
doExecute(sender, playerInfo, islandInfo, subArgs);
return true;
} else {
sender.sendMessage(ChatColor.YELLOW + "Player " + playerInfo.getPlayerName() + " has no island!");
sender.sendMessage("\u00a7ePlayer " + playerInfo.getPlayerName() + " has no island!");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package us.talabrek.ultimateskyblock.admin;
package us.talabrek.ultimateskyblock.command.admin;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import us.talabrek.ultimateskyblock.command.AbstractUSBCommand;
import us.talabrek.ultimateskyblock.command.common.AbstractUSBCommand;
import us.talabrek.ultimateskyblock.player.PlayerInfo;
import us.talabrek.ultimateskyblock.uSkyBlock;

Expand All @@ -17,7 +16,7 @@ protected AbstractPlayerInfoCommand(String name, String permission, String descr
}
protected abstract void doExecute(CommandSender sender, PlayerInfo playerInfo);
@Override
public boolean execute(CommandSender sender, Map<String, Object> data, String... args) {
public boolean execute(CommandSender sender, String alias, Map<String, Object> data, String... args) {
if (args.length > 0) {
String playerName = args[0];
PlayerInfo playerInfo = uSkyBlock.getInstance().getPlayerInfo(playerName);
Expand All @@ -26,7 +25,7 @@ public boolean execute(CommandSender sender, Map<String, Object> data, String...
doExecute(sender, playerInfo);
return true;
}
sender.sendMessage(ChatColor.YELLOW + "Invalid player " + args[0] + " supplied.");
sender.sendMessage("\u00a7eInvalid player " + args[0] + " supplied.");
}
return false;
}
Expand Down
Loading

0 comments on commit a0c1d3f

Please sign in to comment.