Search in sources :

Example 1 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockBreak.

@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
    RedProtect.get().logger.debug("RPGlobalListener - Is BlockBreakEvent event! Cancelled? " + e.isCancelled());
    if (e.isCancelled()) {
        return;
    }
    Block b = e.getBlock();
    Player p = e.getPlayer();
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, b.getLocation())) {
        e.setCancelled(true);
        return;
    }
    if (!bypassBuild(p, b, 2)) {
        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 2 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener 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 3 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockPlace.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
    RedProtect.get().logger.debug("default", "RPGlobalListener - Is ChangeBlockEvent event! Cancelled? " + e.isCancelled());
    BlockSnapshot b = e.getTransactions().get(0).getFinal();
    ItemType item = ItemTypes.NONE;
    if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        item = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
    } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
        item = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
    }
    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, b.getLocation().get())) {
        e.setCancelled(true);
        return;
    }
    if (item.getName().contains("minecart") || item.getName().contains("boat")) {
        if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("default", "RPGlobalListener - Can't place minecart/boat!");
        }
    } else {
        if (!bypassBuild(p, b, 1)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("default", "RPGlobalListener - Can't Build!");
        }
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 4 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockPlace.

@EventHandler(priority = EventPriority.LOWEST)
public void onBlockPlace(BlockPlaceEvent e) {
    RedProtect.get().logger.debug("RPGlobalListener - Is BlockPlaceEvent event! Cancelled? " + e.isCancelled());
    if (e.isCancelled() || e.getItemInHand() == null) {
        return;
    }
    Block b = e.getBlock();
    Player p = e.getPlayer();
    Material item = e.getItemInHand().getType();
    Region r = RedProtect.get().rm.getTopRegion(e.getBlock().getLocation());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, b.getLocation())) {
        e.setCancelled(true);
        return;
    }
    if (item.name().contains("MINECART") || item.name().contains("BOAT")) {
        if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("RPGlobalListener - Can't place minecart/boat!");
        }
    } else {
        if (!bypassBuild(p, b, 1)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("RPGlobalListener - Can't Build!");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Material(org.bukkit.Material) EventHandler(org.bukkit.event.EventHandler)

Example 5 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method MonsterBlockBreak.

@EventHandler
public void MonsterBlockBreak(EntityChangeBlockEvent event) {
    Entity e = event.getEntity();
    Block b = event.getBlock();
    Region r = RedProtect.get().rm.getTopRegion(event.getBlock().getLocation());
    if (r != null) {
        return;
    }
    if (b != null) {
        RedProtect.get().logger.debug("RPGlobalListener - Is EntityChangeBlockEvent event. Block: " + b.getType().name());
    }
    if (e instanceof Monster) {
        if (!RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".entity-block-damage")) {
            event.setCancelled(true);
        }
    }
    if (e instanceof Player) {
        Player p = (Player) e;
        if (!bypassBuild(p, b, 2)) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Monster(org.bukkit.entity.Monster) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)7 EventHandler (org.bukkit.event.EventHandler)7 Block (org.bukkit.block.Block)5 Player (org.bukkit.entity.Player)5 Listener (org.spongepowered.api.event.Listener)5 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)4 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)3 World (org.spongepowered.api.world.World)3 Location (org.bukkit.Location)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Monster (org.bukkit.entity.Monster)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