EpicEnchants/src/main/java/com/songoda/epicenchants/commands/CommandGiveItemDust.java

110 lines
3.8 KiB
Java
Raw Normal View History

package com.songoda.epicenchants.commands;
2019-08-05 04:24:48 +02:00
import com.songoda.core.commands.AbstractCommand;
2019-08-05 04:24:48 +02:00
import com.songoda.epicenchants.CommandCommons;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
2019-08-05 22:49:38 +02:00
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
2019-08-05 04:24:48 +02:00
2019-08-05 22:49:38 +02:00
import java.util.ArrayList;
2019-08-05 04:24:48 +02:00
import java.util.List;
import java.util.stream.Collectors;
public class CommandGiveItemDust extends AbstractCommand {
private final EpicEnchants plugin;
2019-08-05 04:24:48 +02:00
public CommandGiveItemDust(EpicEnchants plugin) {
super(false, "giveitemdust");
this.plugin = plugin;
2019-08-05 04:24:48 +02:00
}
//giveitemdust <player> <group> [type] [percentage]
2019-08-05 04:24:48 +02:00
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2 || args.length > 5)
2019-08-05 04:24:48 +02:00
return ReturnType.SYNTAX_ERROR;
OfflinePlayer target = Bukkit.getPlayer(args[0]);
2019-08-05 04:24:48 +02:00
if (target == null) {
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
2019-08-05 04:24:48 +02:00
return ReturnType.FAILURE;
}
List<Group> groups = plugin.getGroupManager().getValues().stream()
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
2019-08-05 04:24:48 +02:00
if (groups.isEmpty()) {
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
2019-08-05 04:24:48 +02:00
return ReturnType.FAILURE;
}
Group group = groups.get(0);
String dustType = null;
int percentage = -1;
if (args.length > 2) {
dustType = args[2];
2019-08-05 04:24:48 +02:00
}
if (args.length > 3) {
if (!CommandCommons.isInt(args[3], sender))
2019-08-05 04:24:48 +02:00
return ReturnType.FAILURE;
percentage = Integer.parseInt(args[3]);
2019-08-05 04:24:48 +02:00
}
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getDust(group, dustType, percentage, true));
plugin.getLocale().getMessage("command.dust.received")
2019-08-05 04:24:48 +02:00
.processPlaceholder("group", group.getIdentifier())
.sendPrefixedMessage(target.getPlayer());
plugin.getLocale().getMessage("command.dust.gave")
2019-08-05 04:24:48 +02:00
.processPlaceholder("player", target.getPlayer().getName())
.processPlaceholder("group", group.getIdentifier())
.sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) {
2019-08-05 22:49:38 +02:00
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
} else if (args.length == 2) {
return plugin.getGroupManager().getValues().stream()
2019-08-05 22:49:38 +02:00
.map(Group::getIdentifier).collect(Collectors.toList());
} else if (args.length == 3) {
2019-08-05 22:49:38 +02:00
List<String> dusts = new ArrayList<>();
FileConfiguration dustConfig = plugin.getFileManager().getConfiguration("items/dusts");
2019-08-05 22:49:38 +02:00
dusts.addAll(dustConfig.getConfigurationSection("dusts").getKeys(false));
return dusts;
} else if (args.length == 4) {
2019-08-05 22:49:38 +02:00
List<String> rates = new ArrayList<>();
2021-07-10 23:41:20 +02:00
for (int i = 1; i <= 100; i++)
2019-08-05 22:49:38 +02:00
rates.add(String.valueOf(i));
return rates;
}
2019-08-05 04:24:48 +02:00
return null;
}
@Override
public String getPermissionNode() {
return "epicenchants.giveitemdust";
}
@Override
public String getSyntax() {
return "giveitemdust <player> <group> [type] [percentage]";
2019-08-05 04:24:48 +02:00
}
@Override
public String getDescription() {
return "Give item dust.";
}
}