use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RPMine19 method onPlayerInteract.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
Block b = event.getClickedBlock();
ItemStack itemInHand = event.getItem();
Location l = null;
if (b != null) {
l = b.getLocation();
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
} else {
l = p.getLocation();
}
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
Material hand = itemInHand.getType();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && hand.equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RedProtect method onEnable.
public void onEnable() {
try {
plugin = this;
BossBar = checkBM();
MyChunk = checkMyChunk();
MyPet = checkMyPet();
McMMo = checkMcMMo();
Mc = checkMc();
Vault = checkVault();
SkillAPI = checkSkillAPI();
PvPm = checkPvPm();
Ess = checkEss();
GP = checkGP();
Dyn = checkDyn();
WE = checkWe();
AWE = checkAWe();
SC = checkSP();
Fac = checkFac();
PLib = checkPLib();
PlaceHolderAPI = checkPHAPI();
JarFile = this.getFile();
initVars();
RPConfig.init();
RPLang.init();
rm.loadAll();
OnlineMode = serv.getOnlineMode();
serv.getPluginManager().registerEvents(new RPGlobalListener(), this);
serv.getPluginManager().registerEvents(new RPBlockListener(), this);
serv.getPluginManager().registerEvents(new RPPlayerListener(), this);
serv.getPluginManager().registerEvents(new RPEntityListener(), this);
serv.getPluginManager().registerEvents(new RPWorldListener(), this);
serv.getPluginManager().registerEvents(new RPAddProtection(), this);
version = getBukkitVersion();
logger.debug("Version String: " + version);
if (version >= 180) {
serv.getPluginManager().registerEvents(new RPMine18(), this);
}
if (version >= 190) {
serv.getPluginManager().registerEvents(new RPMine19(), this);
}
getCommand("RedProtect").setExecutor(new RPCommands());
if (Vault) {
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
logger.warning("Vault found, but for some reason cant be used with RedProtect.");
Vault = false;
} else {
econ = rsp.getProvider();
logger.info("Vault found. Hooked.");
}
}
if (PLib) {
logger.info("ProtocolLib found. Hidding Gui Flag item stats.");
}
if (PvPm) {
logger.info("PvPManager found. Hooked.");
}
if (Ess) {
pless = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
logger.info("Essentials found. Hooked.");
}
if (WE) {
logger.info("WorldEdit found. Hooked.");
}
if (AWE) {
logger.info("AsyncWorldEdit found. Hooked.");
}
if (BossBar) {
logger.info("BossbarAPI found. Hooked.");
}
if (MyPet) {
serv.getPluginManager().registerEvents(new MPListener(), this);
logger.info("MyPet found. Hooked.");
}
if (McMMo) {
serv.getPluginManager().registerEvents(new McMMoListener(), this);
logger.info("McMMo found. Hooked.");
}
if (SkillAPI) {
serv.getPluginManager().registerEvents(new SkillAPIListener(), this);
logger.info("SkillAPI found. Hooked.");
}
if (MyChunk) {
logger.sucess("MyChunk found. Ready to convert!");
logger.warning("Use '/rp mychunkconvert' to start MyChunk conversion (This may cause lag during conversion)");
}
if (Mc) {
logger.info("MagicCarpet found. Hooked.");
}
if (SC) {
clanManager = SimpleClans.getInstance().getClanManager();
logger.info("SimpleClans found. Hooked.");
}
if (Dyn && RPConfig.getBool("hooks.dynmap.enable")) {
logger.info("Dynmap found. Hooked.");
logger.info("Loading dynmap markers...");
dynmap = new RPDynmap((DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"));
logger.info("Dynmap markers loaded!");
}
if (PlaceHolderAPI) {
new RPPlaceHoldersAPI(this).hook();
logger.info("PlaceHolderAPI found. Hooked and registered some chat placeholders.");
}
if (Fac) {
serv.getPluginManager().registerEvents(new RPFactions(), this);
logger.info("Factions found. Hooked.");
}
if (!RPConfig.getString("file-type").equalsIgnoreCase("mysql")) {
RPUtil.ReadAllDB(rm.getAllRegions());
} else {
logger.info("Theres " + rm.getTotalRegionsNum() + " regions on (" + RPConfig.getString("file-type") + ") database!");
}
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¯ " + pdf.getFullName() + " enabled");
logger.clear("");
if (RPConfig.getBool("update-check.enable")) {
logger.info("Checking for update...");
if (CheckUpdate()) {
logger.sucess("Update available! Use /rp update to download.");
} else {
logger.info("No update available.");
}
}
if (RPConfig.getString("file-type").equals("yml")) {
AutoSaveHandler();
}
} catch (Exception e) {
e.printStackTrace();
if (!RPConfig.getString("file-type").equalsIgnoreCase("mysql")) {
logger.severe("Error enabling RedProtect, plugin will shut down.");
this.disable();
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
Entity e = event.getRightClicked();
Player p = event.getPlayer();
if (e == null) {
return;
}
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEntityEvent event: " + e.getType().name());
Location l = e.getLocation();
if (e instanceof ItemFrame || e instanceof Painting) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
event.setCancelled(true);
}
} else if ((e instanceof Minecart || e instanceof Boat)) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantenter");
event.setCancelled(true);
}
} else if (RedProtect.get().MyPet && e instanceof MyPetBukkitEntity) {
if (((MyPetBukkitEntity) e).getOwner().getPlayer().equals(p)) {
}
} else if (!RPUtil.isBukkitEntity(e) && (!(event.getRightClicked() instanceof Player))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.allowMod(p)) {
RedProtect.get().logger.debug("PlayerInteractEntityEvent - Block is " + event.getRightClicked().getType().name());
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 onPlayerInteract.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
RedProtect.get().logger.debug("RPPlayerListener - PlayerInteractEvent canceled? " + event.isCancelled());
final Player p = event.getPlayer();
Block b = event.getClickedBlock();
ItemStack itemInHand = event.getItem();
Location l;
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
if (b != null) {
l = b.getLocation();
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
} else {
l = p.getLocation();
}
if (itemInHand != null && !itemInHand.getType().equals(Material.AIR)) {
String claimmode = RPConfig.getWorldClaimType(p.getWorld().getName());
if (itemInHand.getType().name().equalsIgnoreCase(RPConfig.getString("wands.adminWandID")) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || p.hasPermission("redprotect.admin.claim"))) {
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
if (!RPUtil.canBuildNear(p, l)) {
event.setCancelled(true);
return;
}
RedProtect.get().secondLocationSelections.put(p, l);
p.sendMessage(RPLang.get("playerlistener.wand2") + RPLang.get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RPLang.get("general.color") + ").");
event.setCancelled(true);
} else if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) {
if (!RPUtil.canBuildNear(p, l)) {
event.setCancelled(true);
return;
}
RedProtect.get().firstLocationSelections.put(p, l);
p.sendMessage(RPLang.get("playerlistener.wand1") + RPLang.get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RPLang.get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RPLang.get("general.color") + ").");
event.setCancelled(true);
}
// show preview border
if (RedProtect.get().firstLocationSelections.containsKey(p) && RedProtect.get().secondLocationSelections.containsKey(p)) {
Location loc1 = RedProtect.get().firstLocationSelections.get(p);
Location loc2 = RedProtect.get().secondLocationSelections.get(p);
if (loc1.getWorld().equals(loc2.getWorld()) && loc1.distanceSquared(loc2) > RPConfig.getInt("region-settings.define-max-distance") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.define-max-distance")) {
Double dist = loc1.distanceSquared(loc2);
RPLang.sendMessage(p, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RPConfig.getInt("region-settings.define-max-distance"), dist.intValue()));
} else {
RPUtil.addBorder(p, RPUtil.get4Points(loc1, loc2, p.getLocation().getBlockY()));
}
}
return;
}
if (itemInHand.getType().name().equalsIgnoreCase(RPConfig.getString("wands.infoWandID"))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (p.hasPermission("redprotect.infowand")) {
if (r == null) {
RPLang.sendMessage(p, "playerlistener.noregion.atblock");
} else if (r.canBuild(p)) {
p.sendMessage(RPLang.get("general.color") + "--------------- [" + ChatColor.GOLD + r.getName() + RPLang.get("general.color") + "] ---------------");
p.sendMessage(r.info());
p.sendMessage(RPLang.get("general.color") + "-----------------------------------------");
} else {
p.sendMessage(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", r.getLeadersDesc()));
}
event.setCancelled(true);
return;
}
}
}
if (event.isCancelled()) {
return;
}
Region r = RedProtect.get().rm.getTopRegion(l);
// start player checks
if (r == null) {
if (b != null && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RPConfig.getStringList("private.allowed-blocks").contains(b.getType().name()))) {
Boolean out = RPConfig.getBool("private.allow-outside");
if (out && !cont.canOpen(b, p)) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
}
}
} else {
// other blocks and interactions
if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
Material hand = itemInHand.getType();
if (hand.equals(Material.ENDER_PEARL) && !r.canTeleport(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
} else if ((hand.equals(Material.BOW) || (hand.name().contains("SNOW") && hand.name().contains("BALL")) || hand.name().contains("FIREWORK") || hand.equals(Material.EGG)) && !r.canProtectiles(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
} else if (hand.equals(Material.POTION) && !r.usePotions(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
} else if (hand.name().contains("_EGG") && !r.canInteractPassives(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
}
}
// if (r != null) && (b != null) >>
if (b != null) {
if (b.getType().equals(Material.DRAGON_EGG) || b.getType().name().equalsIgnoreCase("BED") || b.getType().name().contains("NOTE_BLOCK") || b.getType().name().contains("CAKE")) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
} else if (b.getState() instanceof Sign && RPConfig.getBool("region-settings.enable-flag-sign")) {
Sign s = (Sign) b.getState();
String[] lines = s.getLines();
if (lines[0].equalsIgnoreCase("[flag]") && r.flags.containsKey(lines[1])) {
String flag = lines[1];
if (!(r.flags.get(flag) instanceof Boolean)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.sign.cantflag"));
return;
}
if (RedProtect.get().ph.hasPerm(p, "redprotect.flag." + flag)) {
if (r.isAdmin(p) || r.isLeader(p) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.flag." + flag)) {
if (RPConfig.getBool("flags-configuration.change-flag-delay.enable")) {
if (RPConfig.getStringList("flags-configuration.change-flag-delay.flags").contains(flag)) {
if (!RedProtect.get().changeWait.contains(r.getName() + flag)) {
RPUtil.startFlagChanger(r.getName(), flag, p);
changeFlag(r, flag, p, s);
return;
} else {
RPLang.sendMessage(p, RPLang.get("gui.needwait.tochange").replace("{seconds}", RPConfig.getString("flags-configuration.change-flag-delay.seconds")));
return;
}
}
}
changeFlag(r, flag, p, s);
return;
}
}
RPLang.sendMessage(p, "cmdmanager.region.flag.nopermregion");
}
} else if (b.getType().equals(Material.ENDER_CHEST)) {
if (!r.canEnderChest(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
}
} else if (!b.getType().equals(Material.ENDER_CHEST) && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RPConfig.getStringList("private.allowed-blocks").contains(b.getType().name()))) {
if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
}
} else if (b.getType().name().contains("LEVER") || (b.getType().name().contains("REDSTONE") && !b.getType().equals(Material.REDSTONE_ORE))) {
if (!r.canLever(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantlever");
event.setCancelled(true);
}
} else if (b.getType().name().contains("BUTTON")) {
if (!r.canButton(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantbutton");
event.setCancelled(true);
}
} else if (RPDoor.isOpenable(b) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
{
RPLang.sendMessage(p, "playerlistener.region.cantdoor");
event.setCancelled(true);
} else {
RPDoor.ChangeDoor(b, r);
}
} else if (itemInHand != null && (itemInHand.getType().name().startsWith("BOAT") || itemInHand.getType().name().contains("MINECART"))) {
if (!r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
event.setUseItemInHand(Event.Result.DENY);
event.setCancelled(true);
}
} else if ((event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && b.getType().name().contains("SIGN") && !r.canSign(p)) {
Sign sign = (Sign) b.getState();
for (String tag : RPConfig.getStringList("region-settings.allow-sign-interact-tags")) {
// check first rule
if (sign != null && tag.equalsIgnoreCase(sign.getLine(0))) {
return;
}
// check if tag is owners or members names
if (tag.equalsIgnoreCase("{membername}")) {
for (String leader : r.getLeaders()) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
return;
}
}
for (String admin : r.getAdmins()) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
return;
}
}
for (String member : r.getMembers()) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
return;
}
}
}
// check if tag is player name
if (tag.equalsIgnoreCase("{playername}")) {
if (sign.getLine(0).equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
return;
}
}
}
RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
event.setUseItemInHand(Event.Result.DENY);
event.setCancelled(true);
} else if ((itemInHand != null && !itemInHand.getType().equals(Material.AIR)) && !r.canBuild(p) && !r.canPlace(itemInHand.getType()) && (itemInHand.getType().equals(Material.FLINT_AND_STEEL) || itemInHand.getType().equals(Material.WATER_BUCKET) || itemInHand.getType().equals(Material.BUCKET) || itemInHand.getType().equals(Material.LAVA_BUCKET) || itemInHand.getType().equals(Material.ITEM_FRAME) || itemInHand.getType().equals(Material.PAINTING))) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
event.setUseInteractedBlock(Event.Result.DENY);
} else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(b)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY);
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener 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);
}
}
Aggregations