Development Assistance Problem with Minigame Plugin

Discussion in 'Plugin Help/Development/Requests' started by Zekrom2802, Jun 6, 2015.

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

    Zekrom2802

    Hello, I'm trying to make a minigame plugin. I made an own Minigame class with some functions. Here is my code.

    Code:
    public class Minigame {
      
        private String name;
        private List<String> description;
        private String command;
        private List<String> aliases;
      
        public Minigame(String name, List<String> description, String command, List<String> aliases) {
            this.name = name;
            this.description = description;
            this.command = command;
            this.aliases = aliases;
        }
      
        public static ArrayList<Minigame> getMinigames() {
            ArrayList<Minigame> minigames = new ArrayList<Minigame>();
            minigames.add(new Minigame("test", Arrays.asList("descr", "iption"), "command", Arrays.asList("alias", "alias2")));
            return minigames;
          
        }
      
      
      
        public String getName() {
            return name;
        }
      
        public List<String> getDescription() {
            return description;
        }
      
        public String getCommand() {
            return command;
        }
      
        public List<String> getAliases() {
            return aliases;
        }
      
        public List<String> getCommandAndAliases() {
            List<String> caa = getAliases();
            caa.add(getCommand());
            return caa;
        }
      
        public static Minigame getMinigame(String name) {
            for(int i = 0; i < getMinigames().size(); i++) {
                if (getMinigames().get(i).getName().equals(name)) {
                    return getMinigames().get(i);
                }
            }
            return null;
        }
    
    
    }
    But now, when I try to use the "getCommandAndAliases()" function I get this error:

    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'comm
    and' in plugin TheGordiansMinigames v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServe
    r.java:646) ~[spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerCon
    nection.java:1139) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java
    :974) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_45]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
            at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot-1.8
    .3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:7
    12) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:3
    68) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:6
    51) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java
    :554) [spigot-1.8.3.jar:git-Spigot-870264a-0a645a2]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.UnsupportedOperationException
            at java.util.AbstractList.add(Unknown Source) ~[?:1.8.0_45]
            at java.util.AbstractList.add(Unknown Source) ~[?:1.8.0_45]
            at com.thegordians.minigames.Minigame.getCommandAndAliases(Minigame.java
    :51) ~[?:?]
            at com.thegordians.minigames.TCommandExecutor.onCommand(TCommandExecutor
    .java:19) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got-1.8.3.jar:git-Spigot-870264a-0a645a2]
    I tried a few things, but nothing helps. Please help me.
     
  2. Offline

    meguy26

    @Zekrom2802
    I think I may know what your problem is, do you use Arrays.asList anywhere? Because Arrays.asList returns a list with a size that cannot be changed, so you cannot add values.

    EDIT:
    If you are using
    Code:
    Arrays.asList(T...);
    anywhere, simply add the following class to your project:
    Code:
    /**
    * The MIT License (MIT)
    *
    * Copyright (c) 2015 neonblue858@gmail.com
    *
    * Permission is hereby granted, free of charge, to any person obtaining a
    * copy of this software and associated documentation files (the
    * "Software"), to deal in the Software without restriction, including
    * without limitation the rights to use, copy, modify, merge, publish,
    * distribute, sublicense, and/or sell copies of the Software, and to permit
    * persons to whom the Software is furnished to do so, subject to the
    * following conditions:
    *
    * The above copyright notice and this permission notice shall be included
    * in all copies or substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
    * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
    * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
    * USE OR OTHER DEALINGS IN THE SOFTWARE.
    */
    package fake.package.name.put.yours.here;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class ListUtil {
        @SafeVarargs
        /**
         * This method has the same effect as {@code Arrays.asList(T... values)} however, this method does not return a fixed-size list, but rather a fully mutable ArrayList.
         * @param values The values of the list.
         * @return The build list.
         */
        public static <T> List<T> buildList(T... values) {
            List<T> toReturn = new ArrayList<T>();
            for (T obj : values) {
                toReturn.add(obj);
            }
            return toReturn;
        }
    }
    
    and replace all calls to "Arrays.asList()" with ListUtil.BuildList().
     
    Last edited: Jun 8, 2015
  3. Offline

    Zekrom2802

    Hello, sorry that I didn't answered yet. Your solution kinda worked, but now I get a new error:

    Code:
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
            at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_45]
            at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_45]
     
  4. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives.
     
Thread Status:
Not open for further replies.

Share This Page