use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class TeleportCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Player target;
if (src instanceof Player) {
target = (Player) src;
} else {
src.sendMessage(Text.of(TextColors.RED, "You are not a player and teleporting other players is not currently supported!"));
return CommandResult.empty();
}
Optional<Vector3d> dest = args.getOne("dest");
Vector3d rotation = new Vector3d(0, 0, 0);
World targetExtent = target.getWorld();
String destStr;
if (dest.isPresent()) {
if (!src.hasPermission("skree.teleport.teleport.coord")) {
src.sendMessage(Text.of(TextColors.RED, "You do not have permission to teleport by coordinates here."));
return CommandResult.empty();
}
destStr = dest.get().toString();
} else {
if (!src.hasPermission("skree.teleport.teleport.player")) {
src.sendMessage(Text.of(TextColors.RED, "You do not have permission to teleport to players here."));
return CommandResult.empty();
}
Player player = args.<Player>getOne("dest-player").get();
targetExtent = player.getWorld();
rotation = player.getRotation();
dest = Optional.of(player.getLocation().getPosition());
destStr = player.getName();
}
Optional<Location<World>> optSafeDest = SafeTeleportHelper.getSafeDest(target, new Location<>(targetExtent, dest.get()));
if (optSafeDest.isPresent()) {
if (!WorldEntryPermissionCheck.checkDestination(target, optSafeDest.get().getExtent())) {
src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
return CommandResult.empty();
}
target.setLocationAndRotation(optSafeDest.get(), rotation);
src.sendMessage(Text.of(TextColors.YELLOW, "Teleported to " + destStr + '.'));
} else {
src.sendMessage(Text.of(TextColors.RED, "The requested destination is unsafe."));
}
return CommandResult.success();
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class ZoneSlaveOrb method onDropItem.
@Listener
public void onDropItem(DropItemEvent.Dispense event) {
event.getEntities().stream().filter(entity -> entity instanceof Item).forEach(entity -> {
ItemStack stack = ((EntityItem) entity).getEntityItem();
if (isZoneSlaveItem(stack)) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
if (!notifyGroupOwner(stack, player, false)) {
}
player.sendMessage(Text.of(TextColors.RED, "You've declined your group invite."));
}
entity.remove();
}
});
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class ZoneItemUtil method notifyGroupOwner.
public static boolean notifyGroupOwner(ItemStack stack, Player holder, boolean joined) {
Validate.isTrue(isZoneSlaveItem(stack));
Optional<Player> optPlayer = getGroupOwner(stack);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
if (joined) {
if (incrementCount(stack, player)) {
player.sendMessage(Text.of(TextColors.GOLD, holder.getName() + " has accepted your invitation."));
}
} else {
if (!isAttuned(stack) || decrementCount(stack, player)) {
player.sendMessage(Text.of(TextColors.RED, holder.getName() + " has declined your invitation."));
}
}
return true;
}
return false;
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class CursedMineInstance method drain.
public void drain() {
for (Entity e : getContained(Carrier.class)) {
// TODO Inventory API not fully implemented
if (!(e instanceof Player)) {
continue;
}
Inventory eInventory = ((Carrier) e).getInventory();
if (e instanceof Player) {
Location<World> playerLoc = e.getLocation();
// Emerald
long diff = System.currentTimeMillis() - lastActivation;
if (playerLoc.getY() < 30 && (lastActivation == 0 || diff <= timeTilPumpShutoff * .35 || diff >= timeTilPumpShutoff * 5)) {
PositionRandomizer randomizer = new PositionRandomizer(5);
for (int i = 0; i < Probability.getRangedRandom(2, 5); i++) {
Vector3i targetPos;
do {
targetPos = randomizer.createPosition3i(playerLoc.getPosition());
} while (getRegion().getExtent().getBlockType(targetPos) != BlockTypes.AIR);
Entity entity = getRegion().getExtent().createEntity(EntityTypes.BLAZE, targetPos);
getRegion().getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.MOB_SPAWNER).build()).build());
}
}
}
for (int i = 0; i < (eInventory.size() / 2) - 2 || i < 1; i++) {
if (e instanceof Player) {
if (Probability.getChance(15) && checkInventory((Player) e)) {
((Player) e).sendMessage(Text.of(TextColors.YELLOW, "Divine intervention protects some of your items."));
continue;
}
}
// Iron
eInventory.query(ItemTypes.IRON_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.IRON_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.IRON_INGOT).poll(Probability.getRandom(8));
// Gold
eInventory.query(ItemTypes.GOLD_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.GOLD_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.GOLD_INGOT).poll(Probability.getRandom(10));
eInventory.query(ItemTypes.GOLD_NUGGET).poll(Probability.getRandom(80));
// Redstone
eInventory.query(ItemTypes.REDSTONE_ORE).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.REDSTONE).poll(Probability.getRandom(34));
// Lap
eInventory.query(ItemTypes.LAPIS_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.LAPIS_ORE).poll(Probability.getRandom(4));
eInventory.query(LAPIS_DYE).poll(Probability.getRandom(34));
// Diamond
eInventory.query(ItemTypes.DIAMOND_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.DIAMOND_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.DIAMOND).poll(Probability.getRandom(16));
}
}
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class WildernessTeleportCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command!"));
return CommandResult.empty();
}
if (!src.hasPermission("skree.world.wilderness.teleport")) {
src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
return CommandResult.empty();
}
WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
WildernessWorldWrapper wrapper = service.getEffectWrapper(WildernessWorldWrapper.class).get();
int targetLevel = args.<Integer>getOne("target level").get();
if (targetLevel < 1) {
src.sendMessage(Text.of("The target level must be at least 1."));
return CommandResult.empty();
}
Optional<World> optWorld = Sponge.getServer().getWorld(args.<String>getOne("world type").get());
if (!optWorld.isPresent()) {
src.sendMessage(Text.of("That world is not currently accessible."));
return CommandResult.empty();
}
World world = optWorld.get();
int variance = (int) (Math.sqrt(targetLevel) * 2);
int negative = Probability.getChance(3) ? -1 : 1;
targetLevel += Probability.getRandom(variance) * negative;
Player player = (Player) src;
for (int i = 0; i < 2; ++i) {
tf(player).hurtResistantTime = 0;
player.damage(wrapper.getDamageMod(targetLevel) * 3, DamageSource.builder().type(DAMAGE_TYPE).build());
}
if (player.get(Keys.HEALTH).orElse(0D) > 0) {
int unit = wrapper.getLevelUnit(world);
Location<World> dest;
do {
int x = getLevelCoord(targetLevel, unit);
int z = getLevelCoord(targetLevel, unit);
dest = SafeTeleportHelper.getSafeDest(new Location<>(world, x, 60, z)).orElse(null);
} while (dest == null);
player.setLocation(dest);
}
return CommandResult.success();
}
Aggregations