-
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Mirai edited this page May 7, 2024
·
8 revisions
An example of how to use some of its methods could be the following:
package org.example;
import net.ritasister.wgrp.api.WorldGuardRegionProtect;
import net.ritasister.wgrp.api.WorldGuardRegionProtectProvider;
import net.ritasister.wgrp.api.manager.regions.RegionAdapterManager;
import net.ritasister.wgrp.api.messaging.MessagingService;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.jetbrains.annotations.NotNull;
public class FantasticClass implements Listener {
@EventHandler
public void doAwesomeStuff(@NotNull PlayerMoveEvent event) {
WorldGuardRegionProtect api = WorldGuardRegionProtectProvider.get();
Player player = event.getPlayer();
/*
* Location, where the event will be triggered with sending
* a message and checking the region that the player
* hit the region boundary by entering it
*/
Location location = event.getTo();
String exampleCmd = "/test";
RegionAdapterManager regionAdapter = api.getRegionAdapter();
MessagingService messagingService = api.getMessagingService();
if(regionAdapter.checkStandingRegion(location)) {
event.setCancelled(true);
messagingService.notify(player.getName(), exampleCmd, regionAdapter.getProtectRegionName(location));
}
/*
* Or do just cancel join into the region.
*/
if(regionAdapter.checkStandingRegion(location)) {
event.setCancelled(true);
}
}
}