mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
a
This commit is contained in:
parent
978447cdbb
commit
b30cdd3b2f
8 changed files with 94 additions and 18 deletions
|
|
@ -81,10 +81,20 @@ class AchievementAPI{
|
|||
],
|
||||
|
||||
];
|
||||
|
||||
|
||||
private $server;
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an achievement
|
||||
* @param string $achievementId
|
||||
* @param string $achievementName
|
||||
* @param array $requires
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addAchievement($achievementId, $achievementName, array $requires = []){
|
||||
if(!isset(self::$achievements[$achievementId])){
|
||||
self::$achievements[$achievementId] = [
|
||||
|
|
@ -147,6 +157,47 @@ class AchievementAPI{
|
|||
}
|
||||
}
|
||||
|
||||
public function viewAchievements($cmd, $params, $issuer, $alias)
|
||||
{
|
||||
if(!($issuer instanceof Player) && !isset($params[0])){
|
||||
return "Please enter a nickname.";
|
||||
} else{
|
||||
if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){
|
||||
$player = $this->server->api->player->get($params[0]);
|
||||
if($player instanceof Player){
|
||||
$data = $player->data;
|
||||
} else{
|
||||
$data = $this->server->api->player->getOffline(trim($params[0]), false);
|
||||
}
|
||||
} else{
|
||||
$data = $issuer->achievements;
|
||||
}
|
||||
}
|
||||
if($data === false){
|
||||
return "Player {$params[0]} is not found.";
|
||||
}
|
||||
if($data instanceof Config){
|
||||
$achs = $data->get("achievements");
|
||||
}else{
|
||||
$achs = $data;
|
||||
}
|
||||
|
||||
if(count($achs) <= 0){
|
||||
return "Player {$params[0]} unlocked 0 achievements";
|
||||
}
|
||||
$output = "Unlocked Achievements(".count($achs)."), ";
|
||||
foreach($achs as $achievement => $unlocked){
|
||||
if($unlocked && isset(self::$achievements[$achievement])){
|
||||
$info = self::$achievements[$achievement];
|
||||
$output .= "{$info["name"]}, ";
|
||||
}
|
||||
}
|
||||
return substr($output, 0, - 2);
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
|
||||
$this->server->api->console->alias("getplayerachievements", "ach");
|
||||
$this->server->api->console->cmdWhitelist("ach");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ class BanAPI{
|
|||
private $ops;
|
||||
/** @var Config */
|
||||
private $bannedIPs;
|
||||
private $cmdWL = [];//Command WhiteList
|
||||
|
||||
public $cmdWhitelist = [];//Command WhiteList
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
|
|
@ -43,10 +44,13 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Whitelists a CMD so everyone can issue it - Even non OPs.
|
||||
* @deprecated use ConsoleAPI::cmdWhitelist
|
||||
* @see ConsoleAPI::cmdWhitelist
|
||||
* @param string $cmd Command to Whitelist
|
||||
*/
|
||||
public function cmdWhitelist($cmd){//Whitelists a CMD so everyone can issue it - Even non OPs.
|
||||
$this->cmdWhitelist[strtolower(trim($cmd))] = true;
|
||||
public function cmdWhitelist($cmd){//
|
||||
$this->server->api->console->cmdWhitelist($cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ class ChatAPI{
|
|||
$this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->ban->cmdWhitelist("tell");
|
||||
$this->server->api->ban->cmdWhitelist("me");
|
||||
$this->server->api->console->cmdWhitelist("tell");
|
||||
$this->server->api->console->cmdWhitelist("me");
|
||||
$this->server->api->console->alias("msg", "tell");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,18 @@ class ConsoleAPI{
|
|||
$this->register("difficulty", "<0|1|2|3>", [$this, "defaultCommands"]);
|
||||
$this->register("stop", "", [$this, "defaultCommands"]);
|
||||
$this->register("defaultgamemode", "<mode>", [$this, "defaultCommands"]);
|
||||
$this->server->api->ban->cmdWhitelist("help");
|
||||
$this->server->api->ban->cmdWhitelist("status");
|
||||
$this->cmdWhitelist("help");
|
||||
$this->cmdWhitelist("status");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whitelists a CMD so everyone can issue it - Even non OPs.
|
||||
* @param string $cmd Command to Whitelist
|
||||
*/
|
||||
public function cmdWhitelist($cmd){
|
||||
$this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true;
|
||||
}
|
||||
|
||||
public function register($cmd, $help, $callback){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ class PlayerAPI{
|
|||
$this->server->api->console->alias("who", "list");
|
||||
$this->server->api->console->alias("suicide", "kill");
|
||||
$this->server->api->console->alias("tppos", "tp");
|
||||
$this->server->api->ban->cmdWhitelist("list");
|
||||
$this->server->api->ban->cmdWhitelist("ping");
|
||||
$this->server->api->ban->cmdWhitelist("spawn");
|
||||
$this->server->api->console->cmdWhitelist("list");
|
||||
$this->server->api->console->cmdWhitelist("ping");
|
||||
$this->server->api->console->cmdWhitelist("spawn");
|
||||
$this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = " . ENTITY_PLAYER . " AND health < 20;");
|
||||
}
|
||||
|
||||
|
|
@ -360,7 +360,7 @@ class PlayerAPI{
|
|||
}
|
||||
}
|
||||
|
||||
public function getOffline($name){
|
||||
public function getOffline($name, $create = true){
|
||||
$iname = strtolower($name);
|
||||
$default = [
|
||||
"caseusername" => $name,
|
||||
|
|
@ -387,10 +387,12 @@ class PlayerAPI{
|
|||
];
|
||||
|
||||
if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){
|
||||
if($this->server->extraprops->get("save-player-data")){
|
||||
if($this->server->extraprops->get("save-player-data") && $create){
|
||||
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
|
||||
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
|
||||
$data->save();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ class PluginAPI extends stdClass{
|
|||
$this->randomNonce = Utils::getRandomBytes(16, false);
|
||||
$this->server->api->console->register("plugins", "", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("version", "", [$this, "commandHandler"]);
|
||||
$this->server->api->ban->cmdWhitelist("version");
|
||||
$this->server->api->console->cmdWhitelist("version");
|
||||
if($this->server->extraprops->get("query-plugins")){ //allow players to also view plugins ingame, since query makes names public
|
||||
$this->server->api->console->cmdWhitelist("plugins");
|
||||
}
|
||||
$this->server->api->console->alias("pl", "plugins");
|
||||
$this->server->api->console->alias("ver", "version");
|
||||
$this->server->api->console->alias("about", "version");
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ class ServerAPI{
|
|||
* @var TileAPI
|
||||
*/
|
||||
public $tile;
|
||||
/**
|
||||
* @var AchievementAPI
|
||||
*/
|
||||
public $achievement;
|
||||
private $asyncCalls = [];
|
||||
private $server;
|
||||
private $config;
|
||||
|
|
@ -144,7 +148,6 @@ class ServerAPI{
|
|||
console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0);
|
||||
|
||||
$this->loadProperties();
|
||||
|
||||
$this->loadAPI("console", "ConsoleAPI");
|
||||
$this->loadAPI("level", "LevelAPI");
|
||||
$this->loadAPI("block", "BlockAPI");
|
||||
|
|
@ -155,6 +158,7 @@ class ServerAPI{
|
|||
$this->loadAPI("player", "PlayerAPI");
|
||||
$this->loadAPI("time", "TimeAPI");
|
||||
$this->loadAPI("queryAPI", "QueryAPI");
|
||||
$this->loadAPI("achievement", "AchievementAPI");
|
||||
foreach($this->apiList as $ob){
|
||||
if(is_callable([$ob, "init"])){
|
||||
$ob->init(); //Fails sometimes!!!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue