========================== Sending a vote to Votifier ========================== When you have a server which runs the classic Votifier plugin, you can use this code here. .. warning:: The classic Votifier plugin relies on ``javax.xml.bind.DatatypeConverter``, which was removed from the JDK in Java 11, so it only runs on Java 8. The newest Minecraft server that still runs on Java 8 is **1.16.5** (1.17 raised the requirement to Java 16), which makes 1.16.5 the last version the classic plugin works on. On a newer server it fails to enable with ``NoClassDefFoundError: javax/xml/bind/DatatypeConverter``. Prefer :doc:`NuVotifier ` — the maintained successor that runs on current Java and is backwards compatible with this classic protocol. You can place following code wherever you want to set up the vote: .. code-block:: php setHost('127.0.0.1') ->setPublicKey('MIIBIjANBgkq...') ; And then to send it to the server: .. code-block:: php setUsername($_GET['username']) ->setServiceName('Your vote list') ->setAddress($_SERVER['REMOTE_ADDR']) ; try { /** @var Votifier $server */ $server->sendVote($vote); // Connection created, and vote sent. // Doesn't mean the server handled it correctly, but the client did. } catch (InvalidArgumentException $e) { // Not all variables that are needed have been set. // See $e->getMessage() for all errors. } catch (NoConnectionException $e) { // Could not create a connection (socket) to the specified server } catch (PackageNotReceivedException $e) { // If the package couldn't be received, for whatever reason. } catch (PackageNotSentException $e) { // If the package couldn't be send, for whatever reason. } Send multiple votes =================== If you want you can also pass multiple votes, for when you have set up something like a scheduler. .. code-block:: php sendVote($vote1, $vote2, $vote3); To have an in-depth look at the classes and their objects, refer to the API section. Full example ============ The following code is another example of a full HTML page with the code from above .. code-block:: php setHost('127.0.0.1') ->setPublicKey('MIIBIjANBgkq...') ; $vote = (new ClassicVote()) ->setUsername($_GET['username']) ->setServiceName('Your vote list') ->setAddress($_SERVER['REMOTE_ADDR']) ; try { $server->sendVote($vote); echo "

Connection created, and vote sent. Doesn't mean the server handled it correctly, but the client did.

"; } catch (InvalidArgumentException $e) { echo "

Not all variables that are needed have been set. See $e->getMessage() for all errors.

"; } catch (NoConnectionException $e) { echo "

Could not create a connection (socket) to the specified server

"; } catch (PackageNotReceivedException $e) { echo "

If the package couldn't be received, for whatever reason.

"; } catch (PackageNotSentException $e) { echo "

If the package couldn't be send, for whatever reason.

"; } } ?> Votifier