├── LICENSE
├── README.md
├── assets
├── list.png
└── sidebar.png
├── plugin.yml
└── src
└── Saisana299
└── easyscoreboardapi
├── EasyScoreboardAPI.php
└── EventListener.php
/LICENSE:
--------------------------------------------------------------------------------
1 | University of Illinois/NCSA
2 | Open Source License
3 |
4 | Copyright (c) 2019 Saisana299. All rights reserved.
5 |
6 | Developed by: Saisana299
7 | https://github.com/Saisana299
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of
10 | this software and associated documentation files (the "Software"), to deal with
11 | the Software without restriction, including without limitation the rights to
12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13 | of the Software, and to permit persons to whom the Software is furnished to do
14 | so, subject to the following conditions:
15 |
16 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
17 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.
18 | * Neither the names of Saisana299 nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
26 | SOFTWARE.
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EasyScoreboardAPI
2 | [](https://github.com/Saisana299/EasyScoreboardAPI/blob/master/LICENSE)
3 | [](https://github.com/Saisana299/EasyScoreboardAPI/releases/tag/v1.2.1)
4 | EasyScoreboardAPIは指定したプレイヤーにスコアボードを表示させることができるAPIです
5 |
6 | ### 対応状況
7 | - [x] sidebar
8 | - [x] list
9 | - [ ] belowname `※1`
10 |
11 | ### ダウンロード
12 | ダウンロードはこちら [Download](https://github.com/Saisana299/EasyScoreboardAPI/releases/tag/v1.2.1)
13 |
14 | ### 使い方
15 | ##### ・必須Use文
16 | ```php
17 | use Saisana299\easyscoreboardapi\EasyScoreboardAPI;
18 | ```
19 | ___
20 | ##### ・スコアボードを作成しプレイヤーに送信
21 | ```php
22 | $api = EasyScoreboardAPI::getInstance();
23 | $api->sendScoreboard($player, $displaySlot, $displayName, $sortOrder);
24 | ```
25 | |変数名|入れる値|説明|
26 | |:--:|:--:|:--:|
27 | |$player|Playerオブジェクト|スコアボードを表示するプレイヤー|
28 | |$displaySlot|`"sidebar"` or `"list"`|スコアボードを表示する場所|
29 | |$displayName|文字列|スコアボードに表示する文字|
30 | |$sortOrder|`true` or `false`|スコアの並び順です (true=降順、false=昇順)|
31 | ___
32 | ##### ・プレイヤーにスコアを表示、スコアの更新
33 | ```php
34 | $api = EasyScoreboardAPI::getInstance();
35 | $api->setScore($player, $displaySlot, $message, $score, $scoreboardId);
36 | ```
37 | |変数名|入れる値|説明|
38 | |:--:|:--:|:--:|
39 | |$player|Playerオブジェクト|スコアを表示するプレイヤー|
40 | |$displaySlot|`"sidebar"` or `"list"`|スコアボードを表示した場所|
41 | |$message|文字列|スコア名|
42 | |$score|整数|スコア|
43 | |$scoreboardId|整数|スコアのID (任意の数字) `※2`|
44 | ___
45 | ##### ・プレイヤーにプレイヤースコアを表示、プレイヤースコアの更新
46 | ※listのみ表示できます(sidebarには表示できません)
47 | ```php
48 | $api = EasyScoreboardAPI::getInstance();
49 | $api->setPlayerScore($player, $player2, $score, $scoreboardId);
50 | ```
51 | |変数名|入れる値|説明|
52 | |:--:|:--:|:--:|
53 | |$player|Playerオブジェクト|プレイヤースコアを表示するプレイヤー|
54 | |$player2|Playerオブジェクト|スコア (プレイヤー)|
55 | |$score|整数|スコア|
56 | |$scoreboardId|整数|スコアのID (任意の数字) `※2`|
57 | ___
58 | ##### ・プレイヤーに表示したスコアを消去
59 | ```php
60 | $api = EasyScoreboardAPI::getInstance();
61 | $api->removeScore($player, $displaySlot, $scoreboardId);
62 | ```
63 | |変数名|入れる値|説明|
64 | |:--:|:--:|:--:|
65 | |$player|Playerオブジェクト|表示したスコアを消去するプレイヤー|
66 | |$displaySlot|`"sidebar"` or `"list"`|スコアボードを表示した場所|
67 | |$scoreboardId|整数|スコアのID (任意の数字) `※2`|
68 | ___
69 | ##### ・プレイヤーに表示したスコアボードを消去
70 | ```php
71 | $api = EasyScoreboardAPI::getInstance();
72 | $api->deleteScoreboard($player, $displaySlot);
73 | ```
74 | |変数名|入れる値|説明|
75 | |:--:|:--:|:--:|
76 | |$player|Playerオブジェクト|表示したスコアボードを消去するプレイヤー|
77 | |$displaySlot|`"sidebar"` or `"list"`|スコアボードを表示した場所|
78 | ___
79 | ##### ・プレイヤーがスコアボードを表示しているか確認
80 | 返り値が true= 表示されている、false= 表示されていない。
81 | ```php
82 | $api = EasyScoreboardAPI::getInstance();
83 | $api->hasScoreboard($player, $displaySlot);
84 | ```
85 | |変数名|入れる値|説明|
86 | |:--:|:--:|:--:|
87 | |$player|Playerオブジェクト|確認するプレイヤー|
88 | |$displaySlot|`"sidebar"` or `"list"`|スコアボードの表示場所|
89 | ___
90 | ##### ・スコアボードを表示している全プレイヤーを取得
91 | 配列を返します。
92 | ```php
93 | $api = EasyScoreboardAPI::getInstance();
94 | $api->getScoreboardPlayers($displaySlot);
95 | ```
96 | |変数名|入れる値|説明|
97 | |:--:|:--:|:--:|
98 | |$displaySlot|`"sidebar"` or `"list"`|スコアボードの表示場所|
99 | ___
100 | ### 注釈
101 | `※1` --- パケット名が不明なため保留中
102 | `※2` --- スコアのIDは好きな数字を入れてください
103 | ```php
104 | $api = EasyScoreboardAPI::getInstance();
105 | $api->setScore($player, "sidebar", "TEST", 1, 1);
106 | $api->setScore($player, "sidebar", "TEST2", 1, 1);
107 | ```
108 | この場合スコアIDが両方1なので、後からsetScoreしたものが表示されます(TEST2)
109 | スコア名が同じだった場合も一番最後にsetScoreしたものが表示されます。
110 |
111 | ※使えば分かると思います
112 | ___
113 |
114 | ### 使用例
115 | ##### sidebarに表示
116 | ```php
117 | //$playerはSaisana299
118 | $api = EasyScoreboardAPI::getInstance();
119 | $api->sendScoreBoard($player, "sidebar", "TEST", false);
120 | $api->setScore($player, "sidebar", "時間 ", 111, 1);
121 | ```
122 | とすると...
123 |
124 | ___
125 |
126 | #### listに表示
127 | ```php
128 | //$playerはSaisana299
129 | $api = EasyScoreboardAPI::getInstance();
130 | $api->sendScoreBoard($player, "list", "TEST", false);
131 | $api->setPlayerScore($player, $player, 1, 1);
132 | $api->setScore($player,"list", "時間", 111, 2);
133 | ```
134 | とすると...
135 |
136 |
--------------------------------------------------------------------------------
/assets/list.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Saisana299/EasyScoreboardAPI/fcb7974ea730a44ba302dd22b3457c25284e28c8/assets/list.png
--------------------------------------------------------------------------------
/assets/sidebar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Saisana299/EasyScoreboardAPI/fcb7974ea730a44ba302dd22b3457c25284e28c8/assets/sidebar.png
--------------------------------------------------------------------------------
/plugin.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: EasyScoreboardAPI
3 | main: Saisana299\easyscoreboardapi\EasyScoreboardAPI
4 | version: 1.2.1
5 | api:
6 | - 3.5.0
7 | load: POSTWORLD
8 | author: Saisana299
9 | authors: [PawarenessC]
10 | description: 簡単なスコアボードのAPI
11 | ...
12 |
--------------------------------------------------------------------------------
/src/Saisana299/easyscoreboardapi/EasyScoreboardAPI.php:
--------------------------------------------------------------------------------
1 | getLogger()->info("§eEasy§aScore§bBoard§cAPI§fを読み込みました");
30 | if (!file_exists($this->getDataFolder())) mkdir($this->getDataFolder(), 0744, true);
31 | $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
32 | self::$instance = $this;
33 | }
34 |
35 | public function allremove(string $name){
36 | if(isset(self::$sidebar[$name])){
37 | unset(self::$sidebar[$name]);
38 | }
39 | if(isset(self::$list[$name])){
40 | unset(self::$list[$name]);
41 | }
42 | }
43 |
44 | //以下API
45 |
46 | /**
47 | * スコアボードを作成し、プレイヤーに表示します
48 | *
49 | * @param Player $player
50 | * @param string $displaySlot [スコアボードの表示場所 (sidebar, list)]
51 | * @param string $displayName [スコアボードの表示名]
52 | * @param boolean $sortOrder [並び順 (true = スコアが多い順 | false = スコアが少ない順)]
53 | */
54 | public function sendScoreboard(Player $player, string $displaySlot, string $displayName, bool $sortOrder): void{
55 |
56 | if($displaySlot !== "sidebar" && $displaySlot !== "list"){
57 | return;
58 | }
59 |
60 | if($displaySlot === "sidebar"){
61 | if(isset(self::$sidebar[$player->getName()])){
62 | self::deleteScoreboard($player,$displaySlot);
63 | }
64 | }elseif($displaySlot === "list"){
65 | if(isset(self::$list[$player->getName()])){
66 | self::deleteScoreboard($player,$displaySlot);
67 | }
68 | }
69 |
70 | if($sortOrder === true){
71 | $sortOrder = 1;
72 | }else{
73 | $sortOrder = 0;
74 | }
75 |
76 | $pk = new SetDisplayObjectivePacket();
77 | $pk->displaySlot = $displaySlot;
78 | $pk->objectiveName = $displaySlot;
79 | $pk->displayName = $displayName;
80 | $pk->criteriaName = "dummy";
81 | $pk->sortOrder = $sortOrder;
82 | $player->sendDataPacket($pk);
83 |
84 | if($displaySlot === "sidebar"){
85 | self::$sidebar[$player->getName()] = true;
86 | }elseif($displaySlot === "list"){
87 | self::$list[$player->getName()] = true;
88 | }
89 | }
90 |
91 | /**
92 | * プレイヤーに表示されているスコアボードを消去します
93 | *
94 | * @param Player $player
95 | * @param string $displaySlot [スコアボードの表示場所 (sidebar, list)]
96 | */
97 | public function deleteScoreboard(Player $player, string $displaySlot): void{
98 |
99 | if($displaySlot !== "sidebar" && $displaySlot !== "list"){
100 | return;
101 | }
102 |
103 | $pk = new RemoveObjectivePacket();
104 | $pk->objectiveName = $displaySlot;
105 | $player->sendDataPacket($pk);
106 |
107 | if($displaySlot === "sidebar"){
108 | if(isset(self::$sidebar[$player->getName()])){
109 | unset(self::$sidebar[$player->getName()]);
110 | }
111 | }elseif($displaySlot === "list"){
112 | if(isset(self::$list[$player->getName()])){
113 | unset(self::$list[$player->getName()]);
114 | }
115 | }
116 | }
117 |
118 | /**
119 | * プレイヤーのスコアボードにスコアを追加・更新します
120 | *
121 | * @param Player $player
122 | * @param string $displaySlot [スコアボードの表示場所 (sidebar, list)]
123 | * @param string $message [スコアの名前]
124 | * @param int $score [スコア]
125 | * @param int $scoreboardId [スコアのID (任意の数字)]
126 | */
127 | public function setScore(Player $player, string $displaySlot, string $message, int $score, int $scoreboardId): void{
128 |
129 | if($displaySlot !== "sidebar" && $displaySlot !== "list"){
130 | return;
131 | }
132 |
133 | if($displaySlot === "sidebar"){
134 | if(!isset(self::$sidebar[$player->getName()])){
135 | return;
136 | }
137 | }elseif($displaySlot === "list"){
138 | if(!isset(self::$list[$player->getName()])){
139 | return;
140 | }
141 | }
142 |
143 | $entry = new ScorePacketEntry();
144 | $entry->objectiveName = $displaySlot;
145 | $entry->type = $entry::TYPE_FAKE_PLAYER;
146 | $entry->customName = $message;
147 | $entry->score = $score;
148 | $entry->scoreboardId = $scoreboardId;
149 |
150 | $pk = new SetScorePacket();
151 | $pk->type = $pk::TYPE_CHANGE;
152 | $pk->entries[] = $entry;
153 | $player->sendDataPacket($pk);
154 | }
155 |
156 | /**
157 | * プレイヤーのスコアボードにプレイヤースコアを追加・更新します
158 | *
159 | * @param Player $player
160 | * @param Player $player2 [プレイヤースコア]
161 | * @param int $score [スコア]
162 | * @param int $scoreboardId [スコアのID (任意の数字)]
163 | */
164 | public function setPlayerScore(Player $player, Player $player2, int $score, int $scoreboardId): void{
165 |
166 | if(!isset(self::$list[$player->getName()])){
167 | return;
168 | }
169 |
170 | $entry = new ScorePacketEntry();
171 | $entry->objectiveName = "list";
172 | $entry->type = $entry::TYPE_PLAYER;
173 | $entry->entityUniqueId = $player2->getId();
174 | $entry->score = $score;
175 | $entry->scoreboardId = $scoreboardId;
176 |
177 | $pk = new SetScorePacket();
178 | $pk->type = $pk::TYPE_CHANGE;
179 | $pk->entries[] = $entry;
180 | $player->sendDataPacket($pk);
181 | }
182 |
183 | /**
184 | * プレイヤーのスコアボードのスコアを消去します
185 | *
186 | * @param Player $player
187 | * @param string $displaySlot [スコアボードの表示場所 (sidebar, list)]
188 | * @param int $scoreboardId [スコアのID]
189 | */
190 | public function removeScore(Player $player, string $displaySlot, int $scoreboardId): void{
191 |
192 | if($displaySlot !== "sidebar" && $displaySlot !== "list"){
193 | return;
194 | }
195 |
196 | if($displaySlot === "sidebar"){
197 | if(!isset(self::$sidebar[$player->getName()])){
198 | return;
199 | }
200 | }elseif($displaySlot === "list"){
201 | if(!isset(self::$list[$player->getName()])){
202 | return;
203 | }
204 | }
205 |
206 | $entry = new ScorePacketEntry();
207 | $entry->objectiveName = $displaySlot;
208 | $entry->scoreboardId = $scoreboardId;
209 |
210 | $pk = new SetScorePacket();
211 | $pk->type = $pk::TYPE_REMOVE;
212 | $pk->entries[] = $entry;
213 | $player->sendDataPacket($pk);
214 | }
215 |
216 | /**
217 | * プレイヤーがスコアボードを表示しているかを確認します
218 | *
219 | * @param Player $player
220 | * @param string $displaySlot [スコアボードの表示場所 (sidebar, list)]
221 | */
222 | public function hasScoreboard(Player $player, string $displaySlot): bool{
223 | if($displaySlot === "sidebar"){
224 | return (isset(self::$sidebar[$player->getName()])) ? true : false;
225 | }elseif($displaySlot === "list"){
226 | return (isset(self::$list[$player->getName()])) ? true : false;
227 | }
228 | return false;
229 | }
230 |
231 | /**
232 | * スコアボードを表示している全プレイヤーを取得
233 | *
234 | * @param string $displaySlot [スコアボードの表示場所 (sidebar, list)]
235 | */
236 | public function getScoreboardPlayers(string $displaySlot): array{
237 | if($displaySlot === "sidebar"){
238 | return self::$sidebar;
239 | }elseif($displaySlot === "list"){
240 | return self::$list;
241 | }
242 | return false;
243 | }
244 |
245 | }
246 |
--------------------------------------------------------------------------------
/src/Saisana299/easyscoreboardapi/EventListener.php:
--------------------------------------------------------------------------------
1 | EasyScoreboardAPI = $EasyScoreboardAPI;
17 | }
18 |
19 | public function onQuit(PlayerQuitEvent $event){
20 | $name = $event->getPlayer()->getName();
21 | $this->EasyScoreboardAPI->allremove($name);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------