Skip to content

Commit

Permalink
Fix #40 - xxx on null (no we.session perm), fix meta out of range on
Browse files Browse the repository at this point in the history
rotate
  • Loading branch information
inxomnyaa committed Jan 8, 2018
1 parent 8f492bc commit 76c12f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: MagicWE2
main: xenialdan\MagicWE2\Loader
version: 5.7.0
version: 5.7.1
api:
- 3.0.0-ALPHA10
load: STARTUP
Expand Down
2 changes: 1 addition & 1 deletion src/xenialdan/MagicWE2/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,6 @@ public static function rotationMetaHelper(Block $block, $timesRotate = 1){
$currentrotationindex += $timesRotate;
#return $rotation[($currentrotationindex % count($rotation))];
$extra = intval($meta / count($rotation));
return $rotation[$currentrotationindex % count($rotation)] + ($extra * count($rotation));
return $rotation[$currentrotationindex % count($rotation)] + ($extra * count($rotation)) % 16;
}
}
24 changes: 20 additions & 4 deletions src/xenialdan/MagicWE2/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ public function onBreak(BlockBreakEvent $event){
private function onBreakBlock(BlockBreakEvent $event){
if (!is_null($event->getItem()->getNamedTagEntry("MagicWE"))){
$event->setCancelled();
/** @var Session $session */
$session = API::getSession($event->getPlayer());
if (is_null($session)){
throw new \Exception("No session was created - probably no permission to use " . $this->owner->getName());
}
switch ($event->getItem()->getId()){
case ItemIds::WOODEN_AXE: {
/** @var Session $session */
if (!($session = API::getSession($event->getPlayer()))->isWandEnabled()){
if (!$session->isWandEnabled()){
$event->getPlayer()->sendMessage(Loader::$prefix . TextFormat::RED . "The wand tool is disabled. Use //togglewand to re-enable it");//TODO #translation
break;
}
$selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($event->getBlock()->getLevel())); // TODO check if the selection inside of the session updates
if (is_null($selection)){
throw new \Error("No selection created - Check the console for errors");
}
$event->getPlayer()->sendMessage($selection->setPos1(new Position($event->getBlock()->x, $event->getBlock()->y, $event->getBlock()->z, $event->getBlock()->getLevel())));
break;
}
case ItemIds::STICK: {
/** @var Session $session */
if (!($session = API::getSession($event->getPlayer()))->isDebugStickEnabled()){
if (!$session->isDebugStickEnabled()){
$event->getPlayer()->sendMessage(Loader::$prefix . TextFormat::RED . "The debug stick is disabled. Use //toggledebug to re-enable it");//TODO #translation
break;
}
Expand All @@ -77,6 +85,11 @@ private function onBreakBlock(BlockBreakEvent $event){
private function onRightClickBlock(PlayerInteractEvent $event){
if (!is_null($event->getItem()->getNamedTagEntry("MagicWE"))){
$event->setCancelled();
/** @var Session $session */
$session = API::getSession($event->getPlayer());
if (is_null($session)){
throw new \Exception("No session was created - probably no permission to use " . $this->owner->getName());
}
switch ($event->getItem()->getId()){
/*case ItemIds::WOODEN_SHOVEL: { //TODO Open issue on pmmp, RIGHT_CLICK_BLOCK + RIGHT_CLICK_AIR are BOTH called when right clicking a block - Turns out to be a client bug
$target = $event->getBlock();
Expand All @@ -87,17 +100,20 @@ private function onRightClickBlock(PlayerInteractEvent $event){
}*/
case ItemIds::WOODEN_AXE: {
/** @var Session $session */
if (!($session = API::getSession($event->getPlayer()))->isWandEnabled()){
if (!$session->isWandEnabled()){
$event->getPlayer()->sendMessage(Loader::$prefix . TextFormat::RED . "The wand tool is disabled. Use //togglewand to re-enable it");//TODO #translation
break;
}
$selection = $session->getLatestSelection() ?? $session->addSelection(new Selection($event->getBlock()->getLevel())); // TODO check if the selection inside of the session updates
if (is_null($selection)){
throw new \Error("No selection created - Check the console for errors");
}
$event->getPlayer()->sendMessage($selection->setPos2(new Position($event->getBlock()->x, $event->getBlock()->y, $event->getBlock()->z, $event->getBlock()->getLevel())));
break;
}
case ItemIds::STICK: {
/** @var Session $session */
if (!($session = API::getSession($event->getPlayer()))->isDebugStickEnabled()){
if (!$session->isDebugStickEnabled()){
$event->getPlayer()->sendMessage(Loader::$prefix . TextFormat::RED . "The debug stick is disabled. Use //toggledebug to re-enable it");//TODO #translation
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/xenialdan/MagicWE2/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getPos1(){

public function setPos1(Position $position){
$this->pos1 = $position;
return Loader::$prefix . TextFormat::GREEN . "Position 1 set";
return Loader::$prefix . TextFormat::GREEN . "Position 1 set to X: " . $position->getX() . " Y: " . $position->getY() . " Z: " . $position->getZ();
}

public function getPos2(){
Expand All @@ -67,7 +67,7 @@ public function getPos2(){

public function setPos2(Position $position){
$this->pos2 = $position;
return Loader::$prefix . TextFormat::GREEN . "Position 2 set";
return Loader::$prefix . TextFormat::GREEN . "Position 2 set to X: " . $position->getX() . " Y: " . $position->getY() . " Z: " . $position->getZ();
}

public function getMinVec3(){
Expand Down

0 comments on commit 76c12f4

Please sign in to comment.