Ripping my hair out. To much, to soon.

Discussion in 'Plugin Development' started by spoonikle, Feb 19, 2011.

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

    fullwall

  2. Offline

    spoonikle

    yeah, it appears that item drop events are very fuzzy. i know of a plug-in that uses dropping to build maybe i could "peruse" there code and stumble upon a solution.

    on a side note, how is the source coming together? whats your opinion?

    also, on the idea itself, i want it for my server as players are casted into job groups, one of them being fisherman. and at the moment the rate of earnings for fishermen is very much lower than farmers, and all other jobs because of lag, and unreliable catch times.
     
  3. Offline

    fullwall

    Well, you're missing much of the main 'doing stuff' bit, but so far, pretty well :).
     
  4. Offline

    spoonikle

    yes, i have to go over the Do while loop, when i do then the plug-in will "work". i say "work" because its not gona do exactly what i want without testing and tweaking.

    another side note, i love the prospect of monster tamer. heres another idea, is it possible to make a plug-in that spawns stationary animals? maybe even with name tags? that would be great for a farm, on a server with no animal spawns. you can even make them dispense items like feathers, milk ,eggs, wool and pork.
     
  5. Offline

    nossr50

    I know that feeling, plugin development was very overwhelming for me at first too (for hMod). You'll soon get used to it though, and once you know what you're doing its loads of fun.
     
  6. Offline

    spoonikle

    first night i was hammering this out, every red squiggly in eclipse set me into a blind rage.
     
  7. Offline

    fullwall

    Hahaha, when I was making Gastronomic, I had absolutely no idea what I was doing, and wrote it in a kind of crazy haze :p. Bit of a bug infestation too...

    To spawn stationary animals, you'd have to stop them from moving each time they tried to, so it'd be a bit of a performance hit, but doable. I'm not sure about name tags, you'd probably have to go to the net.minecraft.server classes for that, and try to do it using the player name tag code as a reference.
     
  8. Offline

    spoonikle

    well, to make it easier on the user of the plug-in, how about making invisible barriers? like one block above and to the sides? that would prevent a dispensing ability though. maybe tell players to put them in a pen, lol

    update, got the add fish1 and 3 methods done, now on to the do while loop.
    with that, i think i am done..... I am afraid, something is going to be wrong, and the code is far from ideal, but i think it will be runnable.
     
  9. Offline

    fullwall

    OK, sounds good. Post the code when you're done if you feel like it needs work. I'd be happy to look at it.
     
  10. Offline

    darknesschaos

    I always try to help whenever I could because when I was more n00by of a coder I had some nasty horrific code. This is something you learn with time.
     
  11. Offline

    spoonikle

    I am greatful for all the help that i have received on this thread, and I will try to list you all in the main file
    /* Special thanks to:
    * You
    *
    \*

    now to make that do while loop... i have all the break events double checked, so no matter what the loop will end. well not a do while loop, just a normal while loop.
     
  12. Offline

    darknesschaos

    Thanks! but I don't think I helped as much as fullwall XD
     
  13. Offline

    spoonikle

    yes, solving my hash map issue was huge. i was really stumped.
    --- merged: Feb 20, 2011 8:52 AM ---
    Okay, this is what it is, for now. I am gonna take a break then go over it, to see if i can spot some huge errors and clean up somethings to make them "sound". i updated my DB http://dl.dropbox.com/u/19143385/BigCatch.rar

    (ill get a github latter)

    it will be hard to read, here is a heads up. I declared timer classes in each of the classes, most of them only reset values, but DelayCatch actually runs the main function of the entire plug-in, inside of a while loop. this allowed me to wait just long enough, i hope, for a fish you fly into the players inventory after they reel in the fishing line before i check to see the status of all the boolean expressions, and then set the while loops trigger to false.
     
  14. Offline

    fullwall

    OK, let's see... In BigCatch, you don't need to define the constructor anymore, it's part of you extending JavaPlugin. Also in BigCatch, I don't think you should put a while loop in the onEnable method, it locks up part of your plugin. You should maybe think of another way to check if that bit is true and a new CatchDelay should be created - maybe onPlayerPickUpItem()?

    In DropFish -
    ItemDrop id = (ItemDrop) event.getItem();
    if(id.getItemStack().getType == Material.RAW_FISH())
    droppedFish = true;

    Sorry I can't analyse your code more, I'm still not at my eclipse yet :/.
     
  15. Offline

    spoonikle

    CatchDelay needs to be triggered after a player uses a fishing rod twice, so its parameters seem to be as correct as they can be without a complete rethink of how everything is handled.

    you are totally right about onEnable, but it makes me wonder where i should place the loop... maybe i could initialize the loop in the onPlayerItemEvent in rod Activation, that way it starts in where its trigger originates.

    i didn't think that it would hang the plug-in because the time runs on a separate thread, only lasts 1 second, and only triggers after 2 PlayerItemEvents involving fishing rods.

    ****WOH, major over site. RodActivation never checks what item the PLAYER_ITEM event involves.*****
    ***FIXED updated source on DB, http://dl.dropbox.com/u/19143385/BigCatch.rar ***

    BTW, i love this forum, how do i get one like it? ** answered my own question.. 140.00 bones.

    ill work on clearing up the onEnable() method, when I am "well rested".
     
  16. Offline

    darknesschaos

    use github man, make life easy to share your code!
     
  17. Offline

    fullwall

    I believe you want onRodActivation to be triggered when you throw a rod... in that case, use
    Code:
    onPlayerItem(PlayerItemEvent event)
    if(event.getItem().getTypeId() == fishingrodId)
    //do your code in the function
    I don't even think the while loop will get triggered - onEnable is only called once, on plugin startup. Can't you use a hashmap to see how many times the rod has been used per player, then make a catchdelay?
     
  18. Offline

    spoonikle

    Code:
    public class RodActivation extends PlayerListener {
    
        /*
         * The proceeding method was written by Yurji Of Sweden A valued member of
         * the Bukkit Forum
         */
    
        private static HashMap<Player, Long> firstUse = new HashMap<Player, Long>();
        static HashMap<Player, Long> fishingTime = new HashMap<Player, Long>();
        static HashMap<Player, Boolean> outFishing = new HashMap<Player, Boolean>();
    
        public void onRodActivation(PlayerItemEvent event) {
            Player player = event.getPlayer();
            Material fishingRod = event.getItem().getType();
    
            if (fishingRod == Material.FISHING_ROD) {
                if (firstUse.containsKey(player)) {
                    Long first = firstUse.get(player); // Retrieve the first time
                    Long second = System.currentTimeMillis(); // Retrieve the second
                                                                // time
                    firstUse.remove(player); // Remove the players firstUse date
                    outFishing.put(player, true); // Sets players outFishing status
                                                    // to True
    
                    Long diff = second - first; // Gets the difference in
                                                // milliseconds
                    fishingTime.put(player, diff);
    
                } else {
                    firstUse.put(player, System.currentTimeMillis());
    
                }
            }
        }
    
    }
    you mean like this?
    i get what your saying about onEnable, you are right I am going to move the while loop, it will not get used unless i move it to another place.

    the hash map fishingTime stores the player and the Differance bettween the logged system times of each use of the fishing rod.

    also, im working on setting up a github, its just not as friendly as dropbox is ATM.
     
  19. Offline

    fullwall

    Well, you want catch delay to be triggered every second rod throw, so you need another HashMap telling you how many times they have thrown the rod.

    About the onPlayerItem, I mean like this
    Code:
    public void onPlayerItem(PlayerItemEvent event) {
            Player player = event.getPlayer();
            Material fishingRod = event.getItem().getType();
    
            if (fishingRod == Material.FISHING_ROD) {
                     //do stuff
                }
    }
    
    --- merged: Feb 20, 2011 10:14 AM ---
    At the moments, onRodActivation will never get called (I don't think).
     
  20. Offline

    spoonikle

    Code:
    package com.hotmail.spoonikle.bigcatch;
    
    import java.util.HashMap;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerItemEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class RodActivation extends PlayerListener {
    
        private BigCatch plugin;
    
        public RodActivation(BigCatch instance) {
            plugin = instance;
        }
    
        /*
         * The proceeding method was written by Yurji Of Sweden A valued member of
         * the Bukkit Forum
         */
    
        private static HashMap<Player, Long> firstUse = new HashMap<Player, Long>();
        static HashMap<Player, Long> fishingTime = new HashMap<Player, Long>();
        static HashMap<Player, Boolean> outFishing = new HashMap<Player, Boolean>();
    
        @SuppressWarnings("static-access")
        public void onPlayerItem(PlayerItemEvent event) {
            Player player = event.getPlayer();
            Material fishingRod = event.getItem().getType();
    
            while (plugin.rodActivation.outFishing.get(plugin.catchFish.getFishingplayer()) == true ) {
                plugin.new CatchDelay(1);
    
            }
    
            if (fishingRod == Material.FISHING_ROD) {
                if (firstUse.containsKey(player)) {
                    Long first = firstUse.get(player); // Retrieve the first time
                    Long second = System.currentTimeMillis(); // Retrieve the second
                                                                // time
                    firstUse.remove(player); // Remove the players firstUse date
                    outFishing.put(player, true); // Sets players outFishing status
                                                    // to True
    
                    Long diff = second - first; // Gets the difference in
                                                // milliseconds
                    fishingTime.put(player, diff);
    
                } else {
                    firstUse.put(player, System.currentTimeMillis());
    
                }
            }
        }
    
    }
    moved the while loop statement.
    your right! onRodActivation should be changed to onPlayerItem!! (or what ever it is for when a player right clicks the air with an item)

    the hashMap currently sets true if there is a previous record of this event already stored, I still dont see an issue with this method.

    the first part of the loop checks to see if the hashMap firstUse has the the players name in it, if true it takes the value and compares it to the current system time and registers the difference. Then marks the hashMap outFishing to true and places the difference in time from the first click event to the second inside the variable fishingTime, else it registers the event into the hashmap firstUse.

    i do not see any fault or lacking, in this code statement. course I iz bind.
     
  21. Offline

    fullwall

    There should be no problem with the onPlayerItemEvent. I think that the while loop should be an if statement - it's never going to change, there is no iteration occurring.
     
  22. Offline

    spoonikle

    you are right about the fact that there is to iteration stuffs. i could have yet another nested if. but i like having while written their, too me it sounds more... english. its not the most logical thing it the world.... wait a second.... if its a while loop then it will keep scheduling timers untill the fist timer is finished. that means that (if i guess right) 999 timers will be counting for no damn reason.

    if statement it is.

    all i had to do was listen to my retarded excuse, to realize that the plug-in will spam timers until one timer finaly hits 0 and makes outFishing false.

    first i had the dumb idea that it would be a do, while loop, then the still dumb idea that it would be a while loop. all along it should have been a nested if statement.

    java is still a little iffy for me. if i place the if statement in the onPlayerEvent() will it trigger as soon as outFishing is true? i do not think so... i think i will have to make the DelayCatch If statement a method, and have onPlayerEvent() call it at the end of its if statement.

    screw that, the if statement in onPlayerItem() will trigger it DelayCatch() method no need to make a method for a method for a method. just run the method after the second FISHING_ROD event is logged. that means i can remove the outFishing statement as its no longer needed.

    updated source, made the changes, changed the variable newLong to more descriptive rodCastTime.
     
  23. Offline

    fullwall

    Don't beat yourself up - everyone makes errors (especially me :p). Is the source still uploaded in the same spot?
     
  24. Offline

    spoonikle

    yes, dropBox dose a nice thing, it keeps the same public address as long as the file name remains the same.

    i use it to collaborate on with my servers web designer, i publish plans, plug-in instructions, we look over files and make changes, drop Box has gotten a lot of use by me and my servers co-founder.

    (my awesome server of awesome-niss is currently off line, awaiting a complete overhaul of its game play MECH, and a redesign of its website.)

    um, one of the things i am looking for, is a plug-in that allows you to make a chest that automatically refills itself every few minutes. maybe i will write one, but if there is one already i would like to use it. alternatively an infinite dispenser would be nearly as awesome.

    one part of my server that im hoping to have is a bandit Group, and a police group. one of the game play MECHs of the bandit group that i planned out, involves stealing from non-player owned areas, like a mock lumber mill, bank, or ore refinery inside the city limits, a refreshing chest would allow me to set an amount they can steal and how often.
    --- merged: Feb 21, 2011 2:20 AM ---
    ok, so i have started running and testing.
    I am looking at a lot of null pointer exceptions.

    at one point i pressed and held right click with my fishing rod, and it spammed the console with errors that it could not forward the event.

    my timers are pointing at null, and i don't think that events are being passes to them. i may have to use bukkit's schedulers, something i don't know how to do. I updated the source, http://dl.dropbox.com/u/19143385/BigCatch.rar i got a gitHub but i cant get it to commit the changes.

    can you help me read this, and test it. how would i test this program in eclipse?

    [​IMG]
     
  25. Offline

    darknesschaos

    well, the problem is on line 21 under onPlayerDropItem
     
  26. Offline

    spoonikle

    I am working on changing all of the variables, here is the current version of the DropFish class.

    Code:
    package com.hotmail.spoonikle.bigcatch;
    
    import java.util.Timer;
    import java.util.TimerTask;
    import org.bukkit.Material;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class DropFish extends PlayerListener {
    
        private boolean dropedFish = false;
    
        // method for the reset timer to reset dropedFish to false.
        public void setDropedFish(boolean dropedFish) {
            this.dropedFish = dropedFish;
        }
    
        public void onPlayerDropItem(PlayerDropItemEvent event) {
                Material dropEvent = event.getItemDrop().getItemStack().getData().getItemType();
            if (dropEvent == Material.RAW_FISH)
                dropedFish = true;
            new DropReset(60); // resets dropedFish to false after 60 seconds.
    
        }
    
        public boolean isDropedFish() {
            return dropedFish;
        }
    
        // Declaration of a Timer, to reset the value dropedFish
        public class DropReset {
            Timer timer;
    
            public DropReset(int seconds) {
                timer = new Timer();
                timer.schedule(new RemindTask(), seconds * 1000);
            }
    
            // Declaration of the timer and its method.
            class RemindTask extends TimerTask {
                public void run() {
                    setDropedFish(false);
                }
            }
        }
    }
    
    I am focusing on this, and relocated the place where I identify the player.

    Material dropEvent = event.getItemDrop().getItemStack().getData().getItemType(); I am not sure about this.... i dont think it works.

    i got all night to look over my source.
    --- merged: Feb 21, 2011 4:07 AM ---
    this is very close, very close. it actually needs to be -
    Code:
    public void onPlayerDropItem(PlayerDropItemEvent event) {
            ItemDrop id = (ItemDrop) event.getItemDrop();
            if(id.getItemStack().getType() == Material.RAW_FISH){
                dropedFish = true;
            new DropReset(60); // resets dropedFish to false after 60 seconds.
            }
    i just started running again. and I am not seeing errors in console.


    *****OMFGBBQ IT WORKS!!!!!!!!!

    *********I am unable to catch a fish normaly..... Item spawn event is being stoped.....

    *********** No i can catch a fish I am just bad at it.... the delay event isnt long enough if you cast your line too far then CatchFish may not be true when 1 second passes. rather weird.

    next feature to add, random number generator number 1-10 numbers 1-4 = catch a fish, 5-6 = leather boots (damaged), 7 = leather helmet (damaged), 8-9 = bone, 10 = nothing. for when a player dose not get a "BigCatch"

    I'm starting to think the window of exploitation is very small, i may remove the DropFish variable entirely.

    OK, here is the bug, CatchFish isn't becoming true when the player picks up the fish.... i will have to look into this... i may change it so that its just a percent chance of catching bonus fish and items instead of checking if you caught a fish.

    Ill see if i can solve the issue.

    the problem lies in, finding the material type of the item a player picks up.
    --- merged: Feb 21, 2011 6:46 AM ---
    alright, i think Its ready. I am gonna tweak some of the timing and make the time till you qualify for a big catch shorter. I love the "random" item thing its really fun! I just need to catch a damn fish to trigger a big catch event to see if it works completely.
     
  27. Offline

    fullwall

    Sorry, I went to sleep :p. Nice to see your issues were fixed :).
     
Thread Status:
Not open for further replies.

Share This Page