use of org.bukkit.entity.Player in project HawkEye by oliverwoodings.
the class SearchParser method parseLocations.
/**
* Formats min and max locations if the radius is set
*/
public void parseLocations() {
if (!(player instanceof Player))
return;
// Check if there is a max radius
if (radius == null && Config.MaxRadius != 0)
radius = Config.MaxRadius;
//If the radius is set we need to format the min and max locations
if (radius != null) {
//Check if location and world are supplied
if (loc == null)
loc = ((Player) player).getLocation().toVector();
if (worlds == null)
worlds = new String[] { ((Player) player).getWorld().getName() };
//Format min and max
minLoc = new Vector(loc.getX() - radius, loc.getY() - radius, loc.getZ() - radius);
maxLoc = new Vector(loc.getX() + radius, loc.getY() + radius, loc.getZ() + radius);
}
}
use of org.bukkit.entity.Player in project HawkEye by oliverwoodings.
the class Undo method run.
/**
* Run the undo.
* Contains appropriate methods of catching errors and notifying the player
*/
public void run() {
//Start rollback process
int i = 0;
while (i < 200 && undoQueue.hasNext()) {
//If undo doesn't exist
DataEntry entry = undoQueue.next();
if (entry.getUndoState() == null)
continue;
//Global undo
if (undoType == RollbackType.GLOBAL) {
entry.getUndoState().update(true);
//Add back into database if delete data is on
if (Config.DeleteDataOnRollback)
DataManager.addEntry(entry);
} else //Player undo
{
Player player = (Player) session.getSender();
Block block = entry.getUndoState().getBlock();
player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
}
counter++;
}
//Check if undo is finished
if (!undoQueue.hasNext()) {
//End timer
Bukkit.getServer().getScheduler().cancelTask(timerID);
session.setDoingRollback(false);
session.setRollbackResults(null);
Util.sendMessage(session.getSender(), "&cUndo complete, &7" + counter + " &cedits performed");
Util.debug("Undo complete, " + counter + " edits performed");
}
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class BlockAction method placeBlock.
/**
* Place a block unless something other than air occupies the spot, or if we
* detect a falling block now sits there. This resolves the issue of falling
* blocks taking up the space, preventing this rollback. However, it also
* means that a rollback *could* interfere with a player-placed block.
*/
protected ChangeResult placeBlock(Player player, QueryParameters parameters, boolean is_preview, Block block, boolean is_deferred) {
final Material m = Material.getMaterial(getBlockId());
BlockStateChange stateChange;
// (essentially liquid/air).
if (!getType().requiresHandler("BlockChangeAction") && !getType().requiresHandler("PrismRollbackAction")) {
if (!me.botsko.elixr.BlockUtils.isAcceptableForBlockPlace(block.getType()) && !parameters.hasFlag(Flag.OVERWRITE)) {
// System.out.print("Block skipped due to being unaccaptable for block place.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
}
// On the blacklist (except an undo)
if (Prism.getIllegalBlocks().contains(getBlockId()) && !parameters.getProcessType().equals(PrismProcessType.UNDO)) {
// System.out.print("Block skipped because it's not allowed to be placed.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
// If we're not in a preview, actually apply this block
if (!is_preview) {
// Capture the block before we change it
final BlockState originalBlock = block.getState();
// it's set to stationary water so the lilypad will sit
if (getBlockId() == 111) {
final Block below = block.getRelative(BlockFace.DOWN);
if (below.getType().equals(Material.WATER) || below.getType().equals(Material.AIR) || below.getType().equals(Material.STATIONARY_WATER)) {
below.setType(Material.STATIONARY_WATER);
} else {
// Prism.debug("Lilypad skipped because no water exists below.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
}
// If portal, we need to light the portal. seems to be the only way.
if (getBlockId() == 90) {
final Block obsidian = me.botsko.elixr.BlockUtils.getFirstBlockOfMaterialBelow(Material.OBSIDIAN, block.getLocation());
if (obsidian != null) {
final Block above = obsidian.getRelative(BlockFace.UP);
if (!(above.getType() == Material.PORTAL)) {
above.setType(Material.FIRE);
return new ChangeResult(ChangeResultType.APPLIED, null);
}
}
}
// it becomes unplayable
if (getBlockId() == 84) {
block_subid = 0;
}
// Set the material
block.setTypeId(getBlockId());
block.setData((byte) getBlockSubId());
/**
* Skulls
*/
if ((getBlockId() == 144 || getBlockId() == 397) && getActionData() instanceof SkullActionData) {
final SkullActionData s = (SkullActionData) getActionData();
// Set skull data
final Skull skull = (Skull) block.getState();
skull.setRotation(s.getRotation());
skull.setSkullType(s.getSkullType());
if (!s.owner.isEmpty()) {
skull.setOwner(s.owner);
}
skull.update();
}
/**
* Spawner
*/
if (getBlockId() == 52) {
final SpawnerActionData s = (SpawnerActionData) getActionData();
// Set spawner data
final CreatureSpawner spawner = (CreatureSpawner) block.getState();
spawner.setDelay(s.getDelay());
spawner.setSpawnedType(s.getEntityType());
spawner.update();
}
/**
* Restoring command block
*/
if (getBlockId() == 137) {
final CommandBlock cmdblock = (CommandBlock) block.getState();
cmdblock.setCommand(data);
cmdblock.update();
}
/**
* Signs
*/
if (parameters.getProcessType().equals(PrismProcessType.ROLLBACK) && (getBlockId() == 63 || getBlockId() == 68) && getActionData() instanceof SignActionData) {
final SignActionData s = (SignActionData) getActionData();
// https://snowy-evening.com/botsko/prism/455/
if (block.getState() instanceof Sign) {
// Set sign data
final Sign sign = (Sign) block.getState();
int i = 0;
if (s.lines != null && s.lines.length > 0) {
for (final String line : s.lines) {
sign.setLine(i, line);
i++;
}
}
sign.update();
}
}
// logic to use materials.
if (me.botsko.elixr.BlockUtils.materialRequiresSoil(block.getType())) {
final Block below = block.getRelative(BlockFace.DOWN);
if (below.getType().equals(Material.DIRT) || below.getType().equals(Material.AIR) || below.getType().equals(Material.GRASS)) {
below.setType(Material.SOIL);
} else {
// System.out.print("Block skipped because there's no soil below.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
}
// Capture the new state
final BlockState newBlock = block.getState();
// Store the state change
stateChange = new BlockStateChange(originalBlock, newBlock);
// If we're rolling back a door, we need to set it properly
if (BlockUtils.isDoor(m)) {
BlockUtils.properlySetDoor(block, getBlockId(), (byte) getBlockSubId());
} else // Or a bed
if (m.equals(Material.BED_BLOCK)) {
BlockUtils.properlySetBed(block, getBlockId(), (byte) getBlockSubId());
} else // Or double plants
if (m.equals(Material.DOUBLE_PLANT)) {
BlockUtils.properlySetDoublePlant(block, getBlockId(), (byte) getBlockSubId());
}
} else {
// Otherwise, save the state so we can cancel if needed
final BlockState originalBlock = block.getState();
// Note: we save the original state as both old/new so we can re-use
// blockStateChanges
stateChange = new BlockStateChange(originalBlock, originalBlock);
// Preview it
player.sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
// Send preview to shared players
for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
if (sharedPlayer instanceof Player) {
((Player) sharedPlayer).sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
}
}
}
return new ChangeResult(ChangeResultType.APPLIED, stateChange);
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class BlockAction method removeBlock.
/**
*
*/
protected ChangeResult removeBlock(Player player, QueryParameters parameters, boolean is_preview, Block block) {
BlockStateChange stateChange;
if (!block.getType().equals(Material.AIR)) {
// Ensure it's acceptable to remove the current block
if (!me.botsko.elixr.BlockUtils.isAcceptableForBlockPlace(block.getType()) && !me.botsko.elixr.BlockUtils.areBlockIdsSameCoreItem(block.getTypeId(), getBlockId()) && !parameters.hasFlag(Flag.OVERWRITE)) {
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
if (!is_preview) {
// Capture the block before we change it
final BlockState originalBlock = block.getState();
// Set
block.setType(Material.AIR);
// Capture the new state
final BlockState newBlock = block.getState();
// Store the state change
stateChange = new BlockStateChange(originalBlock, newBlock);
} else {
// Otherwise, save the state so we can cancel if needed
final BlockState originalBlock = block.getState();
// Note: we save the original state as both old/new so we can
// re-use blockStateChanges
stateChange = new BlockStateChange(originalBlock, originalBlock);
// Preview it
player.sendBlockChange(block.getLocation(), Material.AIR, (byte) 0);
// Send preview to shared players
for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
if (sharedPlayer instanceof Player) {
((Player) sharedPlayer).sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
}
}
}
return new ChangeResult(ChangeResultType.APPLIED, stateChange);
}
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
use of org.bukkit.entity.Player in project Prism-Bukkit by prism.
the class Executor method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
// Set player
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
// Find command
String subcommandName;
if (mode.equals("subcommand") && args.length > 0) {
subcommandName = args[0].toLowerCase();
// Complete subcommand
if (args.length == 1)
return MiscUtils.getStartingWith(subcommandName, subcommands.keySet());
} else {
subcommandName = cmd.getName();
}
String currentMode = mode;
SubCommand sub = subcommands.get(subcommandName);
if (sub == null) {
sub = subcommands.get(defaultSubcommand);
if (sub == null) {
sender.sendMessage("Invalid command");
return null;
} else {
// The default is used, we must switch back to command mode
currentMode = "command";
}
}
// Ensure they have permission
if (player != null && !(sub.playerHasPermission(player))) {
sender.sendMessage("You do not have permission to use this command");
return null;
} else // Ensure min number of arguments
if ((currentMode.equals("subcommand") && (args.length - 1) < sub.getMinArgs()) || (currentMode.equals("command") && (args.length) < sub.getMinArgs())) {
sender.sendMessage("You're missing arguments for this command");
return null;
}
// Ensure command allows console
if (!(sender instanceof Player)) {
if (!sub.isConsoleAllowed()) {
sender.sendMessage("You must be in-game to use this command");
return null;
}
}
// Pass along call to handler
final CallInfo call = new CallInfo(sender, player, args);
return sub.getHandler().handleComplete(call);
}
Aggregations