Hello, I need help with my chat plugin. I have made the code for the "private chat" part in my plugin. The problem is that when the command is ran nothing happens, I have looked in the code an I don't see anything that stops it from working. If you see anything please reply ASAP, please and thank you. notice: I use PHPStorm for my plugins. PHP: /** * @param CommandSender $s * @param Command $c * @param $label * @param array $args */ public function onCommand(CommandSender $s, Command $c, $label, array $args){ switch(strtolower($c->getName())){ case 'group': if($s->hasPermission("cc.groups.all")) { if($s instanceof Player) { if ($args[0] === "create") { $group = $args[1]; $this->cc->createGroup($group, $s); $c_group = new PlayerJoinGroupEvent($s->getName(), $group); $this->cc->getServer()->getPluginManager()->callEvent($c_group); $s->sendMessage(TXT::GREEN . "Successfully created '" . $group . "'!"); } elseif ($args[0] === "delete") { $group = $args[1]; $d_group = new PlayerLeaveGroupEvent($s->getName(), $group); $this->cc->getServer()->getPluginManager()->callEvent($d_group); if ($this->cc->isLeader($group, $s) && $this->cc->groupExists($group)) { $this->cc->deleteGroup($group, $s); } elseif (!$this->cc->isLeader($group, $s)) { $s->sendMessage(TXT::RED . "You are not the owner of this group!"); } elseif (!$this->cc->groupExists($group)) { $s->sendMessage(TXT::RED . "The group '" . $group . "' does not exist."); } } elseif ($args[0] === "changeleader") { $group = $args[2]; if ($this->cc->isLeader($group, $s)) { } } elseif ($args[0] === "add") { $group = $args[1]; $player = $this->getServer()->getPlayerExact($args[2]); if ($player !== null) { $a_member = new PlayerJoinGroupEvent($player, $group); $this->cc->getServer()->getPluginManager()->callEvent($a_member); $this->cc->addMember($group, $player); $s->sendMessage(TXT::GREEN . "Successfully added player " . $player . "!"); } else { $s->sendMessage(TXT::RED . $args[2] . " is not online."); } } elseif ($args[0] === "remove") { $group = $args[1]; $player = $this->getServer()->getPlayerExact($args[2]); if ($player !== null) { $d_member = new PlayerLeaveGroupEvent($player, $group); $this->cc->getServer()->getPluginManager()->callEvent($d_member); $this->cc->removeMember($group, $player); $s->sendMessage(TXT::GREEN . "Successfully removed player " . $player . "!"); } else { $s->sendMessage(TXT::RED . $args[2] . " is not online."); } } elseif ($args[0] === "help") { $this->cc->helpList($s); } if (empty($args[0]) || empty($args[1])) { $s->sendMessage(TXT::RED . "For help, please use: /group help"); } else { return; } }else{ $s->sendMessage(TXT::RED . "Please run this command in-game."); } } break; case 'sgm': if($s->hasPermission("cc.groups.send.message")){ if($s instanceof Player){ if($this->cc->groupExists($args[0])){ $group = $args[0]; $message = array_slice($args, 2); if(!empty($message)){ $this->cc->sendGroupMessage($message, $s, $group); $s->sendMessage($message); }else{ $s->sendMessage(TXT::RED . "Please enter a longer message.\nUsage: /sgm <group> <message>"); } } }else{ $s->sendMessage(TXT::RED . "Please run this command in-game."); } } break; case 'hop': if($s->hasPermission("cc.op.help")) { if($s instanceof Player){ foreach ($args as $message) { foreach ($this->getServer()->getOnlinePlayers() as $p) { if ($p->isOp() && $p !== null) { $default = $this->cc->getConfig()->getNested("OP.help-message"); $p->sendMessage(str_replace(["{PLAYER}", "{MESSAGE}"], [$s, $args], $default)); $s->sendMessage($this->cc->getConfig()->getNested("OP.message-sent")); }else{ $s->sendMessage($this->cc->getConfig()->getNested("OP.no-op-online-message")); } } } if(empty($args)) { $s->sendMessage(TXT::RED . "Please enter a longer message. Usage: /hop <message>"); } }else{ $s->sendMessage(TXT::RED . "Please run this command in-game."); } } break; } } Code: commands: group: description: "access to all group commands" permission: cc.groups.all sgm: description: "send group messages" permission: cc.groups.send.message hop: description: "get instant help from ops" permission: cc.op.help permissions: cc.groups.all: default: true description: "access to all group commands" cc.groups.send.message: default: true description: "send group messages" cc.op.help: default: true description: "get instant help from ops"
hm use debug like PHP: var_dump($cmd->getName()); or if command is "group" PHP: echo "group"; and test where is the problem
Hey! I am experiencing the same thing on my plugin DynMapPE! My command is registered, i know that. But it seems not to get fired in ANY WAY! https://github.com/ImagicalCorp/DynMapPE On /dynmaprefresh not even any output ;(
1st that did nothing. 2nd why should it even do anything different? You just only used another case break thing then i did
Now works.. maybe the doubled braces in the if has permission part. For you: Code: commands: group: description: "access to all group commands" permission: cc.groups.all sgm: description: "send group messages" permission: cc.groups.send.message hop: description: "get instant help from ops" permission: cc.op.help permissions: cc.groups.all: description: "access to all group commands" default: true cc.groups.send.message: description: "send group messages" default: true cc.op.help: description: "get instant help from ops" default: true Check, if that works
Does not work. I will figure it out. I don't see anything wrong. PHP: public function onEnable(){ $log = $this->getLogger(); $log->info("BeastPvP chat enabled!"); $this->muted = array(); $this->msg = array(); $this->pfx = "[ChatControl]"; $this->seconds = $this->getConfig()->getNested("Chat.spam-check-seconds"); $this->sbu = $this->seconds; $this->getServer()->getScheduler()->scheduleRepeatingTask(new Broadcaster($this), 20); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); @mkdir($this->getDataFolder()); @mkdir($this->getDataFolder() . "Groups/"); if(!file_exists($this->getDataFolder() . "config.yml")){ $this->saveDefaultConfig(); } }
You should write after every { a sendMessage code tp check when it doesnt work anymore, also do some else commands
Your onCommand works on my side, and the onEnable function looks good, are there any error messages displayed on console?