use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class PrismPlayerEvents method onPlayerJoin.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
// Lookup player for cache reasons
PlayerIdentification.cachePrismPlayer(player);
// Track the join event
if (!Prism.getIgnore().event("player-join", player))
return;
String ip = null;
if (plugin.getConfig().getBoolean("prism.track-player-ip-on-join")) {
ip = player.getAddress().getAddress().getHostAddress().toString();
}
RecordingQueue.addToQueue(ActionFactory.createPlayer("player-join", event.getPlayer(), ip));
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class PrismVehicleEvents method onVehicleDestroy.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleDestroy(final VehicleDestroyEvent event) {
final Vehicle vehicle = event.getVehicle();
final Entity attacker = event.getAttacker();
// Was it broken by an attack
if (attacker != null) {
if (attacker instanceof Player) {
if (!Prism.getIgnore().event("vehicle-break", ((Player) attacker)))
return;
RecordingQueue.addToQueue(ActionFactory.createVehicle("vehicle-break", vehicle, ((Player) attacker).getName()));
} else {
if (!Prism.getIgnore().event("vehicle-break", attacker.getWorld()))
return;
RecordingQueue.addToQueue(ActionFactory.createVehicle("vehicle-break", vehicle, attacker.getType().name().toLowerCase()));
}
} else {
// Otherwise its driver was reckless
final Entity passenger = vehicle.getPassenger();
if (passenger != null && passenger instanceof Player) {
if (!Prism.getIgnore().event("vehicle-break", ((Player) passenger)))
return;
RecordingQueue.addToQueue(ActionFactory.createVehicle("vehicle-break", vehicle, ((Player) passenger).getName()));
}
}
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class RadiusParameter method process.
/**
*
*/
@Override
public void process(QueryParameters query, String alias, String input, CommandSender sender) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
String inputValue = input;
final FileConfiguration config = Bukkit.getPluginManager().getPlugin("Prism").getConfig();
if (TypeUtils.isNumeric(inputValue) || (inputValue.contains(":") && inputValue.split(":").length >= 1 && TypeUtils.isNumeric(inputValue.split(":")[1]))) {
int radius, desiredRadius;
Location coordsLoc = null;
if (inputValue.contains(":")) {
desiredRadius = Integer.parseInt(inputValue.split(":")[1]);
final String radiusLocOrPlayer = inputValue.split(":")[0];
if (radiusLocOrPlayer.contains(",") && player != null) {
// Coordinates;
// x,y,z
final String[] coordinates = radiusLocOrPlayer.split(",");
if (coordinates.length != 3) {
throw new IllegalArgumentException("Couldn't parse the coordinates '" + radiusLocOrPlayer + "'. Perhaps you have more than two commas?");
}
for (final String s : coordinates) {
if (!TypeUtils.isNumeric(s)) {
throw new IllegalArgumentException("The coordinate '" + s + "' is not a number.");
}
}
coordsLoc = (new Location(player.getWorld(), Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), Integer.parseInt(coordinates[2])));
} else // Try to find an online player
if (Bukkit.getServer().getPlayer(radiusLocOrPlayer) != null) {
player = Bukkit.getServer().getPlayer(radiusLocOrPlayer);
} else {
throw new IllegalArgumentException("Couldn't find the player named '" + radiusLocOrPlayer + "'. Perhaps they are not online or you misspelled their name?");
}
} else {
desiredRadius = Integer.parseInt(inputValue);
}
if (desiredRadius <= 0) {
throw new IllegalArgumentException("Radius must be greater than zero. Or leave it off to use the default. Use /prism ? for help.");
}
// If neither sender or a named player found, die here
if (player == null) {
throw new IllegalArgumentException("The radius parameter must be used by a player. Use w:worldname if attempting to limit to a world.");
}
// Clamp radius based on perms, configs
radius = MiscUtils.clampRadius(player, desiredRadius, query.getProcessType(), config);
if (desiredRadius != radius) {
if (sender != null)
sender.sendMessage(Prism.messenger.playerError("Forcing radius to " + radius + " as allowed by config."));
}
if (radius > 0) {
query.setRadius(radius);
if (coordsLoc != null) {
// We
query.setMinMaxVectorsFromPlayerLocation(coordsLoc);
// need
// to
// set
// this
// *after*
// the
// radius
// has
// been
// set
// or
// it
// won't
// work.
} else {
query.setMinMaxVectorsFromPlayerLocation(player.getLocation());
}
}
} else {
// If neither sender or a named player found, die here
if (player == null) {
throw new IllegalArgumentException("The radius parameter must be used by a player. Use w:worldname if attempting to limit to a world.");
}
// User wants an area inside of a worldedit selection
if (inputValue.equals("we")) {
if (Prism.plugin_worldEdit == null) {
throw new IllegalArgumentException("This feature is disabled because Prism couldn't find WorldEdit.");
} else {
// Load a selection from world edit as our area.
final Prism prism = (Prism) Bukkit.getPluginManager().getPlugin("Prism");
if (!WorldEditBridge.getSelectedArea(prism, player, query)) {
throw new IllegalArgumentException("Invalid region selected. Make sure you have a region selected, and that it doesn't exceed the max radius.");
}
}
} else // Confine to the chunk
if (inputValue.equals("c") || inputValue.equals("chunk")) {
final Chunk ch = player.getLocation().getChunk();
query.setWorld(ch.getWorld().getName());
query.setMinLocation(ChunkUtils.getChunkMinVector(ch));
query.setMaxLocation(ChunkUtils.getChunkMaxVector(ch));
} else // User wants no radius, but contained within the current world
if (inputValue.equals("world")) {
// Do they have permission to override the global lookup radius
if (query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-lookup-radius")) {
throw new IllegalArgumentException("You do not have permission to override the max radius.");
}
// Do they have permission to override the global applier radius
if (!query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-applier-radius")) {
throw new IllegalArgumentException("You do not have permission to override the max radius.");
}
// Use the world defined in the w: param
if (query.getWorld() != null) {
inputValue = query.getWorld();
} else // Use the current world
{
inputValue = player.getWorld().getName();
}
query.setWorld(inputValue);
query.setAllowNoRadius(true);
} else // User has asked for a global radius
if (inputValue.equals("global")) {
// Do they have permission to override the global lookup radius
if (query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-lookup-radius")) {
throw new IllegalArgumentException("You do not have permission to override the max radius.");
}
// Do they have permission to override the global applier radius
if (!query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-applier-radius")) {
throw new IllegalArgumentException("You do not have permission to override the max radius.");
}
// Either they have permission or player is null
query.setWorld(null);
query.setAllowNoRadius(true);
} else {
throw new IllegalArgumentException("Radius is invalid. There's a bunch of choice, so use /prism actions for assistance.");
}
}
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class PrismBlockEvents method onSetFire.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSetFire(final BlockIgniteEvent event) {
String cause = null;
switch(event.getCause()) {
case FIREBALL:
cause = "fireball";
break;
case FLINT_AND_STEEL:
cause = "lighter";
break;
case LAVA:
cause = "lava-ignite";
break;
case LIGHTNING:
cause = "lightning";
break;
default:
}
if (cause != null) {
if (!Prism.getIgnore().event(cause, event.getBlock().getWorld()))
return;
final Player player = event.getPlayer();
if (player != null) {
if ((cause.equals("lighter") || cause.equals("fireball")) && plugin.getConfig().getBoolean("prism.alerts.uses.lighter") && !player.hasPermission("prism.alerts.use.lighter.ignore") && !player.hasPermission("prism.alerts.ignore")) {
plugin.useMonitor.alertOnItemUse(player, "used a " + cause);
}
}
RecordingQueue.addToQueue(ActionFactory.createBlock(cause, event.getBlock(), (player == null ? "Environment" : player.getName())));
}
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class PrismBlockEvents method onBlockBreak.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent event) {
final Player player = event.getPlayer();
Block block = event.getBlock();
if (block.getType().equals(Material.AIR))
return;
// Run ore find alerts
if (!player.hasPermission("prism.alerts.ores.ignore") && !player.hasPermission("prism.alerts.ignore")) {
plugin.oreMonitor.processAlertsFromBlock(player, block);
}
if (!Prism.getIgnore().event("block-break", player))
return;
// Change handling a bit if it's a long block
final Block sibling = me.botsko.elixr.BlockUtils.getSiblingForDoubleLengthBlock(block);
if (sibling != null && !block.getType().equals(Material.CHEST) && !block.getType().equals(Material.TRAPPED_CHEST)) {
block = sibling;
}
// log items removed from container
// note: done before the container so a "rewind" for rollback will work
// properly
logItemRemoveFromDestroyedContainer(player.getName(), block);
RecordingQueue.addToQueue(ActionFactory.createBlock("block-break", block, player.getName()));
// check for block relationships
logBlockRelationshipsForBlock(player.getName(), block);
// if obsidian, log portal blocks
if (block.getType().equals(Material.OBSIDIAN)) {
final ArrayList<Block> blocks = me.botsko.elixr.BlockUtils.findConnectedBlocksOfType(Material.PORTAL, block, null);
if (!blocks.isEmpty()) {
// Only log 1 portal break, we don't need all 8
RecordingQueue.addToQueue(ActionFactory.createBlock("block-break", blocks.get(0), player.getName()));
}
}
// Pass to the break alerter
if (!player.hasPermission("prism.alerts.use.break.ignore") && !player.hasPermission("prism.alerts.ignore")) {
plugin.useMonitor.alertOnBlockBreak(player, event.getBlock());
}
}
Aggregations