Results 1 to 6 of 6
  1. #1

    Retired Prophet
    ToxicJew.'s Avatar
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,781
    Points
    7,586
         User Info     Contact     Gamer ID
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,781
    Points
    7,586

    Contact info:

    Youtube Channel: http://www.youtube.com/kennethbgoodin

    Default My entry in 50 Lines or less Snippet Challenge

    Entered this contest on Spigot where you write a plugin using 50 lines or less. I think my entry's pretty neat: https://www.spigotmc.org/threads/50-...6#post-1088045

    I compressed a pickpocketing system I made down to 50 lines. Has inventory scrambling to hide what you're stealing and only works if the player you're trying to pickpocket can't "see" you (determined by a cone generated to represent clicked player's view.

    Code:
    package com.kbg.Pickpocket;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.inventory.InventoryAction;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class Pickpocket extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
        public void onEnable() {
            this.getServer().getPluginManager().registerEvents  (this, this);
        }
        @org.bukkit.event.EventHandler
        public void onRightClickPlayer(org.bukkit.event.player.PlayerI  nteractEntityEvent event) {
            if (event.getRightClicked() instanceof Player && !isPlayerInCone(event.getPlayer(), (Player) event.getRightClicked(), (event.getPlayer().isSneaking() ? 70 : 90), 5)) //clicking player isn't visible to clicked
                    event.getPlayer().openInventory(scramble(event.get  Player(), (Player) event.getRightClicked()));  
        }
        public static boolean isPlayerInCone(Player p, Player clicked, double coneAngle, double radius) {
            final double coneArea = Math.tan(coneAngle) * Math.tan(coneAngle), radiusSquared = radius * radius;
            org.bukkit.util.Vector n = p.getLocation().toVector().subtract(clicked.getLocation().toVector()).normalize();
            return (clicked.getLocation().getDirection().normalize().  crossProduct(n).lengthSquared() <= coneArea // within cone
                    && clicked.getLocation().distanceSquared(p.getLocatio  n()) <= radiusSquared // within radius
                    && clicked.getLocation().getDirection().dot(n) >= 0); // same direction
        }
        public static Inventory scramble(Player player, Player clicked) {
            Inventory scrambled = org.bukkit.Bukkit.createInventory(clicked, player.getInventory().getSize(), "Pickpocket");
            ItemStack[] newContents = new ItemStack[clicked.getInventory().getContents().length];
            for (int i = 0; i < clicked.getInventory().getContents().length; i++) {
                if (clicked.getInventory().getContents()[i] != null) {
                    ItemStack item = new ItemStack(clicked.getInventory().getContents()[i].getType(), clicked.getInventory().getContents()[i].getAmount());
                    ItemMeta im = item.getItemMeta();
                    im.setDisplayName(org.bukkit.ChatColor.MAGIC + im.getDisplayName());
                    item.setItemMeta(im);
                    item.setType(org.bukkit.Material.PAPER);
                    newContents[i] = item;
                }
            }
            scrambled.setContents(newContents);
            return scrambled;
        }
        @org.bukkit.event.EventHandler
        public void onInventoryClick(org.bukkit.event.inventory.Invent  oryClickEvent event) {
            if (event.getWhoClicked() instanceof Player && event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && event.getClickedInventory().getName().equals("Pickpocket")) {
                ((Player) event.getWhoClicked()).getInventory().addItem(((Pl  ayer) event.getInventory().getHolder()).getInventory().g  etItem(event.getSlot()));
                ((Player) event.getInventory().getHolder()).getInventory().c  lear(event.getSlot());
                ((Player) event.getWhoClicked()).closeInventory();
                event.setCancelled(true);
            }
        }
    }
    Edit: Rewrote one method to use streams, haven't tested it (and no need since the original works), but figured I'd post it anyway. Saved me two whole lines! http://i.imgur.com/Boh2RSy.png

    Proof it works

    Proof it's only 50 lines.

    1 Not allowed! Not allowed!
    Last edited by ToxicJew.; 10-27-2015 at 11:18 AM.
    ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้ส็็็็็็็็็็็็็็็็็็็็ ็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้

  2. #2
    I'ma Fuckin Scalie

    Feckless.'s Avatar
    Join Date
    Dec 2008
    Location
    F̷̧̨̙̞̱̥̓̄̂ͯ̃ͬ̚̚͟U&#
    Posts
    3,012
    Points
    8,633
         User Info     Contact     Gamer ID
    Join Date
    Dec 2008
    Location
    F̷̧̨̙̞̱̥̓̄̂ͯ̃ͬ̚̚͟U&#
    Posts
    3,012
    Points
    8,633
    Gamer IDs

    Gamertag: XEFDragon Steam ID: SketchyDragon

    Default

    fuck.

    dude, i can literally see you running a multi-million dollar software development company while being the lead programmer.

    0 Not allowed! Not allowed!

    Quote Originally Posted by OSaMaBiNLoGiN View Post
    HOLY SHIT KILL YOURSELF
    Quote Originally Posted by Fuck Sky View Post
    Are you fucking retarded

  3. #3

    Retired Prophet
    ToxicJew.'s Avatar
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,781
    Points
    7,586
         User Info     Contact     Gamer ID
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,781
    Points
    7,586

    Contact info:

    Youtube Channel: http://www.youtube.com/kennethbgoodin

    Default

    Thanks man! I've still got a lot to learn though lol.

    0 Not allowed! Not allowed!
    ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้ส็็็็็็็็็็็็็็็็็็็็ ็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้

  4. #4
    Active Member
    Join Date
    Sep 2010
    Posts
    2,563
    Points
    1,839
         User Info     Contact     Gamer ID
    Join Date
    Sep 2010
    Posts
    2,563
    Points
    1,839
    Gamer IDs

    PSN ID: wieisjason

    Default

    and I thought I was going somewhere building my portfolio from scratch, great work man

    0 Not allowed! Not allowed!
    "Rank does not confer power or privilege, it imposes responsibility."

  5. #5

    Retired Prophet
    ToxicJew.'s Avatar
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,781
    Points
    7,586
         User Info     Contact     Gamer ID
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,781
    Points
    7,586

    Contact info:

    Youtube Channel: http://www.youtube.com/kennethbgoodin

    Default

    This is the first challenge like this I've entered, added it to my portfolio immediately lol.

    0 Not allowed! Not allowed!
    ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้ส็็็็็็็็็็็็็็็็็็็็ ็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้

  6. #6
    Bad Company
    RED 58's Avatar

    Badge

    Join Date
    Jan 2012
    Location
    Goober's Coder CP
    Posts
    6,918
    Points
    9,658
         User Info     Contact     Gamer ID
    Join Date
    Jan 2012
    Location
    Goober's Coder CP
    Posts
    6,918
    Points
    9,658

    Default

    Quote Originally Posted by Feckless. View Post
    fuck.

    dude, i can literally see you running a multi-million dollar software development company while being the lead programmer.
    Well shit... if he needs a body guard lemme know lol.

    0 Not allowed! Not allowed!



    Quote Originally Posted by Iced View Post
    Red 58 = Swoot (Reincarnated)
    Quote Originally Posted by GOOBER View Post
    Terr0r you need a Gecko. Lets go to the Pet store and buy one
    Quote Originally Posted by ABlackGuy View Post
    He may not have a soul but he still has a brain. Unlike Russ who has neither.

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 10:33 PM.
Powered by vBulletin®
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.