codename_B's list of plugins under 50 lines of code AKA the under 50 challenge

Discussion in 'Resources' started by codename_B, Aug 23, 2011.

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

    thehutch

    hmm trying but idk how to spawn primed tnt :(
     
  2. Offline

    md_5

    block.getWorld().spawn(location, TNTPrimed.class);
     
  3. Offline

    Rahazan

    Here, SimpleBlock
    A plugin that allows one to disallow people with a certain permission to place a block defined in the permission.

    25 lines
    Code:java
    1. package me.rahazan.simpleblock;
    2. import java.util.logging.Logger;
    3. import org.bukkit.event.Event;
    4. import org.bukkit.event.block.BlockListener;
    5. import org.bukkit.event.block.BlockPlaceEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. public class SimpleBlock extends JavaPlugin {
    8. @Override
    9. public void onEnable() {
    10. this.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACE, new blockListener(), Event.Priority.Highest, this);
    11. Logger.getLogger("Minecraft").info("[SimpleBlock] by Rahazan loaded.");
    12. }
    13. @Override
    14. public void onDisable() {
    15. Logger.getLogger("Minecraft").info("[SimpleBlock] by Rahazan unloaded.");
    16. }
    17. }
    18. class blockListener extends BlockListener {
    19. public void onBlockPlace(BlockPlaceEvent event) {
    20. if (event.getPlayer().hasPermission("simpleblock." + event.getBlock().getTypeId())){
    21. event.getPlayer().sendMessage(org.bukkit.ChatColor.DARK_RED + "You are not capable of doing this.");
    22. event.setBuild(false);
    23. }
    24. }
    25. }
     
  4. Offline

    thehutch

    The most pointless and stupid plugin ever :p I present to you the 10 coding lines of awesome :p
    ThePluginWhichOnlyUsageIsToEnableItself
    [PS] not going to test because idk what it could do to my computer :D
    Code:
    package me.thehutch.testconfig;
    public class ThePluginWhichOnlyUsageIsToEnableItself extends org.bukkit.plugin.java.JavaPlugin {
        public void onDisable() {
            System.out.println("ThePluginWhichOnlyUsageIsToEnableItself is disabled");
        }
        public void onEnable() {
            onEnable();
        System.out.println("ThePluginWhichOnlyUsageIsToEnableItself has been enabled");
        }
    }
     
  5. Without testing I can tell it to you: It will freeze the server and eat up one CPU core. It's the same as you have a "bad" (never ending) for/while loop in a plugin. ;)
    Well, maybe it will eat up RAM, too... Hmm, now I want to test it to get sure. :D
     
  6. Offline

    thehutch

    Fell free I wasnt sure to call the plugin DDos yourself but that would be incorrect :D anyway have fun tell me when your computer reboots :p
     
    Fishrock123 likes this.
  7. Java refuses to load this (Yes, I renamed the class): http://pastebin.com/J6peLpaP :D
     
  8. Offline

    thehutch

    Yes because there an OverFLowError thats the server saying stop the thing now because you blow me up :D
     
  9. Offline

    user_43347

    CowPaths, changes grass to dirt when you walk on it.
    Only 27 lines of code :D (edit: now 26!)
    Code:
    package com.steaks4uce.CowPaths;
    import java.util.logging.Logger;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.event.Event;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CowPaths extends JavaPlugin {
        public void onDisable() {}
    
        public void onEnable() {
            Logger.getLogger("Minecraft").info("[CowPaths] CowPaths 0.1 is enabled!");
            PluginManager pm = getServer().getPluginManager();
            this.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, new playerListener(), Event.Priority.Normal, this);
        }
    
        class playerListener extends PlayerListener {
            public void onPlayerMove(PlayerMoveEvent event) {
                Block belowBlock = event.getPlayer().getLocation().subtract(0, 1, 0).getBlock();
                if (belowBlock.getType()==Material.GRASS) { belowBlock.setType(Material.DIRT); }
            }
        }
    }
     
  10. Offline

    md_5

    Code:java
    1. package com.md_5.sp;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Event;
    7. import org.bukkit.event.Event.Priority;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9. import org.bukkit.event.player.PlayerListener;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Sp extends JavaPlugin {
    14.  
    15. static final Logger logger = Bukkit.getServer().getLogger();
    16.  
    17. public void onEnable() {
    18.  
    19. getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, new PlayerListener() {
    20.  
    21. @Override
    22. public void onPlayerJoin(PlayerInteractEvent event) {
    23. if (event.getPlayer().hasPermission("guardian.superpick") && event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    24. ItemStack item = event.getItem();
    25. BlockBreakEvent e = new BlockBreakEvent(event.getClickedBlock(), event.getPlayer());
    26. if (e.getBlock() != null) {
    27. Bukkit.getServer().getPluginManager().callEvent(e);
    28. }
    29. if (!e.isCancelled() && (item.getType().equals(Material.WOOD_PICKAXE)
    30. || item.getType().equals(Material.STONE_PICKAXE) || item.getType().equals(Material.IRON_PICKAXE)
    31. || item.getType().equals(Material.GOLD_PICKAXE) || item.getType().equals(Material.DIAMOND_PICKAXE))) {
    32. if (e.getBlock() != null) {
    33. e.getBlock().setType(Material.AIR);
    34. }
    35. }
    36. }
    37.  
    38. public void onDisable() {
    39. logger.info(String.format("SuperPick v%1$s by md_5 disabled", this.getDescription().getVersion()));
    40. }
    41. }


    While working on Guardian I decided to do this, a loggable SuperPick compatible with stuff like startgate because it calls the event.
    Completely obsolete @DiddiZ and his version
     
  11. Offline

    DiddiZ

    I want to throw in my Uptime plugin:
    http://forums.bukkit.org/threads/1703

    It's unoptimized regarding lines count.

    Code:java
    1. package de.diddiz.uptime;
    2.  
    3. import static org.bukkit.Bukkit.getLogger;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Uptime extends JavaPlugin
    10. {
    11. private final long serverStart = System.currentTimeMillis();
    12.  
    13. @Override
    14. public void onEnable() {
    15. getLogger().info("Uptime v" + getDescription().getVersion() + " by DiddiZ enabled");
    16. }
    17.  
    18. @Override
    19. public void onDisable() {
    20. getLogger().info("Uptime disabled");
    21. }
    22.  
    23. @Override
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    25. final String commandName = cmd.getName().toLowerCase();
    26. final long diff = System.currentTimeMillis() - serverStart;
    27. final String msg = "Uptime: " + (int)(diff / 86400000) + "d " + (int)(diff / 3600000 % 24) + "h " + (int)(diff / 60000 % 60) + "m " + (int)(diff / 1000 % 60) + "s";
    28. if (commandName.equals("sayuptime"))
    29. if (sender.isOp()) {
    30. getLogger().info("[CONSOLE] " + msg);
    31. getServer().broadcastMessage(ChatColor.LIGHT_PURPLE + "[Server] " + msg);
    32. } else
    33. sender.sendMessage(ChatColor.RED + "You aren't allowed to do this");
    34. else
    35. sender.sendMessage(msg);
    36. return true;
    37. }
    38. }
     
    ArcheCane likes this.
  12. My first plugin for minecraft 1.9. It's called RideThaDragon and I hope the name says all:
    Code:java
    1. package de.V10lator.RideThaDragon;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.CreatureType;
    8. import org.bukkit.entity.LivingEntity;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class RideThaDragon extends JavaPlugin
    13. {
    14. private final HashMap<String, LivingEntity> dragons = new HashMap<String, LivingEntity>();
    15. public void onEnable()
    16. {
    17. getServer().getLogger().info("[RideThaDragon] enabled!");
    18. }
    19. public void onDisable()
    20. {
    21. getServer().getLogger().info("[RideThaDragon] enabled!");
    22. }
    23. public boolean onCommand(CommandSender sender, Command command,
    24. String label, String[] args)
    25. {
    26. if(!(sender instanceof Player) || !sender.hasPermission("dragon.ride"))
    27. return true;
    28. Player player = (Player)sender;
    29. String pn = player.getName();
    30. if(dragons.containsKey(pn))
    31. {
    32. LivingEntity dragon = dragons.get(pn);
    33. dragon.eject();
    34. dragon.remove();
    35. dragons.remove(pn);
    36. }
    37. else
    38. {
    39. LivingEntity dragon = player.getWorld().spawnCreature(player.getLocation(), CreatureType.ENDER_DRAGON);
    40. dragons.put(player.getName(), dragon);
    41. dragon.setPassenger(player);
    42. }
    43. return true;
    44. }
    45. }
    46.  

     
  13. Offline

    zhuowei

    Code:java
    1. package net.zhuoweizhang.checkperm;
    2. import org.bukkit.command.*;
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. public class CheckPermPlugin extends JavaPlugin {
    5. public void onDisable() {
    6. }
    7. public void onEnable() {
    8. }
    9. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    10. if (args.length != 2 || getServer().getPlayer(args[0]) == null)
    11. return false;
    12. boolean hasPerm = getServer().getPlayer(args[0]).hasPermission(args[1]);
    13. sender.sendMessage("Player " + args[0] + " " + (hasPerm? "has" : "does not have") +
    14. " permission " + args[1]);
    15. return true;
    16. }
    17. }

    Checks if a (currently online) player has a permission node.
    /checkperm Notch piggrinder.use.pig
    Edit: because someone wanted it, plugin.yml:
    Show Spoiler
    Code:
    author: zhuowei
    main: net.zhuoweizhang.checkperm.CheckPermPlugin
    name: CheckPerm
    version: '1.0'
    commands:
        checkperm:
            description: Check if a player has a permission node
            usage: /<command> <player> <node>
    
     
    chasechocolate and r3Fuze like this.
  14. Offline

    thehutch

    that wouldnt work that plugn :( you havent added the executor to the onEnable and also there is no command to use this command aka no if(cmd.getName().equalsIgnoreCase("something"))
     
  15. As onCommand is in the main class: Not needed
    As this only has one command: Not needed.

    Next time try it before complaining. :p
     
    chasechocolate, zhuowei and DiddiZ like this.
  16. Offline

    thehutch

    what you sure :O hmm well no idea how that would work tbh calling a command which you havent assigned
     
  17. Offline

    DiddiZ

    @thehutch
    Obviously someone who don't know bukkit from the beginning :D

    You can define commands in the plugin.yml, these are auto bound then.
     
  18. Offline

    thehutch

    Its that a bad comment about me?
    ah ok never knew this thanks :D
     
  19. Offline

    Perdog

    Well I just looked all through this thread and was surprised not too find this, there have been a few godmode plugins, but not this. I intoduce you too

    Eat!: Fill your belly with nothing-ness

    Code:java
    1. package me.Perdog.Eat;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Eat extends JavaPlugin {
    12. Logger log = Logger.getLogger("Minecraft");
    13. public String name;
    14. public ArrayList<String> author;
    15. public void onEnable() {
    16. name = this.getDescription().getFullName();
    17. author = this.getDescription().getAuthors();
    18. log.info(name + " by: " + author + " has been enabled");
    19. }
    20. public void onDisable() {
    21. log.info(name + " has been disabled");
    22. }
    23. public boolean onCommand (CommandSender sender, Command cmd, String label, String[] split) {
    24. Player player = null;
    25. if (sender instanceof Player) {
    26. player = (Player) sender;
    27. }
    28. if (player.hasPermission("Eat.Nothing")) {
    29. if (cmd.getName().equalsIgnoreCase("eat")) {
    30. player.setFoodLevel(20);
    31. return true;
    32. }
    33. }
    34. return false;
    35. }
    36. }


    36 lines of food-less filler :)
     
  20. Offline

    md_5

    The purpose of this thread is to show off java in general as well as plugins.
    None of these have a plugin.yml and therefore none will work. All the plugins leave onCommand without registration as that is not the point.
     
  21. Offline

    Perdog

    I don't know if this was directed at me or not ... if not then disregard the following :p

    But I thought the point of this was just to have fun and create something useful and practical, under 50 lines of code.. that's the challenge isn't it? Otherwise everyone would be doing the simple and basically useless
    Code:java
    1. import org.bukkit.*
    :p and we wouldn't get anything original lol
     
  22. Offline

    md_5

    @Perdog not at you at all
     
  23. Offline

    Perdog

    Then forgive me good sir, I apologize :) lol
     
  24. Offline

    Zaros

    GENIUS. Some one get this man a medal.
     
  25. Offline

    Fishrock123

    Wouldn't that increase the filesize though?

    @md_5 Your supposed to incorporate the code yourself, but you can give download links, such mine. (NoEnderGrief, p. 3)
     
  26. Offline

    codename_B

    One in 50 lines for my new pull request.
    https://github.com/Bukkit/CraftBukkit/pull/527
    IF IT GETS PULLED I'LL BE MAKING THIS INTO AN ACTUAL PLUGIN
    Code:
    package de.bananaco.bsfucator;
    import java.io.*;
    import java.util.*;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.*;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.*;
    import org.bukkit.event.world.*;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Obsfucate extends JavaPlugin {
        public void log(String input) {
            System.out.println("[bFscuator] " + input);
        }
        public void onDisable() {
            log("Disabled");
        }
        public void onEnable() {
            getServer().getPluginManager().registerEvent(Event.Type.CHUNK_LOAD,new Worldscfucate(readConfig()), Priority.Normal, this);
            log("Enabled");
        }
        public Map<Integer, Integer> readConfig() {
            Map<Integer, Integer> map = new HashMap<Integer, Integer>();
            YamlConfiguration config = new YamlConfiguration();
            File file = new File("plugins/bFscucator/settings.yml");
            if (!file.exists()) {
                log("Creating settings.yml");
                file.getParentFile().mkdirs();
                file.createNewFile();
                int[] ids = { 14, 15, 16, 21, 56, 73, 74 };
                List<String> props = new ArrayList<String>();
                for (int id : ids) props.add(id + ":" + 1);
                config.set("to-from", props);
                config.save(file);
            } else
                config.load(file);
            List<String> val = config.getList("to-from");
            if (val != null && val.size() > 0)
                for (String entry : val)map.put(Integer.parseInt(entry.split(":")[0]),Integer.parseInt(entry.split(":")[1]));
            return map;
        }
    }
    class Worldscfucate extends WorldListener {
        private final Map<Integer, Integer> map;
        Worldscfucate(Map<Integer, Integer> map) {
            this.map = map;
        }
        public void onChunkLoad(ChunkLoadEvent event) {
            for (int key : map.keySet()) event.getChunk().getChunkFilter().setFilter(key, map.get(key));
        }
    }
    
     
  27. Offline

    Zaros

    Not by much...
    Code:java
    1. if (player.isGenius == TRUE) {
    2. log.severe("THIS PLAYER IS A GENIUS");
    3. }
     
    com. BOY likes this.
  28. Offline

    Perdog

    Do I hint a bit of sarcasm? :p
     
  29. Offline

    ZachBora

    I don't understand what this is for.
     
  30. Offline

    EdenCampo

    IPFinder.

    I just mixed my code..Deleted unused methods and got 49 lines :D
    Simple plugin to find player's IP.
    Also PermissionsEx Support :p

    Code:
    package com.eden.IPFinder;
    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.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import ru.tehkode.permissions.PermissionManager;
    import ru.tehkode.permissions.bukkit.PermissionsEx;
    public class IPFinder extends JavaPlugin {
    private Logger log = Logger.getLogger("Minecraft");
        @Override
        public void onDisable() {
            System.out.println("[IPFinder] Disabled.");
        }
        @Override
        public void onEnable() {
            System.out.println("[IPFinder] Enabled");
        }
     public boolean onCommand(CommandSender sender,Command cmd,String commandLabel, String[] args){
         if(commandLabel.equalsIgnoreCase("FindIP") || commandLabel.equalsIgnoreCase("IP")){
             Player player = this.getServer().getPlayer(args[0]);
             Player send = (Player) sender;
             if(send.hasPermission("IPFinder.use")){
          sender.sendMessage(ChatColor.YELLOW + player.getName() + "'s IP Address is : " +player.getAddress());
             return true;
             }else{
                 sender.sendMessage(ChatColor.RED + "You dont have permissions to use IPFinder!");
                 return true;
             }
    }
         if(commandLabel.equalsIgnoreCase("FindIP")){
             Player player = this.getServer().getPlayer(args[0]);
             Player send = (Player) sender;
             if(Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")){
                    PermissionManager permissions = PermissionsEx.getPermissionManager();
                    if(permissions.has(send, "IPFinder.use")){
                        sender.sendMessage(ChatColor.YELLOW + player.getName() + "'s IP Address is : " + player.getAddress());
                        return true;
                    }else{
                         sender.sendMessage(ChatColor.RED + "You dont have permissions to use IPFinder!");
                         return true;
         }
    }
    } return false;
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page