Search in sources :

Example 1 with BlockPropertiesSetup

use of fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup in project NoCheatPlus by NoCheatPlus.

the class VanillaBlocksFactory method setupVanillaBlocks.

public Collection<String> setupVanillaBlocks(final WorldConfigProvider<?> worldConfigProvider) {
    // Vanilla blocks (abort with first failure, low to high MC version).
    final List<BlockPropertiesSetup> setups = new LinkedList<BlockPropertiesSetup>();
    final List<String> success = new LinkedList<String>();
    try {
        setups.add(new BlocksMC1_5());
        setups.add(new BlocksMC1_6_1());
        setups.add(new BlocksMC1_7_2());
        setups.add(new BlocksMC1_8());
        setups.add(new BlocksMC1_9());
        setups.add(new BlocksMC1_10());
        setups.add(new BlocksMC1_11());
        setups.add(new BlocksMC1_12());
    } catch (Throwable t) {
    }
    for (final BlockPropertiesSetup setup : setups) {
        try {
            // Assume the blocks setup to message success.
            setup.setupBlockProperties(worldConfigProvider);
            success.add(setup.getClass().getSimpleName());
        // TODO: Do logging from here ?
        } catch (Throwable t) {
            StaticLog.logSevere(setup.getClass().getSimpleName() + ".setupBlockProperties could not execute properly: " + t.getClass().getSimpleName() + " - " + t.getMessage());
            StaticLog.logSevere(t);
            // Abort further processing.
            break;
        }
    }
    // Patches for special circumstances.
    for (IPatchBlockPropertiesSetup patch : new IPatchBlockPropertiesSetup[] { new MultiClientProtocolBlockShapePatch() }) {
        try {
            if (patch.isAvailable()) {
                patch.setupBlockProperties(worldConfigProvider);
                String description = patch.getNeutralDescription();
                if (description == null || description.isEmpty()) {
                    description = patch.getClass().getSimpleName();
                }
                StaticLog.logInfo("Update block-info: " + description);
            }
        } catch (Throwable t) {
            StaticLog.logSevere(patch.getClass().getSimpleName() + " could not be processed: " + t.getClass().getSimpleName() + " - " + t.getMessage());
            StaticLog.logSevere(t);
        }
    }
    return success;
}
Also used : IPatchBlockPropertiesSetup(fr.neatmonster.nocheatplus.compat.blocks.IPatchBlockPropertiesSetup) MultiClientProtocolBlockShapePatch(fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.special.MultiClientProtocolBlockShapePatch) LinkedList(java.util.LinkedList) BlockPropertiesSetup(fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup) IPatchBlockPropertiesSetup(fr.neatmonster.nocheatplus.compat.blocks.IPatchBlockPropertiesSetup)

Example 2 with BlockPropertiesSetup

use of fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method init.

/**
 * Initialize blocks and tools properties. This can be called at any time
 * during runtime.
 *
 * @param mcAccess
 *            If mcAccess implements BlockPropertiesSetup,
 *            mcAccess.setupBlockProperties will be called directly after
 *            basic initialization but before the configuration is applied.
 * @param worldConfigProvider
 *            the world config provider
 */
public static void init(final IHandle<MCAccess> mcAccess, final WorldConfigProvider<?> worldConfigProvider) {
    wrapBlockCache = new WrapBlockCache();
    rtRay = new PassableRayTracing();
    rtAxis = new PassableAxisTracing();
    pLoc = new PlayerLocation(mcAccess, null);
    // getClass().getName() or some abstract.
    final Set<String> blocksFeatures = new LinkedHashSet<String>();
    try {
        initTools(mcAccess, worldConfigProvider);
        initBlocks(mcAccess, worldConfigProvider);
        blocksFeatures.add("BlocksMC1_4");
        // Extra hand picked setups.
        try {
            blocksFeatures.addAll(new VanillaBlocksFactory().setupVanillaBlocks(worldConfigProvider));
        } catch (Throwable t) {
            StaticLog.logSevere("Could not initialize vanilla blocks: " + t.getClass().getSimpleName() + " - " + t.getMessage());
            StaticLog.logSevere(t);
        }
        // Allow mcAccess to setup block properties.
        if (mcAccess instanceof BlockPropertiesSetup) {
            try {
                ((BlockPropertiesSetup) mcAccess).setupBlockProperties(worldConfigProvider);
                blocksFeatures.add(mcAccess.getClass().getSimpleName());
            } catch (Throwable t) {
                StaticLog.logSevere("McAccess.setupBlockProperties (" + mcAccess.getClass().getSimpleName() + ") could not execute properly: " + t.getClass().getSimpleName() + " - " + t.getMessage());
                StaticLog.logSevere(t);
            }
        }
    // TODO: Add registry for further BlockPropertiesSetup instances.
    } catch (Throwable t) {
        StaticLog.logSevere(t);
    }
    // Override feature tags for blocks.
    NCPAPIProvider.getNoCheatPlusAPI().setFeatureTags("blocks", blocksFeatures);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VanillaBlocksFactory(fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.VanillaBlocksFactory) PassableAxisTracing(fr.neatmonster.nocheatplus.utilities.collision.PassableAxisTracing) PassableRayTracing(fr.neatmonster.nocheatplus.utilities.collision.PassableRayTracing) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) BlockPropertiesSetup(fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup)

Aggregations

BlockPropertiesSetup (fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup)2 IPatchBlockPropertiesSetup (fr.neatmonster.nocheatplus.compat.blocks.IPatchBlockPropertiesSetup)1 VanillaBlocksFactory (fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.VanillaBlocksFactory)1 MultiClientProtocolBlockShapePatch (fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.special.MultiClientProtocolBlockShapePatch)1 PassableAxisTracing (fr.neatmonster.nocheatplus.utilities.collision.PassableAxisTracing)1 PassableRayTracing (fr.neatmonster.nocheatplus.utilities.collision.PassableRayTracing)1 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1