Skip to content

Commit

Permalink
Explicitly declared parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Dec 12, 2024
1 parent 5db303f commit a1bc00f
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 19 deletions.
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/ApplyPotionEffect.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import it.fulminazzo.yagl.WrappersAdapter
import it.fulminazzo.yagl.wrappers.PotionEffect
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player) {
try {
PotionEffect effect = new PotionEffect(args[0], Double.valueOf(args[1]),
Expand Down
11 changes: 6 additions & 5 deletions demo/src/main/resources/commands/CreateRecipe.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import it.fulminazzo.yagl.items.Item
import it.fulminazzo.yagl.items.recipes.FurnaceRecipe
import it.fulminazzo.yagl.items.recipes.ShapedRecipe
import it.fulminazzo.yagl.items.recipes.ShapelessRecipe
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

static shaped(sender, label, args, output, name) {
static shaped(CommandSender sender, String[] args, String output, String name) {
try {
def rows = Integer.valueOf(args[0])
def columns = Integer.valueOf(args[1])
Expand All @@ -22,7 +23,7 @@ static shaped(sender, label, args, output, name) {
}
}

static shapeless(sender, label, args, output, name) {
static shapeless(CommandSender sender, String[] args, String output, String name) {
try {
if (args.length == 0) throw new IndexOutOfBoundsException()
BukkitItem.newRecipeItem(output)
Expand All @@ -39,7 +40,7 @@ static shapeless(sender, label, args, output, name) {
}
}

static furnace(sender, label, args, output, name) {
static furnace(CommandSender sender, String[] args, String output, String name) {
try {
BukkitItem.newRecipeItem(output)
.addRecipes(new FurnaceRecipe(name)
Expand All @@ -55,10 +56,10 @@ static furnace(sender, label, args, output, name) {
}
}

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
"${args[2].toLowerCase()}"(sender, label, Arrays.copyOfRange(args, 3, args.length), args[1], args[0])
"${args[2].toLowerCase()}"(sender, Arrays.copyOfRange(args, 3, args.length), args[1], args[0])
} catch (NumberFormatException ignored) {
// auto-generated code
} catch (IndexOutOfBoundsException ignored) {
Expand Down
5 changes: 3 additions & 2 deletions demo/src/main/resources/commands/GetEnchantment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import it.fulminazzo.yagl.WrappersAdapter
import it.fulminazzo.yagl.wrappers.Enchantment
import it.fulminazzo.fulmicollection.structures.tuples.Tuple
import org.bukkit.Material
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.EnchantmentStorageMeta

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
Enchantment enchantment = new Enchantment(args[0], Integer.valueOf(args[1]))
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK)
EnchantmentStorageMeta meta = book.itemMeta
EnchantmentStorageMeta meta = book.itemMeta as EnchantmentStorageMeta
Tuple<org.bukkit.enchantments.Enchantment, Integer> tuple = WrappersAdapter.wEnchantToEnchant(enchantment)
meta.addStoredEnchant(tuple.key, tuple.value, true)
book.setItemMeta(meta)
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/GiveItem.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import it.fulminazzo.yagl.items.Item
import it.fulminazzo.yagl.items.fields.ItemFlag
import it.fulminazzo.yagl.wrappers.Enchantment
import it.fulminazzo.yagl.wrappers.WrapperParser
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
Item item = Item.newItem(args[0])
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/GivePersistentItem.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import it.fulminazzo.yagl.items.PersistentItem
import it.fulminazzo.yagl.items.fields.ItemFlag
import it.fulminazzo.yagl.wrappers.Enchantment
import it.fulminazzo.yagl.wrappers.WrapperParser
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
DeathAction action = DeathAction.valueOf(args[0].toUpperCase())
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/OpenDataGUI.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import it.fulminazzo.yagl.guis.PageableGUI
import it.fulminazzo.yagl.items.BukkitItem
import it.fulminazzo.yagl.utils.EnumUtils
import org.bukkit.Material
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

import java.util.function.Function

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
def data = [
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/OpenGUI.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import it.fulminazzo.yagl.guis.GUIType
import it.fulminazzo.yagl.items.Item
import it.fulminazzo.yagl.items.fields.ItemFlag
import it.fulminazzo.yagl.utils.EnumUtils
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
def columns = 9
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/OpenPageableGUI.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import it.fulminazzo.yagl.guis.PageableGUI
import it.fulminazzo.yagl.items.BukkitItem
import it.fulminazzo.yagl.utils.EnumUtils
import org.bukkit.Material
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player)
try {
PageableGUI gui
Expand Down
5 changes: 3 additions & 2 deletions demo/src/main/resources/commands/PlayEffect.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import it.fulminazzo.yagl.particles.PotionParticleOption
import it.fulminazzo.yagl.particles.PrimitiveParticleOption
import it.fulminazzo.yagl.wrappers.Potion
import it.fulminazzo.fulmicollection.objects.Refl
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

static getOption(sender, particleType, optionType, args) {
static getOption(CommandSender sender, LegacyParticleType particleType, Class optionType, String[] args) {
if (optionType == PotionParticleOption)
new PotionParticleOption(new Potion(args[0], Integer.valueOf(args[1]),
Boolean.valueOf(args[2]), Boolean.valueOf(args[3])))
Expand All @@ -39,7 +40,7 @@ static getOption(sender, particleType, optionType, args) {
else throw new IllegalArgumentException("Cannot get particle option of ${optionType}")
}

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player) {
try {
LegacyParticleType type = LegacyParticleType.valueOf(args[0])
Expand Down
5 changes: 3 additions & 2 deletions demo/src/main/resources/commands/PlayParticle.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import it.fulminazzo.yagl.particles.ParticleType
import it.fulminazzo.yagl.particles.PrimitiveParticleOption
import it.fulminazzo.fulmicollection.objects.Refl
import org.bukkit.Location
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot

static getOption(sender, particleType, optionType, args) {
static getOption(CommandSender sender, ParticleType particleType, Class optionType, String[] args) {
if (optionType == DustParticleOption)
new DustParticleOption(Color.fromARGB(args[0]), Float.valueOf(args[1]))
else if (optionType == DustTransitionParticleOption)
Expand All @@ -40,7 +41,7 @@ static getOption(sender, particleType, optionType, args) {
else throw new IllegalArgumentException("Cannot get particle option of ${optionType}")
}

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player) {
try {
ParticleType type = ParticleType.valueOf(args[0])
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/PlayYAGLCustomSound.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import it.fulminazzo.yagl.WrappersAdapter
import it.fulminazzo.yagl.wrappers.Sound
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player) {
try {
Sound sound = new Sound(args[0], Float.valueOf(args[1]), Float.valueOf(args[2]), args[3])
Expand Down
3 changes: 2 additions & 1 deletion demo/src/main/resources/commands/PlayYAGLSound.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import it.fulminazzo.yagl.WrappersAdapter
import it.fulminazzo.yagl.wrappers.Sound
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

def run = { sender, label, args ->
def run = { CommandSender sender, String label, String[] args ->
if (sender instanceof Player) {
try {
Sound sound = new Sound(args[0], Float.valueOf(args[1]), Float.valueOf(args[2]), args[3])
Expand Down

0 comments on commit a1bc00f

Please sign in to comment.