Skip to content
This repository was archived by the owner on Jul 21, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions src/ChestLocker/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ class Main extends PluginBase{
const ITEM_NAME = "Chest";
const ITEM_NAME_2 = "chest";
const ITEM_ID = 54;

/** @var array */
public $status;
/** @var string */
public $data;

/**
* @param string $symbol
* @param string $message
*
* @return string
*/
public function translateColors($symbol, $message){
$message = str_replace($symbol."0", TextFormat::BLACK, $message);
$message = str_replace($symbol."1", TextFormat::DARK_BLUE, $message);
Expand Down Expand Up @@ -70,6 +77,9 @@ public function translateColors($symbol, $message){
return $message;
}

/**
* @return void
*/
public function onEnable(){
@mkdir($this->getDataFolder());
@mkdir($this->getDataFolder() . Main::_DIRECTORY);
Expand All @@ -81,6 +91,12 @@ public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
}

/**
* @param int $int
* @param string $player
*
* @return void
*/
public function setCommandStatus($int, $player){
//0 Empty
//1 Lock
Expand All @@ -90,6 +106,11 @@ public function setCommandStatus($int, $player){
}
}

/**
* @param string $player
*
* @return int
*/
public function getCommandStatus($player){
if(isset($this->status[strtolower($player)])){
return $this->status[strtolower($player)];
Expand All @@ -99,14 +120,35 @@ public function getCommandStatus($player){
}
}

/**
* @param string $player
*
* @return void
*/
public function endCommandSession($player){
unset($this->status[strtolower($player)]);
}

/**
* @param string $level
* @param string $x
* @param string $y
* @param string $z
*
* @return bool
*/
public function isChestRegistered($level, $x, $y, $z){
return file_exists($this->data . Main::_DIRECTORY . strtolower($level . "/") . strtolower($x . Main::_FILE . $y.Main::_FILE . $z . ".yml"));
}

/**
* @param string $level
* @param string $x
* @param string $y
* @param string $z
*
* @return bool|string
*/
public function getChestOwner($level, $x, $y, $z){
if(file_exists($this->data . Main::_DIRECTORY . strtolower($level . "/") . strtolower($x . Main::_FILE . $y . Main::_FILE . $z . ".yml"))){
$chest = new Config($this->data . Main::_DIRECTORY . strtolower($level . "/") . strtolower($x . Main::_FILE . $y . Main::_FILE . $z . ".yml"), Config::YAML);
Expand All @@ -116,7 +158,16 @@ public function getChestOwner($level, $x, $y, $z){
return false; //Failed: Chest not registered
}
}


/**
* @param string $level
* @param string $x
* @param string $y
* @param string $z
* @param string $player
*
* @return bool
*/
public function lockChest($level, $x, $y, $z, $player){
@mkdir($this->data . Main::_DIRECTORY . strtolower($level . "/"));
if(file_exists($this->data . Main::_DIRECTORY . strtolower($level . "/") . strtolower($x . Main::_FILE . $y.Main::_FILE . $z . ".yml"))){
Expand All @@ -129,6 +180,15 @@ public function lockChest($level, $x, $y, $z, $player){
}
}

/**
* @param string $level
* @param string $x
* @param string $y
* @param string $z
* @param string $player
*
* @return int
*/
public function unlockChest($level, $x, $y, $z, $player){
if(file_exists($this->data . Main::_DIRECTORY . strtolower($level . "/") . strtolower($x . Main::_FILE . $y . Main::_FILE . $z . ".yml"))){
$chest = new Config($this->data . Main::_DIRECTORY . strtolower($level . "/") . strtolower($x . Main::_FILE . $y . Main::_FILE . $z . ".yml"), Config::YAML);
Expand Down