use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onInteractBlock.
// listen all
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
RedProtect.get().logger.debug("player", "RPPlayerListener - InteractBlockEvent canceled? " + event.isCancelled());
BlockSnapshot b = event.getTargetBlock();
BlockState bstate = b.getState();
Location<World> l = null;
if (!b.getState().getType().equals(BlockTypes.AIR)) {
l = b.getLocation().get();
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractBlockEvent event. The block is " + bstate.getType().getName());
} else {
l = p.getLocation();
}
Region r = RedProtect.get().rm.getTopRegion(l);
ItemType itemInHand = ItemTypes.NONE;
ItemStack stack = ItemStack.of(ItemTypes.NONE, 1);
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
stack = p.getItemInHand(HandTypes.MAIN_HAND).get();
itemInHand = stack.getItem();
if (RPUtil.removeGuiItem(stack)) {
p.setItemInHand(HandTypes.MAIN_HAND, ItemStack.of(ItemTypes.NONE, 1));
event.setCancelled(true);
}
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
stack = p.getItemInHand(HandTypes.OFF_HAND).get();
itemInHand = stack.getItem();
if (RPUtil.removeGuiItem(stack)) {
p.setItemInHand(HandTypes.OFF_HAND, ItemStack.of(ItemTypes.NONE, 1));
event.setCancelled(true);
}
}
if (itemInHand.getId().equalsIgnoreCase(RedProtect.get().cfgs.getString("wands.infoWandID"))) {
r = RedProtect.get().rm.getTopRegion(l);
if (RedProtect.get().ph.hasUserPerm(p, "RedProtect.get().infowand")) {
if (r == null) {
RPLang.sendMessage(p, "playerlistener.noregion.atblock");
} else if (r.canBuild(p)) {
p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "--------------- [&e" + r.getName() + RPLang.get("general.color") + "] ---------------"));
p.sendMessage(r.info());
p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
} else {
p.sendMessage(RPUtil.toText(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", RPUtil.UUIDtoPlayer(r.getLeadersDesc()))));
}
event.setCancelled(true);
return;
}
}
// start player checks
if (r == null) {
if (b != null && (bstate instanceof Container || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName()))) {
Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
if (out && !cont.canOpen(b, p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
} else {
int x = b.getLocation().get().getBlockX();
int y = b.getLocation().get().getBlockY();
int z = b.getLocation().get().getBlockZ();
RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", "X:" + x + " Y:" + y + " Z:" + z));
}
}
}
} else {
// if (r != null) && (b != null) >>
if (b != null) {
if (bstate.getType().equals(BlockTypes.DRAGON_EGG) || bstate.getType().equals(BlockTypes.BED) || bstate.getType().equals(BlockTypes.NOTEBLOCK) || bstate.getType().getName().contains("repeater") || bstate.getType().getName().contains("comparator")) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
} else if ((b.getState() instanceof Carrier) || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName())) {
if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (bstate.getType().getName().contains("lever")) {
if (!r.canLever(p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantlever");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.levertoggled").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (bstate.getType().getName().contains("button")) {
if (!r.canButton(p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantbutton");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.buttonactivated").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (RPDoor.isOpenable(b)) {
if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
{
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantdoor");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, "playerlistener.region.opendoor");
RPDoor.ChangeDoor(b, r);
}
} else {
RPDoor.ChangeDoor(b, r);
}
} else if (bstate.getType().getName().contains("rail")) {
if (!r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
event.setCancelled(true);
}
} else if (bstate.getType().getName().contains("sign") && !r.canSign(p)) {
if (b.get(Keys.SIGN_LINES).isPresent()) {
List<Text> sign = b.get(Keys.SIGN_LINES).get();
for (String tag : RedProtect.get().cfgs.getStringList("region-settings.allow-sign-interact-tags")) {
// check first rule
if (tag.equalsIgnoreCase(sign.get(0).toPlain())) {
return;
}
// check if tag is leaders or members names
if (tag.equalsIgnoreCase("{membername}")) {
for (String leader : r.getLeaders()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
return;
}
}
for (String member : r.getMembers()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
return;
}
}
for (String admin : r.getAdmins()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
return;
}
}
}
// check if tag is player name
if (tag.equalsIgnoreCase("{playername}")) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
return;
}
}
}
}
RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
event.setCancelled(true);
} else if ((itemInHand.equals(ItemTypes.FLINT_AND_STEEL) || itemInHand.equals(ItemTypes.WATER_BUCKET) || itemInHand.equals(ItemTypes.BUCKET) || itemInHand.equals(ItemTypes.LAVA_BUCKET) || itemInHand.equals(ItemTypes.ITEM_FRAME) || itemInHand.equals(ItemTypes.PAINTING)) && !r.canBuild(p)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.cantuse"));
event.setCancelled(true);
} else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(bstate)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onInteractRight.
// listen right click
@Listener(order = Order.FIRST)
public void onInteractRight(InteractBlockEvent.Secondary event, @First Player p) {
BlockSnapshot b = event.getTargetBlock();
Location<World> l = null;
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractBlockEvent.Secondary event");
if (!b.getState().getType().equals(BlockTypes.AIR)) {
l = b.getLocation().get();
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractBlockEvent.Secondary event. The block is " + b.getState().getType().getName());
} else {
l = p.getLocation();
}
Region r = RedProtect.get().rm.getTopRegion(l);
ItemType itemInHand = RPUtil.getItemHand(p);
String claimmode = RedProtect.get().cfgs.getWorldClaimType(p.getWorld().getName());
if (itemInHand.getId().equalsIgnoreCase(RedProtect.get().cfgs.getString("wands.adminWandID")) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || RedProtect.get().ph.hasPerm(p, "RedProtect.get().admin.claim"))) {
if (!RPUtil.canBuildNear(p, l)) {
event.setCancelled(true);
return;
}
RedProtect.get().secondLocationSelections.put(p, l);
p.sendMessage(RPUtil.toText(RPLang.get("playerlistener.wand2") + RPLang.get("general.color") + " (&e" + l.getBlockX() + RPLang.get("general.color") + ", &e" + l.getBlockY() + RPLang.get("general.color") + ", &e" + l.getBlockZ() + RPLang.get("general.color") + ")."));
event.setCancelled(true);
// show preview border
if (RedProtect.get().firstLocationSelections.containsKey(p) && RedProtect.get().secondLocationSelections.containsKey(p)) {
Location<World> loc1 = RedProtect.get().firstLocationSelections.get(p);
Location<World> loc2 = RedProtect.get().secondLocationSelections.get(p);
if (loc1.getPosition().distanceSquared(loc2.getPosition()) > RedProtect.get().cfgs.getInt("region-settings.define-max-distance") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.define-max-distance")) {
Double dist = loc1.getPosition().distanceSquared(loc2.getPosition());
RPLang.sendMessage(p, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RedProtect.get().cfgs.getInt("region-settings.define-max-distance"), dist.intValue()));
} else {
RPUtil.addBorder(p, RPUtil.get4Points(loc1, loc2, p.getLocation().getBlockY()));
}
}
return;
}
// other blocks and interactions
if (r != null) {
if ((itemInHand.equals(ItemTypes.ENDER_PEARL) || itemInHand.getName().equals("minecraft:chorus_fruit")) && !r.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setUseItemResult(Tristate.FALSE);
event.setCancelled(true);
} else if ((itemInHand.equals(ItemTypes.BOW) || itemInHand.equals(ItemTypes.SNOWBALL) || itemInHand.equals(ItemTypes.EGG)) && !r.canProtectiles(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setUseItemResult(Tristate.FALSE);
event.setCancelled(true);
} else if (itemInHand.equals(ItemTypes.POTION) && !r.usePotions(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setUseItemResult(Tristate.FALSE);
event.setCancelled(true);
} else if (itemInHand.equals(ItemTypes.MONSTER_EGG) && !r.canInteractPassives(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setUseItemResult(Tristate.FALSE);
event.setCancelled(true);
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RedProtect method onServerStart.
@Listener
public void onServerStart(GameStartedServerEvent event) {
try {
String v = Sponge.getGame().getPlatform().getContainer(Component.API).getVersion().get();
instance = this;
if (v.startsWith("5") || v.startsWith("6")) {
pvhelp = (RPVHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.RPVHelper56").newInstance();
}
if (v.startsWith("7")) {
pvhelp = (RPVHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.RPVHelper7").newInstance();
}
initVars();
OnlineMode = serv.getOnlineMode();
cmdService.register(container, new RPCommands(), Arrays.asList("redprotect", "rp", "regionp", "regp"));
game.getEventManager().registerListeners(container, new RPGlobalListener());
game.getEventManager().registerListeners(container, new RPBlockListener());
game.getEventManager().registerListeners(container, new RPPlayerListener());
game.getEventManager().registerListeners(container, new RPEntityListener());
game.getEventManager().registerListeners(container, new RPWorldListener());
game.getEventManager().registerListeners(container, new RPMine18());
game.getEventManager().registerListeners(container, new RPAddProtection());
loadRegions();
logger.info("Loading API...");
this.rpAPI = new RedProtectAPI();
logger.info("API Loaded!");
logger.clear("&4 _ _ _ &c _ _ _ _ _ _ _ _ _ __");
logger.clear("&4|_| |_ | \\ &c|_| |_| | | | |_ | | / ");
logger.clear("&4| \\ |_ |_/ &c| | \\ |_| | |_ |_ | /");
logger.clear("&a¯ Redprotect " + container.getVersion().get() + " enabled");
logger.clear("");
} catch (Exception e) {
e.printStackTrace();
logger.severe("Error enabling RedProtect, plugin will shut down.");
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerTeleport.
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent e) {
if (e.isCancelled()) {
return;
}
final Player p = e.getPlayer();
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
Location lfrom = e.getFrom();
Location lto = e.getTo();
final Region rfrom = RedProtect.get().rm.getTopRegion(lfrom);
final Region rto = RedProtect.get().rm.getTopRegion(lto);
RedProtect.get().logger.debug("RPPlayerListener - PlayerTeleportEvent from " + lfrom.toString() + " to " + lto.toString());
if (rto != null) {
// Allow teleport to with items
if (!rto.canEnterWithItens(p)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.onlyenter.withitems").replace("{items}", rto.flags.get("allow-enter-items").toString()));
e.setCancelled(true);
return;
}
// Deny teleport to with item
if (!rto.denyEnterWithItens(p)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.denyenter.withitems").replace("{items}", rto.flags.get("deny-enter-items").toString()));
e.setCancelled(true);
return;
}
if (RedProtect.get().PvPm) {
if (rto.isPvPArena() && !PvPlayer.get(p).hasPvPEnabled() && !rto.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.pvpenabled");
e.setCancelled(true);
return;
}
}
if (!rto.canEnter(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantregionenter");
e.setCancelled(true);
return;
}
// enter max players flag
if (rto.maxPlayers() != -1) {
if (!checkMaxPlayer(p, rto)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.maxplayers").replace("{players}", String.valueOf(rto.maxPlayers())));
e.setCancelled(true);
}
}
if (PlayerCmd.containsKey(p.getName())) {
if (!rto.canBack(p) && PlayerCmd.get(p.getName()).startsWith("/back")) {
RPLang.sendMessage(p, "playerlistener.region.cantback");
e.setCancelled(true);
}
if (!rto.AllowHome(p) && PlayerCmd.get(p.getName()).startsWith("/home")) {
RPLang.sendMessage(p, "playerlistener.region.canthome");
e.setCancelled(true);
}
PlayerCmd.remove(p.getName());
}
}
// teleport player to coord/world if playerup 128 y
int NetherY = RPConfig.getInt("netherProtection.maxYsize");
if (lto.getWorld().getEnvironment().equals(World.Environment.NETHER) && NetherY != -1 && lto.getBlockY() >= NetherY && !p.hasPermission("redprotect.bypass.nether-roof")) {
RPLang.sendMessage(p, RPLang.get("playerlistener.upnethery").replace("{location}", NetherY + ""));
e.setCancelled(true);
}
if (e.getCause().equals(PlayerTeleportEvent.TeleportCause.ENDER_PEARL)) {
if (rfrom != null && !rfrom.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantteleportitem");
e.setCancelled(true);
}
if (rto != null && !rto.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantteleportitem");
e.setCancelled(true);
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(RedProtect.get(), () -> {
if (rto != null && rfrom == null) {
RegionFlags(rto, null, p);
}
if (rto != null && rfrom != null) {
RegionFlags(rto, rfrom, p);
}
if (rto == null && rfrom != null) {
noRegionFlags(rfrom, p);
}
if (rfrom == null && rto != null) {
noRegionFlags(rto, p);
}
if (rfrom == null && rto == null) {
// remove all if no regions
List<String> toRemove = new ArrayList<>();
for (String taskId : PlayertaskID.keySet()) {
if (PlayertaskID.get(taskId).equals(p.getName())) {
if (taskId.contains("forcefly")) {
p.setFlying(false);
p.setAllowFlight(false);
} else {
for (PotionEffect pot : p.getActivePotionEffects()) {
p.removePotionEffect(pot.getType());
}
}
toRemove.add(taskId);
stopTaskPlayer(taskId);
}
}
for (String key : toRemove) {
PlayertaskID.remove(key);
}
}
}, 40L);
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerMovement.
@EventHandler
public void onPlayerMovement(PlayerMoveEvent e) {
if (e.isCancelled() || RPConfig.getBool("performance.disable-onPlayerMoveEvent-handler")) {
return;
}
Player p = e.getPlayer();
// test player target
if (RPConfig.getBool("server-protection.check-killaura-freekill.enable")) {
Entity pent = getTarget(p);
int trysp = 0;
int mrate = 0;
if (pent != null && pent instanceof Player && dmgp.containsKey(pent.getName())) {
if (trys.containsKey(p.getName())) {
trysp = trys.get(p.getName());
}
trysp++;
trys.put(p.getName(), trysp);
if (RPConfig.getBool("server-protection.check-killaura-freekill.debug-trys")) {
RedProtect.get().logger.warning("Player: " + p.getName() + " | Try count: " + trysp);
}
if (trysp % RPConfig.getInt("server-protection.check-killaura-freekill.check-rate") == 0) {
RedProtect.get().logger.warning("Player: " + p.getName() + " | Check Rate Match: (" + trysp + ")");
if (matchRate.containsKey(p.getName())) {
mrate = matchRate.get(p.getName());
}
mrate++;
matchRate.put(p.getName(), mrate);
if (mrate == RPConfig.getInt("server-protection.check-killaura-freekill.rate-multiples")) {
RedProtect.get().logger.severe("Player: " + p.getName() + " | MATCH RATE! Possible Hack or FreeKill: (" + mrate + ")");
matchRate.put(p.getName(), 0);
}
}
} else {
trys.remove(p.getName());
matchRate.remove(p.getName());
}
}
Location lfrom = e.getFrom();
Location lto = e.getTo();
// RedProtect.get().logger.debug("RPPlayerListener - PlayerMoveEvent from "+lfrom.toString()+" to "+lto.toString());
if (lto.getWorld().equals(lfrom.getWorld()) && lto.distance(lfrom) > 0.1 && RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
// teleport player to coord/world if playerup 128 y
int NetherY = RPConfig.getInt("netherProtection.maxYsize");
if (lto.getWorld().getEnvironment().equals(World.Environment.NETHER) && NetherY != -1 && lto.getBlockY() >= NetherY && !p.hasPermission("redprotect.bypass.nether-roof")) {
for (String cmd : RPConfig.getStringList("netherProtection.execute-cmd")) {
RedProtect.get().serv.dispatchCommand(RedProtect.get().serv.getConsoleSender(), cmd.replace("{player}", p.getName()));
}
RPLang.sendMessage(p, RPLang.get("playerlistener.upnethery").replace("{location}", NetherY + ""));
}
Region r = RedProtect.get().rm.getTopRegion(lto);
World w = lfrom.getWorld();
if (r != null) {
// Enter flag
if (!r.canEnter(p)) {
e.setTo(RPUtil.DenyEnterPlayer(w, lfrom, e.getTo(), p, r, false));
RPLang.sendMessage(p, "playerlistener.region.cantregionenter");
}
// enter max players flag
if (r.maxPlayers() != -1) {
if (!checkMaxPlayer(p, r)) {
e.setTo(RPUtil.DenyEnterPlayer(w, lfrom, e.getTo(), p, r, false));
RPLang.sendMessage(p, RPLang.get("playerlistener.region.maxplayers").replace("{players}", String.valueOf(r.maxPlayers())));
}
}
// remove pots
if (!r.allowEffects(p)) {
for (PotionEffect pot : p.getActivePotionEffects()) {
if (pot.getDuration() < 36000) {
p.removePotionEffect(pot.getType());
}
}
}
// Mypet Flag
if (RedProtect.get().MyPet && !r.canPet(p)) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(p)) {
MyPetPlayer mpp = MyPetApi.getPlayerManager().getMyPetPlayer(p);
if (mpp.hasMyPet() && mpp.getMyPet().getStatus() == PetState.Here) {
mpp.getMyPet().removePet();
RPLang.sendMessage(p, "playerlistener.region.cantpet");
}
}
}
// Allow enter with items
if (!r.canEnterWithItens(p)) {
e.setTo(RPUtil.DenyEnterPlayer(w, lfrom, e.getTo(), p, r, false));
RPLang.sendMessage(p, RPLang.get("playerlistener.region.onlyenter.withitems").replace("{items}", r.flags.get("allow-enter-items").toString()));
}
// Deny enter with item
if (!r.denyEnterWithItens(p)) {
e.setTo(RPUtil.DenyEnterPlayer(w, lfrom, e.getTo(), p, r, false));
RPLang.sendMessage(p, RPLang.get("playerlistener.region.denyenter.withitems").replace("{items}", r.flags.get("deny-enter-items").toString()));
}
// update region admin or leander visit
if (RPConfig.getString("region-settings.record-player-visit-method").equalsIgnoreCase("ON-REGION-ENTER")) {
if (r.isLeader(p) || r.isAdmin(p)) {
if (r.getDate() == null || (!r.getDate().equals(RPUtil.DateNow()))) {
r.setDate(RPUtil.DateNow());
}
}
}
// Deny Fly
if (!p.getGameMode().toString().equalsIgnoreCase("SPECTATOR") && !r.canFly(p) && p.isFlying()) {
p.setFlying(false);
// p.setAllowFlight(false);
RPLang.sendMessage(p, "playerlistener.region.cantfly");
}
if (Ownerslist.get(p.getName()) != r.getName()) {
Region er = RedProtect.get().rm.getRegion(Ownerslist.get(p.getName()), p.getWorld());
Ownerslist.put(p.getName(), r.getName());
// Execute listener:
EnterExitRegionEvent event = new EnterExitRegionEvent(er, r, p);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// --
RegionFlags(r, er, p);
if (!r.getWelcome().equalsIgnoreCase("hide ")) {
EnterExitNotify(r, p);
}
} else {
RegionFlags(r, null, p);
}
} else {
// if (r == null) >>
if (Ownerslist.get(p.getName()) != null) {
Region er = RedProtect.get().rm.getRegion(Ownerslist.get(p.getName()), p.getWorld());
if (Ownerslist.containsKey(p.getName())) {
Ownerslist.remove(p.getName());
}
// Execute listener:
EnterExitRegionEvent event = new EnterExitRegionEvent(er, null, p);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// ---
if (er == null) {
// remove all if no regions
List<String> toRemove = new ArrayList<>();
for (String taskId : PlayertaskID.keySet()) {
if (PlayertaskID.get(taskId).equals(p.getName())) {
if (taskId.contains("forcefly")) {
p.setFlying(false);
p.setAllowFlight(false);
} else {
for (PotionEffect pot : p.getActivePotionEffects()) {
p.removePotionEffect(pot.getType());
}
}
toRemove.add(taskId);
stopTaskPlayer(taskId);
}
}
for (String key : toRemove) {
PlayertaskID.remove(key);
}
} else {
noRegionFlags(er, p);
if (!er.getWelcome().equalsIgnoreCase("hide ") && RPConfig.getBool("notify.region-exit")) {
if (RedProtect.get().version >= 1110) {
SendNotifyMsg(p, RPLang.get("playerlistener.region.wilderness"), "RED");
} else {
SendNotifyMsg(p, RPLang.get("playerlistener.region.wilderness"), null);
}
}
}
}
}
}
Aggregations