diff --git a/build.gradle.kts b/build.gradle.kts index 1794f34..4655664 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "cloud.cloudie" -version = "0.3.5" +version = "0.3.6" repositories { mavenCentral() diff --git a/src/main/java/cloud/cloudie/cloudsystem/CloudSystem.java b/src/main/java/cloud/cloudie/cloudsystem/CloudSystem.java index 1a3d7e4..749cc68 100644 --- a/src/main/java/cloud/cloudie/cloudsystem/CloudSystem.java +++ b/src/main/java/cloud/cloudie/cloudsystem/CloudSystem.java @@ -1,6 +1,7 @@ package cloud.cloudie.cloudsystem; import cloud.cloudie.cloudsystem.commands.FlyCommand; +import cloud.cloudie.cloudsystem.commands.GiveCommand; import cloud.cloudie.cloudsystem.commands.PissCommand; import cloud.cloudie.cloudsystem.commands.ReskinCommand; import cloud.cloudie.cloudsystem.commands.RulesGUICommand; @@ -14,9 +15,11 @@ import cloud.cloudie.cloudsystem.util.UpdateChecker; import co.aikar.commands.PaperCommandManager; import com.google.common.collect.ImmutableList; +import org.bukkit.Material; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,10 +43,10 @@ public void onEnable() { getLogger().info("|---[ CloudieSMP ]---------------------------------------|"); getLogger().info("| |"); + commandCompletions(); registerClasses(); registerCommands(); registerEvents(); - commandCompletions(); getLogger().info("| |"); getLogger().info("|-----------------------------[ ENABLED SUCCESSFULLY ]---|"); @@ -57,6 +60,7 @@ void registerCommands(){ manager.registerCommand(new ReskinCommand()); manager.registerCommand(new PissCommand()); manager.registerCommand(new RulesGUICommand()); + manager.registerCommand(new GiveCommand()); //if renameCommands are enabled if(getConfig().getBoolean("ShortenCommands")){ @@ -85,6 +89,10 @@ void commandCompletions(){ List skins = getConfig().getStringList("skins"); return ImmutableList.copyOf(skins); }); + + manager.getCommandCompletions().registerCompletion("Items", context -> Arrays.stream(Material.values()) + .map(Material::name) + .toList()); } @Override diff --git a/src/main/java/cloud/cloudie/cloudsystem/commands/GiveCommand.java b/src/main/java/cloud/cloudie/cloudsystem/commands/GiveCommand.java new file mode 100644 index 0000000..92ff123 --- /dev/null +++ b/src/main/java/cloud/cloudie/cloudsystem/commands/GiveCommand.java @@ -0,0 +1,56 @@ +package cloud.cloudie.cloudsystem.commands; + +import co.aikar.commands.BaseCommand; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Default; +import co.aikar.commands.annotation.Optional; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +@CommandAlias("i") +@CommandPermission("system.admin.give") +public class GiveCommand extends BaseCommand { + + @Default + @CommandCompletion("@Items @range:1-64 @Players") + public void onGiveCommand(CommandSender sender, String targetItem, @Optional Integer amount, @Optional String targetName) { + // Ensure sender is a player + if (!(sender instanceof Player player)) { + sender.sendMessage(Component.text("Only players can give items.") + .color(TextColor.fromHexString("#FF5555"))); + return; + } + + // Set amount (default to 1 if not provided) + int itemAmount = (amount != null) ? Math.max(1, Math.min(amount, 64)) : 1; // Ensure it's between 1-64 + + // Determine the target player + Player target = (targetName != null) ? Bukkit.getPlayerExact(targetName) : player; + if (target == null) { + sender.sendMessage(Component.text("Player not found.") + .color(TextColor.fromHexString("#FF5555"))); + return; + } + + // Check if item exists + Material material = Material.matchMaterial(targetItem); + if (material == null) { + sender.sendMessage(Component.text("Invalid item name: " + targetItem) + .color(TextColor.fromHexString("#FF5555"))); + return; + } + + // Give the item + ItemStack item = new ItemStack(material, itemAmount); + target.getInventory().addItem(item); + + sender.sendMessage(Component.text("Gave " + itemAmount + "x " + material.name() + " to " + target.getName() + ".") + .color(TextColor.fromHexString("#55FF55"))); } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e25afa9..02ded78 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ messages: - welcome: "Welcome to Cloudie SMP S9, {player}!" + welcome: "Welcome to CloudSystem, {player}!" skins: - cat_ears - dog_ears