Major Things I need help with quick!

Discussion in 'Spigot Plugin Development' started by VinexAx789, Jun 17, 2015.

  1. LandMine Part: What I want to do is make a "ssssssssss" sound when a player steps on the landmine then the explosion will be delayed for 1 second then explode who ever places the land mine it shouldn't hurt them nor there teammates I have four teams red team, green team, blue team then purple team I also do not want it damaging blocks just players it should almost kill them too but not the team that uses it.

    LandMine Code:

    Code (Java):
        private List<Location> mines = new ArrayList<Location>();
     
        @EventHandler
        public void onActivate(final PlayerInteractEvent event) {
            final Player p = event.getPlayer();
            if(event.getAction().equals(Action.PHYSICAL)) {
                if(event.getClickedBlock().getType().equals(Material.STONE_PLATE)) {
                    if(mines.contains(event.getClickedBlock().getLocation())) {
                        event.getClickedBlock().setType(Material.AIR);
                        mines.remove(event.getClickedBlock().getLocation());
                        Bukkit.getScheduler().scheduleSyncDelayedTask(
                                Bukkit.getPluginManager().getPlugin(
                                        "MyTestPlugin"), new Runnable() {
                            public void run(){
                                p.playSound(p.getLocation(), Sound.FUSE, 50F, 50F);
                                event.getClickedBlock().getWorld().createExplosion(event.getClickedBlock().getLocation(), 2, false);
                            }
                        },1L);
                    }
                }
            }
        }
     
            @EventHandler
            public void onPlaceMine(BlockPlaceEvent event) {
                if(event.getBlock().getType().equals(Material.STONE_PLATE)) {
                    mines.add(event.getBlock().getLocation());
                    event.getPlayer().sendMessage(ChatColor.YELLOW + "You have placed a" + ChatColor.RED + " landmine!");
                }
            }
    Team Players Code:

    I use this to sort who gets certain things.

    Code (Java):
        ArrayList<Player> redplayers = new ArrayList<Player>();
        ArrayList<Player> greenplayers = new ArrayList<Player>();
        ArrayList<Player> blueplayers = new ArrayList<Player>();
        ArrayList<Player> purpleplayers = new ArrayList<Player>();
       
    Pyro Kit: So I have a small issue when a bow with flame 2 is shot at tnt it turns into primed and blows up so I can't have that happen so what I need to do is make it so when a player gets hit with an arrow from kit pyro they get fire on them for the amount of time the fire ticks stay on so this is what I did.

    Pyro Code:

    Code (Java):
        @EventHandler
        public void onEntityDamageByEntity11(EntityDamageByEntityEvent event) {
            Entity entity = event.getDamager();
            if ((entity instanceof Arrow)) {
                Arrow arrow = (Arrow) entity;
                Entity shooter = arrow.getShooter();
                if(kitselected.get(arrow).equals("pyro")){
                if ((shooter instanceof Player)) {
                        Entity entity1 = event.getEntity();
                        if (players.contains(((Player) shooter).getPlayer().getName())) {
                            entity1.setFireTicks(80);
                        }

                    }
                }
    Please help me fix my buggy code thanks!

    Now a user from a forum site said to me something to guide me and he's now been offline for 6 days so here's what I have to some up what he have said.

    "@VinexAx789 Well, I can't do everything for you, so instead of giving code I'll give u an idea of what to do:

    For your first problem, you will first need to make a HashMap. Make it that when you place the landmine (BlockPlaceEvent), it will add to the hashmap the Block and team, so your HashMap might look something like this:
    HashMap<Block,String>
    For the delay, all you have to do is make a BukkitRunnable and then run it later.
    Than, to make the mine only damage players of the opposite teams, make it that when you stand on the mine, it will get the hashmap we made earlier and get the team that placed the mine. It will then go through all the nearby players of that team and do p.setNoDamageTicks(1)
    Than run the explosion and they shouldn't take damage.

    For your second problem, have a class that has a runnable running every tick or two and set the block at the location of any primed tnt to tnt and kill the primed tnt."


    So here's what I summed up from that:

    1. Add a HashMap such as this for an example
    Code (Java):
    HashMap<Block, Player> stoneplate = new HashMap<Block, Player>();

    2. Make a BukkitRunnble such as this for an example
    Code (Java):
        private List<Location> mines = new ArrayList<Location>();

        @EventHandler
        public void onActivate(final PlayerInteractEvent event) {
            final Player p = event.getPlayer();
            if(event.getAction().equals(Action.PHYSICAL)) {
                if(event.getClickedBlock().getType().equals(Material.STONE_PLATE)) {
                    if(mines.contains(event.getClickedBlock().getLocation())) {
                        event.getClickedBlock().setType(Material.AIR);
                        mines.remove(event.getClickedBlock().getLocation());
                        new BukkitRunnable() {
                       
                            public void run() {
                                p.playSound(p.getLocation(), Sound.FUSE, 50F, 50F);
                                event.getClickedBlock().getWorld().createExplosion(event.getClickedBlock().getLocation(), 2, false);
                           
                            }
                        };
                    }
                    }
                }
        }
    3. Now for this one I'm having trouble doing since I'm sorta a moderate developer still I'm horrible with HashMaps so I might of made the one I created up there incorrect.

    4. I basically get the block that is TNTPrimed then delete it then spawn a TNT block there again.

    5. Now the only thing do not understand how to do is the hashmap I should say I do not understand because I do I'm just having a brain fart atm.

    If you could help me out some more it would be much appreciated! :) Thanks for the help so far!

    I've been stuck here and I need help fast!

    - Thanks Again

     
  2. HashMap<Location, (Team or String)>. On land mine place hashmap.put(Location, Team)
    Then when its activated hashmap.get(Location of Landmine interacted with) if team received = team of player dont set off
     
    • Like Like x 1
  3. Also, I noticed that you wanted the SyncDelayedTask for your landmine to be 1 second. You entered the parameter as 1L. The parameter it takes is in ticks so I suggest you change it to 20 because 20 ticks = 1 second.
    HashMaps basically store values in a key-value way. HashMap<Key, Value>. You can use this to your advantage. You know that for a landmine, it generally has 2 attributes that vary: Location and Team. What is unique? We know that you cannot have 2 landmines in the same location. Thus, use it as your key.
    Code (Text):
    HashMap<Location, Team>
    * Team - you can change this to a String. It depends on what you use to identify a team.
    Now when a player places a landmine, do something like this (assume our HashMap variable is called map).
    Code (Text):
    Location location = *Location of landmine placed*
    Team team = *Team*
    map.put(location, team);
    Now when you want to check whether or not a block is a landmine, just do
    Code (Text):
    Location location = *Location to check*
    if (map.containsKey(location)) {
      *It's a landmine*
    } else {
      *It's not a landmine*
    }
     
    • Like Like x 1
  4. Thank you guys I try it and see what happens and I'll let you guys know.