@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_AdminList.isSuperAdmin(player) || 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_AdminList.isSuperAdmin(player) || 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 = TFM_DepreciationAggregator.getTargetBlock(player, 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 = TFM_DepreciationAggregator.getTargetBlock(player, 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 = TFM_DepreciationAggregator.getTargetBlock( player, 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; } case RAW_FISH: { final int RADIUS_HIT = 5; final int STRENGTH = 4; // Clownfish if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData()) == 2) { if (TFM_AdminList.isSeniorAdmin(player, true) || TFM_AdminList.isTelnetAdmin(player, true)) { boolean didHit = false; final Location playerLoc = player.getLocation(); final Vector playerLocVec = playerLoc.toVector(); final List<Player> players = player.getWorld().getPlayers(); for (final Player target : players) { if (target == player) { continue; } final Location targetPos = target.getLocation(); final Vector targetPosVec = targetPos.toVector(); try { if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) { TFM_Util.setFlying(player, false); target.setVelocity( targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH)); didHit = true; } } catch (IllegalArgumentException ex) { } } if (didHit) { final Sound[] sounds = Sound.values(); for (Sound sound : sounds) { if (sound.toString().contains("HIT")) { playerLoc .getWorld() .playSound( randomOffset(playerLoc, 5.0), sound, 100.0f, randomDoubleRange(0.5, 2.0).floatValue()); } } } } else { final StringBuilder msg = new StringBuilder(); final char[] chars = (player.getName() + " is a clown.").toCharArray(); for (char c : chars) { msg.append(TFM_Util.randomChatColor()).append(c); } TFM_Util.bcastMsg(msg.toString()); player.getInventory().getItemInHand().setType(Material.POTATO_ITEM); } event.setCancelled(true); break; } } } break; } } }
@Override public boolean run( CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { if (args.length == 0) { playerMsg("Available toggles: "); playerMsg("- waterplace"); playerMsg("- fireplace"); playerMsg("- lavaplace"); playerMsg("- fluidspread"); playerMsg("- lavadmg"); playerMsg("- firespread"); playerMsg("- prelog"); playerMsg("- lockdown"); playerMsg("- petprotect"); playerMsg("- droptoggle"); playerMsg("- nonuke"); playerMsg("- explosives"); playerMsg("- chaos", ChatColor.DARK_RED); return false; } if (args[0].equals("waterplace")) { toggle("Water placement is", TFM_ConfigEntry.ALLOW_WATER_PLACE); return true; } if (args[0].equals("fireplace")) { toggle("Fire placement is", TFM_ConfigEntry.ALLOW_FIRE_PLACE); return true; } if (args[0].equals("lavaplace")) { toggle("Lava placement is", TFM_ConfigEntry.ALLOW_LAVA_PLACE); return true; } if (args[0].equals("fluidspread")) { toggle("Fluid spread is", TFM_ConfigEntry.ALLOW_FLUID_SPREAD); return true; } if (args[0].equals("lavadmg")) { toggle("Lava damage is", TFM_ConfigEntry.ALLOW_LAVA_DAMAGE); return true; } if (args[0].equals("firespread")) { toggle("Fire spread is", TFM_ConfigEntry.ALLOW_FIRE_SPREAD); TFM_GameRuleHandler.setGameRule( TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()); return true; } if (args[0].equals("prelog")) { toggle("Command prelogging is", TFM_ConfigEntry.ENABLE_PREPROCESS_LOG); return true; } if (args[0].equals("lockdown")) { TFM_Util.adminAction( sender.getName(), (TotalFreedomMod.lockdownEnabled ? "De-a" : "A") + "ctivating server lockdown", true); TotalFreedomMod.lockdownEnabled = !TotalFreedomMod.lockdownEnabled; return true; } if (args[0].equals("petprotect")) { toggle("Tamed pet protection is", TFM_ConfigEntry.ENABLE_PET_PROTECT); return true; } if (args[0].equals("droptoggle")) { toggle("Automatic entity wiping is", TFM_ConfigEntry.AUTO_ENTITY_WIPE); return true; } if (args[0].equals("adminworld")) { if (!TFM_Util.isHighRank(sender)) { TFM_Util.playerMsg(sender, TFM_Command.MSG_NO_PERMS, ChatColor.RED); return true; } toggle("Adminworld is", TFM_ConfigEntry.ENABLE_ADMINWORLD); return true; } if (args[0].equals("chaos")) { if (!TFM_Util.isHighRank(sender)) { TFM_Util.playerMsg(sender, TFM_Command.MSG_NO_PERMS, ChatColor.RED); return true; } TFM_Util.adminAction(sender.getName(), "Toggling Chaos Mode!", false); TFM_Util.bcastMsg( !TFM_ConfigEntry.ENABLE_CHAOS.getBoolean() ? "EEEK, HIDE THE F*****G CHILDREN!!!!!" : "Everyone is safe... FOR NOW...", ChatColor.RED); toggle("Chaos mode is", TFM_ConfigEntry.ENABLE_CHAOS); return true; } if (args[0].equals("nonuke")) { if (args.length >= 2) { try { TFM_ConfigEntry.NUKE_MONITOR_RANGE.setDouble( Math.max(1.0, Math.min(500.0, Double.parseDouble(args[1])))); } catch (NumberFormatException nfex) { } } if (args.length >= 3) { try { TFM_ConfigEntry.NUKE_MONITOR_COUNT_BREAK.setInteger( Math.max(1, Math.min(500, Integer.parseInt(args[2])))); } catch (NumberFormatException nfex) { } } toggle("Nuke monitor is", TFM_ConfigEntry.NUKE_MONITOR_ENABLED); if (TFM_ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) { playerMsg( "Anti-freecam range is set to " + TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble() + " blocks."); playerMsg( "Block throttle rate is set to " + TFM_ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger() + " blocks destroyed per 5 seconds."); } return true; } if (args[0].equals("explosives")) { if (args.length == 2) { try { TFM_ConfigEntry.EXPLOSIVE_RADIUS.setDouble( Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1])))); } catch (NumberFormatException ex) { playerMsg(ex.getMessage()); return true; } } toggle("Explosions are", TFM_ConfigEntry.ALLOW_EXPLOSIONS); if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { playerMsg("Radius set to " + TFM_ConfigEntry.EXPLOSIVE_RADIUS.getDouble()); } return true; } return false; }
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerMove(PlayerMoveEvent event) { final Location from = event.getFrom(); final Location to = event.getTo(); try { if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0001 * 0.0001)) { // If player just rotated, but didn't move, don't process this event. return; } } catch (IllegalArgumentException ex) { } if (!TFM_AdminWorld.getInstance().validateMovement(event)) { return; } final Player player = event.getPlayer(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) { Player fuckoffPlayer = fuckoff.getKey(); if (fuckoffPlayer.equals(player) || !fuckoffPlayer.isOnline()) { continue; } double fuckoffRange = fuckoff.getValue(); Location playerLocation = player.getLocation(); Location fuckoffLocation = fuckoffPlayer.getLocation(); double distanceSquared; try { distanceSquared = playerLocation.distanceSquared(fuckoffLocation); } catch (IllegalArgumentException ex) { continue; } if (distanceSquared < (fuckoffRange * fuckoffRange)) { event.setTo( fuckoffLocation .clone() .add( playerLocation .subtract(fuckoffLocation) .toVector() .normalize() .multiply(fuckoffRange * 1.1))); break; } } // Freeze if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) { TFM_Util.setFlying(player, true); event.setTo(playerdata.getFreezeLocation()); } if (playerdata.isCaged()) { Location targetPos = player.getLocation().add(0, 1, 0); boolean outOfCage; if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld())) { outOfCage = true; } else { outOfCage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5); } if (outOfCage) { playerdata.setCaged( true, targetPos, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER), playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER)); playerdata.regenerateHistory(); playerdata.clearHistory(); TFM_Util.buildHistory(targetPos, 2, playerdata); TFM_Util.generateHollowCube( targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER)); TFM_Util.generateCube( targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER)); } } if (playerdata.isOrbiting()) { if (player.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) { player.setVelocity(new Vector(0, playerdata.orbitStrength(), 0)); } } if (TFM_Jumppads.getMode().isOn()) { TFM_Jumppads.PlayerMoveEvent(event); } if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean() && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) { return; } final Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator(); while (landmines.hasNext()) { final Command_landmine.TFM_LandmineData landmine = landmines.next(); final Location location = landmine.location; if (location.getBlock().getType() != Material.TNT) { landmines.remove(); continue; } if (landmine.player.equals(player)) { break; } if (!player.getWorld().equals(location.getWorld())) { continue; } if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius))) { break; } landmine.location.getBlock().setType(Material.AIR); final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class); tnt1.setFuseTicks(40); tnt1.setPassenger(player); tnt1.setVelocity(new Vector(0.0, 2.0, 0.0)); final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class); tnt2.setFuseTicks(1); player.setGameMode(GameMode.SURVIVAL); landmines.remove(); } }
@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; } } }