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

    Hoolean

    Just a reminder for you guys, it's the best plugins in under 50 lines, not 50 lines :p
     
    codename_B likes this.
  2. Offline

    bobacadodl

    Just do something like this :)

    Code:
    if(player.getItemInHand().getType==Material.PUMPKIN_PIE){
      if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Deadly Pie"){
        player.setHealth(0);
      }
    }
     
  3. Offline

    TGMGamingzz1

    whats the plugin.yml????
     
  4. Offline

    chasechocolate

    Assuming you know how to code Bukkit plugins, you should be able to easily figure this out.
     
  5. Offline

    turt2live


    You'd need a strip color and remove the space :p I'd personally add some data to the stack and check that
     
  6. Offline

    bobacadodl

    Its easier to store it in the name/the lore. Storing metadata wouldnt be persistent throughout restarts, but storing it in NBT would work although its more complicated than storing it in the name
     
  7. Offline

    turt2live

    Wat.

    item.setDamage(someShortValue);
     
  8. Offline

    bobacadodl

    Oh, thats what you meant :p
    Does that work for any item? Including those which dont have durability or data values?
     
  9. Offline

    turt2live

    It should.

    (I do it here to a Baked Potato)
     
    bobacadodl likes this.
  10. Offline

    Scizzr

    SpeedTest - Tells you how long (in both milliseconds and ticks) it took you between block breaks
    48 lines - Not sure if I can make it shorter, but don't really care to
    Notes:
    • Commands:
    - /speedtest : (Player only) Toggle SpeedTest monitoring
    • Permissions:
    - None

    plugin.yml
    Code:
    main: com.example.speedtest.SpeedTest
     
    name: SpeedTest
    version: 1.0.0
    author: Scizzr
     
    commands:
      speedtest:
        description: Toggle SpeedTest monitoring
    
    Code:java
    1. package com.example.speedtest;
    2.  
    3. import java.util.concurrent.ConcurrentHashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class SpeedTest extends JavaPlugin implements Listener {
    16. ConcurrentHashMap<String, Long> tests = new ConcurrentHashMap<String, Long>();
    17. public void onEnable() {
    18. Bukkit.getPluginManager().registerEvents(this, this);
    19. getCommand("speedtest").setExecutor(new CommandExecutor() {
    20. public boolean onCommand(CommandSender s, Command cmd, String lbl, String[] args) {
    21. if (!(s instanceof Player)) {
    22. s.sendMessage("Only players can use this command.".replace('&', '§'));
    23. } else {
    24. if (tests.containsKey(s.getName())) {
    25. tests.remove(s.getName());
    26. } else {
    27. tests.put(s.getName(), (long)-1);
    28. }
    29. s.sendMessage(String.format("&6[SpeedTest]%s", (tests.containsKey(s.getName()) ? " §aenabled" : " §2disabled")).replace('&', '§'));
    30. }
    31. return true;
    32. }
    33. });
    34. }
    35. @EventHandler
    36. public void onBlockBreak(BlockBreakEvent e) {
    37. if (tests.containsKey(e.getPlayer().getName())) {
    38. if (tests.get(e.getPlayer().getName()) > -1) {
    39. long now = System.currentTimeMillis(),
    40. old = tests.get(e.getPlayer().getName()),
    41. diff = now - old,
    42. ticks = Math.round((double)diff/50);
    43. e.getPlayer().sendMessage(String.format("&6[SpeedTest] &rTime elapsed: %d ms (%d ms) = %d ticks", diff, ticks*50, ticks).replace('&', '§'));
    44. }
    45. tests.put(e.getPlayer().getName(), System.currentTimeMillis());
    46. }
    47. }
    48. }
     
  11. Offline

    Cirno

    Just use System.currentTimeMillis() instead of creating a Calender object.
     
  12. Offline

    Scizzr

    Oh, haha... Completely forgot about that. Well, post revised to reflect the suggestion. Saved a whole 2 lines. :D
     
  13. Offline

    Awesomeman2

    Is this still alive? Just wondering I might think about resizing my plugin :p
     
  14. Offline

    Ultimate_n00b

    This will always be alive.
     
    drpk, Afridge1O1, maxben34 and 2 others like this.
  15. Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.plugin.java.JavaPlugin;
    3.  
    4. class FantasticPlugin extends JavaPlugin{
    5. public void onEnable(){
    6. this.getServer().getPluginManager().disablePlugin(this);}


    It's fully OOP-compliant, conforms to all known RFC standards, and runs in O(1) time no matter how many plugins you have installed! What more could you ask for? It even shuts itself down when needed to reduce memory load, which I'm quite certain that server devs would be grateful for.

    It can also be modified with ease to never shut down, ensuring that other plugins don't hog up vital memory addresses. This versatility is what makes my plugin far superior to all others in its class.

    An improved version is planned to actually save so much memory that it take up negative space in RAM. It does so by randomly algorithmically shutting down other plugins.

    On a less silly note, this does sound like an interesting challenge. I'll try to create something for this when I get the chance.
     
  16. Offline

    Awesomeman2

  17. Offline

    Ultimate_n00b

    Minecade in general actually, but this discussion is not for here.
     
  18. Offline

    MrInspector

    Spawn a skeleton horse!

    Main class

    Code:java
    1.  
    2. package plugin.tupay.skeletonhorse
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Entity;
    9. import org.bukkit.entity.EntityType;
    10. import org.bukkit.entity.Horse;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class SkeletonHorse extends JavaPlugin {
    16.  
    17.  
    18. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    19. if (!(sender instanceof Player)) {
    20. sender.sendMessage(ChatColor.RED + "Console can't use this command, silly!");
    21. return true;
    22. }
    23.  
    24. Player p = (Player) sender;
    25.  
    26. if (cmd.getName().equalsIgnoreCase("skeletonhorse")) {
    27. Entity e = p.getWorld().spawnEntity(p.getLocation(), EntityType.HORSE);
    28. Horse ho = (Horse)e;
    29. ho.setVariant(Horse.Variant.SKELETON_HORSE);
    30. ho.setTamed(true);
    31. ho.setOwner(p);
    32. return true;
    33. }
    34. return true;
    35. }
    36.  
    37.  
    38. }
    39.  
    40.  


    plugin.yml

    Code:java
    1.  
    2. name: SkeletonHorse
    3. main: plugin.tupay.skeletonhorse.SkeletonHorse
    4. version: 1.0
    5. commands:
    6. skeletonhorse:
    7. description: Spawn a skeleton horse
    8. permission: skeletonhorse.cmd
    9.  
     
  19. Offline

    xGhOsTkiLLeRx

  20. Offline

    Zarko

    SoupDrops w/ config

    Code:java
    1. package me.zarko.SD;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Material;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.PlayerDeathEvent;
    12. import org.bukkit.inventory.Inventory;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class SD extends JavaPlugin implements Listener {
    17.  
    18. FileConfiguration config;
    19. File cfile;
    20. private int Soups;
    21.  
    22. @Override
    23. public void onEnable() {
    24. config = getConfig();
    25. config.options().copyDefaults(true);
    26. saveConfig();
    27. cfile = new File(getDataFolder(), "config.yml");
    28. this.Soups = this.config.getInt("Soups");
    29. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    30. }
    31. @EventHandler
    32. public void onDeath(PlayerDeathEvent e) {
    33. Player player = e.getEntity();
    34. Inventory inv = player.getInventory();
    35. inv.clear();
    36. player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(Material.MUSHROOM_SOUP, (Soups)));
    37. }
    38. }
    39.  

    38 lines
     
  21. Offline

    sgavster

    Diamond Vote ~26 lines, needs Votifier (if not 'allowed' let me know)
    Code:java
    1. package me.sgavster.diamondvote;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.inventory.ItemStack;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. import com.vexsoftware.votifier.model.VotifierEvent;
    12.  
    13. public class Main extends JavaPlugin implements Listener
    14. {
    15. public void onEnable()
    16. {
    17. Bukkit.getPluginManager().registerEvents(this, this);
    18. }
    19.  
    20. @EventHandler
    21. public void onv(VotifierEvent e)
    22. {
    23. Player p = Bukkit.getPlayer(e.getVote().getUsername());
    24. p.getInventory().addItem(new ItemStack(Material.DIAMOND));
    25. }
    26. }
     
  22. Offline

    Zarko

    Custom Unkown Message With config:
    Code:java
    1. package me.Zarko.CustomUnknownCommand;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.EventPriority;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    13. import org.bukkit.help.HelpTopic;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Main extends JavaPlugin implements Listener {
    17.  
    18. FileConfiguration config;
    19. File cfile;
    20. private String Message;
    21.  
    22. @Override
    23. public void onEnable() {
    24. config = getConfig();
    25. config.options().copyDefaults(true);
    26. saveConfig();
    27. cfile = new File(getDataFolder(), "config.yml");
    28. this.Message = ChatColor.translateAlternateColorCodes("&".charAt(0), this.config.getString("Message"));
    29. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    30. }
    31. @EventHandler(priority = EventPriority.HIGHEST)
    32. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    33. if (!event.isCancelled()) {
    34. Player p = event.getPlayer();
    35. String command = event.getMessage().split(" ") [0];
    36. HelpTopic htopic = Bukkit.getServer().getHelpMap().getHelpTopic(command);
    37. if (htopic == null) {
    38. p.sendMessage(Message);
    39. event.setCancelled(true);
    40. }
    41. }
    42. }
    43. }
    44.  
     
  23. Offline

    sgavster

    BabyPortal, allows you to create a small portal (1x2) ~41 lines

    PHP:
    package me.sgavster.babyportal;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockPhysicsEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    Main extends JavaPlugin implements Listener {
        public 
    void onEnable() { Bukkit.getPluginManager().registerEvents(thisthis); }
        
    boolean nf false;
        @
    EventHandler
        
    public void onLight(PlayerInteractEvent e){
            if(
    e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getPlayer().getItemInHand().getType() == Material.FLINT_AND_STEEL){
                
    Block bl e.getClickedBlock();
                
    Location l bl.getLocation();
                final 
    Location a = new Location(l.getWorld(), l.getX(), l.getY() + 1l.getZ());
                final 
    Location b = new Location(l.getWorld(), l.getX(), l.getY() + 2l.getZ());
                
    Location c = new Location(l.getWorld(), l.getX(), l.getY() + 3l.getZ());
                if(
    a.getBlock().getRelative(BlockFace.EAST).getType().equals(Material.OBSIDIAN) && a.getBlock().getRelative(BlockFace.WEST).getType().equals(Material.OBSIDIAN) || a.getBlock().getRelative(BlockFace.NORTH).getType().equals(Material.OBSIDIAN) && a.getBlock().getRelative(BlockFace.SOUTH).getType().equals(Material.OBSIDIAN)){
                    if(
    b.getBlock().getRelative(BlockFace.EAST).getType().equals(Material.OBSIDIAN) && b.getBlock().getRelative(BlockFace.WEST).getType().equals(Material.OBSIDIAN) || b.getBlock().getRelative(BlockFace.NORTH).getType().equals(Material.OBSIDIAN) && b.getBlock().getRelative(BlockFace.SOUTH).getType().equals(Material.OBSIDIAN)){
                        if(
    c.getBlock().getType().equals(Material.OBSIDIAN)){
                            
    nf true;
                            
    a.getBlock().setType(Material.PORTAL);
                            
    b.getBlock().setType(Material.PORTAL);
                            
    Bukkit.getScheduler().runTaskLater(this, new Runnable() { public void run() { nf false; }}, 20L);
                        }
                    }
                }
            }
        }
        @
    EventHandler
        
    public void oncncl(BlockPhysicsEvent e) { if(nf) { e.setCancelled(true); }}
    }
    I made a bukkitdev plugin for it:

    http://dev.bukkit.org/bukkit-plugins/babyportal/ (it's my code, so I made a project, i didn't copy anyone)
     
  24. Offline

    XDSiLeNtKiLlXD

    codename_B

    Most lightweight AntiBuild ever !? Players cant build or break if you dont have the permissions AntiBuild.Break and AntiBuild.Place

    Code:
    package mainAntiBuild;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class AntiBuild extends JavaPlugin implements Listener
    {
        @Override
        public void onEnable() {getServer().getPluginManager().registerEvents(this, this);}
        @EventHandler
        public void BlockBreakEvent(BlockBreakEvent e)
        {
            if(!e.getPlayer().hasPermission("AntiBuild.Break")) e.setCancelled(true);
        }   
        @EventHandler
        public void BlockPlaceEvent(BlockPlaceEvent e)
        {
            if(!e.getPlayer().hasPermission("AntiBuild.Place")) e.setCancelled(true);
        }
    }
    Hope you guys like it :D
     
  25. Easy way to stop players logging in from another location!

    Code:java
    1. package com.droppages.Skepter;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerLoginEvent;
    11. import org.bukkit.event.player.PlayerLoginEvent.Result;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin implements Listener {
    15.  
    16. public void onEnable() {
    17. getCommand("llp").setExecutor(this);
    18. getServer().getPluginManager().registerEvents(this, this);
    19. saveDefaultConfig();
    20. }
    21.  
    22. public void onDisable() {
    23. saveConfig();
    24. }
    25.  
    26. @EventHandler
    27. public void onlogin(PlayerLoginEvent e) {
    28. for (Player p : Bukkit.getOnlinePlayers()) {
    29. if (p == e.getPlayer()) {
    30. e.disallow(Result.KICK_OTHER, ChatColor
    31. .translateAlternateColorCodes('&', getConfig()
    32. .getString("kick-reason")));
    33. p.sendMessage(ChatColor.translateAlternateColorCodes('&',
    34. getConfig().getString("notify-player")));
    35. return;
    36. }
    37. }
    38. return;
    39. }
    40.  
    41. public boolean onCommand(CommandSender s, Command c, String l, String[] a) {
    42. if (l.equalsIgnoreCase("llp") && s.hasPermission("llp.use")) {
    43. reloadConfig();
    44. return true;
    45. }
    46. return false;
    47. }
    48. }


    And not to forget the 2 extra lines which are from the config.yml:
    Code:
    kick-reason: You aren't allowed to login from another location!
    notify-player: A player tried to login with your account from another location!
     
  26. Offline

    Goblom

    Better Proxy Join comes in @ 67 Lines. This is including all the get____() methods, a message parser, and Metricts start.

    If i were to remove all the all the getter methods, the metrics start and integrate the message parser into the event the plugin would be just under 30 lines (This still including a License tag at the top and an @Author tag above the class.

    Better Proxy join also has the ability to disable the anti-direct-connect for certain people (allowing them to direct connect), supports multiple Proxy IPs and a kick message ;P

    (Seriously not trying to brag here)
    Its better then all other direct-connect stopping plugins, and its 1/4 the size.
    I might be releasing the source soon, Which is why i am posting this.
     
  27. Offline

    MrAwellstein

    One sec, going to go make my small plugin...

    7 lines of code...
    technically

    My Plugin
    BurnOut

    What it does
    Burns all players who join (Except OP)

    What uses does it have?
    This plugin can be used punish players who join after you warn them not to, or something. Or maybe in RP where you spawn burning or something. The sky is the limit!

    How do you disable it?
    You remove it. This plugin is a SUPER LIGHTWEIGHT plugin that is under 50 lines of code, so yeah, don't expect much...

    "This plugin is useless"
    You're useless!

    Code:java
    1. package apples;
    2. import org.bukkit.event.*;
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. import org.bukkit.event.player.PlayerJoinEvent;
    5. public class Main extends JavaPlugin implements Listener{
    6. @Override public void onEnable(){getServer().getPluginManager().registerEvents(this, this);}}
    7. @EventHandler public void onJoin(PlayerJoinEvent event){if(!event.getPlayer().isOp()){event.getPlayer().setFireTicks(100000);}}

    If you want to be technical
    Its ten lines of code with the plugin.yml
    HTML:
    name: BurnOut
    main: apples.Main
    version: 0.1
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  28. Offline

    chaseoes

    You're forgetting the size of the Metrics class.
     
    Goblom likes this.
  29. Offline

    chasechocolate

    /me wants more.
     
    LCastr0 likes this.
  30. Offline

    Hollasch

    Code:java
    1. package main.java.com.minevast.plugin.example;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
    7. import org.bukkit.event.server.ServerListPingEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. import java.net.InetAddress;
    11.  
    12. public class Example extends JavaPlugin implements Listener {
    13.  
    14. public void onEnable() {
    15. saveDefaultConfig();
    16. getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. public void onDisable() {
    20. saveDefaultConfig();
    21. }
    22.  
    23. @EventHandler
    24. public void ping(ServerListPingEvent event) {
    25. String search = compileInetAddress(event.getAddress());
    26. if (getConfig().contains(search)) {
    27. String pName = getConfig().getString(search+".name");
    28. int joins = getConfig().getInt(search+".joins");
    29. event.setMotd(ChatColor.translateAlternateColorCodes('&', "&c&oWelcome: &4" + pName + " &c&oto the server! You have joined the server: &4"+joins+" &c&otimes!"));
    30. }
    31. }
    32.  
    33. @EventHandler
    34. public void login(AsyncPlayerPreLoginEvent event) {
    35. String player = event.getName();
    36. String save = compileInetAddress(event.getAddress());
    37. getConfig().set(save+".name", player);
    38. getConfig().set(save+".joins", getConfig().contains(save+".joins") ? getConfig().getInt(save+".joins")+1 : 1);
    39. saveConfig();
    40. reloadConfig();
    41. }
    42.  
    43. private String compileInetAddress(InetAddress address) {
    44. return address.toString().substring(1).replace(".", "_");
    45. }
    46. }


    Displays the players name in the MOTD along with the amount of times they joined the server.
     
    LCastr0 and bigteddy98 like this.
Thread Status:
Not open for further replies.

Share This Page