New Coder Custom Slenderman Plugin

Discussion in 'Plugin Development' started by linkrock4, Mar 6, 2013.

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

    linkrock4

    Hi, im linkrock4 and i need help with this plugin. Basicly what this plugin does is its a multiplayer 1v1 minigame. This plugin needs disguisecraft to run, but anyways. When the game starts someone gets set as the slenderman and someone as the survivor. The slenderman is disgised as enderman and the survivor keeps his skin. (There are 5 diffrent maps for map cycle and i just want to know if this map cycle is well made:
    Code:
    package com.gmail.TehLinky4.Ender;
     
    import java.util.List;
    import java.util.Random;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class Ender extends JavaPlugin {
     
            public void onEnable(){
                getLogger().info("Ender is enabled!");
            }
            public void onDisable() {
                getLogger().info("Ender is disabled!"); 
            }
         
              private Random randomGenerator;
              private List<String> maps2;
            @SuppressWarnings("unchecked")
            public void getMaps()
            {
                maps2 = (List<String>) this.getConfig().getList("Maps");
                randomGenerator = new Random();
            }
            public String getRandomMap()
            {
                if(maps2.size() == 0 || maps2 == null){
                    this.getLogger().severe("!!!COULD NOT FIND ANY MAPS OR MAPS LIST RETURNED NULL!!!");
                    return null;
                }else{
                    int index = randomGenerator.nextInt(maps2.size());
                    String map = (String) maps2.get(index);
                    return map;
                }
     
            }
            public Location getLocationConfig(String mapname){
                World map = Bukkit.getWorld(mapname);
         
                      int x = this.getConfig().getInt(mapname + ".x");
                      int y = this.getConfig().getInt(mapname + ".y");
                      int z = this.getConfig().getInt(mapname + ".z");
     
                      Location loc = new Location(map, x, y, z); //defines new location
     
                      return loc;
     
                  }
     
        String mapchosen = getRandomMap();
        World mapworld = Bukkit.getWorld(mapchosen); {
        for(Player p:Bukkit.getOnlinePlayers()){
              p.teleport(getLocationConfig(mapchosen));
        }
    }
    }
    and i also need help with this that im not able to do: when the survivor reaches 8 books in his inventory the game ends, or, when the survivor dies the game ends. This is what i have so far tho i have an error here:
    Code:
    package com.gmail.TehLinky4.Ender1;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Ender1 extends JavaPlugin {
     
        public void onEnable(){
            getLogger().info("Ender1 is enabled!");
        }
        public void onDisable() {
            getLogger().info("Ender1 is disabled!"); 
        }
    +_+_+_+_+ 
        boolean contains (int material340, int 8);
    }
    }
    +_+_+_+_+
    The error is in between the +_+_+_+_+ and i cant find out why. Basicly that boolean does is it founds out if theres 8 books in the survivors inventory but i dont know how to really make it.


    Thnks for the help :)

    NOTE: THE MAP CYCLE CODE IS NOT MINE BUT SOMEONE HELPED ME DO IT BECAUSE I HONESTLY HAD NO IDEA HOW TO DO IT, BUT I DID HALF OF IT :)
     
  2. Offline

    ZeusAllMighty11

    Code:
    boolean hasBooks(Player p){
        return p.getInventory().contains(Material.WRITTEN_BOOK);
    }
    
    Code:
    int getAllBooks(Player p){
       int count = 0;
       for(ItemStack i : player.getInventory().getContents()){
           if(i.getType().equals(Material.WRITTEN_BOOK){
            count += 1; // or count ++;
           }
           return count;
       }
     
  3. Offline

    chasechocolate

    I would use:
    Code:java
    1. public boolean hasItems(Player player, Material item, int amount){
    2. PlayerInventory playerInv = player.getInventory();
    3. if(playerInv.contains(item, amount){
    4. return true;
    5. }
    6. return false;
    7. }

    Also, for ending the game, listen for PlayerDeathEvent and compare the event.getEntity() with the survivor or slenderman.
     
  4. Offline

    linkrock4

    Wow thanks for the code and the game end :) One last thing btw. It tells me i cant return false? it also says The method containsAtLeast(ItemStack, int) in the type Inventory is not applicable for the arguments (int, int), Im really sorry for asking newbish questions :(
     
  5. Offline

    ZeusAllMighty11

    linkrock4

    Code:
    public boolean hasItems(Player player, Material item, int amount){
      PlayerInventory playerInv = player.getInventory();
      if(playerInv.containsAtLeast(item, amount){
        return true;
      } else {
        return false;
      }
      return false; // has to be here
    }
    
     
  6. Offline

    chasechocolate

    linkrock4 fixed it, edited my first post.
     
  7. Offline

    linkrock4

    Thx :D
     
Thread Status:
Not open for further replies.

Share This Page