用于Minecraft的有用PHP类

v1.3.5 2022-12-08 22:05 UTC

This package is auto-updated.

Last update: 2024-10-01 00:07:31 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

PHP-Minecraft

用于Minecraft的有用PHP类

使用Composer吗?

首先像这样要求:

composer require spirit55555/php-minecraft

然后这样使用:

<?php
require 'vendor/autoload.php';
use \Spirit55555\Minecraft\MinecraftColors;

MinecraftColors::clean("test");
?>

没有使用Composer?

只需下载文件并包含它们。

MinecraftColors.php

将Minecraft颜色代码转换为HTML/CSS。也可以删除颜色代码。

用法

<?php
require 'vendor/autoload.php';
use \Spirit55555\Minecraft\MinecraftColors;

//Support for § and & signs
$text = '§4Lorem §3§lipsum §rdolor &nsit &c&mamet';

//Convert to HTML with CSS colors
echo MinecraftColors::convertToHTML($text);

//Same as above, but will replace \n with <br />
echo MinecraftColors::convertToHTML($text, true);

//Same as above, but will use CSS classes instead of inline styles
echo MinecraftColors::convertToHTML($text, true, true, 'mc-motd--');

//Will be compatible with the server.properties file
echo MinecraftColors::convertToMOTD($text);

//Will be compatible with BungeeCord's config.yml file
echo MinecraftColors::convertToMOTD($text, '&');

//Will also output RGB/HEX colors, if they exist (&#000000)
//NOTE: Not supported in Vanilla Minecraft
echo MinecraftColors::convertToMOTD($text, '&', true);

//Same as above, but RGB/HEX in a long format (&x&0&0&0&0&0&0)
//NOTE: Not supported in Vanilla Minecraft
echo MinecraftColors::convertToMOTD($text, '&', true, true);

//Remove all color codes
echo MinecraftColors::clean($text);
?>

有关Minecraft颜色的更多信息:https://minecraft.fandom.com/wiki/Formatting_codes#Color_codes

MinecraftJSONColors.php

将Minecraft JSON (https://wiki.vg/Chat) 文本转换为旧格式 ('§aHello')

用法

<?php
require 'vendor/autoload.php';
use \Spirit55555\Minecraft\MinecraftJSONColors;

$first_component = ['text' => 'first '];
$second_component = ['text' => 'second ', 'color' => 'red'];
$third_component = ['text' => 'third ', 'strikethrough' => true];
$json = ['extra' => [$first_component, $second_component, $third_component]];

echo MinecraftJSONColors::convertToLegacy($json);
?>

MinecraftVotifier.php

将Votifier投票发送到Minecraft服务器。

用法

<?php
require 'vendor/autoload.php';
use \Spirit55555\Minecraft\MinecraftVotifier;

$votifier = new MinecraftVotifier('YOUR_PUBLIC_KEY', 'YOUR_SERVER_IP', 'YOUR_VOTIFIER_PORT', 'YOUR_SERVICE_NAME');
$votifier->sendVote('MINECRAFT_USERNAME');
?>

有关Votifier的更多信息:https://dev.bukkit.org/projects/votifier