use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class ReportUtil method name.
public static Text name(BlockSnapshot snapshot, Receiver receiver) {
BlockType type = snapshot.getState().getType();
Translation trans = type.getTranslation();
if (snapshot.getState().getType().getItem().isPresent()) {
trans = ItemStack.builder().fromBlockSnapshot(snapshot).build().getTranslation();
}
Builder builder = Text.builder();
builder.append(Text.of(GOLD, trans).toBuilder().onHover(showText(Text.of(type.getName()))).build());
Optional<List<DataView>> items = snapshot.toContainer().getViewList(BlockReport.BLOCK_ITEMS);
if (items.isPresent() && !items.get().isEmpty()) {
// TODO lookup config : detailed inventory? click on ∋ to activate/deactivate or using cmd
builder.append(Text.of(" ∋ ["));
if (receiver.getLookup().getSettings().showDetailedInventory()) {
builder.append(Text.of(" "));
for (DataView dataView : items.get()) {
DataContainer itemData = DataContainer.createNew();
itemData.set(DataQuery.of("Count"), dataView.get(DataQuery.of("Count")).get());
itemData.set(DataQuery.of("ItemType"), dataView.get(DataQuery.of("id")).get());
Optional<DataView> tag = dataView.getView(DataQuery.of("tag"));
if (tag.isPresent()) {
itemData.set(DataQuery.of("UnsafeData"), tag.get().getValues(false));
}
itemData.set(DataQuery.of("UnsafeDamage"), dataView.get(DataQuery.of("Damage")).get());
ItemStack item = ItemStack.builder().fromContainer(itemData).build();
builder.append(Text.of(dataView.getInt(DataQuery.of("Slot")).get()).toBuilder().onHover(showItem(item.createSnapshot())).build());
builder.append(Text.of(" "));
}
} else {
builder.append(Text.of("..."));
}
builder.append(Text.of("]"));
}
Optional<List<Text>> sign = snapshot.get(Keys.SIGN_LINES);
if (sign.isPresent()) {
builder.append(Text.of(" "), Text.of("[I]").toBuilder().onHover(showText(Text.joinWith(Text.NEW_LINE, sign.get()))).build());
}
return builder.build();
}
use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class ElevatorListener method onInteractBlock.
@Listener
public void onInteractBlock(InteractBlockEvent event, @Root Player player) {
if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand)) {
return;
}
BlockType type = event.getTargetBlock().getState().getType();
if (type != BlockTypes.STANDING_SIGN && type != BlockTypes.WALL_SIGN) {
return;
}
Location<World> loc = event.getTargetBlock().getLocation().get();
ElevatorData data = loc.get(ElevatorData.class).orElse(null);
Boolean sneak = player.get(Keys.IS_SNEAKING).orElse(false);
if (sneak) {
Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
if (data == null) {
if (!(event instanceof InteractBlockEvent.Primary)) {
// Only Punch to activate
return;
}
if (itemInHand.isPresent()) {
if (player.hasPermission(module.getPerm().CREATE.getId()) && itemInHand.get().getType().equals(module.getConfig().creationItem)) {
data = new ElevatorData();
data.setOwner(player.getUniqueId());
loc.offer(data);
ItemStack item = itemInHand.get();
item.setQuantity(item.getQuantity() - 1);
player.setItemInHand(HandTypes.MAIN_HAND, item);
List<Text> list = loc.get(Keys.SIGN_LINES).get();
// Set First Line with name of renamed Item
list.set(0, itemInHand.get().get(Keys.DISPLAY_NAME).orElse(list.get(0)));
loc.offer(Keys.SIGN_LINES, list);
i18n.send(ACTION_BAR, player, POSITIVE, "Elevator created!");
updateSign(loc, data);
event.setCancelled(true);
}
}
} else if (// Sign has Elevator Data and hand is empty
!itemInHand.isPresent()) {
if (player.hasPermission(module.getPerm().ADJUST.getId())) {
// Search order dependent on click
Vector3i target = data.getTarget();
target = findNextSign(loc, target, loc.getBlockPosition(), event instanceof InteractBlockEvent.Primary);
data.setTarget(target);
updateSign(loc, data);
event.setCancelled(true);
}
} else if (itemInHand.get().getType() == ItemTypes.PAPER && event instanceof InteractBlockEvent.Primary) {
if (player.hasPermission(module.getPerm().RENAME.getId())) {
List<Text> list = loc.get(Keys.SIGN_LINES).get();
// Set First Line with name of renamed Item
list.set(0, itemInHand.get().get(Keys.DISPLAY_NAME).orElse(list.get(0)));
loc.offer(Keys.SIGN_LINES, list);
i18n.send(ACTION_BAR, player, POSITIVE, "Elevator name changed!");
event.setCancelled(true);
}
}
return;
}
if (event instanceof InteractBlockEvent.Secondary && player.hasPermission(module.getPerm().USE.getId())) {
Optional<Vector3i> target = event.getTargetBlock().get(IElevatorData.TARGET);
if (target.isPresent()) {
if (loc.getExtent().get(target.get(), ElevatorData.class).isPresent()) {
Vector3i sign = target.get();
Vector3d pPos = player.getLocation().getPosition();
Location<World> targetLoc = new Location<>(player.getWorld(), pPos.getX(), sign.getY() - 1, pPos.getZ());
if (!player.setLocationSafely(targetLoc)) {
i18n.send(ACTION_BAR, player, NEGATIVE, "Target obstructed");
}
event.setCancelled(true);
} else {
i18n.send(ACTION_BAR, player, NEGATIVE, "Target sign was destroyed!");
event.setCancelled(true);
}
}
}
if (event instanceof InteractBlockEvent.Secondary) {
Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
if (itemInHand.isPresent()) {
if (player.hasPermission(module.getPerm().CREATE.getId()) && itemInHand.get().getType().equals(module.getConfig().creationItem)) {
event.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.block.BlockType in project AdamantineShield by Karanum.
the class LookupLine method getHoverText.
public Text getHoverText() {
Text result = Text.of(TextColors.DARK_AQUA, "Location: ", TextColors.AQUA, pos.toString());
if (data == null)
return result;
ConfigurationNode workingNode = null;
ConfigurationNode node = null;
try {
node = DataUtils.configNodeFromString(data);
} catch (IOException e) {
e.printStackTrace();
return result;
}
// Common tags
workingNode = node.getNode("UnsafeDamage");
if (!workingNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Damage: ", TextColors.AQUA, workingNode.getInt());
}
// Item exclusive tags
if (target instanceof ItemType) {
workingNode = node.getNode("UnsafeData", "SkullOwner");
if (!workingNode.isVirtual()) {
String name = workingNode.getString();
if (!workingNode.getNode("Name").isVirtual())
name = workingNode.getNode("Name").getString();
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Player: ", TextColors.AQUA, name);
}
workingNode = node.getNode("UnsafeData", "display");
if (!workingNode.isVirtual()) {
ConfigurationNode innerNode = workingNode.getNode("Name");
if (!innerNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Name: ", TextColors.AQUA, innerNode.getString());
}
innerNode = workingNode.getNode("color");
if (!innerNode.isVirtual()) {
int color = innerNode.getInt();
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Color: ", TextColors.AQUA, "(", TextColors.RED, color >> 16, TextColors.AQUA, ", ", TextColors.GREEN, (color >> 8) % 256, TextColors.AQUA, ", ", TextColors.BLUE, color % 256, TextColors.AQUA, ")");
}
innerNode = workingNode.getNode("Lore");
if (!innerNode.isVirtual()) {
try {
Text sub = Text.of(TextColors.DARK_AQUA, "Lore: ");
for (String line : innerNode.getList(TypeToken.of(String.class))) {
sub = Text.of(sub, Text.NEW_LINE, TextColors.DARK_AQUA, " - ", TextColors.AQUA, line);
}
result = Text.of(result, Text.NEW_LINE, sub);
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
}
workingNode = node.getNode("UnsafeData", "title");
if (!workingNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Title: ", TextColors.AQUA, workingNode.getString());
}
workingNode = node.getNode("UnsafeData", "author");
if (!workingNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Author: ", TextColors.AQUA, workingNode.getString());
}
workingNode = node.getNode("UnsafeData", "Unbreakable");
if (!workingNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.AQUA, "Is unbreakable");
}
}
// Block exclusive tags
if (target instanceof BlockType) {
workingNode = node.getNode("UnsafeData", "Owner", "Name");
if (!workingNode.isVirtual() && !workingNode.getString().isEmpty()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Player: ", TextColors.AQUA, workingNode.getString());
}
workingNode = node.getNode("UnsafeData", "CustomName");
if (!workingNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Name: ", TextColors.AQUA, workingNode.getString());
}
workingNode = node.getNode("UnsafeData", "Text1");
if (!workingNode.isVirtual()) {
ConfigurationNode dataNode = node.getNode("UnsafeData");
if (!(dataNode.getNode("Text2").isVirtual() || dataNode.getNode("Text3").isVirtual() || dataNode.getNode("Text4").isVirtual())) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, "Text:");
Pattern p = DataUtils.SIGN_TEXT_REGEX;
for (int i = 1; i <= 4; ++i) {
Matcher m = p.matcher(dataNode.getNode("Text" + i).getString());
if (m.matches()) {
result = Text.of(result, Text.NEW_LINE, TextColors.DARK_AQUA, " - ", TextColors.AQUA, m.group(1));
}
}
} else {
result = Text.of(result, Text.NEW_LINE, TextColors.RED, "Contains incomplete sign data");
}
}
workingNode = node.getNode("UnsafeData", "Lock");
if (!workingNode.isVirtual()) {
result = Text.of(result, Text.NEW_LINE, TextColors.AQUA, "Is locked");
}
}
return result;
}
use of org.spongepowered.api.block.BlockType in project AdamantineShield by Karanum.
the class BlockLookupResult method readResult.
protected void readResult(ResultSet results) throws SQLException {
while (results.next()) {
Vector3i pos = new Vector3i(results.getInt("x"), results.getInt("y"), results.getInt("z"));
UUID world = UUID.fromString(results.getString("world"));
ActionType type = ActionType.valueCache[results.getByte("type")];
String cause = results.getString("cause");
String data = results.getString("data");
BlockType block = Sponge.getRegistry().getType(BlockType.class, results.getString("AS_Id.value")).get();
boolean rolledBack = results.getBoolean("rolled_back");
long timestamp = results.getLong("time");
lines.add(new LookupLine(pos, world, type, cause, data, block, 1, 0, rolledBack, timestamp));
}
}
use of org.spongepowered.api.block.BlockType in project AdamantineShield by Karanum.
the class RollbackManager method performAddition.
// TODO: Set proper causes for block changes caused by rollback/undo
private void performAddition(LookupLine line) {
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null)
return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
ItemType type = (ItemType) line.getTarget();
ItemStack stack = ItemStack.builder().fromContainer(line.getDataAsView()).itemType(type).quantity(line.getCount()).build();
Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
slot.set(stack);
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = null;
if (line.getDataAsView() == null) {
block = BlockState.builder().blockType((BlockType) line.getTarget()).build();
w.setBlock(line.getPos(), block);
} else {
DataView blockData = line.getDataAsView();
DataView blockState = blockData.getView(DataQuery.of("BlockState")).orElse(null);
block = BlockState.builder().build(blockState).orElse(null);
if (block != null)
w.setBlock(line.getPos(), block);
}
}
}
Aggregations