Merge pull request #87 from mc-server/transapi
Add TransAPI as a default plugin.
This commit is contained in:
commit
6d69078517
20
MCServer/Plugins/TransAPI/LICENSE
Normal file
20
MCServer/Plugins/TransAPI/LICENSE
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013 Alexander Harkness
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
MCServer/Plugins/TransAPI/README.md
Normal file
20
MCServer/Plugins/TransAPI/README.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
TransAPI
|
||||||
|
========
|
||||||
|
|
||||||
|
A plugin translation API for MCServer.
|
||||||
|
|
||||||
|
TransAPI is designed to be used with the [client library](https://github.com/bearbin/transapi-client), however there is also a stable API available for use.
|
||||||
|
|
||||||
|
API
|
||||||
|
---
|
||||||
|
|
||||||
|
GetLanguage ( cPlayer )
|
||||||
|
Returns the user's preferred language (or server default if not set). (ISO 639-1 language code)
|
||||||
|
|
||||||
|
GetConsoleLanguage ( )
|
||||||
|
Returns the preferred language for console text. (ISO 639-1 language code)
|
||||||
|
|
||||||
|
Commands
|
||||||
|
--------
|
||||||
|
|
||||||
|
* /language [lang] - Takes a language code (ISO 639-1) and sets the user's preferred language to that. (tranapi.setlang)
|
91
MCServer/Plugins/TransAPI/main.lua
Normal file
91
MCServer/Plugins/TransAPI/main.lua
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
-- This plugin copyright Alexander Harkness 2013, licensed under the MIT license.
|
||||||
|
|
||||||
|
-- Configuration
|
||||||
|
g_ServerLang = "en"
|
||||||
|
g_ConsoleLang = "en"
|
||||||
|
|
||||||
|
-- Global Variables
|
||||||
|
g_Plugin = nil
|
||||||
|
g_PluginManager = nil
|
||||||
|
g_PluginDir = nil
|
||||||
|
g_UserData = nil
|
||||||
|
|
||||||
|
-- START WITH DA AWESOME!
|
||||||
|
function Initialize( Plugin )
|
||||||
|
|
||||||
|
-- Set up the globals.
|
||||||
|
g_Plugin = Plugin
|
||||||
|
g_PluginManager = cRoot:Get():GetPluginManager()
|
||||||
|
g_PluginDir = Plugin:GetDirectory()
|
||||||
|
|
||||||
|
-- Set up the plugin details.
|
||||||
|
Plugin:SetName( "TransAPI" )
|
||||||
|
Plugin:SetVersion( 1 )
|
||||||
|
|
||||||
|
-- This is the place for commands!
|
||||||
|
g_PluginManager:BindCommand("/language", "transapi.setlang", HandleLanguageCommand, " - Set your preferred language (use ISO 639-1)")
|
||||||
|
|
||||||
|
-- Load the userdata file.
|
||||||
|
g_UserData = cIniFile( g_PluginDir .. "/userdata.ini" )
|
||||||
|
if g_UserData ~= true then
|
||||||
|
LOGERROR( "TransAPI INI file could not be opened!" )
|
||||||
|
end
|
||||||
|
|
||||||
|
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function GetLanguage( Player )
|
||||||
|
|
||||||
|
-- Returns a language to use.
|
||||||
|
if g_UserData:ReadFile() == true then
|
||||||
|
local userLang = g_UserData:GetValueSet( Player:GetName(), "language", "false" )
|
||||||
|
g_UserData:WriteFile()
|
||||||
|
end
|
||||||
|
|
||||||
|
if userLang == "false" then
|
||||||
|
return g_ServerLang
|
||||||
|
else
|
||||||
|
return userLang
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function GetConsoleLanguage()
|
||||||
|
-- Return the language to use for console messages.
|
||||||
|
return g_ConsoleLang
|
||||||
|
end
|
||||||
|
|
||||||
|
function HandleLanguageCommand ( Split, Player )
|
||||||
|
|
||||||
|
-- If the user is not setting the language, tell them the currently selected one.
|
||||||
|
if #Split ~= 2 then
|
||||||
|
|
||||||
|
local userLang = g_UserData:GetValueSet( Player:GetName(), "language", "false" )
|
||||||
|
if userLang == "false" then
|
||||||
|
return g_ServerLang
|
||||||
|
else
|
||||||
|
return userLang
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set the language.
|
||||||
|
local success = g_UserData:SetValue( Player:GetName(), "language" Split[2] )
|
||||||
|
g_UserData:WriteFile()
|
||||||
|
|
||||||
|
if not success then
|
||||||
|
Player:SendMessage( "Language could not be set!" )
|
||||||
|
else
|
||||||
|
Player:SendMessage( "Language set!" )
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function OnDisable()
|
||||||
|
LOG( "Disabled TransAPI!" )
|
||||||
|
end
|
@ -18,6 +18,7 @@ DefaultWorld=world
|
|||||||
Plugin=Core
|
Plugin=Core
|
||||||
Plugin=ChunkWorx
|
Plugin=ChunkWorx
|
||||||
Plugin=ChatLog
|
Plugin=ChatLog
|
||||||
|
Plugin=TransAPI
|
||||||
|
|
||||||
[Monsters]
|
[Monsters]
|
||||||
AnimalsOn=0
|
AnimalsOn=0
|
||||||
|
Loading…
Reference in New Issue
Block a user