use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onConsume.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onConsume(UseItemStackEvent.Start e, @First Player p) {
ItemStack stack = e.getItemStackInUse().createStack();
RedProtect.get().logger.debug("player", "Is UseItemStackEvent.Start event. Item: " + stack.getItem().getName());
// deny potion
List<String> Pots = RedProtect.get().cfgs.getStringList("server-protection.deny-potions");
if (stack.get(Keys.POTION_EFFECTS).isPresent() && Pots.size() > 0) {
List<PotionEffect> pot = stack.get(Keys.POTION_EFFECTS).get();
for (PotionEffect pots : pot) {
if (Pots.contains(pots.getType().getName().toUpperCase()) && !p.hasPermission("redprotect.bypass")) {
e.setCancelled(true);
RPLang.sendMessage(p, "playerlistener.denypotion");
}
}
}
Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
if (r != null && stack.getItem().equals(ItemTypes.POTION) && !r.usePotions(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setCancelled(true);
}
if (r != null && stack.getItem().getName().equals("minecraft:chorus_fruit") && !r.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setCancelled(true);
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPPlayerListener method DenyEnterPlayer.
private Transform<World> DenyEnterPlayer(World wFrom, Transform<World> from, Transform<World> to, Player p, Region r) {
Location<World> setFrom = from.getLocation();
Location<World> setTo = to.getLocation();
for (int i = 0; i < r.getArea() + 10; i++) {
Region r1 = RedProtect.get().rm.getTopRegion(wFrom, setFrom.getBlockX() + i, setFrom.getBlockY(), setFrom.getBlockZ());
Region r2 = RedProtect.get().rm.getTopRegion(wFrom, setFrom.getBlockX() - i, setFrom.getBlockY(), setFrom.getBlockZ());
Region r3 = RedProtect.get().rm.getTopRegion(wFrom, setFrom.getBlockX(), setFrom.getBlockY(), setFrom.getBlockZ() + i);
Region r4 = RedProtect.get().rm.getTopRegion(wFrom, setFrom.getBlockX(), setFrom.getBlockY(), setFrom.getBlockZ() - i);
Region r5 = RedProtect.get().rm.getTopRegion(wFrom, setFrom.getBlockX() + i, setFrom.getBlockY(), setFrom.getBlockZ() + i);
Region r6 = RedProtect.get().rm.getTopRegion(wFrom, setFrom.getBlockX() - i, setFrom.getBlockY(), setFrom.getBlockZ() - i);
if (r1 != r) {
setTo = setFrom.add(+i, 0, 0);
break;
}
if (r2 != r) {
setTo = setFrom.add(-i, 0, 0);
break;
}
if (r3 != r) {
setTo = setFrom.add(0, 0, +i);
break;
}
if (r4 != r) {
setTo = setFrom.add(0, 0, -i);
break;
}
if (r5 != r) {
setTo = setFrom.add(+i, 0, +i);
break;
}
if (r6 != r) {
setTo = setFrom.add(-i, 0, -i);
break;
}
}
return new Transform<>(setTo).setRotation(to.getRotation());
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
/*
@Listener(order = Order.FIRST, beforeModifications = true)
public void MoveItem(ClickInventoryEvent e, @First Player p){
Container cont = e.getTargetInventory().getProperties(Names.);
Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
if (r != null && e.getInventory().getTitle() != null){
if (r.getName().length() > 16){
if (e.getInventory().getTitle().equals(RPLang.get("gui.invflag").replace("{region}", r.getName().substring(0, 16)))){
return;
}
} else {
if (e.getInventory().getTitle().equals(RPLang.get("gui.invflag").replace("{region}", r.getName())) || e.getInventory().getTitle().equals(RPLang.get("gui.editflag"))){
return;
}
}
}
if (RPUtil.RemoveGuiItem(e.getCurrentItem())){
e.setCurrentItem(new ItemStack(Material.AIR));
}
}
*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @First Player p) {
Entity ent = e.getTargetEntity();
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractEntityEvent event: " + ent.getType().getName());
Location<World> l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null) {
return;
}
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
if (ent instanceof Hanging || ent.getType().equals(EntityTypes.ARMOR_STAND)) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
e.setCancelled(true);
}
} else if ((ent.getType().getName().contains("minecart") || ent.getType().getName().contains("boat")) && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantenter");
e.setCancelled(true);
} else if (!r.allowMod(p) && !RPUtil.isBukkitEntity(ent) && (!(ent instanceof Player))) {
RedProtect.get().logger.debug("player", "PlayerInteractEntityEvent - Block is " + ent.getType().getName());
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
e.setCancelled(true);
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region 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.Region in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockPlace.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @First Player p) {
RedProtect.get().logger.debug("blocks", "BlockListener - Is BlockPlaceEvent event! Cancelled? " + e.isCancelled());
BlockSnapshot b = e.getTransactions().get(0).getOriginal();
Location<World> bloc = b.getLocation().get();
World w = bloc.getExtent();
ItemType m = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
m = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
m = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
Boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
if (r == null && RedProtect.get().cfgs.getGlobalFlagList(w.getName(), "if-build-false", "place-blocks").contains(b.getState().getType().getName())) {
return;
}
if (r != null) {
if (!r.canMinecart(p) && m.getName().contains("minecart")) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
e.setCancelled(true);
return;
}
if (b.getState().getType().equals(BlockTypes.MOB_SPAWNER) && r.allowSpawner(p)) {
return;
}
try {
if (!r.canBuild(p) && !r.canPlace(b)) {
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
e.setCancelled(true);
} else {
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && (m.equals(ItemTypes.HOPPER) || m.getName().contains("rail"))) {
int x = bloc.getBlockX();
int y = bloc.getBlockY();
int z = bloc.getBlockZ();
BlockSnapshot ib = w.createSnapshot(x, y + 1, z);
if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) {
RPLang.sendMessage(p, "blocklistener.container.chestinside");
e.setCancelled(true);
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
Aggregations