Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 28th, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace FactionsPro;
  4.  
  5. use pocketmine\plugin\PluginBase;
  6. use pocketmine\command\{Command, CommandSender};
  7. use pocketmine\event\Listener;
  8. use pocketmine\event\block\BlockBreakEvent;
  9. use pocketmine\event\player\{PlayerJoinEvent, PlayerChatEvent};
  10. use pocketmine\{Server, Player};
  11. use pocketmine\event\entity\EntityDamageByEntityEvent;
  12. use pocketmine\utils\{Config, TextFormat};
  13. use pocketmine\event\entity\EntityDamageEvent;
  14. use pocketmine\block\Snow;
  15. use pocketmine\math\Vector3;
  16. use pocketmine\entity\{Skeleton, Pig, Chicken, Zombie, Creeper, Cow, Spider, Blaze, Ghast};
  17. use pocketmine\level\{Position, Level};
  18.  
  19. class FactionMain extends PluginBase implements Listener {
  20.    
  21.     public $db;
  22.     public $prefs;
  23.     public $war_req = [];
  24.     public $wars = [];
  25.     public $war_players = [];
  26.     public $antispam;
  27.     public $purechat;
  28.     public $esssentialspe;
  29.     public $factionChatActive = [];
  30.     public $allyChatActive = [];
  31.     private $prefix = "§7[§6Void§bFactions§cPE§7]";
  32.    
  33.     const HEX_SYMBOL = "e29688";
  34.    
  35.     public function onLoad(): void{
  36.         $this->getLogger()->info("FactionsPro is being enabled - Please wait whilst our Loading system becomes visible.");
  37.     }
  38.     public function onEnable(): void{
  39.         @mkdir($this->getDataFolder());
  40.         if (!file_exists($this->getDataFolder() . "BannedNames.txt")) {
  41.             $file = fopen($this->getDataFolder() . "BannedNames.txt", "w");
  42.             $txt = "Admin:admin:Staff:staff:Owner:owner:Builder:builder:Op:OP:op";
  43.             fwrite($file, $txt);
  44.         $this->getLogger()->info("FactionsPro has been enabled with success. If any errors popup after enabled, then let us know.");
  45.         }
  46.         $this->getServer()->getPluginManager()->registerEvents(new FactionListener($this), $this);
  47.         $this->antispam = $this->getServer()->getPluginManager()->getPlugin("AntiSpamPro");
  48.         if (!$this->antispam) {
  49.             $this->getLogger()->info("AntiSpamPro is not installed. If you want to ban rude Faction names, then AntiSpamPro needs to be installed. Disabling Rude faction names system.");
  50.         }
  51.         $this->purechat = $this->getServer()->getPluginManager()->getPlugin("PureChat");
  52.         if (!$this->purechat) {
  53.             $this->getLogger()->info("PureChat is not installed. If you want to display Faction ranks in chat, then PureChat needs to be installed. Disabling Faction chat system.");
  54.         }
  55.         $this->essentialspe = $this->getServer()->getPluginManager()->getPlugin("EssentialsPE");
  56.         if (!$this->essentialspe) {
  57.             $this->getLogger()->info("EssentialsPE is not installed. If you want to use the new Faction Raiding system, then EssentialsPE needs to be installed. Disabling Raiding system.");
  58.         }
  59.     $this->economyapi = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
  60.     if (!$this->economyapi) {
  61.         $this->getLogger()->info("EconomyAPI is not installed. If you want to use the Faction Values system, then EconomyAPI needs to be installed. Disabling the Factions Value system.");
  62.     }
  63.         $this->fCommand = new FactionCommands($this);
  64.         $this->prefs = new Config($this->getDataFolder() . "Prefs.yml", CONFIG::YAML, array(
  65.             "MaxFactionNameLength" => 15,
  66.             "MaxPlayersPerFaction" => 30,
  67.             "OnlyLeadersAndOfficersCanInvite" => true,
  68.             "OfficersCanClaim" => false,
  69.         "ClaimingEnabled" => true,
  70.             "PlotSize" => 16,
  71.             "PlayersNeededInFactionToClaimAPlot" => 5,
  72.             "PowerNeededToClaimAPlot" => 1000,
  73.             "PowerNeededToSetOrUpdateAHome" => 250,
  74.             "PowerGainedPerPlayerInFaction" => 50,
  75.             "PowerGainedPerKillingAnEnemy" => 10,
  76.             "PowerGainedPerAlly" => 100,
  77.             "AllyLimitPerFaction" => 5,
  78.             "TheDefaultPowerEveryFactionStartsWith" => 0,
  79.         "EnableOverClaim" => true,
  80.             "ClaimWorlds" => [],
  81.             "AllowChat" => true,
  82.             "AllowFactionPvp" => false,
  83.             "AllowAlliedPvp" => false,
  84.             "BroadcastFactionCreation" => true,
  85.             "FactionCreationBroadcast" => "%PLAYER% created a faction named %FACTION%",
  86.             "BroadcastFactionDisband" => true,
  87.             "FactionDisbandBroadcast" => "The Faction named %FACTION% was disbaned by %PLAYER%",
  88.             "defaultFactionBalance" => 0,
  89.         "MoneyGainedPerPlayerInFaction" => 20,
  90.         "MoneyGainedPerAlly" => 50,
  91.             "MoneyNeededToClaimAPlot" => 0,
  92.         "MOTDTime" => 60,
  93.         "InviteTime" => 60,
  94.         "AllyTimes" => 60,
  95.         "OurAllies" => "Your allies",
  96.         "TopMoney" => "Top 10 Richest factions",
  97.         "TopSTR" => "Top 10 BEST Factions",
  98.         "EnoughToOverClaim" => "§bYou have enough STR power to overclaim this plot! Now, Type §3/f overclaim to overclaim this plot if you want.",
  99.         "NotEnoughToOC" => "§cI'm sorry, but you do not have enough STR to overclaim this land.",
  100.         "DisabledMessage" => "§cThis command §cis disabled!",
  101.         "ServerName" => "§6Void§bFactions§cPE",
  102.                 "pluginprefix" => "§7[§6Void§bFactions§cPE§7]",
  103.                 "spawnerPrices" => [
  104.                     "skeleton" => 500,
  105.                     "pig" => 200,
  106.                     "chicken" => 100,
  107.                     "iron golem" => 5000,
  108.                     "zombie" => 800,
  109.                     "creeper" => 4000,
  110.                     "cow" => 700,
  111.                     "spider" => 500,
  112.                     "magma" => 10000,
  113.                     "ghast" => 10000,
  114.                     "blaze" => 15000,
  115.             "empty" => 100
  116.                 ],
  117.         ));
  118.         $this->prefix = $this->prefs->get("pluginprefix", $this->prefix);
  119.         if(sqrt($size = $this->prefs->get("PlotSize")) % 2 !== 0){
  120.             $this->getLogger()->notice("Square Root Of Plot Size ($size) Must Not Be An unknown Number in the plugin! (The size was Currently: ".(sqrt($size = $this->prefs->get("PlotSize"))).")");
  121.             $this->getLogger()->notice("Available Sizes: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024");
  122.             $this->getLogger()->notice("Plot Size Set To 16 automatically");
  123.             $this->prefs->set("PlotSize", 16);
  124.         }
  125.         $this->db = new \SQLite3($this->getDataFolder() . "FactionsPro.db");
  126.         $this->db->exec("CREATE TABLE IF NOT EXISTS master (player TEXT PRIMARY KEY COLLATE NOCASE, faction TEXT, rank TEXT);");
  127.         $this->db->exec("CREATE TABLE IF NOT EXISTS confirm (player TEXT PRIMARY KEY COLLATE NOCASE, faction TEXT, invitedby TEXT, timestamp INT);");
  128.         $this->db->exec("CREATE TABLE IF NOT EXISTS alliance (player TEXT PRIMARY KEY COLLATE NOCASE, faction TEXT, requestedby TEXT, timestamp INT);");
  129.         $this->db->exec("CREATE TABLE IF NOT EXISTS motdrcv (player TEXT PRIMARY KEY, timestamp INT);");
  130.         $this->db->exec("CREATE TABLE IF NOT EXISTS motd (faction TEXT PRIMARY KEY, message TEXT);");
  131.         $this->db->exec("CREATE TABLE IF NOT EXISTS plots(faction TEXT PRIMARY KEY, x1 INT, z1 INT, x2 INT, z2 INT);");
  132.         $this->db->exec("CREATE TABLE IF NOT EXISTS home(faction TEXT PRIMARY KEY, x INT, y INT, z INT, world TEXT);");
  133.         $this->db->exec("CREATE TABLE IF NOT EXISTS strength(faction TEXT PRIMARY KEY, power INT);");
  134.         $this->db->exec("CREATE TABLE IF NOT EXISTS allies(ID INT PRIMARY KEY,faction1 TEXT, faction2 TEXT);");
  135.         $this->db->exec("CREATE TABLE IF NOT EXISTS enemies(ID INT PRIMARY KEY,faction1 TEXT, faction2 TEXT);");
  136.         $this->db->exec("CREATE TABLE IF NOT EXISTS alliescountlimit(faction TEXT PRIMARY KEY, count INT);");
  137.        
  138.         $this->db->exec("CREATE TABLE IF NOT EXISTS balance(faction TEXT PRIMARY KEY, cash INT)");
  139.         try{
  140.             $this->db->exec("ALTER TABLE plots ADD COLUMN world TEXT default null");
  141.             Server::getInstance()->getLogger()->info(TextFormat::GREEN . "FactionPro: Added 'world' column to plots");
  142.         }catch(\ErrorException $ex){
  143.         }
  144.     }
  145.     public function onCommand(CommandSender $sender, Command $command, string $label, array $args) :bool {
  146.         return $this->fCommand->onCommand($sender, $command, $label, $args);
  147.     }
  148.     public function setEnemies($faction1, $faction2) {
  149.         $stmt = $this->db->prepare("INSERT INTO enemies (faction1, faction2) VALUES (:faction1, :faction2);");
  150.         $stmt->bindValue(":faction1", $faction1);
  151.         $stmt->bindValue(":faction2", $faction2);
  152.         $stmt->execute();
  153.     }
  154.    
  155.     public function areEnemies($faction1, $faction2) {
  156.         $result = $this->db->query("SELECT ID FROM enemies WHERE faction1 = '$faction1' AND faction2 = '$faction2';");
  157.         $resultArr = $result->fetchArray(SQLITE3_ASSOC);
  158.         if (empty($resultArr) == false) {
  159.             return true;
  160.         }
  161.     }
  162.    
  163.     public function isInFaction($player) {
  164.         $result = $this->db->query("SELECT player FROM master WHERE player='$player';");
  165.         $array = $result->fetchArray(SQLITE3_ASSOC);
  166.         return empty($array) == false;
  167.     }
  168.    
  169.     public function getFaction($player) {
  170.         $faction = $this->db->query("SELECT faction FROM master WHERE player='$player';");
  171.         $factionArray = $faction->fetchArray(SQLITE3_ASSOC);
  172.         return $factionArray["faction"];
  173.     }
  174.    
  175.     public function setFactionPower($faction, $power) {
  176.         if ($power < 0) {
  177.             $power = 0;
  178.         }
  179.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO strength (faction, power) VALUES (:faction, :power);");
  180.         $stmt->bindValue(":faction", $faction);
  181.         $stmt->bindValue(":power", $power);
  182.         $stmt->execute();
  183.     }
  184.     public function setAllies($faction1, $faction2) {
  185.         $stmt = $this->db->prepare("INSERT INTO allies (faction1, faction2) VALUES (:faction1, :faction2);");
  186.         $stmt->bindValue(":faction1", $faction1);
  187.         $stmt->bindValue(":faction2", $faction2);
  188.         $stmt->execute();
  189.     }
  190.     public function areAllies($faction1, $faction2) {
  191.         $result = $this->db->query("SELECT ID FROM allies WHERE faction1 = '$faction1' AND faction2 = '$faction2';");
  192.         $resultArr = $result->fetchArray(SQLITE3_ASSOC);
  193.         if (empty($resultArr) == false) {
  194.             return true;
  195.         }
  196.     }
  197.     public function updateAllies($faction) {
  198.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO alliescountlimit(faction, count) VALUES (:faction, :count);");
  199.         $stmt->bindValue(":faction", $faction);
  200.         $result = $this->db->query("SELECT ID FROM allies WHERE faction1='$faction';");
  201.         $i = 0;
  202.         while ($resultArr = $result->fetchArray(SQLITE3_ASSOC)) {
  203.             $i = $i + 1;
  204.         }
  205.         $stmt->bindValue(":count", (int) $i);
  206.         $stmt->execute();
  207.     }
  208.     public function getAlliesCount($faction) {
  209.         $result = $this->db->query("SELECT count FROM alliescountlimit WHERE faction = '$faction';");
  210.         $resultArr = $result->fetchArray(SQLITE3_ASSOC);
  211.         return (int) $resultArr["count"];
  212.     }
  213.     public function getAlliesLimit() {
  214.         return (int) $this->prefs->get("AllyLimitPerFaction");
  215.     }
  216.     public function deleteAllies($faction1, $faction2) {
  217.         $stmt = $this->db->prepare("DELETE FROM allies WHERE faction1 = '$faction1' AND faction2 = '$faction2';");
  218.         $stmt->execute();
  219.     }
  220.     public function getFactionPower($faction) {
  221.         $result = $this->db->query("SELECT power FROM strength WHERE faction = '$faction';");
  222.         $resultArr = $result->fetchArray(SQLITE3_ASSOC);
  223.         return (int) $resultArr["power"];
  224.     }
  225.     public function addFactionPower($faction, $power) {
  226.         if ($this->getFactionPower($faction) + $power < 0) {
  227.             $power = $this->getFactionPower($faction);
  228.         }
  229.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO strength (faction, power) VALUES (:faction, :power);");
  230.         $stmt->bindValue(":faction", $faction);
  231.         $stmt->bindValue(":power", $this->getFactionPower($faction) + $power);
  232.         $stmt->execute();
  233.     }
  234.     public function subtractFactionPower($faction, $power) {
  235.         if ($this->getFactionPower($faction) - $power < 0) {
  236.             $power = $this->getFactionPower($faction);
  237.         }
  238.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO strength (faction, power) VALUES (:faction, :power);");
  239.         $stmt->bindValue(":faction", $faction);
  240.         $stmt->bindValue(":power", $this->getFactionPower($faction) - $power);
  241.         $stmt->execute();
  242.     }
  243.     public function isLeader($player) {
  244.         $faction = $this->db->query("SELECT rank FROM master WHERE player='$player';");
  245.         $factionArray = $faction->fetchArray(SQLITE3_ASSOC);
  246.         return $factionArray["rank"] == "Leader";
  247.     }
  248.     public function isOfficer($player) {
  249.         $faction = $this->db->query("SELECT rank FROM master WHERE player='$player';");
  250.         $factionArray = $faction->fetchArray(SQLITE3_ASSOC);
  251.         return $factionArray["rank"] == "Officer";
  252.     }
  253.     public function isMember($player) {
  254.         $faction = $this->db->query("SELECT rank FROM master WHERE player='$player';");
  255.         $factionArray = $faction->fetchArray(SQLITE3_ASSOC);
  256.         return $factionArray["rank"] == "Member";
  257.     }
  258.     public function getPlayersInFactionByRank($s, $faction, $rank) {
  259.         if ($rank != "Leader") {
  260.             $rankname = $rank . 's';
  261.         } else {
  262.             $rankname = $rank;
  263.         }
  264.         $team = "";
  265.         $result = $this->db->query("SELECT player FROM master WHERE faction='$faction' AND rank='$rank';");
  266.         $row = array();
  267.         $i = 0;
  268.         while ($resultArr = $result->fetchArray(SQLITE3_ASSOC)) {
  269.             $row[$i]['player'] = $resultArr['player'];
  270.             if ($this->getServer()->getPlayer($row[$i]['player']) instanceof Player) {
  271.                 $team .= TextFormat::ITALIC . TextFormat::AQUA . $row[$i]['player'] . TextFormat::GREEN . "[ON]" . TextFormat::RESET . TextFormat::WHITE . "||" . TextFormat::RESET;
  272.             } else {
  273.                 $team .= TextFormat::ITALIC . TextFormat::AQUA . $row[$i]['player'] . TextFormat::RED . "[OFF]" . TextFormat::RESET . TextFormat::WHITE . "||" . TextFormat::RESET;
  274.             }
  275.             $i = $i + 1;
  276.         }
  277.         $s->sendMessage($this->formatMessage("~ *<$rankname> of |$faction|* ~", true));
  278.         $s->sendMessage($team);
  279.     }
  280.     public function getAllAllies($s, $faction) {
  281.         $team = "";
  282.         $result = $this->db->query("SELECT faction2 FROM allies WHERE faction1='$faction';");
  283.         $row = array();
  284.         $i = 0;
  285.         while ($resultArr = $result->fetchArray(SQLITE3_ASSOC)) {
  286.             $row[$i]['faction2'] = $resultArr['faction2'];
  287.             $team .= TextFormat::ITALIC . TextFormat::GREEN . $row[$i]['faction2'] . TextFormat::RESET . TextFormat::WHITE . "§2,§a " . TextFormat::RESET;
  288.             $i = $i + 1;
  289.         }
  290.     $allies = $this->prefs->get("OurAllies");
  291.         $s->sendMessage($this->formatMessage("$allies", true));
  292.         $s->sendMessage($team);
  293.     }
  294.     public function sendListOfTop10FactionsTo($s) {
  295.         $tf = "";
  296.         $result = $this->db->query("SELECT faction FROM strength ORDER BY power DESC LIMIT 10;");
  297.         $row = array();
  298.         $i = 0;
  299.     $topstr = $this->prefs->get("TopSTR");
  300.         $s->sendMessage("$topstr", true);
  301.         while ($resultArr = $result->fetchArray(SQLITE3_ASSOC)) {
  302.             $j = $i + 1;
  303.             $cf = $resultArr['faction'];
  304.             $pf = $this->getFactionPower($cf);
  305.             $df = $this->getNumberOfPlayers($cf);
  306.             $s->sendMessage(TextFormat::ITALIC . TextFormat::GOLD . "§6§l$j -> " . TextFormat::GREEN . "§r§d$cf" . TextFormat::GOLD . " §b| " . TextFormat::RED . "§e$pf STR" . TextFormat::GOLD . " §b| " . TextFormat::LIGHT_PURPLE . "§a$df/50" . TextFormat::RESET);
  307.             $i = $i + 1;
  308.         }
  309.     }
  310.     public function getPlayerFaction($player) {
  311.         $faction = $this->db->query("SELECT faction FROM master WHERE player='$player';");
  312.         $factionArray = $faction->fetchArray(SQLITE3_ASSOC);
  313.         return $factionArray["faction"];
  314.     }
  315.     public function getLeader($faction) {
  316.         $leader = $this->db->query("SELECT player FROM master WHERE faction='$faction' AND rank='Leader';");
  317.         $leaderArray = $leader->fetchArray(SQLITE3_ASSOC);
  318.         return $leaderArray['player'];
  319.     }
  320.     public function factionExists($faction) {
  321.         $result = $this->db->query("SELECT player FROM master WHERE faction='$faction';");
  322.         $array = $result->fetchArray(SQLITE3_ASSOC);
  323.         return empty($array) == false;
  324.     }
  325.     public function sameFaction($player1, $player2) {
  326.         $faction = $this->db->query("SELECT faction FROM master WHERE player='$player1';");
  327.         $player1Faction = $faction->fetchArray(SQLITE3_ASSOC);
  328.         $faction = $this->db->query("SELECT faction FROM master WHERE player='$player2';");
  329.         $player2Faction = $faction->fetchArray(SQLITE3_ASSOC);
  330.         return $player1Faction["faction"] == $player2Faction["faction"];
  331.     }
  332.     public function getNumberOfPlayers($faction) {
  333.         $query = $this->db->query("SELECT COUNT(player) as count FROM master WHERE faction='$faction';");
  334.         $number = $query->fetchArray();
  335.         return $number['count'];
  336.     }
  337.     public function isFactionFull($faction) {
  338.         return $this->getNumberOfPlayers($faction) >= $this->prefs->get("MaxPlayersPerFaction");
  339.     }
  340.     public function isNameBanned($name) {
  341.         $bannedNames = file_get_contents($this->getDataFolder() . "BannedNames.txt");
  342.         $isbanned = false;
  343.         if (isset($name) && $this->antispam && $this->antispam->getProfanityFilter()->hasProfanity($name)) $isbanned = true;
  344.         return (strpos(strtolower($bannedNames), strtolower($name)) > 0 || $isbanned);
  345.     }
  346.     public function newPlot($faction, $x1, $z1, $x2, $z2) {
  347.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO plots (faction, x1, z1, x2, z2) VALUES (:faction, :x1, :z1, :x2, :z2);");
  348.         $stmt->bindValue(":faction", $faction);
  349.         $stmt->bindValue(":x1", $x1);
  350.         $stmt->bindValue(":z1", $z1);
  351.         $stmt->bindValue(":x2", $x2);
  352.         $stmt->bindValue(":z2", $z2);
  353.         $stmt->execute();
  354.     }
  355.     public function drawPlot($sender, $faction, $x, $y, $z, $level, $size) {
  356.         $arm = ($size - 1) / 2;
  357.         $block = new Snow();
  358.         if ($this->cornerIsInPlot($x + $arm, $z + $arm, $x - $arm, $z - $arm)) {
  359.             $claimedBy = $this->factionFromPoint($x, $z);
  360.             $power_claimedBy = $this->getFactionPower($claimedBy);
  361.             $power_sender = $this->getFactionPower($faction);
  362.            
  363.         if ($this->prefs->get("EnableOverClaim")) {
  364.                 if ($power_sender < $power_claimedBy) {
  365.             $noclaim = $this->prefs->get("NotEnoughToOC");
  366.                     $sender->sendMessage($this->formatMessage("$noclaim", true));
  367.                 } else {
  368.             $yesclaim = $this->prefs->get("EnoughToOverClaim");
  369.                     $sender->sendMessage($this->formatMessage("$yesclaim", true));
  370.                 }
  371.                 return false;
  372.             } else {
  373.         $ocmessage = $this->prefs->get("DisabledMessage");
  374.                 $sender->sendMessage($this->formatMessage("$ocmessage", true));
  375.                 return false;
  376.         }
  377.         }
  378.         $level->setBlock(new Vector3($x + $arm, $y, $z + $arm), $block);
  379.         $level->setBlock(new Vector3($x - $arm, $y, $z - $arm), $block);
  380.         $this->newPlot($faction, $x + $arm, $z + $arm, $x - $arm, $z - $arm);
  381.         return true;
  382.     }
  383.     public function isInPlot($player) {
  384.         $x = $player->getFloorX();
  385.         $z = $player->getFloorZ();
  386.         $result = $this->db->query("SELECT faction FROM plots WHERE $x <= x1 AND $x >= x2 AND $z <= z1 AND $z >= z2;");
  387.         $array = $result->fetchArray(SQLITE3_ASSOC);
  388.         return empty($array) == false;
  389.     }
  390.     public function factionFromPoint($x, $z) {
  391.         $result = $this->db->query("SELECT faction FROM plots WHERE $x <= x1 AND $x >= x2 AND $z <= z1 AND $z >= z2;");
  392.         $array = $result->fetchArray(SQLITE3_ASSOC);
  393.         return $array["faction"];
  394.     }
  395.     public function inOwnPlot($player) {
  396.         $playerName = $player->getName();
  397.         $x = $player->getFloorX();
  398.         $z = $player->getFloorZ();
  399.         return $this->getPlayerFaction($playerName) == $this->factionFromPoint($x, $z);
  400.     }
  401.     public function pointIsInPlot($x, $z) {
  402.         $result = $this->db->query("SELECT faction FROM plots WHERE $x <= x1 AND $x >= x2 AND $z <= z1 AND $z >= z2;");
  403.         $array = $result->fetchArray(SQLITE3_ASSOC);
  404.         return !empty($array);
  405.     }
  406.     public function cornerIsInPlot($x1, $z1, $x2, $z2) {
  407.         return($this->pointIsInPlot($x1, $z1) || $this->pointIsInPlot($x1, $z2) || $this->pointIsInPlot($x2, $z1) || $this->pointIsInPlot($x2, $z2));
  408.     }
  409.     public function formatMessage($string, $confirm = false) {
  410.         if ($confirm) {
  411.             return TextFormat::GREEN . "$string";
  412.         } else {
  413.             return TextFormat::YELLOW . "$string";
  414.         }
  415.     }
  416.     public function motdWaiting($player) {
  417.         $stmt = $this->db->query("SELECT player FROM motdrcv WHERE player='$player';");
  418.         $array = $stmt->fetchArray(SQLITE3_ASSOC);
  419.         return !empty($array);
  420.     }
  421.     public function getMOTDTime($player) {
  422.         $stmt = $this->db->query("SELECT timestamp FROM motdrcv WHERE player='$player';");
  423.         $array = $stmt->fetchArray(SQLITE3_ASSOC);
  424.         return $array['timestamp'];
  425.     }
  426.     public function setMOTD($faction, $player, $msg) {
  427.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO motd (faction, message) VALUES (:faction, :message);");
  428.         $stmt->bindValue(":faction", $faction);
  429.         $stmt->bindValue(":message", $msg);
  430.         $result = $stmt->execute();
  431.         $this->db->query("DELETE FROM motdrcv WHERE player='$player';");
  432.     }
  433.     public function getMapBlock(){
  434.        
  435.     $symbol = hex2bin(self::HEX_SYMBOL);
  436.        
  437.     return $symbol;
  438.     }
  439.     public function getBalance($faction){
  440.         $stmt = $this->db->query("SELECT * FROM balance WHERE `faction` LIKE '$faction';");
  441.         $array = $stmt->fetchArray(SQLITE3_ASSOC);
  442.         if(!$array){
  443.             $this->setBalance($faction, $this->prefs->get("defaultFactionBalance", 0));
  444.             $this->getBalance($faction);
  445.         }
  446.         return $array["cash"];
  447.     }
  448.     public function setBalance($faction, int $money){
  449.         $stmt = $this->db->prepare("INSERT OR REPLACE INTO balance (faction, cash) VALUES (:faction, :cash);");
  450.         $stmt->bindValue(":faction", $faction);
  451.         $stmt->bindValue(":cash", $money);
  452.         return $stmt->execute();
  453.     }
  454.     public function addToBalance($faction, int $money){
  455.         if($money < 0) return false;
  456.         return $this->setBalance($faction, $this->getBalance($faction) + $money);
  457.     }
  458.     public function takeFromBalance($faction, int $money){
  459.         if($money < 0) return false;
  460.         return $this->setBalance($faction, $this->getBalance($faction) - $money);
  461.     }
  462.     public function sendListOfTop10RichestFactionsTo(Player $s){
  463.         $result = $this->db->query("SELECT * FROM balance ORDER BY cash DESC LIMIT 10;");
  464.         $i = 0;
  465.     $topmoney = $this->prefs->get("TopMoney");
  466.         $s->sendMessage("$topmoney", true);
  467.         while($resultArr = $result->fetchArray(SQLITE3_ASSOC)){
  468.             var_dump($resultArr);
  469.             $j = $i + 1;
  470.             $cf = $resultArr['faction'];
  471.             $pf = $resultArr["cash"];
  472.             $s->sendMessage(TextFormat::BOLD.TextFormat::GOLD.$j.". ".TextFormat::RESET.TextFormat::AQUA.$cf.TextFormat::RED.TextFormat::BOLD." §c- ".TextFormat::LIGHT_PURPLE."§d$".$pf);
  473.             $i = $i + 1;
  474.         }
  475.     }
  476.     public function getSpawnerPrice(string $type) : int {
  477.         $sp = $this->prefs->get("spawnerPrices");
  478.         if(isset($sp[$type])) return $sp[$type];
  479.         return 0;
  480.     }
  481.     public function getEconomy(){
  482.         $pl = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
  483.         if(!$pl) return $pl;
  484.         if(!$pl->isEnabled()) return null;
  485.         return $pl;
  486.     }
  487.    
  488.     public function onDisable(): void {
  489.         $this->db->close();
  490.     }
  491. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top