类net.minecraft.util.ChatAllowedCharacters源码实例Demo

下面列出了怎么用net.minecraft.util.ChatAllowedCharacters的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: LiquidBounce   文件: MixinGuiEditSign.java
/**
 * @author CCBlueX
 */
@Overwrite
protected void keyTyped(char typedChar, int keyCode) throws IOException {
    this.signCommand1.textboxKeyTyped(typedChar, keyCode);
    this.signCommand2.textboxKeyTyped(typedChar, keyCode);
    this.signCommand3.textboxKeyTyped(typedChar, keyCode);
    this.signCommand4.textboxKeyTyped(typedChar, keyCode);

    if(signCommand1.isFocused() || signCommand2.isFocused() || signCommand3.isFocused() || signCommand4.isFocused())
        return;

    if(keyCode == 200) {
        this.editLine = this.editLine - 1 & 3;
    }

    if(keyCode == 208 || keyCode == 28 || keyCode == 156) {
        this.editLine = this.editLine + 1 & 3;
    }

    String s = this.tileSign.signText[this.editLine].getUnformattedText();
    if(keyCode == 14 && s.length() > 0) {
        s = s.substring(0, s.length() - 1);
    }

    if((ChatAllowedCharacters.isAllowedCharacter(typedChar) || (enabled && typedChar == '§')) && this.fontRendererObj.getStringWidth(s + typedChar) <= 90) {
        s = s + typedChar;
    }

    this.tileSign.signText[this.editLine] = new ChatComponentText(s);
    if(keyCode == 1) {
        this.actionPerformed(this.doneBtn);
    }
}
 
源代码2 项目: LiquidBounce   文件: MixinGuiEditSign.java
/**
 * @author CCBlueX
 */
@Overwrite
protected void keyTyped(char typedChar, int keyCode) throws IOException {
    this.signCommand1.textboxKeyTyped(typedChar, keyCode);
    this.signCommand2.textboxKeyTyped(typedChar, keyCode);
    this.signCommand3.textboxKeyTyped(typedChar, keyCode);
    this.signCommand4.textboxKeyTyped(typedChar, keyCode);

    if(signCommand1.isFocused() || signCommand2.isFocused() || signCommand3.isFocused() || signCommand4.isFocused())
        return;

    if(keyCode == 200) {
        this.editLine = this.editLine - 1 & 3;
    }

    if(keyCode == 208 || keyCode == 28 || keyCode == 156) {
        this.editLine = this.editLine + 1 & 3;
    }

    String s = this.tileSign.signText[this.editLine].getUnformattedText();
    if(keyCode == 14 && s.length() > 0) {
        s = s.substring(0, s.length() - 1);
    }

    if((ChatAllowedCharacters.isAllowedCharacter(typedChar) || (enabled && typedChar == '§')) && this.fontRendererObj.getStringWidth(s + typedChar) <= 90) {
        s = s + typedChar;
    }

    this.tileSign.signText[this.editLine] = new ChatComponentText(s);
    if(keyCode == 1) {
        this.actionPerformed(this.doneBtn);
    }
}
 
源代码3 项目: Hyperium   文件: MaterialTextField.java
public void keyTyped(char typedChar, int keyCode) {
    if (focused) {
        if (keyCode == 28) {
            focused = false;
        } else if (keyCode == 14) {
            if (!text.isEmpty()) {
                text = text.substring(0, text.length() - 1);
            }
        } else if (ChatAllowedCharacters.isAllowedCharacter(typedChar)) {
            text += typedChar;
        }
    }
}
 
源代码4 项目: ehacks-pro   文件: CharacterFilter.java
public static String filerAllowedCharacters(String str, boolean section) {
    StringBuilder sb = new StringBuilder();
    for (char c : str.toCharArray()) {
        if (!ChatAllowedCharacters.isAllowedCharacter((char) c) && (!section || c != '\u00a7' && c != '\n')) {
            continue;
        }
        sb.append(c);
    }
    return sb.toString();
}
 
源代码5 项目: NotEnoughItems   文件: SaveLoadButton.java
@Override
public boolean handleKeyPress(int keyID, char keyChar) {
    if (!focused) {
        return false;
    }

    if (keyID == Keyboard.KEY_BACK) {
        if (label.length() > 0) {
            label = label.substring(0, label.length() - 1);
            onTextChange();
            backdowntime = System.currentTimeMillis();
        }
    } else if (keyID == Keyboard.KEY_RETURN) {
        focused = false;
    } else if (keyChar == 22)//paste
    {
        String pastestring = GuiScreen.getClipboardString();
        if (pastestring == null) {
            pastestring = "";
        }

        label = label + pastestring;
        onTextChange();
    } else if (ChatAllowedCharacters.isAllowedCharacter(keyChar)) {
        label = label + keyChar;
        onTextChange();
    }
    return true;
}
 
源代码6 项目: NotEnoughItems   文件: SaveLoadButton.java
@Override
public boolean handleKeyPress(int keyID, char keyChar)
{
    if(!focused)
        return false;
    
    if(keyID == Keyboard.KEY_BACK)
    {
        if(label.length() > 0)
        {
            label = label.substring(0, label.length() - 1);
            onTextChange();
            backdowntime = System.currentTimeMillis();
        }
    }
    else if(keyID == Keyboard.KEY_RETURN)
    {
        focused = false;
    }        
    else if(keyChar == 22)//paste
    {
        String pastestring = GuiScreen.getClipboardString();
        if(pastestring == null) 
            pastestring = "";

        label = label + pastestring;
        onTextChange();
    }
    else if(ChatAllowedCharacters.isAllowedCharacter(keyChar))
    {
        label = label + keyChar;
        onTextChange();
    }
    return true;
}
 
