Skip to content

CustomTag

Thunder33345 edited this page Jan 18, 2017 · 4 revisions

#Custom Tag This is a document for developers ###Creating Custom Tag Class

To create create a custom tag simply implement _64FF00\PureChat\Tags\CustomTagInterface onto any desired class but it is highly recommend to use a separate class rather then the base class

<?php
/* Made By Thunder33345 */
namespace my\plugin;

use _64FF00\PureChat\Tags\CustomTagInterface;

class CustomTag implements CustomTagInterface
{
  public function onAdd() { }

  public function onError($code) { }

  public function onRemove($code = 0) { }

  public function getPrefix(): string { }

  public function getAllTags(): array { }
}

Lets start from the basic

onAdd() gets called when your tag is successfully added (examples usage: set up fireworks!)

onError() gets called when there a issue in adding it, the $code provides insight to what gone wrong you can get more detail via _64FF00\PureChat\Errors\ErrorHelper::getDetails($code)

onRemove() gets called when your class have been removed the $code represent what the error is (use ErrorHelper)

getPrefix() defines should return what the prefix of the class is, it is required to be lower cased, alphanumerical only and at least 3 character long IF said tag is "example" user should use {example_(suffix)}

getAllTags() returns an array of tag tag, it should follow the format of [ "suffix"=>"funcName", "secondsuffix"=>"secondFuncName" ]

####About getAllTags

the suffix should be lower cased letters only and at least 3 character long,

the functionName(inside the suffix) should be the name of the function that will get called

the function itself should have a parameter of Player $player as that is what will be passed when it is called, and it is expected to return a string

the function will be called when associated suffix is used, when executing the function is expected to handle all exceptions and throwable with a catch statement, if any exception get thrown PC will remove the tag for it's own safety

###Registering Custom Tag To PureChat

In order to register a tag you just created you will have to call registerCustomTag(CustomTagInterface $tag, $quite, $detail)

$tag should be the tag itself

$quite will suppress thrown exception

$detail will return the details IF an error occurred

Clone this wiki locally