use of org.bukkit.block.BlockFace in project AreaShop by NLthijs48.
the class StackCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
// Check permission
if (!sender.hasPermission("areashop.stack")) {
plugin.message(sender, "stack-noPermission");
return;
}
// Only from ingame
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
final Player player = (Player) sender;
// Specify enough arguments
if (args.length < 5) {
plugin.message(sender, "stack-help");
return;
}
// Check amount
int tempAmount = -1;
try {
tempAmount = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
// Incorrect number
}
if (tempAmount <= 0) {
plugin.message(player, "stack-wrongAmount", args[1]);
return;
}
// Check gap
int gap;
try {
gap = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
plugin.message(player, "stack-wrongGap", args[2]);
return;
}
// Check region type
if (!"rent".equalsIgnoreCase(args[4]) && !"buy".equalsIgnoreCase(args[4])) {
plugin.message(sender, "stack-help");
return;
}
// Get WorldEdit selection
final Selection selection = plugin.getWorldEdit().getSelection(player);
if (selection == null) {
plugin.message(player, "stack-noSelection");
return;
}
// Get or create group
RegionGroup group = null;
if (args.length > 5) {
group = plugin.getFileManager().getGroup(args[5]);
if (group == null) {
group = new RegionGroup(plugin, args[5]);
plugin.getFileManager().addGroup(group);
}
}
// Get facing of the player (must be clearly one of the four directions to make sure it is no mistake)
BlockFace facing = Utils.yawToFacing(player.getLocation().getYaw());
if (player.getLocation().getPitch() > 45) {
facing = BlockFace.DOWN;
} else if (player.getLocation().getPitch() < -45) {
facing = BlockFace.UP;
}
if (!(facing == BlockFace.NORTH || facing == BlockFace.EAST || facing == BlockFace.SOUTH || facing == BlockFace.WEST || facing == BlockFace.UP || facing == BlockFace.DOWN)) {
plugin.message(player, "stack-unclearDirection", facing.toString().toLowerCase().replace('_', '-'));
return;
}
Vector shift = new BlockVector(0, 0, 0);
if (facing == BlockFace.SOUTH) {
shift = shift.setZ(-selection.getLength() - gap);
} else if (facing == BlockFace.WEST) {
shift = shift.setX(selection.getWidth() + gap);
} else if (facing == BlockFace.NORTH) {
shift = shift.setZ(selection.getLength() + gap);
} else if (facing == BlockFace.EAST) {
shift = shift.setX(-selection.getWidth() - gap);
} else if (facing == BlockFace.DOWN) {
shift = shift.setY(-selection.getHeight() - gap);
} else if (facing == BlockFace.UP) {
shift = shift.setY(selection.getHeight() + gap);
}
AreaShop.debug(" calculated shift vector: " + shift + ", with facing=" + facing);
// Create regions and add them to AreaShop
final String nameTemplate = args[3];
final int regionsPerTick = plugin.getConfig().getInt("adding.regionsPerTick");
final boolean rentRegions = "rent".equalsIgnoreCase(args[4]);
final int amount = tempAmount;
final RegionGroup finalGroup = group;
final Vector finalShift = shift;
String type;
if (rentRegions) {
type = "rent";
} else {
type = "buy";
}
Message groupsMessage = Message.empty();
if (group != null) {
groupsMessage = Message.fromKey("stack-addToGroup").replacements(group.getName());
}
plugin.message(player, "stack-accepted", amount, type, gap, nameTemplate, groupsMessage);
plugin.message(player, "stack-addStart", amount, regionsPerTick * 20);
new BukkitRunnable() {
private int current = -1;
private RegionManager manager = AreaShop.getInstance().getWorldGuard().getRegionManager(selection.getWorld());
private int counter = 1;
private int tooLow = 0;
private int tooHigh = 0;
@Override
public void run() {
for (int i = 0; i < regionsPerTick; i++) {
current++;
if (current < amount) {
// Create the region name
String counterName = counter + "";
int minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
while (counterName.length() < minimumLength) {
counterName = "0" + counterName;
}
String regionName;
if (nameTemplate.contains("#")) {
regionName = nameTemplate.replace("#", counterName);
} else {
regionName = nameTemplate + counterName;
}
while (manager.getRegion(regionName) != null || AreaShop.getInstance().getFileManager().getRegion(regionName) != null) {
counter++;
counterName = counter + "";
minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
while (counterName.length() < minimumLength) {
counterName = "0" + counterName;
}
if (nameTemplate.contains("#")) {
regionName = nameTemplate.replace("#", counterName);
} else {
regionName = nameTemplate + counterName;
}
}
// Add the region to WorldGuard (at startposition shifted by the number of this region times the blocks it should shift)
BlockVector minimum = new BlockVector(selection.getNativeMinimumPoint().add(finalShift.multiply(current)));
BlockVector maximum = new BlockVector(selection.getNativeMaximumPoint().add(finalShift.multiply(current)));
// Check for out of bounds
if (minimum.getBlockY() < 0) {
tooLow++;
continue;
} else if (maximum.getBlockY() > 256) {
tooHigh++;
continue;
}
ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, minimum, maximum);
manager.addRegion(region);
// Add the region to AreaShop
if (rentRegions) {
RentRegion rent = new RentRegion(regionName, selection.getWorld());
if (finalGroup != null) {
finalGroup.addMember(rent);
}
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addRent(rent);
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
rent.update();
} else {
BuyRegion buy = new BuyRegion(regionName, selection.getWorld());
if (finalGroup != null) {
finalGroup.addMember(buy);
}
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addBuy(buy);
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
buy.update();
}
}
}
if (current >= amount) {
if (player.isOnline()) {
int added = amount - tooLow - tooHigh;
Message wrong = Message.empty();
if (tooHigh > 0) {
wrong.append(Message.fromKey("stack-tooHigh").replacements(tooHigh));
}
if (tooLow > 0) {
wrong.append(Message.fromKey("stack-tooLow").replacements(tooLow));
}
plugin.message(player, "stack-addComplete", added, wrong);
}
this.cancel();
}
}
}.runTaskTimer(plugin, 1, 1);
}
use of org.bukkit.block.BlockFace in project MagicPlugin by elBukkit.
the class StairsSpell method createStairs.
protected void createStairs(Block targetBlock) {
BlockFace vertDirection = BlockFace.UP;
BlockFace horzDirection = getPlayerFacing();
int depth = defaultDepth;
int height = defaultHeight;
int width = defaultWidth;
Material fillMaterial = targetBlock.getType();
BlockFace toTheLeft = goLeft(horzDirection);
BlockFace toTheRight = goRight(horzDirection);
Block bottomBlock = targetBlock;
Block bottomLeftBlock = bottomBlock;
for (int i = 0; i < width / 2; i++) {
bottomLeftBlock = bottomLeftBlock.getRelative(toTheLeft);
}
targetBlock = bottomLeftBlock;
Material stairsMaterial = Material.COBBLESTONE_STAIRS;
for (int d = 0; d < depth; d++) {
bottomBlock = bottomLeftBlock;
for (int w = 0; w < width; w++) {
targetBlock = bottomBlock;
for (int h = 0; h < height; h++) {
if (isDestructible(targetBlock) && hasBuildPermission(targetBlock)) {
// Check to see if the torch will stick to the wall
// TODO: Check for glass, other non-sticky types.
Block checkBlock = null;
if (w == 0) {
checkBlock = targetBlock.getRelative(toTheLeft);
} else {
checkBlock = targetBlock.getRelative(toTheRight);
}
// Put torches on the left and right wall
boolean useTorch = (torchFrequency > 0 && (w == 0 || w == width - 1) && (h == 1) && (d % torchFrequency == 0) && checkBlock.getType() != Material.AIR);
boolean useStairs = (h == 0);
if (useStairs) {
registerForUndo(targetBlock);
targetBlock.setType(stairsMaterial);
} else if (useTorch) {
registerForUndo(targetBlock);
targetBlock.setType(Material.TORCH);
} else {
registerForUndo(targetBlock);
targetBlock.setType(Material.AIR);
}
Block standingBlock = targetBlock.getRelative(BlockFace.DOWN);
if (standingBlock.getType() == Material.AIR) {
registerForUndo(standingBlock);
standingBlock.setType(fillMaterial);
}
}
targetBlock = targetBlock.getRelative(BlockFace.UP);
}
bottomBlock = bottomBlock.getRelative(toTheRight);
}
bottomLeftBlock = bottomLeftBlock.getRelative(horzDirection);
bottomLeftBlock = bottomLeftBlock.getRelative(vertDirection);
}
registerForUndo();
}
use of org.bukkit.block.BlockFace in project MagicPlugin by elBukkit.
the class LevitateSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
direction = null;
directionOffset = ConfigurationUtils.getVector(parameters, "direction_offset");
directionForceY = ConfigurationUtils.getDouble(parameters, "direction_y", null);
flight = parameters.getBoolean("flight", true);
int checkHeight = parameters.getInt("check_height", 4);
startDelay = parameters.getInt("start_delay", 0);
flyDelay = parameters.getInt("fly_delay", 2);
slowMultiplier = parameters.getDouble("slow", 1);
castBoost = parameters.getDouble("boost", 0);
deactivateFrequency = parameters.getInt("auto_deactivate", 10);
yBoost = parameters.getDouble("y_boost", 2);
flySpeed = (float) parameters.getDouble("speed", 0);
thrustSpeed = (float) parameters.getDouble("thrust", 0);
thrustFrequency = parameters.getInt("thrust_interval", thrustFrequency);
autoDeactivateHeight = parameters.getInt("auto_deactivate", 0);
maxHeight = parameters.getInt("max_height", 0);
maxHeightAboveGround = parameters.getInt("max_height_above_ground", 0);
boostTicks = parameters.getInt("boost_ticks", 1);
crashDistance = parameters.getDouble("crash_distance", 0);
slowReduceBoostTicks = parameters.getInt("slow_ticks", 4);
moveDistance = parameters.getDouble("steer_speed", 0);
sneakMoveDistance = parameters.getDouble("slow_steer_speed", -1);
if (parameters.contains("mount_item")) {
mountItem = ConfigurationUtils.getMaterial(parameters, "mount_item");
} else {
mountItem = null;
}
mountBaby = parameters.getBoolean("mount_baby", false);
useHelmet = parameters.getBoolean("armor_stand_helmet", false);
useArmorStand = parameters.getBoolean("armor_stand", false);
armorStandMarker = parameters.getBoolean("armor_stand_marker", false);
smallArmorStand = parameters.getBoolean("armor_stand_small", false);
armorStandGravity = parameters.getBoolean("armor_stand_gravity", true);
armorStandArm = ConfigurationUtils.getVector(parameters, "armor_stand_arm");
armorStandHead = ConfigurationUtils.getVector(parameters, "armor_stand_head");
armorStandBody = ConfigurationUtils.getVector(parameters, "armor_stand_body");
pitchAmount = ConfigurationUtils.getDouble(parameters, "armor_stand_pitch", 0.0);
yawAmount = ConfigurationUtils.getDouble(parameters, "armor_stand_yaw", 0.0);
rollAmount = ConfigurationUtils.getDouble(parameters, "armor_stand_roll", 0.0);
maxMountBoost = parameters.getDouble("mount_boost", 1);
mountBoostPerJump = parameters.getDouble("mount_boost_per_jump", 0.5);
mountBoostMinimum = parameters.getDouble("mount_boost_minimum", 0.5);
mountBoostFromJump = parameters.getBoolean("mount_boost_from_jump", false);
mountBoostTicks = parameters.getInt("mount_boost_ticks", 40);
mountHealth = parameters.getDouble("mount_health", 2);
mountInvisible = parameters.getBoolean("mount_invisible", true);
mountSilent = parameters.getBoolean("mount_silent", true);
stashItem = parameters.getBoolean("stash_item", false);
mountBoostTicks = (int) (mountBoostTicks + mage.getPower() * parameters.getInt("power_mount_boost_ticks", 0));
mountHealth = (int) (mountHealth + mage.getPower() * parameters.getDouble("power_mount_health", 0));
if (moveDistance != 0) {
moveDistance += mage.getPower() * parameters.getDouble("power_steer_speed", 0);
}
mountBoostPerJump += mage.getPower() * parameters.getDouble("power_mount_boost_per_jump", 0);
slowReduceBoostTicks = (int) (slowReduceBoostTicks + mage.getPower() * parameters.getDouble("power_slow_ticks", 0));
if (moveDistance < 0) {
moveDistance = 0;
}
// FX
if (parameters.contains("effect_particle")) {
parseParticleEffect(parameters.getString("effect_particle"));
effectParticleData = 0;
} else {
effectParticle = null;
}
if (parameters.contains("effect_sound")) {
parseSoundEffect(parameters.getString("effect_sound"));
} else {
effectSound = null;
}
effectParticleData = (float) parameters.getDouble("effect_particle_data", effectParticleData);
effectParticleCount = parameters.getInt("effect_particle_count", effectParticleCount);
effectParticleInterval = parameters.getInt("effect_particle_interval", effectParticleInterval);
effectSoundInterval = parameters.getInt("effect_sound_interval", effectSoundInterval);
effectSoundVolume = (float) parameters.getDouble("effect_sound_volume", effectSoundVolume);
effectSoundPitch = (float) parameters.getDouble("effect_sound_pitch", effectSoundPitch);
effectSoundCounter = 0;
effectParticleCounter = 0;
if (parameters.contains("mount_reason")) {
String reasonText = parameters.getString("mount_reason").toUpperCase();
try {
mountSpawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
} catch (Exception ex) {
sendMessage("Unknown spawn reason: " + reasonText);
return SpellResult.FAIL;
}
}
if (parameters.contains("mount_type")) {
try {
String entityType = parameters.getString("mount_type");
mountType = EntityType.valueOf(entityType.toUpperCase());
} catch (Exception ex) {
ex.printStackTrace();
return SpellResult.FAIL;
}
} else {
mountType = null;
}
if (parameters.contains("mount_color")) {
try {
String colorString = parameters.getString("mount_color");
mountHorseColor = Horse.Color.valueOf(colorString.toUpperCase());
} catch (Exception ex) {
ex.printStackTrace();
return SpellResult.FAIL;
}
} else {
mountHorseColor = Horse.Color.WHITE;
}
if (parameters.contains("mount_style")) {
try {
String styleString = parameters.getString("mount_style");
mountHorseStyle = Horse.Style.valueOf(styleString.toUpperCase());
} catch (Exception ex) {
ex.printStackTrace();
return SpellResult.FAIL;
}
} else {
mountHorseStyle = Horse.Style.NONE;
}
crashEffects = getPotionEffects(parameters);
double speedBonus = parameters.getDouble("power_speed", 0);
double boostBonus = parameters.getDouble("power_boost", 0);
double maxSpeedBonus = parameters.getDouble("power_mount_boost", 0);
thrustSpeed += thrustSpeed + mage.getPower() * speedBonus;
castBoost += mage.getPower() * boostBonus;
maxMountBoost += mage.getPower() * maxSpeedBonus;
if (isActive()) {
if (castBoost != 0) {
boostTicksRemaining += boostTicks;
return SpellResult.ALTERNATE;
} else if (mountEntity != null && thrust != null) {
return SpellResult.NO_ACTION;
}
land();
return SpellResult.DEACTIVATE;
}
if (mountType != null) {
Location testLocation = getEyeLocation();
for (BlockFace facing : CHECK_FACES) {
Block block = testLocation.getBlock().getRelative(facing);
if (!isOkToStandIn(block)) {
return SpellResult.FAIL;
}
}
Block block = testLocation.getBlock();
for (int i = 0; i < checkHeight; i++) {
if (!isOkToStandIn(block)) {
return SpellResult.FAIL;
}
block = block.getRelative(BlockFace.UP);
}
}
if (stashItem) {
PlayerInventory inventory = player.getInventory();
heldItemSlot = inventory.getHeldItemSlot();
}
activate();
return SpellResult.CAST;
}
use of org.bukkit.block.BlockFace in project MagicPlugin by elBukkit.
the class TunnelSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
defaultDepth = parameters.getInt("depth", defaultDepth);
defaultWidth = parameters.getInt("width", defaultWidth);
defaultHeight = parameters.getInt("height", defaultHeight);
defaultSearchDistance = parameters.getInt("search_distance", defaultSearchDistance);
torchFrequency = parameters.getInt("torch_frequency", torchFrequency);
Block playerBlock = getPlayerBlock();
if (playerBlock == null) {
return SpellResult.NO_TARGET;
}
if (!hasBreakPermission(playerBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
BlockFace direction = getPlayerFacing();
Block searchBlock = playerBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP);
int searchDistance = 0;
while (searchBlock.getType() == Material.AIR && searchDistance < defaultSearchDistance) {
searchBlock = searchBlock.getRelative(direction);
searchDistance++;
}
int depth = defaultDepth;
int height = defaultHeight;
int width = defaultWidth;
BlockFace toTheLeft = goLeft(direction);
BlockFace toTheRight = goRight(direction);
Block bottomBlock = searchBlock.getRelative(BlockFace.DOWN);
Block bottomLeftBlock = bottomBlock;
for (int i = 0; i < width / 2; i++) {
bottomLeftBlock = bottomLeftBlock.getRelative(toTheLeft);
}
Block targetBlock = bottomLeftBlock;
for (int d = 0; d < depth; d++) {
bottomBlock = bottomLeftBlock;
for (int w = 0; w < width; w++) {
targetBlock = bottomBlock;
for (int h = 0; h < height; h++) {
if (isDestructible(targetBlock) && hasBreakPermission(targetBlock)) {
// Put torches on the left and right wall
/*
boolean useTorch =
(
torchFrequency > 0
&& (w == 0 || w == width - 1)
&& (h == 1)
&& (d % torchFrequency == 0)
);
*/
// TODO!
boolean useTorch = false;
registerForUndo(targetBlock);
if (useTorch) {
// First check to see if the torch will stick to the wall
// TODO: Check for glass, other non-sticky types.
Block checkBlock = null;
if (w == 0) {
checkBlock = targetBlock.getRelative(toTheLeft);
} else {
checkBlock = targetBlock.getRelative(toTheRight);
}
if (checkBlock.getType() == Material.AIR) {
targetBlock.setType(Material.AIR);
} else {
targetBlock.setType(Material.TORCH);
}
} else {
targetBlock.setType(Material.AIR);
}
}
targetBlock = targetBlock.getRelative(BlockFace.UP);
}
bottomBlock = bottomBlock.getRelative(toTheRight);
}
bottomLeftBlock = bottomLeftBlock.getRelative(direction);
}
registerForUndo();
return SpellResult.CAST;
}
use of org.bukkit.block.BlockFace in project MagicPlugin by elBukkit.
the class BlockRecurse method recurse.
protected void recurse(Block block, ActionContext recurseAction, CastContext context, BlockFace nextFace, int rDepth) {
if (nextFace != null) {
block = block.getRelative(nextFace);
}
if (replaceable != null && !replaceable.contains(new MaterialAndData(block))) {
return;
}
UndoList undoList = context.getUndoList();
if (undoList != null) {
if (undoList.contains(block)) {
return;
}
undoList.add(block);
}
context.setTargetLocation(block.getLocation());
if (recurseAction.perform(context) != SpellResult.CAST) {
return;
}
if (rDepth < maxRecursion) {
for (BlockFace face : BlockData.FACES) {
if (nextFace == null || nextFace != BlockData.getReverseFace(face)) {
recurse(block, recurseAction, context, face, rDepth + 1);
}
}
}
}
Aggregations