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


Java WorldServer.getChunkFromChunkCoords方法代碼示例

本文整理匯總了Java中net.minecraft.world.WorldServer.getChunkFromChunkCoords方法的典型用法代碼示例。如果您正苦於以下問題:Java WorldServer.getChunkFromChunkCoords方法的具體用法?Java WorldServer.getChunkFromChunkCoords怎麽用?Java WorldServer.getChunkFromChunkCoords使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.world.WorldServer的用法示例。


在下文中一共展示了WorldServer.getChunkFromChunkCoords方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import net.minecraft.world.WorldServer; //導入方法依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length == 0 || args.length > 1) {
		throw new WrongUsageException("<Owner>");
	}
	
	ForgePlayer forgePlayer = Universe.get().getPlayer(args[0]);
	
	if (forgePlayer == null) {
		throw new CommandException(String.format("There is no player called %s that has been on this server", args[0]));
	}
	
	ForgeTeam team = forgePlayer.getTeam();
	
	if (team == null) {
		throw new CommandException(String.format("Player %s is not in a team", forgePlayer.getName()));
	}
	
	Set<ClaimedChunk> teamClaimedChunks = ClaimedChunks.get().getTeamChunks(team);
	
	if (teamClaimedChunks.isEmpty()) {
		throw new CommandException(String.format("team %s has not claimed any chunks", team.getName()));
	}
	
	ArrayList<PlayerInChunk> playersInChunks = new ArrayList<PlayerInChunk>();
	for (ClaimedChunk claimedChunk : teamClaimedChunks) {
		ChunkDimPos dimPos = claimedChunk.getPos();
		WorldServer world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(dimPos.dim);
		Chunk chunk = world.getChunkFromChunkCoords(dimPos.posX, dimPos.posZ);
		ChunkListOfPlayers chunkListOfPlayers = AllChunks.getChunk(chunk);
		if (chunkListOfPlayers == null) {
			continue;
		}
		
		playersInChunks.addAll(chunkListOfPlayers.playersInChunk);
	}
	
	Collections.sort(playersInChunks, new PlayersInChunkListComparator());
	for (PlayerInChunk player : playersInChunks) {
		String playerName = server.getPlayerProfileCache().getProfileByUUID(player.getPlayer()).getName();
		String enterTime = player.getEnterTimeCalendar().format(DateTimeFormatter.ofPattern("u/M/d H:m:s"));
		if (player.hasLeft()) {
			String leaveTime = player.getLeaveTimeCalendar().format(DateTimeFormatter.ofPattern("u/M/d H:m:s"));
			Duration stayTime = player.getStayTime();
			Long years = stayTime.toDays() / 365L;
			Long months = stayTime.toDays() / 30L;
			Long days = stayTime.toDays();
			Long hours = stayTime.toHours();
			Long minutes = stayTime.toMinutes();
			Long seconds = stayTime.getSeconds();
			if (months > 11) {
				months = months - (years * 12);
			}
			if (days > 29) {
				days = days - (days / 30 * 30);
			}
			if (hours > 23) {
				hours = hours - (hours / 24 * 24);
			}
			if (minutes > 59) {
				minutes = minutes - (minutes / 60 * 60);
			}
			if (seconds > 59) {
				seconds = seconds - (seconds / 60 * 60);
			}
			sender.sendMessage(new TextComponentString(String.format("Player %s was in one of the chunks from %s to %s for %s years and %s months and %s days and %s hours and %s minutes and %s seconds.", playerName, enterTime, leaveTime, years, months, days, hours, minutes, seconds)));
		} else {
			sender.sendMessage(new TextComponentString(String.format("Player %s was in one of the chunks from %s and has not left yet", playerName, enterTime)));
		}
	}
}
 
開發者ID:coehlrich,項目名稱:chunk-logger,代碼行數:72,代碼來源:GetPlayersInClaimedChunks.java


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