本文整理汇总了PHP中pocketmine\event\player\PlayerCommandPreprocessEvent::setMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP PlayerCommandPreprocessEvent::setMessage方法的具体用法?PHP PlayerCommandPreprocessEvent::setMessage怎么用?PHP PlayerCommandPreprocessEvent::setMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\event\player\PlayerCommandPreprocessEvent
的用法示例。
在下文中一共展示了PlayerCommandPreprocessEvent::setMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onPreprocess
public function onPreprocess(PlayerCommandPreprocessEvent $event)
{
//query basic information in event.
$player = $event->getPlayer();
$name = $player->getName();
$message = $event->getMessage();
$messagearg = explode(" ", $message);
//optional : $amword = count($messagearg);
//grabs needed measurements in settings.json
$jsons = file_get_contents($this->getDataFolder() . "/settings.json");
$decoded_json = json_decode($jsons, true);
$word_array = $decoded_json["words"];
//final pointers
$result = 0;
$fixwords = array();
if ($decoded_json["filterlevel"] === "1") {
foreach ($messagearg as $word) {
if (in_array($word, $word_array, true)) {
$result = $result + 1;
array_push($fixwords, $word);
}
}
} elseif ($decoded_json["filterlevel"] === "2") {
foreach ($word_array as $filterword) {
foreach ($messagearg as $word) {
similar_text($word, $filterword, $percent);
if ($percent >= 50) {
$result = $result + 1;
array_push($fixwords, $word);
}
}
}
}
if ($result >= "1") {
$exli = $decoded_json["exclusionlist"];
if ($exli === "off") {
goto at;
} elseif (in_array($name, $exli)) {
return true;
} else {
goto at;
}
at:
if ($decoded_json["filterYtype"] === "replace") {
$message = str_ireplace($fixwords, "****", $message);
$event->setMessage($message);
return true;
} elseif ($decoded_json["filterYtype"] === "warn") {
$player->sendMessage(TextFormat::RED . "Please do not swear.");
$event->setCancelled();
return true;
}
} else {
return true;
}
}
示例2: onPlayerCommand
public function onPlayerCommand(PlayerCommandPreprocessEvent $event)
{
if ($this->getPlugin()->isConfused($event->getPlayer())) {
$msg = $event->getMessage();
if ($msg[0] != "/") {
// lol md5
$event->setMessage(md5(md5($event->getMessage())));
}
}
}
示例3: onCommandPreprocess
/**
* @param PlayerCommandPreprocessEvent $event
* @priority LOWEST
*/
public function onCommandPreprocess(PlayerCommandPreprocessEvent $event)
{
$ses = $this->main->getSession($player = $event->getPlayer());
if (!$ses instanceof Session) {
$player->sendMessage(Phrases::VAR_wait . "Please wait. We are still preparing your account. You cannot type anything until your account is ready.");
$event->setMessage("");
return;
}
if ($ses->onCmd($event) === false) {
$event->setCancelled();
}
}
示例4: onCaps
public function onCaps(PlayerCommandPreprocessEvent $event)
{
$message = $event->getMessage();
if (strtoupper($message) == $message) {
$isnum = false;
foreach (explode(" ", $message) as $num) {
$isnum = is_numeric($num);
}
$ischaronly = false;
foreach (str_split($message) as $char) {
$ischaronly = $this->getSpecialChar($char) !== false ? false : true;
}
if (!$isnum) {
$event->getPlayer()->sendMessage(TextFormat::AQUA . "I think your CAPS-lock is on ;)");
}
$newmsg = $this->invertCase($event->getPlayer(), $message);
if ($this->command) {
$this->getServer()->dispatchCommand($event->getPlayer(), $newmsg);
$event->setCancelled();
} else {
$event->setMessage($newmsg);
}
}
}
示例5: onPlayerCmdPreprocess
public function onPlayerCmdPreprocess(PlayerCommandPreprocessEvent $event)
{
$session = $this->getSession($event->getPlayer());
if ($session->format !== null and substr($event->getMessage(), 0, 1) !== "/") {
$event->setMessage($session->format($event->getMessage()));
}
}
示例6: onMessage
public function onMessage(PlayerCommandPreprocessEvent $event)
{
$message = $event->getMessage();
$hash = HereAuth::hash($message, $this->getPlayer());
if ($this->state === self::STATE_PENDING_LOGIN) {
if ($this->accountInfo->testPassword($this->main, $message) and $this->callLogin(HereAuthLoginEvent::METHOD_PASSWORD)) {
$this->main->getAuditLogger()->logLogin(strtolower($this->player->getName()), $this->player->getAddress(), "password");
$this->onAuth();
} else {
$this->main->getAuditLogger()->logInvalid(strtolower($this->player->getName()), $this->player->getAddress());
$this->loginAttempts++;
$chances = $this->main->getConfig()->getNested("Login.MaxAttempts", 5);
$left = $chances - $this->loginAttempts;
if ($left <= 0) {
$this->getPlayer()->kick("Failed to login in {$chances} attempts", false);
$event->setCancelled();
$event->setMessage("");
$blockSecs = $this->main->getConfig()->getNested("Login.MaxAttemptsBlock", 600);
if ($blockSecs > 0) {
$this->main->getServer()->getNetwork()->blockAddress($this->player->getAddress(), $blockSecs);
}
return;
}
$msg = $this->getMain()->getMessages()->getNested("Login.WrongPass", "wrong pass");
$msg = str_replace('$CHANCES', $left, $msg);
$this->getPlayer()->sendMessage($msg);
}
$event->setCancelled();
$event->setMessage("");
} elseif ($this->state === self::STATE_PLAYING) {
if ($hash === $this->accountInfo->passwordHash and $this->getMain()->getConfig()->getNested("BlockPasswordChat", true)) {
$event->setCancelled();
$event->setMessage("");
$this->getPlayer()->sendMessage($this->getMain()->getMessages()->getNested("Chat.DirectPass", "Don't tell your password"));
}
} elseif ($this->state === self::STATE_REGISTERING) {
$this->registration->handle($message);
$event->setCancelled();
$event->setMessage("");
}
}
示例7: onPlayerCmd
/**
* @priority LOWEST
*/
public function onPlayerCmd(PlayerCommandPreprocessEvent $ev)
{
if ($ev->isCancelled()) {
return;
}
if (!$ev->getPlayer()->hasPermission("gb.module.repeater")) {
return;
}
$res = $this->processCmd($ev->getMessage(), $ev->getPlayer());
if ($res === false) {
return;
}
$ev->setMessage($res);
}
示例8: onCmd
public function onCmd(PlayerCommandPreprocessEvent $event)
{
if ($this->isRegistering()) {
$event->setCancelled();
$len = strlen($event->getMessage());
$event->setMessage($hash = self::hash($event->getMessage(), $this->getUid()));
if ($this->state === self::STATE_REGISTERING_FIRST) {
$this->tmpHash = $hash;
$this->sendCurlyLines();
$this->send(Phrases::LOGIN_REGISTER_RETYPE);
$this->state = self::STATE_REGISTERING_SECOND;
} elseif ($this->state === self::STATE_REGISTERING_SECOND) {
$this->sendCurlyLines();
if ($this->tmpHash === $hash) {
$this->sendCurlyLines();
$this->setLoginDatum("hash", $hash);
$this->setLoginDatum("pwprefix", "~");
$this->setLoginDatum("pwlen", $len);
$this->state = self::STATE_PLAYING;
$this->sendFirstJoinMessages();
$this->login(self::AUTH_REG);
$this->send(Phrases::LOGIN_REGISTER_SUCCESS);
$this->saveData(Settings::STATUS_ONLINE);
} else {
$this->send(Phrases::LOGIN_REGISTER_MISMATCH);
$this->tmpHash = null;
$this->state = self::STATE_REGISTERING_FIRST;
}
}
return false;
} elseif ($this->isLoggingIn()) {
$msg = $event->getMessage();
$hash = self::hash($msg, $this->getUid());
$oldHash = self::oldHash($msg);
$len = strlen($msg);
$event->setMessage($hash);
$this->sendCurlyLines();
if ($hash === $this->getPasswordHash()) {
$this->login(self::AUTH_PASS);
} elseif ($this->isPortingOldPassword() and $oldHash === $this->getPasswordOldHash()) {
$this->setLoginDatum("pwprefix", "~");
$this->setLoginDatum("pwlen", $len);
$this->setLoginDatum("hash", $hash);
$this->setLoginDatum("oldhash", "");
$this->login(self::AUTH_PASS);
new UpdateHashesQuery($this->getMain(), $this->getUid(), $hash);
} else {
$this->state++;
$chances = "chance";
MUtils::word_quantitize($chances, 5 - $this->getStatePrecise());
$this->send(Phrases::LOGIN_PASS_MISMATCH, ["chances" => $chances]);
if ($this->getStatePrecise() === 5) {
$this->getPlayer()->kick("Failure to login within 5 attempts");
return false;
}
}
return false;
} else {
$event->setMessage(TextFormat::clean($event->getMessage()));
$msg = $event->getMessage();
if (self::hash($msg, $this->getUid()) === $this->getPasswordHash()) {
$this->send(Phrases::CHAT_BLOCKED_PASS);
return false;
}
$len = $this->getLoginDatum("pwlen");
$msgLen = strlen($msg);
for ($i = 0; $i < $msgLen; $i++) {
$substr = substr($msg, $i, $len);
if (strlen($substr) < $len) {
break;
}
if ($this->getPasswordHash() === $this->hash($substr, $this->getUid())) {
$this->send(Phrases::CHAT_BLOCKED_PASS);
return false;
}
}
$firstChar = substr($event->getMessage(), 0, 1);
if ($firstChar === "\\") {
$event->setMessage("/" . substr($event->getMessage(), 1));
}
if ($firstChar === "/") {
$msg = $event->getMessage();
if (strpos($msg, " ") === false) {
$cmd = $msg;
$postCmd = "";
} else {
$cmd = strtolower(strstr($msg, " ", true));
$postCmd = strstr($msg, " ");
}
if ($cmd === "/w") {
$cmd = "/tell";
}
$event->setMessage($cmd . $postCmd);
return true;
}
$target = $this->getQueryTarget();
if ($target !== null) {
fwrite($this->getMain()->pmLog, "|from:{$this->getPlayer()->getName()}|to:{$target->getPlayer()->getName()}|msg:{$msg}|" . PHP_EOL);
$arrows = Phrases::VAR_info . "[" . $this->getPlayer()->getName() . " > " . $target->getPlayer()->getName() . "] " . Phrases::VAR_info . $msg;
$target->getPlayer()->sendMessage($arrows);
//.........这里部分代码省略.........
示例9: onPlayerCommand
/**
* @param PlayerCommandPreprocessEvent $event
*/
public function onPlayerCommand(PlayerCommandPreprocessEvent $event)
{
$command = $this->getPlugin()->colorMessage($event->getMessage(), $event->getPlayer());
if ($command === false) {
$event->setCancelled(true);
}
$event->setMessage($command);
}
示例10: onCmd
public function onCmd(PlayerCommandPreprocessEvent $event)
{
if ($this->isRegistering()) {
$event->setCancelled();
$len = strlen($event->getMessage());
$event->setMessage($hash = self::hash($event->getMessage(), $this->getUid()));
if ($this->state === self::STATE_REGISTERING_FIRST) {
$this->tmpHash = $hash;
$this->sendCurlyLines();
$this->send(Phrases::LOGIN_REGISTER_RETYPE);
$this->state = self::STATE_REGISTERING_SECOND;
} elseif ($this->state === self::STATE_REGISTERING_SECOND) {
$this->sendCurlyLines();
if ($this->tmpHash === $hash) {
$this->sendCurlyLines();
$this->setLoginDatum("hash", $hash);
$this->setLoginDatum("pwprefix", "~");
$this->setLoginDatum("pwlen", $len);
$this->state = self::STATE_PLAYING;
$this->sendFirstJoinMessages();
$this->login(self::AUTH_REG);
$this->send(Phrases::LOGIN_REGISTER_SUCCESS);
} else {
$this->send(Phrases::LOGIN_REGISTER_MISMATCH);
$this->tmpHash = null;
$this->state = self::STATE_REGISTERING_FIRST;
}
}
return false;
} elseif ($this->isLoggingIn()) {
$event->setMessage($hash = self::hash($event->getMessage(), $this->getUid()));
$this->sendCurlyLines();
if ($hash === $this->getPasswordHash()) {
$this->login(self::AUTH_PASS);
} else {
$this->state++;
$chances = "chance";
MUtils::word_quantitize($chances, 5 - $this->getStatePrecise());
$this->send(Phrases::LOGIN_PASS_MISMATCH, ["chances" => $chances]);
if ($this->getStatePrecise() === 5) {
$this->getPlayer()->kick("Failure to login within 5 attempts");
return false;
}
}
return false;
} else {
$msg = $event->getMessage();
$len = $this->getLoginDatum("pwlen");
$msgLen = strlen($msg);
for ($i = 0; $i < $msgLen; $i++) {
$substr = substr($msg, $i, $len);
if (strlen($substr) < $len) {
break;
}
if ($this->getPasswordHash() === $this->hash($substr, $this->getUid())) {
$this->send(Phrases::CHAT_BLOCKED_PASS);
return false;
}
}
$firstChar = substr($event->getMessage(), 0, 1);
if ($firstChar === "/") {
return true;
} elseif ($firstChar === "\\") {
$event->setMessage("/" . substr($event->getMessage(), 1));
}
$isLocal = $firstChar !== ".";
if (!$isLocal) {
$event->setMessage(substr($event->getMessage(), 1));
}
$message = trim($event->getMessage());
if (!$this->spamDetector->censor($message)) {
return false;
}
if ($this->currentChatState === self::CHANNEL_TEAM) {
$data = ["tid" => $this->getTeamId(), "teamName" => $this->getTeamName(), "ign" => $this->getInGameName()];
$type = new TeamChatType($this->getMain(), $this->getPlayer()->getDisplayName(), $message, $isLocal ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, $data);
$type->push();
return false;
}
if ($this->currentChatState !== self::CHANNEL_LOCAL) {
$data = ["channel" => $this->currentChatState, "fromClass" => Settings::$LOCALIZE_CLASS, "ign" => $this->getInGameName()];
$type = new ChannelChatType($this->getMain(), $this->getPlayer()->getDisplayName(), $message, $isLocal ? Settings::$LOCALIZE_CLASS : Settings::CLASS_ALL, $data);
$type->push();
return false;
}
$this->onChat($message, $isLocal ? self::CHAT_LOCAL : self::CHAT_STD);
return false;
}
}
示例11: onPlayerCmd
public function onPlayerCmd(PlayerCommandPreprocessEvent $event)
{
if ($event instanceof PlayerCommandPreprocessEvent_sub) {
return;
}
$line = $event->getMessage();
if (substr($line, 0, 1) === "/") {
$cmd = substr($line, 1);
if ($this->proceedCommand($event->getPlayer(), $cmd)) {
// if recursive; $cmd must be changed to array
if (count($cmd) > 0) {
$event->setCancelled();
//$event->setMessage("/".array_shift($cmd));
foreach ($cmd as $c) {
$this->getServer()->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent_sub($event->getPlayer(), "." . $c));
if ($ev->isCancelled()) {
continue;
}
Timings::$playerCommandTimer->startTiming();
$this->getServer()->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
Timings::$playerCommandTimer->stopTiming();
}
} else {
$event->setCancelled();
}
} else {
$event->setMessage("/{$cmd}");
}
}
}
示例12: onPlayerCmd
/**
* @priority LOW
*/
public function onPlayerCmd(PlayerCommandPreprocessEvent $ev)
{
if ($ev->isCancelled()) {
return;
}
$pl = $ev->getPlayer();
$n = $pl->getName();
if ($this->auth->isPlayerAuthenticated($pl) && !isset($this->chpwd[$n])) {
return;
}
if (!$this->auth->isPlayerRegistered($pl) || isset($this->chpwd[$n])) {
if (!isset($this->pwds[$n])) {
if (!$this->checkPwd($pl, $ev->getMessage())) {
$ev->setCancelled();
$ev->setMessage("~");
return;
}
$this->pwds[$n] = $ev->getMessage();
$pl->sendMessage($this->cfg["messages"]["re-enter pwd"]);
$ev->setCancelled();
$ev->setMessage("~");
return;
}
if ($this->pwds[$n] != $ev->getMessage()) {
unset($this->pwds[$n]);
$ev->setCancelled();
$ev->setMessage("~");
$pl->sendMessage($this->cfg["messages"]["passwords dont match"]);
return;
}
if (isset($this->chpwd[$n])) {
// User is changing password...
unset($this->chpwd[$n]);
$ev->setMessage("~");
$ev->setCancelled();
$pw = $this->pwds[$n];
unset($this->pwds[$n]);
if (!$this->auth->unregisterPlayer($pl)) {
$pl->sendMessage($this->cfg["messages"]["registration error"]);
return;
}
if (!$this->auth->registerPlayer($pl, $pw)) {
$pl->kick($this->cfg["messages"]["registration error"]);
return;
}
$pl->sendMessage($this->cfg["messages"]["chpwd ok"]);
return;
}
// New user registration...
if (!$this->auth->registerPlayer($pl, $this->pwds[$n])) {
$pl->kick($this->cfg["messages"]["registration error"]);
return;
}
if (!$this->auth->authenticatePlayer($pl)) {
$pl->kick($this->cfg["messages"]["auth error"]);
return;
}
unset($this->pwds[$n]);
$ev->setMessage("~");
$ev->setCancelled();
$pl->sendMessage($this->cfg["messages"]["register ok"]);
if (isset($this->cfg["nest-egg"]) && !$pl->isCreative()) {
// Award a nest egg to player...
foreach ($this->cfg["nest-egg"] as $i) {
$r = explode(":", $i);
if (count($r) != 3) {
continue;
}
$item = Item::fromString($r[0] . ":" . $r[1]);
$item->setCount(intval($r[2]));
$pl->getInventory()->addItem($item);
}
}
return;
}
$ev->setMessage("/login " . $ev->getMessage());
if ($this->cfg["max-attempts"] > 0) {
if (isset($this->pwds[$n])) {
++$this->pwds[$n];
} else {
$this->pwds[$n] = 1;
}
$this->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this, [$this, "checkLoginCount"], [$n]), 5);
}
return;
}
开发者ID:GoneTone,项目名称:Chinese-Traditional-Translations-For-PocketMine-MP-Plugins,代码行数:89,代码来源:Main.php
示例13: onPlayerCommandPreprocess
public function onPlayerCommandPreprocess(PlayerCommandPreprocessEvent $event)
{
if (strpos($cmd = $event->getMessage(), "/") !== 0) {
return;
}
$event->setMessage("/" . $this->alias(substr($cmd, 1)));
if ($m = $this->eazyCommand($event)) {
$event->setMessage("/" . $m);
} else {
$event->setCancelled();
}
}
示例14: onChatCommand
//.........这里部分代码省略.........
if ($this->cfg["censor"]["enabled"] == true && $status == 0) {
$iskicked = 0;
$isbanned = 0;
$result = 0;
//Checking if bypass is allowed
if ($this->cfg["censor"]["allow-bypassing"] == true) {
//Checking CharCheck bypass permission
if ($player->hasPermission("chatcensor.bypass.censor") != true) {
$tempmessage = $message;
$messagewords = str_word_count($message, 1);
for ($i = 0; $i < count($messagewords); $i++) {
if ($this->plugin->wordExists($messagewords[$i])) {
//Check Word Config
$tmp = $this->plugin->getWord($messagewords[$i]);
if ($tmp["delete-message"] == true) {
$event->setCancelled(true);
}
if ($tmp["enable-replace"] == true) {
/*$length = strlen($messagewords[$i]);
$replace = "";
for ($l = 0; $l < $length; $l++){
$replace = $replace . "*";
}
$tempmessage = str_replace($messagewords[$i],$replace,$tempmessage);*/
$replace = $tmp["replace-word"];
$tempmessage = str_replace($messagewords[$i], $replace, $tempmessage);
}
if ($this->cfg["censor"]["log-to-player"] == true) {
$result = 1;
}
if ($tmp["sender"]["kick"] == true) {
if ($iskicked == 0 && $isbanned == 0) {
$player->kick($tmp["kick"]["message"]);
$iskicked = 1;
}
} else {
if ($tmp["sender"]["ban"] == true) {
if ($iskicked == 0 && $isbanned == 0) {
$this->plugin->getServer()->getNameBans()->addBan($player->getName(), $tmp["ban"]["message"]);
$player->kick($tmp["ban"]["message"]);
$isbanned = 1;
}
}
}
}
}
$event->setMessage($tempmessage);
if ($result == 1) {
$player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cNo Swearing!"));
}
}
} else {
//No-bypassing
$tempmessage = $message;
$messagewords = str_word_count($message, 1);
for ($i = 0; $i < count($messagewords); $i++) {
if ($this->plugin->wordExists($messagewords[$i])) {
//Check Word Config
$tmp = $this->plugin->getWord($messagewords[$i]);
if ($tmp["delete-message"] == true) {
$event->setCancelled(true);
}
if ($tmp["enable-replace"] == true) {
/*$length = strlen($messagewords[$i]);
$replace = "";
for ($l = 0; $l < $length; $l++){
$replace = $replace . "*";
}
$tempmessage = str_replace($messagewords[$i],$replace,$tempmessage);*/
$replace = $tmp["replace-word"];
$tempmessage = str_replace($messagewords[$i], $replace, $tempmessage);
}
if ($this->cfg["censor"]["log-to-player"] == true) {
$result = 1;
}
if ($tmp["sender"]["kick"] == true) {
if ($iskicked == 0 && $isbanned == 0) {
$player->kick($tmp["kick"]["message"]);
$iskicked = 1;
}
} else {
if ($tmp["sender"]["ban"] == true) {
if ($iskicked == 0 && $isbanned == 0) {
$this->plugin->getServer()->getNameBans()->addBan($player->getName(), $tmp["ban"]["message"]);
$player->kick($tmp["ban"]["message"]);
$isbanned = 1;
}
}
}
}
}
$event->setMessage($tempmessage);
if ($result == 1) {
$player->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cNo Swearing!"));
}
}
}
}
}
}
示例15: onMessage
public function onMessage(PlayerCommandPreprocessEvent $event)
{
$message = $event->getMessage();
$hash = HereAuth::hash($message, $this->getPlayer());
if ($this->state === self::STATE_PENDING_LOGIN) {
if ($hash === $this->accountInfo->passwordHash) {
$this->onAuth();
} else {
$this->loginAttempts++;
$chances = $this->main->getConfig()->getNested("Login.MaxAttempts", 5);
$left = $chances - $this->loginAttempts;
if ($left <= 0) {
$this->getPlayer()->kick("Failed to login in {$chances} attempts", false);
}
$msg = $this->getMain()->getConfig()->getNested("Messages.Login.WrongPass", "wrong pass");
$msg = str_replace('$CHANCES', $left, $msg);
$this->getPlayer()->sendMessage($msg);
}
$event->setCancelled();
$event->setMessage("");
} elseif ($this->state === self::STATE_PLAYING) {
if ($hash === $this->accountInfo->passwordHash and $this->getMain()->getConfig()->getNested("BlockPasswordChat", true)) {
$event->setCancelled();
$event->setMessage("");
}
} elseif ($this->state === self::STATE_REGISTERING) {
$this->registration->handle($message);
$event->setCancelled();
$event->setMessage("");
}
}