Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package fr.hikings.warzone.task;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.Sound;
  6. import org.bukkit.World;
  7. import org.bukkit.entity.Player;
  8.  
  9. import com.massivecraft.factions.FPlayer;
  10. import com.massivecraft.factions.FPlayers;
  11. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  12. import com.sk89q.worldguard.protection.flags.DefaultFlag;
  13. import com.sk89q.worldguard.protection.flags.StateFlag;
  14. import com.sk89q.worldguard.protection.managers.RegionManager;
  15.  
  16. import fr.hikings.warzone.Main;
  17.  
  18. public class TaskTime {
  19.     private Main main;
  20.    
  21.     public TaskTime(Main main) {
  22.         this.main = main;
  23.     }
  24.    
  25.    
  26.     public void startTaskTime() {
  27.         final FPlayers factions = FPlayers.getInstance();
  28.         final World eventWorld = main.getServer().getWorld("world");
  29.         final RegionManager regionManager = main.getWorldGuard().getRegionManager(eventWorld);
  30.        
  31.         main.getServer().getScheduler().runTaskTimerAsynchronously(main, ()-> {
  32.            
  33.             if(!main.isActivate) return;
  34.            
  35.             for(Player player : Bukkit.getOnlinePlayers()) {
  36.                 final Location location = player.getLocation();
  37.                 final World world = location.getWorld();
  38.                
  39.                
  40.                 if(world.getName().equals("world") && inWarzone(location)) {
  41.                     final FPlayer fp = factions.getByPlayer(player);
  42.                    
  43.                     if(fp != null && fp.hasFaction() && fp.getFaction().isNormal()) {
  44.                         final String fid = fp.getFactionId();
  45.                         final ApplicableRegionSet set = regionManager.getApplicableRegions(location);
  46.                        
  47.                         if(set.queryState(null, DefaultFlag.PVP) == StateFlag.State.ALLOW) {
  48.                             int points = 1;
  49.                            
  50.                             player.sendMessage(" §4§lWarZone §8» §c+10 §4points !");
  51.                             player.playSound(location, Sound.LEVEL_UP, 1, 1);
  52.                             player.giveExp(100);
  53.                            
  54.                            
  55.                             if(main.time.containsKey(fid)) {
  56.                                 points += main.time.get(fid);
  57.                             } main.time.put(fid, points);
  58.                         }  
  59.                     }  
  60.                 }
  61.             }          
  62.         }, 1200L, 1200L);
  63.     }
  64.    
  65.     private boolean inWarzone(Location location) {
  66.         final int x = location.getBlockX();
  67.         final int z = location.getBlockZ();
  68.        
  69.         if((x < 400) && x > (-400)) {
  70.             if((z > -400) && (z < 400)) {
  71.                 return true;
  72.             }
  73.         } return false;
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement