Skip to content

Instantly share code, notes, and snippets.

View PJZ9n's full-sized avatar
🏠
Working from home

PJZ9n PJZ9n

🏠
Working from home
View GitHub Profile
@PJZ9n
PJZ9n / zip.php
Created August 4, 2020 10:57
zipをpharから読み出すテスト
<?php
//phar://path/to/resources/test.zip
$path = $this->getFile() . "resources/test.zip";
echo "path: ";
var_dump($path);
//本当にファイルが存在するのかの確認
echo "content-length10(base64): ";
var_dump(base64_encode(substr(file_get_contents($path), 0, 10)));
//zip
$zip = new \ZipArchive();
@PJZ9n
PJZ9n / いろいろしたやつ.php
Created August 2, 2020 17:59
チェスト関連でいろいろしたやつ
<?php
/**
* Copyright (c) 2020 PJZ9n.
*
* This file is part of NewChestShop.
*
* NewChestShop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@PJZ9n
PJZ9n / config-with-static.php
Created August 1, 2020 10:11
メインクラスに静的なメンバ変数としてConfigを持つ
<?php
declare(strict_types=1);
use pocketmine\utils\Config;
class aClass
{
private static $config;
@PJZ9n
PJZ9n / private.php
Created August 1, 2020 10:00
メンバ変数のアクセス修飾子
<?php
declare(strict_types=1);
class aClass
{
private $hoge = "fuga";
}
class bClass
@PJZ9n
PJZ9n / AntiSpamBug.php
Created July 30, 2020 01:53
クライアントによるスパムバグを防ぐ
<?php
/**
* @name AntiSpamBug
* @version 1.0.0
* @main pjz9n\antispambug\AntiSpamBug
* @api 3.11.0
*/
declare(strict_types=1);
@PJZ9n
PJZ9n / chesttransaction.php
Last active July 23, 2020 20:11
チェストをプレイヤーが操作したことを検知する
<?php
public function on(InventoryTransactionEvent $event): void
{
$tra = $event->getTransaction();
if (count($tra->getActions()) !== 2) {
//TODO
return;
}
//プレイヤーの取得
$player = null;
@PJZ9n
PJZ9n / form-with-config.php
Created July 11, 2020 02:46
FormでもConfigを使う
<?php
declare(strict_types=1);
use pocketmine\form\Form;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
class Main extends PluginBase
@PJZ9n
PJZ9n / wctest.php
Created July 9, 2020 05:39
ワールドコピーのテスト
<?php
public function onEnable(): void
{
$name = "world-" . uniqid();
$this->copyWorld("world", $name);
$this->getServer()->loadLevel($name);
var_dump($this->getServer()->getLevelByName($name)->getId());
$this->func("test", function () {
@PJZ9n
PJZ9n / copytheworld.php
Last active July 9, 2020 02:31
ワールドをコピーする
<?php
/**
* ワールドをコピーする
*
* @param string $from コピー元ワールド名(ディレクトリ名)
* @param string $to コピー先ワールド名(ディレクトリ名)
*/
public function copyWorld(string $from, string $to): void
{
/** @var Plugin $this */
@PJZ9n
PJZ9n / hash.php
Created July 7, 2020 08:32
パスワードハッシュの例
<?php
//パスワードの登録例
$password = "Password";//登録するパスワード
var_dump($password);
$hash = password_hash($password, PASSWORD_DEFAULT);//ハッシュ化する
var_dump($hash);
//$hashの内容を保存しておく
//パスワードの検証例