Package dev.selena.luacore.utils.lua
Class ScriptHelper
java.lang.Object
dev.selena.luacore.utils.lua.ScriptHelper
A useful tool for script assistance parsed into lua scripts as arg.scriptHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyPotionEffect(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType effectType, int duration, int amplifier) applies a potion effect to the player Note: if you are running the script on a different thread you will need to use applyPotionEffectAsyncvoidapplyPotionEffectAsync(org.bukkit.entity.Player player, String effectType, int duration, int amplifier) Used for when you cant seem to bind the class in luavoidapplyPotionEffectAsync(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType effectType, int duration, int amplifier) Used for applying potion effects when the Lua script isn't on the main threadvoiddropItem(org.bukkit.inventory.ItemStack item, org.bukkit.Location loc) Used for dropping an ItemStack at a location in the worldstatic org.luaj.vm2.LuaValueextractConstantValue(String path, String constantName) Used for getting a LuaValue from a scriptorg.bukkit.block.BlockgetBlockAtLocation(org.bukkit.Location loc) Used for getting the Block at a locationorg.bukkit.LocationgetBlockLocation(org.bukkit.block.Block block) Used for getting the location of a blockstatic intgetIntFromLuaValue(org.luaj.vm2.LuaValue content) Used for getting an Integer from a LuaValueorg.bukkit.inventory.ItemStackgetItem(org.bukkit.Material type, int amount) Used for getting an ItemStack in luabooleangetProbability(int min, int max, int goal) Generates a random int between min and max then checks if its equal to the goal Added because I feel Luas Math.random(min, max) is too high bias.static String[]getStringArrayFromLuaValue(org.luaj.vm2.LuaValue content) Used for getting a string array from a LuaValuestatic StringgetStringFromLuaValue(org.luaj.vm2.LuaValue content) Used for getting a string from a LuaValuevoidgiveItem(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item) User for giving a player an ItemStackstatic booleanhasDebuff(org.bukkit.entity.Player player) Checks if the player has a debuff potion effectstatic booleanhasPotionEffect(org.bukkit.entity.Player player, String potionEffect) Used for checking if the player has a potion effectstatic StringintToRoman(int num) Used for converting an Int to roman numeralsstatic booleanisDebuff(org.bukkit.potion.PotionEffectType effectType) Used for checking of a potion effect is a debuffstatic Object[]multiplyArray(Object[] array, int amount) Used for duplicating the array x times Example of use, I had a mask plugin and one of the maks gave 2x the rewards from fishing Using this method you can double the rewards easilystatic voidremoveDebuffs(org.bukkit.entity.Player player) Removes all debuffs from the playerstatic voidremoveEffectAsync(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType effect) Used for removing a single effect from a player on an async threadstatic voidremoveEffects(org.bukkit.entity.Player player, List<org.bukkit.potion.PotionEffectType> effects) Used for removing potion effects from a playerstatic voidremoveEffects(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType... effects) Used for removing potion effects from a playerstatic voidremoveEffectsAsync(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType... effects) Used for removing potion effects when on a different threadvoidsetAttribute(org.bukkit.entity.LivingEntity entity, String registryName, double value) Used for setting an entity attributesvoidsetAttributeAsync(org.bukkit.entity.LivingEntity entity, String registryName, double value) Used for setting an entity attributesvoidsetBlockAtLocation(org.bukkit.Location loc, org.bukkit.Material blockType) voidsetItemInEquipmentSlot(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, org.bukkit.inventory.EquipmentSlot slot, int... amount) Used for updating the item in a specified EquipmentSlot on the main threadvoidsetItemInEquipmentSlotAsync(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, org.bukkit.inventory.EquipmentSlot slot, int... amount) Used for updating the item in a specified EquipmentSlot on an async threadvoidsetItemInMainHand(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the main hand on the main threadvoidsetItemInMainHandAsync(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the main hand on an async threadvoidsetItemInOffHand(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the offhand on the main threadvoidsetItemInOffHandAsync(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the offhand on an async thread
-
Constructor Details
-
ScriptHelper
public ScriptHelper()
-
-
Method Details
-
applyPotionEffect
public void applyPotionEffect(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType effectType, int duration, int amplifier) applies a potion effect to the player Note: if you are running the script on a different thread you will need to use applyPotionEffectAsync- Parameters:
player- The player you want to effecteffectType- The potion effect typeduration- Duration of the effect (-1 for infinite)amplifier- The amplifier of the effect- See Also:
-
applyPotionEffectAsync
public void applyPotionEffectAsync(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType effectType, int duration, int amplifier) Used for applying potion effects when the Lua script isn't on the main thread- Parameters:
player- The player you want to effecteffectType- The potion effect typeduration- The duration of the effectamplifier- The amplifier of the effect
-
applyPotionEffectAsync
public void applyPotionEffectAsync(org.bukkit.entity.Player player, String effectType, int duration, int amplifier) Used for when you cant seem to bind the class in lua- Parameters:
player- The player you want to effecteffectType- The String Name of the potion effectduration- The durationamplifier- The amplifier
-
setAttributeAsync
public void setAttributeAsync(org.bukkit.entity.LivingEntity entity, String registryName, double value) Used for setting an entity attributes- Parameters:
entity- The entity you want to modifyregistryName- The minecraft registry name you want to setvalue- The value (0d or 1d for boolean)
-
setAttribute
Used for setting an entity attributes- Parameters:
entity- The entity you want to modifyregistryName- The minecraft registry name you want to setvalue- The value (0d or 1d for boolean)
-
getItem
public org.bukkit.inventory.ItemStack getItem(org.bukkit.Material type, int amount) Used for getting an ItemStack in lua- Parameters:
type- The Material typeamount- The ItemStack size- Returns:
- The requested ItemStack
-
getBlockLocation
public org.bukkit.Location getBlockLocation(org.bukkit.block.Block block) Used for getting the location of a block- Parameters:
block- The block you want the location of- Returns:
- Location of the block
-
setBlockAtLocation
public void setBlockAtLocation(org.bukkit.Location loc, org.bukkit.Material blockType) -
getBlockAtLocation
public org.bukkit.block.Block getBlockAtLocation(org.bukkit.Location loc) Used for getting the Block at a location- Parameters:
loc- The location you want the block of- Returns:
- The block at the requested location
-
dropItem
public void dropItem(org.bukkit.inventory.ItemStack item, org.bukkit.Location loc) Used for dropping an ItemStack at a location in the world- Parameters:
item- The Item you want to droploc- The location you want to drop it
-
giveItem
public void giveItem(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item) User for giving a player an ItemStack- Parameters:
player- The player you want to give the Item toitem- The ItemStack you want to give
-
setItemInMainHandAsync
public void setItemInMainHandAsync(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the main hand on an async thread- Parameters:
player- The player you want to updateitem- The new/modified itemamount- optionally, the amount you want to set it to
-
setItemInOffHandAsync
public void setItemInOffHandAsync(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the offhand on an async thread- Parameters:
player- The player you want to updateitem- The new/modified itemamount- optionally, the amount you want to set it to
-
setItemInEquipmentSlotAsync
public void setItemInEquipmentSlotAsync(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, org.bukkit.inventory.EquipmentSlot slot, int... amount) Used for updating the item in a specified EquipmentSlot on an async thread- Parameters:
player- The player you want to updateitem- The new/modified itemslot- The EquipmentSlotamount- optionally, the amount you want to set it to- See Also:
-
setItemInMainHand
public void setItemInMainHand(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the main hand on the main thread- Parameters:
player- The player you want to updateitem- The new/modified itemamount- optionally, the amount you want to set it to
-
setItemInOffHand
public void setItemInOffHand(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, int... amount) Used for updating the item in the offhand on the main thread- Parameters:
player- The player you want to updateitem- The new/modified itemamount- optionally, the amount you want to set it to
-
setItemInEquipmentSlot
public void setItemInEquipmentSlot(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item, org.bukkit.inventory.EquipmentSlot slot, int... amount) Used for updating the item in a specified EquipmentSlot on the main thread- Parameters:
player- The player you want to updateitem- The new/modified itemslot- The EquipmentSlotamount- optionally, the amount you want to set it to- See Also:
-
getProbability
public boolean getProbability(int min, int max, int goal) Generates a random int between min and max then checks if its equal to the goal Added because I feel Luas Math.random(min, max) is too high bias.- Parameters:
min- The min value (exclusive)max- The max value (inclusive)goal- The number you are aiming to be below- Returns:
- True if below the number false if above
-
extractConstantValue
Used for getting a LuaValue from a script- Parameters:
path- The script name and pathconstantName- The variable you want to get- Returns:
- Returns a LuaValue object from the script
- See Also:
-
intToRoman
Used for converting an Int to roman numerals- Parameters:
num- The number you want to convert- Returns:
- The roman numeral value for the int
-
getStringFromLuaValue
Used for getting a string from a LuaValue- Parameters:
content- The LuaValue you want to convert to a string- Returns:
- String from the LuaValue
- See Also:
-
getStringArrayFromLuaValue
Used for getting a string array from a LuaValue- Parameters:
content- The LuaValue you want to convert- Returns:
- String[] of the LuaValue parsed in
- See Also:
-
getIntFromLuaValue
public static int getIntFromLuaValue(org.luaj.vm2.LuaValue content) Used for getting an Integer from a LuaValue- Parameters:
content- The LuaValue you want to convert- Returns:
- int of the LuaValue parsed in
- See Also:
-
isDebuff
public static boolean isDebuff(org.bukkit.potion.PotionEffectType effectType) Used for checking of a potion effect is a debuff- Parameters:
effectType- The potion effect you want to check- Returns:
- True if the effect is a debuff
-
hasDebuff
public static boolean hasDebuff(org.bukkit.entity.Player player) Checks if the player has a debuff potion effect- Parameters:
player- The player you want to check- Returns:
- True if the player has a debuff
-
hasPotionEffect
Used for checking if the player has a potion effect- Parameters:
player- The player you want to checkpotionEffect- The name of the potion effect- Returns:
- True if the player has the effect (False if the effect doesn't exist)
-
removeDebuffs
public static void removeDebuffs(org.bukkit.entity.Player player) Removes all debuffs from the player- Parameters:
player- The player you want to remove the debuffs from
-
removeEffects
public static void removeEffects(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType... effects) Used for removing potion effects from a player- Parameters:
player- The player you want to remove the effects fromeffects- The potion effects you want to remove
-
removeEffects
public static void removeEffects(org.bukkit.entity.Player player, List<org.bukkit.potion.PotionEffectType> effects) Used for removing potion effects from a player- Parameters:
player- The player you want to remove the effects fromeffects- The potion effects you want to remove
-
removeEffectsAsync
public static void removeEffectsAsync(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType... effects) Used for removing potion effects when on a different thread- Parameters:
player- The player you want to remove potion effects fromeffects- The potion effect you want to remove from the player
-
removeEffectAsync
public static void removeEffectAsync(org.bukkit.entity.Player player, org.bukkit.potion.PotionEffectType effect) Used for removing a single effect from a player on an async thread- Parameters:
player- The player you want to remove the effect fromeffect- The effect type you want to remove
-
multiplyArray
Used for duplicating the array x times Example of use, I had a mask plugin and one of the maks gave 2x the rewards from fishing Using this method you can double the rewards easily- Parameters:
array- The array you want to duplicateamount- The amount of duplicates that should go into the array- Returns:
- The new array
-