use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class SkyWarsListener method onInteract.
@Listener
public void onInteract(InteractBlockEvent event, @First Player player) {
Optional<SkyWarsInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
SkyWarsInstance inst = optInst.get();
if (inst.getState() != SkyWarsState.IN_PROGRESS) {
return;
}
Optional<SkyWarsPlayerData> optPlayerData = inst.getPlayerData(player);
if (!optPlayerData.isPresent()) {
return;
}
SkyWarsPlayerData playerData = optPlayerData.get();
Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optStack.isPresent()) {
return;
}
ItemStack stack = optStack.get();
if (stack.getItem() == CustomItemTypes.SKY_FEATHER) {
Vector3d vel = EntityDirectionUtil.getFacingVector(player);
Optional<SkyFeather.Data> optData = SkyFeather.getDataFor(stack);
if (!optData.isPresent()) {
return;
}
SkyFeather.Data data = optData.get();
double radius = data.radius;
double flight = data.flight;
double pushBack = data.pushBack;
if (event instanceof InteractBlockEvent.Primary.MainHand) {
if (!playerData.canFly()) {
return;
}
vel = vel.mul(flight);
player.setVelocity(vel);
playerData.stopFlight(250);
} else if (event instanceof InteractBlockEvent.Secondary.MainHand) {
if (!playerData.canPushBack()) {
return;
}
vel = vel.mul(pushBack * 2);
SpongePlayer spongePlayer = SpongeWorldEdit.inst().wrapPlayer(player);
Collection<Entity> possibleTargets = inst.getContained(Player.class, Chicken.class);
possibleTargets.remove(player);
ParticleEffect radiationEffect = ParticleEffect.builder().type(ParticleTypes.FLAME).quantity(1).build();
TargetBlock targetBlock = new TargetBlock(spongePlayer, 50, .2);
while (targetBlock.getNextBlock() != null) {
BlockWorldVector weBlock = targetBlock.getCurrentBlock();
Location<World> loc = new Location<>(inst.getRegion().getExtent(), weBlock.getX(), weBlock.getY(), weBlock.getZ());
for (int i = 0; i < 10; ++i) {
inst.getRegion().getExtent().spawnParticles(radiationEffect, loc.getPosition().add(Probability.getRangedRandom(0, 1.0), Probability.getRangedRandom(0, 1.0), Probability.getRangedRandom(0, 1.0)));
}
for (Entity aEntity : possibleTargets) {
if (aEntity.getLocation().getPosition().distanceSquared(loc.getPosition()) <= Math.pow(radius, 2)) {
if (aEntity instanceof Player) {
Player aPlayer = (Player) aEntity;
if (inst.isFriendlyFire(player, aPlayer)) {
continue;
}
// Handle Sender
playerData.stopPushBack(250);
player.sendMessage(Text.of(TextColors.YELLOW, "You push back: ", aPlayer.getName(), "!"));
// Handle Target
aPlayer.setVelocity(vel);
Optional<SkyWarsPlayerData> optAPlayerData = inst.getPlayerData(aPlayer);
if (optAPlayerData.isPresent()) {
SkyWarsPlayerData aPlayerData = optAPlayerData.get();
if (aPlayerData.canDefrost()) {
aPlayerData.stopFlight();
}
}
} else {
inst.awardPowerup(player, stack);
aEntity.remove();
}
}
}
}
}
tf(stack).attemptDamageItem(1, new Random());
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class FreakyFourInstance method dabombDetonate.
public void dabombDetonate(double percentEffectiveness) {
ZoneBoundingBox dabombRG = getRegion(FreakyFourBoss.DA_BOMB);
Vector3i min = dabombRG.getMinimumPoint();
Vector3i max = dabombRG.getMaximumPoint();
int minX = min.getX();
int minY = min.getY();
int minZ = min.getZ();
int maxX = max.getX();
int maxZ = max.getZ();
int dmgFact = (int) Math.max(3, percentEffectiveness * config.daBombTNTStrength);
for (int x = minX; x < maxX; ++x) {
for (int z = minZ; z < maxZ; ++z) {
if (Probability.getChance(config.daBombTNT)) {
getRegion().getExtent().triggerExplosion(Explosion.builder().location(new Location<>(getRegion().getExtent(), new Vector3d(x, minY, z))).radius(dmgFact).canCauseFire(false).shouldDamageEntities(true).build(), Cause.source(SkreePlugin.container()).build());
}
}
}
}
use of org.spongepowered.api.world.Location in project ProjectWorlds by trentech.
the class CommandTeleport method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (!(source instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "Must be a player"), false);
}
Player player = (Player) source;
if (arguments.equalsIgnoreCase("teleport")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
String worldName;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<WorldProperties> optionalProperties = Sponge.getServer().getWorldProperties(worldName);
if (!optionalProperties.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
}
WorldProperties properties = optionalProperties.get();
Optional<World> optionalWorld = Sponge.getServer().getWorld(worldName);
if (!optionalWorld.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, properties.getWorldName(), " is not loaded"), false);
}
World world = optionalWorld.get();
Location<World> location = world.getSpawnLocation();
Rotation rotation = Rotation.getClosest(player.getRotation().getFloorY());
if (args.length > 2) {
boolean skip = false;
for (int i = 1; i < args.length - 1; i++) {
if (skip) {
skip = false;
continue;
}
String arg = args[i];
String value;
try {
value = args[i + 1];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-coords")) {
if (arg.equalsIgnoreCase("random")) {
Optional<Location<World>> optionalLocation = TeleportManager.getRandomLocation(world, 2000);
if (!optionalLocation.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "Took to long to find a safe random location. Try again"), false);
}
location = optionalLocation.get();
} else {
String[] coords = value.split(",");
try {
int x = Integer.parseInt(coords[0]);
int y = Integer.parseInt(coords[1]);
int z = Integer.parseInt(coords[2]);
location = world.getLocation(x, y, z);
} catch (Exception e) {
throw new CommandException(Text.of(TextColors.RED, coords.toString(), " is not a valid Coordinate"), true);
}
}
} else if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("-direction")) {
Optional<Rotation> optionalRotation = Rotation.get(value);
if (!optionalRotation.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "Incorrect direction"));
}
rotation = optionalRotation.get();
} else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-force")) {
Optional<Location<World>> optionalLocation = TeleportManager.getSafeLocation(location);
if (!optionalLocation.isPresent()) {
throw new CommandException(Text.of(Text.builder().color(TextColors.RED).append(Text.of("Unsafe spawn point detected. ")).onClick(TextActions.executeCallback(TeleportManager.setUnsafeLocation(location))).append(Text.of(TextColors.GOLD, TextStyles.UNDERLINE, "Click Here")).build(), TextColors.RED, " or use the -f flag to force teleport."));
}
location = optionalLocation.get();
} else {
source.sendMessage(Text.of(TextColors.YELLOW, arg, " is not a valid Flag"));
throw new CommandException(getHelp().getUsageText());
}
skip = true;
}
}
player.setLocationAndRotation(location, rotation.toVector3d());
player.sendTitle(Title.of(Text.of(TextColors.DARK_GREEN, properties.getWorldName()), Text.of(TextColors.AQUA, "x: ", location.getBlockX(), ", y: ", location.getBlockY(), ", z: ", location.getBlockZ())));
return CommandResult.success();
}
use of org.spongepowered.api.world.Location in project SpongeForge by SpongePowered.
the class MixinBlockSnapshot method createSpongeBlockSnapshot.
@Override
public BlockSnapshot createSpongeBlockSnapshot() {
Location<World> location = new Location<>((World) this.getWorld(), VecHelper.toVector3i(this.pos));
SpongeBlockSnapshotBuilder builder = new SpongeBlockSnapshotBuilder();
builder.blockState((BlockState) this.replacedBlock).worldId(location.getExtent().getUniqueId()).position(location.getBlockPosition());
if (this.nbt != null) {
builder.unsafeNbt(this.nbt);
}
TileEntity te = getTileEntity();
if (te != null) {
if (!te.hasWorld()) {
te.setWorld(this.getWorld());
}
for (DataManipulator<?, ?> manipulator : ((IMixinCustomDataHolder) te).getCustomManipulators()) {
builder.add(manipulator);
}
}
return builder.build();
}
use of org.spongepowered.api.world.Location in project guardian by ichorpowered.
the class FlightCheck method getSequence.
@Override
public SequenceBlueprint<Event> getSequence(final Detection detection) {
final Double analysisTime = detection.getContentContainer().get(ContentKeys.ANALYSIS_TIME).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double analysisIntercept = detection.getContentContainer().get(ContentKeys.ANALYSIS_INTERCEPT).orElse(GuardianValue.empty()).getDirect().orElse(0d);
final Double minimumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MINIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double maximumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MAXIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
return new GuardianSequenceBuilder().capture(new ControlCapture(detection.getPlugin(), detection)).capture(new AltitudeCapture(detection.getPlugin(), detection)).capture(new MaterialCapture(detection.getPlugin(), detection)).capture(new PotionEffectCapture(detection.getPlugin(), detection)).observe(MoveEntityEvent.class).after().delay(analysisTime.intValue()).condition(sequenceContext -> {
final GuardianPlayerEntry<Player> entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Summary summary = sequenceContext.get(CommonContextKeys.SUMMARY);
final GuardianCaptureRegistry captureRegistry = sequenceContext.get(CommonContextKeys.CAPTURE_REGISTRY);
final long lastActionTime = sequenceContext.get(CommonContextKeys.LAST_ACTION_TIME);
summary.set(SequenceReport.class, new SequenceReport(false, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build()));
if (!entityEntry.getEntity(Player.class).isPresent())
return false;
final Player player = entityEntry.getEntity(Player.class).get();
/*
* Capture Collection
*/
final CaptureContainer captureContainer = captureRegistry.getContainer();
final Optional<Location> initial = captureContainer.get(GuardianSequence.INITIAL_LOCATION);
final Optional<Double> effectLiftAmplifier = captureContainer.get(PotionEffectCapture.VERTICAL_SPEED_MODIFIER);
final Optional<Double> materialSpeedAmplifier = captureContainer.get(MaterialCapture.SPEED_MODIFIER);
final Optional<Double> altitude = captureContainer.get(AltitudeCapture.RELATIVE_ALTITUDE);
final Optional<Map<String, Integer>> materialStateTicks = captureContainer.get(MaterialCapture.ACTIVE_MATERIAL_TICKS);
final Optional<Map<String, Integer>> controlStateTicks = captureContainer.get(ControlCapture.ACTIVE_CONTROL_TICKS);
if (!initial.isPresent() || !materialSpeedAmplifier.isPresent() || !altitude.isPresent() || !materialStateTicks.isPresent())
return false;
final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entityEntry, detection.getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entityEntry, detection.getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entityEntry, detection.getContentContainer()).orElse(GuardianValue.empty());
final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
long current = System.currentTimeMillis();
// Gets the average time between now and the last action.
double averageActionTime = ((current - lastActionTime) / 1000) / 0.05;
if (averageActionTime < minimumTickRate) {
detection.getLogger().warn("The server may be overloaded. A check could not be completed.");
return false;
} else if (averageActionTime > maximumTickRate) {
return false;
}
if (player.get(Keys.VEHICLE).isPresent() || (player.get(Keys.IS_FLYING).isPresent() && player.get(Keys.IS_FLYING).get()) || player.getLocation().getY() < 1)
return false;
final double intercept = analysisIntercept + (effectLiftAmplifier.orElse(0d) / analysisTime);
// Gets the players vertical displacement in the world.
final double verticalDisplacement = ((player.getLocation().getY() - initial.get().getY()) == 0) ? intercept : player.getLocation().getY() - initial.get().getY();
// Gets the players relative altitude to the ground.
final double averageAltitude = altitude.get() / averageActionTime;
// Gets the time the player is on solid ground or a liquid.
final int solidMaterialTime = materialStateTicks.get().get(MaterialCapture.SOLID);
final int liquidMaterialTime = materialStateTicks.get().get(MaterialCapture.LIQUID);
// Gets the time the player is using flight.
final int flightControlTime = controlStateTicks.get().get(ControlCapture.FLY);
if (verticalDisplacement <= 1 || averageAltitude <= 1 || WorldUtil.containsBlocksUnder(player.getLocation(), playerBox, 1d) || solidMaterialTime > 1 || liquidMaterialTime > 1 || flightControlTime > 1)
return false;
if (((verticalDisplacement / averageAltitude) + averageAltitude) > intercept) {
// ------------------------- DEBUG -----------------------------
System.out.println(player.getName() + " has been caught using fly hacks. (" + ((verticalDisplacement / averageAltitude) + averageAltitude) + ")");
// -------------------------------------------------------------
SequenceReport report = new SequenceReport(true, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build());
report.put("type", "Flight");
report.put("information", Collections.singletonList("Gained altitude over " + ((verticalDisplacement / averageAltitude) + averageAltitude) + "."));
report.put("initial_location", initial.get());
report.put("final_location", player.getLocation());
report.put("severity", ((verticalDisplacement / averageAltitude) + averageAltitude) / (verticalDisplacement + averageAltitude));
summary.set(SequenceReport.class, report);
return true;
}
return false;
}, ConditionType.NORMAL).build(SequenceContext.builder().owner(detection).root(this).build());
}
Aggregations