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

QuietNoob plugin not doing what i intended..

Comments in 'Plugin Development' started by dxm_hippie, Apr 11, 2015.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Ok so i had a idea for a plugin, it seems very simple so should be easy enough for my first plugin :p please no one steal my idea :( Its simple..one permission and one event to cancel if the sender doesnt have that permission. The whole function of this plugin is to stop annoying players who ask how to mine..or stupid stuff like that. Basically its a noob blocker lol It will work with pureperms so in my case a "guest" wont be able to chat in public chat but they can still /tell and i was also planning on adding a /how command to tell them how they can earn the right to chat. here is my main.php i have all the stuff set up and it will load correctly but wont do any thing, kinda expected from my first plugin lol if someone could just tell me if im even close? and if i am then please suggest other ways i can do this but if im not even close just tell me to go read a book :p oh btw thanks @LDX ..i studied your ichat plugin to find a way to cancel the chat event and stuff lol

    <?php

    namespace CrazyHippie\QuietNoob;

    use pocketmine\event\player\PlayerChatEvent;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\Player;

    class Main extends PluginBase implements Listener {

    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
    }

    public function onChat(PlayerChatEvent $i, Chat $p, $event, $lable, $args) {
    if($i->hasPermission("talk.noob")) {
    if(!($i instanceof Player)) {
    return true;
    }
    if(!isset($args[0])) {
    return false;
    }
    $p = $this->getServer()->getPlayer($args[0]);
    if($this->checkMessage($event->getMessage()) || ($event->getPlayer()->hasPermission("talk.noob"))) {
    $r = array();
    foreach($this->getServer()->getOnlinePlayers() as $p) {
    if(!isset($this->data["chat"][strtolower($p->getName())])) {
    $r[] = $p;
    }
    }
    $event->setRecipients($r);
    } else {
    $sendMessage = $event->getPlayer()->sendMessage("[QuietNoob] You must be a citizen to talk in public chat.");
    $event->setCancelled();
    return true;

    }
    }
    }
    }
    Last edited: Apr 11, 2015
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    onChat. Wont be right!
  3. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Won't work.
  4. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Thats a better reply than what i was expecting :p im sure there is lots wrong with this code :( what should i do with the onChat? just get rid of it? lol i used another plugin to see how to do most of this..so im sure i got some stuff in there thats not even necessary.
  5. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Why cant that work? if you can /mute a player why cant you have them muted unless they have a permission node?
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I supose that you want to check if player has a permission but instead of checking if event has a permission :D
    dxm_hippie likes this.
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    It won't work. You only need this:
    PHP:
    public function onPlayerChat(PlayerChatEvent $event){
            
    //Code here
    }
  8. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    oh thank! lol i thought you ment like this plugin would be impossible.
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    dxm_hippie likes this.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
     public function PlayerChatEvent(PlayerChatEvent $event){

    $player $event->getPlayer();

    $name $event->getPlayer()->getName();
    If(!(
    $player->hasPermission(noob.talk))){
    $event->setCancelled(true);
    $player->sendMessage("Your message here");
    }
  11. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I can do the plugin.yml like this right? i was a little confused on how to add a permission to something thats not a command..

    PHP:
    nameQuietNoob
    main
    CrazyHippie\QuietNoob\main
    version
    0.1
    api
    1.6.0
    permission
    talk.noob
  12. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Look at my tutorial in the wiki here: https://github.com/Gamecrafter/Example-Plugins
  13. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Thank you peeps soo much! i got it working for the most part now :) it will do what is intended all except for the message to be sent to the player whos chat is blocked i get error when they try to type

    [CRITICAL] Could not pass event pocketmine\event\player\PlayerChatEvent to QuietNoob v0.1: Undefined property: CrazyHippie\QuietNoob\Main::$getserver on CrazyHippie\QuietNoob\Main
    14:21:14 [NOTICE] UndefinedPropertyException: "Undefined property: CrazyHippie\QuietNoob\Main::$getserver" (E_NOTICE) in "/QuietNoob/src/CrazyHippie/QuietNoob/main" at line 27

    line 27 is

    $this->getserver->getplayer->$player()->sendMessage("[QuietNoob] You need to be a citizen to talk in public chat.");

    i will figure it out later :p got some stuff to do but thanks again!

    [edit] i tried

    $player->sendMessage("Your message here");

    and the server crashed when i tried to type :p
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You're writing worng: "getserver->getplayer->"





    Pocketmine is thinking that getserver and getplayer is variable.
    So do "getServer()->getPlayer()" instead and remember it will always start wit lowercase and next words will start with uppercase!
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Dont do put those brackets $player() at variable it should be this: "$this->getServer()->getPlayer()->sendMessags("Message here");"

    If you have any other error just put it in here and i will try to answer ASAP ;)
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can just create a permission node for public chat and revoke it for the guest rank in PurePerms.
  17. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    now you tell me :p i already got it working perfectly..just need to add a command like /how to tell them how to earn the right to chat. Got this idea from a pc server. it wouldn't let me chat bc i was a noob lol
  18. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Works great, seems to take a long time to load it tho..and it so small it shouldn't take any time at all lol

    PHP:
    <?php

    namespace CrazyHippie\QuietNoob;

    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener {
       
        public function 
    onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
    $this->getLogger()->info("┬žaEnabling ".$this->getDescription()->getFullName()."...");

    }

    public function 
    onDisable(){
            
    $this->getLogger()->info("┬žcDisabling ".$this->getDescription()->getFullName()."...");
        }
       
        public function 
    onPlayerChat(PlayerChatEvent $event){
           
            
    $player $event->getPlayer();
           
    If(!(
    $player->hasPermission("talk.noob"))) {
    $event->setCancelled(true);
    $event->getPlayer()->sendMessage("[QuietNoob] You need to be a citizen to talk in public chat.");
    }
     
        }

           
    }
  19. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    This may seem a bit mean...but i dont have time to tell someone how to mine -_- lol also will come in handy when someone gets there account ban and come back on a guest account trying to cuss and what not. Also thinking of adding a config to set a time, so it will be a set time they have to figure things out before asking.
  20. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    ps. i think i fell in love with developing! :D ik i have lots to learn..like lots lol i just started tinkering a few days ago.
    PEMapModder likes this.

Share This Page

Advertisement