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

    zhuowei

    ExplosionResistanceConfig: Allows a user to edit the Explosion resistance of a block.
    Code:java
    1. package net.zhuoweizhang.explosionresistanceconfig;
    2. import net.minecraft.server.Block;
    3. import org.bukkit.configuration.file.FileConfiguration;
    4. import java.util.*;
    5. import java.lang.reflect.*;
    6. import org.bukkit.Material;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. public class ExplosionResistanceConfigPlugin extends JavaPlugin {
    9. public void onDisable() {
    10. }
    11. public void onEnable() {
    12. Field durabilityField;
    13. try {
    14. durabilityField = Block.class.getDeclaredField("durability");
    15. durabilityField.setAccessible(true);
    16. } catch (Exception e) {
    17. e.printStackTrace();
    18. return;
    19. }
    20. FileConfiguration config = this.getConfig();
    21. config.options().copyDefaults(true);
    22. for (Map map: (List<Map>) config.get("blocks")) {
    23. Map.Entry m = (Map.Entry) map.entrySet().toArray()[0];
    24. String blockName = m.getKey().toString();
    25. String blockValue = m.getValue().toString();
    26. int blockId;
    27. Material material = Material.matchMaterial(blockName);
    28. if (material != null) {
    29. blockId = material.getId();
    30. } else {
    31. try {
    32. blockId = Integer.parseInt(blockName);
    33. } catch (NumberFormatException ex) {
    34. this.getLogger().severe("Unable to parse block type: " + blockName + ". Skipping to next entry.");
    35. continue;
    36. }
    37. }
    38. Block block = Block.byId[blockId];
    39. if (block == null) {
    40. this.getLogger().severe("Unable to find block: " + blockName + ". Skipping to next entry.");
    41. continue;
    42. }
    43. try {
    44. durabilityField.setFloat(block, Float.parseFloat(blockValue));
    45. } catch (Exception e) { e.printStackTrace();}
    46. }
    47. this.saveConfig();
    48. }
    49. }

    plugin.yml:
    Code:
    author: zhuowei
    main: net.zhuoweizhang.explosionresistanceconfig.ExplosionResistanceConfigPlugin
    name: ExplosionResistanceConfig
    version: '1.0'
    config.yml:
    Code:
    blocks:
        - SAND: 45
        - 49: 3
    To configure: each pair is of the format
    block:value
    so SAND: 45 will give sand the same resistance as stone, and 49: 3 will make obsidian break like gravel in explosions.
     
  2. Offline

    colony88

    Code:java
    1. package me.cedi.antijoinleavemsg;
    2.  
    3. public class AntiJoinLeaveMsg extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
    4. public void onDisable() {}
    5. public void onEnable() {getServer().getPluginManager().registerEvents(this, this);}
    6. @org.bukkit.event.EventHandler
    7. public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event){
    8. if(event.getPlayer().hasPermission("AJLM.fullsilence.join")){
    9. event.setJoinMessage(null);
    10. for(org.bukkit.entity.Player onlinePlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()){
    11. if(onlinePlayer.isOp()){
    12. onlinePlayer.sendMessage(org.bukkit.ChatColor.GREEN + event.getPlayer().getName() + " joined the game.");
    13. }
    14. }
    15. return;
    16. }
    17. if(event.getPlayer().hasPermission("AJLM.hide.join")){
    18. for(org.bukkit.entity.Player onlinePlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()){
    19. if(onlinePlayer.equals(event.getPlayer()) == false){
    20. event.setJoinMessage(null);
    21. onlinePlayer.sendMessage(org.bukkit.ChatColor.YELLOW + event.getPlayer().getName() + " joined the game.");
    22. }
    23. }
    24. return;
    25. }
    26. }
    27. @org.bukkit.event.EventHandler
    28. public void onPlayerLeave(org.bukkit.event.player.PlayerQuitEvent event){
    29. if(event.getPlayer().hasPermission("AJLM.fullsilence.quit")){
    30. event.setQuitMessage(null);
    31. for(org.bukkit.entity.Player onlinePlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()){
    32. if(onlinePlayer.isOp()){
    33. onlinePlayer.sendMessage(org.bukkit.ChatColor.GREEN + event.getPlayer().getName() + " left the game.");
    34. }
    35. }
    36. return;
    37. }
    38. if(event.getPlayer().hasPermission("AJLM.hide.quit")){
    39. for(org.bukkit.entity.Player onlinePlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()){
    40. if(onlinePlayer.equals(event.getPlayer()) == false){
    41. event.setQuitMessage(null);
    42. onlinePlayer.sendMessage(org.bukkit.ChatColor.YELLOW + event.getPlayer().getName() + " left the game.");
    43. }
    44. }
    45. return;
    46. }
    47. }
    48. }


    Hides the join/leave messages with permissions. Found on DevBukkit http://dev.bukkit.org/server-mods/antijoinleavemessages/
     
  3. Requested by a lazy server owner: uzalog. Prints the server log to you if you have the permissions node for it:
    Code:java
    1. package de.V10lator.uza;
    2.  
    3. import java.util.logging.Handler;
    4. import java.util.logging.LogRecord;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Log extends JavaPlugin
    12. {
    13. public void onEnable()
    14. {
    15. Logger log = getServer().getLogger();
    16. log.addHandler(new LogToChat());
    17. }
    18.  
    19. private class LogToChat extends Handler
    20. {
    21. public void publish(LogRecord record)
    22. {
    23. String msg = record.getMessage();
    24. if(msg != null)
    25. {
    26. msg = ChatColor.RED+"["+record.getLevel().getLocalizedName()+"] "+msg;
    27. for(Player p: getServer().getOnlinePlayers())
    28. if(p.hasPermission("uza.log"))
    29. p.sendMessage(msg);
    30. }
    31. }
    32.  
    33. public void flush() {}
    34.  
    35. public void close() throws SecurityException {}
    36.  
    37. }
    38. }
    39.  
     
    codename_B likes this.
  4. Offline

    Uzalu

    Lazy? no. i'm not a java programmer, and just wondered if it was possible. Never asked you to make it, but thanks anyway.

    -uzalu
     
  5. Offline

    axoila

    I've made my first plugin: SimpleHide
    It's not ready, but actaly is have under 50 lines and it hides/shows you specific players!

    Code:text
    1.  
    2. package me.Axoila.hide;
    3.  
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Hide extends JavaPlugin {
    10. @Override
    11. public void onEnable() {
    12. System.out.println("[Axoila] I hope my plugin is working for now!");
    13. }
    14. @Override
    15. public void onDisable() {
    16. System.out.println("[Axoila] my plugin is deactivated now!");
    17. }
    18.  
    19. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    20. boolean succeed = false ;
    21. if (cmd.getName().equalsIgnoreCase("hide")) {
    22. if (args.length == 1) {
    23. if (sender.hasPermission("simple.hide")) {
    24. Player target = (Player) this.getServer().getPlayer( args[0] );
    25. Player player = (Player) sender ;
    26. target.hidePlayer (player) ;
    27. [QUOTE][/QUOTE]
    28. player.sendMessage("[SimpleHide] " + target + " can't see you !");
    29. System.out.println(player + " is hidden from " + target + "!");
    30. succeed = true ;
    31. }
    32. }
    33. }
    34. if (cmd.getName().equalsIgnoreCase("show")) {
    35. if (args.length == 1) {
    36. if (sender.hasPermission("simple.hide")) {
    37. Player target = (Player) this.getServer().getPlayer( args[0] );
    38. Player player = (Player) sender ;
    39. target.showPlayer (player) ;
    40. player.sendMessage("[SimpleHide] " + target + "can see you !");
    41. succeed = true ;
    42. }
    43. }
    44. }
    45. return succeed;
    46. }
    47. }
    48.  
     
  6. Offline

    colony88

    It's succeed, not sucseed :p
     
  7. Offline

    jtjj222

    Microfied alien world gen, because I love 'em:
    Show Spoiler
    Code:java
    1.  
    2. /*
    3. * Simple alien landscape generator, slow but effective, by jtjj222.
    4. */
    5.  
    6. package com.Hills.Main;
    7.  
    8. import java.util.Arrays;
    9. import java.util.Random;
    10.  
    11. import org.bukkit.Material;
    12. import org.bukkit.World;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.util.noise.SimplexOctaveGenerator;
    15.  
    16. public class Main extends JavaPlugin{
    17.  
    18. public void onEnable() {}
    19. public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
    20. return new ChunkGenerator();
    21. }
    22.  
    23. }
    24. class ChunkGenerator extends org.bukkit.generator.ChunkGenerator {
    25.  
    26. public int xyzToByte(int x, int y, int z) {
    27. return (x * 16 + z) * 256 + y;
    28. }
    29. @Override
    30. public byte[] generate(World world, Random rand, int ChunkX, int ChunkZ) {
    31.  
    32. Random random = new Random(world.getSeed());
    33. SimplexOctaveGenerator gen = new SimplexOctaveGenerator(random, 8);
    34. byte[] chunk = new byte[16*16*256];
    35.  
    36. gen.setScale(1/256.0);
    37. double threshold = 0.0;
    38. Arrays.fill(chunk, (byte)Material.GLOWSTONE.getId());
    39. for (int x=0;x<16;x++) { for (int z=0;z<16;z++) {
    40. int real_x = x+ChunkX * 16;
    41. int real_z = z+ChunkZ*16;
    42. for (int y=1;y<256;y++) {
    43. if(gen.noise(real_x, y, real_z, 0.5, 0.5) > threshold) {
    44. chunk[xyzToByte(x,y,z)] = (byte)Material.AIR.getId();}}}}
    45. return chunk;}}

    pic:
    Show Spoiler

    [​IMG]
     
  8. Offline

    axoila

    Thanks!
    I'm not a Native English speaker, but fixed it.
     
  9. Offline

    xGhOsTkiLLeRx

    Guess this has been done before - but anyway (was a small request)

    ColoredMessages - Use colors in Chat
    Lines: 23 + 4 = 27
    Download: http://dl.dropbox.com/u/26476995/ColoredMessages.jar

    ColoredMessages.class
    Code:java
    1. package de.xghostkillerx.coloredmessages;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerChatEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class ColoredMessages extends JavaPlugin implements Listener {
    9.  
    10. public void onDisable() {
    11. getServer().getLogger().info("ColoredMessages has been disabled!");
    12. }
    13.  
    14. public void onEnable() {
    15. getServer().getPluginManager().registerEvents(this, this);
    16. getServer().getLogger().info("ColoredMessages is enabled!");
    17. }
    18.  
    19. @EventHandler
    20. public void onPlayerChat(PlayerChatEvent e) {
    21. e.setMessage(e.getMessage().replaceAll("&([0-9a-fk-or])", "\u00A7$1"));
    22. }
    23. }

    plugin.yml
    Code:
    name: ColoredMessages
    main: de.xghostkillerx.coloredmessages.ColoredMessages
    version: 1.0
    author: xGhOsTkiLLeRx
     
  10. Offline

    colony88

    I'm not a native speaker either :p
     
  11. Offline

    C0nsole

    I could actually use this, what is the permission to let them chat?
     
  12. Offline

    colony88

    "ChatBlock.Chat"
     
    garrett2smart87 likes this.
  13. Offline

    Jozeth

    ExplodoDeath, explode on death...
    Code:java
    1. package me.jozeth.ExplodoDeath;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.EventPriority;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityDeathEvent;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.PluginManager;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class ExplodoDeath extends JavaPlugin implements Listener {
    17. public static ExplodoDeath plugin;
    18. public final Logger logger = Logger.getLogger("Minecraft");
    19. @EventHandler(priority = EventPriority.HIGH)
    20. public void onDeathBack(EntityDeathEvent event) {
    21. if(event.getEntity() instanceof Player) {
    22. Player player = (Player) event.getEntity();
    23. World world = player.getWorld();
    24. Location location = player.getLocation();
    25. world.createExplosion(location, 0);
    26. }
    27. }
    28. public void onDisable() {
    29. PluginDescriptionFile pdfFile = this.getDescription();
    30. this.logger.info("[ExplodoDeath] " + pdfFile.getName() + " v" + pdfFile.getVersion() + " disabled.");
    31. }
    32. public void onEnable() {
    33. plugin = this;
    34. PluginDescriptionFile pdfFile = this.getDescription();
    35. this.logger.info("[ExplodoDeath] " + pdfFile.getName() + " v" + pdfFile.getVersion() + " enabled.");
    36. }
    37. public void registerEvents() {
    38. PluginManager pm = getServer().getPluginManager();
    39. pm.registerEvents(this, this);
    40. }
    41. }
     
  14. Offline

    Gravity Retired Staff

    Damage, all mob damage is multiplied by a configurable amount, default 2. 44 lines.
    Code:
    package net.h31ix.damage;
     
    import java.io.File;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Damage extends JavaPlugin implements Listener
    {
        @Override
        public void onDisable() {
        }
       
        @Override
        public void onEnable() {
            File file = new File(this.getDataFolder()+"/config.yml");
            if(!file.exists()) {
                this.saveDefaultConfig();
            }
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent event) {
            if(event.getEntity() instanceof Player && !(event.getDamager() instanceof Player) && event.getDamager() instanceof LivingEntity) {
                event.setDamage(this.getConfig().getInt("damage-multiplyer") *event.getDamage());
            }
            else if (event.getEntity() instanceof Player && !(((Arrow)event.getDamager()).getShooter() instanceof Player) && ((Arrow)event.getDamager()).getShooter() instanceof LivingEntity) {
                event.setDamage(this.getConfig().getInt("damage-multiplyer") *event.getDamage());
            }
        }
    }
    
    plugin.yml:
    Code:
    author: H31IX
    database: false
    main: net.h31ix.damage.Damage
    name: Damage
    startup: postworld
    url: http://H31IX.NET/
    version: '1.0'
    
    config.yml:
    Code:
    damage-multiplyer: 2
    
     
  15. Offline

    colony88

    The shorter version, only 26 lines:
    Code:java
    1. package me.jozeth.ExplodoDeath;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.World;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.PlayerDeathEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class ExplodoDeath extends JavaPlugin implements Listener{
    12. public void onDisable() {
    13. System.out.println("[ExplodoDeath] ExplodoDeath v"+getDescription().getVersion()+" is disabled.");
    14. }
    15. public void onEnable() {
    16. System.out.println("[ExplodoDeath] ExplodoDeath v"+getDescription().getVersion()+" is enabled.");
    17. getServer().getPluginManager().registerEvents(this, this);
    18. }
    19. @EventHandler
    20. public void onPlayerDeath(PlayerDeathEvent e){
    21. Player player = (Player)e.getEntity();
    22. World w = player.getWorld();
    23. Location loc = player.getLocation();
    24. w.createExplosion(loc, 0);
    25. }
    26. }
     
  16. colony88 that's possible even shorter by not creating the variables in the first place, which aren't required since you're not using them more than once but even so, calling getEntity() twice won't hinder performance at all... and you can also remove the messages and onDisable().
    Also, getEntity() is already Player in that event, so casting it is pointless.
    Code:
    public class ExplodoDeath extends JavaPlugin implements Listener
    {
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this);
        }
    
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event)
        {
            event.getEntity().getWorld().createExplosion(event.getEntity().getLocation(), 0);
        }
    }
     
    colony88 likes this.
  17. Offline

    colony88

    I know I can remove the messages and the variables, but that seems so innatural. But you are right about the casting :p
     
  18. Offline

    hawkfalcon

    My MelonSeedsFromGrass Plugin:D
    Code:java
    1. package com.hawkfalcon1.MelonSeedsFromGrass;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.EventPriority;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.BlockBreakEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class MelonSeedsFromGrass extends JavaPlugin implements Listener {
    16.  
    17. public void onEnable() {
    18. getServer().getPluginManager().registerEvents(this, this);
    19. }
    20.  
    21. public void onDisable() {
    22. }
    23.  
    24. @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    25.  
    26. public void onBlockBreak(BlockBreakEvent event)
    27. {
    28. if(event.getBlock().getType() == Material.LONG_GRASS)
    29. {
    30. Block block = event.getBlock();
    31. Player player = event.getPlayer();
    32. Random rand = new Random();
    33.  
    34. if (rand.nextInt(100) < 5) {
    35. if (player.hasPermission("MelonSeedsFromGrass.use")) {
    36. block.setType(Material.AIR);
    37.  
    38. block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.MELON_SEEDS, 1));
    39. event.setCancelled(true); // Cancel the event because you've done it yourself.
    40. }
    41. }
    42. }
    43. }
    44. }
     
  19. Offline

    Hidendra

    krinsdeath

    ChestSuite. The under 50-lines fully-complete protection suite.

    It persists all protections through restarts. Only Chests are protected, and they are automatically protected when you place them.

    https://github.com/Hidendra/ChestSuite

    Code:Java
    1. package com.griefcraft;
    2. public class ChestSuite extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
    3. private java.util.Map<Integer /* Hashcode of Location */, String> protections = new java.util.HashMap<Integer, String>();
    4. private java.io.File dbfile = new java.io.File("plugins/ChestSuite/chestsuite.db");
    5. @Override public void onEnable() {
    6. getServer().getPluginManager().registerEvents(this, this);
    7. getDataFolder().mkdir();
    8. try {
    9. if (dbfile.exists()) {
    10. java.io.ObjectInputStream is = new java.io.ObjectInputStream(new java.io.FileInputStream(dbfile));
    11. protections = (java.util.Map<Integer, String>) is.readObject();
    12. is.close();
    13. } else dbfile.createNewFile();
    14. } catch (Exception e) { e.printStackTrace(); }
    15. }
    16. @Override public void onDisable() {
    17. try {
    18. java.io.ObjectOutputStream os = new java.io.ObjectOutputStream(new java.io.FileOutputStream(dbfile));
    19. os.writeObject(protections);
    20. os.close();
    21. } catch (Exception e) { e.printStackTrace(); }
    22. }
    23. @org.bukkit.event.EventHandler public void onBlockPlace(org.bukkit.event.block.BlockPlaceEvent event) {
    24. if (!canAccess(event.getBlock().getLocation().hashCode(), event.getPlayer().getName())) {
    25. event.setCancelled(true);
    26. } else {
    27. if (event.getBlock().getType() == org.bukkit.Material.CHEST) {
    28. protections.put(event.getBlock().getLocation().hashCode(), event.getPlayer().getName());
    29. event.getPlayer().sendMessage("Protected!");
    30. }
    31. }
    32. }
    33. @org.bukkit.event.EventHandler public void onBlockInteract(org.bukkit.event.player.PlayerInteractEvent event) {
    34. if (!canAccess(event.getClickedBlock().getLocation().hashCode(), event.getPlayer().getName())) {
    35. event.setCancelled(true);
    36. event.getPlayer().sendMessage(org.bukkit.ChatColor.DARK_RED + "That chest is locked by a magical spell.");
    37. }
    38. }
    39. @org.bukkit.event.EventHandler public void onBlockDamage(org.bukkit.event.block.BlockDamageEvent event) {
    40. if (!canAccess(event.getBlock().getLocation().hashCode(), event.getPlayer().getName())) {
    41. event.setCancelled(true);
    42. event.getPlayer().sendMessage(org.bukkit.ChatColor.DARK_RED + "That chest is locked by a magical spell.");
    43. }
    44. }
    45. private boolean canAccess(int hash, String player) {
    46. String owner = protections.get(hash);
    47. return owner == null || player.equals(owner);
    48. }
    49. }
     
    Fishrock123 and codename_B like this.
  20. Offline

    Deathmarine Retired Staff

    Under 25 login and quit message disabler.

    Code:java
    1.  
    2. package com.modcrafting.loginmessagedisable;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.event.player.PlayerQuitEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9.  
    10. public class DisableMessages extends JavaPlugin implements Listener{
    11. public void onEnable(){
    12. this.getServer().getPluginManager().registerEvents(this, this);
    13. }
    14. @EventHandler
    15. public void onPlayerJoin(PlayerJoinEvent event){
    16. event.setJoinMessage(null);
    17. }
    18. @EventHandler
    19. public void onPlayerQuit(PlayerQuitEvent event){
    20. event.setQuitMessage(null);
    21. }
    22. }
    23.  
     
  21. Offline

    krinsdeath

    Haha. Command based world spawn persistence. /setspawn [player] (as console) or /setspawn (as a player) to set the world's spawn point. Permission based.

    Code:
    package net.krinsoft.setspawnlite;
     
    /**
    * @author krinsdeath
    */
    public class SpawnCore extends org.bukkit.plugin.java.JavaPlugin {
     
        @Override public void onEnable() {}
     
        @Override public void onDisable() {}
     
        public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
            if (check(sender)) {
                org.bukkit.entity.Player player;
                if (sender instanceof org.bukkit.command.ConsoleCommandSender) {
                    if (args.length == 0) {
                        error(sender, "You must specify a player from the console.");
                        return true;
                    } else {
                        player = getServer().getPlayer(args[0]);
                        if (player == null) {
                            error(sender, "The specified player must be online.");
                            return true;
                        }
                    }
                } else {
                    player = (org.bukkit.entity.Player) sender;
                }
                player.getWorld().setSpawnLocation((int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ());
                if (sender.equals(player)) {
                    message(sender, "Set spawn location for " + player.getWorld().getName() + " to your current position.");
                } else {
                    message(player, sender.getName() + " has set this world's spawn point to your location.");
                    message(sender, "Set spawn location for " + player.getWorld().getName() + " to " + player.getName() + "'s position.");
                }
                return true;
            } else {
                error(sender, "You don't have permission to use /setspawn.");
            }
            return false;
        }
     
        private void message(org.bukkit.command.CommandSender sender, String msg) { sender.sendMessage(org.bukkit.ChatColor.GREEN + "[SetSpawnLite] " + msg); }
     
        private void error(org.bukkit.command.CommandSender sender, String msg) { sender.sendMessage(org.bukkit.ChatColor.RED + "[SetSpawnLite] " + msg); }
     
        public boolean check(org.bukkit.command.CommandSender sender) { return sender instanceof org.bukkit.command.ConsoleCommandSender || sender.hasPermission("setspawnlite.set"); }
     
    }
    
     
  22. Offline

    md_5

    You cheated so much on the line limit :p
    But not bad work :)
     
  23. Offline

    md_5

    DenySpout

    Does what it says on the tin, blocks Spoutcraft.
    Code:java
    1. package com.md_5;
    2.  
    3. public class DenySpout extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
    4.  
    5. @Override
    6. public void onEnable() {
    7. try {
    8. Class<?>[] params = {int.class, boolean.class, boolean.class, Class.class};
    9. java.lang.reflect.Method addClassMapping = net.minecraft.server.Packet.class.getDeclaredMethod("a", params);
    10. addClassMapping.setAccessible(true);
    11. addClassMapping.invoke(null, 195, true, true, CustomPacket.class);
    12. } catch (Exception ex) {
    13. }
    14. getServer().getPluginManager().registerEvents(this, this);
    15. }
    16.  
    17. @org.bukkit.event.EventHandler
    18. public void onJoin(org.bukkit.event.player.PlayerJoinEvent event) {
    19. net.minecraft.server.Packet18ArmAnimation packet = new net.minecraft.server.Packet18ArmAnimation();
    20. packet.a = -42;
    21. ((org.bukkit.craftbukkit.entity.CraftPlayer) event.getPlayer()).getHandle().netServerHandler.sendPacket(packet);
    22. }
    23.  
    24. public static class CustomPacket extends net.minecraft.server.Packet {
    25.  
    26. public CustomPacket() {
    27. }
    28.  
    29. public int a() {
    30. return 8;
    31. }
    32.  
    33. public void a(java.io.DataInputStream in) throws java.io.IOException {
    34. in.readShort();
    35. in.readShort();
    36. in.skipBytes(in.readInt());
    37. }
    38.  
    39. public void a(java.io.DataOutputStream out) throws java.io.IOException {
    40. }
    41.  
    42. public void handle(net.minecraft.server.NetHandler handler) {
    43. ((net.minecraft.server.NetServerHandler) handler).disconnect("Please use the orginal Minecraft client from [url="http://www.minecraft.net"]www.minecraft.net[/url]");
    44. }
    45. }
    46. }
    47.  
     
    jamietech, jtjj222 and zhuowei like this.
  24. Offline

    evilmidget38 Retired Staff

    I call it Simple Warp. It's a simple /setwarp and /warp plugin, and it's less than 50 lines of code. I don't know how to get copy-able line numbers in eclipse, but the main is 44 lines of code, and the plugin.yml is 3 lines.
    47 lines total.

    Code:
    package me.natemortensen.simplewarp;
    import org.bukkit.*;
    import org.bukkit.command.*;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class SimpleWarp extends JavaPlugin{
    public void onEnable(){
    this.getCommand("warp").setExecutor(this);
    this.getCommand("setwarp").setExecutor(this);
    this.getLogger().info("SimpleWarp has been enabled!");
    }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("setwarp")){
           if(args.length < 1){
           sender.sendMessage(ChatColor.RED+"You must specify a name!");
           return true;
           }
           getConfig().set(args[0], locationToString(((Player)sender).getLocation()));
            }
            else if(cmd.getName().equalsIgnoreCase("warp")){
           if (args.length < 1){
           sender.sendMessage(ChatColor.RED+"You must specify a warp.");
           return true;
           }
           String s = getConfig().getString(args[0]);
           if (s == null) {
           sender.sendMessage(ChatColor.RED+"Unable to find warp.");
           return true;
           }
           ((Player)sender).teleport(parseLocation(s));
            }
            return true;
        }
        public Location parseLocation(String location){
       String[] coords = location.split(",");
       return new Location(this.getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3]));  
        }
        public String locationToString(Location location){
       return location.getWorld().getName()+","+Double.toString(location.getX())+","+Double.toString(location.getY())+","+Double.toString(location.getZ());
        }
    public void onDisable(){
    this.getLogger().info("SimpleWarp has been disabled.");
    }
    }
    Code:
    main: me.natemortensen.simplewarp.SimpleWarp
    version: 0.1
    name: Simple Warp
     
  25. Offline

    Gravity Retired Staff

    Well that won't work because you didn't register the commands in your plugin.yml.. did you test it? :eek:
     
  26. Offline

    ProFatal

    SimpleNameColor: 48 lines. Add color to peoples tags
    Code:
    package me.fatal.simplenamecolor;
     
    import net.minecraft.server.EntityPlayer;
    import net.minecraft.server.Packet20NamedEntitySpawn;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class main extends JavaPlugin{
        public void onDisable(){}
       
        public void onEnable(){}
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] arg){
            if(sender instanceof Player){
                if(commandLable.equalsIgnoreCase("name")){
                    for(ChatColor chatc  : ChatColor.values()){
                        if(replaceString(chatc).equalsIgnoreCase(arg[0])){
                            setPlayerName((Player)sender, chatc.toString());
                        }
                    }
                }
            }
            return true;
        }
       
        private String replaceString(ChatColor color){
            String chatcolorReplace = color.name().replaceAll("_","");
            return chatcolorReplace;
        }
       
        private void setPlayerName(Player player, String color){
            String oldName = player.getName();
     
            EntityPlayer changingName = ((CraftPlayer)player).getHandle();
            changingName.name = color+player.getName();
            for(Player playerinworld : Bukkit.getOnlinePlayers()){
                if(playerinworld != player){
                    ((CraftPlayer)playerinworld).getHandle().netServerHandler.sendPacket(new Packet20NamedEntitySpawn(changingName));
                }
            }
            changingName.name = oldName;
        }
    }
    all people have to do is
    Code:
    /name red
    and then their tag will become red
    Code:
    /name blue
    and its blue.
     
  27. Offline

    evilmidget38 Retired Staff

    Oh, I thought if you registered them in onEnable() they'd work. I guess I'll change that. By removing the .setExecutor part that'll give me 2 more lines to use, so I then have roughly 5 lines to register them with in the plugin.yml.

    This new version is 49 lines, and has been tested. It works.

    39 lines for the class, 10 lines in the plugin.yml

    Code:
    package me.natemortensen.simplewarp;
    import org.bukkit.*;
    import org.bukkit.command.*;
    public class SimpleWarp extends org.bukkit.plugin.java.JavaPlugin{
    public void onEnable(){
    this.getLogger().info("SimpleWarp has been enabled!");
    }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("setwarp")){
           if(args.length < 1){
           sender.sendMessage(ChatColor.RED+"You must specify a name!");
           return true;
           }
           getConfig().set(args[0], locationToString(((org.bukkit.entity.Player)sender).getLocation()));
            }
            else if(cmd.getName().equalsIgnoreCase("warp")){
           if (args.length < 1){
           sender.sendMessage(ChatColor.RED+"You must specify a warp.");
           return true;
           }
           if (getConfig().getString(args[0]) == null) {
           sender.sendMessage(ChatColor.RED+"Unable to find warp.");
           return true;
           }
           ((org.bukkit.entity.Player)sender).teleport(parseLocation(getConfig().getString(args[0])));
            }
            return true;
        }
        public Location parseLocation(String location){
       String[] coords = location.split(",");
       return new Location(this.getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3]));  
        }
        public String locationToString(Location location){
       return location.getWorld().getName()+","+Double.toString(location.getX())+","+Double.toString(location.getY())+","+Double.toString(location.getZ());
        }
    public void onDisable(){
    this.getLogger().info("SimpleWarp has been disabled.");
    }
    }
    Code:
    main: me.natemortensen.simplewarp.SimpleWarp
    version: 0.1
    name: Simple Warp
    commands:
      warp:
          description: Warp to the specified warp.
          usage: /warp <command to run>
      setwarp:
          description: Set a warp that players can warp to.
          usage: /setwarp <command to run>
     
  28. Offline

    Gravity Retired Staff

    You have to do both, lol.
    So you didn't try these before you posted them?
     
  29. Offline

    evilmidget38 Retired Staff

    The original one hadn't been tried, but I've tried it since then. Looking back, that was probably a poor decision. At 11:00 PM when I realized some code I had written to help someone was close to 50 lines, I thought I might as well post it.

    The 50 line challenge is kind of funny. It encourages some of the worst code practices you can find. My plugin has no local variables, whatsoever(assuming you don't count the arguments in the onCommand constructor). Not to mention it encourages using imports as little as possible, and doing as little safety checks as possible. Between the code I had before, and the code I put into the challenge, I cut out roughly 30 lines.
     
    h31ix likes this.
  30. Offline

    Fishrock123

Thread Status:
Not open for further replies.

Share This Page