Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
v2.0 (#2)
Browse files Browse the repository at this point in the history
* v2.0

* v2.0

* v2.0

* v2.0

* v2.0

* v2.0
  • Loading branch information
Infernus101 authored Oct 13, 2017
1 parent bbce53c commit 5fee3a3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ProfileUI
author: Infernus101
api: [2.0.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3, 3.0.0-ALPHA4, 3.0.0-ALPHA5, 3.0.0-ALPHA6, 3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9]
main: Infernus101\Main
version: 1.0
version: 2.0
commands:
profile:
description: Player profile UI!
description: Player profile UI!
13 changes: 13 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
### CONFIG - Infernus101###
# show player's rank? 0 to disable, only pureperms support
rank: 1
# show player's money? 0 to disable, only economy by onebone support
money: 1
# show player's faction? 0 to disable, only FactionsPro by tethered support
faction: 1
# show player's first joined? 0 to disable
first-played: 1
# show player's last seen? 0 to disable
last-seen: 1
...
10 changes: 9 additions & 1 deletion src/Infernus101/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@

use Infernus101\window\Handler;
use pocketmine\Player;
use pocketmine\OfflinePlayer;
use pocketmine\Server;
use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\command\Command;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\utils\Config;
use pocketmine\utils\TextFormat;

class Main extends PluginBase implements Listener {

public function onEnable(){
$this->getServer()->getLogger()->notice("[ProfielUI] Enabled! - By Infernus101");
$file = "config.yml";
if(!file_exists($this->getDataFolder() . $file)){
@mkdir($this->getDataFolder());
file_put_contents($this->getDataFolder() . $file, $this->getResource($file));
}
$this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML);
}

public function onDisable(){
Expand All @@ -34,7 +42,7 @@ public function onCommand(CommandSender $sender, Command $cmd, String $label, ar
return false;
}
$noob = $this->getServer()->getOfflinePlayer($args[0]);
if(!$noob instanceof Player){
if(!$noob instanceof OfflinePlayer and !$noob instanceof Player){
$sender->sendMessage(TextFormat::RED."> Player not found!");
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Infernus101/window/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class Handler {
ProfileWindow::class,
];

public function getWindowJson(int $windowId, Main $loader, Player $player, Player $args): string {
public function getWindowJson(int $windowId, Main $loader, Player $player, $args): string {
return $this->getWindow($windowId, $loader, $player, $args)->getJson();
}

public function getWindow(int $windowId, Main $loader, Player $player, Player $args): Window {
public function getWindow(int $windowId, Main $loader, Player $player, $args): Window {
if(!isset($this->types[$windowId])) {
throw new \OutOfBoundsException("Tried to get window of non-existing window ID.");
}
Expand All @@ -39,4 +39,4 @@ public function getWindowIdFor(int $windowId): int {
}
return 4000 + $windowId;
}
}
}
60 changes: 58 additions & 2 deletions src/Infernus101/window/ProfileWindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,69 @@

class ProfileWindow extends Window {
public function process(): void {
$flag = true;
$name = $this->args->getName();
$manager = $this->pl->getServer()->getPluginManager();
if($this->pl->config->get("rank") == 1){
$pp = $manager->getPlugin("PurePerms");
$rank = $pp->getUserDataMgr()->getGroup($this->args)->getName();
}
if($this->pl->config->get("money") == 1){
$eco = $manager->getPlugin("EconomyAPI");
$money = $eco->myMoney($name);
}
if($this->pl->config->get("faction") == 1){
$f = $manager->getPlugin("FactionsPro");
if($f->isInFaction($name)){
$fac = $f->getPlayerFaction($name);
}
else{
$fac = '-';
}
}
if($this->pl->config->get("last-seen") == 1){
if($this->args instanceof Player){
$status = 'Online';
$flag = true;
}
else{
$status = 'Offline';
$date = date("l, F j, Y", ($last = $this->args->getLastPlayed() / 1000));
$time = date("h:ia", $last);
$flag = false;
}
}
if($this->pl->config->get("first-played") == 1){
$date2 = date("l, F j, Y", ($first = $this->args->getFirstPlayed() / 1000));
$time2 = date("h:ia", $first);
}
$this->data = [
"type" => "custom_form",
"title" => "§e$name"."'s Profile",
"title" => TextFormat::AQUA."$name"."'s Profile",
"content" => []
];
$this->data["content"][] = ["type" => "label", "text" => "Name: $name"];
if($this->pl->config->get("rank") == 1){
$this->data["content"][] = ["type" => "label", "text" => "Rank: $rank"];
}
if($this->pl->config->get("money") == 1){
$this->data["content"][] = ["type" => "label", "text" => "Money: $money"];
}
if($this->pl->config->get("faction") == 1){
$this->data["content"][] = ["type" => "label", "text" => "Faction: $fac"];
}
if($this->pl->config->get("first-played") == 1){
$this->data["content"][] = ["type" => "label", "text" => "First Played: $date2 at $time2"];
}
if($this->pl->config->get("last-seen") == 1){
if($flag == true){
$this->data["content"][] = ["type" => "label", "text" => "Status: $status"];
}
if($flag == false){
$this->data["content"][] = ["type" => "label", "text" => "Status: $status"];
$this->data["content"][] = ["type" => "label", "text" => "Last seen: $date at $time"];
}
}
}
private function select($index){
$handler = new Handler();
Expand All @@ -29,4 +85,4 @@ public function handle(ModalFormResponsePacket $packet): bool {
$this->select($index);
return true;
}
}
}
6 changes: 3 additions & 3 deletions src/Infernus101/window/Window.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class Window {
protected $args = null;
protected $data = [];

public function __construct(Main $pl, Player $player, Player $args) {
public function __construct(Main $pl, Player $player, $args) {
$this->pl = $pl;
$this->player = $player;
$this->args = $args;
Expand All @@ -38,7 +38,7 @@ public function getProfilePlayer(): Player {
return $this->args;
}

public function navigate(int $menu, Player $player, Handler $handler, Player $args): void {
public function navigate(int $menu, Player $player, Handler $handler, $args): void {
$packet = new ModalFormRequestPacket();
$packet->formId = $handler->getWindowIdFor($menu);
$packet->formData = $handler->getWindowJson($menu, $this->pl, $player, $args);
Expand All @@ -48,4 +48,4 @@ public function navigate(int $menu, Player $player, Handler $handler, Player $ar
protected abstract function process(): void;

public abstract function handle(ModalFormResponsePacket $packet): bool;
}
}

0 comments on commit 5fee3a3

Please sign in to comment.