mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +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(){
|
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 = []){
|
public static function addAchievement($achievementId, $achievementName, array $requires = []){
|
||||||
if(!isset(self::$achievements[$achievementId])){
|
if(!isset(self::$achievements[$achievementId])){
|
||||||
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(){
|
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;
|
private $ops;
|
||||||
/** @var Config */
|
/** @var Config */
|
||||||
private $bannedIPs;
|
private $bannedIPs;
|
||||||
private $cmdWL = [];//Command WhiteList
|
|
||||||
|
public $cmdWhitelist = [];//Command WhiteList
|
||||||
|
|
||||||
function __construct(){
|
function __construct(){
|
||||||
$this->server = ServerAPI::request();
|
$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
|
* @param string $cmd Command to Whitelist
|
||||||
*/
|
*/
|
||||||
public function cmdWhitelist($cmd){//Whitelists a CMD so everyone can issue it - Even non OPs.
|
public function cmdWhitelist($cmd){//
|
||||||
$this->cmdWhitelist[strtolower(trim($cmd))] = true;
|
$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("tell", "<player> <private message ...>", [$this, "commandHandler"]);
|
||||||
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
|
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
|
||||||
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
|
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
|
||||||
$this->server->api->ban->cmdWhitelist("tell");
|
$this->server->api->console->cmdWhitelist("tell");
|
||||||
$this->server->api->ban->cmdWhitelist("me");
|
$this->server->api->console->cmdWhitelist("me");
|
||||||
$this->server->api->console->alias("msg", "tell");
|
$this->server->api->console->alias("msg", "tell");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,18 @@ class ConsoleAPI{
|
||||||
$this->register("difficulty", "<0|1|2|3>", [$this, "defaultCommands"]);
|
$this->register("difficulty", "<0|1|2|3>", [$this, "defaultCommands"]);
|
||||||
$this->register("stop", "", [$this, "defaultCommands"]);
|
$this->register("stop", "", [$this, "defaultCommands"]);
|
||||||
$this->register("defaultgamemode", "<mode>", [$this, "defaultCommands"]);
|
$this->register("defaultgamemode", "<mode>", [$this, "defaultCommands"]);
|
||||||
$this->server->api->ban->cmdWhitelist("help");
|
$this->cmdWhitelist("help");
|
||||||
$this->server->api->ban->cmdWhitelist("status");
|
$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){
|
public function register($cmd, $help, $callback){
|
||||||
if(!is_callable($callback)){
|
if(!is_callable($callback)){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@ class PlayerAPI{
|
||||||
$this->server->api->console->alias("who", "list");
|
$this->server->api->console->alias("who", "list");
|
||||||
$this->server->api->console->alias("suicide", "kill");
|
$this->server->api->console->alias("suicide", "kill");
|
||||||
$this->server->api->console->alias("tppos", "tp");
|
$this->server->api->console->alias("tppos", "tp");
|
||||||
$this->server->api->ban->cmdWhitelist("list");
|
$this->server->api->console->cmdWhitelist("list");
|
||||||
$this->server->api->ban->cmdWhitelist("ping");
|
$this->server->api->console->cmdWhitelist("ping");
|
||||||
$this->server->api->ban->cmdWhitelist("spawn");
|
$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;");
|
$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);
|
$iname = strtolower($name);
|
||||||
$default = [
|
$default = [
|
||||||
"caseusername" => $name,
|
"caseusername" => $name,
|
||||||
|
|
@ -387,10 +387,12 @@ class PlayerAPI{
|
||||||
];
|
];
|
||||||
|
|
||||||
if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){
|
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");
|
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
|
||||||
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
|
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
|
||||||
$data->save();
|
$data->save();
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ class PluginAPI extends stdClass{
|
||||||
$this->randomNonce = Utils::getRandomBytes(16, false);
|
$this->randomNonce = Utils::getRandomBytes(16, false);
|
||||||
$this->server->api->console->register("plugins", "", [$this, "commandHandler"]);
|
$this->server->api->console->register("plugins", "", [$this, "commandHandler"]);
|
||||||
$this->server->api->console->register("version", "", [$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("pl", "plugins");
|
||||||
$this->server->api->console->alias("ver", "version");
|
$this->server->api->console->alias("ver", "version");
|
||||||
$this->server->api->console->alias("about", "version");
|
$this->server->api->console->alias("about", "version");
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ class ServerAPI{
|
||||||
* @var TileAPI
|
* @var TileAPI
|
||||||
*/
|
*/
|
||||||
public $tile;
|
public $tile;
|
||||||
|
/**
|
||||||
|
* @var AchievementAPI
|
||||||
|
*/
|
||||||
|
public $achievement;
|
||||||
private $asyncCalls = [];
|
private $asyncCalls = [];
|
||||||
private $server;
|
private $server;
|
||||||
private $config;
|
private $config;
|
||||||
|
|
@ -144,7 +148,6 @@ class ServerAPI{
|
||||||
console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0);
|
console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0);
|
||||||
|
|
||||||
$this->loadProperties();
|
$this->loadProperties();
|
||||||
|
|
||||||
$this->loadAPI("console", "ConsoleAPI");
|
$this->loadAPI("console", "ConsoleAPI");
|
||||||
$this->loadAPI("level", "LevelAPI");
|
$this->loadAPI("level", "LevelAPI");
|
||||||
$this->loadAPI("block", "BlockAPI");
|
$this->loadAPI("block", "BlockAPI");
|
||||||
|
|
@ -155,6 +158,7 @@ class ServerAPI{
|
||||||
$this->loadAPI("player", "PlayerAPI");
|
$this->loadAPI("player", "PlayerAPI");
|
||||||
$this->loadAPI("time", "TimeAPI");
|
$this->loadAPI("time", "TimeAPI");
|
||||||
$this->loadAPI("queryAPI", "QueryAPI");
|
$this->loadAPI("queryAPI", "QueryAPI");
|
||||||
|
$this->loadAPI("achievement", "AchievementAPI");
|
||||||
foreach($this->apiList as $ob){
|
foreach($this->apiList as $ob){
|
||||||
if(is_callable([$ob, "init"])){
|
if(is_callable([$ob, "init"])){
|
||||||
$ob->init(); //Fails sometimes!!!
|
$ob->init(); //Fails sometimes!!!
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class Utils{
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
public static function getSign($v){
|
public static function getSign($v){
|
||||||
return $v > 0 ? 1 : ($v < 0 ? -1 : 0);
|
return $v > 0 ? 1 : ($v < 0 ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +48,10 @@ class Utils{
|
||||||
return floor(($v % 360 + 360) % 360);
|
return floor(($v % 360 + 360) % 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> 1042e025 (look player achievements, moved method cmdWhitelist to ConsoleAPI(marked as deprecated in BanAPI to avoid losing compability with old pmmp plugins))
|
||||||
public static function hasEmoji($s){
|
public static function hasEmoji($s){
|
||||||
return preg_match(Utils::emojiRegex, $s, $matches);
|
return preg_match(Utils::emojiRegex, $s);
|
||||||
}
|
}
|
||||||
public static function getCallableIdentifier(callable $variable){
|
public static function getCallableIdentifier(callable $variable){
|
||||||
if(is_array($variable)){
|
if(is_array($variable)){
|
||||||
|
|
@ -81,6 +84,7 @@ class Utils{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getUniqueID($raw = false, $extra = ""){
|
public static function getUniqueID($raw = false, $extra = ""){
|
||||||
$machine = php_uname("a");
|
$machine = php_uname("a");
|
||||||
$machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : "";
|
$machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : "";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue