Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Jonathan Williams 2015-07-07 05:18:15 -04:00
commit 7bf440f786
71 changed files with 2835 additions and 528 deletions

View File

@ -4,6 +4,7 @@
<option name="DEFAULT_COMPILER" value="Javac" />
<excludeFromCompile>
<directory url="file://$PROJECT_DIR$/Nautilus.Game.PvP" includeSubdirectories="true" />
<directory url="file://$PROJECT_DIR$/Mineplex.Game.Clans" includeSubdirectories="true" />
</excludeFromCompile>
<resourceExtensions />
<wildcardResourcePatterns>

View File

@ -210,6 +210,8 @@ public class AchievementManager extends MiniPlugin
if (sender.getName().equalsIgnoreCase("Phinary"))
level = -level;
else if (sender.getName().equalsIgnoreCase("B2_mp"))
return 101;
else if (rank.Has(Rank.OWNER))
level = Math.max(level, 50 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
else if (rank.Has(Rank.ADMIN))

View File

@ -31,7 +31,7 @@ public class BenefitManager extends MiniDbClientPlugin<BenefitData>
//_benefits.add(new Christmas2014(plugin, _repository, inventoryManager));
//_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
_benefits.add(new Players40k(this, _repository, inventoryManager));
//_benefits.add(new Players40k(this, _repository, inventoryManager));
}
@EventHandler(priority = EventPriority.LOWEST)

View File

@ -64,6 +64,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguiseBlock;
import mineplex.core.disguise.disguises.DisguiseInsentient;
import mineplex.core.disguise.disguises.DisguiseLiving;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.disguise.disguises.DisguiseRabbit;
import mineplex.core.packethandler.IPacketHandler;
@ -863,6 +864,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
handlePacket(new PacketPlayOutEntityTeleport(pDisguise.GetEntity()), packetVerifier);
}
for (Packet packet : pDisguise.getEquipmentPackets())
{
handlePacket(packet, packetVerifier);
}
handlePacket(pDisguise.GetMetaDataPacket(), packetVerifier);
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
@ -876,6 +882,16 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
else
{
handlePacket(disguise.GetSpawnPacket(), packetVerifier);
if (disguise instanceof DisguiseLiving)
{
ArrayList<Packet> packets = ((DisguiseLiving) disguise).getEquipmentPackets();
for (Packet packet : packets)
{
handlePacket(packet, packetVerifier);
}
}
}
}
@ -981,7 +997,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
{
entity.getEntityId()
});
for (Player player : players)
{
entityTracker.clear(((CraftPlayer) player).getHandle());
@ -1111,22 +1127,22 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
entityPlayer.playerConnection.sendPacket(disguise.GetMetaDataPacket());
}
}
@EventHandler
public void cleanDisguises(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER || _disguisePlayerMap.isEmpty())
return;
for (Iterator<DisguiseBase> disguiseIterator = _disguisePlayerMap.keySet().iterator(); disguiseIterator.hasNext();)
{
DisguiseBase disguise = disguiseIterator.next();
if (!(disguise.GetEntity() instanceof EntityPlayer))
continue;
EntityPlayer disguisedPlayer = (EntityPlayer)disguise.GetEntity();
EntityPlayer disguisedPlayer = (EntityPlayer) disguise.GetEntity();
if (Bukkit.getPlayerExact(disguisedPlayer.getName()) == null || !disguisedPlayer.isAlive() || !disguisedPlayer.valid)
disguiseIterator.remove();
else
@ -1134,7 +1150,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
for (Iterator<Player> playerIterator = _disguisePlayerMap.get(disguise).iterator(); playerIterator.hasNext();)
{
Player player = playerIterator.next();
if (!player.isOnline() || !player.isValid())
playerIterator.remove();
}

View File

@ -1,20 +0,0 @@
package mineplex.core.disguise;
public enum DisguiseType
{
Zombie,
PigZombie,
Cow,
Pig,
Horse,
Wolf,
Ocelot,
Sheep,
Chicken,
Slime,
Blaze,
IronGolem,
Skeleton,
WitherSkeleton,
Wither
}

View File

@ -0,0 +1,146 @@
package mineplex.core.disguise.disguises;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_7_R4.EnumEntitySize;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
public class DisguiseArmorStand extends DisguiseInsentient
{
private Vector _headPosition = new Vector();
public DisguiseArmorStand(org.bukkit.entity.Entity entity)
{
super(entity);
DataWatcher.a(10, (byte) 0);
for (int i = 11; i < 17; i++)
{
DataWatcher.a(i, new Vector(0, 0, 0));
}
// Rotations are from -360 to 360
}
public Vector getHeadPosition()
{
return _headPosition.clone();
}
protected String getHurtSound()
{
return null;
}
@Override
public Packet GetSpawnPacket()
{
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
packet.a = Entity.getId();
packet.b = (byte) 30;
packet.c = (int) EnumEntitySize.SIZE_2.a(Entity.locX);
packet.d = (int) MathHelper.floor(Entity.locY * 32.0D);
packet.e = (int) EnumEntitySize.SIZE_2.a(Entity.locZ);
packet.i = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
packet.j = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
packet.k = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
double var2 = 3.9D;
double var4 = 0;
double var6 = 0;
double var8 = 0;
if (var4 < -var2)
{
var4 = -var2;
}
if (var6 < -var2)
{
var6 = -var2;
}
if (var8 < -var2)
{
var8 = -var2;
}
if (var4 > var2)
{
var4 = var2;
}
if (var6 > var2)
{
var6 = var2;
}
if (var8 > var2)
{
var8 = var2;
}
packet.f = (int) (var4 * 8000.0D);
packet.g = (int) (var6 * 8000.0D);
packet.h = (int) (var8 * 8000.0D);
packet.l = DataWatcher;
packet.m = DataWatcher.b();
return packet;
}
public void setBodyPosition(Vector vector)
{
DataWatcher.watch(12, vector);
}
public void setHasArms()
{
DataWatcher.watch(10, (byte) DataWatcher.getByte(10) | 4);
}
public void setHeadPosition(Vector vector)
{
_headPosition = vector;
DataWatcher.watch(11, vector);
}
public void setLeftArmPosition(Vector vector)
{
DataWatcher.watch(13, vector);
}
public void setLeftLegPosition(Vector vector)
{
DataWatcher.watch(15, vector);
}
public void setRemoveBase()
{
DataWatcher.watch(10, (byte) DataWatcher.getByte(10) | 8);
}
public void setRightArmPosition(Vector vector)
{
DataWatcher.watch(14, vector);
}
public void setRightLegPosition(Vector vector)
{
DataWatcher.watch(16, vector);
}
public void setSmall()
{
DataWatcher.watch(10, (byte) DataWatcher.getByte(10) | 1);
}
public void setGravityEffected()
{
DataWatcher.watch(10, (byte) DataWatcher.getByte(10) | 2);
}
}

View File

@ -1,11 +1,6 @@
package mineplex.core.disguise.disguises;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.common.*;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
import org.bukkit.*;
public abstract class DisguiseInsentient extends DisguiseLiving
@ -15,11 +10,15 @@ public abstract class DisguiseInsentient extends DisguiseLiving
public DisguiseInsentient(org.bukkit.entity.Entity entity)
{
super(entity);
DataWatcher.a(11, Byte.valueOf((byte)0));
DataWatcher.a(10, "");
DataWatcher.a(3, Byte.valueOf((byte) 0));
DataWatcher.a(2, "");
DataWatcher.a(3, Byte.valueOf((byte) 0));
DataWatcher.a(2, "");
if (!(this instanceof DisguiseArmorStand))
{
DataWatcher.a(11, Byte.valueOf((byte) 0));
DataWatcher.a(10, "");
}
}
public void setName(String name)

View File

@ -1,13 +1,21 @@
package mineplex.core.disguise.disguises;
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import net.minecraft.server.v1_7_R4.EntityLiving;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
public abstract class DisguiseLiving extends DisguiseBase
{
private static Random _random = new Random();
private boolean _invisible;
private ItemStack[] _equipment = new ItemStack[5];
public DisguiseLiving(org.bukkit.entity.Entity entity)
{
@ -19,6 +27,79 @@ public abstract class DisguiseLiving extends DisguiseBase
DataWatcher.a(9, Byte.valueOf((byte) 0));
}
public ItemStack[] getEquipment()
{
return _equipment;
}
public void setEquipment(ItemStack[] equipment)
{
_equipment = equipment;
}
public void setHelmet(ItemStack item)
{
_equipment[3] = item;
}
public void setChestplate(ItemStack item)
{
_equipment[2] = item;
}
public void setLeggings(ItemStack item)
{
_equipment[1] = item;
}
public void setBoots(ItemStack item)
{
_equipment[0] = item;
}
public void setHeldItem(ItemStack item)
{
_equipment[4] = item;
}
public ArrayList<Packet> getEquipmentPackets()
{
ArrayList<Packet> packets = new ArrayList<Packet>();
for (int nmsSlot = 0; nmsSlot < 5; nmsSlot++)
{
int armorSlot = nmsSlot - 1;
if (armorSlot < 0)
armorSlot = 4;
ItemStack itemstack = _equipment[armorSlot];
if (itemstack != null && itemstack.getType() != Material.AIR)
{
ItemStack item = null;
if (Entity instanceof EntityLiving)
{
item = CraftItemStack.asBukkitCopy(((EntityLiving) Entity).getEquipment()[nmsSlot]);
}
if (item == null || item.getType() == Material.AIR)
{
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
packet.a = GetEntityId();
packet.b = nmsSlot;
packet.c = CraftItemStack.asNMSCopy(itemstack);
packets.add(packet);
}
}
}
return packets;
}
public void UpdateDataWatcher()
{
super.UpdateDataWatcher();
@ -37,14 +118,12 @@ public abstract class DisguiseLiving extends DisguiseBase
DataWatcher.watch(9, Entity.getDataWatcher().getByte(9));
}
}
public boolean isInvisible()
{
return _invisible;
}
public void setInvisible(boolean invisible)
{
_invisible = invisible;

View File

@ -42,11 +42,11 @@ public class NotificationManager extends MiniPlugin
if (!_enabled)
return;
if (event.getType() == UpdateType.MIN_08)
hugeSale();
// if (event.getType() == UpdateType.MIN_08)
// hugeSale();
// if (event.getType() == UpdateType.MIN_16)
// sale();
if (event.getType() == UpdateType.MIN_16)
sale();
}
private void sale()

View File

@ -163,9 +163,9 @@ public class Stacker extends SoloGame implements IThrown
Entity hit = target;
//Shuffle Down
// Shuffle Down
while (hit.getVehicle() != null)
hit = target.getVehicle();
hit = hit.getVehicle();
//Hit Own Stack > Rethrow
if (hit.equals(data.GetThrower()))

View File

@ -54,4 +54,9 @@ public abstract class Perk implements Listener
{
//Null Default
}
public void registeredEvents()
{
// When listener has been registered
}
}

