Dev diary 1: Lets start!

Hello fellow minecraftians! Here's my first dev diary, where I'll tell how the project is progressing, Java stuff I learn and some code tips.

Well, so actually I have this code:

package io.github.nnubes256.minedigger;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class Minedigger extends JavaPlugin {

    protected CommandMan commandMan;

    @Override
    public void onEnable() {
        commandMan = new CommandMan(this);
    }

    @Override
    public void onDisable() {

    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        return commandMan.parse(sender,command,args);
    }
}

CommandMan is my command handler. For keep the main class clean, I send all commands there:

package io.github.nnubes256.minedigger;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

public class CommandMan {

    private Plugin plugin;

    public CommandMan(Plugin plugin) {
        this.plugin = plugin;
    }

    public boolean parse(CommandSender sender, Command command, String[] args) {
        // I return false here because this is a stub xd.
        return false;
    }
}

For init this class, I simply make a variable for contain the instance, make it and use the parse() method of this class for get rid of the commands, and send instructions to the rest of modules. The modules are modular(duh) classes that get rid of a concrete thing. For example:

  • GameDirector(class not created yet) will handle both the listeners and the game logic.
  • DiggerZone is a class that defines each Minesweeper area.
    • This class could be extended for create new Minedigger gamemodes(Minesweeper PvP? Turn-based games?).

Lets go with DiggerZone:

package io.github.nnubes256.minedigger;

import me.desht.dhutils.cuboid.Cuboid;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

public class DiggerZone {

    private String name;
    private Block pos1;
    private Block pos2;
    private Cuboid protection;
    
    private Player whoIsPlaying = null;

    public DiggerZone(String name, Block pos1, Block pos2) {
        this.name = name;
        this.pos1 = pos1;
        this.pos2 = pos2;
        this.protection = new Cuboid(pos1.getLocation(), pos2.getLocation());
    }

    public String getName() {
        return name;
    }

    protected Block getPos1() {
        return pos1;
    }

    protected Block getPos2() {
        return pos2;
    }

    public Cuboid getCuboid() {
        return protection;
    }

    // To be or not to be static...
    public void startGame(Player player) {
        // TODO Make this method
    }
    
    public void resetZone() {
        // TODO Make this method
    }
    
    public Player getWhoIsPlaying() {
        return whoIsPlaying;
    }
}

The Cuboid class is part of dhutils by desht. I use it for get control of the zone blocks, and it will be used for the listeners. getName(), getPos1() and getPos2() return the name of the arena and the two blocks that define the cuboid. getCuboid() returns a cuboid object that wraps the zone. startGame(Player player) starts the game with the defined player. resetZone() kicks playing players out of the arena and then disolves the game. getWhoIsPlaying() returns the player actually playing.

Suggestions? Tell me on the main page or here!

Regards!


Comments

Posts Quoted:
Reply
Clear All Quotes