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

    Roervig2473

    I just had to make one myself, so here it is

    Code:JAVA
    1.  
    2. package org.craftingdreamznetwork.Roervig2473.plugins.Whoops;
    3. public class Whoops extends org.bukkit.plugin.java.JavaPlugin{
    4. public void onEnable(){
    5. System.out.println("[Whoops] Is enabled:D");
    6. System.out.println("Nope!");
    7. org.bukkit.Bukkit.getServer().shutdown();
    8. }
    9. public void onDisable(){
    10. System.out.println("[Whoops] got disabled:O");
    11. }
    12. }
    13.  


    and the plugin is availeble here

    Made 1 more
    Code:JAVA
    1.  
    2. package org.craftingdreamznetwork.Roervig2473.plugins.Nope.ALL;
    3. public class Nope extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener {
    4. public void onEnable() {
    5. System.out.println("[Nope] I'm enabled OMFG!");
    6. getServer().getPluginManager().registerEvents(this, this);
    7. }
    8. public void onDisable() {
    9. System.out.println("[Nope] I'm disabled :O");
    10. }
    11. public void onPlayerLogin(org.bukkit.event.player.PlayerLoginEvent e, org.bukkit.entity.Player player) {
    12. if(player.getName().equalsIgnoreCase("Jeb_")) {
    13. player.kickPlayer("NOPE!");
    14. }
    15. }
    16. }
    17.  


    Making a bukkitdev for it now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  2. Offline

    md_5

    LanBukkit, shows your Bukkit server to the lan:
    Code:java
    1.  
    2. package com.md_5;
    3. import java.io.IOException;
    4. import java.net.DatagramPacket;
    5. import java.net.DatagramSocket;
    6. import java.net.InetSocketAddress;
    7. import java.util.logging.Level;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. public class LanBukkit extends JavaPlugin implements Runnable {
    10. private DatagramSocket socket;
    11. private InetSocketAddress broadcastAddr = new InetSocketAddress("224.0.2.60", 4445);
    12. @Override
    13. public void onEnable() {
    14. try {
    15. socket = new DatagramSocket();
    16. getServer().getScheduler().scheduleAsyncRepeatingTask(this, this, 0, 30);
    17. } catch (IOException ex) {
    18. getLogger().severe("Could not start LAN server broadcaster");
    19. }
    20. }
    21. @Override
    22. public void onDisable() {
    23. if (socket != null) {
    24. socket.close();
    25. }
    26. getServer().getScheduler().cancelTasks(this);
    27. }
    28. public void run() {
    29. try {
    30. byte[] broadcast = ("[MOTD]" + getServer().getMotd() + "[/MOTD][AD]" + getServer().getIp() + ":" + getServer().getPort() + "[/AD]").getBytes();
    31. socket.send(new DatagramPacket(broadcast, broadcast.length, broadcastAddr));
    32. } catch (IOException ex) {
    33. getLogger().log(Level.SEVERE, "Caught exception, shutting down", ex);
    34. }
    35. }
    36. }
     
    Ultimate_n00b, desht, zhuowei and 2 others like this.
  3. Offline

    jacklin213

    md_5 how do u do the java brackets?
     
  4. Offline

    md_5

    You mean
    Code:
    [SYNTAX=java]Code[/SYNTAX]
     
    Tanite likes this.
  5. Offline

    jacklin213

    Code:java
    1. test


    EDIT: oh thanks md_5
     
  6. Offline

    codename_B

    PlayerCleanup - remove all player.dat files older than a certain date (on server startup)
    Code:
    package de.bananaco.cleanup;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.plugin.java.JavaPlugin;
    // download at http://www.sendspace.com/file/mofqpf
    public class PlayerCleanup extends JavaPlugin {
        public static final int DEFAULT_LENGTH = 60*60*24*7;
        private long cleanupSeconds;
        @Override
        public void onEnable() {
            if(getConfig().get("cleanup-seconds") == null) {
                getConfig().options().header("This is the age of the file (in seconds) before it is flagged for deletion\nDefault: 7 days\n(60*60*24*7)");
                getConfig().set("cleanup-seconds", DEFAULT_LENGTH);
                saveConfig();
            }
            this.cleanupSeconds = getConfig().getInt("cleanup-seconds")*1000;
            List<File> cleanup = getDataFiles(new ArrayList<File>());
            System.out.println("Checking through "+cleanup.size()+" player.dat files");
            List<File> expired = new ArrayList<File>();
            for(File file : cleanup)
                if(hasExpired(file.lastModified()))
                    expired.add(file); // add the file to the expired list
            cleanup.clear(); // remove the references
            System.out.println("Found "+expired.size()+" expired player.dat files");
            if(expired.size() > 0) {
                for(File file : expired) file.delete();
                expired.clear();
            }
        }   
        public boolean hasExpired(long time) {
            return time+cleanupSeconds < System.currentTimeMillis();
        }
        public List<File> getDataFiles(List<File> files) {
            File root = getDataFolder().getAbsoluteFile().getParentFile().getParentFile(); // return the server root folder
            File[] subFiles = root.listFiles(); // return the files in the server root
            for(int i=0; i<subFiles.length; i++) {
                File players = new File(subFiles[i], "players");
                if(players.exists()) // does the folder contain a players directory?
                    addAll(players, ".dat", files); // if so add all player.dat files contained in the directory
            }
            return files;
        }
        public void addAll(File file, String ending, List<File> files) {
            File[] subFiles = file.listFiles();
            for(File f : subFiles) // just need to iterate
                if(f.getName().endsWith(ending)) // if it ends with our ending
                    files.add(f); // add the the list if it ends with the ending we're looking for
        }
    }
    
    Made per-request of this fellow - bang on 50 lines
    http://forums.bukkit.org/threads/player-dat-cleaner-request.94555/
     
  7. Offline

    Deathmarine

    Code:java
    1. package com.modcrafting.simpleragequit;
    2. import java.io.File;
    3. import java.util.HashSet;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.PlayerDeathEvent;
    7. import org.bukkit.event.player.PlayerQuitEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. public class SimpleRageQuit extends JavaPlugin implements Listener{
    10. HashSet<String> set = new HashSet<String>();
    11. public void onEnable(){
    12. this.getServer().getPluginManager().registerEvents(this, this);
    13. this.getDataFolder().mkdir();
    14. if(!new File(this.getDataFolder(),"config.yml").exists()){
    15. this.getConfig().set("RageMessage", "&4%name% RageQuit");
    16. this.getConfig().set("TimeInTicks",(int) 120);
    17. this.saveConfig();
    18. }
    19. }
    20. @EventHandler
    21. public void onPlayerQuit(PlayerQuitEvent event){
    22. if(set.contains(event.getPlayer().getName())){
    23. String message = this.getConfig().getString("RageMessage");
    24. if(message.contains("%name%")) message = message.replace("%name%", event.getPlayer().getName());
    25. event.setQuitMessage(formatMessage(message));
    26. }
    27. }
    28. @EventHandler
    29. public void onPlayerDeath(PlayerDeathEvent event){
    30. final String name = event.getEntity().getName();
    31. set.add(name);
    32. getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable(){
    33. @Override
    34. public void run() {
    35. set.remove(name);
    36. }
    37. },this.getConfig().getInt("TimeInTicks"));
    38. }
    39. public String formatMessage(String str){
    40. String funnyChar = new Character((char) 167).toString();
    41. str = str.replaceAll("&", funnyChar);
    42. return str;
    43. }
    44. }


    Request as well.. http://forums.bukkit.org/threads/simple-ragequit-message.94048/
    Originally 5 lines.

    Why waste time defining each label?
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. if(!(sender instanceof Player)) return true;
    4. return ((Player)sender).addPotionEffect(new PotionEffect(PotionEffectType.getByName(label.toUpperCase()), 20000, 1));
    5. }
    6.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  8. Deathmarine Cause, for example, you can't transform "fireresistance" to "FIRE_RESISTANCE". ;)
     
  9. Offline

    codename_B

    It'd probably be easier to do it like this
    Code:
    public PotionEffectType getByNameLoosely(String name) {
    name = name.toLowerCase();
    for(PotionEffectType type : PotionEffectType.values()) {
    String n = type.getName().toLowerCase().replaceAll("_", "");
    if(n.contains(name) || name.contains(n)) return type;
    }
    return null;
    }
    
     
    zhuowei likes this.
  10. Offline

    Deathmarine

    I don't completely like it. If your name is h you'll get the first type of that list.
    Code:java
    1.  
    2. public PotionEffectType seeAndSay(String name){
    3. for(PotionEffectType type : PotionEffectType.values()){
    4. String n = type.getName().replaceAll("_", "");
    5. if(name.equalsIgnoreCase(n)){
    6. return type;
    7. }
    8. }
    9. return null;
    10. }
    11.  

    Fixed :)

    Code:
    String st = "fireresistance";
    st = new StringBuffer(st).insert(4, "_").toString().toUpperCase();
    
    Sorry had to go all literal. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  11. Offline

    totokaka

    Ok, I've got one. Notify, it notifies op's when players tries to excecute commands.
    31 lines including plugin.yml
    Code:java
    1. package me.totokaka.notify;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Notify extends JavaPlugin implements Listener{
    10.  
    11. public void onEnable(){
    12. Bukkit.getPluginManager().registerEvents(this, this);
    13. }
    14.  
    15. @EventHandler
    16. public void onCommand(PlayerCommandPreprocessEvent event){
    17. if(event.getPlayer().hasPermission("notify.log")){
    18. Bukkit.broadcast(event.getPlayer().getName()+" excecuted command: "+event.getMessage(), "notify.notify");
    19. }
    20. }
    21. }


    Code:YAML
    1. main: me.totokaka.notify.Notify
    2. version: 1.0
    3. name: Notify
    4. permissions:
    5. notify.notify:
    6. description: notifies when a player excecutes a command
    7. default: op
    8. notify.log:
    9. description: notifies an op when a command by this player is excecuted
    10. default: not op
     
  12. Offline

    Kodfod

    Code:java
    1. package me.kodfod.PlayInfo;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class PlayInfo extends JavaPlugin{
    11.  
    12. public void onEnable() {
    13. }
    14.  
    15. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    16. String player2 = Bukkit.getPlayer(args[0]).getDisplayName();
    17. if (cmd.getName().equalsIgnoreCase("pinfo")) {
    18. if (sender.hasPermission("pinfo.use")) {
    19. sender.sendMessage(ChatColor.AQUA + "--------------" + player2 + ChatColor.AQUA + "--------------");
    20. sender.sendMessage(ChatColor.GREEN + "- IP Address: " + "/" + Bukkit.getPlayer(args[0]).getAddress());
    21. sender.sendMessage(ChatColor.GREEN + "- Health: " + Bukkit.getPlayer(args[0]).getHealth() + "/" + Bukkit.getPlayer(args[0]).getMaxHealth());
    22. sender.sendMessage(ChatColor.GREEN + "- Location: " + Bukkit.getPlayer(args[0]).getWorld().getName() + ", X:" + Bukkit.getPlayer(args[0]).getLocation().getBlockX() + ", Y:" + Bukkit.getPlayer(args[0]).getLocation().getBlockY() + ", Z:" + Bukkit.getPlayer(args[0]).getLocation().getBlockZ());
    23. sender.sendMessage(ChatColor.GREEN + "- Gamemode: " + Bukkit.getPlayer(args[0]).getGameMode().name().toLowerCase());
    24. sender.sendMessage(ChatColor.GREEN + "- Experience: " + Bukkit.getPlayer(args[0]).getLevel());
    25. sender.sendMessage(ChatColor.GREEN + "- FoodLevel: " + Bukkit.getPlayer(args[0]).getFoodLevel());
    26. sender.sendMessage(ChatColor.GREEN + "- Is OP: " + Bukkit.getPlayer(args[0]).isOp());
    27. sender.sendMessage(ChatColor.GREEN + "- Played Before: " + Bukkit.getPlayer(args[0]).hasPlayedBefore());
    28. sender.sendMessage(ChatColor.GREEN + "- Can Fly: " + Bukkit.getPlayer(args[0]).getAllowFlight());
    29. sender.sendMessage(ChatColor.GREEN + "- Player Time: " + Bukkit.getPlayer(args[0]).getPlayerTime());
    30. sender.sendMessage(ChatColor.GREEN + "- Item Held: " + Bukkit.getPlayer(args[0]).getItemInHand().getType());
    31. sender.sendMessage(ChatColor.GREEN + "- White Listed: " + Bukkit.getPlayer(args[0]).isWhitelisted());
    32. sender.sendMessage(ChatColor.AQUA + "-------------End Player Info--------------");
    33. return true;
    34. }
    35. sender.sendMessage(ChatColor.GREEN + "You Do not Have Permission");
    36.  
    37. return true;
    38. }
    39. return false;
    40. }
    41. public void onDisable() {
    42. }
    43. }
     
  13. Kodfod
    That code is slow... you really should store Bukkit.getPlayer()... instead of the player's displayname which you use only once.
    And you can gain some lines by removing onEnable() and onDisable(), and by using a single if() with the 'and' logic operator: &&
    It's also ArrayOutOfBounds error prone because you're not checking if command actually has an argument.
     
  14. Offline

    Kodfod

    true true and true.

    Seeing it was a very early plugin of mine, i expected nothing less xD
     
  15. codename_B nice code snippet. :)
    Let me try to port it into the code:
    Code:java
    1. package me.apie.potioneffect;
    2. import org.bukkit.command.*;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5. import org.bukkit.potion.*;
    6. public class Main extends JavaPlugin {
    7. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    8. if(!(sender instanceof Player)) return true;
    9. label = label.toUpperCase();
    10. for(PotionEffectType type: PotionEffectType.values()) {
    11. String n = type.getName().replaceAll("_", "");
    12. if(n.contains(label) || label.contains(n))
    13. return ((Player)sender).addPotionEffect(new PotionEffect(type, 20000, 1));
    14. }
    15. return false;
    16. }
    17. }
     
    zhuowei likes this.
  16. Offline

    rmh4209

    My very simple plugin that I'm using for my server:

    OreToStone - Turn any ore into stone on generation
    Code:
    package org.inesgar.OreToStone;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Chunk;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.world.ChunkPopulateEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class OTS extends JavaPlugin implements Listener
    {
     
        private static final Logger log = Logger.getLogger("Minecraft");
     
        @Override
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this);
            log.info("[OTS] Enabled.");
        }
     
        @Override
        public void onDisable()
        {
            log.info("[OTS] Disabled.");
        }
     
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onChunkPopulate(ChunkPopulateEvent event)
        {
            Chunk chunk = event.getChunk();
            for (int y = 0; y < chunk.getWorld().getMaxHeight(); y++)
                for (int x = 0; x < 16; x++)
                    for (int z = 0; z < 16; z++)
                    {
                        if (chunk.getBlock(x, y, z).getType().toString().toUpperCase().contains("ORE"))
                            chunk.getBlock(x, y, z).setType(Material.STONE);
                    }
        }
    }
    
     
  17. Offline

    Icyene

    RunTexture - Change texture packs during runtime;

    With 1.3.1 allowing texture pack changes:

    Code:
    import net.minecraft.server.Packet250CustomPayload;
     
    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 RuntimeTPACKChange extends JavaPlugin
    {
      public boolean onCommand(CommandSender sender, Command command,
        String label, String[] args)
      {
    if(args.length == 0) {
    return;
    }
    for(Player p: Bukkit.getServer().getOnlinePlayers()) {
    ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(new Packet250CustomPayload("MC|TPack", (args[0]+"\0"+16).getBytes()));
    }
    return true;
      }
    }
    
     
  18. Offline

    chaseoes

    :(

    Code:
    import net.minecraft.server.Packet250CustomPayload;
    
    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 RuntimeTPACKChange extends JavaPlugin
    {
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args)
        {
            if(args == null) {
                return;
            }
            for(Player p: Bukkit.getServer().getOnlinePlayers()) {
                ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(new Packet250CustomPayload("MC|TPack", (args[0]+"\0"+16).getBytes()));
            }
            return true;
        }
    }
     
  19. "args" is never null btw, it's got length 0 when you don't input arguments but not null :p
     
  20. Offline

    Icyene

    Indent nazi XD
    Cool, thanks :) didn't know that; I usually don't use commands in my plugins. Plus I wrote that in the browser, hence the horrible indenting. Fixed :p
     
  21. Offline

    afistofirony

    Facepalm - 24-line, permission based /facepalm plugin.

    NOTE: Yes, there is no logger implementation. I just thought the OnDisable was decently funny.
    Code:java
    1. package com.futuredev.facepalm;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.*;
    6. import org.bukkit.entity.Player;
    7.  
    8. public class Facepalm extends JavaPlugin {;
    9.  
    10. public void onEnable(){
    11. getLogger().info("Facepalm enabled.");
    12. }
    13. public void onDisable(){
    14. getLogger().info("Facepalm was disabled. *facepalm*");
    15.  
    16. }public boolean onCommand(CommandSender Sender, Command cmd, String label, String[] args) {
    17. Sender = (Player) Sender;
    18. if (cmd.getName().equalsIgnoreCase("facepalm"));{
    19. if(Sender.hasPermission("facepalm.facepalm"));{
    20. getServer().broadcastMessage(ChatColor.AQUA + Sender.getName() + " facepalmed.");
    21. }
    22. }return true;
    23. }}
     
  22. Offline

    turt2live

    Runs commands on first join (like rules)

    Code:
    package com.turt2live.cmdjoin;
     
    import java.util.List;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CmdOnJoin extends JavaPlugin implements Listener {
        @Override
        public void onEnable(){
            getConfig().options().copyDefaults(true);
            saveConfig();
            getServer().getPluginManager().registerEvents(this, this);
        }
     
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            if(!event.getPlayer().hasPlayedBefore()){
                reloadConfig();
                List<String> commands = getConfig().getStringList("commands");
                if(commands != null){
                    for(String command : commands){
                        getServer().dispatchCommand(event.getPlayer(), command);
                    }
                }
            }
        }
    }
    Configuration layout:
    Code:
    # Do not include the slash, arguments are supported (like 'help 2')
    commands:
    - rules
     
  23. Offline

    codename_B

    My new plugin, RealTNT!
    Makes TNT act more like it would in real life :D

    spot on 50 lines ;)
    Code:
    package de.bananaco.wind;
    import org.bukkit.*;
    import org.bukkit.block.Block;
    import org.bukkit.entity.*;
    import org.bukkit.event.*;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    public class WindStorm extends JavaPlugin implements Listener {
        @EventHandler
        public void onEntityExplode(EntityExplodeEvent event) {
            explodeBlocks(event.getLocation(), event.getYield(), new Vector(0, 0, 0));
            event.getEntity().remove();
            event.setCancelled(true);
        }
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
        public void explodeBlocks(Location center, float yield, Vector v) {
            int p = (int) (yield*12);
            World world = center.getWorld();
            world.playEffect(center, Effect.SMOKE, p);
            Block c = center.getBlock();
            for(int x=-p; x<=p; x++)
                for(int z=-p; z<=p; z++)
                    for(int y=-p; y<=p; y++) {
                        Vector v2 = new Vector(x, y, z);
                        if(v2.distance(v) <= p) {
                            Block f = c.getRelative(x, y, z);
                            if(f.getType() != Material.AIR && !f.isLiquid()) {
                                if(f.getType() == Material.TNT)
                                    world.spawn(f.getLocation(), TNTPrimed.class).setVelocity(getFlight(v2, yield, 0.4));
                                else
                                    world.spawnFallingBlock(f.getLocation(), f.getTypeId(), f.getData());
                                f.setType(Material.AIR);
                            }
                        }
                    }
            for(Entity e : world.getEntities())
                if(e.getLocation().distance(center) < p) {
                    Vector v2 = new Vector(e.getLocation().getX()-center.getX(), e.getLocation().getY()-center.getY(), e.getLocation().getZ()-center.getZ());
                    e.setVelocity(getFlight(v2, yield, 0.4));
                }
        }
     
        public Vector getFlight(Vector v, float yield, double flight) {
            double x = v.getX()==0?((Math.random()>0.5)?flight:-flight):v.getX()>0?flight:-flight, y = yield*3, z = v.getZ()==0?((Math.random()>0.5)?flight:-flight):v.getZ()>0?flight:-flight;
            return new Vector(x, y, z);
        }
    }
    
    http://dev.bukkit.org/server-mods/realtnt/
     
  24. Dude, you have to give this awesome piece of code to Mojang... This has to be implemented upstream! :D
     
    -_Husky_- likes this.
  25. codename_B
    Interesting but I was hoping for something else, which I'd like to suggest !
    It will take the plugin out of this challange but it will be a better plugin IMO... so, instead of throwing blocks randomly, you can get the strength and eventually make a custom list of what blocks should just break, what blocks should fly and what blocks should just drop and crumble on impact (custom dropping entity advised to detect collision and spawn some effects... the STEP_SOUND would be great !)
    You should also take into account the distance from the center, the close the block is to the center, the more it will shatter or fly... and on the edges of the explosion the blocks should just crumble... eventually a delayed task to make blocks fall.
    This is what I imagined:

    ... oh how I loved destroying buildings in that game :}


    Hmm, but a question... why did you cancel the event ? You could've just looped through the blockList() to do your thing.
     
  26. Offline

    codename_B

    Digi less client-side lag if you cancel the event.
     
  27. Offline

    codename_B

    SkyChanger - change any world to appear like any dimension (nether, normal, end)

    Code:
    package de.bananaco.change;
    import net.minecraft.server.*;
    import org.bukkit.*;
    import org.bukkit.command.*;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.*;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class WorldChanger extends JavaPlugin implements Listener {
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if(getConfig().get(player.getWorld().getName()) != null) {
                setDimension(player, getConfig().getInt(player.getWorld().getName(), 0));
            }
        }
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
            if(args.length == 2) {
                if(Bukkit.getWorld(args[0]) == null) return false;
                org.bukkit.World w = Bukkit.getWorld(args[0]);
                for(Player p : w.getPlayers()) setDimension(p, getDimension(args[1]));
                getConfig().set(w.getName(), getDimension(args[1]));
                saveConfig();
                sender.sendMessage("Set world: "+w.getName()+" to dimension "+getDimension(args[1]));
                return true;
            }
            return false;
        }
        public int getDimension(String input) {
            try {
                int i = Integer.parseInt(input);
                if(i == 0 || i == -1 || i == 1) return i;
            } catch (Exception e) {}
            return 0;
        }
        public void setDimension(Player player, int dimension) {
            CraftPlayer cp = (CraftPlayer) player;
            Packet9Respawn packet = new Packet9Respawn(dimension, (byte) 1, net.minecraft.server.WorldType.NORMAL, player.getWorld().getMaxHeight(), EnumGamemode.a(player.getGameMode().getValue()));
            cp.getHandle().netServerHandler.sendPacket(packet);
            org.bukkit.Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
            for(int x=-10; x<10; x++)
                for(int z=-10; z<10; z++)
                    player.getWorld().refreshChunk(chunk.getX()+x, chunk.getZ()+z);
        }
    }
    
    http://www.sendspace.com/file/49pecs
     
    -_Husky_-, zhuowei, WarmakerT and 3 others like this.
  28. codename_B You. Are. Awesome.

    Code:java
    1. package com.tips48.hb;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class HB extends JavaPlugin {
    6.  
    7. }
    8.  

    Made you a Herobrine plugin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  29. Offline

    kyle1320

    My entry:
    Code:
    package me.kyle1320.Under50;
    import java.util.HashMap;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerToggleSneakEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Under50 extends JavaPlugin implements Listener{
        public HashMap<String, Block> blocks = new HashMap<String, Block>();
        public HashMap<Block, Material> oldMats = new HashMap<Block, Material>();
        public Material mat = Material.GLASS;
        public Integer width = 5;
        @Override public void onDisable() {System.out.println("Platformer disabled.");}
        @Override public void onEnable() {getServer().getPluginManager().registerEvents(this, this); System.out.println("Platformer enabled");}
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (sender instanceof Player && cmd.getName().equalsIgnoreCase("platform")) {
                Player player = (Player)sender;
                Block corner = player.getLocation().getBlock().getRelative(width / 2, -1, width / 2);
                if (!blocks.containsKey(player.getName())) {movePlatform(player.getName(), corner, corner);
                }else {movePlatform(player.getName(), corner, null); blocks.remove(player.getName());}
                return true;}return false;}
        @EventHandler public void playerMoved(PlayerMoveEvent event) {
            if (blocks.containsKey(event.getPlayer().getName())) {
                Player player = event.getPlayer();
                Block corner = player.getLocation().getBlock().getRelative(width / 2, -1, width / 2);
                if (!blocks.get(player.getName()).equals(corner)) {movePlatform(player.getName(), blocks.get(player.getName()), corner);}}}
        @EventHandler public void playerSneaked(PlayerToggleSneakEvent event) {
            Player player = event.getPlayer();
            Block corner = player.getLocation().getBlock().getRelative(width / 2, -1, width / 2);
            if (blocks.containsKey(player.getName())) {movePlatform(player.getName(), corner, corner.getRelative(0, -1, 0));}}
        @EventHandler public void loggedOff(PlayerQuitEvent event) {
            Player player = event.getPlayer();
            if (blocks.containsKey(player.getName())) {movePlatform(player.getName(), player.getLocation().getBlock().getRelative(width / 2, -1, width / 2), null); blocks.remove(player.getName());}}
        public void movePlatform(String name, Block from, Block to) {
            Block[] oldBlocks = new Block[(int)Math.pow(width, 2)];
            for (int i=0; i<width; i++) {
                for (int j=0; j<width; j++) {
                    oldBlocks[i * width + j] = from.getRelative(-i, 0, -j);}}
            Block[] newBlocks = new Block[(int)Math.pow(width, 2)];
            if (to != null){for (int i=0; i<width; i++) {for (int j=0; j<width; j++) {newBlocks[i * width + j] = to.getRelative(-i, 0, -j);}}
                for (Block b : oldBlocks) {if (oldMats.containsKey(b)) {b.setTypeId(oldMats.get(b).getId(), false); oldMats.remove(b);}}
                for (Block b : newBlocks) {oldMats.put(b, b.getType()); b.setType(mat);}
            }else {for (Block b : oldBlocks) {if (oldMats.containsKey(b)) {b.setTypeId(oldMats.get(b).getId(), false); oldMats.remove(b);}}}
            blocks.put(name, to);}}
    Note: This is, for all intents and purposes, a joke. This is the result of me telling myself I could do it and then realizing I couldn't. This is probably not without bugs and will probably never be without bugs. It does work, though.

    Platformer! Typing /platform will spawn a 5x5 platform of glass that follows you around. Typing /platform again will remove the platform. Press shift to move down. When the player leaves the platform will also be removed. It is designed to be easily configurable with width and material variables that can be easily changed.
    50 lines ;)
     
  30. Offline

    codename_B

    No need to overjustify yourself. Inefficient and laggy methods are more than welcome in the U50 lines section ;)
     
Thread Status:
Not open for further replies.

Share This Page