Added /talgive
This commit is contained in:
@@ -6,7 +6,9 @@ import com.willfp.eco.util.interfaces.EcoRunnable;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.talismans.commands.CommandTaldebug;
|
||||
import com.willfp.talismans.commands.CommandTalgive;
|
||||
import com.willfp.talismans.commands.CommandTalreload;
|
||||
import com.willfp.talismans.commands.TabcompleterTalgive;
|
||||
import com.willfp.talismans.config.TalismansConfigs;
|
||||
import com.willfp.talismans.display.packets.PacketAutoRecipe;
|
||||
import com.willfp.talismans.display.packets.PacketChat;
|
||||
@@ -122,7 +124,8 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Arrays.asList(
|
||||
new CommandTaldebug(this),
|
||||
new CommandTalreload(this)
|
||||
new CommandTalreload(this),
|
||||
new CommandTalgive(this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,7 +168,8 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
TalismansConfigs.class,
|
||||
TalismanChecks.class,
|
||||
TalismanChecks.class,
|
||||
Talismans.class
|
||||
Talismans.class,
|
||||
TabcompleterTalgive.class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.willfp.talismans.commands;
|
||||
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandTalgive extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /talgive command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandTalgive(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, "talgive", "talismans.give", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable AbstractTabCompleter getTab() {
|
||||
return new TabcompleterTalgive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("needs-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("needs-talisman"));
|
||||
return;
|
||||
}
|
||||
|
||||
String recieverName = args.get(0);
|
||||
Player reciever = Bukkit.getPlayer(recieverName);
|
||||
|
||||
if (reciever == null) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("invalid-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
String talismanName = args.get(1);
|
||||
Talisman talisman = Talismans.getByKey(this.getPlugin().getNamespacedKeyFactory().create(talismanName));
|
||||
if (talisman == null) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("invalid-talisman"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = Configs.LANG.getMessage("give-success");
|
||||
message = message.replace("%talisman%", talisman.getFormattedName()).replace("%recipient%", reciever.getName());
|
||||
sender.sendMessage(message);
|
||||
reciever.getInventory().addItem(talisman.getItemStack());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.willfp.talismans.commands;
|
||||
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TabcompleterTalgive extends AbstractTabCompleter {
|
||||
/**
|
||||
* The cached enchantment names.
|
||||
*/
|
||||
private static final List<String> TALISMAN_NAMES = Talismans.values().stream().filter(Talisman::isEnabled).map(talisman -> talisman.getKey().getKey()).collect(Collectors.toList());
|
||||
|
||||
/**
|
||||
* Instantiate a new tab-completer for /talgive.
|
||||
*/
|
||||
public TabcompleterTalgive() {
|
||||
super((AbstractCommand) Objects.requireNonNull(Bukkit.getPluginCommand("talgive")).getExecutor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on /ecoreload.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void reload() {
|
||||
TALISMAN_NAMES.clear();
|
||||
TALISMAN_NAMES.addAll(Talismans.values().stream().filter(Talisman::isEnabled).map(talisman -> talisman.getKey().getKey()).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The execution of the tabcompleter.
|
||||
*
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments of the command.
|
||||
* @return A list of tab-completions.
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTab(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.isEmpty()) {
|
||||
// Currently, this case is not ever reached
|
||||
return TALISMAN_NAMES;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions);
|
||||
return completions;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
StringUtil.copyPartialMatches(args.get(1), TALISMAN_NAMES, completions);
|
||||
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
messages:
|
||||
prefix: "&c&lTalismans&r &8» &r"
|
||||
prefix: "&6&lTalismans&r &8» &r"
|
||||
no-permission: "&cYou don't have permission to do this!"
|
||||
not-player: "&cThis command must be run by a player"
|
||||
reloaded: "Reloaded!"
|
||||
needs-player: "&cYou must specify a player"
|
||||
invalid-player: "&cInvalid player!"
|
||||
needs-talisman: "&cYou must specify a talisman"
|
||||
invalid-talisman: "&cInvalid talisman!"
|
||||
give-success: "Gave &a%talisman%&r to &a%recipient%"
|
||||
|
||||
description-color: "&8"
|
||||
@@ -28,9 +28,9 @@ commands:
|
||||
taldebug:
|
||||
description: Debug information
|
||||
permission: talismans.taldebug
|
||||
talismans:
|
||||
description: Shows talisman inventory
|
||||
permission: talismans.inventory
|
||||
talgive:
|
||||
description: Give a player a talisman
|
||||
permission: talismans.give
|
||||
|
||||
permissions:
|
||||
talismans.*:
|
||||
@@ -39,7 +39,7 @@ permissions:
|
||||
children:
|
||||
talismans.reload: true
|
||||
talismans.taldebug: true
|
||||
talismans.talismans: true
|
||||
talismans.give: true
|
||||
talismans.fromtable.*: true
|
||||
|
||||
talismans.reload:
|
||||
@@ -48,8 +48,8 @@ permissions:
|
||||
talismans.taldebug:
|
||||
description: Allows the use of /taldebug to print verbose debug information to console
|
||||
default: op
|
||||
talismans.inventory:
|
||||
description: Allows the use of /talismans to show the player's talisman inventory.
|
||||
talismans.give:
|
||||
description: Allows the use of /talgive.
|
||||
default: true
|
||||
talismans.fromtable.*:
|
||||
description: Allows crafting all talismans
|
||||
|
||||
Reference in New Issue
Block a user