I just wanted to know how to "Capture a flag" in my plugin. What i want it to do is when they run below their teams flag, and if they have the enemies flag.. then it sends them a message like "You scored!" and to clear their inventory.. This is the last thing i need to work on for my plugin but i cant get it to work! Please help!
you could record the locations of their 'base' and then crosscheck those with the block location of the player in a PlayerMoveEvent. Using a PlayerMoveEvent can be risky because it can be called hundreds of times a second. You would want to limit how much code it goes through with like checking if the player has a flag before anything else or something to really limit what is calculated in each run through.
I saved the location of the flag in the config then used Code:java if(player.getLocation.equals(new Location(player.getWorld(), plugin.getConfig().getInt("Location.Flag.X"),plugin.getConfig().getInt("Location.Flag.Y") - 1,plugin.getConfig().getInt("Location.Flag.Z"){//rest of my code here}
You should check if they're within a certain amount, getting the numbers to line up perfectly would be unlikely.
If you want to check if a player stepped on a certain block then you can just get the block under them and check the location of that block with the location of the block that you want them to step on
Something like this: Code: Location pLoc = plater.getLocation().getBlock().getLocation().subtract(0, 1, 0); Location bLoc = LocationOfNeededBlock; if(pLoc == bLoc) { //remove flag and do whatever else you have to }