use of org.spongepowered.api.item.ItemType 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.item.ItemType 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);
}
}
}
use of org.spongepowered.api.item.ItemType in project AdamantineShield by Karanum.
the class RollbackManager method performRemoval.
private void performRemoval(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();
Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
slot.set(ItemStack.of(ItemTypes.NONE, 0));
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
w.setBlock(line.getPos(), block);
}
}
use of org.spongepowered.api.item.ItemType in project core by CubeEngine.
the class MaterialMatcher method buildLocalizedNames.
private void buildLocalizedNames(Map<String, ItemType> defLocalizedName, Map<String, ItemType> localizedName) {
for (ItemType itemType : Sponge.getRegistry().getAllOf(ItemType.class)) {
String id = itemType.getName();
ids.put(id, itemType);
if (id.startsWith("minecraft:")) {
ids.put(id.substring("minecraft:".length()), itemType);
}
String defName = itemType.getTranslation().get(Locale.getDefault());
defLocalizedName.put(defName, itemType);
String[] splitDefName = defName.split(" ");
if (splitDefName.length > 1) {
defName = splitDefName[splitDefName.length - 1];
defName += String.join(" ", splitDefName).replace(defName, "");
defLocalizedName.put(defName, itemType);
}
String sourceName = itemType.getTranslation().get(Locale.US);
localizedName.put(sourceName, itemType);
String[] splitSourceName = sourceName.split(" ");
if (splitSourceName.length > 1) {
sourceName = splitSourceName[splitSourceName.length - 1];
sourceName += String.join(" ", splitSourceName).replace(sourceName, "");
localizedName.put(sourceName, itemType);
}
}
}
use of org.spongepowered.api.item.ItemType in project core by CubeEngine.
the class ItemTypeParser method suggest.
@Override
public List<String> suggest(Class type, CommandInvocation invocation) {
ArrayList<String> list = new ArrayList<>();
String token = invocation.currentToken().toLowerCase();
if (MINECRAFT.startsWith(token)) {
list.add(MINECRAFT);
}
boolean startMc = token.startsWith(MINECRAFT);
for (ItemType iType : Sponge.getRegistry().getAllOf(ItemType.class)) {
if (iType.getId().startsWith(token)) {
if (!iType.getId().startsWith(MINECRAFT) || startMc) {
list.add(iType.getId());
}
}
if (iType.getId().startsWith(MINECRAFT + token)) {
list.add(iType.getId().substring(MINECRAFT.length()));
}
}
return list;
}
Aggregations