Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 189 lines 6.1 kB view raw
1package net.minecraft.server; 2 3import java.util.List; 4import java.util.Random; 5 6import org.bukkit.craftbukkit.event.CraftEventFactory; 7import org.bukkit.event.block.BlockRedstoneEvent; 8import org.bukkit.event.entity.EntityInteractEvent; 9 10import uk.betacraft.uberbukkit.Uberbukkit; 11 12public class BlockPressurePlate extends Block { 13 14 private EnumMobType a; 15 16 protected BlockPressurePlate(int i, int j, EnumMobType enummobtype, Material material) { 17 super(i, j, Uberbukkit.getTargetPVN() >= 12 ? material : Material.STONE); 18 this.a = enummobtype; 19 this.a(true); 20 float f = 0.0625F; 21 22 this.a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f); 23 } 24 25 public int c() { 26 return 20; 27 } 28 29 public AxisAlignedBB e(World world, int i, int j, int k) { 30 return null; 31 } 32 33 public boolean a() { 34 return false; 35 } 36 37 public boolean b() { 38 return false; 39 } 40 41 public boolean canPlace(World world, int i, int j, int k) { 42 return world.e(i, j - 1, k); 43 } 44 45 public void c(World world, int i, int j, int k) { 46 } 47 48 public void doPhysics(World world, int i, int j, int k, int l) { 49 boolean flag = false; 50 51 if (!world.e(i, j - 1, k)) { 52 flag = true; 53 } 54 55 if (flag) { 56 this.g(world, i, j, k, world.getData(i, j, k)); 57 world.setTypeId(i, j, k, 0); 58 } 59 } 60 61 public void a(World world, int i, int j, int k, Random random) { 62 if (!world.isStatic) { 63 if (world.getData(i, j, k) != 0) { 64 this.g(world, i, j, k); 65 } 66 } 67 } 68 69 public void a(World world, int i, int j, int k, Entity entity) { 70 if (!world.isStatic) { 71 if (world.getData(i, j, k) != 1) { 72 this.g(world, i, j, k); 73 } 74 } 75 } 76 77 private void g(World world, int i, int j, int k) { 78 boolean flag = world.getData(i, j, k) == 1; 79 boolean flag1 = false; 80 float f = 0.125F; 81 List list = null; 82 83 if (this.a == EnumMobType.EVERYTHING) { 84 list = world.b((Entity) null, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f))); 85 } 86 87 if (this.a == EnumMobType.MOBS) { 88 list = world.a(EntityLiving.class, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f))); 89 } 90 91 if (this.a == EnumMobType.PLAYERS) { 92 list = world.a(EntityHuman.class, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f))); 93 } 94 95 if (list.size() > 0) { 96 flag1 = true; 97 } 98 99 // CraftBukkit start - Interact Pressure Plate 100 org.bukkit.World bworld = world.getWorld(); 101 org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager(); 102 103 if (flag != flag1) { 104 if (flag1) { 105 for (Object object : list) { 106 if (object != null) { 107 org.bukkit.event.Cancellable cancellable; 108 109 if (object instanceof EntityHuman) { 110 cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) object, org.bukkit.event.block.Action.PHYSICAL, i, j, k, -1, null); 111 } else if (object instanceof Entity) { 112 cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), bworld.getBlockAt(i, j, k)); 113 manager.callEvent((EntityInteractEvent) cancellable); 114 } else { 115 continue; 116 } 117 if (cancellable.isCancelled()) { 118 return; 119 } 120 } 121 } 122 } 123 124 BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bworld.getBlockAt(i, j, k), flag ? 1 : 0, flag1 ? 1 : 0); 125 manager.callEvent(eventRedstone); 126 127 flag1 = eventRedstone.getNewCurrent() > 0; 128 } 129 // CraftBukkit end 130 131 if (flag1 && !flag) { 132 world.setData(i, j, k, 1); 133 world.applyPhysics(i, j, k, this.id); 134 world.applyPhysics(i, j - 1, k, this.id); 135 world.b(i, j, k, i, j, k); 136 world.makeSound((double) i + 0.5D, (double) j + 0.1D, (double) k + 0.5D, "random.click", 0.3F, 0.6F); 137 } 138 139 if (!flag1 && flag) { 140 world.setData(i, j, k, 0); 141 world.applyPhysics(i, j, k, this.id); 142 world.applyPhysics(i, j - 1, k, this.id); 143 world.b(i, j, k, i, j, k); 144 world.makeSound((double) i + 0.5D, (double) j + 0.1D, (double) k + 0.5D, "random.click", 0.3F, 0.5F); 145 } 146 147 if (flag1) { 148 world.c(i, j, k, this.id, this.c()); 149 } 150 } 151 152 public void remove(World world, int i, int j, int k) { 153 int l = world.getData(i, j, k); 154 155 if (l > 0) { 156 world.applyPhysics(i, j, k, this.id); 157 world.applyPhysics(i, j - 1, k, this.id); 158 } 159 160 super.remove(world, i, j, k); 161 } 162 163 public void a(IBlockAccess iblockaccess, int i, int j, int k) { 164 boolean flag = iblockaccess.getData(i, j, k) == 1; 165 float f = 0.0625F; 166 167 if (flag) { 168 this.a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f); 169 } else { 170 this.a(f, 0.0F, f, 1.0F - f, 0.0625F, 1.0F - f); 171 } 172 } 173 174 public boolean a(IBlockAccess iblockaccess, int i, int j, int k, int l) { 175 return iblockaccess.getData(i, j, k) > 0; 176 } 177 178 public boolean d(World world, int i, int j, int k, int l) { 179 return world.getData(i, j, k) == 0 ? false : l == 1; 180 } 181 182 public boolean isPowerSource() { 183 return true; 184 } 185 186 public int e() { 187 return 1; 188 } 189}