當前位置: 首頁>>代碼示例>>Java>>正文


Java Location.getTileEntity方法代碼示例

本文整理匯總了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;
}
 
開發者ID:TheoKah,項目名稱:CarrotShop,代碼行數:14,代碼來源:Shop.java

示例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());
		}
	}
 
開發者ID:TheoKah,項目名稱:CarrotShop,代碼行數:74,代碼來源:ShopsLogs.java

示例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;
}
 
開發者ID:TheoKah,項目名稱:CarrotShop,代碼行數:7,代碼來源:Shop.java


注:本文中的org.spongepowered.api.world.Location.getTileEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。