mirror of
https://github.com/Auxilor/Reforges.git
synced 2025-12-22 16:39:34 +00:00
Moved commands to kotlin
This commit is contained in:
@@ -1,151 +0,0 @@
|
||||
package com.willfp.reforges.commands;
|
||||
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.TabCompleteHandler;
|
||||
import com.willfp.eco.core.command.impl.Subcommand;
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||
import com.willfp.reforges.reforges.Reforge;
|
||||
import com.willfp.reforges.reforges.Reforges;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGive extends Subcommand {
|
||||
/**
|
||||
* The cached names.
|
||||
*/
|
||||
private static final List<String> STONE_NAMES = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The cached numbers.
|
||||
*/
|
||||
private static final List<String> NUMBERS = Arrays.asList(
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"10",
|
||||
"32",
|
||||
"64"
|
||||
);
|
||||
|
||||
/**
|
||||
* Instantiate a new command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandGive(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "give", "reforges.command.give", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on reload.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void reload() {
|
||||
STONE_NAMES.clear();
|
||||
STONE_NAMES.addAll(Reforges.values().stream()
|
||||
.filter(Reforge::getRequiresStone)
|
||||
.map(Reforge::getId)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler getHandler() {
|
||||
return (sender, args) -> {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-stone"));
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if (args.size() > 2) {
|
||||
try {
|
||||
amount = Integer.parseInt(args.get(2));
|
||||
} catch (NumberFormatException ignored) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
String recieverName = args.get(0);
|
||||
Player reciever = Bukkit.getPlayer(recieverName);
|
||||
|
||||
if (reciever == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
String key = args.get(1);
|
||||
|
||||
Reforge reforge = Reforges.getByKey(key);
|
||||
|
||||
if (reforge == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-stone"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = this.getPlugin().getLangYml().getMessage("give-success");
|
||||
message = message.replace("%reforge%", reforge.getName()).replace("%recipient%", reciever.getName());
|
||||
sender.sendMessage(message);
|
||||
|
||||
ItemStack itemStack = reforge.getStone();
|
||||
itemStack.setAmount(amount);
|
||||
reciever.getInventory().addItem(itemStack);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabCompleteHandler getTabCompleter() {
|
||||
return (sender, args) -> {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.isEmpty()) {
|
||||
// Currently, this case is not ever reached
|
||||
return STONE_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), STONE_NAMES, completions);
|
||||
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions);
|
||||
|
||||
completions.sort((s1, s2) -> {
|
||||
int t1 = Integer.parseInt(s1);
|
||||
int t2 = Integer.parseInt(s2);
|
||||
return t1 - t2;
|
||||
});
|
||||
|
||||
return completions;
|
||||
}
|
||||
|
||||
return new ArrayList<>(0);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.willfp.reforges.commands;
|
||||
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.TabCompleteHandler;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.reforges.gui.ReforgeGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandOpen extends PluginCommand {
|
||||
/**
|
||||
* Instantiate a new command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandOpen(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "open", "reforges.command.open", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler getHandler() {
|
||||
return (sender, args) -> {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(args.get(0));
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
player.playSound(
|
||||
player.getLocation(),
|
||||
Sound.valueOf(this.getPlugin().getConfigYml().getString("gui.open-sound.id").toUpperCase()),
|
||||
1f,
|
||||
(float) this.getPlugin().getConfigYml().getDouble("gui.open-sound.pitch")
|
||||
);
|
||||
ReforgeGUI.getMenu().open(player);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabCompleteHandler getTabCompleter() {
|
||||
return (sender, args) -> {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.size() == 1) {
|
||||
StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions);
|
||||
return completions;
|
||||
}
|
||||
|
||||
return new ArrayList<>(0);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.willfp.reforges.commands;
|
||||
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.reforges.gui.ReforgeGUI;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandReforge extends PluginCommand {
|
||||
/**
|
||||
* Instantiate a new command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandReforge(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "reforge", "reforges.command.reforge", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler getHandler() {
|
||||
return (sender, args) -> {
|
||||
Player player = (Player) sender;
|
||||
|
||||
player.playSound(
|
||||
player.getLocation(),
|
||||
Sound.valueOf(this.getPlugin().getConfigYml().getString("gui.open-sound.id").toUpperCase()),
|
||||
1f,
|
||||
(float) this.getPlugin().getConfigYml().getDouble("gui.open-sound.pitch")
|
||||
);
|
||||
ReforgeGUI.getMenu().open(player);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.willfp.reforges.commands;
|
||||
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandReforges extends PluginCommand {
|
||||
/**
|
||||
* Instantiate a new command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandReforges(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "reforges", "reforges.command.reforges", false);
|
||||
|
||||
this.addSubcommand(new CommandReload(plugin))
|
||||
.addSubcommand(new CommandGive(plugin))
|
||||
.addSubcommand(new CommandOpen(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler getHandler() {
|
||||
return (sender, args) -> {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-command"));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.willfp.reforges.commands;
|
||||
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.impl.Subcommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends Subcommand {
|
||||
/**
|
||||
* Instantiate a new command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandReload(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "reload", "reforges.command.reload", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler getHandler() {
|
||||
return (sender, args) -> {
|
||||
this.getPlugin().reload();
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.willfp.reforges.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.TabCompleteHandler
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||
import com.willfp.reforges.reforges.Reforge
|
||||
import com.willfp.reforges.reforges.Reforges
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.util.StringUtil
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
|
||||
class CommandGive(
|
||||
plugin: EcoPlugin
|
||||
) : Subcommand(plugin, "give", "reforges.command.give", false) {
|
||||
private val numbers = listOf(
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"10",
|
||||
"32",
|
||||
"64"
|
||||
)
|
||||
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender, args ->
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("needs-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
if (args.size == 1) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("needs-stone"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
val amount = if (args.size > 2) args[2].toIntOrNull() ?: 1 else 1
|
||||
val recieverName = args[0]
|
||||
val reciever = Bukkit.getPlayer(recieverName)
|
||||
if (reciever == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
val key = args[1]
|
||||
val reforge = Reforges.getByKey(key)
|
||||
if (reforge == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-stone"))
|
||||
return@CommandHandler
|
||||
}
|
||||
var message = plugin.langYml.getMessage("give-success")
|
||||
message = message.replace("%reforge%", reforge.name).replace("%recipient%", reciever.name)
|
||||
sender.sendMessage(message)
|
||||
val itemStack = reforge.stone
|
||||
itemStack.amount = amount
|
||||
reciever.inventory.addItem(itemStack)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTabCompleter(): TabCompleteHandler {
|
||||
return TabCompleteHandler { _, args ->
|
||||
val completions = mutableListOf<String>()
|
||||
if (args.isEmpty()) {
|
||||
// Currently, this case is not ever reached
|
||||
return@TabCompleteHandler stoneNames
|
||||
}
|
||||
if (args.size == 1) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
Bukkit.getOnlinePlayers().map { it.name },
|
||||
completions
|
||||
)
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(args[1], stoneNames, completions)
|
||||
Collections.sort(completions)
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
if (args.size == 3) {
|
||||
StringUtil.copyPartialMatches(args[2], numbers, completions)
|
||||
completions.sortWith { s1, s2 ->
|
||||
val t1 = s1.toInt()
|
||||
val t2 = s2.toInt()
|
||||
t1 - t2
|
||||
}
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val stoneNames = mutableListOf<String>()
|
||||
|
||||
/**
|
||||
* Called on reload.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
@JvmStatic
|
||||
fun reload() {
|
||||
stoneNames.clear()
|
||||
stoneNames.addAll(
|
||||
Reforges.values().stream()
|
||||
.filter(Reforge::requiresStone)
|
||||
.map(Reforge::id)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.willfp.reforges.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.TabCompleteHandler
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.reforges.gui.ReforgeGUI.menu
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.util.StringUtil
|
||||
|
||||
class CommandOpen(
|
||||
plugin: EcoPlugin
|
||||
) : PluginCommand(plugin, "open", "reforges.command.open", false) {
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender, args ->
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("needs-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
val player = Bukkit.getPlayer(args[0])
|
||||
if (player == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
player.playSound(
|
||||
player.location,
|
||||
Sound.valueOf(plugin.configYml.getString("gui.open-sound.id").uppercase()),
|
||||
1f,
|
||||
plugin.configYml.getDouble("gui.open-sound.pitch").toFloat()
|
||||
)
|
||||
menu.open(player)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTabCompleter(): TabCompleteHandler {
|
||||
return TabCompleteHandler { _, args ->
|
||||
val completions = mutableListOf<String>()
|
||||
if (args.size == 1) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
Bukkit.getOnlinePlayers().map { it.name },
|
||||
completions
|
||||
)
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.reforges.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.reforges.gui.ReforgeGUI.menu
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class CommandReforge(
|
||||
plugin: EcoPlugin
|
||||
) : PluginCommand(plugin, "reforge", "reforges.command.reforge", true) {
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { player, _ ->
|
||||
player as Player
|
||||
player.playSound(
|
||||
player.location,
|
||||
Sound.valueOf(plugin.configYml.getString("gui.open-sound.id").uppercase()),
|
||||
1f,
|
||||
plugin.configYml.getDouble("gui.open-sound.pitch").toFloat()
|
||||
)
|
||||
menu.open(player)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.reforges.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
|
||||
class CommandReforges(plugin: EcoPlugin) : PluginCommand(plugin, "reforges", "reforges.command.reforges", false) {
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender, _ ->
|
||||
sender.sendMessage(
|
||||
plugin.langYml.getMessage("invalid-command")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
addSubcommand(CommandReload(plugin))
|
||||
.addSubcommand(CommandGive(plugin))
|
||||
.addSubcommand(CommandOpen(plugin))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.reforges.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
|
||||
class CommandReload(plugin: EcoPlugin) : Subcommand(plugin, "reload", "reforges.command.reload", false) {
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender, _ ->
|
||||
plugin.reload()
|
||||
sender.sendMessage(plugin.langYml.getMessage("reloaded"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user