Skip to content

Commit

Permalink
Merge branch 'rewrite'
Browse files Browse the repository at this point in the history
  • Loading branch information
falkirks committed Apr 17, 2017
2 parents 590017d + 191e02e commit 1cd19e4
Show file tree
Hide file tree
Showing 30 changed files with 1,484 additions and 448 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
out
old
mines.yml
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Falkirks
Copyright (c) 2017 Falkirks

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 2 additions & 7 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
name: MineReset
main: minereset\MineReset
version: 2.4
main: falkirks\minereset\MineReset
version: 3.0
author: Falk
api: [1.0.0, 2.0.0, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3, 3.0.0-ALPHA4, 3.0.0-ALPHA5]
load: POSTWORLD
commands:
mine:
description: "MineReset command"
usage: "/mine <create|set|list|reset|reset-all|destroy> <name> [parameters]"
permission: minereset.command
permissions:
minereset:
default: op
Expand Down
147 changes: 147 additions & 0 deletions src/falkirks/minereset/Mine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
namespace falkirks\minereset;

use falkirks\minereset\task\ResetTask;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\math\Vector3;

/**
* Class Mine
* @package falkirks\minereset\mine
*/
class Mine{
private $pointA;
private $pointB;
private $level;
private $data;
private $name;
private $isResetting;

private $api;

/**
* Mine constructor.
* @param MineManager $api
* @param Vector3 $pointA
* @param Vector3 $pointB
* @param string $level
* @param string $name
* @param array $data
*/
public function __construct(MineManager $api, Vector3 $pointA, Vector3 $pointB, $level, string $name, array $data = []){
$this->pointA = $pointA;
$this->pointB = $pointB;
$this->level = $level;
$this->data = $data;
$this->name = $name;
$this->api = $api;

$this->isResetting = false;
}

/**
* @return Vector3
*/
public function getPointA(): Vector3{
return $this->pointA;
}

/**
* @return Vector3
*/
public function getPointB(): Vector3{
return $this->pointB;
}

public function isPointInside(Position $position): bool{
if($this->getLevel() !== null && $position->getLevel()->getId() !== $this->getLevel()->getId()){
return false;
}

return $position->getX() >= $this->getPointA()->getX()
&& $position->getX() <= $this->getPointB()->getX()
&& $position->getY() >= $this->getPointA()->getY()
&& $position->getY() <= $this->getPointB()->getY()
&& $position->getZ() >= $this->getPointA()->getZ()
&& $position->getZ() <= $this->getPointB()->getZ();
}

/**
* @return Level | null
*/
public function getLevel(){
return $this->api->getApi()->getServer()->getLevelByName($this->level);
}

/**
* @return string
*/
public function getLevelName(): string {
return $this->level;
}

/**
* @return array
*/
public function getData(): array{
return $this->data;
}

/**
* @param array $data
*/
public function setData(array $data){
$this->data = $data;
$this->getApi()->offsetSet($this->getName(), $this);
}

/**
* @return string
*/
public function getName(): string{
return $this->name;
}

/**
* @return MineManager
*/
public function getApi(): MineManager{
return $this->api;
}

/**
* @return bool
*/
public function isResetting(){
return $this->isResetting;
}

public function reset(){
if(!$this->isResetting() && $this->getLevel() !== null){
$this->isResetting = true;

$chunks = [];
$chunkClass = Chunk::class;
for ($x = $this->getPointA()->getX(); $x-16 <= $this->getPointB()->getX(); $x += 16){
for ($z = $this->getPointA()->getZ(); $z-16 <= $this->getPointB()->getZ(); $z += 16) {
$chunk = $this->getLevel()->getChunk($x >> 4, $z >> 4, true);

$chunkClass = get_class($chunk);
$chunks[Level::chunkHash($x >> 4, $z >> 4)] = $chunk->fastSerialize();
}
}

$resetTask = new ResetTask($this->getName(), $chunks, $this->getPointA(), $this->getPointB(), $this->data, $this->getLevel()->getId(), $chunkClass);
$this->getApi()->getApi()->getServer()->getScheduler()->scheduleAsyncTask($resetTask);
return true;
}
return false;
}

public function doneReset(){
$this->isResetting = false;
}

}
Loading

0 comments on commit 1cd19e4

Please sign in to comment.