[SPOUT] Using two Classes to create a GUI

Discussion in 'Plugin Development' started by FlareLine, Jun 11, 2013.

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

    FlareLine

    Hi All.
    I recently updated my plugin, LogStore, to include a simple GUI with a Close button, as I wish to become familiar with Spout plugin building as well as Bukkit, and I am very interested in Spout atm.

    The main reason I am posting again is because I have an error.

    I have a working update (Search it up) that includes neither a GUI Method nor a separate class for this - therefore, I only have one class. This works perfectly.

    I then proceed to add another class, which works fine as well, I am able to see that the command, /store spouter, gets the required color, "green", and this method is located in the other class.

    When I add a GUI to this new class, and reference it in the main class, it compiles fine... When try retry the command, /store spouter , to see whether the GUI was correctly implemented, nothing happens. I try the /store command... Nothing happens, which therefore means the plugin is BROKEN?

    I have the code of the original jarfile, the jarfile containing the color method and the new class, and the jarfile most recently compiled, with the GUI in it.

    Old Jarfile:
    http://dev.bukkit.org/bukkit-mods/logstore/files/3-log-store-v1-01/
    MultiClass Jarfile:
    http://dev.bukkit.org/bukkit-mods/logstore/files/4-log-store-multi-class/
    New Code:
    Main Class:
    Code:
    //
    //            DON'T FORGET TO EDIT THE PLUGIN.YML TO THE CURRENT BUILD!!!!!!!!!
    //
     
    package user.flareline.logstore;
     
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.getspout.spoutapi.SpoutManager;
    import org.getspout.spoutapi.player.SpoutPlayer;
     
    import user.flareline.logstore.GUI;
     
    public class LogStore extends JavaPlugin{
     
        public GUI gui;
     
        public void onEnable() {
     
     
            getCommand("store").setExecutor(this);
            File dir = new File("plugins/LogStore");
            if (dir.exists()){
                getLogger().info("LogStore folder already exists!");
            }
            else {
                dir.mkdir();   
                getLogger().info("LogStore folder created!");
            }
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, GUI GUI) {
            if(cmd.getName().equalsIgnoreCase("store") && args.length == 0) {
                sender.sendMessage(ChatColor.DARK_RED + "=====" + ChatColor.YELLOW + "LogStore" + ChatColor.DARK_RED + "=====");
                sender.sendMessage(ChatColor.GOLD + "/store" + ChatColor.DARK_GRAY + " - " + ChatColor.DARK_GREEN+ "Display this message.");
                sender.sendMessage(ChatColor.GOLD + "/store <name>" + ChatColor.DARK_GRAY + " - " + ChatColor.DARK_GREEN+ "Store an entry for 'name'.");
                sender.sendMessage(ChatColor.GOLD + "/store <name> <#>" + ChatColor.DARK_GRAY + " - " + ChatColor.DARK_GREEN+ "Store # entries for 'name'.");
                return true;
            }
            //File directory = new File(this.getDataFolder().getPath());
            //sender.sendMessage(directory.getAbsolutePath());
            File logger = new File(this.getDataFolder() + "/logger.txt");
            SPOUTER:
                if(args.length == 1) {
                    if(args[0].equalsIgnoreCase("spouter")){
                        sender.sendMessage(ChatColor.LIGHT_PURPLE + "You have activated the SPOUTER Command.");
                        sender.sendMessage(ChatColor.YELLOW + "Opening GUI Window...");
                        /*GUI METHOD******************************************************/
                        /*GUI METHOD******************************************************/
                        GUI.GUIMethod((SpoutPlayer) sender, this, GUI.titlelength, GUI.descriptionlength);
                        /*****************************************************************/
                        /*****************************************************************/
                        break SPOUTER;
                    }
                    if(args[0].equalsIgnoreCase("createlogger")){
                        if(logger.exists()){
                            sender.sendMessage(ChatColor.AQUA + "LogStore Logger already exists!");
                        } else {
                            sender.sendMessage(ChatColor.AQUA + "Creating LogStore Logger!");
                            try {
                                logger.createNewFile();
                            } catch (IOException E)
                            {
                                String createerror = new String(E.toString());
                                sender.sendMessage(ChatColor.AQUA + "An Error has occurred!");
                                sender.sendMessage(createerror);
                            }
                            sender.sendMessage(ChatColor.AQUA + "Complete!");
                        }
                    } else {
                        sender.sendMessage(ChatColor.AQUA + "Adding an entry under the name: " + ChatColor.DARK_AQUA + args[0]);
     
                        try{
                            FileWriter fw = new FileWriter(logger, true);
                            if (!logger.exists()){
                                logger.createNewFile();
                                sender.sendMessage(ChatColor.AQUA + "Logger File created");
                            } else {
                                sender.sendMessage(ChatColor.AQUA + "Logger File exists!");
                                fw.flush();
                                fw.write(args[0]);
                                fw.write("\r\n----\r\n");
                                fw.close();
                            }
                        } catch (IOException e){   
                        }
                    }
                }
            if (args.length == 2) {
                if (!logger.exists()){
                    sender.sendMessage(ChatColor.AQUA + "Please use /store createlogger\n");
                    sender.sendMessage(ChatColor.AQUA + "to create a Logger, as one\n");
                    sender.sendMessage(ChatColor.AQUA + "does not already exist.");
                } else {
                    sender.sendMessage(ChatColor.AQUA + "Trying to Log " + args[1] + " entries for: " + args[0]);
                    try {
                        FileWriter fw2 = new FileWriter(logger, true);
                        fw2.flush();
                        int argcount = Integer.valueOf(args[1]);
                        int counter = 0;
                        while (counter < argcount){
                            sender.sendMessage("Printing entry: " + counter);
                            fw2.write(args[0]);
                            fw2.write("\r\n----\r\n");
                            sender.sendMessage("Printed: " + counter);
                            counter = counter + 1;
                        }
                        fw2.close();
     
                    } catch (IOException fwerror){
                        String fwerror2 = fwerror.toString();
                        sender.sendMessage(ChatColor.AQUA + "Entries could not be logged!");
                        sender.sendMessage(ChatColor.AQUA + fwerror2);
                    }
                }
     
            }
            return false;
        }
        public void onDisable() {       
        }
    }
    
    Secondary Jarfile:
    Code:
    package user.flareline.logstore;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
     
    import org.getspout.spoutapi.event.screen.TextFieldChangeEvent;
    import org.getspout.spoutapi.gui.Button;
    import org.getspout.spoutapi.gui.GenericButton;
    import org.getspout.spoutapi.gui.GenericComboBox;
    import org.getspout.spoutapi.gui.GenericLabel;
    import org.getspout.spoutapi.gui.GenericPopup;
    import org.getspout.spoutapi.gui.GenericTextField;
    import org.getspout.spoutapi.player.SpoutPlayer;
     
    @SuppressWarnings("unused")
     
    public class GUI implements Listener{
       
        GenericPopup popup;
        GenericLabel title;
        GenericButton closebutton;
     
        SpoutPlayer player;
     
        int screenid;
        GenericLabel screenidlabel;
     
        int titlelength = 0;
        int descriptionlength = 0;
       
       
        public void GUIMethod(SpoutPlayer player ,Plugin plugin, int TitleLength, int DescriptionLength) {
           
            this.player = player;
            this.screenid = 0;
            this.titlelength = titlelength;
            this.descriptionlength = descriptionlength;
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
       
            title.setX(175);
            title.setY(60);
            title.setHeight(10);
            title.setWidth(80);
           
            closebutton =new GenericButton("Cancel");
            closebutton.setX(200);
            closebutton.setY(200);
            closebutton.setWidth(100);
            closebutton.setHeight(20);
           
            popup = new GenericPopup();
            popup.attachWidgets(plugin, title, closebutton);
            popup.setVisible(true);
            popup.setDirty(true);
           
            player.getMainScreen().attachPopupScreen(popup);
        }
           
            public boolean isCancelButton(Button button){
                        if (button == this.closebutton){
                            return true;
                        }
                        return false;
            }
        }

    I'm sorry if this post is really long and very hard to read...
    Any help is greatly appreciated and I am sorry if this is a very basic issue.
    Cheers, FlareLine.
     
  2. Offline

    Ivan

  3. Offline

    FlareLine

    Ivan Will do, I'll leave this open and report back here with updated information regarding this issue. :)
     
    Wizardo367 likes this.
Thread Status:
Not open for further replies.

Share This Page