# Solved How would I check if...

Discussion in 'Plugin Development' started by blok601, Jun 9, 2015.

Not open for further replies.
1. Offline

### blok601

How would I check if a player is inside or touching a cobweb, and then apply damage to the player. I am kind of new to this, but I do understand code. I just have no idea where to start. Thanks in advance!
-blok601

#1
2. Offline

#2
3. Offline

### TheDiamond06

What if the player doesn't move inside of the cobweb?

@blok601
You could have a repeating task every 10 ticks or something that loops through all the players and checks if their location contains a cobweb.

#3
4. Offline

@blok601
When a player is touching a cobweb their movement speed is greatly reduce so you can probably quickly eliminate players with normal walk speed. And then double check if a player with low movement speed is touching a cobweb by scanning all blocks within a 1 block radius of the player to see if it contains a cobweb.

#4
5. Offline

### blok601

Thanks!I know this is a bad question, but how would you scan the blocks with a 1 block radius? Sorry about that, I am not good at this, but it will be nice to learn.

#5
6. Offline

### CraftBang

@blok601
Code from there:
Code:
```for(int x = (int) player.getLocation().getX() - 10; x <= (int) player.getLocation().getX() + 10; x++) {
for(int y = (int) player.getLocation().getY() - 10; y <= (int) player.getLocation().getY() + 10; y++) {
for(int z = (int) player.getLocation().getZ() - 10; z <= (int) player.getLocation().getZ() + 10; z++) {
player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
}
}
}```
I guess replace all 10's with 1 ?

#6
7. Offline

### blok601

Well, I went back to that thread, and all this does is make a wall around the player.

#7
8. Offline

### CraftBang

@blok601

But just replace
Code:
`player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);`
with if(player.getWorld().getBlockAt(x, y, z).getType() == Material.COB_WEB /*< NOT SURE ABOUT COBWEB*/){
//do something here because he is in a cobweb
}

#8
9. Offline

@CraftBang The problem with that method would be that it would damage players if they're near cobweb, not just if they're in cobweb.

#9
10. Offline

### blok601

Would you just do a repeating task?

#10
11. Offline

Maybe ?

#11
12. Offline

### JBoss925

Get the block at the location of the player and if it's a cobweb, damage said player. I would personally use a runnable.

#12
13. Offline

### blok601

Sorry, I am sortve a noob. I know how to use a runnable and all, but how would I check the block at the player's location.

#13
14. Offline

### FisheyLP

player.getLocation().getBlock()

#14
15. Offline

### JBoss925

player.getLocation().getBlock().getType() == Material.COBWEB

#15
16. Offline

### blok601

So I am using a syncRepeatingTask in the onEnable. Am I correct?

#16
17. Offline

### Awesomebanana2002

Make a new class:
Code:
```public class TestCobweb extends BukkitRunnable {
public static List<Player> inCobweb = new ArrayList<Player>();

@Override
public void run() {
for(Player p : Bukkit.getOnlinePlayers()) {
if(p.getLocation().getBlock().getType()==Material.COBWEB) {
}else{
if(inCobweb.contains(p)) inCobweb.remove(p);
}
}
}
}```
And put this in your main class:
Code:
```@Override
public void onEnable() {
}```

18. Offline

### blok601

I really didn't think of that, thanks! I want to damage the player, so would I just do player.damage(5) under the p.getLocation?

#18
19. Offline

Yes

#19
20. Offline

### Awesomebanana2002

Well, if you use that, each tick (there are 20 ticks in a second) will the player get 2,5 hearts damage, so then just change
new TestCobweb().runTaskTimer(this, 1, 1); to new TestCobweb().runTaskTimer(this, 20, 20); to damage it 2,5 hearts every second

21. Offline

### blok601

Alright, trying it out right now. Thanks for the help everyone!

#21