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

    riggah

    Respawn automatically when you die! (45 lines)

    Code: (41 lines)
    Code:java
    1. package me.riggah.autorespawn;
    2. import java.lang.reflect.Field;
    3. import net.minecraft.server.v1_7_R1.EnumClientCommand;
    4. import net.minecraft.server.v1_7_R1.PacketPlayInClientCommand;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.PlayerDeathEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. public class AutoRespawn extends JavaPlugin implements Listener{
    13. @Override
    14. public void onEnable(){
    15. this.getServer().getPluginManager().registerEvents(this, this);
    16. }
    17. @EventHandler
    18. public void onRespawn(PlayerDeathEvent ev){
    19. final Player plr = ev.getEntity();
    20. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    21. @Override
    22. public void run() {
    23. PacketPlayInClientCommand packet = new PacketPlayInClientCommand();
    24. try {
    25. Field a = PacketPlayInClientCommand.class.getDeclaredField("a");
    26. a.setAccessible(true);
    27. a.set(packet, EnumClientCommand.PERFORM_RESPAWN);
    28. } catch (NoSuchFieldException e) {
    29. e.printStackTrace();
    30. } catch (SecurityException e) {
    31. e.printStackTrace();
    32. } catch (IllegalArgumentException e) {
    33. e.printStackTrace();
    34. } catch (IllegalAccessException e) {
    35. e.printStackTrace();
    36. }
    37. ((CraftPlayer) plr).getHandle().playerConnection.a(packet);
    38. }
    39. }, 2L);
    40. }
    41. }

    plugin.yml (4 lines)
    Code:java
    1. name: AutoRespawn
    2. version: 1.0
    3. author: riggah
    4. main: me.riggah.autorespawn.AutoRespawn
     
  2. Offline

    AoH_Ruthless

    Configure your own commands without using a plugin.yml. Utilizes the simple Bukkit Configuration API and sends messages to command users without that pesky "Unknown Command" message. Click here to read an in-depth tutorial of this same exact code.

    47 Lines of Code and still follows Java Code Conventions :)

    Code:java
    1. package com.valygard;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.configuration.ConfigurationSection;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Links extends JavaPlugin implements Listener {
    11. public void onEnable() {
    12. loadConfigFile();
    13.  
    14. getServer().getPluginManager().registerEvents(this, this);
    15. }
    16.  
    17. private void loadConfigFile() {
    18. saveDefaultConfig();
    19.  
    20. if (getConfig().getConfigurationSection("commands") == null) {
    21. getConfig().set("commands.donate",
    22. "&5To receive amazing merchandise for low prices, visit our web store &e@ [url]http://notarealwebsite.net[/url]");
    23. }
    24. getConfig().options().header(
    25. "vLinks configuration-file v" + getDescription().getVersion());
    26.  
    27. saveConfig();
    28. }
    29.  
    30. @EventHandler
    31. public void onPreprocess(PlayerCommandPreprocessEvent e) {
    32. ConfigurationSection s = getConfig()
    33. .getConfigurationSection("commands");
    34.  
    35. for (String command : s.getKeys(false)) {
    36. if (e.getMessage().equalsIgnoreCase("/" + command)) {
    37. e.getPlayer().sendMessage(
    38. ChatColor.translateAlternateColorCodes('&', getConfig()
    39. .getString("commands." + command)));
    40. e.setCancelled(true);
    41. }
    42. }
    43.  
    44. if (!s.getKeys(false).contains(e.getMessage().replace("/", "")))
    45. e.setCancelled(false);
    46. }
    47. }
     
  3. Offline

    PipeCastells_

    codename_B
    A simple and pointless plugin... FlyingHorses!
    Because everyone love pointless stuff
    Quick description: When you right/left click a blaze rod and have the permission flyinghorse.use, you spawn a horse and start flying around
    Code:java
    1.  
    2. import org.bukkit.Bukkit;
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Horse;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerInteractEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin implements Listener {
    11.  
    12. public void onEnable() {
    13. getLogger().info("Pipecastells_ entrance to CodeName_b 50 lines challenge");
    14. getServer().getPluginManager().registerEvents(this, this);
    15. }
    16.  
    17. @SuppressWarnings("deprecation")
    18. @EventHandler
    19. public void onInteract(final PlayerInteractEvent e) {
    20. if (e.getPlayer().getItemInHand().getType() == Material.BLAZE_ROD) {
    21. if (e.getPlayer().hasPermission("flyinghorse.use")) {
    22. final Horse horse = e.getPlayer().getWorld().spawn(e.getPlayer().getEyeLocation(), Horse.class);
    23. horse.setVelocity(e.getPlayer().getLocation().getDirection().multiply(2));
    24. horse.setPassenger(e.getPlayer());
    25.  
    26. Bukkit.getScheduler().scheduleAsyncRepeatingTask(this,new Runnable() {
    27. public void run() {
    28. if (!horse.isDead() && !e.getPlayer().isDead()) {
    29. horse.setVelocity(e.getPlayer().getLocation().getDirection().multiply(1));
    30. if(horse.getPassenger() != e.getPlayer() && !horse.isOnGround()){
    31. horse.setPassenger(e.getPlayer());
    32. }
    33. }else{
    34. try{
    35. this.finalize();
    36. }catch(Throwable ex){
    37. ex.printStackTrace();
    38. }
    39. }
    40.  
    41. }
    42. }, 0, 10);
    43. }
    44. }
    45. }
    46. }
     
    codename_B likes this.
  4. Offline

    Dudemister1999

    codename_B I made a currency system, and/or API. I call it Crapi (CRedit API)

    Code:java
    1. package me.dudemister.crapi;
    2.  
    3. public class CurrencyAPI extends org.bukkit.plugin.java.JavaPlugin implements org.bukkit.event.Listener
    4. {
    5. public CrAPI dataFile;
    6.  
    7. @Override
    8. public void onEnable() {
    9. dataFile = new CrAPI(getDataFolder(), "data.yml");
    10. }
    11. @Override
    12. public void onDisable() {
    13. dataFile.save();
    14. }
    15. [USER=90828046]Org[/USER].bukkit.event.EventHandler
    16. public void onChat(org.bukkit.event.player.AsyncPlayerChatEvent event) {
    17. String cmd = event.getMessage().split(" ")[0];
    18. if(cmd.equalsIgnoreCase(".getcredits") && event.getPlayer().hasPermission("crapi.get")) {
    19. event.getPlayer().sendMessage(org.bukkit.ChatColor.GREEN + "Your Credits: " + org.bukkit.ChatColor.GOLD + dataFile.config.getInt(event.getPlayer().getUniqueId() + ".balance", 0));
    20. event.setCancelled(true);
    21. }
    22. if(cmd.equalsIgnoreCase(".addcredits") && event.getPlayer().hasPermission("crapi.add")) {
    23. event.getPlayer().sendMessage(org.bukkit.ChatColor.GREEN + "Adding credits to account...");
    24. dataFile.config.set(event.getPlayer().getUniqueId() + ".balance", (dataFile.config.getInt(event.getPlayer().getUniqueId() + ".balance", 0) + 100) );
    25. dataFile.save();
    26. event.setCancelled(true);
    27. }
    28. }
    29. }
    30.  
    31. final class CrAPI
    32. {
    33. public org.bukkit.configuration.file.YamlConfiguration config;
    34. public java.io.File file;
    35.  
    36. public CrAPI(java.io.File folder, String name) {
    37. file = new java.io.File(folder, name);
    38. config = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(file);
    39. save();
    40. }
    41. public boolean save() {
    42. if(!file.exists()) {
    43. try {file.createNewFile(); return true;}
    44. catch (java.io.IOException ex) {System.out.println("Could not save data!"); return false;}
    45. } else {
    46. try {config.save(file); return true;}
    47. catch (java.io.IOException ex) {System.out.println("Could not save data!"); return false;}
    48. }
    49. }
    50. }
     
  5. Offline

    MineStein

    And if I wrote it all on one line? :p
     
  6. Offline

    teej107

    I would actually count the number of lines by counting the semi-colons, methods, fields, etc. After all you could have this:
    Code:java
    1. public class Lines()
    2. {
    3. public Lines()
    4. {
    5.  
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16.  
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23.  
    24.  
    25.  
    26.  
    27.  
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  
    34.  
    35.  
    36.  
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43.  
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54.  
    55.  
    56.  
    57.  
    58.  
    59.  
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66.  
    67.  
    68.  
    69.  
    70. System.exit(0);
    71. }
    72. }
    And it'll fail the under 50 lines challenge.
     
  7. Offline

    DigitalSniperz

    ProxyJoin

    Code:java
    1. package com.mineferno.proxy;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.EventPriority;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.event.player.PlayerLoginEvent;
    7.  
    8. import Listener;
    9. import JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin implements Listener {
    12. public void onEnable() {
    13. getServer().getPluginManager().registerEvents(this, this);
    14. }
    15. public String ip = "localhost";
    16. @EventHandler(priority=EventPriority.HIGHEST)
    17. public void onPlayerLogin(PlayerLoginEvent event)
    18. {
    19. if (!event.getAddress().getHostAddress().equals(ip)) {
    20. event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Connect via proxy!");
    21. }
    22. }
    23. }


    23 lines
     
  8. Offline

    Dudemister1999

    DigitalSniperz Wouldn't AsyncPlayerPreLoginEvent be better? Stop him before he even tries?
     
  9. Offline

    DigitalSniperz

    Either way works.
     
  10. Offline

    woaosodo

    Bleed:
    Lines: 46

    Code:java
    1. package me.woaosodo.Bleed;
    2. import java.util.ArrayList;
    3. import java.util.UUID;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Effect;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.LivingEntity;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Bleed extends JavaPlugin implements Listener {
    16. ArrayList<UUID> isBleeding = new ArrayList();
    17. public void onEnable(){
    18. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20. @EventHandler
    21. public void onDamage(final EntityDamageByEntityEvent e){
    22. if(e.getDamager() instanceof Player){
    23. if(!isBleeding.contains(e.getEntity().getUniqueId())){
    24. isBleeding.add(e.getEntity().getUniqueId());
    25. for(int x = 0; x < 10; x++){
    26. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    27. @Override
    28. public void run() {
    29. if(!e.getEntity().isDead()){
    30. e.getEntity().getWorld().playEffect(e.getEntity().getLocation().add(0,.5,0), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
    31. LivingEntity entity = (LivingEntity) e.getEntity();
    32. entity.damage(1.0);
    33. }
    34. }
    35. }, x*20);
    36. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    37. @Override
    38. public void run() {
    39. isBleeding.remove(e.getEntity().getUniqueId());
    40. }
    41. }, 5*20);
    42. }
    43. }
    44. }
    45. }
    46. }
     
  11. Offline

    stoneminer02

    Pretty easy EnderBow.
    Needs to have "A bow that teleports you." as the lore to be used, has to have infinity 1.
    Code:java
    1. package me.stoneminer02.bukkit.plugin.enderbow;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.enchantments.Enchantment;
    5.  
    6. public class Main extends org.bukkit.plugin.java.JavaPlugin implements
    7. org.bukkit.event.Listener
    8. {
    9. @Override
    10. public void onEnable()
    11. {
    12. org.bukkit.Bukkit.getServer().getPluginManager()
    13. .registerEvents(this, this);
    14. }
    15.  
    16. [USER=90828046]Org[/USER].bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.HIGH, ignoreCancelled = true)
    17. public void onProjectileLand(org.bukkit.event.entity.EntityShootBowEvent e)
    18. {
    19. if (e.getEntity() instanceof org.bukkit.entity.Player)
    20. {
    21. org.bukkit.entity.Player player = (org.bukkit.entity.Player) e
    22. .getEntity();
    23. if (e.getProjectile() instanceof org.bukkit.entity.Arrow
    24. && e.getBow().getEnchantmentLevel(
    25. Enchantment.ARROW_INFINITE) == 1
    26. && e.getBow()
    27. .getItemMeta()
    28. .getLore()
    29. .equals(ChatColor
    30. .stripColor("A bow that teleports you.")
    31. .toLowerCase().toString()))
    32. player.launchProjectile(org.bukkit.entity.EnderPearl.class)
    33. .setVelocity(
    34. e.getProjectile().getVelocity().multiply(1.1));
    35. }
    36. }
    37.  
    38. [USER=90828046]Org[/USER].bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.NORMAL)
    39. public void onDamage(org.bukkit.event.entity.EntityDamageEvent e)
    40. {
    41. e.setCancelled(true);
    42. }
    43. }
    44.  
     
  12. Offline

    Dudemister1999

    stoneminer02 Only one problem: Your code puts all entities in godmode.
     
  13. Offline

    woaosodo

    Just messing around with code -- One more for old times sake I guess :)
    NoTNT (42 Lines)
    [Not exactly no tnt.. More like blocks damaged reset fairly quickly]

    Code:java
    1. package me.woaosodo.NoTNT;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Effect;
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.entity.EntityType;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.EntityExplodeEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class NoTNT extends JavaPlugin implements Listener {
    14.  
    15. public void onEnable(){
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. @SuppressWarnings("deprecation")
    20. @EventHandler
    21. public void onTNT(EntityExplodeEvent e){
    22. if (e.getEntityType().equals(EntityType.PRIMED_TNT)){
    23. int x = 0;
    24. for(final Block b : e.blockList()){
    25. final int bm = b.getTypeId();
    26. final byte bt = b.getData();
    27. x=x+1;
    28. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    29.  
    30. public void run() {
    31. b.getLocation().getBlock().setTypeIdAndData(bm,(byte) bt, false);
    32. b.getLocation().getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
    33. }
    34.  
    35. },x+100);
    36. b.setType(Material.AIR);
    37. e.setCancelled(true);
    38. }
    39. }
    40. }
    41. }
    42.  
     
  14. Offline

    irfantogluk

    AntiMulti - 48 lines
    Prevents more than one players at the same time using the same IP address to enter the server.

    Code:java
    1.  
    2. package so.irfn.antimulti;
    3.  
    4. import java.io.File;
    5. import java.io.IOException;
    6. import java.net.InetSocketAddress;
    7.  
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class AntiMulti extends JavaPlugin implements Listener {
    17. public void onEnable() {
    18. getServer().getPluginManager().registerEvents(this, this);
    19. File configlist = new File(getDataFolder().getAbsolutePath() + File.separator + "config.yml");
    20. if (!getDataFolder().exists()) {
    21. getDataFolder().mkdir();
    22. }
    23. if (!configlist.exists()) {
    24. try {
    25. configlist.createNewFile();
    26. FileConfiguration cfg = YamlConfiguration.loadConfiguration(configlist);
    27. cfg.set("kickMessage", "&cYou are using same IP address with %OTHER_PLAYER%. Multiple accounts are not allowed.");
    28. cfg.save(configlist);
    29. } catch (IOException ex) {
    30. }
    31. }
    32. }
    33.  
    34.  
    35. @EventHandler
    36. public void OyuncuGirdiginde(PlayerJoinEvent e)
    37. {
    38. String Giren = e.getPlayer().getDisplayName();
    39. InetSocketAddress IP = e.getPlayer().getAddress();
    40. for (Player Oyuncular : getServer().getOnlinePlayers())
    41. {
    42. String Digerleri = Oyuncular.getPlayer().getDisplayName();
    43. InetSocketAddress IP_Oyuncular = Oyuncular.getAddress();
    44. if ((!e.getPlayer().isOp() || !e.getPlayer().hasPermission("multi.bypass")) && (Oyuncular != null) && (!Digerleri.equals(Giren)) && (IP_Oyuncular.getHostString().equals(IP.getHostString()))){
    45. e.getPlayer().kickPlayer(getConfig().getString("kickMessage").replace("%OTHER_PLAYER%", Digerleri).replaceAll("&([a-z0-9])", "§$1"));
    46. e.setJoinMessage(null);}
    47. }
    48. }
    49. }
    50.  
     
  15. Offline

    Dudemister1999

    InstantPotion - 50 lines
    Allows players to instantly consume potions, with plugin cancellation support!

    Code:
    package me.dudemister.misc;
    
    import org.bukkit.Material;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.Potion;
    import java.util.Arrays;
    
    public class Main extends JavaPlugin implements Listener
    {
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onPlayerClick(PlayerInteractEvent event) {
            if(Arrays.asList(Action.RIGHT_CLICK_AIR, Action.RIGHT_CLICK_BLOCK).contains(event.getAction())) {
                if (event.getItem() != null && event.getItem().getType() == Material.POTION) {
                    PlayerItemConsumeEvent potionEvent = new PlayerItemConsumeEvent(event.getPlayer(), event.getItem());
                   
                    if(!potionEvent.isCancelled()) {
                        Potion.fromItemStack(event.getItem()).apply(event.getPlayer());
                        decreaseHandItem(event.getPlayer());
                    }
                }
            }
        }
       
        private void decreaseHandItem(Player player) {
            ItemStack item = player.getItemInHand();
            if(item.getAmount() > 1)
            {
                item.setAmount(item.getAmount() - 1);
                player.setItemInHand(item);
            }
            else
            {
                player.setItemInHand(new ItemStack(Material.AIR, 1));
            }
            player.updateInventory();
        }
    }
    It isn't perfect (Quite frankly it can be buggy, with the occasional potion return), but it's a big idea in a little package. I'll improve the code when I resolve the bugs.
     
    Phasesaber and Hoolean like this.
  16. Offline

    MrAwellstein

    Plugin Name: Under50
    Lines: 5
    Lines with plugin.yml: 8
    Functionality: Sends players a message when they join the server.
    Package: Default

    Main.java (open)
    Code:
    public class Main extends org.bukkit.plugin.java.JavaPlugin {
        @Override public void onEnable() {
            org.bukkit.Bukkit.getPluginManager().registerEvents(new org.bukkit.event.Listener(){@org.bukkit.event.EventHandler public void b(org.bukkit.event.player.PlayerJoinEvent event){event.getPlayer().sendMessage("Welcome to the Server! :D");}}, this);
        }
    }

    Something you'll notice, is that I only have one function being called, and since it is technically only one function, I only need to allocate one line for it.

    Show Spoiler
    Code:
    name: Under50
    version: 0.1
    main: Main
     
    Last edited: Feb 26, 2015
    Regablith and ChipDev like this.
  17. Offline

    Regablith

    Good job
     
  18. Offline

    MrAwellstein

    Thanks.
     
  19. Offline

    MrAwellstein

    I miscounted the number of lines in my plugin.yml.... I thought I had 2 instead of 3....
     
  20. Tab header & footer - 38 lines

    Code:java
    1. package com.bwfcwalshy.under50;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. import com.comphenix.protocol.PacketType;
    10. import com.comphenix.protocol.ProtocolLibrary;
    11. import com.comphenix.protocol.ProtocolManager;
    12. import com.comphenix.protocol.events.PacketContainer;
    13. import com.comphenix.protocol.wrappers.WrappedChatComponent;
    14.  
    15. public class Main extends JavaPlugin implements Listener{
    16.  
    17. ProtocolManager mang;
    18.  
    19. public void onEnable(){
    20. saveDefaultConfig();
    21. this.mang = ProtocolLibrary.getProtocolManager();
    22. getServer().getPluginManager().registerEvents(this, this);
    23. }
    24.  
    25. @EventHandler
    26. public void onJoin(PlayerJoinEvent e){
    27. PacketContainer pc = this.mang.createPacket(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER);
    28.  
    29. pc.getChatComponents().write(0, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Tab.Header"))))
    30. .write(1, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Tab.Footer"))));
    31.  
    32. try{
    33. this.mang.sendServerPacket(e.getPlayer(), pc);
    34. }catch (Exception ex){
    35. ex.printStackTrace();
    36. }
    37. }
    38. }
     
  21. @bwfcwalshy
    38 + thousands of lines from ProtocolLib :p
     
  22. @Assist But that's external so yeah :p
     
  23. Offline

    dori99xd

    @bwfcwalshy Here's my version without ProtocolLib! :D
    42 Lines....
    Code:
    package de.underthedom.test;
    import java.lang.reflect.Field;
    
    import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
    import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerListHeaderFooter;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin implements Listener{
        private Field subTitleField;
    
        @Override
        public void onEnable(){
            saveDefaultConfig();
            try {
                subTitleField = PacketPlayOutPlayerListHeaderFooter.class.getDeclaredField("b");
                subTitleField.setAccessible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Bukkit.getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Tab.Header")) + "\"}"));
            try {
                subTitleField.set(packet, ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Tab.Footer")) + "\"}"));
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            ((CraftPlayer)e.getPlayer()).getHandle().playerConnection.sendPacket(packet);
        }
    }
    Edit: lel. my eclipse tells my that are 42 lines. wtf.
     
    bwfcwalshy likes this.
  24. Offline

    mrCookieSlime

    @dori99xd
    There, even more compact :p

    Code:
    package de.underthedom.test;import java.lang.reflect.Field;import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerListHeaderFooter; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.plugin.java.JavaPlugin;public class Main extends JavaPlugin implements Listener{private Field subTitleField;@Override public void onEnable(){saveDefaultConfig();try {subTitleField = PacketPlayOutPlayerListHeaderFooter.class.getDeclaredField("b");subTitleField.setAccessible(true);} catch (Exception e) {e.printStackTrace();}Bukkit.getPluginManager().registerEvents(this, this);}@EventHandler public void onJoin(PlayerJoinEvent e) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Tab.Header")) + "\"}"));try {subTitleField.set(packet, ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Tab.Footer")) + "\"}"));} catch (Exception e2) {e2.printStackTrace();}((CraftPlayer)e.getPlayer()).getHandle().playerConnection.sendPacket(packet);}}
     
  25. Offline

    dori99xd

  26. Offline

    mrCookieSlime

    I didn't do it. I simply took your Code and compressed it into one line, didn't even improve a thing.
    It's april 1st, I am not taking things too seriously today ^^
     
    dori99xd and bwfcwalshy like this.
  27. Offline

    Dudemister1999

    Here's a little landmine plugin (48 lines).
    I know it's been a while since the last post, but I refuse to let such a fun thread die!

    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class LandminePlugin extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            Location from = event.getFrom();
            Location to = event.getTo();
            if(from.distance(to) > 0) { //Are they actually moving?
                Block feet = player.getLocation().getBlock();
                if(feet != null && feet.getType() == Material.STONE_PLATE && feet.hasMetadata("landmine"))
                {
                    feet.setType(Material.AIR);
                    feet.getWorld().createExplosion(feet.getLocation().subtract(0, 1, 0), 4F); //Blow up below the pressure plate, vaulting the player into the air!
                }
            }
        }
       
        @EventHandler
        public void onPlace(BlockPlaceEvent event) {
            ItemStack item = event.getItemInHand();
            if(item != null && item.getType() == Material.STONE_PLATE && item.hasItemMeta()) {
                ItemMeta meta = item.getItemMeta();
                if(meta.hasDisplayName() && meta.getDisplayName().equals(ChatColor.GOLD + "Landmine")) {
                    event.getBlock().setMetadata("landmine", new org.bukkit.metadata.FixedMetadataValue(this, true));
                    event.getPlayer().sendMessage(ChatColor.RED + "Landmine placed, watch yourself!");
                }
            }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page