1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Change Sign Display Text (custom plugin)

Discussion in 'Development' started by ALLINSEO, Mar 18, 2017.

  1. ALLINSEO

    ALLINSEO Baby Zombie

    Messages:
    133
    I want to be able to change the display text (check Signchange.php) on a sign but leave the real text in the data some how (refer to Action.php)

    I dont think My implementation of setText in SignChange.php will work and if it does I dont think I can use Action.php anymore.

    any suggestions?

    SignChange.php

    Code:
     public function onSignChange(SignChangeEvent $sc){
    
           if($this->getConfig()->get('op-create') == "true" && !$sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-prefix') || $this->getConfig()->get('op-create') == "true" && !$sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-op-prefix')|| $this->getConfig()->get('op-create') == "true" && !$sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-console-prefix')|| $this->getConfig()->get('op-create') == "true" && !$sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-console-prefix2')){
    
               $sc->setCancelled();
               $sc->getPlayer()->sendMessage($this->getConfig()->get('non-op-create-fail-message'));
    
           }
       
       
    $CPF = if($this->getConfig()->get('op-create') == "true" && $sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-prefix');
    
               $CPF || $this->getConfig()->get('op-create') == "true" && $sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-op-prefix')) {
                   $block->setText("Dev Server Commands","$block->getText()[2]","Command xyz 123","Clicking Sign will do x")
               
               }
           
           $CPF || $this->getConfig()->get('op-create') == "true" && $sc->getPlayer()->isOP() && $sc->getLine(0) == $this->getConfig()->get('sign-console-prefix')) {
                               $block->setText("My Console Commands","$block->getText()[2]","Console-Command2","Execute-Console-Commands")
               
           }
    
    SignUseAction.php
    Code:
     
       if($this->getConfig()->get('have-message') == "true"){
                           $PlayerName = $tap->getPlayer()->getName();
                           $cmd = $block->getText()[2] . $block->getText()[3];
                           $cmd2 = $block->getText()[2] . $PlayerName . $block->getText()[3];
                              if($block->getText()[0] == $this->getConfig()->get('sign-console-prefix')) {
                                                    
                                                        $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd2);
                                                
                                                    }
    
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    1) What are you trying to do? I know you are trying to get, set, and check text on a sign, but what is the purpose of all of it?
    2) Have you tested it yet? If you haven't, test it. You'll know pretty quickly if it works or not, and if it's very bad, you can use any errors you get to resolve the issue.
    3) I am not sure if putting an if statement into a variable is a sin, but I don't suggest doing it, and definitely not the way you did it. I also don't suggest making such long if statements. It's a little confusing.
    4) What context is the second code block in? We don't know what event that is in, what $tap or $block are, etc.
     
    jasonwynn10 likes this.
  3. ALLINSEO

    ALLINSEO Baby Zombie

    Messages:
    133
    well currently the plugin will issue commands either from the users cmd panel or from the console. only if a custom prefix is placed in the first line and only if the person who sets the prefix is a OP.
    The purpose was so that I can allow non op users to issue commands from console
    example;
    line1: [Console-Commands]
    line2: This is a description
    line3: world
    line4: MyWorld

    when right clicked the sign would issue $cmd2 which is /world $playername myworld

    my issue is that even though the example structure I provided is required for Action.php I want to be able to change what the text is displaying to the end user.

    example;
    line1; [Console-Commands] = Our Server Commands
    line2: $block->getText()[2] (get the description from second line and input it again)
    line3: "world" = This is a command
    line4: "MyWorld" = command will do x

    this below code is not actual code just a rough idea of how I am trying to make it function
    Code:
    if $this->getConfig()->get('sign-op-prefix') || $sc->getLine(3) = $line3
    if $line3 = "world" {
    $block->setText[3] ="This is a command"
    }
    
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You could use data packets to make the sign text change only for the user who tapped the sign, but not for anyone else.
     
  5. ALLINSEO

    ALLINSEO Baby Zombie

    Messages:
    133
    Hmm data packets?
    That might work but it would have to be changed before the user taps the sign.
    Maybe "get>username if not AdminUserName> do this" ?
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    If you want the sign text to differ per person, then send a packet indicating that change to the client onJoin
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.