Rickylachow

Untitled

Dec 13th, 2022
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. package prymarp.prymarp.events.worldguardevents;
  2.  
  3. import com.sk89q.worldedit.util.Location;
  4. import com.sk89q.worldedit.world.World;
  5. import com.sk89q.worldguard.LocalPlayer;
  6. import com.sk89q.worldguard.commands.CommandUtils;
  7. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  8. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  9. import com.sk89q.worldguard.session.MoveType;
  10. import com.sk89q.worldguard.session.Session;
  11. import com.sk89q.worldguard.session.handler.Handler;
  12.  
  13. import java.util.Set;
  14.  
  15. import static prymarp.prymarp.PrymaRP.PRYMAFLAG_COMUNE_ENTRY;
  16.  
  17. public class WGPrymaRegistrazioneEntry extends Handler {
  18.  
  19. public static final Factory FACTORY = new Factory();
  20.  
  21. public static class Factory extends Handler.Factory<WGPrymaRegistrazioneEntry> {
  22. @Override
  23. public WGPrymaRegistrazioneEntry create(Session session) {
  24. return new WGPrymaRegistrazioneEntry(session);
  25. }
  26. }
  27.  
  28. private static final long MESSAGE_THRESHOLD = 1000 * 2;
  29. private long lastMessage;
  30.  
  31. public WGPrymaRegistrazioneEntry(Session session) {
  32. super(session);
  33. }
  34.  
  35. @Override
  36. public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
  37. boolean allowed = toSet.testState(player, PRYMAFLAG_COMUNE_ENTRY);
  38.  
  39. if (!getSession().getManager().hasBypass(player, (World) to.getExtent()) && !allowed && moveType.isCancellable()) {
  40. String message = "Non puoi entrare in questo comune prima di aver completato la registrazione!";
  41. long now = System.currentTimeMillis();
  42.  
  43. if ((now - lastMessage) > MESSAGE_THRESHOLD && message != null && !message.isEmpty()) {
  44. player.printRaw(CommandUtils.replaceColorMacros(message));
  45. lastMessage = now;
  46. }
  47.  
  48. return false;
  49. } else {
  50. return true;
  51. }
  52. }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment