Developing help

Discussion in 'Spigot Plugin Development' started by suitinacow, Jun 29, 2015.

  1. Hey guys, this is my first plugin and I'm having trouble exporting my maven project as a .jar file. when i export the file it says this: [​IMG]

    This might be an effect of my pom.xml which has an error saying:
    Code (Text):
    Failure to transfer net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer artifact net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): The operation was cancelled.

    org.eclipse.aether.transfer.ArtifactTransferException: Failure to transfer net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer artifact net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): The operation was cancelled.
        at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:238)
        at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:206)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:585)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:503)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:367)
        at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:205)
        at org.apache.maven.project.DefaultProjectBuilder.resolveDependencies(DefaultProjectBuilder.java:215)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:188)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:119)
        at org.eclipse.m2e.core.internal.embedder.MavenImpl.readMavenProject(MavenImpl.java:636)
        at org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.resolveProjectDependencies(DefaultMavenDependencyResolver.java:63)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refreshPhase2(ProjectRegistryManager.java:529)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$3.call(ProjectRegistryManager.java:491)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$3.call(ProjectRegistryManager.java:1)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:495)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:350)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:297)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.getProjectFacade(MavenBuilder.java:154)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:89)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200)
        at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
        at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:262)
        at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:402)
        at org.eclipse.core.internal.resources.Project$1.run(Project.java:556)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
        at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:534)
        at org.eclipse.core.internal.resources.Project.build(Project.java:111)
        at org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.buildProjects(JarFileExportOperation.java:1159)
        at org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.singleRun(JarFileExportOperation.java:1006)
        at org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.execute(JarFileExportOperation.java:987)
        at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:108)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
        at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:130)
        at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
     
    My two classes look like this :
    Code (Text):
    package io.github.suitinacow.TestPlugin;

    import java.awt.List;
    import java.lang.reflect.Array;
    import java.util.ArrayList;

    import org.apache.commons.lang.StringUtils;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Commands extends JavaPlugin implements Listener {
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("addLine"))
            {
                if(sender instanceof Player)
                {
                    String sentence = StringUtils.join(args);
                    ArrayList<String> sentences = new ArrayList<String>();
                    sentences.add(sentence);
                    player.sendMessage(player.getName() + ", " + sentence);
                    this.getConfig().set("path.to.sentences", sentences);
                    this.saveConfig();
                }
            }
         
            if(cmd.getName().equalsIgnoreCase("testRl")){
                this.saveConfig();
                this.reloadConfig();
                if(!(sender instanceof Player))
                {
                    sender.sendMessage("Must be a player.");
                }
                else
                {
                    player.sendMessage(player.getName() + ", plugin is reloaded.");
                }
                return true;
            }
            return false;
        }
     

    }
     
    And

    Code (Text):
    package io.github.suitinacow.TestPlugin;

    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public final class TestPlugin extends JavaPlugin implements Listener {      
         
        @Override
        public void onEnable(){
            this.saveDefaultConfig();
        }

        @Override
        public void onDisable() {
            this.saveConfig();
        }

    }
     
     
  2. In your plugin.yml which one did you istablish as your main class?
     
    • Funny Funny x 3
  3. The class with the enable and disable methods should be the only one with extends javaPlugin, you do NOT need to extends javaPlugin for a command executor
     
  4. Creeoer

    Supporter

    Btw what's with the this statements, you don't really need them...
     
  5. Your first plugin?

    FIRST PLUGIN!!!!!???

    This thing is two classes dude. If you're having issues like this

    A. Learn Java

    B. Start with a basic tutorial

    I can already tell you for config you don't need two classes. You don't need so many array lists. All you need is to get the stuff from the config (which it looks like you're trying to do) by doing getConfig().getString("string name")
     
    • Agree Agree x 1

  6. i've read many tutorials before starting my first plugin and i made the main class for the onEnable and onDisbale and had another class for commands only just to organize things better.. i'm not trying to get anything from the config. im trying to add what i type into the game chat and display it back to me and also store it into my config.yml.. this is all for practice so i understand storing better.
     

  7. thanks for the tip
     
  8. what do you mean my statements? im trying to store what i type after "/addline" to the config.. im doing it for practice.
     
  9. but i did make some changes since the post.. if you want to see it its right here:
    Code (Text):
    if(cmd.getName().equalsIgnoreCase("addLine"))
            {
                if(sender instanceof Player)
                {
                    String sentence = args.toString();
                    player.sendMessage(player.getName() + ", " + sentence);
                    this.getConfig().addDefault("sentences", sentence);
                    this.saveConfig();
                }
            }
    better?
     
  10. Isnt sentence already a string.. ?
     
  11. no its ony created in line
    Code (Text):
    String sentence = args.toString();
     
  12. Ok, and your command wouldn't be/addline it would be /addLine
     
  13. /addline and /addLine are treated the same.. it wouldnt make a difference when you type it in game?