Development Assistance Serializing Object

Discussion in 'Plugin Help/Development/Requests' started by flash1110, Apr 17, 2015.

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

    flash1110

    Trying to serialize my "koth" object. Here is the stack trace and the code.


    Code:
    Error occurred while enabling TXKoth v1.0 (Is it up to date?)
    org.bukkit.craftbukkit.libs.com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
        at org.bukkit.craftbukkit.libs.com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.libs.com.google.gson.Gson.fromJson(Gson.java:803) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.libs.com.google.gson.Gson.fromJson(Gson.java:768) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.libs.com.google.gson.Gson.fromJson(Gson.java:717) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.libs.com.google.gson.Gson.fromJson(Gson.java:689) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at me.flash1110.txkoth.Main.onEnable(Main.java:62) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:340) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:312) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:723) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.Bukkit.reload(Bukkit.java:543) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:624) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1058) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:919) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-00eba53]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_31]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_31]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:643) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:598) [craftbukkit.jar:git-Bukkit-00eba53]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:506) [craftbukkit.jar:git-Bukkit-00eba53]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_31]
    Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
        at org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonReader.beginObject(JsonReader.java:374) ~[craftbukkit.jar:git-Bukkit-00eba53]
        at org.bukkit.craftbukkit.libs.com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165) ~[craftbukkit.jar:git-Bukkit-00eba53]
        ... 27 more
    
    OnEnable:
    Code:
    Koth toAdd = gson.fromJson(str.toString(), Koth.class);
                addKoth(toAdd.getName(), toAdd);
    OnDisable:
    Code:
    Gson gson = new Gson();
    
    
    String str = gson.toJson(koth);
    
    
    if (settings.getRegion().getConfigurationSection("koth") == null) { settings.getRegion().createSection("koth"); settings.saveRegion(); }
    
    if (settings.getRegion().get("koth." + koth.getName()) == null) {
    
        settings.getRegion().set("koth." + koth.getName(), str.toString());
    
    }
    
    settings.saveRegion();
     
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  3. Offline

    Lolmewn

    What's in your KOTH object?
     
  4. Offline

    flash1110

    Sorry, was at school. Here is my Koth class @Lolmewn


    Code:
    package me.flash1110.txkoth;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    
    public class Koth implements Serializable {
    
        private String name;
        private Cuboid cuboid;
        private int captureTime;
        private boolean Active;
        public static ArrayList<Koth> on = new ArrayList<Koth>();
     
        public Koth(String name, Cuboid cuboid, int captureTime) {
            this.name = name;
            this.cuboid = cuboid;
            this.captureTime = captureTime;
            Active = false;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        public Cuboid getCuboid() {
            return this.cuboid;
        }
     
        public void setCuboid(Cuboid cuboid) {
            this.cuboid = cuboid;
        }
     
        public int getCaptureTime() {
            return this.captureTime;
        }
     
        public void setCaptureTime(int captureTime) {
            this.captureTime = captureTime;
        }
     
        public Boolean getActive() {
            return Active;
        }
     
        public void setActive(boolean active) {
            Active = active;
        }
     
        public Boolean isKothOn(Koth koth) {
            if (on.contains(koth)) {
                return true;
            }
            return false;
        }
     
        public void run(CommandSender sender) {
            if (Active) {
                sender.sendMessage(Main.getPrefix() + ChatColor.RED + "Koth " + ChatColor.WHITE + getName() + ChatColor.RED + " already activated");
                return;
            }
            Active = true;
         
            Bukkit.getServer().broadcastMessage(Main.getPrefix() + ChatColor.GREEN + "Koth " + getName() + " has been started by " + ChatColor.GOLD + sender.getName() + "!");
            Bukkit.getServer().broadcastMessage(Main.getPrefix() + ChatColor.GREEN + "Koth " + getName() + " has a capture time of " + ChatColor.LIGHT_PURPLE + getCaptureTime() + ".");
            Bukkit.getServer().broadcastMessage(Main.getPrefix() + ChatColor.WHITE + ChatColor.BOLD + "Use /koth toggle to enable/disable koth messages.");
            on.add(Main.getKoth(getName()));
        }
    
        public void stop(CommandSender sender) {
            if (!Active) {
                sender.sendMessage("Koth is not activated");
                return;
            }
            Active = false;
         
            Bukkit.getServer().broadcastMessage(Main.getPrefix() + ChatColor.GREEN + "Koth " + getName() + " has been ended by " + ChatColor.GOLD + sender.getName() + "!");
            on.remove(Main.getKoth(getName()));
        }
    }
    
     
    Last edited: Apr 17, 2015
  5. Offline

    flash1110

Thread Status:
Not open for further replies.

Share This Page