Need help with My 1v1 Plugin

Discussion in 'Plugin Development' started by Frostblockers, Jan 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Frostblockers

    Hey guys , i made that 1v1mebro plugin, but there is still a couple of things i need someone to help me about since im new to bukkit coding so Here it is.
    Here is my command.class Class an I want to add a perm for the setstart command...
    just do ctrl+f and type setstart and you will find it, I want a perm called 1v1MeBro.setstart
    And i also wanna be able to change the Kit in configs, like i can add whatever i want to it.
    Its only 1 kit.

    i want the Kit file to be kit.yml if possible Please :D

    So if you can please rewrite these codes for me i would really love it Thx

    Code:
    package com.FightmeBro.Frostblockers;
    
    import net.minecraft.server.v1_7_R3.NBTTagList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    
    public class command
      implements CommandExecutor
    {
      main pl;
     
      public command(main pl)
      {
        this.pl = pl;
      }
     
      public boolean onCommand(CommandSender sender, Command cmd, String l, String[] args)
      {
        Player p = (Player)sender;
        if (args.length == 0)
        {
          p.sendMessage("§6---------------------------------------------");
          p.sendMessage("§1Made by §bFrostblockers");
          p.sendMessage("§6---------------------------------------------");
          p.sendMessage(main.prefix + " /1v1MeBro join - Join");
          p.sendMessage(main.prefix + " /1v1MeBro leave - leave");
          p.sendMessage(main.prefix + " /1v1MeBro setstart<1:2> - Set spawnPoints!");
          p.sendMessage("§3---------------------------------------------");
          p.sendMessage("§3Version: " + this.pl.getDescription().getVersion());
          p.sendMessage("§3---------------------------------------------");
        }
        else if (args[0].equalsIgnoreCase("join"))
        {
          if (main.joinable)
          {
            if (main.ingame.size() == 0)
            {
              main.ingame.add(p);
              p.getInventory().clear();
              p.sendMessage(main.prefix + "Joined the queue!");
            }
            else if (main.ingame.size() == 1)
            {
              main.ingame2.add(p);
             
              p.sendMessage(main.prefix + "Joined the arena");
             
              p.getInventory().clear();
             
              main.joinable = false;
             
              Bukkit.getScheduler().runTaskTimerAsynchronously(this.pl, new Runnable()
              {
                int i = 15;
               
                public void run()
                {
                  this.i -= 1;
                  for (Player p1 : main.ingame)
                  {
                    if (this.i == 10) {
                      p1.sendMessage(main.prefix + "The 1v1 begin in §b10 §3Seconds!");
                    } else if (this.i == 5) {
                        p1.sendMessage(main.prefix + "The 1v1 begin in §b5 §3Seconds!");
                    } else if (this.i == 4) {
                        p1.sendMessage(main.prefix + "The 1v1 begin in §b4 §3Seconds!");
                    } else if (this.i == 3) {
                        p1.sendMessage(main.prefix + "The 1v1 begin in §b3 §3Seconds!");
                    } else if (this.i == 2) {
                        p1.sendMessage(main.prefix + "The 1v1 begin in §b2 §3Seconds!");
                    } else if (this.i == 1) {
                        p1.sendMessage(main.prefix + "The 1v1 begin in §b1 §3Seconds!");
                    }
                    if (this.i == 0)
                    {
                        p1.sendMessage(main.prefix + "The battle begin §eNow!");
                      Bukkit.getScheduler().cancelTasks(command.this.pl);
                      p1.getInventory().addItem(new ItemStack[] { new ItemStack(Material.IRON_SWORD) });
                      p1.getInventory().addItem(new ItemStack[] { new ItemStack(Material.BOW) });
                      p1.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ARROW, 32) });
                      p1.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                      p1.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                      p1.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                      p1.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
                      p1.getInventory().addItem(new ItemStack[] { new ItemStack(Material.GOLDEN_APPLE) });
                      main.joinable = false;
                     
    
                      double x = command.this.pl.getConfig().getDouble("Start.1.X");
                      double y = command.this.pl.getConfig().getDouble("Start.1.Y");
                      double z = command.this.pl.getConfig().getDouble("Start.1.Z");
                      float yaw = (float)command.this.pl.getConfig().getDouble("Start.1.Yaw");
                      float pitch = (float)command.this.pl.getConfig().getDouble("Start.1.Pitch");
                      String worldname = command.this.pl.getConfig().getString("Start.1.World");
                     
                      World w = Bukkit.getWorld(worldname);
                     
                      Location l = new Location(w, x, y, z);
                      p1.setHealth(20.0D);
                      p1.setFoodLevel(20);
                      l.setPitch(pitch);
                      l.setYaw(yaw);
                      p1.teleport(l);
                      p1.setGameMode(GameMode.SURVIVAL);
                    }
                  }
                  for (Player p2 : main.ingame2)
                  {
                    if (this.i == 10) {
                        p2.sendMessage(main.prefix + "The 1v1 begin in §b10 §3Seconds!");
                    } else if (this.i == 5) {
                        p2.sendMessage(main.prefix + "The 1v1 begin in §b5 §3Seconds!");
                    } else if (this.i == 4) {
                        p2.sendMessage(main.prefix + "The 1v1 begin in §b4 §3Seconds!");
                    } else if (this.i == 3) {
                        p2.sendMessage(main.prefix + "The 1v1 begin in §b3 §3Seconds!");
                    } else if (this.i == 2) {
                        p2.sendMessage(main.prefix + "The 1v1 begin in §b2 §3Seconds!");
                    } else if (this.i == 1) {
                        p2.sendMessage(main.prefix + "The 1v1 begin in §b1 §3Seconds!");
                    }
                    if (this.i == 0)
                    {
                        p2.sendMessage(main.prefix + "The battle begin §eNow!");
                      Bukkit.getScheduler().cancelTasks(command.this.pl);
                     
                      p2.getInventory().addItem(new ItemStack[] { new ItemStack(Material.IRON_SWORD) });
                      p2.getInventory().addItem(new ItemStack[] { new ItemStack(Material.BOW) });
                      p2.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ARROW, 32) });
                      p2.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                      p2.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                      p2.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                      p2.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
                      p2.getInventory().addItem(new ItemStack[] { new ItemStack(Material.GOLDEN_APPLE) });
                      main.joinable = false;
                      double x = command.this.pl.getConfig().getDouble("Start.2.X");
                      double y = command.this.pl.getConfig().getDouble("Start.2.Y");
                      double z = command.this.pl.getConfig().getDouble("Start.2.Z");
                      float yaw = (float)command.this.pl.getConfig().getDouble("Start.2.Yaw");
                      float pitch = (float)command.this.pl.getConfig().getDouble("Start.2.Pitch");
                      String worldname = command.this.pl.getConfig().getString("Start.2.World");
                     
                      World w = Bukkit.getWorld(worldname);
                     
                      Location l = new Location(w, x, y, z);
                      p2.setHealth(20.0D);
                      p2.setFoodLevel(20);
                      l.setPitch(pitch);
                      l.setYaw(yaw);
                      p2.teleport(l);
                      p2.setGameMode(GameMode.SURVIVAL);
                    }
                  }
                }
                }
              , 0L, 20L);
            }
          }
          else {
            p.sendMessage(main.prefix + " The arena is already ingame!");
          }
        }
        else if (args[0].equalsIgnoreCase("setstart"))
        {
          if (args[1].equalsIgnoreCase("1"))
          {
            this.pl.getConfig().set("Start.1.X", Integer.valueOf(p.getLocation().getBlockX()));
            this.pl.getConfig().set("Start.1.Y", Integer.valueOf(p.getLocation().getBlockY()));
            this.pl.getConfig().set("Start.1.Z", Integer.valueOf(p.getLocation().getBlockZ()));
            this.pl.getConfig().set("Start.1.Yaw", Float.valueOf(p.getLocation().getYaw()));
            this.pl.getConfig().set("Start.1.Pitch", Float.valueOf(p.getLocation().getPitch()));
            this.pl.getConfig().set("Start.1.World", p.getWorld().getName());
           
    
            p.sendMessage(main.prefix + "Start §e1 §3has been set !");
            this.pl.saveConfig();
          }
          else if (args[1].equalsIgnoreCase("2"))
          {
            this.pl.getConfig().set("Start.2.X", Integer.valueOf(p.getLocation().getBlockX()));
            this.pl.getConfig().set("Start.2.Y", Integer.valueOf(p.getLocation().getBlockY()));
            this.pl.getConfig().set("Start.2.Z", Integer.valueOf(p.getLocation().getBlockZ()));
            this.pl.getConfig().set("Start.2.Yaw", Float.valueOf(p.getLocation().getYaw()));
            this.pl.getConfig().set("Start.2.Pitch", Float.valueOf(p.getLocation().getPitch()));
            this.pl.getConfig().set("Start.2.World", p.getWorld().getName());
           
    
            p.sendMessage(main.prefix + "Start §e2 §3has been set !");
            this.pl.saveConfig();
          }
          else
          {
            p.sendMessage(main.prefix + "You can only place 2 Startpoints");
          }
        }
        else if (args[0].equalsIgnoreCase("leave"))
        {
          main.ingame.clear();
          main.ingame2.clear();
          main.joinable = true;
          ((CraftPlayer)p).getHandle().inventory.b(new NBTTagList());
          p.sendMessage(main.prefix + "§bYou left, or your oppenent did.");
          p.performCommand("spawn");
          this.pl.getServer().getScheduler().cancelTasks(this.pl);
          for (Player p1 : main.ingame)
          {
              p.sendMessage(main.prefix + "§bYou left,or your oppenent did.");
              p.getInventory().clear();
            p1.performCommand("spawn");
          }
          for (Player p2 : main.ingame2)
          {
              p.sendMessage(main.prefix + "§bYou left,or your oppenent did.");
              p.getInventory().clear();
            p2.performCommand("spawn");
          }
        }
        return true;
      }
    }
    

    And do the config or kit.yml too plis
     
  2. Offline

    BladeXTD

    You could take some of the code from the Kits plugin (so you can add kits & set 1v1 defaults) and merge the code.
     
  3. Offline

    mrCookieSlime

    Moved to Plugin Developement.
     
    BladeXTD likes this.
  4. What you wanna do ? I don't understand what you want .
     
  5. Offline

    Frostblockers

    I want the plugin to be Mine and not using anyother plugins.
    I want to be able to change the kit through the config file Like
    Id Amount
    Id Amount
    Id Amount

    And also have a permission made for the /1v1mebro setstart command
     
  6. Offline

    BladeXTD

    Hmm...
    I will look into doing this. I am currently on a trip and cannot code plugins. Sorry about that.

    and setOp?
     
  7. Offline

    Frostblockers

    Thank u it would really help me out, and what do u mean by setOp
     
Thread Status:
Not open for further replies.

Share This Page