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

    Tj3

    I know, and I also know being a Bukkit admin doesn't mean your a code expert, I was just trying to feel special. D:
    Hehe, thanks for ruining my feeling of being special. :p
     
  2. Offline

    Evangon

    Taco
    Code:
    public class NothingPlugin extends org.bukkit.plugin.java.JavaPlugin { public void onDisable() {} public void onEnable() {} }
    umad taco
     
  3. Offline

    Fishrock123

    Interesting... So really, What is considered "cheating" in this challenge?

    (Other than no line breaks and import *; Those are somewhat obvious, I think? Idk.)
     
  4. Evangon you're not really saving lines with some parts of the code, for example:
    Code:
    if(command.getName().equalsIgnoreCase("forcechat")){
                    if(sender.hasPermission("forcechat.use.normal")){
    You could've just used one if with those two :p
    And there's duplicated code at the say/execute part... so instead of:
    Code:
    if(!(args0[0].contains("/"))){
                                log.info(sender.getName() + " has forced " + args0[0] + " to say " + hax0r + ".");
                                server.getPlayer(args0[0]).chat(hax0r);
                                return true;
                            } else if(sender.hasPermission("forcechat.use.forcecommand")){
                                log.info(sender.getName() + " has forced " + args0[0] + " to execute " + hax0r + ".");
                                server.getPlayer(args0[0]).chat(hax0r);
                            }
    you could've just:
    Code:
    if(!(args0[0].contains("/") && !sender.hasPermission("forcechat.use.forcecommand")))
    {
        log.info(sender.getName() + " has forced " + args0[0] + " to " + (args0[0].contains("/") ? "execute" : "say") + " " + hax0r + ".");
        server.getPlayer(args0[0]).chat(hax0r);
        return true;
    }
    I'm not sure about the conditional tough but you get the point :p

    Also, what's that
    Code:
    [I][/I][/i]
    on line 41 ? :confused:
     
  5. Offline

    stelar7

    That would be the forum messing code up, as always
     
  6. Offline

    Fishrock123

    Also, Evangon really doesn't need "@Override".
     
  7. My Code for WaterJutsu (like in the naruto anime it let's you walk on water or with this code any liquid) 43 Lines of code
    Code:java
    1. package com.rosaage.WaterJutsu;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Location;
    5. import org.bukkit.World;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.event.Event.Priority;
    9. import org.bukkit.event.Event.Type;
    10. import org.bukkit.event.player.PlayerListener;
    11. import org.bukkit.event.player.PlayerMoveEvent;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class WaterJutsu extends JavaPlugin {
    16. public static final Logger log = Logger.getLogger("Minecraft.WaterJutsu");
    17.  
    18. public void onDisable() {
    19. PluginDescriptionFile pdfFile = this.getDescription();
    20. log.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " is disabled!");
    21. }
    22.  
    23. public void onEnable() {
    24. final FileConfiguration config = this.getConfig();
    25. config.addDefault("Block id", 1);
    26. this.getConfig().options().copyDefaults(true);
    27. saveConfig();
    28. this.getServer().getPluginManager().registerEvent(Type.PLAYER_MOVE, new PlayerListener() {
    29. @Override
    30. public void onPlayerMove(PlayerMoveEvent evt) {
    31. Location loc = evt.getPlayer().getLocation();
    32. World w = loc.getWorld();
    33. loc.setY(loc.getY() - 1);
    34. Block b = w.getBlockAt(loc);
    35. if(b.isLiquid() == true) {
    36. b.setTypeId(config.getInt("Block id"));
    37. }
    38. }
    39. }, Priority.Normal, this);
    40. PluginDescriptionFile pdfFile = this.getDescription();
    41. log.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " is Enabled!");
    42. }
    43. }

    plugin.yml:
    Code:
    name: WaterJutsu
    main: com.rosaage.WaterJutsu.WaterJutsu
    version: 1.0
     
  8. Offline

    LartTyler

    Plugin name: Un-till We Farm Again
    Purpose: Reverts tilled farmland back to dirt when the crop growing out of it is harvested.
    Code:
    package me.dbstudios.uwfa;
     
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.event.Event;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class UWFA extends JavaPlugin {
        private UWFABlockListener bListener;
     
        public void onEnable() {
            bListener = new UWFABlockListener();
         
            this.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_BREAK, bListener, Event.Priority.Normal, this);
         
            this.getServer().getLogger().info("[UWFA] Un-till We Farm Again (v" + this.getDescription().getVersion() + ") enabled.");
        }
     
        public void onDisable() {
            this.getServer().getLogger().info("[UWFA] Un-till We Farm Again disabled.");
        }
    }
     
    class UWFABlockListener extends BlockListener {
        public UWFABlockListener() {}
     
        public void onBlockBreak(BlockBreakEvent ev) {
            Block block = (new Location(ev.getBlock().getWorld(), ev.getBlock().getX(), ev.getBlock().getY() - 1, ev.getBlock().getZ())).getBlock();
         
            if (block.getTypeId() == 60) {
                block.setType(Material.DIRT);
            }
        }
    }
     
  9. Offline

    ThatBox

    Plugin Name: CommandLog
    Purpose: Logs commands. WITH DATES! :O
    Code:java
    1. package box.commandlog;
    2.  
    3. import java.text.DateFormat;
    4. import java.text.SimpleDateFormat;
    5. import java.util.Date;
    6. import java.util.logging.Logger;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.EventPriority;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class CommandLog extends JavaPlugin implements Listener
    18. {
    19. Logger log = Logger.getLogger("Minecraft");
    20.  
    21. @Override
    22. public void onDisable()
    23. {
    24. log.info("[CommandLog] {" + getDescription().getVersion() + "} has been disabled!");
    25. }
    26.  
    27. @Override
    28. public void onEnable()
    29. {
    30. getServer().getPluginManager().registerEvents(this, this);
    31. log.info("[CommandLog] {" + getDescription().getVersion() + "} has been enabled!");
    32. }
    33.  
    34. @EventHandler(priority = EventPriority.MONITOR)
    35. public void command(PlayerCommandPreprocessEvent event)
    36. {
    37. DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy / HH:mm:ss");
    38. Date date = new Date();
    39. log.info("[" + dateFormat.format(date) + "] " + event.getPlayer().getName() + ": " + event.getMessage());
    40. for(Player player : Bukkit.getOnlinePlayers())
    41. {
    42. if(player.hasPermission("commandlog.message"))
    43. {
    44. player.sendMessage(ChatColor.GOLD + "[" + dateFormat.format(date) + "] " + ChatColor.AQUA + event.getPlayer().getName() + ": " + event.getMessage());
    45. }
    46. }
    47. }
    48. }
     
    Fishrock123 likes this.
  10. Offline

    nala3

    Plugin Name: IHateGiantShrooms
    Purpose: Stops mushroom growth without permission and has a fancy command

    Code:java
    1.  
    2. package ihategiantshrooms;
    3. import java.util.logging.Level;
    4. import java.util.logging.Logger;
    5. import org.bukkit.TreeType;
    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.EventPriority;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.world.StructureGrowEvent;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15. public class IHateGiantShrooms extends JavaPlugin implements CommandExecutor, Listener{
    16. String pre = "[IHGS] ";
    17. static final Logger log = Logger.getLogger("Minecraft");
    18. @Override
    19. public void onDisable() {
    20. String ver = this.getDescription().getVersion();
    21. log.log(Level.INFO, pre + "IHateGiantShrooms version " + ver + " disabled.");
    22. }
    23. @Override
    24. public void onEnable() {
    25. this.getCommand("ihgs").setExecutor(this);
    26. String ver = this.getDescription().getVersion();
    27. getServer().getPluginManager().registerEvents(this, this);
    28. log.log(Level.INFO, pre + "IHateGiantShrooms version " + ver + " enabled.");
    29. }
    30. @Override
    31. public boolean onCommand(CommandSender cs, Command cmnd, String string, String[] strings){
    32. Player player = null;
    33. if(cs instanceof Player){ player = (Player) cs; }
    34. if(cmnd.getName().equalsIgnoreCase("ihgs")){
    35. String description = this.getDescription().getDescription();
    36. String ver = this.getDescription().getVersion();
    37. cs.sendMessage("This server is running I Hate Giant Shrooms v" + ver);
    38. cs.sendMessage("About: " + description);
    39. return true;
    40. } else { return false; }
    41. }
    42. @EventHandler(priority = EventPriority.NORMAL)
    43. public void onShroomGrow(StructureGrowEvent event){
    44. Player player = event.getPlayer();
    45. if(!player.hasPermission("ihategiantshrooms.grow") && event.isFromBonemeal() == true && event.getSpecies() == TreeType.BROWN_MUSHROOM || event.getSpecies() == TreeType.RED_MUSHROOM){
    46. event.setCancelled(true);
    47. }
    48. }
    49. }
    50.  
     
  11. Offline

    colony88

    I have one: Set the weather to sunny (includes permissions) or other weather kinds (50 lines)

    Code:java
    1. package me.cedi.setsunny;
    2.  
    3. import org.bukkit.World;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.command.ConsoleCommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class setsunny extends JavaPlugin{
    11. public void onDisable() {
    12. System.out.println("SetSunny v" + getDescription().getVersion() + " Disabled!");
    13. }
    14. public void onEnable() {
    15. System.out.println("SetSunny v" + getDescription().getVersion() + " Enabled!");
    16. }
    17. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]args){
    18.  
    19. if(sender instanceof Player){
    20. World w = ((Player) sender).getWorld();
    21. if(cmd.getName().equalsIgnoreCase("setsunny") && (sender.hasPermission("SetWeather.sunny") || sender.isOp())){
    22. w.setThundering(false);
    23. w.setStorm(false);
    24. w.setWeatherDuration(1000000);
    25. sender.sendMessage("Weather set to sunny.");
    26. return true;
    27. }
    28. if(cmd.getName().equalsIgnoreCase("setstormy") && (sender.hasPermission("SetWeather.stormy") || sender.isOp())){
    29. w.setThundering(true);
    30. w.setStorm(true);
    31. w.setWeatherDuration(1000000);
    32. sender.sendMessage("Weather set to stormy.");
    33. return true;
    34. }
    35. if(cmd.getName().equalsIgnoreCase("setrainy") && (sender.hasPermission("SetWeather.rainy") || sender.isOp())){
    36. w.setThundering(false);
    37. w.setStorm(true);
    38. w.setWeatherDuration(1000000);
    39. sender.sendMessage("Weather set to rainy.");
    40. return true;
    41. }
    42. return false;
    43. }
    44. else if(sender instanceof ConsoleCommandSender){
    45. System.out.println("Cannot run this from console!");
    46. return true;
    47. }
    48. return true;
    49. }
    50. }

    And the plugin.yml:
    Code:
    name: SetSunny
    main: me.cedi.setsunny.setsunny
    version: 0.2
    commands:
      setsunny:
        description: Set the weather to sunny.
        permission: SetWeather.sunny
        usage: /<command>
      setstormy:
        description: Set the weather to stormy.
        permission: SetWeather.stormy
        usage: /<command>
      setrainy:
        description: Set the weather to rainy.
        permission: SetWeather.rainy
        usage: /<command>
     
  12. A typo there, however, you shouldn't hardcode that, just use <command>, it's a macro that will be replaced with the command or alias used.
     
  13. Offline

    colony88

    Woops, thanks for seeing that :p
     
  14. The point was you should use <command> !
     
  15. Offline

    colony88

    I did that, didn't I?
     
  16. When I posted you didn't, you only fixed the typo, so let's just leave it at that, too much offtopic :)
     
  17. Offline

    md_5

    https://github.com/md-5/Raz3r/blob/master/src/main/java/com/md_5/raz3r/Raz3r.java
    Raz3r a Minecraft <-> Irc bot in 42 lines!
    Code:java
    1. package com.md_5.raz3r;
    2. public class Raz3r extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
    3. private final org.pircbotx.PircBotX bot = new org.pircbotx.PircBotX();
    4. @Override
    5. public void onEnable() {
    6. getConfig().options().copyDefaults(true);
    7. saveConfig();
    8. new Thread() {
    9. @Override
    10. public void run() {
    11. try {
    12. bot.setLogin("Raz3r");
    13. bot.connect(getConfig().getString("host"));
    14. bot.changeNick(getConfig().getString("nick"));
    15. bot.joinChannel(getConfig().getString("channel"));
    16. bot.getListenerManager().addListener(new org.pircbotx.hooks.ListenerAdapter<org.pircbotx.PircBotX>() {
    17. @Override
    18. public void onMessage(final org.pircbotx.hooks.events.MessageEvent<org.pircbotx.PircBotX> event) throws Exception {
    19. if (!event.getUser().getNick().equalsIgnoreCase(event.getBot().getNick())) {
    20. getServer().broadcastMessage("[IRC]<" + event.getUser().getNick() + "> " + event.getMessage());
    21. }
    22. }
    23. });
    24. } catch (Exception ex) {
    25. ex.printStackTrace();
    26. }
    27. }
    28. }.start();
    29. getServer().getPluginManager().registerEvents(this, this);
    30. }
    31. @org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR, ignoreCancelled = true)
    32. public void onPlayerChat(final org.bukkit.event.player.PlayerChatEvent event) {
    33. bot.sendMessage(getConfig().getString("channel"), org.bukkit.ChatColor.stripColor(String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage())));
    34. }
    35. }
    36.  
     
    colony88 and ThatBox like this.
  18. What exactly are that lines for except eating CPU/RAM? ;)
    No need to have a player if you don't use it and no need to check the command name if you use only one command.
     
    thehutch and ThatBox like this.
  19. Offline

    McAndze

    ZeMicroWarps - 49 lines
    Here it is! The ultimate Warps-plugin with under 50 lines of code!
    Features:
    • Saves and loads warps from config.yml!
    • Commands: /setwarp, /rmwarp, /warp with their own zemicrowarps.<command> permission!
    • Good-looking messages when using /setwarp & /rmwarp!
    Oh yeah. Marketing.
    Code:java
    1. package me.mcandze.under50;
    2. import java.util.HashMap;
    3. import java.util.Map;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.ConfigurationSection;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. public class ZeMicroWarps extends JavaPlugin{
    13. private HashMap<String, Location> warps = new HashMap<String, Location>();
    14. public void onDisable() {
    15. HashMap<String, String> warpsToString = new HashMap<String, String>();
    16. for (String s: warps.keySet()){
    17. Location get = warps.get(s);
    18. String x = String.valueOf(get.getX()), y = String.valueOf(get.getY()), z = String.valueOf(get.getZ()), yaw = String.valueOf(get.getYaw()), pitch = String.valueOf(get.getPitch()), world = get.getWorld().getName(), value = x + ":" + y + ":" + z + ":" + yaw + ":" + pitch + ":" + world + ":";
    19. warpsToString.put(s, value);
    20. }
    21. this.getConfig().createSection("warps", (Map)warpsToString);
    22. this.saveConfig();
    23. }
    24. public void onEnable() {
    25. this.getDataFolder().mkdirs();
    26. ConfigurationSection c = this.getConfig().getConfigurationSection("warps");
    27. if (c != null) for (String s: c.getKeys(false)){ String[] split = ((String)c.getValues(false).get(s)).split(":");
    28. double x = Double.valueOf(split[0]), y = Double.valueOf(split[1]), z = Double.valueOf(split[2]);
    29. float yaw = Float.valueOf(split[3]), pitch = Float.valueOf(split[4]);
    30. World world = world = this.getServer().getWorld(split[5]);
    31. warps.put(s, new Location(world, x, y, z, yaw, pitch));
    32. }
    33. }
    34. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    35. if (!(sender instanceof Player)) return true;
    36. if (args.length < 1) return true;
    37. if (!((Player)sender).hasPermission("zemicrowarps." + args[0].toLowerCase())) return true;
    38. if (cmd.getName().equalsIgnoreCase("setwarp")){
    39. warps.put(args[0], ((Player)sender).getLocation());
    40. sender.sendMessage(ChatColor.GOLD + "[MicroWarps]: " + ChatColor.WHITE + "Warp: " + ChatColor.RED + args[0] + ChatColor.WHITE + " created.");
    41. } else if (cmd.getName().equalsIgnoreCase("warp")){
    42. if ((warps.get(args[0]) != null)) ((Player)sender).teleport(warps.get(args[0]));
    43. } else if (cmd.getName().equalsIgnoreCase("rmwarp")){
    44. warps.remove(args[0]);
    45. sender.sendMessage(ChatColor.GOLD + "[MicroWarps]: " + ChatColor.WHITE + "Warp: " + ChatColor.RED + args[0] + ChatColor.WHITE + " removed.");
    46. }
    47. return true;
    48. }
    49. }


    EDIT: Doesn't quite seem to respect indents and spaces. So here is a pastie of the code: http://pastie.org/3366559

    plugin.yml!
     
    Fishrock123 likes this.
  20. Offline

    nala3

    there really isn't, I think I was planning on using the player for something but never did :p
     
  21. Offline

    Bertware

    it isn't a plugin , but it's exactly 50 lines :p
    this gets the name, version, download and compatible CB version for a plugin on bukkitdev

    PHP:
    <?php
    $plugin_name 
    $_GET['plugin']; //Get plugin name from URL
    $plugin_name strtolower($plugin_name); //to lower for valid URL
    $base "http://bukget.org/api/plugin/"// Base path for bukget API plugin search
    $url=$base $plugin_name;
    $content file_get_contents($base $plugin_name); //Get content
    echo Getname($content); //get plugin name
    echo "<br>";
    echo 
    GetVersion($content); //get plugin version
    echo "<br>";
    echo 
    GetLink($content);//get plugin DL link
    echo "<br>";
    echo 
    GetCB($content); //get compatible CB version
     
    function Getname($cont) {
    //example: "name": "locked-chest-surprise",
    $start strpos($cont,'"plugin_name": "');
    $cont mb_substr($cont,$start+16); //+16, because strpos get start of string, we need the end
    $split explode('"',$cont); //get first element of this array, to get the value
    $cont $split[0];
    return 
    $cont;
    }
    function 
    GetVersion($cont) {
    //example: "name": "UselessTNT ver.2.8",
    $versions_start strpos($cont,'"md5":'); //make sure it detects the version name, not hte plugin name. so remove first part of result
    $cont mb_substr($cont,$versions_start);
    $start strpos($cont,'"name": "');
    $cont mb_substr($cont,$start+9,$versions_start);
    $split explode('"',$cont);
    $cont $split[0];
    return 
    $cont;
    }
    function 
    GetLink($cont) {
    //example: "dl_link": "http://dev.bukkit.org/media/files/562/989/UselessTNT.jar",
    $start strpos($cont,'"dl_link": "');
    $cont mb_substr($cont,$start+12);
    $split explode('"',$cont);
    $cont $split[0];
    return 
    $cont;
    }
    function 
    GetCB($cont) {
    //example: "game_builds": [ "CB 1.0.1-R1" ], //spaces in this comment might be incorrect
    $start strpos($cont,'"CB ');
    $cont mb_substr($cont,$start+1);
    $split explode('"',$cont);
    $cont $split[0];
    return 
    $cont;
    }
     
    ?>
     
    Fishrock123 likes this.
  22. Bertware
    But you kinda wasted space with unneeded variables... $url is not used, $base and $plugin_name are not required to be stored, just use them in file_get_contents()... and you could've also shortened those echoes

    I mean something like this.
    PHP:
    $content file_get_contents("http://bukget.org/api/plugin/" strtolower($_GET['plugin'])); //Get content
    echo Getname($content); //get plugin name
    echo '<br>'.GetVersion($content); //get plugin version
    echo '<br>'.GetLink($content);//get plugin DL link
    echo '<br>'.GetCB($content); //get compatible CB version
    But anyway, it's usefull :p
     
  23. Offline

    Bertware

    I know, but i wrote it for someone else, so I added some to increase readability/easyness to change it ;)

    I just changed some lines (it's still less then 50 :p)

    from this:
    PHP:
    echo Getname($content); //get plugin name
     
    echo '<br>'.GetVersion($content); //get plugin version
     
    echo '<br>'.GetLink($content);//get plugin DL link
     
    echo '<br>'.GetCB($content); //get compatible CB version
    to this:
    PHP:
    echo '<a href="' GetLink($content) . '"><img src="http://mag.racked.eu/mcimage/i327/' GetName($content) . '/' GetVersion($content) . '/mca.png"</a>';


    this line shows an achievement image, with a hyperlink to the download.
    example: http://automation.bertware.net/plugin.php?plugin=worldguard
    you can replace worldguard with any plugin
     
  24. Offline

    Wolvereness Bukkit Team Member

    Code:java
    1. package com.wolvereness.logincommand;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. /**
    12. * @author Wolfe
    13. * Licensed under GNU GPL v3
    14. */
    15. public class LoginCommand extends JavaPlugin implements Listener {
    16. @Override
    17. public boolean onCommand(
    18. final CommandSender sender,
    19. final Command command,
    20. final String label,
    21. final String[] args) {
    22. if(!(sender.isOp() && args.length > 0 && args[0].equalsIgnoreCase("reload"))) {
    23. sender.sendMessage(getDescription().getFullName() + " by Wolvereness");
    24. } else {
    25. reloadConfig();
    26. sender.sendMessage(getDescription().getFullName() + " by Wolvereness reloaded");
    27. }
    28. return true;
    29. }
    30. public void onDisable() {}
    31. public void onEnable() {
    32. getServer().getPluginManager().registerEvents(this, this);
    33. }
    34. @EventHandler
    35. public void onPlayerJoin(final PlayerJoinEvent event) {
    36. final Player player = event.getPlayer();
    37. for(final String item : getConfig().getKeys(false)) {
    38. if(!getConfig().isConfigurationSection(item)) {
    39. continue;
    40. }
    41. final String command = String.format(getConfig().getConfigurationSection(item).getString("c"), event.getPlayer());
    42. final long delay = getConfig().getConfigurationSection(item).getLong("d");
    43. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    44. public void run() {
    45. getLogger().info(String.format("Executing %s for %s after %d delay", item, player.getName(), delay));
    46. getServer().dispatchCommand(player, command);
    47. }}, delay);
    48. }
    49. }
    50. }
    And the plugin.yml:
    Code:
    author: Wolvereness
    main: com.wolvereness.logincommand.LoginCommand
    name: LoginCommand
    version: '1.0'
    commands:
      logincommand:
        description: Used to reload
    In short, this plugin will execute a list of commands defined in the config.yml as configuration sections, with the node c for the command to be executed and d for the tick delay. We actually use this plugin to send the message of the day to users after 30 seconds.
    It's exactly 50 lines of code, but I didn't change my code style for it at all, exception of removing a few comments.
     
    codename_B likes this.
  25. Offline

    xGhOsTkiLLeRx

    AnimalOwner - Returns the name of the tamed animal (cat or wolf) if right clicked!
    *NEW* Displays the health of the clicked tamed animal!
    *NEW 2* Works now, if the player is offline!
    Download

    Lines: 41 + 4 = 45
    AnimalOwner class:
    Code:java
    1. package de.xghostkillerx.animalowner;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.OfflinePlayer;
    5. import org.bukkit.craftbukkit.entity.CraftLivingEntity;
    6. import org.bukkit.craftbukkit.entity.CraftPlayer;
    7. import org.bukkit.entity.AnimalTamer;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Tameable;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerInteractEntityEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class AnimalOwner extends JavaPlugin implements Listener {
    16.  
    17. public void onDisable() {
    18. getServer().getLogger().info("AnimalOwner has been disabled!");
    19. }
    20.  
    21. public void onEnable() {
    22. getServer().getPluginManager().registerEvents(this, this);
    23. getServer().getLogger().info("AnimalOwner is enabled!");
    24. }
    25.  
    26. @EventHandler
    27. public void onPlayerInteractEntity(PlayerInteractEntityEvent e) {
    28. if (e.getRightClicked() instanceof Tameable) {
    29. if (((Tameable) e.getRightClicked()).isTamed()) {
    30. AnimalTamer owner = ((Tameable) e.getRightClicked()).getOwner();
    31. String ownerName = "";
    32. if (owner instanceof Player) ownerName = ((CraftPlayer) owner).getName();
    33. else if (owner instanceof OfflinePlayer) ownerName = ((OfflinePlayer) owner).getName();
    34. if (!e.getPlayer().getName().equals(ownerName)) {
    35. e.getPlayer().sendMessage(ChatColor.GRAY + "The owner of this animal is " + ownerName + "!");
    36. e.getPlayer().sendMessage(ChatColor.GRAY + "Health: " + ((CraftLivingEntity) e.getRightClicked()).getHealth());
    37. }
    38. }
    39. }
    40. }
    41. }

    plugin.yml
    Code:
    name: AnimalOwner
    main: de.xghostkillerx.animalowner.AnimalOwner
    version: 1.0
    author: xGhOsTkiLLeRx
    Also, it does only display the name, if you are not the owner!
    It was necessary to do some "weird" casts, since I couldn't caste AnimalTamer to Player...
     
  26. Offline

    zhuowei

    LameKart:You're on a boat. Look up, right click with coal in your hand. The boat can now travel on land at 2x the normal speed and acceleration! Anything is possible when Bukkit includes the setWorkOnLand function.

    This was inspired by MineKart.
    Code:java
    1. package net.zhuoweizhang.lamekart;
    2. import org.bukkit.*;
    3. import org.bukkit.entity.*;
    4. import org.bukkit.event.*;
    5. import org.bukkit.event.block.*;
    6. import org.bukkit.event.player.*;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. public class LameKartPlugin extends JavaPlugin implements Listener {
    9. public void onDisable() {
    10. }
    11. public void onEnable() {
    12. getServer().getPluginManager().registerEvents(this, this);
    13. }
    14. @EventHandler(priority=EventPriority.MONITOR)
    15. public void onPlayerInteract(PlayerInteractEvent e) {
    16. if(!(e.getAction() == Action.RIGHT_CLICK_AIR && e.getItem() != null && e.getItem().getType() == Material.COAL))
    17. return;
    18. if(e.getPlayer().getVehicle() != null && e.getPlayer().getVehicle() instanceof Boat) {
    19. if (!e.getPlayer().hasPermission("lamekart.use")) return;
    20. ((Boat) e.getPlayer().getVehicle()).setWorkOnLand(true);
    21. ((Boat) e.getPlayer().getVehicle()).setMaxSpeed(2);
    22. ((Boat) e.getPlayer().getVehicle()).setOccupiedDeceleration(0.4);
    23. e.getPlayer().sendMessage("Vroom!");
    24. }
    25. }
    26. }

    plugin.yml:
    Show Spoiler
    Code:
    author: zhuowei
    description: Boats travel on land. Inspired by MineKart by Rahazan.
    main: net.zhuoweizhang.lamekart.LameKartPlugin
    name: LameKart
    version: 1.0.0
    permissions:
        lamecart.use:
            description: Allow a player to use a piece of coal to make boats work on land.
            default: true
    

    Download: https://github.com/downloads/zhuowei/zhuowei.github.com/LameKart-1.0.0.jar
     
    Fishrock123 likes this.
  27. Offline

    djmati11

    Fixed for 1.2.3 (17 lines now!)
    Code:
    package com.djmat11.BetterThanVines;
    public class BetterThanVines extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
       public void onEnable() {
       getServer().getPluginManager().registerEvents(this, this);
            System.out.println("[BetterThanVines] BetterThanVines 0.1 is enabled!");
        }
        @org.bukkit.event.EventHandler
        public void onPlayerMove (org.bukkit.event.player.PlayerMoveEvent event){
       org.bukkit.entity.Player p = event.getPlayer();
            if (p.getLocation().getBlock().getType()==org.bukkit.Material.VINE) {
           org.bukkit.util.Vector playerDirection = p.getVelocity();
           org.bukkit.util.Vector newVelocity = new org.bukkit.util.Vector(playerDirection.getX(), 0.30, playerDirection.getZ());
                p.setVelocity(newVelocity);
            }
        }
        public void onDisable() {}
    }
     
  28. djmati11
    You climb vines by default in 1.2, so there's no need.
     
    colony88 likes this.
  29. Offline

    djmati11

    @up But only on solid blocks, with this you can climb them even without solid blocks :D
     
  30. djmati11 maybe it's better that default way :p the swamp trees have vines all over the place and to get to the tree you must cut them down in order to get to the trunk if using that plugin... also, it's server side and it relies heavily on low ping, high ping users might end up stressed or even dead due to lag.
     
    McLuke500 likes this.
Thread Status:
Not open for further replies.

Share This Page