First require it like this:
composer require spirit55555/php-minecraft
and then use it like this:
<?php
require 'vendor/autoload.php';
use \Spirit55555\Minecraft\MinecraftColors;
MinecraftColors::clean("test");
?>
Just download the files and include them.
Convert Minecraft color codes to HTML/CSS. Can also remove the color codes.
<?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 (�)
//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);
?>
Converts Minecraft JSON text to legacy format ('§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);
?>
Send Votifier votes to a Minecraft server.
This supports v2 (token) and v1 (public key) versions of the protocol.
If both are supplied, it will try v2 first and fall back to v1.
<?php
require 'vendor/autoload.php';
use Spirit55555\Minecraft\MinecraftVotifier;
use Spirit55555\Minecraft\MinecraftVotifierVote;
try {
$vote = new MinecraftVotifierVote('SERVICE_NAME', 'IP_ADDRESS', 'USERNAME', 'UUID');
$votifier = new MinecraftVotifier('SERVER_HOST', 'VOTIFIER_PORT', 'TOKEN', 'PUBLIC_KEY');
$votifier->sendVote($vote);
}
catch (Exception $e) {
echo $e->getMessage();
}
?>
More information about the Votifier protocols: https://github.com/NuVotifier/NuVotifier/wiki/Technical-QA