Skip to content

Commit

Permalink
feat: setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Josscoder committed Jan 6, 2025
0 parents commit 11a2953
Show file tree
Hide file tree
Showing 17 changed files with 777 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build

on:
push:
branches:
- master

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Startup
uses: actions/checkout@v3

- name: Download PHP Release
uses: dsaltares/fetch-gh-release-asset@1.1.0
with:
file: PHP-Linux-x86_64-PM5.tar.gz
repo: NetherGamesMC/php-build-scripts
version: "tags/php-8.2-latest"

- name: Unpack PHP Release
run: tar -xzvf PHP-Linux-x86_64-PM5.tar.gz

- name: Download Composer
run: curl -o composer.phar "https://getcomposer.org/composer-stable.phar"

- name: Config Composer
run: ./bin/php7/bin/php composer.phar config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

- name: Install Composer dependencies
run: ./bin/php7/bin/php composer.phar install --prefer-dist --no-interaction

- name: Run Build
run: ./bin/php7/bin/php -dphar.readonly=0 vendor/bin/pharynx -i . -c -p=GlassBridge.phar

- name: Get plugin.yml information
run: |
name=$(grep -oP '(?<=name: ).*' plugin.yml || echo "unknown")
version=$(grep -oP '(?<=version: ).*' plugin.yml || echo "unknown")
echo "Name of plugin: $name"
echo "Version of plugin: $version"
echo "PLUGIN_NAME=$name" >> $GITHUB_ENV
echo "PLUGIN_VERSION=$version" >> $GITHUB_ENV
- name: Create Release
uses: ncipollo/release-action@v1.14.0
with:
artifacts: ${{ github.workspace }}/Snow.phar
draft: false
name: ${{ env.PLUGIN_NAME }} v${{ env.PLUGIN_VERSION }} Release
tag: v${{ env.PLUGIN_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
body: "The artifacts are kept up to date with the master branch"
commit: ${{ github.sha }}
allowUpdates: true
removeArtifacts: true
replacesArtifacts: true
35 changes: 35 additions & 0 deletions .github/workflows/phpstan-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PHPStan CI

on: push

jobs:
phpstan:
name: PHPStan Analysis
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"

steps:
- name: Startup
uses: actions/checkout@v3

- name: Download PHP Release
uses: dsaltares/fetch-gh-release-asset@1.1.0
with:
file: PHP-Linux-x86_64-PM5.tar.gz
repo: NetherGamesMC/php-build-scripts
version: "tags/php-8.2-latest"

- name: Unpack PHP Release
run: tar -xzvf PHP-Linux-x86_64-PM5.tar.gz

- name: Download Composer
run: curl -o composer.phar "https://getcomposer.org/composer-stable.phar"

- name: Config Composer
run: ./bin/php7/bin/php composer.phar config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

- name: Install Composer dependencies
run: ./bin/php7/bin/php composer.phar install --prefer-dist --no-interaction

- name: Run PHPStan
run: ./bin/php7/bin/php vendor/bin/phpstan.phar analyze --no-progress
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
/.idea
/composer.lock
/*.phar
38 changes: 38 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "josscoder/glass-bridge",
"type": "pocketmine-plugin",
"autoload": {
"classmap": [
"src/"
]
},
"authors": [
{
"name": "Josscoder",
"email": "josscoder@hotmail.com"
}
],
"minimum-stability": "dev",
"require": {
"blockbrawn/commando": "dev-master"
},
"require-dev": {
"nethergamesmc/pocketmine-mp": "dev-stable",
"sof3/pharynx": "dev-master",
"phpstan/phpstan": "1.12.7"
},
"repositories": [
{
"type": "vcs",
"url": "git@github.com:NetherGamesMC/PocketMine-MP.git"
}
],
"scripts": {
"lint": [
"./vendor/bin/phpstan analyse --no-progress"
],
"build": [
"@php -dphar.readonly=0 ./vendor/bin/pharynx -i . -c -p=GlassBridge.phar"
]
}
}
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 9
paths:
- src/GlassBridge
10 changes: 10 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: GlassBridge
main: GlassBridge\GlassBridgePlugin
authors:
- Josscoder
version: 1.0.0-ALPHA
api: 5.17.0

permissions:
glassbridge.command:
default: op
48 changes: 48 additions & 0 deletions src/GlassBridge/GlassBridgePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace GlassBridge;

use CortexPE\Commando\exception\HookAlreadyRegistered;
use CortexPE\Commando\PacketHooker;
use GlassBridge\command\GlassBridgeCommand;
use GlassBridge\listener\GlassBridgeListener;
use GlassBridge\listener\GlassEditListener;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\SingletonTrait;
use pocketmine\utils\TextFormat;

class GlassBridgePlugin extends PluginBase
{
use SingletonTrait {
setInstance as private;
reset as private;
}

protected function onLoad(): void
{
self::setInstance($this);
}

/**
* @throws HookAlreadyRegistered
*/
protected function onEnable(): void
{
if (!PacketHooker::isRegistered()) {
PacketHooker::register($this);
}

$pluginManager = $this->getServer()->getPluginManager();
$pluginManager->registerEvents(new GlassBridgeListener(), $this);
$pluginManager->registerEvents(new GlassEditListener(), $this);

$this->getServer()->getCommandMap()->register('glassbridge', new GlassBridgeCommand($this, 'glassbridge'));

$this->getLogger()->info(TextFormat::GREEN . 'SquidGame Glass Bridge plugin enabled');
}

protected function onDisable(): void
{
$this->getLogger()->info(TextFormat::RED . 'SquidGame Glass Bridge plugin disabled');
}
}
45 changes: 45 additions & 0 deletions src/GlassBridge/command/GlassBridgeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace GlassBridge\command;

use CortexPE\Commando\BaseCommand;
use GlassBridge\command\subcommands\AddGlassSectionSubCommand;
use GlassBridge\command\subcommands\EditGlassSectionSubCommand;
use GlassBridge\command\subcommands\RemoveGlassSectionSubCommand;
use GlassBridge\GlassBridgePlugin;
use pocketmine\command\CommandSender;
use pocketmine\plugin\Plugin;

class GlassBridgeCommand extends BaseCommand
{
/**
* @var GlassBridgePlugin
*/
protected Plugin $plugin;

protected function prepare(): void
{
$this->registerSubCommand(new AddGlassSectionSubCommand($this->plugin,
'add',
'Adds a new section of glass'
));
$this->registerSubCommand(new RemoveGlassSectionSubCommand($this->plugin,
'remove',
'Removes a section of glass'
));
$this->registerSubCommand(new EditGlassSectionSubCommand($this->plugin,
'edit',
'Edit a section of glass'
));

$this->setPermission('glassbridge.command');
}

/**
* @param CommandSender $sender
* @param string $aliasUsed
* @param array<string, mixed> $args
* @return void
*/
public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {}
}
49 changes: 49 additions & 0 deletions src/GlassBridge/command/subcommands/AddGlassSectionSubCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace GlassBridge\command\subcommands;

use CortexPE\Commando\args\IntegerArgument;
use CortexPE\Commando\BaseSubCommand;
use CortexPE\Commando\constraint\InGameRequiredConstraint;
use CortexPE\Commando\exception\ArgumentOrderException;
use GlassBridge\data\GlassBridge;
use GlassBridge\data\GlassSection;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;

class AddGlassSectionSubCommand extends BaseSubCommand
{
/**
* @throws ArgumentOrderException
*/
protected function prepare(): void
{
$this->registerArgument(0, new IntegerArgument('index'));
$this->addConstraint(new InGameRequiredConstraint($this));
$this->setUsage('/glassbridge add <index>');
}

/**
* @param Player $sender
* @param string $aliasUsed
* @param array<string, mixed> $args
* @return void
*/
public function onRun(CommandSender $sender, string $aliasUsed, array $args): void
{
/** @var int $index */
$index = $args['index'];

if (GlassBridge::getInstance()->exists($index)) {
$sender->sendMessage(TextFormat::RED . 'That section of the glass bridge already exists!');

return;
}

GlassBridge::getInstance()->addSection(new GlassSection($index, null, null));

$sender->sendMessage(TextFormat::colorize("&aYou have created the glass bridge section &e#$index&a!"));
$sender->sendMessage(TextFormat::colorize("&bNow use &6/glassbridge edit <index> &bto set the &6firstGlass &band the &6secondGlass"));
}
}
58 changes: 58 additions & 0 deletions src/GlassBridge/command/subcommands/EditGlassSectionSubCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace GlassBridge\command\subcommands;

use CortexPE\Commando\args\IntegerArgument;
use CortexPE\Commando\BaseSubCommand;
use CortexPE\Commando\constraint\InGameRequiredConstraint;
use CortexPE\Commando\exception\ArgumentOrderException;
use GlassBridge\data\GlassBridge;
use GlassBridge\data\GlassSection;
use GlassBridge\registry\GlassEditManager;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;

class EditGlassSectionSubCommand extends BaseSubCommand
{
/**
* @throws ArgumentOrderException
*/
protected function prepare(): void
{
$this->registerArgument(0, new IntegerArgument('index'));
$this->addConstraint(new InGameRequiredConstraint($this));
$this->setUsage('/glassbridge edit <index>');
}

/**
* @param Player $sender
* @param string $aliasUsed
* @param array<string, mixed> $args
* @return void
*/
public function onRun(CommandSender $sender, string $aliasUsed, array $args): void
{
/** @var int $index */
$index = $args['index'];

if (is_null($glassSection = GlassBridge::getInstance()->getSection($index))) {
$sender->sendMessage(TextFormat::RED . 'That section of the glass bridge does not exist!');

return;
}

if (GlassEditManager::getInstance()->exists($sender)) {
$sender->sendMessage(TextFormat::RED . 'You are already editing another glass section, finish editing to edit another one!');

return;
}

$glassSection->setFirstGlass(null);
$glassSection->setSecondGlass(null);

GlassEditManager::getInstance()->addEditor($sender, $glassSection);
$sender->sendMessage(TextFormat::colorize("&aYou are editing the glass section &e#$index&a!"));
$sender->sendMessage(TextFormat::GOLD . "-> break the first glass's minVector");
}
}
Loading

0 comments on commit 11a2953

Please sign in to comment.