Java Code Examples for net.minecraft.util.ChatAllowedCharacters#filterAllowedCharacters()

The following examples show how to use net.minecraft.util.ChatAllowedCharacters#filterAllowedCharacters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiVertTextField.java    From pycode-minecraft with MIT License 4 votes vote down vote up
/**
 * Adds the given text after the cursor, or replaces the currently selected text if there is a selection.
 */
public void writeText(String textToWrite)
{
    String s = "";
    String s1 = ChatAllowedCharacters.filterAllowedCharacters(textToWrite);
    int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd;
    int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition;
    int k = this.maxStringLength - this.text.length() - (i - j);

    if (!this.text.isEmpty())
    {
        s = s + this.text.substring(0, i);
    }

    int l;

    if (k < s1.length())
    {
        s = s + s1.substring(0, k);
        l = k;
    }
    else
    {
        s = s + s1;
        l = s1.length();
    }

    if (!this.text.isEmpty() && j < this.text.length())
    {
        s = s + this.text.substring(j);
    }

    if (this.validator.apply(s))
    {
        this.text = s;
        this.moveCursorBy(i - this.selectionEnd + l);

        if (this.guiResponder != null)
        {
            this.guiResponder.setEntryValue(this.id, this.text);
        }
    }
}