Added level support in /talgive
This commit is contained in:
@@ -47,7 +47,7 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:5.0.0'
|
||||
compileOnly 'com.willfp:eco:5.2.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.TalismanLevel;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -42,11 +43,21 @@ public class CommandTalgive extends AbstractCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
int level = 1;
|
||||
|
||||
if (args.size() > 2) {
|
||||
try {
|
||||
amount = Integer.parseInt(args.get(2));
|
||||
level = Integer.parseInt(args.get(2));
|
||||
} catch (NumberFormatException ignored) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if (args.size() > 3) {
|
||||
try {
|
||||
level = Integer.parseInt(args.get(3));
|
||||
} catch (NumberFormatException ignored) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -67,11 +78,17 @@ public class CommandTalgive extends AbstractCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
TalismanLevel talismanLevel = talisman.getLevel(level);
|
||||
if (talismanLevel == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-level"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = this.getPlugin().getLangYml().getMessage("give-success");
|
||||
message = message.replace("%talisman%", talisman.getFormattedName()).replace("%recipient%", reciever.getName());
|
||||
message = message.replace("%talisman%", talismanLevel.getName()).replace("%recipient%", reciever.getName());
|
||||
sender.sendMessage(message);
|
||||
|
||||
ItemStack itemStack = talisman.getItemStack();
|
||||
ItemStack itemStack = talismanLevel.getItemStack();
|
||||
itemStack.setAmount(amount);
|
||||
reciever.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@ package com.willfp.talismans.commands;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.talismans.TalismansPlugin;
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.TalismanLevel;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
@@ -83,7 +86,26 @@ public class TabcompleterTalgive extends AbstractTabCompleter {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions);
|
||||
Talisman talisman = Talismans.getByKey(TalismansPlugin.getInstance().getNamespacedKeyFactory().create(args.get(1).toLowerCase()));
|
||||
if (talisman == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> levels = talisman.getLevels().stream().map(TalismanLevel::getLevel).map(String::valueOf).collect(Collectors.toList());
|
||||
|
||||
StringUtil.copyPartialMatches(args.get(2), levels, completions);
|
||||
|
||||
completions.sort((s1, s2) -> {
|
||||
int t1 = Integer.parseInt(s1);
|
||||
int t2 = Integer.parseInt(s2);
|
||||
return t1 - t2;
|
||||
});
|
||||
|
||||
return completions;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
StringUtil.copyPartialMatches(args.get(3), NUMBERS, completions);
|
||||
|
||||
completions.sort((s1, s2) -> {
|
||||
int t1 = Integer.parseInt(s1);
|
||||
|
||||
@@ -7,6 +7,7 @@ messages:
|
||||
invalid-player: "&cInvalid player!"
|
||||
needs-talisman: "&cYou must specify a talisman"
|
||||
invalid-talisman: "&cInvalid talisman!"
|
||||
invalid-level: "&cLevel doesn't exist!"
|
||||
give-success: "Gave &a%talisman%&r to &a%recipient%"
|
||||
|
||||
description-color: "&8"
|
||||
Reference in New Issue
Block a user