Module:Sandbox/PhoenixAsh89/Version link

local p = {}

local function removePrefix( s, prefixes )
	local final = s
	for _, p in ipairs( prefixes ) do
		final = final:gsub( '^' .. p, '' )
	end
	return mw.text.trim(final)
end

local function getLast( prefix )
	return function( s )
		local last = mw.ustring.match( s, '^.+%s+(%S+)$' )
		return prefix .. last
	end
end

local function getJava( s )
	return 'Java Edition ' .. removePrefix( s, { '[Jj]ava', ' [Ee]dition', '[Jj][Ee]' } )
end

local function getBedrock( s )
	return 'Bedrock Edition ' .. removePrefix( s, { '[Bb]edrock', ' [Ee]dition', '[Bb][Ee]' } )
end

local function getPocket( s )
	if(s:match('Alpha') and not s:match('Realms')) then
		return 'Pocket Edition ' .. mw.getCurrentFrame():callParserFunction( '#dplreplace', s, '/^(pocket edition|pocket|pe) (Alpha)? ?v?(\\d+\\.\\d+\\.\\d+)? ?(build \\d+)?/i', 'v\\3 alpha \\4' )
	end
	return 'Pocket Edition ' .. removePrefix( s, { '[Pp]ocket', ' [Ee]dition', '[Pp][Ee]' } )
end

local function getEducation( s )
	return 'Minecraft Education ' .. removePrefix( s, { '[Ee]ducation', ' [Ee]dition', '[Ee][Dd][Uu]', '[Ee][Ee]' } )
end

local function getChinese()
	return 'China Edition#History'
end

local function getLauncher( s )
	return 'Minecraft launcher#' .. removePrefix( s, { '[Ll]auncher' } )
end

local function getPlayStation( s )
	return removePrefix( s, { '[Pp]layStation', '[Pp][Ss]' } ) .. '#Legacy Console Edition'
end

local prefixFunctions = {
	java = getJava,
	je = getJava,
	['pre-classic'] = getJava,
	classic = getJava,
	indev = getJava,
	infdev = getJava,
	alpha = getJava,
	beta = getJava,
	pe = getPocket,
	pocket = getPocket,
	be = getBedrock,
	bedrock = getBedrock,
	edu = getEducation,
	education = getEducation,
	ee = getEducation,
	china = getChinese,
	chinese = getChinese,
	launcher = getLauncher,
	earth = getLast( 'Earth:' ),
	dungeons = getLast( 'Dungeons:' ),
	['dungeons arcade'] = getLast( 'Dungeons:' ),
	legends = getLast( 'Legends:' ),
	realms = getLast( 'Realms#' ),
	['360'] = getLast( 'Xbox 360 Edition ' ),
	xbox360 = getLast( 'Xbox 360 Edition ' ),
	xbone = getLast( 'Xbox One Edition ' ),
	xb1 = getLast( 'Xbox One Edition ' ),
	xbox1 = getLast( 'Xbox One Edition ' ),
	ps = getPlayStation,
	ps3 = getLast( 'PlayStation 3 Edition ' ),
	ps4 = getLast( 'PlayStation 4 Edition ' ),
	playstation = getLast( 'PlayStation 4 Edition ' ),
	psv = getLast( 'PlayStation Vita Edition ' ),
	psvita = getLast( 'PlayStation Vita Edition ' ),
	wii = getLast( 'Wii U Edition Patch ' ),
	wiiu = getLast( 'Wii U Edition Patch ' ),
	switch = getLast( 'Nintendo Switch Edition ' ),
	nswitch = getLast( 'Nintendo Switch Edition ' ),
	['3ds'] = getLast( 'New Nintendo 3DS Edition ' ),
	new = getLast( 'New Nintendo 3DS Edition ' ),
	new3ds = getLast( 'New Nintendo 3DS Edition ' ),
	minecraftedu = getLast( 'MinecraftEdu ' ),
	launcher = getLast( 'Launcher ' ),
}

function p.version( s )
	local v = s:gsub( '^[Mm]inecraft ', '' )
	local prefix = mw.text.split( v, '%s' )[1]:lower()
	local func = prefixFunctions[prefix]
	if func then
		return func( v )
	else
		return v
	end
end

function p.main( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( [[Module:ProcessArgs]] ).merge( false )
	end
	local text
	if args[2]=='' then
		text = mw.ustring.match( args[1], '^.+%s+(%S+)$' )
	else
		text = args[2] or args[1]
	end
	return '[[' .. p.version( args[1] ) .. '|' .. text .. ']]'
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.