OpenJS-docs
Download plugin
  • Overview
    • Welcome
  • Getting Started
    • Installing the plugin
    • Configuration file
    • Commands
    • Creating scripts
  • OpenJS Components
    • Feature Flags
    • Managing scripts within scripts
    • Sharing variables between scripts
    • Custom Commands
    • Using PlaceHolderApi
    • Listening and cancelling events
    • Custom events
    • Loading and saving data
    • Logging in console
    • Scheduling
    • Java imports
  • Example Scripts
    • spawn hit stand command
    • Knockbackstick command
    • No hit-cooldown script
    • NoBlockPlacing script
    • Saving Player data script
    • running code asynchronously
    • WhileTrue do script
Powered by GitBook
On this page
  1. Example Scripts

spawn hit stand command

hitstandcommand.js
var Bukkit = org.bukkit;
var PotionEffect = Bukkit.potion.PotionEffect;
var PotionEffectType = Bukkit.potion.PotionEffectType;

// Damage listener for "noVuln" tagged entities
registerEvent("org.bukkit.event.entity.EntityDamageEvent", {
    handleEvent: function(event) {
        var entity = event.getEntity();

        if (entity.getScoreboardTags().contains("noVuln")) {
            // Optionally restore full health
            if (entity.getHealth() < entity.getMaxHealth()) {
                entity.setHealth(entity.getMaxHealth());
            }
        }
    }
});

// Command to spawn an invincible, no-AI zombie
addCommand("hitstand", {
    onCommand: function(sender, args) {
        args = toArray(args);

        if (!sender.getLocation) {
            sender.sendMessage("§cThis command can only be used by players.");
            return;
        }

        var loc = sender.getLocation();
        var zombie = sender.getWorld().spawn(loc, Bukkit.entity.Zombie.class);

        zombie.setSilent(true);
        zombie.setPersistent(true);
        zombie.setCollidable(true);
        zombie.setInvulnerable(false);
        zombie.addScoreboardTag("noVuln");

        // Prevent movement with slowness 255
        zombie.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, 1000000000, 255, true, false));
        sender.sendMessage("§aSpawned a zombie that appears invincible.");
    }
});
PreviousJava importsNextKnockbackstick command

Last updated 4 days ago