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

Solved Plugin not working?

Discussion in 'Development' started by WinterBuild7074, Jul 2, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I'm coding a plugin, but isn't working at all. Please help me fix and explain my mistakes (I want to learn too).
    I'm not getting any errors.

    PHP:
    <?php
    namespace WinterBuild7074\NoCrafting;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    class 
    Main extends PluginBase implements Listener {
        
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
        }
        
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            switch(
    $cmd->getName()) {
                case 
    "nocrafting":
                case 
    "disablecrafting":
                case 
    "turnoffcrafting":
                    if(
    $sender->hasPermission("nocrafting.tools")) {
                        if(isset(
    $args[0])) {
                            if(
    strtolower($args[0]) === "add" || strtolower($args[0]) === "remove") {
                                if(isset(
    $args[1])) {
                                    
    $level $args[1];
                                    if(
    $this->getServer()->isLevelGenerated($level)) {
                                        if(
    $args[0] === "add") {
                                            
    $disablecrafting $this->getConfig()->get("DisableCrafting");
                                            
    $disablecrafting[] = $level;
                                            
    $this->getConfig()->set("DisableCrafting"$disablecrafting);
                                        } else {
                                            
    $disablecrafting $this->getConfig()->get("DisableCrafting");
                                            if(
    in_array($level$disablecrafting)) {
                                                
    $pos array_search($level$disablecrafting);
                                                unset(
    $disablecrafting[$pos]);
                                                
    $this->getConfig()->set("DisableCrafting"$disablecrafting);
                                            } else {
                                                
    $sender->sendMessage("§cCannot remove world from config because that world isn't in the §oDisableCrafting§r§c list.");
                                            }
                                        }
                                    } else {
                                        
    $sender->sendMessage("§cWorld doesn't exist.");
                                    }
                                } else {
                                    
    $sender->sendMessage("§cUsage: /" $label " <add|remove> <worldName>");
                                }
                            } else {
                                
    $sender->sendMessage("§cUsage: /" $label " <add|remove> <worldName>");
                            }
                        } else {
                            
    $sender->sendMessage("§cUsage: /" $label " <add|remove> <worldName>");
                        }
                    }
                    break;
                
                case 
    "getworldname":
                    if(
    $sender->hasPermission("nocrafting.world")) {
                        
    $playerlevel $sender->getLevel()->getName();
                        
    $sender->sendMessage("§aName of world: §o" $playerlevel);
                    }
                    break;
            }
        }
        public function 
    onTouch(PlayerInteractEvent $event) {
            
    $block $event->getBlock();
            
    $player $event->getPlayer();
            
    $blocklevel $block->getLevel()->getName();
            
    $blockedcrafting $this->getConfig()->get("BlockedCrafting");
            
    $opcrafting $this->getConfig()->get("OPCrafting");
            if(
    strtolower($opcrafting) === "true") {
                if(!
    $player->hasPermission("nocrafting.op")) {
                    if(
    $block->getId() === 58) {
                        if(
    in_array($blocklevel$blockedcrafting)) {
                            
    $event->setCancelled();
                        }
                    }
                }
            } else {
                if(
    $block->getId() === 58) {
                    if(
    in_array($blocklevel$blockedcrafting)) {
                        
    $event->setCancelled();
                    }
                }
            }
        }
    }
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    because you only block crafting bench not actual crafting?
    like using inv bench etc?
     
    Muqsit likes this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Are you sure your code is even being executed? Use var_dump().
    Anyway, I found a possible fault in your code. You forgot to save the config after modifying it.
     
    EdwardHamHam likes this.
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    How do I save it?
     
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Oh, I forgot that. But why can players still open the Crafting Tables?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Your code might not be fully executing. Can you provide the level name and the config file?
     
  7. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    You can't cancel opening of the crafting GUI, it's client-sided.
     
    Muqsit, jasonwynn10 and Miste like this.
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    That means, it's not possible to completely block crafting (except the Crafting Tables)?
     
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    You can cancel the event, but you can't stop the client opening the GUI.
     
    Muqsit and Voli like this.
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    could the server remove the window after it opens?
     
  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.