Solved plugin not working

Discussion in 'Plugin Development' started by vhbob, Feb 3, 2016.

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

    vhbob

    Hey, i made a plugin and its not starting up, idk why... heres my code (yes my plugin.yml is fine
    Code:
    package com.vhbob.coins;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CoinsMain extends JavaPlugin {
    
        public Logger logger = Bukkit.getLogger();
    
        public void onEnable() {
            logger.info(ChatColor.GREEN + "The Coins Plugin By Vhbob Has Been Enabled!");
        }
    
        public void onDisable() {
            logger.info(ChatColor.RED + "The Coins Plugin By Vhbob Has Been Disabled!");
        }
    
        @EventHandler
        public void join(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if (!getConfig().contains(p.getName() + " Coins")) {
                getConfig().set(p.getName() + " Coins", 0);
                saveConfig();
            }
        }
    
        public void giveCoins(Player p, int i){
            int bal = getConfig().getInt(p.getName() + " Coins");
            getConfig().set(p.getName() + " Coins", bal + i);
            saveConfig();
            p.sendMessage("You Have Earned " + ChatColor.GREEN + i + ChatColor.RESET + " Coins");
        }
    
        public void takeCoins(Player p, int i){
            int bal = getConfig().getInt(p.getName() + " Coins");
            getConfig().set(p.getName() + " Coins", bal - i);
            saveConfig();
            p.sendMessage("You Have Lost " + ChatColor.RED + i + ChatColor.RESET + " Coins");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                if (cmd.getName().equalsIgnoreCase("CoinBalance")) {
                    int bal = getConfig().getInt(p.getName() + " Coins");
                    p.sendMessage("You have " + ChatColor.GOLD + bal + ChatColor.RESET + " coins!");
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Only players can exacute this command!");
            }
            return false;
        }
    
    }
    
    )
     
  2. Offline

    MarinD99

    You haven't registered the listeners.
     
  3. Offline

    WinX64

    Not starting up as...? Not loading? Not working like intended? Something is happening but it shouldn't be?
    Something that you missed was to register your listener.
     
  4. Offline

    vhbob

    @WinX64 @MarinD99 the server isnt booting up and it says its because of this error:
    Code:
    com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1
     
  5. Offline

    WinX64

    What's the rest of the stack trace? Or is that all of it?
     
  6. Add @Override annotation on onEnable, onDisable and onCommand, also as @MarinD99 said you haven't registered events.

    Events
     
  7. Offline

    vhbob

    @MaTaMoR_ i registered my events and put @Override and it still no work

    @WinX64 the rest of the stack trace is this :
    Code:
    ---- Minecraft Crash Report ----
    // My bad.
    
    Time: 2/3/16 5:42 PM
    Description: Exception in server tick loop
    
    com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1
        at com.google.gson.Gson.fromJson(Gson.java:815)
        at com.google.gson.Gson.fromJson(Gson.java:768)
        at net.minecraft.server.v1_8_R3.JsonList.load(JsonList.java:172)
        at net.minecraft.server.v1_8_R3.DedicatedPlayerList.z(SourceFile:99)
        at net.minecraft.server.v1_8_R3.DedicatedPlayerList.<init>(SourceFile:25)
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:179)
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:504)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1
        at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:338)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
        at com.google.gson.Gson.fromJson(Gson.java:803)
        ... 7 more
    
    
    A detailed walkthrough of the error, its code path and all known details is as follows:
    ---------------------------------------------------------------------------------------
    
    -- System Details --
    Details:
        Minecraft Version: 1.8.8
        Operating System: Windows 8.1 (amd64) version 6.3
        Java Version: 1.7.0_79, Oracle Corporation
        Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
        Memory: 180641152 bytes (172 MB) / 322961408 bytes (308 MB) up to 3795320832 bytes (3619 MB)
        JVM Flags: 0 total;
        IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
        CraftBukkit Information:
       Running: CraftBukkit version git-Bukkit-18fbb24 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT) true
       Plugins: { Coins v0.1 com.vhbob.coins.CoinsMain [Vhbob],}
       Warnings: DEFAULT
       Reload Count: 0
       Threads: { RUNNABLE Thread-4: [java.lang.Throwable.fillInStackTrace(Native Method), java.lang.Throwable.fillInStackTrace(Throwable.java:783), java.lang.Throwable.<init>(Throwable.java:265), java.lang.Exception.<init>(Unknown Source), java.io.IOException.<init>(Unknown Source), java.io.FileOutputStream.writeBytes(Native Method), java.io.FileOutputStream.write(Unknown Source), java.io.BufferedOutputStream.flushBuffer(Unknown Source), java.io.BufferedOutputStream.write(Unknown Source), java.io.PrintStream.write(Unknown Source), org.fusesource.jansi.AnsiOutputStream.write(AnsiOutputStream.java:82), java.io.FilterOutputStream.write(Unknown Source), java.io.PrintStream.write(Unknown Source), java.io.FilterOutputStream.write(Unknown Source), org.bukkit.craftbukkit.v1_8_R3.util.TerminalConsoleWriterThread.run(TerminalConsoleWriterThread.java:44), java.lang.Thread.run(Unknown Source)], RUNNABLE Signal Dispatcher: [], RUNNABLE Attach Listener: [], RUNNABLE Server thread: [java.lang.Thread.dumpThreads(Native Method), java.lang.Thread.getAllStackTraces(Unknown Source), org.bukkit.craftbukkit.v1_8_R3.CraftCrashReport.call(CraftCrashReport.java:29), net.minecraft.server.v1_8_R3.CrashReportSystemDetails.a(SourceFile:78), net.minecraft.server.v1_8_R3.CrashReport.h(CrashReport.java:127), net.minecraft.server.v1_8_R3.CrashReport.<init>(CrashReport.java:34), net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:554), java.lang.Thread.run(Unknown Source)], RUNNABLE DestroyJavaVM: [], WAITING Finalizer: [java.lang.Object.wait(Native Method), java.lang.ref.ReferenceQueue.remove(Unknown Source), java.lang.ref.ReferenceQueue.remove(Unknown Source), java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)], WAITING Reference Handler: [java.lang.Object.wait(Native Method), java.lang.Object.wait(Object.java:503), java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)], WAITING Snooper Timer: [java.lang.Object.wait(Native Method), java.lang.Object.wait(Object.java:503), java.util.TimerThread.mainLoop(Unknown Source), java.util.TimerThread.run(Unknown Source)], RUNNABLE Netty Server IO #0: [sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method), sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source), sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source), sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source), sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source), sun.nio.ch.SelectorImpl.select(Unknown Source), io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622), io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310), io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116), java.lang.Thread.run(Unknown Source)], TIMED_WAITING Server Infinisleeper: [java.lang.Thread.sleep(Native Method), net.minecraft.server.v1_8_R3.DedicatedServer$1.run(DedicatedServer.java:53)],}
       Recent tasks from -31--1{}
        Profiler Position: N/A (disabled)
        Is Modded: Definitely; Server brand changed to 'CraftBukkit'
        Type: Dedicated Server (map_server.txt)
     
    Last edited by a moderator: Feb 3, 2016
  8. When you set or get anything try with :
    Code:
    player.getName() + ".Coins" 
    
     
  9. Offline

    vhbob

  10. Offline

    mythbusterma

    @vhbob @MaTaMoR_

    If you read the stack trace, it has nothing to do with the plugin. One of the .json files the server creates is corrupted. Just delete all the .json files that the server uses.
     
  11. Offline

    vhbob

    ill try that haha... thanks
     
  12. Yeah, it was strange, i really don't know what it was.
     
Thread Status:
Not open for further replies.

Share This Page