源代码7 项目: NBTEdit   文件: CharacterFilter.java
public static String filerAllowedCharacters(String str, boolean section) {
    StringBuilder sb = new StringBuilder();
    char[] arr = str.toCharArray();
    int length = arr.length;

    for (int i = 0; i < length; ++i) {
        char c = arr[i];
        if (ChatAllowedCharacters.isAllowedCharacter(c) || (section && (c == NBTStringHelper.SECTION_SIGN || c == '\n')))
            sb.append(c);
    }

    return sb.toString();
}
 
源代码8 项目: PneumaticCraft   文件: GuiAphorismTile.java
@Override
protected void keyTyped(char par1, int par2){
    if(par2 == 1) {
        NetworkHandler.sendToServer(new PacketAphorismTileUpdate(tile));
    } else if(par2 == 200) {
        cursorY--;
        if(cursorY < 0) cursorY = textLines.length - 1;
    } else if(par2 == 208 || par2 == 156) {
        cursorY++;
        if(cursorY >= textLines.length) cursorY = 0;
    } else if(par2 == 28) {
        cursorY++;
        textLines = ArrayUtils.add(textLines, cursorY, "");
    } else if(par2 == 14) {
        if(textLines[cursorY].length() > 0) {
            textLines[cursorY] = textLines[cursorY].substring(0, textLines[cursorY].length() - 1);
        } else if(textLines.length > 1) {
            textLines = ArrayUtils.remove(textLines, cursorY);
            cursorY--;
            if(cursorY < 0) cursorY = 0;
        }
    } else if(ChatAllowedCharacters.isAllowedCharacter(par1)) {
        textLines[cursorY] = textLines[cursorY] + par1;
    }
    tile.setTextLines(textLines);
    super.keyTyped(par1, par2);
}
 
源代码9 项目: ehacks-pro   文件: GuiTextField.java
public boolean textboxKeyTyped(char par1, int par2) {
    if (this.isEnabled && this.isFocused) {
        switch (par1) {
            case '\u0001': {
                this.setCursorPositionEnd();
                this.setSelectionPos(0);
                return true;
            }
            case '\u0003': {
                GuiScreen.setClipboardString(this.getSelectedtext());
                return true;
            }
            case '\u0016': {
                this.writeText(GuiScreen.getClipboardString());
                return true;
            }
            case '\u0018': {
                GuiScreen.setClipboardString(this.getSelectedtext());
                this.writeText("");
                return true;
            }
        }
        switch (par2) {
            case 14: {
                if (GuiScreen.isCtrlKeyDown()) {
                    this.deleteWords(-1);
                } else {
                    this.deleteFromCursor(-1);
                }
                return true;
            }
            case 199: {
                if (GuiScreen.isShiftKeyDown()) {
                    this.setSelectionPos(0);
                } else {
                    this.setCursorPositionZero();
                }
                return true;
            }
            case 203: {
                if (GuiScreen.isShiftKeyDown()) {
                    if (GuiScreen.isCtrlKeyDown()) {
                        this.setSelectionPos(this.getNthWordFromPos(-1, this.getSelectionEnd()));
                    } else {
                        this.setSelectionPos(this.getSelectionEnd() - 1);
                    }
                } else if (GuiScreen.isCtrlKeyDown()) {
                    this.setCursorPosition(this.getNthWordFromCursor(-1));
                } else {
                    this.moveCursorBy(-1);
                }
                return true;
            }
            case 205: {
                if (GuiScreen.isShiftKeyDown()) {
                    if (GuiScreen.isCtrlKeyDown()) {
                        this.setSelectionPos(this.getNthWordFromPos(1, this.getSelectionEnd()));
                    } else {
                        this.setSelectionPos(this.getSelectionEnd() + 1);
                    }
                } else if (GuiScreen.isCtrlKeyDown()) {
                    this.setCursorPosition(this.getNthWordFromCursor(1));
                } else {
                    this.moveCursorBy(1);
                }
                return true;
            }
            case 207: {
                if (GuiScreen.isShiftKeyDown()) {
                    this.setSelectionPos(this.text.length());
                } else {
                    this.setCursorPositionEnd();
                }
                return true;
            }
            case 211: {
                if (GuiScreen.isCtrlKeyDown()) {
                    this.deleteWords(1);
                } else {
                    this.deleteFromCursor(1);
                }
                return true;
            }
        }
        if (ChatAllowedCharacters.isAllowedCharacter((char) par1)) {
            this.writeText(Character.toString(par1));
            return true;
        }
        return false;
    }
    return false;
}
 
源代码10 项目: pycode-minecraft   文件: GuiVertTextField.java
/**
 * 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);
        }
    }
}
 
源代码11 项目: NotEnoughItems   文件: TextField.java
public boolean isValid(String string) {
    // Solve the problem that Minecraft can't post Chinese characters
    return ChatAllowedCharacters.isAllowedCharacter(string.charAt(string.length() - 1));
}
 
源代码12 项目: NotEnoughItems   文件: TextField.java
public boolean isValid(String string) {
    // Solve the problem that Minecraft can't post Chinese characters
    return ChatAllowedCharacters.isAllowedCharacter(string.charAt(string.length() - 1));
}
 
源代码13 项目: CodeChickenCore   文件: GuiCCTextField.java
public boolean canAddChar(char c)
{
    return allowedCharacters == null ? ChatAllowedCharacters.isAllowedCharacter(c) : allowedCharacters.indexOf(c) >= 0;
}
 
 类所在包
 同包方法