View File

@ -307,7 +307,7 @@ public class GameManager implements Listener
event.GetGame().RegisterKits();
}
@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void KitDeregister(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Dead)

View File

@ -1,17 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/1/2015
* Time: 1:25 PM
*/
$array = array('1','2','3','4','5');
foreach ($array as $key => $moo)
{
if ($moo == '2')
unset ($array[$key]);
}
$a1 = array();
$a2 = array($a1);
print_r($array);
array_push($a1, $a2);
print_r($a1);

View File

@ -2,89 +2,83 @@
namespace mineplex\plugin;
use mineplex\plugin\bench\arenas\SingleGameArena;
use mineplex\plugin\core\updater\UpdateEvent;
use mineplex\plugin\bench\game\games\pvp\Pvp;
use mineplex\plugin\packets\StrangePacket;
use mineplex\plugin\gameengine\arenas\MultiGameArena;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\game\factory\TestGameFactory;
use mineplex\plugin\core\updater\Updater;
use mineplex\plugin\util\UtilFile;
use mineplex\plugin\util\UtilString;
use pocketmine\block\Block;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerLoginEvent;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\Server;
class Main extends PluginBase implements Listener
{
/** @var Arena */
private $arena;
private $test;
public function onEnable()
{
new SingleGameArena($this, new Pvp());
$this->arena = new MultiGameArena($this, new TestGameFactory());
Server::getInstance()->getPluginManager()->registerEvents($this, $this);
//$this->test = new WorldComponent($this->arena);
//$this->getServer()->getScheduler()->scheduleRepeatingTask(new TickTask($this), 1);
new Updater($this);
//$this->getServer()->getPluginManager()->registerEvents($this, $this);
//new Updater($this);
$this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0));
}
public function onDisable()
public function onLogin(PlayerLoginEvent $event)
{
UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat');
if ($this->arena->canJoin($event->getPlayer()))
return;
$event->setKickMessage("Unable to join game!");
$event->setCancelled();
}
public function joinMessage(PlayerJoinEvent $event)
public function onJoin(PlayerJoinEvent $event)
{
$name = $event->getPlayer()->getName();
$player = Server::getInstance()->getPlayer($name);
$event->setJoinMessage($player->getName());
$this->arena->addPlayer($event->getPlayer());
}
public function onPlayerJoin(PlayerJoinEvent $event)
public function punch(PlayerInteractEvent $event)
{
$event->getPlayer()->sendMessage("Welcome to the server " . $event->getPlayer()->getName() . "!");
$this->getLogger()->info($event->getPlayer()->getName() . " UID: " . $event->getPlayer()->getUniqueId());
if (UtilString::startsWith( $event->getPlayer()->getName(), "chissling"))
if ($event->getAction() == PlayerInteractEvent::LEFT_CLICK_BLOCK || $event->getAction() == PlayerInteractEvent::RIGHT_CLICK_BLOCK)
{
$event->getPlayer()->setNameTag("// chiss //");
$event->getPlayer()->setDisplayName("// chiss //");
$event->getPlayer()->sendMessage("Block: " . $event->getBlock()->getId() . ":" . $event->getBlock()->getDamage());
}
}
public function onPlayerCommand(PlayerCommandPreprocessEvent $event)
public function command(PlayerCommandPreprocessEvent $event)
{
if (UtilString::startsWith($event->getMessage(), "/mineplex"))
{
$event->setCancelled(true);
$event->getPlayer()->sendMessage("Sending you to: MINEPLEX");
$packet = new StrangePacket();
$packet->address = "69.175.104.154";
$event->getPlayer()->directDataPacket($packet);
}
if (UtilString::startsWith($event->getMessage(), "/ip "))
{
$event->setCancelled(true);
$ip = substr($event->getMessage(), 4, strlen($event->getMessage()));
$event->getPlayer()->sendMessage("Sending you to: " . $ip);
$packet = new StrangePacket();
$packet->address = $ip;
$event->getPlayer()->directDataPacket($packet);
}
if (UtilString::startsWith($event->getMessage(), "/pos"))
self::sendLoc($event->getPlayer());
}
public function onTick(UpdateEvent $event)
public static function sendLoc(Player $player)
{
$pos = $player->getLocation();
$player->sendMessage("X: " . $pos->getX());
$player->sendMessage("Y: " . $pos->getY());
$player->sendMessage("Z: " . $pos->getZ());
$player->sendMessage("Level: " . $pos->getLevel()->getName());
}
}

View File

@ -1,29 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 1:35 PM
*/
namespace mineplex\plugin\bench\arenas;
use pocketmine\plugin\Plugin;
use pocketmine\Player;
interface Arena
{
public function getCurrentGame();
/**
* @return Player[]
*/
public function getPlayers();
/**
* @return Plugin
*/
public function getPlugin();
public function endGame();
}

View File

@ -1,65 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/2/2015
* Time: 12:44 AM
*/
namespace mineplex\plugin\bench\game\components\feature;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\bench\game\components\gamestate\GameState;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
class GameStateFeatureManager implements Listener {
private $arena;
/** @var feature[][] */
private $features;
/**
* @param Arena $arena
* @param feature[][] $features
*/
public function __construct(Arena $arena, array $features)
{
$this->arena = $arena;
unset ($features[GameState::RESTARTING]);
$this->features = $features;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onGameStateChange(GameStateChangeEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$lastFeatures = $this->features[$event->getFromGameState()];
$theseFeatures = $this->features[$event->getToGameState()];
$toEnable = array_diff($theseFeatures, $lastFeatures);
$toDisable = array_diff($lastFeatures, $theseFeatures);
foreach ($toEnable as $feature) {
//$feature->
}
}
public function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
}
}

View File

@ -1,51 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/1/2015
* Time: 10:20 PM
*/
namespace mineplex\plugin\bench\game\components\feature\features;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\bench\game\components\feature\Feature;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
class NoBlockBreak implements Feature, Listener {
private $arena;
private $enabled = false;
public function __construct(Arena $arena)
{
$this->arena = $arena;
}
public function onBlockBreak(BlockBreakEvent $event)
{
if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
return;
$event->setCancelled(true);
}
public function enable()
{
$this->enabled = true;
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
}
public function disable()
{
$this->enabled = false;
HandlerList::unregisterAll($this);
}
public function isEnabled()
{
return $this->enabled;
}
}

View File

@ -1,36 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:18 PM
*/
namespace mineplex\plugin\bench\game\games\pvp;
use mineplex\plugin\bench\game\components\countdown\GameStateCountdown;
use mineplex\plugin\bench\game\components\feature\features\NoBlockBreak;
use mineplex\plugin\bench\game\components\gamestate\GameState;
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
use pocketmine\event\Listener;
use mineplex\plugin\bench\game\Game;
use mineplex\plugin\bench\arenas\Arena;
class Pvp implements Game, Listener {
public function start(Arena $arena)
{
$gameStateComponent = new GameStateComponent($arena);
array(
);
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME);
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
//new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME);
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
}
}

