All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.BlockPressurePlateBinary Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package net.minecraft.server;

import org.bukkit.event.entity.EntityInteractEvent;

import java.util.List;

public class BlockPressurePlateBinary extends BlockPressurePlateAbstract {

  public static final BlockStateBoolean POWERED = BlockStateBoolean.of("powered");
  private final BlockPressurePlateBinary.EnumMobType b;

  protected BlockPressurePlateBinary(Material material, BlockPressurePlateBinary.EnumMobType blockpressureplatebinary_enummobtype) {
    super(material);
    this.j(this.blockStateList.getBlockData().set(BlockPressurePlateBinary.POWERED, false));
    this.b = blockpressureplatebinary_enummobtype;
  }

  protected int e(IBlockData iblockdata) {
    return iblockdata.get(BlockPressurePlateBinary.POWERED) ? 15 : 0;
  }

  protected IBlockData a(IBlockData iblockdata, int i) {
    return iblockdata.set(BlockPressurePlateBinary.POWERED, i > 0);
  }

  protected int f(World world, BlockPosition blockposition) {
    AxisAlignedBB axisalignedbb = this.getBoundingBox(blockposition);
    List list;

    switch (BlockPressurePlateBinary.SyntheticClass_1.a[this.b.ordinal()]) {
      case 1:
        list = world.getEntities(null, axisalignedbb);
        break;

      case 2:
        list = world.a(EntityLiving.class, axisalignedbb);
        break;

      default:
        return 0;
    }

    if (!list.isEmpty()) {
  
      for (Entity value : list) {
  
        // CraftBukkit start - Call interact event when turning on a pressure plate
        if (this.e(world.getType(blockposition)) == 0) {
          org.bukkit.World bworld = world.getWorld();
          org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager();
          org.bukkit.event.Cancellable cancellable;
      
          if (value instanceof EntityHuman) {
            cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) value, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null);
          } else {
            cancellable = new EntityInteractEvent(value.getBukkitEntity(), bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
            manager.callEvent((EntityInteractEvent) cancellable);
          }
      
          // We only want to block turning the plate on if all events are cancelled
          if (cancellable.isCancelled()) {
            continue;
          }
        }
        // CraftBukkit end
    
        if (!value.aI()) {
          return 15;
        }
      }
    }

    return 0;
  }

  public IBlockData fromLegacyData(int i) {
    return this.getBlockData().set(BlockPressurePlateBinary.POWERED, i == 1);
  }

  public int toLegacyData(IBlockData iblockdata) {
    return iblockdata.get(BlockPressurePlateBinary.POWERED) ? 1 : 0;
  }

  protected BlockStateList getStateList() {
    return new BlockStateList(this, BlockPressurePlateBinary.POWERED);
  }

  public enum EnumMobType {
    EVERYTHING,
    MOBS;

    EnumMobType() {
    }
  }

  static class SyntheticClass_1 {

    static final int[] a = new int[BlockPressurePlateBinary.EnumMobType.values().length];

    static {
      try {
        BlockPressurePlateBinary.SyntheticClass_1.a[BlockPressurePlateBinary.EnumMobType.EVERYTHING.ordinal()] = 1;
      } catch (NoSuchFieldError ignored) {
      }

      try {
        BlockPressurePlateBinary.SyntheticClass_1.a[BlockPressurePlateBinary.EnumMobType.MOBS.ordinal()] = 2;
      } catch (NoSuchFieldError ignored) {
      }

    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy