本文整理汇总了Java中org.spongepowered.api.world.Location.getTileEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getTileEntity方法的具体用法?Java Location.getTileEntity怎么用?Java Location.getTileEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.world.Location
的用法示例。
在下文中一共展示了Location.getTileEntity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrice
import org.spongepowered.api.world.Location; //导入方法依赖的package包/类
static protected final int getPrice(Location<World> location) {
Optional<TileEntity> sign = location.getTileEntity();
if (sign.isPresent() && sign.get().supports(SignData.class)) {
Optional<SignData> data = sign.get().get(SignData.class);
if (data.isPresent()) {
String priceLine = data.get().lines().get(3).toPlain().replaceAll("[^\\d]", "");
if (priceLine.length() == 0)
return 0;
return Integer.parseInt(priceLine);
}
}
return -1;
}
示例2: log
import org.spongepowered.api.world.Location; //导入方法依赖的package包/类
public static void log(UUID shopOwnerUUID, Player player, String type, Location<World> location, Optional<Integer> price, Optional<Currency> currency, Optional<Inventory> itemsA, Optional<Inventory> itemsB) {
String shopOwner = shopOwnerUUID != null ? shopOwnerUUID.toString() : "server";
if (shopOwnerUUID != null) {
Optional<Player> seller = Sponge.getServer().getPlayer(shopOwnerUUID);
if (!seller.isPresent()) {
ShopsData.soldSomethingOffline(shopOwnerUUID);
}
}
JsonObject newNode = new JsonObject();
newNode.addProperty("player", player.getName());
newNode.addProperty("playerID", player.getUniqueId().toString());
newNode.addProperty("time", System.currentTimeMillis());
JsonObject locationNode = new JsonObject();
locationNode.addProperty("world", location.getExtent().getName());
locationNode.addProperty("worldID", location.getExtent().getUniqueId().toString());
locationNode.addProperty("X", location.getBlockX());
locationNode.addProperty("Y", location.getBlockY());
locationNode.addProperty("Z", location.getBlockZ());
Optional<TileEntity> sign = location.getTileEntity();
if (sign.isPresent() && sign.get().supports(SignData.class)) {
Optional<SignData> data = sign.get().getOrCreate(SignData.class);
if (data.isPresent()) {
locationNode.addProperty("line0", data.get().lines().get(0).toPlain());
locationNode.addProperty("line1", data.get().lines().get(1).toPlain());
locationNode.addProperty("line2", data.get().lines().get(2).toPlain());
locationNode.addProperty("line3", data.get().lines().get(3).toPlain());
}
}
newNode.add("sign", locationNode);
if (ShopsData.hasMultipleCurrencies() && currency.isPresent()) {
JsonObject currencyNode = new JsonObject();
currencyNode.addProperty("currencySymbol", TextSerializers.FORMATTING_CODE.serialize(currency.get().getSymbol()));
currencyNode.addProperty("currencySymbolplain", currency.get().getSymbol().toPlain());
currencyNode.addProperty("currencyName", currency.get().getName());
currencyNode.addProperty("currencyDName", TextSerializers.FORMATTING_CODE.serialize(currency.get().getDisplayName()));
currencyNode.addProperty("currencyPDName", TextSerializers.FORMATTING_CODE.serialize(currency.get().getPluralDisplayName()));
newNode.add("currency", currencyNode);
}
if (price.isPresent())
newNode.addProperty("price", price.get());
if (itemsA.isPresent())
newNode.add("items", invToArray(itemsA.get()));
if (itemsB.isPresent())
newNode.add("items2", invToArray(itemsB.get()));
try {
File file = new File(carrotLogsFolder, shopOwner + "." + type);
if (!file.exists()) {
file.createNewFile();
JsonObject firstNode = new JsonObject();
firstNode.addProperty("init", true);
firstNode.addProperty("time", System.currentTimeMillis());
Files.write(file.toPath(), firstNode.toString().getBytes(), StandardOpenOption.APPEND);
}
Files.write(file.toPath(), ",".getBytes(), StandardOpenOption.APPEND);
Files.write(file.toPath(), newNode.toString().getBytes(), StandardOpenOption.APPEND);
} catch (IOException e) {
CarrotShop.getLogger().error("Unable to store logs for shop " + shopOwner + " triggered by " + player.getName() + ": " + e.getMessage());
}
}
示例3: Shop
import org.spongepowered.api.world.Location; //导入方法依赖的package包/类
public Shop(Location<World> loc) {
Optional<TileEntity> tile = loc.getTileEntity();
if (!tile.isPresent() || !tile.get().supports(SignData.class))
throw new ExceptionInInitializerError("Improbable error: managed to trigger a shop creation event from something other than a sign");
location = loc;
}