Search in sources :

Example 1 with PetCore

use of simplepets.brainsynder.PetCore in project SimplePets by brainsynder-Dev.

the class ItemLoaders method initiate.

public void initiate() {
    PetCore core = PetCore.get();
    PetCore.get().debug("Initializing Menu Items...");
    if (items != null)
        if (!items.isEmpty())
            items.clear();
    PetCore.get().debug("Loading Customizable Item Files...");
    File customFolder = new File(core.getDataFolder().toString() + "/Items/Custom/");
    if (!customFolder.exists())
        customFolder.mkdirs();
    List<File> files = Arrays.asList(customFolder.listFiles());
    add(new Air(Item.getLocation(core, Air.class)));
    add(new Hat(Item.getLocation(core, Hat.class)));
    add(new Name(Item.getLocation(core, Name.class)));
    add(new NextPage(Item.getLocation(core, NextPage.class)));
    add(new PreviousPage(Item.getLocation(core, PreviousPage.class)));
    add(new Remove(Item.getLocation(core, Remove.class)));
    add(new Ride(Item.getLocation(core, Ride.class)));
    add(new Storage(Item.getLocation(core, Storage.class)));
    add(new Placeholder(Item.getLocation(core, Placeholder.class)));
    add(new Data(Item.getLocation(core, Data.class)));
    add(new SavePet(Item.getLocation(core, SavePet.class)));
    add(new Saves(Item.getLocation(core, Saves.class)));
    add(new RedPlaceholder(Item.getLocation(core, RedPlaceholder.class)));
    add(new Update(Item.getLocation(core, Update.class)));
    add(new FlameOn(new File(customFolder, "flameon.json")));
    for (Item loader : items.values()) {
        loader.save();
    }
    PetCore.get().debug("Files have been loaded.");
    if (!files.isEmpty()) {
        for (File file : files) {
            if (!file.getName().endsWith(".json"))
                continue;
            Item item = new Item(file);
            if (item.hasKey("namespace") && item.isEnabled()) {
                items.putIfAbsent(item.namespace(), item);
            }
        }
    }
    AIR = getLoader(Air.class);
    PLACEHOLDER = getLoader(Placeholder.class);
    RED_PLACEHOLDER = getLoader(RedPlaceholder.class);
    DATA = getLoader(Data.class);
}
Also used : PetCore(simplepets.brainsynder.PetCore) File(java.io.File)

Example 2 with PetCore

use of simplepets.brainsynder.PetCore in project SimplePets by brainsynder-Dev.

the class OnPetSpawn method onCreatureSpawnUnBlock.

@EventHandler(priority = EventPriority.HIGHEST)
public void onCreatureSpawnUnBlock(CreatureSpawnEvent event) {
    Entity e = event.getEntity();
    PetCore core = PetCore.get();
    if (ReflectionUtil.getEntityHandle(e) instanceof IImpossaPet && event.isCancelled()) {
        if (core.getConfiguration().getBoolean("Complete-Mobspawning-Deny-Bypass") || core.getLinkRetriever().getProtectionLink(IWorldGuardLink.class).allowPetSpawn(event.getLocation()) || core.getLinkRetriever().getProtectionLink(IPlotSquaredLink.class).allowPetSpawn(event.getLocation()) || core.getLinkRetriever().getProtectionLink(IWorldBorderLink.class).allowPetSpawn(event.getLocation())) {
            event.setCancelled(false);
        }
    }
}
Also used : PetCore(simplepets.brainsynder.PetCore) Entity(org.bukkit.entity.Entity) IImpossaPet(simplepets.brainsynder.api.entity.misc.IImpossaPet) IPlotSquaredLink(simplepets.brainsynder.links.IPlotSquaredLink) EventHandler(org.bukkit.event.EventHandler)

Example 3 with PetCore

use of simplepets.brainsynder.PetCore in project SimplePets by brainsynder-Dev.

the class OnPetSpawn method onMove.

@EventHandler
public void onMove(PetMoveEvent e) {
    try {
        if (e.getEntity() == null)
            return;
        if (e.getEntity().getPet() != null && e.getEntity().getOwner() != null) {
            IEntityPet entity = e.getEntity();
            PetOwner petOwner = PetOwner.getPetOwner(entity.getOwner());
            PetCore core = PetCore.get();
            if (e.getCause() == PetMoveEvent.Cause.RIDE) {
                if (!core.getLinkRetriever().canRidePet(petOwner, entity.getEntity().getLocation())) {
                    petOwner.getPet().setVehicle(false, false);
                    entity.getOwner().sendMessage(PetCore.get().getMessages().getString("Pet-No-Enter", true));
                }
                return;
            }
            if (!core.getLinkRetriever().canPetEnter(petOwner, entity.getEntity().getLocation())) {
                petOwner.removePet();
                entity.getOwner().sendMessage(PetCore.get().getMessages().getString("Pet-No-Enter", true));
            }
        }
    } catch (Exception ignored) {
    }
}
Also used : PetCore(simplepets.brainsynder.PetCore) PetOwner(simplepets.brainsynder.player.PetOwner) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EventHandler(org.bukkit.event.EventHandler)

