use of org.spongepowered.api.world.World in project Skree by Skelril.
the class JungleRaidEffectListener method onPlayerInteract.
@Listener(order = Order.LATE)
public void onPlayerInteract(InteractBlockEvent.Primary.MainHand event, @First Player player) {
Optional<Location<World>> optBlockLoc = event.getTargetBlock().getLocation();
if (!optBlockLoc.isPresent()) {
return;
}
Location<World> blockLoc = optBlockLoc.get();
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(blockLoc);
if (!optInst.isPresent()) {
return;
}
JungleRaidInstance inst = optInst.get();
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && player.getUniqueId().equals(inst.getFlagData().titan)) {
if (blockLoc.getBlockType() == BlockTypes.BEDROCK) {
return;
}
// TODO Convert to the Sponge API
((net.minecraft.world.World) blockLoc.getExtent()).destroyBlock(new BlockPos(blockLoc.getX(), blockLoc.getY(), blockLoc.getZ()), true);
}
}
use of org.spongepowered.api.world.World in project Skree by Skelril.
the class SkullOfTheFallen method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (this != optHeldItem.get().getItem()) {
return;
}
Location<World> pLoc = player.getLocation();
Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
if (optWorldService.isPresent()) {
WorldService worldService = optWorldService.get();
WildernessWorldWrapper wrapper = worldService.getEffectWrapper(WildernessWorldWrapper.class).get();
Optional<Integer> optLevel = wrapper.getLevel(pLoc);
if (optLevel.isPresent()) {
int level = optLevel.get();
DecimalFormat df = new DecimalFormat("#,###.##");
player.sendMessages(Text.of(TextColors.YELLOW, "Wilderness level: " + level), Text.of(TextColors.YELLOW, "PvP Enabled: " + (wrapper.allowsPvP(level) ? "Yes" : "No")), Text.of(TextColors.YELLOW, "Mob damage: +" + df.format(wrapper.getDamageMod(level))), Text.of(TextColors.YELLOW, "Mob health: x" + df.format(wrapper.getHealthMod(level))), Text.of(TextColors.YELLOW, "Ore modifier: x" + df.format(wrapper.getOreMod(wrapper.getDropTier(level)))), Text.of(TextColors.YELLOW, "Drop modifier: x" + df.format(level * wrapper.getDropMod(wrapper.getDropTier(level)))));
} else {
player.sendMessage(Text.of(TextColors.RED, "You're not in a Wilderness world!"));
}
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.world.World in project Skree by Skelril.
the class WorldListCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
List<WorldEffectWrapper> worldEffectWrapperList = service.getEffectWrappers().stream().sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).collect(Collectors.toList());
for (WorldEffectWrapper wrapper : worldEffectWrapperList) {
String worldType = wrapper.getName();
if (!src.hasPermission("skree.world." + worldType.toLowerCase() + ".teleport")) {
continue;
}
src.sendMessage(Text.of(TextColors.GOLD, "Available ", worldType, " worlds (click to teleport):"));
for (World world : wrapper.getWorlds()) {
String worldName = world.getName();
String prettyName = worldName.replaceAll("_", " ");
src.sendMessage(Text.of(TextColors.YELLOW, TextActions.runCommand("/world " + worldName), TextActions.showText(Text.of("Teleport to " + prettyName)), " - ", prettyName));
}
}
return CommandResult.success();
}
use of org.spongepowered.api.world.World 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.world.World in project Skree by Skelril.
the class Luminositor method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (optHeldItem.isPresent()) /* && optClickedPosition.isPresent() */
{
if (this.equals(optHeldItem.get().getItem())) {
Direction dir = event.getTargetSide();
Optional<Location<World>> optTargetBlockLoc = event.getTargetBlock().getLocation();
if (!optTargetBlockLoc.isPresent()) {
return;
}
Location<World> targetBlockLoc = optTargetBlockLoc.get();
Vector3i targPos = targetBlockLoc.getBlockPosition().add(dir.toVector3d().toInt());
Location<World> trueTargBlock = new Location<>(targetBlockLoc.getExtent(), targPos);
int lightLevel = LightLevelUtil.getMaxLightLevel(trueTargBlock).get();
TextColor color;
if (lightLevel >= 12) {
color = TextColors.GREEN;
} else if (lightLevel >= 8) {
color = TextColors.RED;
} else {
color = TextColors.DARK_RED;
}
// TODO system message.color(color)
player.sendMessage(Text.of(TextColors.YELLOW, "Light level: ", color, lightLevel));
event.setUseBlockResult(Tristate.FALSE);
}
}
}
Aggregations