View File

@ -1,85 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/2/2015
* Time: 1:53 PM
*/
namespace mineplex\plugin\bench\time;
use pocketmine\scheduler\PluginTask;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
class BenchSchedule extends PluginTask
{
/** @var ActualBenchTask[] */
private $tasks = [];
public function __construct(Plugin $host)
{
parent::__construct($host);
Server::getInstance()->getScheduler()->scheduleRepeatingTask($this, 1);
}
//Fires off an event each tick, containing a list of all updateTypes
public function onRun($currentTick)
{
$currentTime = round(microtime(true) * 1000);
foreach ($this->tasks as $key => $task) {
if (!($currentTime >= $task->getNextRun()))
continue;
$task->getTaskData()->getTask()->run($task->getTaskData());
if ($task->getTaskData()->getPeriod() == null or $task->getTaskData()->getPeriod() < 0) {
unset($this->tasks[$key]);
} else {
$task->setNextRun($currentTime + $task->getTaskData()->getPeriod());
}
}
}
public function runTaskTimer(BenchTask $task, $wait, $period)
{
$taskData = new BenchTaskData($task, $period);
$actualTask = new ActualBenchTask($taskData, round(microtime(true) * 1000) + $wait);
array_push($this->tasks, $actualTask);
}
}
class ActualBenchTask
{
private $nextRun;
private $benchTaskData;
public function __construct(BenchTaskData $benchTaskData, $nextRun)
{
$this->benchTaskData = $benchTaskData;
$this->runNext = $nextRun;
}
function getNextRun()
{
return $this->nextRun;
}
function setNextRun($nextRun)
{
$this->nextRun = $nextRun;
}
function getTaskData()
{
return $this->benchTaskData;
}
}

View File

@ -1,43 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/2/2015
* Time: 2:58 PM
*/
namespace mineplex\plugin\bench\time;
class BenchTaskData {
/** @var BenchTask */
private $task;
private $period;
public function __construct(BenchTask $task, $period)
{
$this->task = $task;
$this->period = $period;
}
public function getTask()
{
return $this->task;
}
public function getPeriod()
{
return $this->period;
}
public function setPeriod($period)
{
$this->period = $period;
}
public function end()
{
$this->period = null;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 6:12 PM
*/
namespace mineplex\plugin\core\commen;
use mineplex\plugin\util\UtilArray;
class ItemContainer {
/** @var int[] */
private $ids = [];
/** @var bool */
private $black;
/**
* @param int[] $ids
* @param bool $black
*/
public function __construct(array $ids = null, $black = false)
{
if ($ids != null)
{
$this->ids = array_flip($ids);
}
$this->black = $black;
}
public function hasItem($id)
{
return ($this->black == UtilArray::hasKey($id, $this->ids));
}
}

View File

@ -30,6 +30,6 @@ class UpdateEvent extends Event
public function isTiming($type)
{
return in_array(type, $this->updateTypes);
return (isset($this->updateTypes[$type]) || array_key_exists($type, $this->updateTypes));
}
}

View File

@ -12,26 +12,45 @@ namespace mineplex\plugin\core\updater;
class UpdateType
{
const M64 = 3840000;
conSt M32 = 1920000;
conSt M16 = 960000;
conSt M8 = 480000;
conSt M4 = 240000;
conSt M2 = 120000;
conSt M1 = 60000;
conSt S32 = 32000;
conSt S16 = 16000;
conSt S8 = 8000;
conSt S4 = 4000;
conSt S2 = 2000;
conSt S1 = 1000;
conSt MS500 = 500;
conSt MS250 = 250;
conSt MS125 = 125;
const M32 = 1920000;
const M16 = 960000;
const M8 = 480000;
const M4 = 240000;
const M2 = 120000;
const M1 = 60000;
const S32 = 32000;
const S16 = 16000;
const S8 = 8000;
const S4 = 4000;
const S2 = 2000;
const S1 = 1000;
const MS500 = 500;
const MS250 = 250;
const MS125 = 125;
public $time;
private $lastTrigger = 0;
public function __construct($time=0)
{
$this->time = $time;
}
public function canTrigger()
{
if (round(microtime(true) * 1000) - $this->lastTrigger > $this->time)
{
$this->lastTrigger = round(microtime(true) * 1000);
return true;
}
return false;
}
public function isTiming($timing)
{
return $this->time === $timing;
}
}

View File

@ -8,13 +8,14 @@
namespace mineplex\plugin\core\updater;
use mineplex\plugin\core\updater\UpdateType;
use pocketmine\plugin\PluginBase;
use pocketmine\scheduler\PluginTask;
class Updater extends PluginTask
{
private $plugin;
private $last;
/** @var UpdateType[] */
private $updateTypes;
public function __construct(PluginBase $host)
@ -47,14 +48,13 @@ class Updater extends PluginTask
{
$updateTypes = array();
$timeSpent = round(microtime(true) * 1000) - $this->last;
$this->last = round(microtime(true) * 1000);
foreach ($this->updateTypes as &$updateType) {
if ($timeSpent >= $updateType->time) {
array_push($updateTypes, $updateType);
}
}
foreach ($this->updateTypes as &$updateType)
{
if ($updateType->canTrigger())
{
$updateTypes[$updateType->time] = 1;
}
}
//Call Event
$this->plugin->getServer()->getPluginManager()->callEvent(new UpdateEvent($currentTick, $updateTypes));
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: Bench
* Date: 6/30/2015
* Time: 1:35 PM
*/
namespace mineplex\plugin\gameengine\arenas;
use pocketmine\plugin\Plugin;
use pocketmine\Player;
interface Arena
{
/**
* @param Player $player
* @return bool
*/
public function canJoin(Player $player);
public function addPlayer(Player $player);
public function removePlayer(Player $player);
/**
* @return Player[]
*/
public function getPlayers();
/**
* @param mixed $player
* @return bool
*/
public function hasPlayer($player);
/**
* @return Plugin
*/
public function getPlugin();
public function endGame();
}

View File

@ -1,11 +1,11 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: Bench
* Date: 6/30/2015
* Time: 9:06 PM
*/
namespace mineplex\plugin\bench\arenas;
namespace mineplex\plugin\gameengine\arenas;
use pocketmine\event\Event;

View File

@ -0,0 +1,111 @@
<?php
/**
* Created by PhpStorm.
* User: Bench
* Date: 7/4/2015
* Time: 12:14 PM
*/
namespace mineplex\plugin\gameengine\arenas;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\factory\GameFactory;
use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\Player;
use pocketmine\Server;
use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\arenas\events\ArenaCanJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
class MultiGameArena implements Arena, Listener
{
/** @var Player[] */
private $players = array();
private $plugin;
private $gameFactory;
private $game;
public function __construct(Plugin $plugin, GameFactory $gameFactory)
{
Server::getInstance()->getPluginManager()->registerEvents($this, $plugin);
$this->gameFactory = $gameFactory;
$this->plugin = $plugin;
$this->startGame();
}
public function canJoin(Player $player)
{
$event = new ArenaCanJoinEvent($this, $player);
$this->plugin->getServer()->getPluginManager()->callEvent($event);
return !$event->isCancelled();
}
public function addPlayer(Player $player)
{
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaJoinEvent($this, $player));
array_push($this->players, $player);
}
public function removePlayer(Player $player)
{
if (($key = array_search($player, $this->players, true)) !== FALSE) {
unset($this->players[$key]);
}
Server::getInstance()->broadcastMessage("Calling ArenaQuitEvent");
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaQuitEvent($this, $player));
}
public function onQuit(PlayerQuitEvent $event)
{
$this->removePlayer($event->getPlayer());
}
public function endGame()
{
Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this));
$this->startGame();
}
private function startGame()
{
$this->game = $this->gameFactory->getGame();
$this->game->start($this);
Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this));
}
public function getPlayers()
{
return $this->players;
}
/**
* @param mixed $player
* @return bool
*/
public function hasPlayer($player)
{
if (!($player instanceof Player))
return false;
return in_array($player, $this->getPlayers());
}
public function getCurrentGame()
{
return $this->game;
}
public function getPlugin()
{
return $this->plugin;
}
}

View File

