Creating a fake item on the floor

Discussion in 'Plugin Development' started by AlexHH251997, Jan 20, 2014.

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

    AlexHH251997

    Hi there,


    I am making a gamemode which involves every 60 seconds a game changing item called the 'FATE GEM' will spawn in one of many locations randomly across the map. Once you walk over the 'FATE GEM' you will be given an Emerald called 'FATE GEM', once right clicked it will open a inventory with all of perks of the 'FATE GEM'. Now I know how to give the item to the player, how to create its own ItemMeta and how to create an inventory menu. The problem I am struggling with is how to:
    • Spawn the item on the floor at a given location
    • Removing the item once someone has walked over it
    • Setting a location from a command
    This is my InGame Gametime class, it is where I define when to load the map etc etc. I have removed anything that is not important:
    Code:java
    1. @Override
    2. public void run() {
    3. if(Lobby.lobbyMode == false){
    4. itime--;
    5. }
    6. if(itime != 0){
    7. if(itime == 2399){
    8. World w = Bukkit.getServer().getWorld(plugin.vtmng.getWinnerWorld());
    9. w.setTime(0);
    10. w.setWeatherDuration(99999999);
    11. mapsInformation(plugin.vtmng.getWinnerWorld());
    12. plugin.getLogger().info("PREPARING: " + plugin.vtmng.getWinnerWorld());
    13. Bukkit.broadcastMessage(plugin.prefix + ChatColor.AQUA + "30" + ChatColor.GOLD + " seconds until the Lobby ends.");
    14. }if(itime == 2380){
    15. for(Player p1 : Bukkit.getOnlinePlayers()) {
    16. for(Player player : Bukkit.getOnlinePlayers()) {
    17. p1.showPlayer(player);
    18. player.showPlayer(p1);
    19. }
    20. }
    21. Bukkit.broadcastMessage(plugin.prefix + ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "10" + ChatColor.DARK_GRAY + "] " + ChatColor.GOLD + "seconds untill the game starts!");
    22. }if(itime == 2375){
    23. Bukkit.broadcastMessage(plugin.prefix + ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "5" + ChatColor.DARK_GRAY + "] " + ChatColor.GOLD + "seconds untill the game starts!");
    24. }if(itime == 2374){
    25. Bukkit.broadcastMessage(plugin.prefix + ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "4" + ChatColor.DARK_GRAY + "] " + ChatColor.GOLD + "seconds untill the game starts!");
    26. }if(itime == 2373){
    27. Bukkit.broadcastMessage(plugin.prefix + ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "3" + ChatColor.DARK_GRAY + "] " + ChatColor.GOLD + "seconds untill the game starts!");
    28. }if(itime == 2372){
    29. Bukkit.broadcastMessage(plugin.prefix + ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "2" + ChatColor.DARK_GRAY + "] " + ChatColor.GOLD + "seconds untill the game starts!");
    30. }if(itime == 2371){
    31. Bukkit.broadcastMessage(plugin.prefix + ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "1" + ChatColor.DARK_GRAY + "] " + ChatColor.GOLD + "seconds untill the game starts!");
    32. }if(itime == 2370){
    33. //END OF PREGAME
    34. Lobby.pregameMode = false;
    35. HandlerList.unregisterAll(plugin.pgl);
    36. Bukkit.broadcastMessage(plugin.prefix + ChatColor.GOLD + "Fate beings... Good luck!");
    37. //This is where I want to spawn the first item onto the map from a given location that is
    38. //defined by the /setgemspawn command.
    39. }if(itime == 4){
    40. plugin.getServer().createWorld(new WorldCreator("deathmatch"));
    41. }
    42. //MORE
    43. }else{
    44. cancel();
    45. }
    46.  
    47. }

    I now need to create a /setgemspawn command that the 'FATE GEM' will spawn at. The location needs to be usable when spawning the item.
    If you have any ideas please let me know.
    Regards,
    Alex Harris
     
  2. Offline

    guangong4

    Basically, you just have to utilize ItemMeta.
    If you want a player to get the item, then they just walk over it and take it like vanilla minecraft.
    Code:
    ItemStack fategem = new ItemStack(Material.EMERALD);
    // Creates an ItemStack, fategem.
            ItemMeta fatemeta = fategem.getItemMeta();
    // We are going to edit the item meta.
            fategem.setAmount(1);
            fatemeta.setDisplayName("FATE GEM");
    // And then set it to the ItemStack.
            fategem.setItemMeta(fatemeta);
    Item item = p.getWorld().dropItem(location, fategem);
    // Then we drop the item.
    You should know how to use HashMaps, which can store locations.
     
  3. Offline

    AlexHH251997

    Thanks. I have used HashMaps before I am just not 100% sure on picking a random location from the HashMap. Any idea's?
     
  4. Offline

    Garris0n

    Well for one, why are you storing the locations in maps exactly?
     
  5. Offline

    AlexHH251997

    I am not sure, I thought about a config but then I realized that it would be easier to store the locations in the map exactly as then I could work from it easier.
     
  6. Offline

    guangong4

    You could have the locations in HashMaps like <locone, location>, <loctwo, location>.
    Then you just do Math.random(); and use that to choose which HashMap you're pulling the location from.
    But, if you're going to be doing it with a HashMap, you might as well just put the coordinates and whatnot straight into the plugin.
     
Thread Status:
Not open for further replies.

Share This Page