Compile and execute programs on the fly with groovy scripts ideally this will also pull from a git repo but currently it listens to all changes plugins/CobbleGroovy/scripts
Pre set up Script Environment: https://github.com/HeathLoganCampbell/CobbleGroovy-Scripts
- Init.Groovy gets called, this is where you set up your watch files
package scripts.global
import dev.cobblesword.cobblegroovy.tools.CC
import me.lucko.helper.Commands
import me.lucko.helper.Events
import me.lucko.helper.Schedulers
import me.lucko.helper.hologram.BaseHologram
import me.lucko.helper.hologram.BukkitHologramFactory
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.boss.BarColor
import org.bukkit.boss.BarFlag
import org.bukkit.boss.BarStyle
import org.bukkit.boss.BossBar
import org.bukkit.entity.Player
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.player.AsyncPlayerChatEvent
Commands.create().assertPermission("example.command.yeet")
.assertPlayer()
.handler(sender -> {
sender.sender().sendMessage(ChatColor.RED.toString() + "Weeee")
BaseHologram hologram = new BukkitHologramFactory()
.newHologram(Position.of(sender.sender().getLocation()),
[
CC.red + "Hello world",
"I Am Iron Man"
])
hologram.spawn()
BossBar bossBar = Bukkit.createBossBar("yeet world", BarColor.WHITE, BarStyle.SOLID, BarFlag.DARKEN_SKY)
bossBar.addPlayer(sender.sender())
}).registerAndBind(registry, "yeet")
Schedulers.async().runRepeating(() -> {
Bukkit.broadcastMessage(CC.red + "Example")
}, 20, 20).bindWith(registry)
Events.subscribe(BlockPlaceEvent.class).handler{
Block block = it.getBlock()
block.setType(Material.GOLD_BLOCK)
}.bindWith(registry)
Events.subscribe(AsyncPlayerChatEvent.class).handler{
it.setFormat(CC.red + "%s: %s")
it.getPlayer().sendMessage("ABCCC")
}.bindWith(registry)
Schedulers.async().runRepeating(() -> {
for (Player player : Bukkit.getOnlinePlayers())
{
player.setPlayerListName(" My Name Jeff ")
player.setPlayerListHeaderFooter("Header", "fotters")
}
}, 20, 20).bindWith(registry)
Commands.create().handler { command ->
command.sender().sendMessage("Test")
}.register("Example")
Events.subscribe(InventoryCloseEvent.class).handler { event ->
def player = event.getPlayer()
player.sendMessage("Hello world")
}
Database.executeQuery("SELECT * FROM table WHERE id = ?",
{ statement -> statement.setInt(1, 1) },
{ result -> })
Database.execute("DELETE FROM table", { statement -> })
package scripts.global
import dev.cobblesword.cobblegroovy.tools.CC
import dev.cobblesword.cobblegroovy.tools.item.Items
import me.lucko.helper.Commands
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.block.BlockFace
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerMoveEvent
// create new item, cheese that when eld leaves a trail of sponges
CustomItem cheese = Items.create("CHEESE", Material.SPONGE)
.displayName(CC.bYellow + "Cheese")
.subscribe(PlayerMoveEvent.class, (e, item, customItem) -> {
Player player = e.getPlayer();
Location location = player.getLocation();
Block block = location.getBlock();
Block standingBlock = block.getRelative(BlockFace.DOWN);
if (standingBlock.getType() != Material.AIR) {
standingBlock.setType(Material.SPONGE);
}
})
cheese.bindWith(registry)
// Give new custom item
Commands.create().assertPlayer()
.handler { cmd ->
var sender = cmd.sender()
sender.getInventory().addItem(cheese.getItemStack())
}.registerAndBind(registry, "cheese")
For more info on the api, look at lucko's helper repository's wiki
To get rid of .bindWith(registry)
being scrattered everywhere, we need to add our own wrappers to Events, Commands, Schedulers and call Events.init(registry) once the file starts to be read and Events.complete() once the file is finished. the limitation here is we cannot have any registered events async or delayed.
class Events
{
private static GroovyScript currentGroovyScript;
public static void init(GroovyScript currentGroovyScript)
{
currentGroovyScript = currentGroovyScript;
}
public static void complete()
{
currentGroovyScript = null;
}
public static void subscribe(class class, EventPriority eventPriority)
{
if(currentGroovyScript == null) throw exception;
Events.subscribe(class, eventPriority).bindWith(currentGroovyScript)
}
}