Example 4 with PetCore

use of simplepets.brainsynder.PetCore in project SimplePets by brainsynder-Dev.

the class OnPetSpawn method onCreatureSpawnUnBlock.

@EventHandler(priority = EventPriority.HIGHEST)
public void onCreatureSpawnUnBlock(EntitySpawnEvent event) {
    Entity e = event.getEntity();
    PetCore core = PetCore.get();
    if (ReflectionUtil.getEntityHandle(e) instanceof IImpossaPet && event.isCancelled()) {
        if (core.getConfiguration().getBoolean("Complete-Mobspawning-Deny-Bypass") || core.getLinkRetriever().getProtectionLink(IWorldGuardLink.class).allowPetSpawn(event.getLocation()) || core.getLinkRetriever().getProtectionLink(IPlotSquaredLink.class).allowPetSpawn(event.getLocation()) || core.getLinkRetriever().getProtectionLink(IWorldBorderLink.class).allowPetSpawn(event.getLocation())) {
            event.setCancelled(false);
        }
    }
}
Also used : PetCore(simplepets.brainsynder.PetCore) Entity(org.bukkit.entity.Entity) IImpossaPet(simplepets.brainsynder.api.entity.misc.IImpossaPet) IPlotSquaredLink(simplepets.brainsynder.links.IPlotSquaredLink) EventHandler(org.bukkit.event.EventHandler)

Example 5 with PetCore

use of simplepets.brainsynder.PetCore in project SimplePets by brainsynder-Dev.

the class InvLoaders method initiate.

public void initiate() {
    PetCore core = PetCore.get();
    PetCore.get().debug("Initializing Inventories...");
    if (loaders != null)
        if (!loaders.isEmpty())
            loaders.clear();
    PetCore.get().debug("Loading Customizable Inventories Files...");
    loaders.add(new SelectionMenu(CustomInventory.getLocation(core, SelectionMenu.class)));
    loaders.add(new DataMenu(CustomInventory.getLocation(core, DataMenu.class)));
    loaders.add(new SavesMenu(CustomInventory.getLocation(core, SavesMenu.class)));
    loaders.add(new ArmorMenu(CustomInventory.getLocation(core, ArmorMenu.class)));
    for (CustomInventory loader : loaders) {
        loader.save();
        loader.load();
    }
    PetCore.get().debug("Files have been loaded.");
    SELECTION = getLoader(SelectionMenu.class);
    PET_DATA = getLoader(DataMenu.class);
    SAVES = getLoader(SavesMenu.class);
    ARMOR = getLoader(ArmorMenu.class);
}
Also used : PetCore(simplepets.brainsynder.PetCore) DataMenu(simplepets.brainsynder.menu.inventory.list.DataMenu) SavesMenu(simplepets.brainsynder.menu.inventory.list.SavesMenu) SelectionMenu(simplepets.brainsynder.menu.inventory.list.SelectionMenu) ArmorMenu(simplepets.brainsynder.menu.inventory.list.ArmorMenu)

Aggregations

PetCore (simplepets.brainsynder.PetCore)8 File (java.io.File)3 EventHandler (org.bukkit.event.EventHandler)3 Entity (org.bukkit.entity.Entity)2 IImpossaPet (simplepets.brainsynder.api.entity.misc.IImpossaPet)2 IPlotSquaredLink (simplepets.brainsynder.links.IPlotSquaredLink)2 IEntityPet (simplepets.brainsynder.api.entity.IEntityPet)1 ArmorMenu (simplepets.brainsynder.menu.inventory.list.ArmorMenu)1 DataMenu (simplepets.brainsynder.menu.inventory.list.DataMenu)1 SavesMenu (simplepets.brainsynder.menu.inventory.list.SavesMenu)1 SelectionMenu (simplepets.brainsynder.menu.inventory.list.SelectionMenu)1 MenuItem (simplepets.brainsynder.menu.menuItems.base.MenuItem)1 PetOwner (simplepets.brainsynder.player.PetOwner)1