Search in sources :

Example 26 with Event

use of org.bukkit.event.Event in project Denizen-For-Bukkit by DenizenScript.

the class ModifyBlockCommand method handleLocation.

void handleLocation(LocationTag location, int index, List<MaterialTag> materialList, boolean doPhysics, ItemTag natural, int radius, int height, int depth, List<Float> percents, Player source, ScriptEntry entry) {
    MaterialTag material;
    if (percents == null) {
        material = materialList.get(index % materialList.size());
    } else {
        material = null;
        for (int i = 0; i < materialList.size(); i++) {
            float perc = percents.get(i) / 100f;
            if (CoreUtilities.getRandom().nextDouble() <= perc) {
                material = materialList.get(i);
                break;
            }
        }
        if (material == null) {
            return;
        }
    }
    World world = location.getWorld();
    location.setX(location.getBlockX());
    location.setY(location.getBlockY());
    location.setZ(location.getBlockZ());
    if (source != null) {
        Event event;
        if (material.getMaterial() == Material.AIR) {
            event = new BlockBreakEvent(location.getBlock(), source);
        } else {
            Block block = location.getBlock();
            BlockState state = NMSHandler.getBlockHelper().generateBlockState(block, material.getMaterial());
            state.setBlockData(material.getModernData());
            event = new BlockPlaceEvent(block, state, block, new ItemTag(material, 1).getItemStack(), source, true, EquipmentSlot.HAND);
        }
        Bukkit.getPluginManager().callEvent(event);
        if (((Cancellable) event).isCancelled()) {
            if (entry.dbCallShouldDebug()) {
                Debug.echoDebug(entry, "Source event cancelled, not changing block.");
            }
            return;
        }
    }
    setBlock(location, material, doPhysics, natural);
    if (radius != 0) {
        for (int x = 0; x < 2 * radius + 1; x++) {
            for (int z = 0; z < 2 * radius + 1; z++) {
                setBlock(new Location(world, location.getX() + x - radius, location.getY(), location.getZ() + z - radius), material, doPhysics, natural);
            }
        }
    }
    if (height != 0) {
        for (int x = 0; x < 2 * radius + 1; x++) {
            for (int z = 0; z < 2 * radius + 1; z++) {
                for (int y = 1; y < height + 1; y++) {
                    setBlock(new Location(world, location.getX() + x - radius, location.getY() + y, location.getZ() + z - radius), material, doPhysics, natural);
                }
            }
        }
    }
    if (depth != 0) {
        for (int x = 0; x < 2 * radius + 1; x++) {
            for (int z = 0; z < 2 * radius + 1; z++) {
                for (int y = 1; y < depth + 1; y++) {
                    setBlock(new Location(world, location.getX() + x - radius, location.getY() - y, location.getZ() + z - radius), material, doPhysics, natural);
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) Cancellable(org.bukkit.event.Cancellable) Event(org.bukkit.event.Event) EntityChangeBlockEvent(org.bukkit.event.entity.EntityChangeBlockEvent) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) BlockPhysicsEvent(org.bukkit.event.block.BlockPhysicsEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location)

Aggregations

Event (org.bukkit.event.Event)26 Listener (org.bukkit.event.Listener)8 Test (org.junit.Test)7 EventException (org.bukkit.event.EventException)6 EventHandler (org.bukkit.event.EventHandler)6 EventExecutor (org.bukkit.plugin.EventExecutor)6 PluginManager (org.bukkit.plugin.PluginManager)6 RegisteredListener (org.bukkit.plugin.RegisteredListener)5 Cancellable (org.bukkit.event.Cancellable)4 TestEvent (org.bukkit.event.TestEvent)4 Field (java.lang.reflect.Field)3 Map (java.util.Map)3 Set (java.util.Set)3 EventPriority (org.bukkit.event.EventPriority)3 File (java.io.File)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 ConquerFaction (me.andrew28.addons.conquer.api.ConquerFaction)2 ConquerPlayer (me.andrew28.addons.conquer.api.ConquerPlayer)2 ConquerFactionCreateEvent (me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent)2