Search in sources :

Example 1 with Sign

use of org.spongepowered.api.block.tileentity.Sign in project TotalEconomy by Erigitic.

the class TEJobManager method onSignInteract.

/**
     * Called when a player clicks a sign. If the clicked sign is a "Job Changing" sign then the player's job will
     * be changed on click.
     *
     * @param event InteractBlockEvent
     */
@Listener
public void onSignInteract(InteractBlockEvent event) {
    if (event.getCause().first(Player.class).isPresent()) {
        Player player = event.getCause().first(Player.class).get();
        if (event.getTargetBlock().getLocation().isPresent()) {
            Optional<TileEntity> tileEntityOpt = event.getTargetBlock().getLocation().get().getTileEntity();
            if (tileEntityOpt.isPresent()) {
                TileEntity tileEntity = tileEntityOpt.get();
                if (tileEntity instanceof Sign) {
                    Sign sign = (Sign) tileEntity;
                    Optional<SignData> data = sign.getOrCreate(SignData.class);
                    if (data.isPresent()) {
                        SignData signData = data.get();
                        Text lineOneText = signData.lines().get(0);
                        Text lineTwoText = signData.lines().get(1);
                        String lineOne = lineOneText.toPlain();
                        String lineTwo = lineTwoText.toPlain().toLowerCase();
                        if (lineOne.equals("[TEJobs]")) {
                            if (jobExists(lineTwo)) {
                                if (setJob(player, lineTwo)) {
                                    player.sendMessage(Text.of(TextColors.GRAY, "Job changed to: ", TextColors.GOLD, lineTwo));
                                } else {
                                    player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to set job. Contact your administrator."));
                                }
                            } else {
                                player.sendMessage(Text.of(TextColors.RED, "[TE] Sorry, this job does not exist"));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Player(org.spongepowered.api.entity.living.player.Player) SignData(org.spongepowered.api.data.manipulator.mutable.tileentity.SignData) Sign(org.spongepowered.api.block.tileentity.Sign) Text(org.spongepowered.api.text.Text) Listener(org.spongepowered.api.event.Listener)

Aggregations

Sign (org.spongepowered.api.block.tileentity.Sign)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 SignData (org.spongepowered.api.data.manipulator.mutable.tileentity.SignData)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 Text (org.spongepowered.api.text.Text)1