use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class BiomeCommand method execute.
@Override
public boolean execute(CommandSender sender, String[] args) {
final Player player = (Player) sender;
final User user = this.plugin.getUserManager().getUser(player);
final Optional<Island> islandOptional = user.getIsland();
if (!islandOptional.isPresent()) {
player.sendMessage(StringUtils.color(this.plugin.getMessages().noIsland.replace("%prefix%", plugin.getConfiguration().prefix)));
return false;
}
if (args.length != 2) {
player.openInventory(new IslandBiomeGUI(1, islandOptional.get(), player.getWorld().getEnvironment(), getCooldownProvider(), player.getOpenInventory().getTopInventory()).getInventory());
// The BiomeGUI handles the cooldown
return false;
}
final Optional<XBiome> biomeOptional = XBiome.matchXBiome(args[1]);
// Return if the biome doesn't exist or isn't supported by this version
if (!biomeOptional.isPresent() || biomeOptional.get().getBiome() == null || biomeOptional.get() == XBiome.THE_VOID) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().invalidBiome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(islandOptional.get(), biomeOptional.get());
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().changedBiome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%biome%", WordUtils.capitalizeFully(biomeOptional.get().name().toLowerCase().replace("_", " ")))));
return true;
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class BypassCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Allows admins to bypass Island restrictions.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
user.setBypassing(!user.isBypassing());
player.sendMessage(StringUtils.color((user.isBypassing() ? IridiumSkyblock.getInstance().getMessages().nowBypassing : IridiumSkyblock.getInstance().getMessages().noLongerBypassing).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return true;
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class ChatCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Chats with the sender's island members {@link Island}.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
Optional<Island> island = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length > 1) {
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
for (User user : island.get().getMembers()) {
Player recipient = Bukkit.getPlayer(user.getUuid());
if (recipient != null) {
recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%message%", message)));
}
}
} else {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
UserChatToggleEvent userChatToggleEvent = new UserChatToggleEvent(user, !user.isIslandChat());
Bukkit.getPluginManager().callEvent(userChatToggleEvent);
if (userChatToggleEvent.isCancelled())
return false;
user.setIslandChat(!user.isIslandChat());
player.sendMessage(StringUtils.color((user.isIslandChat() ? IridiumSkyblock.getInstance().getMessages().islandChatEnabled : IridiumSkyblock.getInstance().getMessages().islandChatDisabled).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return true;
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class ShopCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments. Not
* called when the command execution was invalid (no permission, no player or command
* disabled).
*
* @param sender The CommandSender which executes this command
* @param arguments The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] arguments) {
Player player = (Player) sender;
User user = IridiumSkyblockAPI.getInstance().getUser(player);
if (!user.getIsland().isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (arguments.length == 1) {
player.openInventory(new ShopOverviewGUI(player.getOpenInventory().getTopInventory()).getInventory());
} else {
String[] commandArguments = Arrays.copyOfRange(arguments, 1, arguments.length);
String categoryName = String.join(" ", commandArguments);
Optional<ShopCategory> category = IridiumSkyblock.getInstance().getShopManager().getCategoryByName(categoryName);
if (!category.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noShopCategory.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
player.openInventory(new ShopCategoryGUI(category.get(), player.getOpenInventory().getTopInventory()).getInventory());
}
return true;
}
use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.
the class TransferCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Transfers Island ownership.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length != 2) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
User islandOwner = island.get().getOwner();
OfflinePlayer targetPlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
if (!user.getIslandRank().equals(IslandRank.OWNER) && !user.isBypassing()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTransferOwnership.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (!island.get().equals(targetUser.getIsland().orElse(null))) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (islandOwner.getUuid().equals(targetPlayer.getUniqueId())) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTransferYourself.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
islandOwner.setIslandRank(IslandRank.CO_OWNER);
targetUser.setIslandRank(IslandRank.OWNER);
for (User member : island.get().getMembers()) {
Player islandMember = Bukkit.getPlayer(member.getUuid());
if (islandMember == null)
continue;
islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().transferredOwnership.replace("%oldowner%", user.getName()).replace("%newowner%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return true;
}
Aggregations