The Versatile API

Discussion in 'WIP and Development Status' started by maux, Apr 20, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    maux

    Hello. I have made an API class for my plugin called Game. It's just a test plugin so that I can mess around with Minecraft and Bukkit stuff. I have, however, gotten more interested in the project, and so I have expounded on it more. I hope to bring it to the public very soon so that it could exponentially make every developer's job easier. Here is a preview of the class:

    API.class (open)

    Code:
    package maux.gamemanager.api;
    
    import java.util.List;
    
    import org.bukkit.Location;
    import org.bukkit.World.Environment;
    import org.bukkit.WorldType;
    
    import maux.gamemanager.command.CommandManager;
    import maux.gamemanager.group.Group;
    import maux.gamemanager.group.Permission;
    import maux.gamemanager.v1_8_R3.mauxgame.MauxGame;
    import maux.gamemanager.v1_8_R3.mauxgame.MauxPlayer;
    import maux.gamemanager.v1_8_R3.mauxgame.MauxServer;
    import maux.gamemanager.v1_8_R3.modifier.ModifierCommand;
    import net.minecraft.server.v1_8_R3.EnumParticle;
    
    /**
    * This is an interface allows code to be reached from a center-point without
    * the constant instantiation of classes.
    *
    * @author Max
    * @see maux.gamemanager.v1_8_R3.mauxgame.MauxGame
    */
    
    public interface API {
    
        /**
         * Returns the MauxGame class
         *
         * @return
         */
    
        public static API getHandle() {
            return new MauxGame();
        }
    
        /**
         * Adds a warp location
         *
         * @param location
         * @param name
         */
    
        public void addWarp(Location location, String name);
    
        /**
         * Creates the world "worldName"
         *
         * @param worldName
         */
    
        public void addWorld(String worldName);
    
        /**
         * Creates the world "worldName" with a specific environment
         *
         * @param worldName
         * @param environment
         */
    
        public void addWorld(String worldName, Environment environment);
    
        /**
         * Creates the world "worldName" with a specific environment and world type
         *
         * @param worldName
         * @param environment
         * @param worldType
         */
    
        public void addWorld(String worldName, Environment environment, WorldType worldType);
    
        /**
         * Downloads the world "worldName" from "worldLink"
         *
         * @param worldLink
         * @param worldName
         */
    
        public void downloadWorld(String worldLink, String worldName);
    
        /**
         * Returns the list of Groups
         *
         * @return
         */
    
        public Group getGroups();
    
        /**
         * Returns the list of Permissions
         *
         * @return
         */
    
        public Permission getPermissions();
    
        /**
         * Returns the custom MauxPlayer
         *
         * @param player
         * @return
         */
    
        public MauxPlayer getPlayer(String player);
    
        /**
         * Returns the custom MauxServer
         *
         * @return
         */
    
        public MauxServer getServer();
    
        /**
         * Checks if the player has the Permission
         *
         * @param player
         * @param permission
         * @return
         */
    
        public boolean hasPermission(MauxPlayer player, Permission permission);
    
        /**
         * Hides the command class that extend CommandManager
         *
         * @param commands
         * @return
         */
    
        public ModifierCommand hideCommand(CommandManager command);
    
        /**
         * Hides the command classes that extend CommandManager
         *
         * @param commands
         * @return
         */
    
        public ModifierCommand hideCommands(List<CommandManager> commands);
    
        /**
         * Loads the world "worldName"
         *
         * @param worldName
         */
    
        public void loadWorld(String worldName);
    
        /**
         * Removes the server spawn
         */
    
        public void removeSpawn(MauxPlayer player);
    
        /**
         * Removes the warp
         *
         * @param name
         */
    
        public void removeWarp(String name);
    
        /**
         * Removes the world "worldName"
         *
         * @param worldName
         */
    
        public void removeWorld(String worldName);
    
        /**
         * Resets the command list
         *
         * @return
         */
    
        public ModifierCommand resetCommandTabList();
    
        /**
         * Sends the player an Action Bar text
         *
         * @param player
         * @param text
         */
    
        public void sendActionBar(MauxPlayer player, String text);
    
        /**
         * Sends the server an Action Bar text
         *
         * @param text
         */
    
        public void sendActionBar(String text);
    
        /**
         * Sends the server Particles
         *
         * @param particle
         * @param globe
         * @param speed
         */
    
        public void sendParticles(EnumParticle particle);
    
        /**
         * Sends the player Particles
         *
         * @param player
         * @param location
         * @param particle
         * @param globe
         * @param speed
         */
    
        public void sendParticles(MauxPlayer player, Location location, EnumParticle particle);
    
        /**
         * Sends the server to spawn
         */
    
        public void sendSpawn();
    
        /**
         * Sends the player to spawn
         *
         * @param player
         */
    
        public void sendSpawn(MauxPlayer player);
    
        /**
         * Sends the player a Title ModifierChatText
         *
         * @param player
         * @param bigText
         * @param smallText
         */
    
        public void sendTitleText(MauxPlayer player, String bigText, String smallText);
    
        /**
         * Sends the server a Title ModifierChatText
         *
         * @param bigText
         * @param smallText
         */
    
        public void sendTitleText(String bigText, String smallText);
    
        /**
         * Sends the player to the warp
         *
         * @param player
         * @param name
         */
    
        public void sendWarp(MauxPlayer player, String name);
    
        /**
         * Sends the server to the warp
         *
         * @param name
         */
    
        public void sendWarp(String name);
    
        /**
         * Sets the command list
         *
         * @param commandList
         * @return
         */
    
        public ModifierCommand setCommandTabList(List<String> commandList);
    
        /**
         * Sets the server spawn
         *
         * @param location
         */
    
        public void setSpawn(Location location);
    
        /**
         * Sets the player's Tab List
         *
         * @param player
         * @param header
         * @param footer
         */
    
        public void setTabList(MauxPlayer player, String header, String footer);
    
        /**
         * Sets the server's Tab List
         *
         * @param header
         * @param footer
         */
    
        public void setTabList(String header, String footer);
    
        /**
         * Shows the command class that extend CommandManager
         *
         * @param command
         * @return
         */
    
        public ModifierCommand showCommand(CommandManager command);
    
        /**
         * Shows the command classes that extend CommandManager
         *
         * @param commands
         * @return
         */
    
        public ModifierCommand showCommands(List<CommandManager> commands);
    
        /**
         * Unloads the world "worldName"
         *
         * @param worldName
         */
    
        public void unloadWorld(String worldName);
    
    }
    


    Includes (open)

    - Built in custom player
    - Built in custom server
    - Built in group/permission manager
    - Ability to add teleport locations
    - Ability to remove teleport locations
    - Easy to use command system
    - Ability to send modifiers (ActionBar, Titles, TabList, Particles, CommandList, etc.)
    - Ability to add worlds
    - Ability to remove worlds
    - Ability to download worlds
    - Ability to load worlds
    - Ability to unload worlds
    - Built in custom game manager
    - Built in event system
    - Ability to modify command tab/command list (sort of) -> /{tab}
    - Ability to reset command tab/command list
    - Ability to hide commands (that extend the class CommandManager)
    - Ability to show commands (that extend the class CommandManager)


    This project uses completely no dependencies at all making it quite the handy and resourceful API, if I do say so myself. I am still working on this project, and I am trying to perfect all the issues. I hope to release this project very soon. Please do give me comments on what you think. Thank you.
     
    Last edited: Apr 20, 2016
  2. Online

    timtower Moderator Moderator

    Moved to WIP
    @maux why not use abstraction and hide all version numbers?
     
  3. Offline

    mcdorli

    This sounds like a wrapper around bukkit. We already have a way to get all permissions/send titles/set spawns/manage worlds/etc. Why do we need a custom server/player? Why is this an interface?
     
  4. Offline

    maux

  5. Online

    timtower Moderator Moderator

    @maux You have version numbers in the includes corrosponding to the minecraft version.
    Why not use abstraction to hide that? Will make the plugins more flexible as they dont need to update their code because the version changed, then the server owner only needs to update your lib.
     
  6. Offline

    maux

    The custom player and server is a wrapper. Let me show you the custom player class, I am not finished with it yet but here it is:
    MauxPlayer.class (open)

    Code:
    package maux.gamemanager.v1_8_R3.mauxgame;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    import maux.gamemanager.api.API;
    import maux.gamemanager.event.PacketReceiveEvent;
    import maux.gamemanager.group.Group;
    import maux.gamemanager.group.Permission;
    import maux.gamemanager.world.teleport.TeleportSpawn;
    import maux.gamemanager.world.teleport.TeleportWarp;
    import net.minecraft.server.v1_8_R3.EntityPlayer;
    import net.minecraft.server.v1_8_R3.EnumParticle;
    import net.minecraft.server.v1_8_R3.Packet;
    import net.minecraft.server.v1_8_R3.PlayerConnection;
    
    @SuppressWarnings("rawtypes")
    public class MauxPlayer {
    
        private API api = API.getHandle();
        private Player player;
        private TeleportSpawn spawn;
        private TeleportWarp warp;
    
        public MauxPlayer(Player a) {
            this.player = a;
        }
    
        public Player getBukkitPlayer() {
            return player;
        }
    
        public PlayerConnection getConnection() {
            return getEntityPlayer().playerConnection;
        }
    
        public String getDisplayedName() {
            return getBukkitPlayer().getDisplayName();
        }
    
        public EntityPlayer getEntityPlayer() {
            return ((CraftPlayer) getBukkitPlayer()).getHandle();
        }
    
        public Group getGroup() {
            return null;
        }
    
        public String getName() {
            return getBukkitPlayer().getName();
        }
    
        public int getPing() {
            return getEntityPlayer().ping;
        }
    
        public boolean hasPermission(Permission permission) {
            return getBukkitPlayer().hasPermission(permission.a());
        }
    
        public void resetDamage() {
            getBukkitPlayer().setFireTicks(0);
            getBukkitPlayer().setHealth(20);
            getBukkitPlayer().setFoodLevel(20);
            player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 25, 0), false);
        }
    
        public void resetInventory() {
            getBukkitPlayer().getInventory().clear();
            getBukkitPlayer().getInventory().setHelmet(null);
            getBukkitPlayer().getInventory().setChestplate(null);
            getBukkitPlayer().getInventory().setLeggings(null);
            getBukkitPlayer().getInventory().setBoots(null);
        }
    
        public void resetLevels() {
            getBukkitPlayer().setLevel(0);
            getBukkitPlayer().setExp(0f);
        }
    
        public void resetPlayer() {
            resetInventory();
            resetDamage();
            resetLevels();
        }
    
        public void send(Packet packet) {
            getConnection().sendPacket(packet);
            Bukkit.getServer().getPluginManager().callEvent(new PacketReceiveEvent(this));
        }
    
        public void send(Sound sound, float pitch) {
            getBukkitPlayer().playSound(getBukkitPlayer().getLocation(), sound, 1, pitch);
        }
    
        public void send(String text) {
            getBukkitPlayer().sendMessage(text);
        }
    
        public void sendActionBar(String text) {
            api.sendActionBar(this, text);
        }
    
        public void sendParticles(EnumParticle particle, int globe) {
            api.sendParticles(particle);
        }
    
        public void sendSpawn() {
            spawn.a(this);
        }
    
        public void sendTitleText(String text) {
            sendTitleText("", text);
        }
    
        public void sendTitleText(String highText, String subText) {
            api.sendTitleText(this, highText, subText);
        }
    
        public void sendWarp(String warpName) {
            warp.a(this, warpName);
        }
    
        public void setGroup(Group group) {
    
        }
    
        public void setName(String text) {
            getBukkitPlayer().setDisplayName(text);
            getBukkitPlayer().setPlayerListName(text);
            getBukkitPlayer().setCustomNameVisible(true);
        }
    
    }
    


    The point for this class, if you might be asking, is to simplify certain things like:
    Code:
    ((CraftPlayer) bukkitPlayer).getHandle().playerConnection.sendPacket(packet);
    to:
    Code:
    mauxPlayer.send(packet);
    Other features in the MauxPlayer class include things such as executing plugin features and what nots.

    The getPermissions() & getGroups() part of the API class is still being worked on; however, it's not the Permissions you are thinking about. It's a PermissionManager which eventually ties into the GroupManager class. This allows for the developer to create custom groups, add permissions, remove permissions, etc.

    The managing worlds portion of the API is really neat because it allows you to download worlds from a website (which would be great if you have a game that requires for the map to reset) and allows you to do the other basic features (add, remove, load, etc.) but in a neat, organised fashion.

    The modifier portions of the API is what they are called - modifiers. They modify the game. Of course you are not required to use it, some people know how to make there own methods. These methods are for developers who are trying to speed code, do you know what I mean?

    The reason I have the API class: think of it like this: Player and CraftPlayer classes, 'nuff said. Hopefully you understand where I am going with this.
    Line 23 of API.class (open)

    Code:
     * @see maux.gamemanager.v1_8_R3.mauxgame.MauxGame
    

    If not, here is the reason why I have API as an interface. The MauxGame class has a bunch of other features and what nots that are irrelevant, the class looks quite filthy in my opinion, and the API class makes it easier for developers to read/use, and yes, "a center-point" for the whole entire project. Besides, if they want to see where the magic happens, they can always click COMMAND over the code, and click "Open Implementation." Nothing is stopping them!

    Please reply to me if you have any questions, or if you believe I made a mistake, etc. I'll be happy to address any problems.

    I will take that to consideration, I see what you are talking about.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 21, 2016
Thread Status:
Not open for further replies.

Share This Page