use of br.net.fabiozumbi12.RedProtect.Bukkit.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();
}
}
}
use of br.net.fabiozumbi12.RedProtect.Bukkit.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);
}
}
use of br.net.fabiozumbi12.RedProtect.Bukkit.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);
}
}
}
use of br.net.fabiozumbi12.RedProtect.Bukkit.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;
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Bukkit.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);
}
}
}
Aggregations