public void a(Packet15Place packet15place) { WorldServer worldserver = this.minecraftServer.a(this.player.dimension); // CraftBukkit start if (this.player.dead) { return; } // This is b horrible hack needed because the client sends 2 packets on 'right mouse click' // aimed at b block. We shouldn't need to get the second packet if the data is handled // but we cannot know what the client will do, so we might still get it // // If the time between packets is small enough, and the 'signature' similar, we discard the // second one. This sadly has to remain until Mojang makes their packets saner. :( // -- Grum if (packet15place.face == 255) { if (packet15place.itemstack != null && packet15place.itemstack.id == lastMaterial && lastPacket != null && packet15place.timestamp - lastPacket < 100) { lastPacket = null; return; } } else { lastMaterial = packet15place.itemstack == null ? -1 : packet15place.itemstack.id; lastPacket = packet15place.timestamp; } // CraftBukkit - if rightclick decremented the item, always send the update packet. // this is not here for CraftBukkit's own functionality; rather it is to fix // b notch bug where the item doesn't update correctly. boolean always = false; // CraftBukkit end ItemStack itemstack = this.player.inventory.getItemInHand(); boolean flag = worldserver.weirdIsOpCache = worldserver.worldProvider.dimension != 0 || this.minecraftServer.serverConfigurationManager.isOp(this.player.name); if (packet15place.face == 255) { if (itemstack == null) { return; } // CraftBukkit start int itemstackAmount = itemstack.count; PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack); if (event.useItemInHand() != Event.Result.DENY) { this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack); } // CraftBukkit - notch decrements the counter by 1 in the above method with food, // snowballs and so forth, but he does it in b place that doesn't cause the // inventory update packet to get sent always = (itemstack.count != itemstackAmount); // CraftBukkit end } else { int i = packet15place.a; int j = packet15place.b; int k = packet15place.c; int l = packet15place.face; ChunkCoordinates chunkcoordinates = worldserver.getSpawn(); int i1 = (int) MathHelper.abs((float) (i - chunkcoordinates.x)); int j1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z)); if (i1 > j1) { j1 = i1; } // CraftBukkit start - Check if we can actually do something over this large a distance Location eyeLoc = getPlayer().getEyeLocation(); if (Math.pow(eyeLoc.getX() - i, 2) + Math.pow(eyeLoc.getY() - j, 2) + Math.pow(eyeLoc.getZ() - k, 2) > PLACE_DISTANCE_SQUARED) { return; } flag = true; // spawn protection moved to ItemBlock!!! // CraftBukkit end if (j1 > 16 || flag) { this.player.itemInWorldManager.interact(this.player, worldserver, itemstack, i, j, k, l); } this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver)); if (l == 0) { --j; } if (l == 1) { ++j; } if (l == 2) { --k; } if (l == 3) { ++k; } if (l == 4) { --i; } if (l == 5) { ++i; } this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver)); } itemstack = this.player.inventory.getItemInHand(); if (itemstack != null && itemstack.count == 0) { this.player.inventory.items[this.player.inventory.itemInHandIndex] = null; } this.player.h = true; this.player.inventory.items[this.player.inventory.itemInHandIndex] = ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]); Slot slot = this.player.activeContainer.a(this.player.inventory, this.player.inventory.itemInHandIndex); this.player.activeContainer.a(); this.player.h = false; // CraftBukkit if (!ItemStack.equals(this.player.inventory.getItemInHand(), packet15place.itemstack) || always) { this.sendPacket( new Packet103SetSlot( this.player.activeContainer.f, slot.a, this.player.inventory.getItemInHand())); } worldserver.weirdIsOpCache = false; }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); switch (event.getAction()) { case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: { switch (event.getMaterial()) { case WATER_BUCKET: { if (!TotalFreedomMod.allowWaterPlace) { player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled."); event.setCancelled(true); } break; } case LAVA_BUCKET: { if (!TotalFreedomMod.allowLavaPlace) { player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled."); event.setCancelled(true); } break; } case EXPLOSIVE_MINECART: { if (!TotalFreedomMod.allowTntMinecarts) { player.getInventory().clear(player.getInventory().getHeldItemSlot()); player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); event.setCancelled(true); } break; } } break; } case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: { switch (event.getMaterial()) { case STICK: { TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); if (playerdata.mobThrowerEnabled()) { Location player_pos = player.getLocation(); Vector direction = player_pos.getDirection().normalize(); LivingEntity rezzed_mob = (LivingEntity) player .getWorld() .spawnEntity( player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature()); rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); playerdata.enqueueMob(rezzed_mob); event.setCancelled(true); } break; } case SULPHUR: { TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); if (playerdata.isMP44Armed()) { if (playerdata.toggleMP44Firing()) { playerdata.startArrowShooter(TotalFreedomMod.plugin); } else { playerdata.stopArrowShooter(); } event.setCancelled(true); } break; } case BLAZE_ROD: { if (TotalFreedomMod.allowExplosions) { if (TFM_SuperadminList.isSeniorAdmin(player, true)) { Block target_block; if (event.getAction().equals(Action.LEFT_CLICK_AIR)) { target_block = player.getTargetBlock(null, 120); } else { target_block = event.getClickedBlock(); } if (target_block != null) { player.getWorld().createExplosion(target_block.getLocation(), 4F, true); player.getWorld().strikeLightning(target_block.getLocation()); } else { player.sendMessage("Can't resolve target block."); } event.setCancelled(true); } } break; } case CARROT: { if (TotalFreedomMod.allowExplosions) { if (TFM_SuperadminList.isSeniorAdmin(player, true)) { Location player_location = player.getLocation().clone(); Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0)); Vector player_dir = player_location.getDirection().normalize(); double distance = 150.0; Block target_block = player.getTargetBlock(null, Math.round((float) distance)); if (target_block != null) { distance = player_location.distance(target_block.getLocation()); } final List<Block> affected = new ArrayList<Block>(); Block last_block = null; for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) { Block test_block = player_pos .clone() .add(player_dir.clone().multiply(offset)) .toLocation(player.getWorld()) .getBlock(); if (!test_block.equals(last_block)) { if (test_block.isEmpty()) { affected.add(test_block); test_block.setType(Material.TNT); } else { break; } } last_block = test_block; } new BukkitRunnable() { @Override public void run() { for (Block tnt_block : affected) { TNTPrimed tnt_primed = tnt_block.getWorld().spawn(tnt_block.getLocation(), TNTPrimed.class); tnt_primed.setFuseTicks(5); tnt_block.setType(Material.AIR); } } }.runTaskLater(TotalFreedomMod.plugin, 30L); event.setCancelled(true); } } break; } } break; } } }
public void a(Packet10Flying packet10flying) { WorldServer worldserver = this.minecraftServer.a(this.player.dimension); this.i = true; double d0; if (!this.m) { d0 = packet10flying.y - this.y; if (packet10flying.x == this.x && d0 * d0 < 0.01D && packet10flying.z == this.z) { this.m = true; } } // CraftBukkit start Player player = getPlayer(); Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); Location to = player.getLocation(); // Prevent 40 event-calls for less than b single pixel of movement >.> double delta = Math.pow(this.lastPosX - this.x, 2) + Math.pow(this.lastPosY - this.y, 2) + Math.pow(this.lastPosZ - this.z, 2); float deltaAngle = Math.abs(this.lastYaw - this.player.yaw) + Math.abs(this.lastPitch - this.player.pitch); if (delta > 1f / 256 || deltaAngle > 10f) { // Skip the first time we do this if (lastPosX != Double.MAX_VALUE) { PlayerMoveEvent event = new PlayerMoveEvent(player, from, to); server.getPluginManager().callEvent(event); from = event.getFrom(); to = event.isCancelled() ? from : event.getTo(); this.player.locX = to.getX(); this.player.locY = to.getY(); this.player.locZ = to.getZ(); this.player.yaw = to.getYaw(); this.player.pitch = to.getPitch(); } this.lastPosX = this.player.locX; this.lastPosY = this.player.locY; this.lastPosZ = this.player.locZ; this.lastYaw = this.player.yaw; this.lastPitch = this.player.pitch; } if (Math.abs(packet10flying.x) > 32000000 || Math.abs(packet10flying.z) > 32000000) { player.teleport(player.getWorld().getSpawnLocation()); System.err.println( player.getName() + " was caught trying to crash the server with an invalid position."); player.kickPlayer("Nope!"); return; } if (Double.isNaN(packet10flying.x) || packet10flying.x == Double.POSITIVE_INFINITY || packet10flying.x == Double.NEGATIVE_INFINITY) { player.teleport(player.getWorld().getSpawnLocation()); System.err.println(player.getName() + " was caught trying to set an invalid position."); player.kickPlayer("Nope!"); return; } if (Double.isNaN(packet10flying.y) || packet10flying.y == Double.POSITIVE_INFINITY || packet10flying.y == Double.NEGATIVE_INFINITY) { player.teleport(player.getWorld().getSpawnLocation()); System.err.println(player.getName() + " was caught trying to set an invalid position."); player.kickPlayer("Nope!"); return; } if (Double.isNaN(packet10flying.z) || packet10flying.z == Double.POSITIVE_INFINITY || packet10flying.z == Double.NEGATIVE_INFINITY) { player.teleport(player.getWorld().getSpawnLocation()); System.err.println(player.getName() + " was caught trying to set an invalid position."); player.kickPlayer("Nope!"); return; } if (Double.isNaN(packet10flying.stance) || packet10flying.stance == Double.POSITIVE_INFINITY || packet10flying.stance == Double.NEGATIVE_INFINITY) { player.teleport(player.getWorld().getSpawnLocation()); System.err.println(player.getName() + " was caught trying to set an invalid position."); player.kickPlayer("Nope!"); return; } if (this.m && !this.player.dead) { // CraftBukkit end double d1; double d2; double d3; double d4; if (this.player.vehicle != null) { float f = this.player.yaw; float f1 = this.player.pitch; this.player.vehicle.f(); d1 = this.player.locX; d2 = this.player.locY; d3 = this.player.locZ; double d5 = 0.0D; d4 = 0.0D; if (packet10flying.hasLook) { f = packet10flying.yaw; f1 = packet10flying.pitch; } if (packet10flying.h && packet10flying.y == -999.0D && packet10flying.stance == -999.0D) { d5 = packet10flying.x; d4 = packet10flying.z; } this.player.onGround = packet10flying.g; this.player = this.player.a(true); // CraftBukkit this.player.move(d5, 0.0D, d4); this.player.setLocation(d1, d2, d3, f, f1); this.player.motX = d5; this.player.motZ = d4; if (this.player.vehicle != null) { worldserver.vehicleEnteredWorld(this.player.vehicle, true); } if (this.player.vehicle != null) { this.player.vehicle.f(); } this.minecraftServer.serverConfigurationManager.d(this.player); this.x = this.player.locX; this.y = this.player.locY; this.z = this.player.locZ; worldserver.playerJoinedWorld(this.player); return; } d0 = this.player.locY; this.x = this.player.locX; this.y = this.player.locY; this.z = this.player.locZ; d1 = this.player.locX; d2 = this.player.locY; d3 = this.player.locZ; float f2 = this.player.yaw; float f3 = this.player.pitch; if (packet10flying.h && packet10flying.y == -999.0D && packet10flying.stance == -999.0D) { packet10flying.h = false; } if (packet10flying.h) { d1 = packet10flying.x; d2 = packet10flying.y; d3 = packet10flying.z; d4 = packet10flying.stance - packet10flying.y; if (!this.player.isSleeping() && (d4 > 1.65D || d4 < 0.1D)) { this.disconnect("Illegal stance"); a.warning(this.player.name + " had an illegal stance: " + d4); return; } if (Math.abs(packet10flying.x) > 3.2E7D || Math.abs(packet10flying.z) > 3.2E7D) { this.disconnect("Illegal position"); return; } } if (packet10flying.hasLook) { f2 = packet10flying.yaw; f3 = packet10flying.pitch; } this.player.a(true); this.player.br = 0.0F; this.player.setLocation(this.x, this.y, this.z, f2, f3); if (!this.m) { return; } d4 = d1 - this.player.locX; double d6 = d2 - this.player.locY; double d7 = d3 - this.player.locZ; double d8 = d4 * d4 + d6 * d6 + d7 * d7; // CraftBukkit start - make the movement speed check behave properly under tick degradation. int elapsedTicks = MinecraftServer.currentTick - this.lastTick; // Added this.m condition to solve this check being triggered by teleports if (d8 > 100.0D * (elapsedTicks <= 0 ? 1 : elapsedTicks) && this.m) { a.warning( this.player.name + " moved too quickly! Elapsed ticks: " + (elapsedTicks == 0 ? 1 : elapsedTicks) + ", Distance change: " + d8); this.disconnect("You moved too quickly :( (Hacking?)"); return; } this.lastTick = MinecraftServer.currentTick; // CraftBukkit end float f4 = 0.0625F; boolean flag = worldserver .getEntities( this.player, this.player.boundingBox.clone().shrink((double) f4, (double) f4, (double) f4)) .size() == 0; this.player.move(d4, d6, d7); d4 = d1 - this.player.locX; d6 = d2 - this.player.locY; if (d6 > -0.5D || d6 < 0.5D) { d6 = 0.0D; } d7 = d3 - this.player.locZ; d8 = d4 * d4 + d6 * d6 + d7 * d7; boolean flag1 = false; if (d8 > 0.0625D && !this.player.isSleeping()) { flag1 = true; a.warning(this.player.name + " moved wrongly!"); System.out.println("Got position " + d1 + ", " + d2 + ", " + d3); System.out.println( "Expected " + this.player.locX + ", " + this.player.locY + ", " + this.player.locZ); } this.player.setLocation(d1, d2, d3, f2, f3); boolean flag2 = worldserver .getEntities( this.player, this.player.boundingBox.clone().shrink((double) f4, (double) f4, (double) f4)) .size() == 0; if (flag && (flag1 || !flag2) && !this.player.isSleeping()) { this.a(this.x, this.y, this.z, f2, f3); return; } AxisAlignedBB axisalignedbb = this.player .boundingBox .clone() .b((double) f4, (double) f4, (double) f4) .a(0.0D, -0.55D, 0.0D); if (!this.minecraftServer.o && !worldserver.b(axisalignedbb)) { if (d6 >= -0.03125D) { ++this.h; if (this.h > 80) { a.warning(this.player.name + " was kicked for floating too long!"); this.disconnect("Flying is not enabled on this server"); return; } } } else { this.h = 0; } this.player.onGround = packet10flying.g; this.minecraftServer.serverConfigurationManager.d(this.player); this.player.b(this.player.locY - d0, packet10flying.g); } }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); switch (event.getAction()) { case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: { switch (event.getMaterial()) { case WATER_BUCKET: { if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) { break; } player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled."); event.setCancelled(true); break; } case LAVA_BUCKET: { if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) { break; } player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled."); event.setCancelled(true); break; } case EXPLOSIVE_MINECART: { if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) { break; } player.getInventory().clear(player.getInventory().getHeldItemSlot()); player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); event.setCancelled(true); break; } } break; } case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: { switch (event.getMaterial()) { case STICK: { if (!TFM_AdminList.isSuperAdmin(player)) { break; } event.setCancelled(true); final Location location = player.getTargetBlock(null, 5).getLocation(); final List<RollbackEntry> entries = TFM_RollbackManager.getEntriesAtLocation(location); if (entries.isEmpty()) { TFM_Util.playerMsg(player, "No block edits at that location."); break; } TFM_Util.playerMsg( player, "Block edits at (" + ChatColor.WHITE + "x" + location.getBlockX() + ", y" + location.getBlockY() + ", z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE); for (RollbackEntry entry : entries) { TFM_Util.playerMsg( player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data)); } break; } case BONE: { if (!playerdata.mobThrowerEnabled()) { break; } Location player_pos = player.getLocation(); Vector direction = player_pos.getDirection().normalize(); LivingEntity rezzed_mob = (LivingEntity) player .getWorld() .spawnEntity( player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature()); rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); playerdata.enqueueMob(rezzed_mob); event.setCancelled(true); break; } case SULPHUR: { if (!playerdata.isMP44Armed()) { break; } event.setCancelled(true); if (playerdata.toggleMP44Firing()) { playerdata.startArrowShooter(TotalFreedomMod.plugin); } else { playerdata.stopArrowShooter(); } break; } case BLAZE_ROD: { if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { break; } if (!TFM_AdminList.isSeniorAdmin(player, true)) { break; } event.setCancelled(true); Block targetBlock; if (event.getAction().equals(Action.LEFT_CLICK_AIR)) { targetBlock = player.getTargetBlock(null, 120); } else { targetBlock = event.getClickedBlock(); } if (targetBlock == null) { player.sendMessage("Can't resolve target block."); break; } player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true); player.getWorld().strikeLightning(targetBlock.getLocation()); break; } case CARROT: { if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { break; } if (!TFM_AdminList.isSeniorAdmin(player, true)) { break; } Location location = player.getLocation().clone(); Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0)); Vector playerDirection = location.getDirection().normalize(); double distance = 150.0; Block targetBlock = player.getTargetBlock(null, Math.round((float) distance)); if (targetBlock != null) { distance = location.distance(targetBlock.getLocation()); } final List<Block> affected = new ArrayList<Block>(); Block lastBlock = null; for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) { Block block = playerPostion .clone() .add(playerDirection.clone().multiply(offset)) .toLocation(player.getWorld()) .getBlock(); if (!block.equals(lastBlock)) { if (block.isEmpty()) { affected.add(block); block.setType(Material.TNT); } else { break; } } lastBlock = block; } new BukkitRunnable() { @Override public void run() { for (Block tntBlock : affected) { TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class); tnt.setFuseTicks(5); tntBlock.setType(Material.AIR); } } }.runTaskLater(TotalFreedomMod.plugin, 30L); event.setCancelled(true); break; } } break; } } }