Search in sources :

Example 1 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener 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();
        }
    }
}
Also used : RPPlayerListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPPlayerListener) RPWorldListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPWorldListener) DynmapAPI(org.dynmap.DynmapAPI) RPGlobalListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener) RPAddProtection(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPAddProtection) MPListener(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener) RPMine19(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPMine19) RPMine18(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPMine18) SkillAPIListener(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.SkillAPIListener) RPFactions(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPFactions) RPBlockListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener) McMMoListener(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.McMMoListener) Economy(net.milkbowl.vault.economy.Economy) RPEntityListener(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPEntityListener) RedProtectAPI(br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI) RPPlaceHoldersAPI(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPPlaceHoldersAPI) RPDynmap(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPDynmap) RPCommands(br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPCommands)

Example 2 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onFireSpread.

@EventHandler
public void onFireSpread(BlockSpreadEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockSpreadEvent event");
    if (e.isCancelled()) {
        return;
    }
    Block bfrom = e.getSource();
    Block bto = e.getBlock();
    RedProtect.get().logger.debug("Is BlockSpreadEvent event, source is " + bfrom.getType().name());
    Region rfrom = RedProtect.get().rm.getTopRegion(bfrom.getLocation());
    Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation());
    if ((bfrom.getType().equals(Material.FIRE) || bfrom.getType().name().contains("LAVA")) && rfrom != null && !rfrom.canFire()) {
        e.setCancelled(true);
        return;
    }
    // deny blocks spread in/out regions
    if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
        e.setCancelled(true);
        return;
    }
    if (rfrom == null && rto != null) {
        e.setCancelled(true);
        return;
    }
    if (rfrom != null && rto == null) {
        e.setCancelled(true);
    }
}
Also used : Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 3 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onBlockStartBurn.

@EventHandler
public void onBlockStartBurn(BlockIgniteEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockIgniteEvent event");
    if (e.isCancelled()) {
        return;
    }
    Block b = e.getBlock();
    Block bignit = e.getIgnitingBlock();
    if (b == null) {
        return;
    }
    RedProtect.get().logger.debug("Is BlockIgniteEvent event. Canceled? " + e.isCancelled());
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null && !r.canFire()) {
        if (e.getIgnitingEntity() != null) {
            if (e.getIgnitingEntity() instanceof Player) {
                Player p = (Player) e.getIgnitingEntity();
                if (!r.canBuild(p)) {
                    RPLang.sendMessage(p, "blocklistener.region.cantplace");
                    e.setCancelled(true);
                    return;
                }
            } else {
                e.setCancelled(true);
                return;
            }
        }
        if (bignit != null && (bignit.getType().equals(Material.FIRE) || bignit.getType().name().contains("LAVA"))) {
            e.setCancelled(true);
            return;
        }
        if (e.getCause().equals(IgniteCause.LIGHTNING) || e.getCause().equals(IgniteCause.EXPLOSION) || e.getCause().equals(IgniteCause.FIREBALL)) {
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 4 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onPistonExtend.

@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockPistonExtendEvent event");
    if (RPConfig.getBool("performance.disable-PistonEvent-handler")) {
        return;
    }
    // delay piston
    if (RPConfig.getBool("performance.piston.use-piston-restricter")) {
        if (pistonExtendDelay.contains(e.getBlock().getLocation().toString())) {
            e.setCancelled(true);
            return;
        } else {
            delayExtendPiston(e.getBlock().getLocation().toString());
        }
    }
    Block piston = e.getBlock();
    List<Block> blocks = e.getBlocks();
    Region pr = RedProtect.get().rm.getTopRegion(piston.getLocation());
    Boolean antih = RPConfig.getBool("region-settings.anti-hopper");
    World w = e.getBlock().getWorld();
    for (Block b : blocks) {
        RedProtect.get().logger.debug("BlockPistonExtendEvent event - Block: " + b.getType().name());
        RedProtect.get().logger.debug("BlockPistonExtendEvent event - Relative: " + b.getRelative(e.getDirection()).getType().name());
        Region br = RedProtect.get().rm.getTopRegion(b.getRelative(e.getDirection()).getLocation());
        if (pr == null && br != null || (pr != null && br != null && pr != br && !pr.sameLeaders(br))) {
            e.setCancelled(true);
            return;
        }
        if (antih) {
            int x = b.getX();
            int y = b.getY();
            int z = b.getZ();
            Block ib = w.getBlockAt(x, y + 1, z);
            if (!cont.canWorldBreak(ib) || !cont.canWorldBreak(b)) {
                e.setCancelled(true);
                return;
            }
        }
    }
}
Also used : Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Example 5 with RPBlockListener

use of br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onInteractBlock.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l = null;
    RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent event");
    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null) {
        ItemType itemInHand = ItemTypes.NONE;
        if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
            itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
        } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
            itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
        }
        if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) {
            RPLang.sendMessage(p, "blocklistener.region.cantbuild");
            event.setCancelled(true);
        }
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)13 EventHandler (org.bukkit.event.EventHandler)13 Block (org.bukkit.block.Block)7 Listener (org.spongepowered.api.event.Listener)3 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)2 World (org.bukkit.World)2 BlockState (org.bukkit.block.BlockState)2 Player (org.bukkit.entity.Player)2 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)2 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI)1 MPListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener)1 McMMoListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.McMMoListener)1 RPDynmap (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPDynmap)1 RPFactions (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPFactions)1 RPPlaceHoldersAPI (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPPlaceHoldersAPI)1 SkillAPIListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.SkillAPIListener)1 RPAddProtection (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPAddProtection)1 RPBlockListener (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPBlockListener)1 RPCommands (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPCommands)1 RPEntityListener (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPEntityListener)1