mirror of
https://github.com/farcasclaudiu/QRcraft.git
synced 2026-06-22 07:01:17 +03:00
Init release
Init release
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
*.php text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.txt text eol=lf
|
||||
*.properties text eol=lf
|
||||
*.bat text eol=crlf
|
||||
*.cmd text eol=crlf
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
|
||||
+30
@@ -41,3 +41,33 @@ $RECYCLE.BIN/
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
players/*
|
||||
worlds/*
|
||||
plugins/*
|
||||
bin/*
|
||||
timings/*
|
||||
*.log
|
||||
*.txt
|
||||
*.phar
|
||||
server.properties
|
||||
pocketmine.yml
|
||||
|
||||
# Common IDEs
|
||||
.idea/*
|
||||
nbproject/*
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
/nbproject/private/
|
||||
|
||||
# Sphinx-doc
|
||||
/docs/build/
|
||||
!/docs/requirements.txt
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#QRcraft
|
||||
|
||||
Plugin for PocketMine-MP for creating QR panels (made from white an black wood blocks)
|
||||
|
||||
Copyright (C) 2014 Clodyx <https://github.com/farcasclaudiu/QRcraft>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
ONLY OPs during gameplay (creative preferable)
|
||||
* `/qr` - shows help page
|
||||
* `/qrt <url>` - test QR text/url to count number of needed blocks (NxN)
|
||||
* `/qrc <url> [Auto|horizontal|vertical]` - create QR panel/block
|
||||
* `/qrl` - list QR panels IDs
|
||||
* `/qrd <ID>` - delete a QR panel by ID
|
||||
* `/qrp <ID>` - teleport you nearby QR panel with specified ID
|
||||
|
||||
|
||||
## Configuration
|
||||
No configuration needed for this moment.
|
||||
|
||||
## Permissions
|
||||
|
||||
| Permission | Default | Description |
|
||||
| :---: | :---: | :--- |
|
||||
| clodyx.plugin.qrcraft | op | Allows using the QRcraft plugin functionality |
|
||||
|
||||
|
||||
|
||||
## Releases
|
||||
[1.0.0] - initial release
|
||||
+3314
File diff suppressed because it is too large
Load Diff
+29
@@ -0,0 +1,29 @@
|
||||
name: QRcraft
|
||||
version: 1.0.0
|
||||
api: 1.0.0
|
||||
main: clodyx\qrcraft\QRcraftPlugIn
|
||||
author: Clodyx
|
||||
description: QRcraft by Clodyx
|
||||
commands:
|
||||
qr:
|
||||
description: "Help page QRcraft"
|
||||
permission: clodyx.plugin.qrcraft
|
||||
qrt:
|
||||
description: "Test QR panel size"
|
||||
permission: clodyx.plugin.qrcraft
|
||||
qrc:
|
||||
description: "Create QR code panel"
|
||||
permission: clodyx.plugin.qrcraft
|
||||
qrl:
|
||||
description: "List QR panels IDs"
|
||||
permission: clodyx.plugin.qrcraft
|
||||
qrd:
|
||||
description: "delete QR panel by ID"
|
||||
permission: clodyx.plugin.qrcraft
|
||||
qrp:
|
||||
description: "teleport nearby QR panel by ID"
|
||||
permission: clodyx.plugin.qrcraft
|
||||
permissions:
|
||||
clodyx.plugin.qrcraft:
|
||||
description: "clodyx.plugin.qrcraft"
|
||||
default: op
|
||||
@@ -0,0 +1 @@
|
||||
#Configuration file for FirstPlugin plugin
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1000 B |
+165
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*QRcraft Command
|
||||
*
|
||||
* @author: Clodyx
|
||||
*
|
||||
*/
|
||||
|
||||
namespace clodyx\qrcraft;
|
||||
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\CommandExecutor;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
||||
class QRcraftCommand
|
||||
{
|
||||
|
||||
private $pgin;
|
||||
|
||||
public function __construct(QRcraftPlugIn $pg)
|
||||
{
|
||||
$this->pgin = $pg;
|
||||
}
|
||||
|
||||
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
|
||||
{
|
||||
$cmd = strtolower($command->getName());
|
||||
if ($sender instanceof Player) {
|
||||
$player = $sender->getPlayer();
|
||||
|
||||
switch ($cmd) {
|
||||
case "qr":
|
||||
$this->showusage($sender);
|
||||
break;
|
||||
case "qrt":
|
||||
if (isset ($args [0])) {
|
||||
$url = $args[0];
|
||||
$size = QRhelper::TestQRCode(true, $url);
|
||||
$sender->sendMessage("QR panel for '$url' will need " . $size . "x" . $size . " blocks");
|
||||
} else {
|
||||
$this->showusage($sender);
|
||||
}
|
||||
break;
|
||||
case "qrc":
|
||||
if (isset ($args [0])) {
|
||||
$url = $args[0];
|
||||
$orientation = isset ($args [1]) ? strtolower($args[1]) : "a";//a - auto
|
||||
$allor = array("h", "v", "a");
|
||||
if (!in_array($orientation, $allor)) {
|
||||
$this->showusage($sender);
|
||||
} else {
|
||||
QRhelper::MarkPlayerCanCreateQR($this->pgin, $player, $url, $orientation);
|
||||
}
|
||||
} else {
|
||||
$this->showusage($sender);
|
||||
}
|
||||
break;
|
||||
case "qrl":
|
||||
if (!isset($this->pgin->qrlist) || count($this->pgin->qrlist) == 0) {
|
||||
$player->sendMessage("QR panels list is empty!");
|
||||
} else {
|
||||
$player->sendMessage("--------------");
|
||||
$player->sendMessage("QR LIST");
|
||||
$player->sendMessage("--------------");
|
||||
foreach ($this->pgin->qrlist as $li) {
|
||||
$liId = $li[0];
|
||||
$liText = $li[1];
|
||||
$liSize = $li[2];
|
||||
$coord = $li[3];
|
||||
$liCoord = "x:" . $coord[0] . "-y:" . $coord[1] . "-z:" . $coord[2];//implode("-",$li[3]);
|
||||
$player->sendMessage("[$liId] '$liText' ($liSize) $liCoord");
|
||||
}
|
||||
$player->sendMessage("--------------");
|
||||
}
|
||||
break;
|
||||
case "qrd":
|
||||
if (!isset($this->pgin->qrlist) || count($this->pgin->qrlist) == 0) {
|
||||
$player->sendMessage("QR panel list is empty!");
|
||||
} else {
|
||||
if (isset ($args [0])) {
|
||||
$idToDelete = $args[0];
|
||||
$wasDeleted = false;
|
||||
foreach ($this->pgin->qrlist as $li) {
|
||||
if ($idToDelete == $li[0]) {
|
||||
//delete in world (fill with air)
|
||||
$coord = $li[3];
|
||||
QRhelper::FillWithAir($player->level, $coord);
|
||||
//delete from file
|
||||
unset($this->pgin->qrlist[array_search($li, $this->pgin->qrlist)]);
|
||||
QRhelper::SaveQRlist($this->pgin);
|
||||
$wasDeleted = true;
|
||||
$player->sendMessage("QR panel [$idToDelete] deleted.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$wasDeleted)
|
||||
$player->sendMessage("QR panel [$idToDelete] not found.");
|
||||
} else {
|
||||
$this->showusage($sender);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case "qrp":
|
||||
//todo
|
||||
break;
|
||||
default:
|
||||
$this->showusage($sender);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$this->showusage($sender);
|
||||
}
|
||||
}
|
||||
|
||||
public function showusage(CommandSender $player)
|
||||
{
|
||||
//usage
|
||||
$player->sendMessage("QRcraft usage:");
|
||||
$player->sendMessage("/qr - help page");
|
||||
$player->sendMessage("/qrt <url> - test QR text size");
|
||||
$player->sendMessage("/qrc <url> [Auto|horizontal|vertical] - create qr panel");
|
||||
$player->sendMessage("/qrl - list QR panels IDs");
|
||||
$player->sendMessage("/qrd <ID> - detele QR panel by ID");
|
||||
$player->sendMessage("/qrp <ID> - teleport nearby QR panel by ID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*QRcraft plugin
|
||||
*
|
||||
* @author: Clodyx
|
||||
*
|
||||
*/
|
||||
|
||||
namespace clodyx\qrcraft;
|
||||
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\CommandExecutor;
|
||||
use clodyx\qrcraft\QRcraftCommand;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
||||
class QRcraftPlugIn extends PluginBase implements CommandExecutor
|
||||
{
|
||||
|
||||
public $cmd;
|
||||
private $sessions;
|
||||
public $config;
|
||||
public $qrlist = array();
|
||||
|
||||
public function onLoad()
|
||||
{
|
||||
QRhelper::$log = $this->getLogger();
|
||||
$this->cmd = new QRcraftCommand ($this);
|
||||
$this->log(TextFormat::GREEN . "QRcraft - Loaded");
|
||||
}
|
||||
|
||||
public function onEnable()
|
||||
{
|
||||
$this->setEnabled(true);
|
||||
$this->loadConfiguration();
|
||||
$this->qrlist = QRhelper::LoadQR($this);
|
||||
$this->getServer()->getPluginManager()->registerEvents(new QRcraftPlugInListener($this), $this);
|
||||
$this->log(TextFormat::GREEN . "QRcraft - Enabled");
|
||||
}
|
||||
|
||||
|
||||
public function loadConfiguration()
|
||||
{
|
||||
if (!file_exists($this->getDataFolder() . "config.yml")) {
|
||||
@mkdir($this->getDataFolder());
|
||||
file_put_contents($this->getDataFolder() . "config.yml", $this->getResource("config.yml"));
|
||||
}
|
||||
}
|
||||
|
||||
public function onDisable()
|
||||
{
|
||||
$this->setEnabled(false);
|
||||
$this->log(TextFormat::RED . "QRcraft - Disabled");
|
||||
}
|
||||
|
||||
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
|
||||
{
|
||||
$this->cmd->onCommand($sender, $command, $label, $args);
|
||||
}
|
||||
|
||||
|
||||
public function &session(Player $player)
|
||||
{
|
||||
$userName = $player->getName();
|
||||
if (!isset($this->sessions[$userName])) {
|
||||
$this->sessions[$userName] = array(
|
||||
"create" => false,
|
||||
"url" => "",
|
||||
"size" => 0,
|
||||
"orientation" => "a",
|
||||
);
|
||||
}
|
||||
return $this->sessions[$userName];
|
||||
}
|
||||
|
||||
public function log($msg)
|
||||
{
|
||||
$this->getLogger()->info($msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*QRcraft Listener
|
||||
*
|
||||
* @author: Clodyx
|
||||
*
|
||||
*/
|
||||
|
||||
namespace clodyx\qrcraft;
|
||||
|
||||
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\event\player\PlayerInteractEvent;
|
||||
|
||||
|
||||
class QRcraftPlugInListener implements Listener
|
||||
{
|
||||
|
||||
public $pgin;
|
||||
|
||||
public function __construct(QRcraftPlugIn $pg)
|
||||
{
|
||||
$this->pgin = $pg;
|
||||
}
|
||||
|
||||
public function onPlayerInteract(PlayerInteractEvent $event)
|
||||
{
|
||||
$level = $event->getPlayer()->level;
|
||||
$player = $event->getPlayer();
|
||||
$blockTouched = $event->getBlock();
|
||||
|
||||
if (\pocketmine\DEBUG > 1) {
|
||||
$direction = $player->getDirectionVector();
|
||||
$msg = "Player direction is X:" . round($direction->x, 2) . " Y:" . round($direction->y, 2) . " Z:" . round($direction->z, 2);
|
||||
$this->pgin->log($msg);
|
||||
$player->sendMessage($msg);
|
||||
}
|
||||
|
||||
QRhelper::CreateQRAndUnmark($this->pgin, $player, $blockTouched, $level, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*QRcraft Helper
|
||||
*
|
||||
* @author: Clodyx
|
||||
*
|
||||
*/
|
||||
|
||||
namespace clodyx\qrcraft;
|
||||
|
||||
|
||||
include(__DIR__ . "\..\..\clodyx\phpqrcode\phpqrcode.php");
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\block\Block as BlockAPI;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Config;
|
||||
use clodyx\phpqrcode as QR;
|
||||
|
||||
|
||||
class QRhelper
|
||||
{
|
||||
|
||||
public static $log;
|
||||
|
||||
public static function log($msg)
|
||||
{
|
||||
QRhelper::$log->info($msg);
|
||||
}
|
||||
|
||||
|
||||
public static function TestQRCode($addMargin, $textToQR)
|
||||
{
|
||||
$qrTab = QR\QRcode::text($textToQR, false, QR_ECLEVEL_L, 1, 1);
|
||||
$size = count($qrTab);
|
||||
|
||||
//add margins
|
||||
if ($addMargin) {
|
||||
$margin = 1;
|
||||
$qrTabWithMargins = array();
|
||||
for ($i = 0; $i < $margin; $i++) {
|
||||
$qrTabWithMargins[] = str_repeat("0", $size + 2 * $margin);
|
||||
}
|
||||
foreach ($qrTab as $line) {
|
||||
$qrTabWithMargins[] = str_repeat("0", $margin) . $line . str_repeat("0", $margin);
|
||||
}
|
||||
for ($i = 0; $i < $margin; $i++) {
|
||||
$qrTabWithMargins[] = str_repeat("0", $size + 2 * $margin);
|
||||
}
|
||||
//reassign qrtab
|
||||
$qrTab = $qrTabWithMargins;
|
||||
$size = count($qrTab);
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
|
||||
public static function CreateQRCode($blockTouched, $level, $addMargin, $textToQR, $build)
|
||||
{
|
||||
$genCoord = array();
|
||||
|
||||
#region qrcode wool blocks generation
|
||||
|
||||
$qrTab = QR\QRcode::text($textToQR, false, QR_ECLEVEL_L, 1, 1);
|
||||
$size = count($qrTab);
|
||||
|
||||
//add margins
|
||||
if ($addMargin) {
|
||||
$margin = 1;
|
||||
$qrTabWithMargins = array();
|
||||
for ($i = 0; $i < $margin; $i++) {
|
||||
$qrTabWithMargins[] = str_repeat("0", $size + 2 * $margin);
|
||||
}
|
||||
foreach ($qrTab as $line) {
|
||||
$qrTabWithMargins[] = str_repeat("0", $margin) . $line . str_repeat("0", $margin);
|
||||
}
|
||||
for ($i = 0; $i < $margin; $i++) {
|
||||
$qrTabWithMargins[] = str_repeat("0", $size + 2 * $margin);
|
||||
}
|
||||
//reassign qrtab
|
||||
$qrTab = $qrTabWithMargins;
|
||||
$size = count($qrTab);
|
||||
}
|
||||
|
||||
|
||||
$isFirstBlock = true;
|
||||
for ($iRow = 0; $iRow < $size; $iRow++) {
|
||||
$line = $qrTab[$size - $iRow - 1];
|
||||
|
||||
for ($iCol = 0; $iCol < $size; $iCol++) {
|
||||
$char = $line[$iCol];
|
||||
|
||||
$bitVal = ($char == '1') ? 1 : 0;
|
||||
$sign = $build[2] == "1" ? 1 : -1;
|
||||
if ($build[0] == "v") {
|
||||
//vertical
|
||||
if ($build[1] == "x") {
|
||||
$qrY = $blockTouched->getY() + 1 + $iRow;
|
||||
$qrZ = $blockTouched->getZ();
|
||||
$qrX = $blockTouched->getX() - $sign * $iCol;
|
||||
} else if ($build[1] == "z") {
|
||||
$qrY = $blockTouched->getY() + 1 + $iRow;
|
||||
$qrZ = $blockTouched->getZ() + $sign * $iCol;
|
||||
$qrX = $blockTouched->getX();
|
||||
}
|
||||
} else {
|
||||
//horizontal
|
||||
if ($build[1] == "x") {
|
||||
$qrY = $blockTouched->getY() + 1;
|
||||
$qrZ = $blockTouched->getZ() + $sign * $iRow;
|
||||
$qrX = $blockTouched->getX() - $sign * $iCol;
|
||||
} else if ($build[1] == "z") {
|
||||
$qrY = $blockTouched->getY() + 1;
|
||||
$qrZ = $blockTouched->getZ() + $sign * $iCol;
|
||||
$qrX = $blockTouched->getX() + $sign * $iRow;
|
||||
}
|
||||
}
|
||||
|
||||
QRhelper::CreateWoolBlock($level, $qrX, $qrY, $qrZ, $bitVal);
|
||||
|
||||
if ($isFirstBlock) {
|
||||
$genCoord[] = $qrX;
|
||||
$genCoord[] = $qrY;
|
||||
$genCoord[] = $qrZ;
|
||||
$isFirstBlock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//last block
|
||||
$genCoord[] = $qrX;
|
||||
$genCoord[] = $qrY;
|
||||
$genCoord[] = $qrZ;
|
||||
|
||||
#endregion qrcode
|
||||
|
||||
return $genCoord;
|
||||
}
|
||||
|
||||
|
||||
private static function CreateWoolBlock($level, $qrX, $qrY, $qrZ, $bitVal)
|
||||
{
|
||||
$id = 35;//wool
|
||||
$meta = ($bitVal === 0) ? 0 : 15;//wool color white / black
|
||||
$block = BlockAPI::get($id, $meta);
|
||||
$pos = new Vector3($qrX,
|
||||
$qrY,
|
||||
$qrZ);
|
||||
$level->setBlock($pos, $block);
|
||||
}
|
||||
|
||||
|
||||
public static function FillWithAir($level, $coords)
|
||||
{
|
||||
$x0 = $coords[0];
|
||||
$y0 = $coords[1];
|
||||
$z0 = $coords[2];
|
||||
$x1 = $coords[3];
|
||||
$y1 = $coords[4];
|
||||
$z1 = $coords[5];
|
||||
if($x0>$x1)
|
||||
self::swapValues($x0,$x1);
|
||||
if($y0>$y1)
|
||||
self::swapValues($y0,$y1);
|
||||
if($z0>$z1)
|
||||
self::swapValues($z0,$z1);
|
||||
for ($ix = $x0; $ix <= $x1; $ix++) {
|
||||
for ($iy = $y0; $iy <= $y1; $iy++) {
|
||||
for ($iz = $z0; $iz <= $z1; $iz++) {
|
||||
$id = 0;//air
|
||||
$meta = 0;
|
||||
$block = BlockAPI::get($id, $meta);
|
||||
$pos = new Vector3($ix, $iy, $iz);
|
||||
$level->setBlock($pos, $block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function swapValues(&$x,&$y) {
|
||||
$tmp=$x;
|
||||
$x=$y;
|
||||
$y=$tmp;
|
||||
}
|
||||
|
||||
|
||||
public static function MarkPlayerCanCreateQR(QRcraftPlugIn $plugin, Player $player, $url, $orientation)
|
||||
{
|
||||
if (empty($url)) {
|
||||
$player->sendMessage("Url is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
$size = QRhelper::TestQRCode(true, $url);
|
||||
|
||||
$session =& $plugin->session($player);
|
||||
$session["url"] = $url;
|
||||
$session["orientation"] = $orientation;
|
||||
$session["size"] = $size;
|
||||
$session["create"] = true;
|
||||
|
||||
|
||||
$player->sendMessage("QR block defined $orientation (" . $size . "x" . $size . ") for '" . $url . "'");
|
||||
$player->sendMessage("Touch a block to create it!");
|
||||
}
|
||||
|
||||
public static function CreateQRAndUnmark(QRcraftPlugIn $plugin, Player $player, $blockTouched, $level, $addMargin)
|
||||
{
|
||||
|
||||
$session =& $plugin->session($player);
|
||||
$toCreate = $session["create"];
|
||||
|
||||
if ($toCreate) {
|
||||
$textToQR = $session["url"];
|
||||
$size = $session["size"];
|
||||
$orient = strtolower($session["orientation"]);
|
||||
$allor = array("h", "v", "a");
|
||||
if (!in_array($orient, $allor))
|
||||
$orient = "a";
|
||||
|
||||
//calculate orientation
|
||||
$direction = $player->getDirectionVector();
|
||||
$orient = $orient[0] == "a" ?
|
||||
((abs($direction->y) > .9) ? "h" : "v") :
|
||||
$orient;
|
||||
$build = $orient;
|
||||
if (abs($direction->z) > abs($direction->x)) {
|
||||
//we build blocks on X axis (east+/west-)
|
||||
$build = $build . "x" . ($direction->z > 0 ? "1" : "0");
|
||||
} else {
|
||||
//we build blocks on Z axis (south+/north-)
|
||||
$build = $build . "z" . ($direction->x > 0 ? "1" : "0");
|
||||
}
|
||||
|
||||
//create qr block
|
||||
$genCoords = QRhelper::CreateQRCode($blockTouched, $level, $addMargin, $textToQR, $build);
|
||||
|
||||
//save qr block in list
|
||||
$qrID = QRhelper::SaveQR($plugin, $textToQR, $size, $genCoords);
|
||||
|
||||
//unmark
|
||||
$session["url"] = "";
|
||||
$session["orientation"] = "a";
|
||||
$session["create"] = false;
|
||||
$session["size"] = 0;
|
||||
|
||||
$player->sendMessage("QR block [$qrID] created OK!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function SaveQR(QRcraftPlugIn $plugin, $textToQR, $size, $genCoords)
|
||||
{
|
||||
if (!isset($plugin->qrlist))
|
||||
$plugin->qrlist = array();
|
||||
//calculate new ID
|
||||
$id = 0;
|
||||
foreach ($plugin->qrlist as $li) {
|
||||
$id = max($id, $li[0]);
|
||||
}
|
||||
$id++;//get next ID
|
||||
$data = array();
|
||||
//create new data item
|
||||
$data[] = $id;
|
||||
$data[] = $textToQR;
|
||||
$data[] = $size;
|
||||
$data[] = $genCoords;
|
||||
//add item to list
|
||||
$plugin->qrlist[] = $data;
|
||||
//save list
|
||||
self::SaveQRlist($plugin);
|
||||
//return the new id
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function LoadQR(QRcraftPlugIn $plugin)
|
||||
{
|
||||
$path = QRhelper::GetQRfile($plugin);
|
||||
if (!file_exists($path)) {
|
||||
return null;
|
||||
} else {
|
||||
$config = new Config($path, Config::JSON);
|
||||
return $config->getAll();
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetQRfile(QRcraftPlugIn $plugin)
|
||||
{
|
||||
$filename = "qrlist";
|
||||
$path = $plugin->getDataFolder() . "/$filename.txt";
|
||||
return $path;
|
||||
}
|
||||
|
||||
public static function SaveQRlist(QRcraftPlugIn $plugin)
|
||||
{
|
||||
//save list
|
||||
$path = QRhelper::GetQRfile($plugin);
|
||||
$config = new Config($path, Config::JSON);
|
||||
$config->setAll($plugin->qrlist);
|
||||
return $config->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user