public void addMechanic(IMechanic mechanic) { // TODO: check if this list works as it's supposed to (with passing a reference) if (mechanic instanceof SignMechanic) { SignMechanic signMechanic = (SignMechanic) mechanic; if (signMechanic.isTriggeredByRedstone()) { for (String identifier : signMechanic.getIdentifier()) { ArrayList<SignMechanic> list = redstoneSignMechanicMap.get(identifier); if (list == null) { list = new ArrayList<SignMechanic>(); list.add(signMechanic); redstoneSignMechanicMap.put(identifier, list); } else { list.add(signMechanic); redstoneSignMechanicMap.put(identifier, list); } } } else { for (String identifier : signMechanic.getIdentifier()) { ArrayList<SignMechanic> list = signMechanicMap.get(identifier); if (list == null) { list = new ArrayList<SignMechanic>(); list.add(signMechanic); signMechanicMap.put(identifier, list); } else { list.add(signMechanic); } } } } else if (mechanic instanceof BlockMechanic) { BlockMechanic blockMechanic = (BlockMechanic) mechanic; if (blockMechanic.isTriggeredByRedstone()) { for (Material target : blockMechanic.getMechanicTarget()) { ArrayList<BlockMechanic> list = redstoneBlockMechanicMap.get(target); if (list == null) { list = new ArrayList<BlockMechanic>(); list.add(blockMechanic); redstoneBlockMechanicMap.put(target, list); } else { list.add(blockMechanic); redstoneBlockMechanicMap.put(target, list); } } } else { for (Material target : blockMechanic.getMechanicTarget()) { ArrayList<BlockMechanic> list = blockMechanicMap.get(target); if (list == null) { list = new ArrayList<BlockMechanic>(); list.add(blockMechanic); blockMechanicMap.put(target, list); } else { list.add(blockMechanic); } } } } if (mechanic instanceof ICommandableMechanic) { ICommandableMechanic commandableMechanic = (ICommandableMechanic) mechanic; if (commandableMechanicMap.containsKey(commandableMechanic.getName())) { BetterMechanics.log( "Mechanic: " + commandableMechanic.getName() + " tried to register a command that has already been registered!", Level.SEVERE); } else { commandableMechanicMap.put(commandableMechanic.getName(), commandableMechanic); } } }
public boolean callCommandEvent(Command command, CommandSender commandSender, String[] args) { ICommandableMechanic mechanic = commandableMechanicMap.get(command.getName()); return mechanic != null && mechanic.onCommand(commandSender, command, args); }