[INACTIVE][FUN/FIX] Chasten v1.0 - Discourage players from logging out [1000]

Discussion in 'Inactive/Unsupported Plugins' started by codename_B, Aug 8, 2011.

  1. Offline

    codename_B

    Chasten
    Discourage players from logging out
    [​IMG]
    What it does:
    - drops a players inventory when they quit.

    How to use:
    - drop into plugins/ and use the command "/reload"

    Permissions:
    - this plugin respects the OP system, it also has an admin node "Chasten.admin"
    - any OP/player with this node will NOT drop their inventory when they quit

    Download 1.0:
    - Main Mirror

    Source:
    Code:
    /**
     * I am on a bus, and I am bored.
     * Will code.
     */
    package de.bananaco.chasten;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    /**
     * A simple anti-logout plugin Useful for PVP and non-PVP servers Encourages
     * players to place their items in a chest, very strongly
     *
     * @author codename_B
     * @date 08/08/2011
     */
    public class Chasten extends JavaPlugin {
    
        @Override
        public void onDisable() {
            /*
             * What else do you want me to say?
             */
            System.out.println("[Chasten] Disabled.");
        }
    
        @Override
        public void onEnable() {
            /*
             * Fairly obvious
             */
            System.out.println("[Chasten] Enabled.");
            /*
             * Even more obvious
             */
            System.err.println("[Chasten] You will never be as cool as codename_B");
            /*
             * Let's register the event so this plugin actually does something
             */
            getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT,
                    new ChastenPlayer(), Priority.Monitor, this);
        }
    
    }
    
    /**
     * The listener class, the actual work is done here.
     *
     * @author codename_B
     * @date 08/08/2011
     */
    class ChastenPlayer extends PlayerListener {
        public void onPlayerQuit(PlayerQuitEvent event) {
            Player player = event.getPlayer();
            /*
             * If our player is an admin, or has the admin override node we don't
             * make this apply.
             */
            if (player.isOp() || player.hasPermission("Chasten.admin"))
                return;
            /*
             * All other players however drop their inventory on the ground! We use
             * .clone(); to ensure that when we clear their inventory we still have
             * the contents in memory.
             */
            ItemStack[] stacks = player.getInventory().getContents().clone();
            /*
             * Now we clear the inventory of the player.
             */
            player.getInventory().setContents(new ItemStack[stacks.length]);
            /*
             * And loop through the ItemStacks in the inventory of the player!
             */
            for (ItemStack stack : stacks)
                /*
                 * A little safety check, we don't want NPE's
                 */
                if (stack != null)
                    /*
                     * And drop the item
                     */
                    player.getWorld()
                            .dropItemNaturally(player.getLocation(), stack);
            /*
             * And now we do a little cleanup to ensure that there are no memory
             * leaks for those idiots not using -xincgc flags, or lags on mass
             * player quit.
             */
            stacks = null;
        }
    }
    
    Changelog:
    - 08/08/2011 - released 1.0
     
    varunax likes this.
  2. Offline

    adreide

    It's a little too annoying for the players I think.

    Here is an idea to add some verification:
    - remembering the last time the player was hit by another player
    - remembering the time when the player has logged in

    With these two values you can do two different actions:

    if ((time - timeHit) < someValue) dropItemsAndClearInventory();
    if ((time - timeLogged) < someValue) clearInventory();

    The first condition could be a little more precise so that players won't try to hit people randomly when they say goodbye to steal their stuff.

    The second one will prevent users from logging and disconnecting quickly. Perhaps adding a little counter so that players that simply crashes on a login won't have their inventories removed.

    But all this is just a suggestion.
     
  3. Offline

    codename_B

    @adreide - brilliant ideas. I'll have to make them optional via a config file if/when I implement them.
     
  4. Offline

    Grammar Troll

    Thanks for putting those comments in the source, it's really instructive!
     
  5. Offline

    codename_B

    No worries - if you have any ideas for this plugin - suggest them to me :D
     
  6. Offline

    bloodtake

    I have an idea! You could make it so the longer you play the faster you can mine! My Om Nom Diamonds plugin does a instant mine when eating a diamond so it shouldn't be to hard to just increase mining by time?
     
  7. Offline

    L5D

    You can check if player quit or if player has timeout, because client can crash.
    But player can kill client to don't lost his inventory. Maybe optionnal.
     
  8. Offline

    codename_B

    I don't want to do that though - it doesn't matter HOW they got logged out - the point is they shouldn't be keeping valuables on them :p adds the scare back to minecraft.

    Wha?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  9. Offline

    w000rm

    What does it have to do with this plugin? XD
     
  10. Offline

    blindsarcasm

    Its a suggestion that, instead of discouraging players to log off, encourage them to stay on
     
  11. Offline

    codename_B

    That's not the point here :p
     
  12. Offline

    bloodtake

  13. Offline

    codename_B

  14. This is an awesome solution to maintaining an economy, as the items stay "in circulation". The default option to leave with your items is like someone irl taking all their items to the afterworld when they die.
    Just thought of a possible feature, like life insurance, if you die, or logout (either way you are leaving the world) then if someone is online that is a friend, lets say, they get the inheritance. Otherwise it just drops.
     
  15. it discourages them from logging out because they must drop items in a chest, so someone who has mined diamonds for hours doesnt want to lose a whole fucking stack, use some common sense he did his best to work around the impossible. a server that has worldguard can make house plots and such so that only they can access their chests, if the only way to safely store the whole stack of diamonds is to store it in a chest only you can access (stupid griefers) then you must walk ALL THE WAY BACK - for some people thats more than enough to force someone to keep playing
     
  16. Offline

    varunax

    Love this mod. I really hate it when players are just abusing logging out of every death situation possible. Thanks for this.
     
  17. Offline

    alexander_q

    I searched for days for a plugin that does exactly this. Trying to run it with the latest craftbukkit (1532) and I get...

    ... At startup. Does this need to be updated?
     
  18. Offline

    md_5

    @codename_B
    As you know this is now inactive due to not being maintained if it is on Bukkitdev or you wish to revive it tag me.
     

Share This Page