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

    cholo71796

    @codename_B
    My plugin is the best security plugin- in ten lines of code!
    Code:java
    1. public class UsefulPlugin extends org.bukkit.plugin.java.JavaPlugin {
    2. public void onDisable() {}
    3. public void onEnable() {
    4. getServer().getPluginManager().registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, new org.bukkit.event.player.PlayerListener() {
    5. public void onPlayerLogin(org.bukkit.event.player.PlayerLoginEvent event) {
    6. event.disallow(org.bukkit.event.player.PlayerLoginEvent.Result.KICK_OTHER, "Griefer detection algorithm returned a POSITIVE on your account.");
    7. }
    8. }, org.bukkit.event.Event.Priority.Low, this);
    9. }
    10. }
     
    chasechocolate and r3Fuze like this.
  2. Offline

    cyberdude

    Let me top that:
    Code:java
    1. public class NothingPlugin extends org.bukkit.plugin.java.JavaPlugin { public void onDisable() {} public void onEnable() {} }

    1 line ;)
     
  3. Offline

    Taco

    Well played.
     
    chasechocolate likes this.
  4. Offline

    codename_B

    Erm. Still we have actual working plugins that people actually use under 50 lines :p try again.
     
  5. Offline

    AbeJ

    I changed it a bit. The message is more truthful now.
    Code:java
    1.  
    2. public class UsefulPlugin extends org.bukkit.plugin.java.JavaPlugin {
    3. public void onDisable() {}
    4. public void onEnable() {
    5. getServer().getPluginManager().registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, new org.bukkit.event.player.PlayerListener() {
    6. public void onPlayerLogin(org.bukkit.event.player.PlayerLoginEvent event) {
    7. event.disallow(org.bukkit.event.player.PlayerLoginEvent.Result.KICK_OTHER, "I'm trying to sleep here!");
    8. }
    9. }, org.bukkit.event.Event.Priority.Low, this);
    10. }
    11. }
     
  6. Offline

    zhuowei

    Let's make it more secure.
    Code:java
    1.  
    2. public class UsefulPlugin extends org.bukkit.plugin.java.JavaPlugin {
    3. public void onDisable() {}
    4. public void onEnable() {
    5. getServer().getPluginManager().registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, new org.bukkit.event.player.PlayerListener() {
    6. public void onPlayerLogin(org.bukkit.event.player.PlayerLoginEvent event) { //Shut down the server
    7. System.exit(0); //For the more paranoid, substitute Runtime.getRuntime().halt(0) instead.
    8. }
    9. }, org.bukkit.event.Event.Priority.Low, this);
    10. }
    11. }


    Code:java
    1.  
    2. package net.zhuoweizhang.loginruncommands;
    3.  
    4. import java.util.*;
    5. import org.bukkit.*;
    6. import org.bukkit.command.*;
    7. import org.bukkit.event.*;
    8. import org.bukkit.event.player.*;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.util.config.Configuration;
    12.  
    13. public class LoginRunCommandsPlugin extends JavaPlugin {
    14.  
    15. ConsoleCommandSender sender; List<String> commands; Server server;
    16. final LoginRunCommandsPlayerListener playerListener = new LoginRunCommandsPlayerListener();
    17.  
    18. public void onEnable() {
    19. Configuration config = getConfiguration();
    20. commands = config.getStringList("commands", null);
    21. config.save();
    22. server = getServer();
    23. server.getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this);
    24. sender = new ConsoleCommandSender(getServer());
    25. }
    26.  
    27. public void onDisable() {
    28. }
    29.  
    30. private class LoginRunCommandsPlayerListener extends PlayerListener {
    31. public void onPlayerJoin(PlayerJoinEvent event) {
    32. for (String c : commands) {
    33. String cmd = c.replaceAll("PLAYERNAME", event.getPlayer().getName());
    34. server.dispatchCommand(sender, cmd);
    35. }
    36. }
    37. }
    38. }
    39.  

    Automatically runs a series of commands when a user logs in to the server. I haven't tested this, so I hope it works.
    Configuration example:
    Code:
    commands: ['op PLAYERNAME', 'give PLAYERNAME 46 64']
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
    cholo71796 likes this.
  7. Offline

    Orcem12

    @codename_B I got a basic "create a skylands plugin" (46 lines)
    I call it "ehSkylands" just cause I was lazy. But you can call it under50skylands if you like.

    Code:
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Chunk;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ehSkylands extends JavaPlugin{
        Logger log;
        @Override
        public void onDisable() {
            log.info("[ehSkylands]"+" version "+getDescription().getVersion()+ "disabled.");
        }
        @Override
        public void onEnable() {
            log = Logger.getLogger("Minecraft");
            getServer().createWorld("world_skylands",World.Environment.SKYLANDS);
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd,
                String commandLabel, String[] args) {
            if(sender instanceof Player) {
                Player p = (Player) sender;
            if(commandLabel.equalsIgnoreCase("Skylands")
                || commandLabel.equalsIgnoreCase("eh"))
            {
                Player player = (Player)sender;
                player.sendMessage(ChatColor.BLUE + "[ehSkylands] " + ChatColor.GOLD + "Welcome to the " + ChatColor.YELLOW + "Skylands.");
                    World w  = getServer().getWorld("world_skylands");
                    Location sloc = w.getSpawnLocation();
                    Chunk c = w.getChunkAt(sloc);
                    w.loadChunk(c);
                    p.teleport(sloc);
                    return true;
                        }
                }
            return false;
        }
    }
    Planning on making it smaller so the player can actually go back xD
     
  8. Offline

    zhuowei

    PortalEffect: Spawns a client-side portal block under a person's feet that follows them. This may be useful to simulate the effects of drugs on players, for example.
    Code:java
    1. package net.zhuoweizhang.portaleffect;
    2.  
    3. import java.util.*;
    4. import org.bukkit.*;
    5. import org.bukkit.block.*;
    6. import org.bukkit.command.*;
    7. import org.bukkit.event.*;
    8. import org.bukkit.event.player.*;
    9. import org.bukkit.entity.*;
    10. import org.bukkit.plugin.PluginManager;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class PortalEffectPlugin extends JavaPlugin {
    14.  
    15. final PortalEffectPlayerListener playerListener = new PortalEffectPlayerListener();
    16. final List<Player> players = new ArrayList<Player>();
    17.  
    18. public void onEnable() {
    19. this.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Monitor, this);
    20. }
    21.  
    22. public void onDisable() { }
    23.  
    24. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    25. if (label.equalsIgnoreCase("portaleffect") && args.length == 2 && getServer().getPlayer(args[0]) != null) {
    26. setPortalEffect(getServer().getPlayer(args[0]), Boolean.parseBoolean(args[1].toLowerCase()));
    27. return true;
    28. }
    29. return false;
    30. }
    31.  
    32. public void setPortalEffect(Player player, boolean enable) {
    33. if (enable) { if (!players.contains(player)) { players.add(player); } }
    34. else { if (players.contains(player)) { players.remove(player); } }
    35. }
    36.  
    37. private class PortalEffectPlayerListener extends PlayerListener {
    38. public void onPlayerMove(PlayerMoveEvent event) {
    39. Player player = event.getPlayer(); Location f = event.getFrom(), t = event.getTo();
    40. if (!players.contains(player)) return;
    41. if (f.getBlockX() == t.getBlockX() && f.getBlockY() == t.getBlockY() && f.getBlockZ() == t.getBlockZ()) return;
    42. Block b = player.getWorld().getBlockAt(f);
    43. player.sendBlockChange(f, b.getType(), b.getData());
    44. player.sendBlockChange(t, Material.PORTAL, (byte) 0);
    45. }
    46. }
    47. }


    As a bonus, when a player stands in a portal block, the Escape key is disabled, so the player can't disconnect from the server. :)
    Edit: added command to control which players get the effect. Original version without commands:
    Show Spoiler
    Code:java
    1. package net.zhuoweizhang.portaleffect;
    2.  
    3. import org.bukkit.*;
    4. import org.bukkit.block.*;
    5. import org.bukkit.event.*;
    6. import org.bukkit.event.player.*;
    7. import org.bukkit.entity.*;
    8. import org.bukkit.plugin.PluginManager;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class PortalEffectPlugin extends JavaPlugin {
    12.  
    13. final PortalEffectPlayerListener playerListener = new PortalEffectPlayerListener();
    14.  
    15. @Override
    16. public void onEnable() {
    17. this.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Monitor, this);
    18. }
    19.  
    20. public void onDisable() {
    21. }
    22.  
    23. private class PortalEffectPlayerListener extends PlayerListener {
    24. public void onPlayerMove(PlayerMoveEvent event) {
    25. Player player = event.getPlayer(); Location f = event.getFrom();
    26. Block b = player.getWorld().getBlockAt(f);
    27. player.sendBlockChange(f, b.getType(), b.getData());
    28. player.sendBlockChange(event.getTo(), Material.PORTAL, (byte) 0);
    29. }
    30. }
    31. }
     
    chasechocolate, vanZeben and c_dric like this.
  9. Offline

    V10lator

    Why? V10Dice has 49 lines... -.-
     
  10. Offline

    codename_B

    Unless you have the permission of the original author (or are the original author)
     
  11. Offline

    V10lator

    :) Then I will put the sources on here when I'm at a computer which doesn't cut out empty lines in here (don't know why this netbook does this). It would be less then 49 lines with all empty lines cutted out but... It wouldn't be fair... :D
     
  12. Offline

    MrPuzzles

    Code:
    package net.turbogoat.creepercake;
    
    import java.util.logging.Logger;
    import org.bukkit.entity.Creeper;
    import org.bukkit.event.Event;
    import org.bukkit.event.entity.EntityListener;
    import org.bukkit.event.entity.ExplosionPrimeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CreeperCake extends JavaPlugin
    {
      Logger log = Logger.getLogger("Minecraft");
      public void onDisable()
      {
        log.info("CreeperCake has been disabled");
      }
    
      public void onEnable()
      {
        log.info("CreeperCake has been enabled");
        getServer().getPluginManager().registerEvent(Event.Type.EXPLOSION_PRIME, new entityListener(), Event.Priority.High, this);
      }
    }
    class entityListener extends EntityListener {
        public void onExplosionPrime(ExplosionPrimeEvent event) {
            if (event.getEntity() instanceof Creeper) {
                event.setCancelled(true);
                event.getEntity().getWorld().getBlockAt(event.getEntity().getLocation()).setTypeId(92);
            }
        }
    }
    
    Creepers Make Cake, Not War in 19 (I think) lines :D

    with thanks to @boardinggamer for the idea
     
  13. Offline

    Shamebot

    @zhuowei I'd use a HashSet rather than a ArrayList.
     
  14. Offline

    xpansive

    I dare someone to make a 1k map based demo

    Or I'll do it myself
     
  15. Offline

    V10lator

    Here it is: V10Dice 0.2 - a simple random number generator with permissionsBukkit support:
    Code:
    package com.V10lator.V10Dice;
    
    import java.util.Random;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class V10Dice extends JavaPlugin implements CommandExecutor
    {
      private Random rand = new Random();
      public void onEnable()
      {
        PluginDescriptionFile pdfFile = getDescription();
    	getCommand("roll").setExecutor(this);
    	getServer().getLogger().info("["+pdfFile.getName()+"] v" + pdfFile.getVersion() + " enabled.");
      }
      public void onDisable()
      {
    	getServer().getLogger().info("["+getDescription().getName()+"] disabled.");
      }
      public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args)
      {
    	if((sender instanceof Player) && ((Player)sender).hasPermission("v10dice.dice"))
    	{
    	  int max = 10;
    	  if(args.length > 0)
    		try
    	    {
    		  max = Integer.parseInt(args[0]);
    	    }
    	    catch(NumberFormatException e)
    	    {}
    	  int random = rand.nextInt(max);
    	  sender.sendMessage("Dice: " + random);
    	  for(Entity entity: ((Player)sender).getNearbyEntities(20D, 20D, 20D))
    	  {
    	    if(entity instanceof Player)
    	   	  ((Player)entity).sendMessage("Dice: " + random);
    	  }
    	}
    	return true;
      }
    }
     
  16. Offline

    1337

    Code:
    package me.jack.TMIFix;
    import org.bukkit.plugin.java.*;
    import org.bukkit.event.player.*;
    import org.bukkit.event.Event.*;
    public class TMIfix extends JavaPlugin{
        @Override
        public void onDisable() {
            System.out.println("TMIFix disabled!");
        }
        @Override
        public void onEnable() {
            this.getServer().getPluginManager().registerEvent(Type.PLAYER_MOVE, new Listener(), Priority.Highest, this);
            System.out.println("TMIFix enabled!");
        }
    }
    class Listener extends PlayerListener{
        public void onPlayerMove(PlayerMoveEvent event){
            event.getPlayer().updateInventory();
        }
    }
    fix for using tomanyitems and having invisible items in your inventory,when you move,your inventory is updated,simple :D
    20 lines
     
  17. Offline

    rymate1234

    Well my latest plugin (http://forums.bukkit.org/threads/ad...me-change-your-name-skin-and-more-1060.34773/) is so small I decided to make it under 50 lines!
    Code:java
    1. package net.rymate.ChangeName;
    2. import java.util.logging.Logger;
    3. import net.minecraft.server.EntityPlayer;
    4. import net.minecraft.server.EntityTracker;
    5. import net.minecraft.server.WorldServer;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.craftbukkit.entity.CraftPlayer;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. public class ChangePlayerName extends JavaPlugin {
    13. Logger log = Logger.getLogger("Minecraft");
    14. public void onDisable() {
    15. log.info(this.getDescription().getName() + "disabled!");
    16. }
    17. public void onEnable() {
    18. log.info(this.getDescription().getName() + "enabled!");
    19. }
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    21. if (!(sender instanceof CraftPlayer)) {
    22. sender.sendMessage("You are not an in-game player!");
    23. return false;
    24. }
    25. if (sender.hasPermission("changename.change")) {
    26. EntityPlayer player = (EntityPlayer) ((CraftPlayer) sender).getHandle();
    27. Player senderplayer = (Player) sender;
    28. if (args.length > 0) {
    29. sender.sendMessage("You are now discuised as " + args[0] + "!");
    30. senderplayer.setDisplayName(args[0]);
    31. setPlayerName(player, args[0]);
    32. } else {
    33. sender.sendMessage("Wrong usage! /changename <name>");
    34. }
    35. return true;
    36. } else {
    37. sender.sendMessage("Nope, can't do that!");
    38. return false;
    39. }
    40. }
    41. //thanks to Lahwran for this code :D
    42. public void setPlayerName(EntityPlayer player, String newname) {
    43. WorldServer world = (WorldServer) player.world;
    44. EntityTracker tracker = world.tracker;
    45. tracker.untrackEntity(player);
    46. player.name = newname;
    47. tracker.track(player);
    48. }
    49. }


    Yes, thats 49 lines B)

    AND it has permissions!
     
    codename_B likes this.
  18. Offline

    codename_B

    WOW! :D Mind if I recycle that? ;) I've got a few ideas now inspired by that!
     
    chasechocolate likes this.
  19. Offline

    V10lator

    That remindet me at Name2Name which syncs a players display name to the name and has 41 lines:
    Code:
    package com.V10lator.Name2Name;
    import net.minecraft.server.EntityPlayer;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Name2Name extends JavaPlugin
    {
      private boolean active = false;
      private Name2Name plugin = this;
      public void onEnable()
      {
    	active = true;
    	getServer().getScheduler().scheduleSyncDelayedTask(plugin, new N2NThread(), 4L);
      }
      public void onDisable()
      {
    	active = false;
      }
      public class N2NThread implements Runnable
      {
    	public void run()
    	{
    	  Player[] players = getServer().getOnlinePlayers();
    	  for(Player player: players)
    	  {
    	    EntityPlayer entity = ((CraftPlayer)player).getHandle();
    	    if(!entity.displayName.equals(entity.name) && !entity.displayName.equals(""))
    	    {
    	      entity.name = entity.displayName;
    	      player.teleport(player);
    	    }
    	  }
    	  if(active)
    		getServer().getScheduler().scheduleSyncDelayedTask(plugin, new N2NThread(), 32L);
    	}
      }
    }
    Can I merge codes from yours and this plugin for a new plugin I'm working on? It's name is StealIdent and well... I hope the name says all... ;)
     
  20. Offline

    rymate1234

    Well, if you look on my BukkitDev for it http://dev.bukkit.org/server-mods/changeplayername/ you'll find the license is public domain, so do what you like with it :D
    Just make sure you mention me and lahwran in the plugin post :D

    @V10lator - this also applies to you :D
     
  21. Offline

    V10lator

  22. Offline

    captainawesome7

    I made a Helmet plugin and realized that it was like 30 lines (So I put the classes in 1 file :p)
    It actually works pretty well, it just forces the helmet slot to act like a regular inventory slot (allowing helmets of any block, items won't appear but cause no problems)
    Code:java
    1. package me.captain.helmets;
    2. import org.bukkit.event.Event.Priority;
    3. import org.bukkit.event.Event.Type;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5. import org.bukkit.event.Event.Result;
    6. import org.getspout.spoutapi.event.inventory.InventoryListener;
    7. import org.getspout.spoutapi.event.inventory.InventoryClickEvent;
    8. import org.getspout.spoutapi.event.inventory.InventorySlotType;
    9. public class Helmets extends JavaPlugin {
    10. @Override
    11. public void onEnable() {
    12. getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new IL(), Priority.Normal, this);
    13. System.out.println("[Helmets] enabled.");
    14. }
    15. @Override
    16. public void onDisable() {
    17. }
    18. }
    19. class IL extends InventoryListener {
    20. @Override
    21. public void onInventoryClick(InventoryClickEvent event) {
    22. if(event.getSlotType() == InventorySlotType.HELMET) {
    23. event.setResult(Result.ALLOW);
    24. }
    25. }
    26. }

    http://dev.bukkit.org/server-mods/helmets/
     
  23. Offline

    s1mpl3x

    got 2 more, quite simple but they work like a charm

    SpawnCmd:
    simple plugin which provides the /spawn [player] & /setspawn commands with permissions
    download: http://www.over9000.eu/downloads/minecraft/etc/Spawncmd.jar
    Code:
    package me.simplex.spawncmd;
    import org.bukkit.command.*;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Spawncmd extends JavaPlugin {
        private static final String PREFIX = "[SPAWNCMD] ";
        public void onDisable() {
            System.out.println(PREFIX+"v"+getDescription().getVersion()+" disabled.");
        }
        public void onEnable() {
            System.out.println(PREFIX+"v"+getDescription().getVersion()+" enabled.");
        }
        public boolean onCommand(CommandSender sender, Command command,String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(PREFIX+"Player only command");
                return true;
            }
            Player p = (Player)sender;
            if (command.getName().equalsIgnoreCase("spawn") && args.length == 0 && p.hasPermission("spawncmd.self")) {    // Port self to spawn
                    p.teleport(p.getWorld().getSpawnLocation());
                    p.sendMessage(PREFIX+"Teleported to Spawn.");
                    return true;
            }
            if (command.getName().equalsIgnoreCase("spawn") && args.length == 1 && p.hasPermission("spawncmd.other")) {    // Port others to spawn
                Player tp = getServer().getPlayer(args[0]);
                if (tp == null) {
                    p.sendMessage(PREFIX+"Player not found");
                    return true;
                }
                tp.teleport(tp.getWorld().getSpawnLocation());
                p.sendMessage(PREFIX+"Teleported "+tp.getName()+" to spawn.");
                tp.sendMessage(PREFIX+p.getName()+" teleported you to the spawn.");
                return true;
            }
            if (command.getName().equalsIgnoreCase("setspawn") && args.length == 0 && p.hasPermission("spawncmd.set")) {                        // set the spawn
                p.getWorld().setSpawnLocation(p.getLocation().getBlockX(),p.getLocation().getBlockY(), p.getLocation().getBlockZ());
                p.sendMessage(PREFIX+"Spawnpoint set.");
                return true;
            }
            return false;
        }
    }
    HomeCmd:
    simple plugin which provides /sethome & /home commands per world and with permissions
    download: http://www.over9000.eu/downloads/minecraft/etc/Homecmd.jar
    Code:
    package me.simplex.homecmd;
    import org.bukkit.Location;
    import org.bukkit.command.*;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.config.Configuration;
    public class Homecmd extends JavaPlugin {
        private static final String PREFIX = "[HOMECMD] ";
        private Configuration cfg;
        public void onDisable() {
            System.out.println(PREFIX+"v"+getDescription().getVersion()+" disabled.");
        }
        public void onEnable() {
            System.out.println(PREFIX+"v"+getDescription().getVersion()+" enabled.");
            cfg = getConfiguration();
        }
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(PREFIX+"Player only command");
                return true;
            }
            Player p = (Player)sender;
            if (command.getName().equalsIgnoreCase("home") && args.length == 0 && p.hasPermission("homecmd.go")) {
                int x = cfg.getInt(p.getWorld().getName()+"."+p.getName()+"."+"X", p.getWorld().getSpawnLocation().getBlockX());
                int y = cfg.getInt(p.getWorld().getName()+"."+p.getName()+"."+"Y", p.getWorld().getSpawnLocation().getBlockY());
                int z = cfg.getInt(p.getWorld().getName()+"."+p.getName()+"."+"Z", p.getWorld().getSpawnLocation().getBlockZ());
                p.teleport(new Location(p.getWorld(), x, y, z));
                p.sendMessage(PREFIX+"teleported to home");
                return true;
            }
            if (command.getName().equalsIgnoreCase("sethome") && args.length == 0 && p.hasPermission("homecmd.set")) {
                cfg.setProperty(p.getWorld().getName()+"."+p.getName()+"."+"X", p.getLocation().getBlockX());
                cfg.setProperty(p.getWorld().getName()+"."+p.getName()+"."+"Y", p.getLocation().getBlockY());
                cfg.setProperty(p.getWorld().getName()+"."+p.getName()+"."+"Z", p.getLocation().getBlockZ());
                cfg.save();
                p.sendMessage(PREFIX+"set your home in this world to ["+p.getLocation().getBlockX()+"|"+p.getLocation().getBlockY()+"|"+p.getLocation().getBlockZ()+"]");
                return true;
            }
            return false;
        }
    }
     
  24. Offline

    cholo71796

    @codename_B

    I've been in many situations where a server is locked up completely because TNT is exploding. I wrote this quick plugin to eliminate the need for MCEdit and so forth. Restart/reload server, problem fixed. Deletes all TNTPrimed entities onEnable. Then I realized it was under 50 lines :p
    Code:java
    1. package wut.cholo71796.tntsweep;
    2.  
    3. import org.bukkit.World;
    4. import org.bukkit.entity.Entity;
    5. import org.bukkit.entity.TNTPrimed;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. /**
    9.  *
    10.  * @author Cole Erickson
    11.  */
    12. public class TntSweep extends JavaPlugin {
    13. @Override
    14. public void onDisable() {}
    15. @Override
    16. public void onEnable() {
    17. for (World world : getServer().getWorlds())
    18. for (Entity entity : world.getEntities())
    19. if (entity instanceof TNTPrimed)
    20. entity.remove();
    21. }
    22.  
    23. }
     
  25. Offline

    tips48

    BlockNetherBed - No bed placement in the nether! Was requested by some person.
    Its like 39 lines or something
    Code:java
    1. package com.tips48.blockNetherBed;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.World.Environment;
    7. import org.bukkit.event.Event.Priority;
    8. import org.bukkit.event.Event.Type;
    9. import org.bukkit.event.block.BlockListener;
    10. import org.bukkit.event.block.BlockPlaceEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class BlockNetherBed extends JavaPlugin {
    14. private final String prefix = "[BlockNetherBed]";
    15. private final Logger log = Logger.getLogger("Minecraft");
    16. private final double version = 0.1;
    17. private final int subVersion = 0;
    18.  
    19. public void onEnable() {
    20. log.info(prefix + " " + version + "_" + subVersion + " enabling.");
    21. getServer().getPluginManager().registerEvent(Type.BLOCK_PLACE, new bListener(), Priority.Normal, this);
    22. log.info(prefix + " enabled");
    23. }
    24. public void onDisable() {
    25. log.info(prefix + " disabled.");
    26. }
    27.  
    28. private class bListener extends BlockListener {
    29. public void onBlockPlace(BlockPlaceEvent event) {
    30. if(!(event.getPlayer().getWorld().getEnvironment() == Environment.NETHER)) {
    31. return;
    32. }
    33. if(event.getBlock().getType().equals(Material.BED) || event.getBlock().getType().equals(Material.BED_BLOCK)) {
    34. event.setCancelled(true);
    35. }
    36. }
    37. }
    38. }
    39.  
     
  26. Offline

    Intelli

    ClimbVines

    I didn't really try to make this compact :3.
    However, this plugin enables you to climb vines in Minecraft 1.8

    Code:
    package com.minerealm.core;
    
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.util.Vector;
    
    public class ClimbVines extends JavaPlugin {
        private final ClimbVinesPlayerListener playerListener = new ClimbVinesPlayerListener(this);
    
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_MOVE , playerListener, Priority.Normal, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
        }
    
        public class ClimbVinesPlayerListener extends PlayerListener {
            private final ClimbVines plugin;
    
            public ClimbVinesPlayerListener(ClimbVines instance) {
                plugin = instance;
            }
    
            @Override
            public void onPlayerMove (PlayerMoveEvent event){
                Player player = event.getPlayer();
                Block target = player.getTargetBlock(null, 1);
                int targetid = target.getTypeId();
    
                if (targetid==106){
                    Vector dir = player.getVelocity();
                    Vector vec = new Vector(dir.getX(), 0.40, dir.getZ());
                    player.setVelocity(vec);
                }
            }
        }
    
        public void onDisable() {}
    }
     
  27. Offline

    alexanderpas

    Sneak Preview!
    The /compass command under 50 lines, including usage permission. (proper version will be released as a proper plugin soon.)
    Code:
    package org.dropdev.microcompass;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class MicroCompass extends JavaPlugin {
        Logger log = Logger.getLogger("Minecraft");
        public void onEnable() {
            log.info(this.getDescription().getName() + " has been enabled.");
        }
        public void onDisable() {
            log.info(this.getDescription().getName() + " has been disabled.");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("compass")){
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (player.hasPermission("microcompass.command.compass")) {
                        player.sendMessage(ChatColor.YELLOW + "You are facing: " + getDirection(player));
                    }
                    return true;
                }
            }
            return false;
        }
        private String getDirection(Player player) {
            int degrees = (Math.round(player.getLocation().getYaw()) + 270) % 360;
            if (degrees <= 22) return "North";
            if (degrees <= 67) return "Northeast";
            if (degrees <= 112) return "East";
            if (degrees <= 157) return "Southeast";
            if (degrees <= 202) return "South";
            if (degrees <= 247) return "Southwest";
            if (degrees <= 292) return "West";
            if (degrees <= 337) return "Northwest";
            if (degrees <= 359) return "North";
            return null;
        }
    }
     
  28. Offline

    drampelt

    FlowerMen - all Enderman hold pretty red roses.
    Code:
    package me.drampelt.flowermen;
    import org.bukkit.Material;
    import org.bukkit.entity.*;
    import org.bukkit.event.Event.*;
    import org.bukkit.event.entity.*;
    import org.bukkit.material.MaterialData;
    import org.bukkit.plugin.java.JavaPlugin;
    public class FlowerMen extends JavaPlugin{
    	@Override
    	public void onEnable(){
    		System.out.println("[FlowerMen] enabled.");
    		getServer().getPluginManager().registerEvent(Type.CREATURE_SPAWN, new EntityListener(){
    			@Override
    			public void onCreatureSpawn(CreatureSpawnEvent event){
    				if(event.getCreatureType() == CreatureType.ENDERMAN){
    					Enderman e = (Enderman) event.getEntity();
    					e.setCarriedMaterial(new MaterialData(Material.RED_ROSE));
    				}
    			}
    		}, Priority.Normal, this);
    	}
    	@Override
    	public void onDisable(){
    		System.out.println("[FlowerMen] disabled.");
    	}
    }
    
     
    chasechocolate likes this.
  29. Offline

    r3Fuze

    No Exp - No Exp drops on death (12 lines)

    Code:java
    1. package com.fuze.NoExpUnder50;
    2. public class Main extends org.bukkit.plugin.java.JavaPlugin {
    3. public void onDisable() {System.out.println("NoExpUnder50 disabled.");}
    4. public void onEnable() {
    5. this.getServer().getPluginManager().registerEvent(org.bukkit.event.Event.Type.ENTITY_DEATH, new org.bukkit.event.entity.EntityListener() {
    6. public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent e) {
    7. e.setDroppedExp(0);
    8. }
    9. }, org.bukkit.event.Event.Priority.Normal, this);
    10. System.out.println("NoExpUnder50 enabled.");
    11. }
    12. }


    1 Line version:
    Code:java
    1. package com.fuze.NoExpUnder50; public class Main extends org.bukkit.plugin.java.JavaPlugin { public void onDisable() {System.out.println("NoExpUnder50 disabled.");} public void onEnable() { this.getServer().getPluginManager().registerEvent(org.bukkit.event.Event.Type.ENTITY_DEATH, new org.bukkit.event.entity.EntityListener() { public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent e) { e.setDroppedExp(0); } }, org.bukkit.event.Event.Priority.Normal, this); System.out.println("NoExpUnder50 enabled."); } }


    Unoriginality ftw :D
     
  30. Offline

    Omen

    how do i go about using this?
    i wish i knew java
     
Thread Status:
Not open for further replies.

Share This Page