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