use of org.spongepowered.api.data.manipulator.mutable.tileentity.SignData in project modules-extra by CubeEngine.
the class Writer method editSignInSight.
/**
* Edits the sign the user is looking at
*
* @param user the user
* @param line1 the 1st line
* @param line2 the 2nd line
* @param line3 the 3rd line
* @param line4 the 4th line
*
* @return false if there is no sign to edit in sight
*/
public boolean editSignInSight(Player user, String line1, String line2, String line3, String line4) {
Iterator<BlockRayHit<World>> it = BlockRay.from(user).distanceLimit(10).iterator();
BlockRayHit<World> result = null;
while (it.hasNext()) {
BlockRayHit<World> next = it.next();
BlockType type = next.getLocation().getBlockType();
if (type == WALL_SIGN || type == STANDING_SIGN) {
result = next;
break;
}
}
if (result == null) {
return false;
}
Location<World> block = result.getLocation();
BlockType type = block.getBlockType();
if (type != WALL_SIGN && type != STANDING_SIGN) {
return false;
}
SignData signData = block.get(SignData.class).get();
ListValue<Text> lines = signData.lines();
lines.set(0, line1 == null ? lines.get(0) : Text.of(line1));
lines.set(1, line2 == null ? lines.get(1) : Text.of(line2));
lines.set(2, line3 == null ? lines.get(2) : Text.of(line3));
lines.set(3, line4 == null ? lines.get(3) : Text.of(line4));
System.out.println(block.offer(signData).isSuccessful());
i18n.send(user, POSITIVE, "The sign has been changed!");
return true;
}
use of org.spongepowered.api.data.manipulator.mutable.tileentity.SignData in project TotalEconomy by Erigitic.
the class JobManager 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.Secondary 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 jobName = lineTwoText.toPlain().toLowerCase();
if (lineOne.equals("[TEJobs]")) {
if (jobExists(jobName)) {
if (setJob(player, jobName)) {
Map<String, String> messageValues = new HashMap<>();
messageValues.put("job", titleize(jobName));
player.sendMessage(messageManager.getMessage("jobs.sign", messageValues));
} else {
player.sendMessage(Text.of(TextColors.RED, "Failed to set job. Contact your administrator."));
}
} else {
player.sendMessage(Text.of(TextColors.RED, "Sorry, this job does not exist"));
}
}
}
}
}
}
}
}
use of org.spongepowered.api.data.manipulator.mutable.tileentity.SignData in project TotalEconomy by Erigitic.
the class JobManager method onJobSignCheck.
/**
* Checks sign contents and converts it to a "Job Changing" sign if conditions are met
*
* @param event ChangeSignEvent
*/
@Listener
public void onJobSignCheck(ChangeSignEvent event) {
SignData data = event.getText();
Text lineOne = data.lines().get(0);
Text lineTwo = data.lines().get(1);
String lineOnePlain = lineOne.toPlain();
String lineTwoPlain = lineTwo.toPlain();
if (lineOnePlain.equals("[TEJobs]")) {
lineOne = lineOne.toBuilder().style(TextStyles.BOLD).color(TextColors.DARK_BLUE).build();
String jobName = titleize(lineTwoPlain);
if (jobExists(lineTwoPlain)) {
lineTwo = Text.of(jobName).toBuilder().color(TextColors.BLACK).build();
} else {
lineTwo = Text.of(jobName).toBuilder().color(TextColors.RED).build();
}
data.set(data.lines().set(0, lineOne));
data.set(data.lines().set(1, lineTwo));
data.set(data.lines().set(2, Text.of()));
data.set(data.lines().set(3, Text.of()));
}
}
Aggregations