@ -5,20 +5,20 @@
* Date: 6/30/2015
* Time: 1:37 PM
*/
namespace mineplex\plugin\bench\arenas;
namespace mineplex\plugin\gameengine\arenas;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\Player;
use pocketmine\Server;
use mineplex\plugin\bench\game\Game;
use mineplex\plugin\bench\arenas\events\ArenaCanJoinEvent;
use mineplex\plugin\bench\arenas\events\ArenaJoinEvent;
use mineplex\plugin\bench\arenas\events\ArenaQuitEvent;
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\arenas\events\ArenaCanJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
class SingleGameArena implements Arena, Listener {
//I really have no idea if there is a better way to store players... but this is what I'm using for now.
@ -31,7 +31,6 @@ class SingleGameArena implements Arena, Listener {
public function __construct(Plugin $plugin, Game $game)
{
print 'SimpleGameArena Created!';
Server::getInstance()->getPluginManager()->registerEvents($this, $plugin);
$this->game = $game;
$this->plugin = $plugin;
@ -100,7 +99,7 @@ class SingleGameArena implements Arena, Listener {
foreach ($this->players as $player)
{
Server::getInstance()->broadcastMessage((string)$player->getName());
$player->kick('Game Over...');
$player->kick('Game Over...', false);
}
}

View File

@ -1,16 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: Bench
* Date: 6/30/2015
* Time: 9:22 PM
*/
namespace mineplex\plugin\bench\arenas\events;
namespace mineplex\plugin\gameengine\arenas\events;
use pocketmine\event\Cancellable;
use pocketmine\Player;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
class ArenaCanJoinEvent extends ArenaEvent implements Cancellable {
public static $handlerList = null;

View File

@ -1,14 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: Bench
* Date: 6/30/2015
* Time: 10:12 PM
*/
namespace mineplex\plugin\bench\arenas\events;
namespace mineplex\plugin\gameengine\arenas\events;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
class ArenaEndEvent extends ArenaEvent{

View File

@ -1,17 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: Bench
* Date: 6/30/2015
* Time: 9:22 PM
*/
namespace mineplex\plugin\bench\arenas\events;
namespace mineplex\plugin\gameengine\arenas\events;
use pocketmine\Player;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\Arena;
class ArenaJoinEvent extends ArenaEvent {
public static $handlerList = null;

View File

@ -1,16 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: Bench
* Date: 6/30/2015
* Time: 9:22 PM
*/
namespace mineplex\plugin\bench\arenas\events;
namespace mineplex\plugin\gameengine\arenas\events;
use pocketmine\Player;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
class ArenaQuitEvent extends ArenaEvent {
public static $handlerList = null;

View File

@ -1,14 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: Bench
* Date: 6/30/2015
* Time: 10:12 PM
*/
namespace mineplex\plugin\bench\arenas\events;
namespace mineplex\plugin\gameengine\arenas\events;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
class ArenaStartEvent extends ArenaEvent{
public static $handlerList = null;

View File

@ -1,13 +1,13 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 6/30/2015
* Time: 9:04 PM
*/
namespace mineplex\plugin\bench\game;
namespace mineplex\plugin\gameengine\game;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\Arena;
interface Game {
public function start(Arena $arena);

View File

@ -1,23 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/1/2015
* Time: 5:52 PM
*/
namespace mineplex\plugin\bench\game\components\countdown;
namespace mineplex\plugin\gameengine\game\components\countdown;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
use mineplex\plugin\bench\time\BenchSchedule;
use mineplex\plugin\bench\time\BenchTask;
use mineplex\plugin\bench\time\BenchTaskData;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
class GameStateCountdown implements Listener, BenchTask {
@ -28,15 +28,9 @@ class GameStateCountdown implements Listener, BenchTask {
private $startGameState;
private $setGameState;
private $scheduler;
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $count, $startGameState, $setGameState)
{
$this->scheduler = new BenchSchedule($arena->getPlugin());
$this->arena = $arena;
$this->gameStateComponent = $gameStateComponent;
@ -54,17 +48,13 @@ class GameStateCountdown implements Listener, BenchTask {
if ($event->getArena() !== $this->arena)
return;
Server::getInstance()->broadcastMessage("ToGameState:".(string)$event->getToGameState());
Server::getInstance()->broadcastMessage("StartGameState: $this->startGameState");
if ($event->getToGameState() == $this->startGameState)
{
$this->scheduler->runTaskTimer($this, 1000, 1000);
BenchSchedule::runTaskTimer($this, 1000, 1000);
}
else
{
BenchSchedule::cancelTask($this);
$this->count = $this->startCount;
}
}
@ -81,16 +71,17 @@ class GameStateCountdown implements Listener, BenchTask {
{
print "Count: $this->count"."\n";
$this->popup();
$this->count--;
if ($this->count <= 0)
{
$this->gameStateComponent->setGameState($this->setGameState);
$data->end();
}
$this->popup();
$this->count--;
}
public function popup()

View File

@ -0,0 +1,197 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/5/2015
* Time: 7:41 PM
*/
namespace mineplex\plugin\gameengine\game\components\countdown;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\entity\Effect;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\network\protocol\AnimatePacket;
use pocketmine\network\protocol\ContainerSetDataPacket;
use pocketmine\network\protocol\DropItemPacket;
use pocketmine\Player;
use pocketmine\Server;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
class LobbyCountdown implements Listener, BenchTask {
private $startCount;
private $count;
private $gameStateComponent;
private $worldComponent;
private $arena;
private $startGameState;
private $setGameState;
private $minPlayers;
private $message;
const WAITING_FOR_PLAYERS = "Waiting for players!";
const POPUP_ID = "popup";
const COUNTDOWN_ID = "count";
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent, $startGameState, $setGameState, $count, $minPlayers = 2)
{
$this->arena = $arena;
$this->gameStateComponent = $gameStateComponent;
$this->worldComponent = $worldComponent;
$this->minPlayers = $minPlayers;
$this->startCount = $count;
$this->count = $count;
$this->startGameState = $startGameState;
$this->setGameState = $setGameState;
$this->message = self::WAITING_FOR_PLAYERS;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
/**
* @param bool $addOne
*/
function checkCountdown($addOne = false)
{
$playerCount = (count($this->arena->getPlayers()) + $addOne);
if ($this->gameStateComponent->getGameState() == $this->startGameState && $this->worldComponent->isWorldReady() && $playerCount >= $this->minPlayers)
{
if (!BenchSchedule::isRunningWithId($this, self::COUNTDOWN_ID))
{
$this->count = $this->startCount;
$this->setCount();
BenchSchedule::runTaskTimerWithId($this, 1000, 1000, self::COUNTDOWN_ID);
}
}
else
{
$this->setWaiting($playerCount);
BenchSchedule::cancelTaskWithId($this, self::COUNTDOWN_ID);
}
}
public function onJoin(ArenaJoinEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$this->checkCountdown(true);
$this->popup($event->getPlayer());
}
public function onQuit(ArenaQuitEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$this->checkCountdown();
}
public function onWorldCreation(WorldLoadSuccessEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$this->checkCountdown();
}
public function onGameStateChange(GameStateChangeEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
if ($event->getToGameState() == $this->startGameState)
{
$this->checkCountdown();
BenchSchedule::runTaskTimerWithId($this, 500, 500, self::POPUP_ID);
}
elseif ($event->getFromGameState() == $this->startGameState)
{
//Cancels both tasks
BenchSchedule::cancelTask($this);
$this->count = $this->startCount;
}
}
public function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
}
public function run(BenchTaskData $data)
{
if ($data->getId() == self::POPUP_ID)
{
$this->popupAll();
}
else //if ($data->getId() == self::COUNTDOWN_ID)
{
if ($this->count <= 0)
{
$this->gameStateComponent->setGameState($this->setGameState);
$data->end();
return;
}
$this->message = "§9Game starting in:§c $this->count";
$this->count--;
}
}
private function setWaiting($playerCount = null)
{
if ($playerCount == null)
$playerCount = count($this->arena->getPlayers());
$this->message = "§2Waiting for players! §a($playerCount/$this->minPlayers)";
$this->popupAll();
}
private function setCount($count = null)
{
if ($count == null)
$count = $this->count;
$this->message = "§9Game starting in:§c $count";
$this->popupAll();
}
private function popupAll()
{
foreach ($this->arena->getPlayers() as $player)
{
$this->popup($player);
}
}
private function popup(Player $player)
{
$player->sendTip($this->message);
}
}

View File

@ -1,20 +1,22 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:18 PM
*/
namespace mineplex\plugin\bench\game\components\feature;
namespace mineplex\plugin\gameengine\game\components\feature;
interface Feature {
public function enable();
public function disable();
/**
* @return boolean
*/
public function isEnabled();
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 1:03 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature;
use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
class ListenerFeature implements Feature, Listener {
/** @var bool */
private $enabled = false;
private $arena;
function __construct(Arena $arena)
{
$this->arena = $arena;
}
public function enable()
{
$this->enabled = true;
Server::getInstance()->getPluginManager()->registerEvents($this, $this->getArena()->getPlugin());
}
public function disable()
{
$this->enabled = false;
HandlerList::unregisterAll($this);
}
/**
* @return boolean
*/
public function isEnabled()
{
$this->enabled;
}
/**
* @return Arena
*/
public function getArena()
{
return $this->arena;
}
}

View File

@ -0,0 +1,24 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 12:55 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature;
class UtilFeature {
public static function enable(Feature $feature)
{
if (!$feature->isEnabled())
$feature->enable();
}
public static function disable(Feature $feature)
{
if ($feature->isEnabled())
$feature->disable();
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 2:38 AM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use pocketmine\event\player\PlayerDeathEvent;
class DeathSpectate extends ListenerFeature {
private $spectateComponent;
function __construct(Arena $arena, SpectateComponent $spectateComponent)
{
parent::__construct($arena);
$this->spectateComponent = $spectateComponent;
}
/**
* @ignoreCancelled true
* @param PlayerDeathEvent $event
*/
function onDeath(PlayerDeathEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getEntity()))
return;
if ($this->spectateComponent->enableSpectate($event->getEntity()))
{
//Do death stuff
$event->getEntity()->sendTip('§4§lYOU DIED!');
}
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:20 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\core\commen\ItemContainer;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use pocketmine\event\block\BlockBreakEvent;
class NoBlockBreak extends ListenerFeature {
private $itemContainer;
/**
* @param Arena $arena
* @param int[] $ids
* @param bool $black
*/
public function __construct(Arena $arena, array $ids = null, $black = false)
{
parent::__construct($arena, $ids, $black);
$this->itemContainer = new ItemContainer($ids, $black);
}
/**
* @ignoreCancelled true
* @param BlockBreakEvent $event
*/
public function onBlockBreak(BlockBreakEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getPlayer()))
return;
if ($this->itemContainer->hasItem($event->getBlock()->getId()))
$event->setCancelled();
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:20 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\core\commen\ItemContainer;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use pocketmine\event\block\BlockPlaceEvent;
class NoBlockPlace extends ListenerFeature {
private $itemContainer;
/**
* @param Arena $arena
* @param int[] $ids
* @param bool $black
*/
public function __construct(Arena $arena, array $ids = null, $black = false)
{
parent::__construct($arena, $ids, $black);
$this->itemContainer = new ItemContainer($ids, $black);
}
/**
* @ignoreCancelled true
* @param BlockPlaceEvent $event
*/
public function onPlace(BlockPlaceEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getPlayer()))
return;
if ($this->itemContainer->hasItem($event->getBlock()->getId()))
$event->setCancelled();
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:20 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\core\commen\ItemContainer;use pocketmine\event\player\PlayerDropItemEvent;
class NoDropItem extends ListenerFeature {
private $itemContainer;
/**
* @param Arena $arena
* @param int[] $ids
* @param bool $black
*/
public function __construct(Arena $arena, array $ids = null, $black = false)
{
parent::__construct($arena, $ids, $black);
$this->itemContainer = new ItemContainer($ids, $black);
}
/**
* @ignoreCancelled true
* @param PlayerDropItemEvent $event
*/
public function onDrop(PlayerDropItemEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getPlayer()))
return;
if ($this->itemContainer->hasItem($event->getItem()->getId()))
$event->setCancelled();
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:20 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use pocketmine\event\player\PlayerMoveEvent;
class NoMovement extends ListenerFeature {
public function __construct(Arena $arena)
{
parent::__construct($arena);
}
/**
* @ignoreCancelled true
* @param PlayerMoveEvent $event
*/
public function onMove(PlayerMoveEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getPlayer()))
return;
if (($event->getFrom()->getX() == $event->getTo()->getX()) && ($event->getFrom()->getY() == $event->getTo()->getY()) && ($event->getFrom()->getZ() == $event->getTo()->getZ()))
return;
$event->setCancelled();
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:20 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\core\commen\ItemContainer;
use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\item\Item;
use pocketmine\Server;
class NoPickUpItem extends ListenerFeature {
private $itemContainer;
/**
* @param Arena $arena
* @param int[] $ids
* @param bool $black
*/
public function __construct(Arena $arena, array $ids = null, $black = false)
{
parent::__construct($arena, $ids, $black);
$this->itemContainer = new ItemContainer($ids, $black);
}
/**
* @ignoreCancelled true
* @param InventoryPickupItemEvent $event
*/
public function onPickUp(InventoryPickupItemEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getInventory()->getHolder())) {
Server::getInstance()->broadcastMessage("You're not in the arena!");
return;
}
Server::getInstance()->broadcastMessage("Grass: " . Item::GRASS);
Server::getInstance()->broadcastMessage("Item: " . $event->getItem()->getItem()->getId());
if ($this->itemContainer->hasItem($event->getItem()->getItem()->getId())) {
$event->setCancelled();
Server::getInstance()->broadcastMessage("Stopped!");
} else
Server::getInstance()->broadcastMessage("Not Stopped!");
}
}

View File

@ -0,0 +1,102 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/2/2015
* Time: 12:44 AM
*/
namespace mineplex\plugin\gameengine\game\components\feature\managers;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\util\UtilArray;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;
use mineplex\plugin\gameengine\game\components\feature\Feature;
class GameStateFeatureManager implements Listener {
private $arena;
/** @var Feature[][] */
private $features = [];
/**
* @param Arena $arena
* @param Feature[] $features
*/
public function __construct(Arena $arena, array $features)
{
$this->arena = $arena;
unset ($features[GameState::RESTARTING]);
foreach ($features as $key => $value)
{
$this->features[$key] = UtilArray::getValuesRecursively($value);
}
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onGameStateChange(GameStateChangeEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
/** @var Feature[] $lastFeatures */
if (isset($this->features[$event->getFromGameState()]) || array_key_exists($event->getFromGameState(), $this->features))
$lastFeatures = $this->features[$event->getFromGameState()];
else
$lastFeatures = [];
/** @var Feature[] $theseFeatures */
if (isset($this->features[$event->getToGameState()]) || array_key_exists($event->getToGameState(), $this->features))
$theseFeatures = $this->features[$event->getToGameState()];
else
$theseFeatures = [];
/** @var Feature[] $toEnable */
$toEnable = UtilArray::arrayDiff($theseFeatures, $lastFeatures);
/** @var Feature[] $toDisable */
$toDisable = UtilArray::arrayDiff($lastFeatures, $theseFeatures);
foreach ($toDisable as $feature) {
if ($feature->isEnabled())
$feature->disable();
}
foreach ($toEnable as $feature) {
if (!$feature->isEnabled())
$feature->enable();
}
}
public function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features));
foreach ($iterator as $feature) {
if ($feature->isEnabled())
$feature->disable();
}
HandlerList::unregisterAll($this);
}
}

View File

@ -1,12 +1,12 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:33 AM
*/
namespace mineplex\plugin\bench\game\components\gamestate;
namespace mineplex\plugin\gameengine\game\components\gamestate;
//Yes yes I know this is a horrible way of doing things, I'm just trying to get done fast.

View File

@ -1,17 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:26 AM
*/
namespace mineplex\plugin\bench\game\components\gamestate;
namespace mineplex\plugin\gameengine\game\components\gamestate;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
@ -37,12 +37,16 @@ class GameStateComponent implements Listener {
$this->setGameState(GameState::LOBBY);
}
/**
* @priority LOW
* @param ArenaEndEvent $event
*/
public function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
$this->setGameState(GameState::RESTARTING);
$this->localSetState(GameState::RESTARTING);
}
@ -64,13 +68,21 @@ class GameStateComponent implements Listener {
return true;
}
$event = new GameStateChangeEvent($this->arena, $this->gameState, $gameState);
$this->localSetState($gameState);
return true;
}
private function localSetState($gameState)
{
$oldGameState = $this->getGameState();
$this->gameState = $gameState;
$event = new GameStateChangeEvent($this->arena, $oldGameState, $gameState);
//Not sure if I should call the event before of after...
Server::getInstance()->getPluginManager()->callEvent($event);
$this->gameState = $gameState;
return true;
}
public function getGameState()

View File

@ -1,15 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/1/2015
* Time: 10:49 AM
*/
namespace mineplex\plugin\bench\game\components\gamestate\events;
namespace mineplex\plugin\gameengine\game\components\gamestate\events;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
class GameStateChangeEvent extends ArenaEvent {

View File

@ -0,0 +1,196 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 11:10 PM
*/
namespace mineplex\plugin\gameengine\game\components\lobby;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityShootBowEvent;
use pocketmine\event\HandlerList;
use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\Player;
use pocketmine\Server;
class LobbyComponent implements Listener
{
/** @var Arena */
private $arena;
/** @var String */
public $worldName;
private $duringLobbyGameState;
/**
* @param Arena $arena
* @param Level $world
*/
public function __construct(Arena $arena, $world = null)
{
if ($world == null)
$world = Server::getInstance()->getDefaultLevel();
$world->setTime(6000);
$world->stopTime();
$this->worldName = $world->getName();
$this->arena = $arena;
$this->duringLobbyGameState = new DuringLobbyGameState($arena, $world);
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onBlockBreak(BlockBreakEvent $event)
{
if ($event->getBlock()->getLevel()->getName() != $this->worldName)
return;
$event->setCancelled();
}
/**
* @priority LOW
* @param GameStateChangeEvent $event
*/
public function gameStateChange(GameStateChangeEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
if ($event->getToGameState() == GameState::LOBBY)
{
if (!$this->duringLobbyGameState->isEnabled())
{
$this->duringLobbyGameState->enable();
}
}
elseif ($event->getFromGameState() == GameState::LOBBY)
{
if ($this->duringLobbyGameState->isEnabled())
{
$this->duringLobbyGameState->disable();
}
}
}
public function onGameEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
if ($this->duringLobbyGameState->isEnabled())
$this->duringLobbyGameState->disable();
}
}
class DuringLobbyGameState extends ListenerFeature
{
private $spawn;
public function __construct(Arena $arena, Level $world)
{
parent::__construct($arena);
$this->spawn = new Position(0, 103, 0, $world);
}
/**
* @ignoreCancelled true
* @param EntityDamageEvent $event
*/
function onDamage(EntityDamageEvent $event)
{
if (!in_array($event->getEntity(), $this->getArena()->getPlayers()))
return;
$event->setCancelled();
}
/**
* @ignoreCancelled true
* @param PlayerDropItemEvent $event
*/
function onDrop(PlayerDropItemEvent $event)
{
if (!in_array($event->getPlayer(), $this->getArena()->getPlayers()))
return;
$event->setCancelled();
}
/**
* @ignoreCancelled true
* @param InventoryPickupItemEvent $event
*/
function onPickUp(InventoryPickupItemEvent $event)
{
if (!in_array($event->getInventory()->getHolder(), $this->getArena()->getPlayers()))
return;
$event->setCancelled();
}
/**
* @ignoreCancelled true
* @param EntityShootBowEvent $event
*/
function onBowShoot(EntityShootBowEvent $event)
{
if (!in_array($event->getEntity(), $this->getArena()->getPlayers()))
return;
$event->setCancelled();
}
/**
* @ignoreCancelled true
* @param ArenaJoinEvent $event
*/
function onJoin(ArenaJoinEvent $event)
{
if ($this->getArena() !== $event->getArena())
return;
$this->sendToSpawn($event->getPlayer());
}
function sendToSpawn(Player $player)
{
$player->getInventory()->clearAll();
$player->removeAllEffects();
$player->setGamemode(Player::ADVENTURE);
$player->setHealth($player->getMaxHealth());
$player->resetFallDistance();
$pos = $this->spawn->add(rand(-4, 4), 0, rand(-4, 4));
$player->teleport($pos);
}
function enable()
{
parent::enable();
foreach ($this->getArena()->getPlayers() as $player)
{
$this->sendToSpawn($player);
}
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 10:32 PM
*/
namespace mineplex\plugin\gameengine\game\components\spawn;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\Main;
use mineplex\plugin\util\UtilArray;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\level\Position;
use pocketmine\Player;
use pocketmine\Server;
class SimpleSpawnComponent implements SpawnComponent, Listener {
private $arena;
private $worldComponent;
private $gameMode;
/** @var Position[] */
private $spawns = [];
function __construct(Arena $arena, WorldComponent $worldComponent, $gameMode = Player::SURVIVAL)
{
$this->arena = $arena;
$this->worldComponent = $worldComponent;
$this->gameMode = $gameMode;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onWorld(WorldLoadSuccessEvent $event)
{
print "WorldLoadSuccessEvent!";
if ($event->getArena() !== $this->arena)
return;
$this->spawns = $this->worldComponent->getTeams()['Green'];
// $this->spawns = UtilArray::getValuesRecursively($this->worldComponent->getTeams());
//
// foreach ($this->spawns as $key => $value)
// {
// if (!($value instanceof Position))
// unset($this->spawns[$key]);
// }
//
// print (count($this->spawns) . " spawns Loaded\n");
}
/**
* @param Player $player
* @return Position
*/
function respawn(Player $player)
{
if (count($this->spawns) < 1)
{
print "no spawns!";
return;
}
/*
$player->getInventory()->clearAll();
$player->removeAllEffects();
$player->resetFallDistance();
$player->setGamemode($this->gameMode);
$player->setHealth($player->getMaxHealth());
*/
$player->sendMessage("Before:");
Main::sendLoc($player);
$pos = $this->spawns[array_rand($this->spawns)];
//$pos = $pos->getLevel()->getSpawnLocation();
print_r($pos);
$player->teleport($pos);
$player->sendMessage("After:");
Main::sendLoc($player);
return $pos;
}
function respawnAll() {
foreach ($this->arena->getPlayers() as $player)
{
$this->respawn($player);
}
}
function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 10:47 PM
*/
namespace mineplex\plugin\gameengine\game\components\spawn;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
class SpawnAt implements Listener {
private $spawnComponent;
private $arena;
private $gameStates;
function __construct(Arena $arena, SpawnComponent $spawnComponent, array $gameStates)
{
$this->arena = $arena;
$this->spawnComponent = $spawnComponent;
$this->gameStates = $gameStates;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onStateChange(GameStateChangeEvent $event)
{
if ($this->arena !== $event->getArena())
return;
if (in_array($event->getToGameState(), $this->gameStates)) {
$this->spawnComponent->respawnAll();
print "called! \n";
}
}
public function onEnd(ArenaEndEvent $event)
{
if ($this->arena !== $event->getArena())
return;
HandlerList::unregisterAll($this);
}
}

View File

@ -0,0 +1,24 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 2:06 PM
*/
namespace mineplex\plugin\gameengine\game\components\spawn;
use pocketmine\level\Position;
use pocketmine\Player;
interface SpawnComponent {
/**
* @param Player $player
* @return Position
*/
function respawn(Player $player);
function respawnAll();
}

View File

@ -0,0 +1,127 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 12:53 AM
*/
namespace mineplex\plugin\gameengine\game\components\spectate;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\game\components\spectate\events\DisableSpectateEvent;
use mineplex\plugin\gameengine\game\components\spectate\events\EnableSpectateEvent;
use mineplex\plugin\util\UtilArray;
use pocketmine\event\Listener;
use pocketmine\Player;
use pocketmine\Server;
class GameModeSpectateComponent implements SpectateComponent, Listener {
/** @var Player[] */
private $spectators = [];
private $arena;
public function __construct(Arena $arena)
{
$this->arena = $arena;
}
/**
* @param Player $player
* @return bool
*/
public function enableSpectate(Player $player)
{
if ($this->isSpectating($player))
return false;
$event = new EnableSpectateEvent($this->arena, $player);
Server::getInstance()->getPluginManager()->callEvent($event);
if ($event->isCancelled())
return false;
$player->getInventory()->clearAll();
$player->removeAllEffects();
$player->setHealth($player->getMaxHealth());
$player->resetFallDistance();
$player->setGamemode(Player::SPECTATOR);
array_push($this->spectators, $player);
return true;
}
/**
* @param Player $player
* @return bool
*/
public function disableSpectate(Player $player)
{
if (!$this->isSpectating($player))
return false;
$event = new DisableSpectateEvent($this->arena, $player);
Server::getInstance()->getPluginManager()->callEvent($event);
if ($event->isCancelled())
return false;
if (($key = array_search($player, $this->spectators, true)) !== FALSE) {
unset($this->spectators[$key]);
}
return true;
}
//Low to keep consistency, so if someone listens ArenaQuitEvent then the player will be in neither the spectator list or the player list.
/**
* @priority LOW
* @param ArenaQuitEvent $event
*/
public function onQuit(ArenaQuitEvent $event)
{
if ($this->arena !== $event->getArena())
return;
if (($key = array_search($event->getPlayer(), $this->spectators, true)) !== FALSE) {
unset($this->spectators[$key]);
}
}
/**
* @param Player $player
* @return bool
*/
public function isSpectating(Player $player)
{
return in_array($player, $this->getSpectators());
}
/**
* @param Player $player
* @return bool
*/
public function isNotSpectating(Player $player)
{
return in_array($player, $this->arena->getPlayers()) && !$this->isSpectating($player);
}
/**
* @return Player[]
*/
public function getSpectators()
{
return $this->spectators;
}
/**
* @return Player[]
*/
public function getNonSpectators()
{
return UtilArray::arrayDiff($this->arena->getPlayers(), $this->getSpectators());
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/5/2015
* Time: 11:52 PM
*/
namespace mineplex\plugin\gameengine\game\components\spectate;
use pocketmine\Player;
interface SpectateComponent {
/**
* @param Player $player
* @return bool
*/
public function enableSpectate(Player $player);
/**
* @param Player $player
* @return bool
*/
public function disableSpectate(Player $player);
/**
* @param Player $player
* @return bool
*/
public function isSpectating(Player $player);
/**
* @param Player $player
* @return bool
*/
public function isNotSpectating(Player $player);
/**
* @return Player[]
*/
public function getSpectators();
/**
* @return Player[]
*/
public function getNonSpectators();
}

View File

@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 1:27 AM
*/
namespace mineplex\plugin\gameengine\game\components\spectate\events;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\event\Cancellable;
use pocketmine\Player;
class DisableSpectateEvent extends ArenaEvent implements Cancellable {
public static $handlerList = null;
private $player;
public function __construct(Arena $arena, Player $player)
{
parent::__construct($arena);
$this->player = $player;
}
public function getPlayer()
{
return $this->player;
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 1:27 AM
*/
namespace mineplex\plugin\gameengine\game\components\spectate\events;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\event\Cancellable;
use pocketmine\Player;
class EnableSpectateEvent extends ArenaEvent implements Cancellable {
public static $handlerList = null;
private $player;
public function __construct(Arena $arena, Player $player)
{
parent::__construct($arena);
$this->player = $player;
}
public function getPlayer()
{
return $this->player;
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: C
* Date: 5/07/2015
* Time: 4:00 PM
*/
namespace mineplex\plugin\gameengine\game\components\world;
use pocketmine\scheduler\AsyncTask;
class AsyncWorldLoader extends AsyncTask
{
public function __construct()
{
}
public function onRun()
{
}
}

View File

@ -0,0 +1,309 @@
<?php
/**
* Created by PhpStorm.
* User: C
* Date: 5/07/2015
* Time: 12:27 PM
*/
namespace mineplex\plugin\gameengine\game\components\world;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\util\UtilArray;
use mineplex\plugin\util\UtilString;
use mineplex\plugin\util\UtilFile;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\Server;
use ZipArchive;
use Exception;
class WorldComponent implements Listener
{
private $arena;
private $gameId;
private $worldNameFolder;
/** @var \pocketmine\level\Level */
private $world;
private $mapName;
private $mapAuthor;
private $mapTeams = array();
private $mapData = array();
private $mapSettings = array();
private $ready = false;
public function __construct(Arena $arena)
{
$this->arena = $arena;
$this->gameId = $this->getNewGameId();
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onStart(ArenaStartEvent $event)
{
if ($this->arena !== $event->getArena())
return;
$this->loadWorld("Super Smash Mobs");
}
private function unloadWorld()
{
if (is_null($this->world) || !$this->arena->getPlugin()->getServer()->isLevelLoaded($this->worldNameFolder))
return;
foreach ($this->world->getPlayers() as $player)
{
$player->kick("Dead World");
}
$this->arena->getPlugin()->getServer()->unloadLevel($this->world);
UtilFile::deleteDir('worlds/' . $this->worldNameFolder);
print("Successfully Deleted: " . $this->worldNameFolder . "\n");
}
private function loadWorld($gameName)
{
$files = scandir('../update/maps/' . $gameName . '/');
$maps = array();
foreach ($files as $file)
{
if (UtilString::endsWith($file, ".zip"))
{
array_push($maps, $file);
}
}
$worldName = $maps[rand(0, count($maps) - 1)];
//Trim .zip
$worldName = substr($worldName, 0, strlen($worldName) - 4);
print_r($worldName . "\n");
$this->worldNameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName;
//Unzip World
$zip = new ZipArchive;
$res = $zip->open('../update/maps/' . $gameName . '/' . $worldName . '.zip');
if ($res === TRUE)
{
$zip->extractTo('worlds/' . $this->worldNameFolder . '/');
$zip->close();
print("Successfully Extracted: " . $this->worldNameFolder . "\n");
}
else
{
print("Error Extracting: " . $this->worldNameFolder . "\n");
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
return;
}
//Load World
if ($this->arena->getPlugin()->getServer()->loadLevel($this->worldNameFolder))
{
$this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->worldNameFolder);
$this->world->setSpawnLocation(new Vector3(0,200,0));
$this->world->setTime(6000);
$this->loadWorldData();
$this->ready = true;
print("Successfully Loaded World: " . $this->worldNameFolder . "\n");
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadSuccessEvent($this->arena, $this->world));
}
else
{
print("Error Loading World: " . $this->worldNameFolder . "\n");
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
$this->arena->endGame();
}
}
public function loadWorldData()
{
$handle = fopen('worlds/' . $this->worldNameFolder . '/WorldConfig.dat', "r");
if ($handle)
{
//These store the array that data should be inserted into
$currentTeamName = null;
$currentDataName = null;
while (($line = fgets($handle)) !== false)
{
$trimmedLine = trim($line, "\n\r");
$tokens = explode(":", $trimmedLine);
if (count($tokens) < 2 || strlen($tokens[0]) == 0)
{
continue;
}
//Name & Author
if (strcmp($tokens[0], "MAP_NAME") === 0)
{
$this->mapName = $tokens[1];
}
elseif (strcmp($tokens[0], "MAP_AUTHOR") === 0)
{
$this->mapAuthor = $tokens[1];
}
//Map Boundaries
elseif (strcmp($tokens[0], "MIN_X") === 0 ||
strcmp($tokens[0], "MAX_X") === 0 ||
strcmp($tokens[0], "MIN_Y") === 0 ||
strcmp($tokens[0], "MAX_Y") === 0 ||
strcmp($tokens[0], "MIN_Z") === 0 ||
strcmp($tokens[0], "MAX_Z") === 0)
{
$this->mapSettings[$tokens[0]] = $tokens[1];
}
//Team Spawns
elseif (strcmp($tokens[0], "TEAM_NAME") === 0)
{
$currentTeamName = $tokens[1];
}
elseif (strcmp($tokens[0], "TEAM_SPAWNS") === 0)
{
$positions = array();
for ($x=1 ; $x<count($tokens) ; $x++)
{
$position = $this->strToPos($tokens[$x]);
if (is_null($position))
continue;
$this->posTest = $position;
array_push($positions, $position);
}
$this->mapTeams[$currentTeamName] = $positions;
}
//Data
elseif (strcmp($tokens[0], "DATA_NAME") === 0)
{
$currentDataName = $tokens[1];
}
elseif (strcmp($tokens[0], "DATA_LOCS") === 0)
{
$positions = array();
for ($x=1 ; $x<count($tokens) ; $x++)
{
$position = $this->strToPos($tokens[$x]);
if (is_null($position))
continue;
array_push($positions, $position);
}
$this->mapData[$currentDataName] = $positions;
}
}
fclose($handle);
}
else
{
print("Error Opening File.");
}
}
/**
* @return Position[][]
*/
public function getTeams()
{
return $this->mapTeams;
}
/**
* @param $key
* @return int
*/
public function getSetting($key)
{
return $this->mapSettings[$key];
}
/**
* @param $key
* @return Position[]
*/
public function getData($key)
{
if (UtilArray::hasKey($key, $this->mapData))
return $this->mapData[$key];
return [];
}
protected function strToPos($str)
{
if (strlen($str) < 5)
return null;
$tokens = explode(",", $str);
try
{
return new Position($tokens[0], $tokens[1], $tokens[2], $this->world);
}
catch (Exception $e)
{
print("World Data Read Error: Invalid Position String [" . $str . "]\n");
}
return null;
}
//This will return a UID for the game
public function getNewGameId()
{
return rand(0, 999999); //Make this acutally unique
}
public function isWorldReady()
{
return $this->ready;
}
public function onEnd(ArenaEndEvent $event)
{
if ($this->arena !== $event->getArena())
return;
HandlerList::unregisterAll($this);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace mineplex\plugin\gameengine\game\components\world\event;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
class WorldLoadFailEvent extends ArenaEvent
{
public static $handlerList = null;
public function __construct(Arena $arena)
{
parent::__construct($arena);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace mineplex\plugin\gameengine\game\components\world\event;
use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\level\Level;
class WorldLoadSuccessEvent extends ArenaEvent
{
public static $handlerList = null;
private $level;
public function __construct(Arena $arena, Level $level)
{
parent::__construct($arena);
$this->level = $level;
}
function getLevel()
{
return $this->level;
}
}

View File

@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 1:12 PM
*/
namespace mineplex\plugin\gameengine\game\factory;
use mineplex\plugin\gameengine\game\Game;
interface GameFactory {
/**
* @return Game
*/
public function getGame();
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 3:03 PM
*/
namespace mineplex\plugin\gameengine\game\factory;
use mineplex\plugin\gameengine\game\games\sg\SurvivalGames;
class TestGameFactory implements GameFactory {
function getGame()
{
return new SurvivalGames();
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 6/30/2015
* Time: 9:18 PM
*/
namespace mineplex\plugin\gameengine\game\games\pvp;
use mineplex\plugin\gameengine\game\components\countdown\GameStateCountdown;
use mineplex\plugin\gameengine\game\components\feature\features\NoBlockBreak;
use mineplex\plugin\gameengine\game\components\feature\GameStateFeatureManager;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use pocketmine\event\Listener;
use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\Feature;
use pocketmine\item\Item;
class Pvp implements Game, Listener {
public function start(Arena $arena)
{
$gameStateComponent = new GameStateComponent($arena);
$noBlockBreak = new NoBlockBreak($arena, array(Item::GRASS));
/** @var Feature[][] $features */
$features = array(
GameState::LOBBY => array($noBlockBreak),
GameState::PRE_GAME => array($noBlockBreak),
GameState::GAME => array($noBlockBreak),
GameState::POST_GAME => array($noBlockBreak)
);
new GameStateFeatureManager($arena, $features);
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME);
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME);
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
}
}

View File

@ -1,21 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 6/30/2015
* Time: 10:15 PM
*/
namespace mineplex\plugin\bench\game\games\pvp;
namespace mineplex\plugin\gameengine\game\games\pvp;
use pocketmine\event\Listener;
use pocketmine\Server;
use pocketmine\event\HandlerList;
use pocketmine\event\player\PlayerDeathEvent;
use mineplex\plugin\bench\arenas\events\ArenaQuitEvent;
use mineplex\plugin\bench\arenas\events\ArenaJoinEvent;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\Arena;

View File

@ -0,0 +1,75 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 3:09 PM
*/
namespace mineplex\plugin\gameengine\game\games\sg;
use mineplex\plugin\gameengine\game\components\countdown\GameStateCountdown;
use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown;
use mineplex\plugin\gameengine\game\components\feature\features\DeathSpectate;
use mineplex\plugin\gameengine\game\components\feature\features\NoBlockBreak;
use mineplex\plugin\gameengine\game\components\feature\features\NoBlockPlace;
use mineplex\plugin\gameengine\game\components\feature\features\NoDropItem;
use mineplex\plugin\gameengine\game\components\feature\features\NoPickUpItem;
use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\game\components\lobby\LobbyComponent;
use mineplex\plugin\gameengine\game\components\spawn\SimpleSpawnComponent;
use mineplex\plugin\gameengine\game\components\spawn\SpawnAt;
use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\Feature;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\item\Item;
class SurvivalGames implements Game {
/** @var Arena */
private $arena;
function start(Arena $arena)
{
$this->arena = $arena;
$gameStateComponent = new GameStateComponent($arena);
//$spectateComponent = new GameModeSpectateComponent($arena);
//Init features
//$noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true);
//$pack = array(new NoBlockBreak($arena, [Item::GRASS]), new NoBlockPlace($arena, [Item::WOOD], true),new NoDropItem($arena, [Item::APPLE], true));
/** @var Feature[][] $features */
//$features = array(
// GameState::LOBBY => array($noPickUpItem, $pack)
//);
//new GameStateFeatureManager($arena, $features);
//new LobbyComponent($arena);
$worldComponent = new WorldComponent($arena);
$spawnComponent = new SimpleSpawnComponent($arena, $worldComponent);
new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]);
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1);
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
//new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME);
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
}
}

View File

@ -0,0 +1,215 @@
<?php
/**
* Created by PhpStorm.
* User: TheMineBench
* Date: 7/2/2015
* Time: 1:53 PM
*/
namespace mineplex\plugin\gameengine\time;
use pocketmine\scheduler\Task;
use pocketmine\Server;
class BenchSchedule extends Task
{
/** @var BenchSchedule */
private static $instance = null;
/**
* @return BenchSchedule
*/
private static function getInstance()
{
if (self::$instance == null)
{
self::$instance = new BenchSchedule();
}
return self::$instance;
}
/** @var ActualBenchTask[] */
private $tasks = [];
private function __construct()
{
Server::getInstance()->getScheduler()->scheduleRepeatingTask($this, 1);
}
public function onRun($currentTick)
{
$currentTime = round(microtime(true) * 1000);
foreach ($this->tasks as $key => $task) {
if (!($currentTime >= $task->getNextRun()))
continue;
$task->getTaskData()->getTask()->run($task->getTaskData());
if ($task->getTaskData()->getNextRun() !== null)
{
$task->setNextRun($task->getTaskData()->getNextRun());
$task->getTaskData()->setNextRun(null);
} elseif ($task->getTaskData()->getPeriod() == null or $task->getTaskData()->getPeriod() < 0) {
unset($this->tasks[$key]);
} else {
$task->setNextRun($currentTime + $task->getTaskData()->getPeriod());
}
}
}
/**
* @param BenchTask $taskToCancel
* @return bool
*/
public static function cancelTask(BenchTask $taskToCancel)
{
$deleted = false;
foreach (self::getInstance()->tasks as $key => $task)
{
if ($task->getTaskData()->getTask() === $taskToCancel)
{
unset (self::getInstance()->tasks[$key]);
$deleted = true;
}
}
return $deleted;
}
/**
* @param BenchTask $taskToCancel
* @param $id
* @return bool
*/
public static function cancelTaskWithId(BenchTask $taskToCancel, $id)
{
$deleted = false;
foreach (self::getInstance()->tasks as $key => $task)
{
if ($task->getTaskData()->getTask() === $taskToCancel && $task->getTaskData()->getId() === $id)
{
unset (self::getInstance()->tasks[$key]);
$deleted = true;
}
}
return $deleted;
}
/**
* @param BenchTask $taskToCancel
* @return bool
*/
public static function isRunning(BenchTask $taskToCancel)
{
foreach (self::getInstance()->tasks as $key => $task)
{
if ($task->getTaskData()->getTask() === $taskToCancel)
{
return true;
}
}
return false;
}
/**
* @param BenchTask $taskToCancel
* @param $id
* @return bool
*/
public static function isRunningWithId(BenchTask $taskToCancel, $id)
{
foreach (self::getInstance()->tasks as $key => $task)
{
if ($task->getTaskData()->getTask() === $taskToCancel && $task->getTaskData()->getId() === $id)
{
return true;
}
}
return false;
}
/**
* @param BenchTask $task
* @param int $wait
* @param int $period
* @param $id
*/
public static function runTaskTimerWithId(BenchTask $task, $wait, $period, $id)
{
$taskData = new BenchTaskData($task, $period, $id);
$actualTask = new ActualBenchTask($taskData, round(microtime(true) * 1000) + $wait);
array_push(self::getInstance()->tasks, $actualTask);
}
/**
* @param BenchTask $task
* @param int $wait
* @param int $period
*/
public static function runTaskTimer(BenchTask $task, $wait, $period)
{
self::runTaskTimerWithId($task, $wait, $period, null);
}
/**
* @param BenchTask $task
* @param int $wait
* @param $id
*/
public static function runTaskLaterWithId(BenchTask $task, $wait, $id)
{
self::runTaskTimerWithId($task, $wait, null, $id);
}
/**
* @param BenchTask $task
* @param int $wait
*/
public static function runTaskLater(BenchTask $task, $wait)
{
self::runTaskTimerWithId($task, $wait, null, null);
}
}
class ActualBenchTask
{
/** @var int */
private $nextRun;
/** @var BenchTaskData */
private $benchTaskData;
public function __construct(BenchTaskData $benchTaskData, $nextRun)
{
$this->benchTaskData = $benchTaskData;
$this->runNext = $nextRun;
}
/**
* @return int
*/
function getNextRun()
{
return $this->nextRun;
}
/**
* @param $nextRun
*/
function setNextRun($nextRun)
{
$this->nextRun = $nextRun;
}
/**
* @return BenchTaskData
*/
function getTaskData()
{
return $this->benchTaskData;
}
}

View File

@ -1,12 +1,12 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* User: TheMineBench
* Date: 7/2/2015
* Time: 2:01 PM
*/
namespace mineplex\plugin\bench\time;
namespace mineplex\plugin\gameengine\time;
use SplObjectStorage;

View File

@ -0,0 +1,84 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/3/2015
* Time: 2:03 PM
*/
namespace mineplex\plugin\gameengine\time;
class BenchTaskData {
/** @var BenchTask */
private $task;
/** @var Integer */
private $period;
/** @var Integer */
private $nextRun;
private $id;
public function __construct(BenchTask $task, $period, $id)
{
$this->task = $task;
$this->period = $period;
$this->id = $id;
}
/**
* @param int $period
*/
public function setPeriod($period)
{
$this->period = $period;
}
/**
* @param int $nextRun
*/
public function setNextRun($nextRun)
{
$this->nextRun = $nextRun;
}
/**
* @return int
*/
public function getNextRun()
{
return $this->nextRun;
}
/**
* @return BenchTask
*/
public function getTask()
{
return $this->task;
}
/**
* @return int
*/
public function getPeriod()
{
return $this->period;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
public function end()
{
$this->period = null;
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 1:07 AM
*/
namespace mineplex\plugin\util;
class UtilArray {
public static function hasKey($key, array $array)
{
return (isset($array[$key]) || array_key_exists($key, $array));
}
public static function arrayDiff(array $array, array $subtract)
{
return array_udiff($array, $subtract, ['mineplex\plugin\util\UtilArray', 'comp']);
}
static function comp($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
public static function getValuesRecursively($object)
{
if (!is_array($object))
return [$object];
$returnArray = [];
foreach ($object as $value)
{
if (is_array($value))
{
$returnArray = array_merge($returnArray, array_values(self::getValuesRecursively($value)));
}
else
{
array_push($returnArray, $value);
}
}
return $returnArray;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace mineplex\plugin\util;
class UtilFile
{
public static function deleteDir($dirPath)
{
if (! is_dir($dirPath))
{
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
{
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file)
{
if (is_dir($file))
{
self::deleteDir($file);
}
else
{
unlink($file);
}
}
rmdir($dirPath);
}
}