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"));
}
}
}
}
}
}
}
}
Aggregations