Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error with my code

Comments in 'Plugin Development' started by Skullex, Mar 8, 2016.

  1. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Ok, I have absolutely no idea on why this is happening nor how to fix it so I need your help. I keep receiving a unexpected 'public' error in this code here

    PHP:
    <?php

    namespace CaptainKenji17;
    /*
    * Edit by Skull3x
    * Will be making different sets of copies from         * this code for each and every type of weapon in         * my kits! Credit to CaptainKenji17
    */

    use pocketmine\event\player\PlayerItemHeldEvent;

    use 
    pocketmine\Player;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\entity\EntityDamageEvent;

    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\utils\TextFormat as Color;

    use 
    pocketmine\level\sound\DoorBumpSound;

    use 
    pocketmine\level\sound\DoorCrashSound;

    use 
    pocketmine\Server;

    use 
    pocketmine\entity\Effect;


    class 
    Main extends PluginBase implements Listener{

        public function 
    onEnable(){
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                
    $this->getServer()->getLogger()->info(Color::AQUA "DiamondSword Skill Enabled!");
        }
       
            public function 
    onItemHeld(PlayerItemHeldEvent $event){
        if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 276){
        
    $event->getPlayer()->sendTip("§e-= §bDIAMOND KIT §e=-");
        }
        if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 267){
        
    $event->getPlayer()->sendTip("§e-= §7IRON KIT §e=-");
        }
        if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 268){
    $event->getPlayer()->sendTip("§e-= §6BASIC KIT §e=-");
    }
        if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 283){
    $event->getPlayer()->sendTip("§f-= §eGOLD KIT §f=-");
    }
        if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 272){
    $event->getPlayer()->sendTip("§e-= §8STONE KIT §e=-");
    }

        public function 
    onDamage(EntityDamageEvent $event){
            if(
    $event instanceof EntityDamageByEntityEvent){
                
    $damager $event->getDamager();
                
    $entity $event->getEntity();
                
    $victim $event->getVictim();
                if(
    $damager instanceof Player){
                    if(
    $damager->getInventory()->getItemInHand()->getId() === 276){
                        
    $event->setknockBack($this->getConfig()->get("KnockBack-Power1"));
                        
    $event->getDamager()->addEffect($this->getConfig()->get("Effect1")->setDuration()->get("Duration1")->setAmplifier()->get("Amplifier1")->setVisible()->get("Visible1"));
                        if(
    $damager->getInventory()->getItemInHand()->getId() === 267){
                        
    $event->setknockBack($this->getConfig()->get("KnockBack-Power2"));
                        
    $event->getDamager()->addEffect($this->getConfig()->get("Effect2")->setDuration()->get("Duration2")->setAmplifier()->get("Amplifier2")->setVisible()->get("Visible2"));
                        if(
    $damager->getInventory()->getItemInHand()->getId() === 283){
                        
    $event->setknockBack($this->getConfig()->get("KnockBack-Power3"));
                        
    $event->getDamager()->addEffect($this->getConfig()->get("Effect3")->setDuration()->get("Duration3")->setAmplifier()->get("Amplifier3")->setVisible()->get("Visible3"));
                        if(
    $damager->getInventory()->getItemInHand()->getId() === 272){
                        
    $event->setknockBack($this->getConfig()->get("KnockBack-Power4"));
                        
    $event->getDamager()->addEffect($this->getConfig()->get("Effect4")->setDuration()->get("Duration4")->setAmplifier()->get("Amplifier4")->setVisible()->get("Visible4"));
                        if(
    $damager->getInventory()->getItemInHand()->getId() === 268){
                        
    $event->setknockBack($this->getConfig()->get("KnockBack-Power5"));
                        
    $event->getDamager()->addEffect($this->getConfig()->get("Effect5")->setDuration()->get("Duration5")->setAmplifier()->get("Amplifier5")->setVisible()->get("Visible5"));
    }
    }
    }
    On line 57 and every time I shuffle around the public functions it goes to another and another. I'm so confused..

    Thanks in advance :p
  2. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    You forgot one '}' in onItemHeld
    PocketKiller, PEMapModder and Skullex like this.
  3. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    PHP:
    <?php

    namespace CaptainKenji17;
    /*
    * Edit by Skull3x
    * Will be making different sets of copies from         * this code for each and every type of weapon in         * my kits! Credit to CaptainKenji17
    */

    use pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat as Color;
    use 
    pocketmine\level\sound\DoorBumpSound;
    use 
    pocketmine\level\sound\DoorCrashSound;
    use 
    pocketmine\Server;
    use 
    pocketmine\entity\Effect;

    class 
    Main extends PluginBase implements Listener{

        public function 
    onEnable(){
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info(Color::AQUA "DiamondSword Skill Enabled!");
        }
      
            public function 
    onItemHeld(PlayerItemHeldEvent $event){
                if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 276){
                    
    $event->getPlayer()->sendTip("§e-= §bDIAMOND KIT §e=-");
                }
                if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 267){
                    
    $event->getPlayer()->sendTip("§e-= §7IRON KIT §e=-");
                }
                if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 268){
                    
    $event->getPlayer()->sendTip("§e-= §6BASIC KIT §e=-");
                }
                if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 283){
                    
    $event->getPlayer()->sendTip("§f-= §eGOLD KIT §f=-");
                }
                if(
    $event->getPlayer()->getInventory()->getItemInHand()->getId() === 272){
                    
    $event->getPlayer()->sendTip("§e-= §8STONE KIT §e=-");
                }
            }

            public function 
    onDamage(EntityDamageEvent $event){
                if(
    $event instanceof EntityDamageByEntityEvent){
                    
    $damager $event->getDamager();
                    
    $entity $event->getEntity();
                    
    $victim $event->getVictim();
                }
    /**UNSURE ABOUT THIS **/
                    
    if($damager instanceof Player){
                        if(
    $damager->getInventory()->getItemInHand()->getId() === 276){
                            
    $event->setknockBack($this->getConfig()->get("KnockBack-Power1"));
                            
    $event->getDamager()->addEffect($this->getConfig()->get("Effect1")->setDuration()->get("Duration1")->setAmplifier()->get("Amplifier1")->setVisible()->get("Visible1"));
                        }
                            if(
    $damager->getInventory()->getItemInHand()->getId() === 267){
                            
    $event->setknockBack($this->getConfig()->get("KnockBack-Power2"));
                            
    $event->getDamager()->addEffect($this->getConfig()->get("Effect2")->setDuration()->get("Duration2")->setAmplifier()->get("Amplifier2")->setVisible()->get("Visible2"));
                            }
                            if(
    $damager->getInventory()->getItemInHand()->getId() === 283){
                            
    $event->setknockBack($this->getConfig()->get("KnockBack-Power3"));
                            
    $event->getDamager()->addEffect($this->getConfig()->get("Effect3")->setDuration()->get("Duration3")->setAmplifier()->get("Amplifier3")->setVisible()->get("Visible3"));
                            }
                            if(
    $damager->getInventory()->getItemInHand()->getId() === 272){
                            
    $event->setknockBack($this->getConfig()->get("KnockBack-Power4"));
                            
    $event->getDamager()->addEffect($this->getConfig()->get("Effect4")->setDuration()->get("Duration4")->setAmplifier()->get("Amplifier4")->setVisible()->get("Visible4"));
                            }
                            if(
    $damager->getInventory()->getItemInHand()->getId() === 268){
                            
    $event->setknockBack($this->getConfig()->get("KnockBack-Power5"));
                            
    $event->getDamager()->addEffect($this->getConfig()->get("Effect5")->setDuration()->get("Duration5")->setAmplifier()->get("Amplifier5")->setVisible()->get("Visible5"));
                        }
                    }
            }
    }
                      
                    
    You need a good IDE, or a good text editor. I Use Brackets(io) It helps lay out the code, to keep it tidy, and it helps to put the brackets in the RIGHT place.

    At the end if each IF statments, youll need to tidily end the if statment.
    Here is a rough example.
    PHP:
    If($bob->getInventory()->$item{
    /**STUFF HERE**/
    /** REMEMBER TO END THE IF WITH "}" **/
    }
    Skullex likes this.
  4. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    You're always helping me out :p thanks :D
  5. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    You too :p
  6. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    i dont think my version of the code s fully correct... all i done was reorganised it a bit... and plus, I was in a rush, with other commitments... let me know if it works though:)
    Last edited: Mar 9, 2016
    Skullex likes this.
  7. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    It worked but as you said, unsure.. you was right. Somethings wrong with my configuration related section of the code :(
  8. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    Well, the format is there anyway :)
  9. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Ye

Share This Page

Advertisement