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.

  1. Offline

    Wolvereness Bukkit Team Member

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

    This post has been edited 1 time. It was last edited by Wolvereness Feb 16, 2012.
    codename_B likes this.
  2. Offline

    xGhOsTkiLLeRx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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...

    This post has been edited 10 times. It was last edited by xGhOsTkiLLeRx May 21, 2012.
  3. Offline

    zhuowei

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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:
    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.
  4. Offline

    djmati11

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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() {}
    }

    This post has been edited 1 time. It was last edited by djmati11 Mar 19, 2012.
  5. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @djmati11
    You climb vines by default in 1.2, so there's no need.
    colony88 likes this.
  6. Offline

    djmati11

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @up But only on solid blocks, with this you can climb them even without solid blocks :D
  7. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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.

    This post has been edited 1 time. It was last edited by Digi Mar 20, 2012.
    McLuke500 likes this.
  8. Offline

    zhuowei

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  9. Offline

    colony88

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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/

    This post has been edited 1 time. It was last edited by colony88 Apr 3, 2012.
  10. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  11. Offline

    Uzalu

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    This post has been edited 1 time. It was last edited by Uzalu Apr 21, 2012.
  12. Offline

    axoila

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.  

    This post has been edited 13 times. It was last edited by axoila Jun 10, 2012.
  13. Offline

    colony88

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It's succeed, not sucseed :p
  14. Offline

    jtjj222

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Microfied alien world gen, because I love 'em:
    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:

    [IMG]

    This post has been edited 2 times. It was last edited by jtjj222 Jun 4, 2012.
  15. Offline

    axoila

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Thanks!
    I'm not a Native English speaker, but fixed it.
  16. Offline

    xGhOsTkiLLeRx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    This post has been edited 1 time. It was last edited by xGhOsTkiLLeRx Apr 26, 2012.
  17. Offline

    colony88

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I'm not a native speaker either :p
  18. Online

    C0nsole

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I could actually use this, what is the permission to let them chat?
  19. Offline

    colony88

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    "ChatBlock.Chat"

    This post has been edited 1 time. It was last edited by colony88 May 6, 2012.
    garrett2smart87 likes this.
  20. Online

    Jozeth

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. }

    This post has been edited 2 times. It was last edited by Jozeth May 9, 2012.
  21. Offline

    Gravity BukkitDev Team Lead Moderator BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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
    
  22. Offline

    colony88

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. }
  23. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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);
        }
    }

    This post has been edited 2 times. It was last edited by Digi May 28, 2012.
    colony88 likes this.
  24. Offline

    colony88

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I know I can remove the messages and the variables, but that seems so innatural. But you are right about the casting :p
  25. Online

    hawkfalcon BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. }
  26. Offline

    Hidendra

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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. }

    This post has been edited 2 times. It was last edited by Hidendra Jun 12, 2012.
    Fishrock123 and codename_B like this.
  27. Offline

    Deathmarine BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.  

    This post has been edited 1 time. It was last edited by Deathmarine Jun 16, 2012.
  28. Offline

    krinsdeath BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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"); }
     
    }
    
  29. Offline

    md_5

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You cheated so much on the line limit :p
    But not bad work :)
  30. Offline

    md_5

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

Share This Page