Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is it hard to create a BedWars plugin, how to shortcut then?

Comments in 'Plugin Development' started by MyNameIsTriXz, Jan 11, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I thought what you need for a BedWars/Rush plugin:
    - 4 bed variables for each game
    - 4 Team name variables, who show up grey after destroy for each game
    - 4 arrays for teams for each game
    - 4 arrays to save the players names for the games
    - 4 variables to hold each games team spawns

    Are there any ways to get it not so complicated? Shortcutting ect.?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That's very bad because arrays means not compatible with multiarena. => Get that idea out of your head. :3
    You actually only need a config, no arrays(in the plugin) at all
    applqpak likes this.
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    So whats the difference between saving the playernames in a config instead of saving them into an array? :D
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Config just makes everything more user friendly, editable etc. And: It saves everything after a restart. Arrays would need you to set up everything in the plugin itself: New Map -> You need to update the Plugin, instead of just having to update the config.
    I would recommend you to take a look at my TNTRun Plugin, as that uses a Multiarena System (Config)
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Why not?
    Did you try using a multidimensional array?
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Did you try saving the array so it's still there after a restart? Dif you try to make a user friendly multiarena system with plugin build-in-arrays?
    applqpak likes this.
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Why do you need keep any on array? It's totally unnecesary.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I am talking about the multiarena system, not about players.
    applqpak likes this.
  9. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Link pls? : D
  10. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    *facepalm* I forgot it hasn't been accepted yet. Well, take a look at my twitter Account, it's on there.(You should know it, we've been writing in PM.)
    MyNameIsTriXz and Legoboy0215 like this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is definitely better to use objects of your own classes rather than associative arrays ($array["attribute name"]) to handle data in memory.
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Um... Classes > config > ARRAY.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    SOFe likes this.
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    you should create and arena instance => main arena file so for each arena you should create new instance and there you can create listeners etc. for teams im using Team object, so i have array $teams with 4 instances of Team class. in bedwars i have all players data saved in arrays. but in annihilation i have a PlayerData object where is team, kit, if is in lobby, ender furnace inventory, ender chest inventory etc.

    my Team class (from annihilation, but for bedwars it is similar) :
    PHP:
    <
    <?php

    namespace Annihilation\Arena\Object;

    use 
    Annihilation\Arena\Arena;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\nbt\tag\Compound;
    use 
    pocketmine\nbt\tag\Enum;
    use 
    pocketmine\nbt\tag\Int;
    use 
    pocketmine\nbt\tag\String;
    use 
    pocketmine\Player;
    use 
    pocketmine\tile\Chest;
    use 
    pocketmine\tile\Tile;
    use 
    pocketmine\utils\TextFormat;

    class 
    Team{

        private 
    $name;
        private 
    $color;
        private 
    $id;

        
    /** @var Player[] */
        
    private $players = [];

        private 
    $nexus;

        
    /** @var Vector3[] */
        
    private $data = [];

        private 
    $plugin;

        
    /** @var  Position $spawn */
        
    private $spawn;

        
    /** @var  Chest */
        
    private $brewingShop;
        
    /** @var  Chest */
        
    private $weaponsShop;

        
    /** @var  Chest */
        
    private $kitWindow;

        public function 
    __construct($id$name$colorArena $plugin){
            
    $this->id $id;
            
    $this->name $name;
            
    $this->color $color;
            
    $this->plugin $plugin;
        }

        
    /**
         * @param Vector3[] $data
         */
        
    public function setData(array $dataArena $plugin){
            
    $this->data $data;
            
    $this->nexus = new Nexus($this, new Position($this->data["nexus"]->x$this->data["nexus"]->y$this->data["nexus"]->z$plugin->level));
            
    $this->spawn = new Position($this->data["spawn"]->x$this->data["spawn"]->y$this->data["spawn"]->z$plugin->level);

            
    $nbt = new Compound("", [
                new 
    Enum("Items", []),
                new 
    String("id"Tile::CHEST),
                new 
    Int("x"$this->data["chest"]->x),
                new 
    Int("y"$this->data["chest"]->y),
                new 
    Int("z"$this->data["chest"]->z),
                
    //new String("CustomName", "Brewing Shop")
            
    ]);
            
    $chest Tile::createTile("Chest"$this->plugin->level->getChunk($this->data["chest"]->>> 4$this->data["chest"]->>> 4), $nbt);
            
    $this->brewingShop $chest;
            
    $chest->setName("Brewing Shop");

            
    $items = [[Item::get(Item::BREWING_STAND), Item::get(Item::GOLD_INGOT010)], [Item::get(37403), Item::get(Item::GOLD_INGOT01)], [Item::get(372), Item::get(Item::GOLD_INGOT05)], [Item::get(331), Item::get(Item::GOLD_INGOT03)], [Item::get(376), Item::get(Item::GOLD_INGOT03)], [Item::get(378), Item::get(Item::GOLD_INGOT02)], [Item::get(353), Item::get(Item::GOLD_INGOT02)], [Item::get(382), Item::get(Item::GOLD_INGOT02)], [Item::get(370), Item::get(Item::GOLD_INGOT015)], [Item::get(396), Item::get(Item::GOLD_INGOT02)], [Item::get(375), Item::get(Item::GOLD_INGOT02)], [Item::get(377), Item::get(Item::GOLD_INGOT015)], [Item::get(Item::GUNPOWDER), Item::get(Item::GOLD_INGOT030)]];
            
    //$items = [[Item::get(Item::POTION, 33, 1), Item::get(Item::GOLD_INGOT, 0, 22)]];

            
    $slot 0;
            foreach(
    $items as $array){
                
    $this->brewingShop->getInventory()->setItem($slot$array[0]);
                
    $slot++;
                
    $this->brewingShop->getInventory()->setItem($slot$array[1]);
                
    $slot++;
            }

            
    $chest2 Tile::createTile("Chest"$this->plugin->level->getChunk($this->data["chest"]->>> 4$this->data["chest"]->>> 4), $nbt);
            
    $chest2->setName("Weapons Shop");
            
    $this->weaponsShop $chest2;

            
    $items = [[Item::get(Item::IRON_HELMET), Item::get(Item::GOLD_INGOT010)], [Item::get(Item::IRON_CHESTPLATE), Item::get(Item::GOLD_INGOT018)], [Item::get(Item::IRON_LEGGINGS), Item::get(Item::GOLD_INGOT014)], [Item::get(Item::IRON_BOOTS), Item::get(Item::GOLD_INGOT08)], [Item::get(Item::IRON_SWORD), Item::get(Item::GOLD_INGOT05)], [Item::get(Item::BOW), Item::get(Item::GOLD_INGOT05)], [Item::get(Item::ARROW016), Item::get(Item::GOLD_INGOT05)], [Item::get(Item::CAKE), Item::get(Item::GOLD_INGOT05)], [Item::get(Item::MELON016), Item::get(Item::GOLD_INGOT01)]];

            
    $slot 0;
            foreach(
    $items as $array){
                
    $this->weaponsShop->getInventory()->setItem($slot$array[0]);
                
    $slot++;
                
    $this->weaponsShop->getInventory()->setItem($slot$array[1]);
                
    $slot++;
            }
        }

        public function 
    getId(){
            return 
    $this->id;
        }

        public function 
    addPlayer(Player $p){
            
    $this->players[strtolower($p->getName())] = $p;
            
    $p->setNameTag($this->getColor().$p->getName().TextFormat::WHITE);
            
    $p->setDisplayName($this->plugin->mtcore->getDisplayRank($p)." ".$this->getColor().$p->getName().TextFormat::WHITE);
        }

        public function 
    removePlayer(Player $p){
            unset(
    $this->players[strtolower($p->getName())]);
        }

        public function 
    getName(){
            return 
    $this->name;
        }

        public function 
    getColor(){
            return 
    $this->color;
        }

        
    /**
         * @return Nexus
         */
        
    public function getNexus(){
            return 
    $this->nexus;
        }

        public function 
    isAlive(){
            return 
    count($this->players) > true false;
        }

        public function 
    getPlayers(){
            return 
    $this->players;
        }

        public function 
    message($messagePlayer $player null){
            if(
    $player === null){
                foreach(
    $this->getPlayers() as $p) {
                    
    $p->sendMessage($message);
                }
                return;
            }
            foreach(
    $this->getPlayers() as $p) {
                
    $color $this->getColor();
                
    $p->sendMessage(TextFormat::GRAY "[{$color}Team" TextFormat::GRAY "]   " $player->getDisplayName() . TextFormat::DARK_AQUA " > " $message);
            }
        }

        public function 
    getSpawnLocation(){
            return 
    $this->spawn;
        }

        public function 
    getBrewingShop(){
            return 
    $this->brewingShop;
        }

        public function 
    getWeaponsShop(){
            return 
    $this->weaponsShop;
        }

        public function 
    getKitWindow(){
            return 
    $this->kitWindow->getInventory();
        }
    }
    code is not the best (such as players > 4 : true ? false ) but i began with annihilation development 6 months ago and i could not php very well :D
    Skullex, SOFe and MyNameIsTriXz like this.
  15. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    O
    Thats a good way to script, in my the walls plugin everything was in just one Main file, when I wanted to add a new game I had to add everything new on hooks, function ect.. Thx
  16. Skullz
    Offline

    Skullz New Member

    Joined:
    Jun 3, 2016
    Posts:
    1
    Minecraft User:
    Only1Gam3r
  17. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Why are you commenting on such an old thread just to say 'cool'?

    anyways, @MyNameIsTriXz a good way to create a minigame is to create an arena class, containing class properties of: An array of players in the arena, arrays of teams(if any), arena ID(each arena should have a different ID so you can get each arena without any confusion), and any other details the arena would require. Then you can add methods like getPlayers(), which should return the player array. This way you can create as many arenas as you want(by simply creating a new Arena instance) without being limited to a certain amount. Once you have an arena class, the rest is up to you on how you want the game to work.
    Not saying its the best way, but its the way that works the best for me, and a lot of people do it that way. There are no shortcuts.
    Last edited: Jun 11, 2016
    MyNameIsTriXz likes this.
  18. basprohop
    Offline

    basprohop Active Member Plugin Developer

    Joined:
    Aug 8, 2015
    Posts:
    128
    Plugins:
    3
    Minecraft User:
    basprohop
  19. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    a
    Ah thanks, a class way is also good, but I prefer my way, and it works good, I save things like team in the nametag of the players.
  20. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Whether you use configs don't really affect. You can just read config values into arrays when the server starts.

Share This Page

Advertisement